Sign in to follow this  
c0uchm0nster

Trouble with hooking

Recommended Posts

hi, I know this is a pretty popular question, however I'm running into problems with hooking stuff. I was checking out the sample @ http://www.gamedev.net/community/forums/topic.asp?topic_id=359794 but I can't get it to work with any program (even the provided vertices program.) Unless I'm misunderstanding it's use somehow I'm supposed to run launcher with the target exe, and then i run the exe itself while the launcher is still running and i should see a gradiant box in the top-left corner, no? Is this sample outdated or is something else going on? Thanks.

Share this post


Link to post
Share on other sites
First of all the target application has to be using the DirectX9 API. This is because in order to hook the API you have to write wrapper functions for each DirectX function. Then the dll hooks itself to a target exe. The dll can hook any program, usually you specify an exe name and the dll will check if it's the target application by comparing against it's process name. You can infact have it target anything you want. I'm not sure how Muhammad has implemented this in his example you link.

It's not a very reliable way to overlay graphics on any game, unless your prepared to write wrappers for every DirectX version and that would take a while. If it's a particular game your aiming to overlay graphics for, then you just have to support the appropriate DirectX API that it uses so you can sit between the target app and DirectX. You can usually find out what API it uses by viewing the attached dll's in Process Explorer, viewing the binary in a hex editor, or using a program that shows an exe's dependacies.

There is something interesting I stumbled on recently that uses DirectDraw overlays. "DirectDraw overlays are special DirectDraw surfaces that are shown over everything else, including full-screen games and applications." Might be worth a look.

Let me know if this DirectDraw overlay library is useful, because I have some use for such a thing myself.

http://www.codeplex.com/DirectDrawOverlayLib

Share this post


Link to post
Share on other sites
Yeah I had seen that before. I was just wary of it because it's DX7 stuff, which got "merged" into d3d8 sort of but not really, and it doesn't work reliably in vista and there's no easy way to grab input *shrug*.

The sample you linked to works, but it's image is blury, only updates a couple times a second, and is sparse on commenting at the moment.

All I really want to be able to do is see an aim buddy list, and talk to people while in-game. I know that's a pretty damn big task, but if I can get the hooking (or an overlay + input) solution working I could get the rest of it done just fine.

If overlays are still the best way to go, is there any way to handle input on them?

thanks

Share this post


Link to post
Share on other sites
Again you can use APIHijack to catch keys in DirectInput, and you can even stop keys from passing through to the target application. That is one method. You can download the wrappers for doing this from [url=http://members.iinet.net.au/~freeaxs/etc/DInputWrappers.zip]here[/url].

Next there is a global keyhook method using SetWindowsHookEx with the WH_KEYBOARD_LL parameter. That interecepts windows messages, and again you can block a key from going through to the target application by returning a 1 in the hook callback function. Otherwise you can just pass the messages along. I don't believe this method will work with applications that use DirectInput (for the blocking part, not the actual reading of keys). That being said, just because you have a DirectX application doesn't mean they are using DirectInput for their input system. Check out this [url=http://msdn.microsoft.com/msdnmag/issues/0700/Win32/]article[/url] for a basic global hook for blocking some system keys. It will give you an idea of how that works.

I believe both these methods will also allow you to read in mouse position.

Finally the most basic method to read a keypress globally is to use GetKeyState() API function. That might be enough for your needs, and is obviously alot easier than the other two methods.

Share this post


Link to post
Share on other sites
Quote:
Original post by c0uchm0nster
I was checking out the sample @ http://www.gamedev.net/community/forums/topic.asp?topic_id=359794 but I can't get it to work with any program (even the provided vertices program.) Unless I'm misunderstanding it's use somehow I'm supposed to run launcher with the target exe, and then i run the exe itself while the launcher is still running and i should see a gradiant box in the top-left corner, no?

Yes, that's what should happen.

Quote:
Is this sample outdated or is something else going on?

The sample was more of a proof of concept. It has many of limitations, and they're listed there. Several people have contacted me about since I wrote it, and one of them changed the sample to do global hooking (instead of a specific process), but he didn't publish it anywhere. It means it's possible, though.

I intended to update the hooking sample after finishing the DirectDrawOveray library, but I've been distracted by work and other happenings in life the past couple of weeks.

Quote:
The sample you linked to works, but it's image is blury, only updates a couple times a second, and is sparse on commenting at the moment.

The blurry image bug is fixed, but not in the current (public) release. The update rate is up to the application--the library only provides a blitter.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this