Sorry about that Wingfat, I've registered now.
Email me at
astaelan@telus.net
I don't often sit on the forum waiting for private messages, I'm constantly bouncing between 3 or 4 forums and 10 search engines, another 20 pages trying to dig for some tidbits of information. I think I'm getting really close now with the idea of using Madshi's madHookCode and hooking the device creations. Here's what my latest research and posting in other forums has made me aware of:
First, by using a free program available at
http://www.smidgeonsoft.com/ called PEBrowse (some of you might have known of this already, I didn't), you can find out what exports a DLL has. For example, opening DINPUT.DLL showed me that 3 different creation methods are available:
DirectInputeCreateA, DirectInputCreateW, and DirectInputCreateEx
According to Madshi's latest hint (he likes to hint and point but never give actual answers, it's kinda fun, heh), and some other research, I found that you can create 2 things. First, an EXE, which uses madHookCode to call InjectLibrary. This has the ability to Inject a DLL of your choice into any program. The way it was explained is that it effectively patches the program in such a way that a call to LoadLibrary would be on the first line of the Main execution.
Once this has been achieved, the only other word for the EXE is to call UninjectLibrary when you are done. My understanding is that once you InjectLibrary, I THINK a hook is created so that any program matching criteria passed to InjectLibrary, will be hooked upon their execution. This means InjectLibrary returns immediately if all goes well. This is where I'm currently having some troubles, but I'll continue on the explanation.
Let's assume the DLL is called Hooker.dll for lack of better naming, heh. What we code into Hooker.dll is the actual calls to HookAPI. This is where the "exports" from DINPUT.DLL come into play. By hooking DirectInputCreateA, W, and/or Ex, it is my understanding we can obtain the DirectInput interface for the generic DirectInput object.
Further research leads me to believe that once you have this, you use the interface to hook a specific method. This is where HookCode comes into play. By calling HookCode on index 3 (the fourth method, 0 inclusive), I believe we are hooking CreateDevice. The first 3 (0-2) are the reserved COM interfaces for Query, AddRef, RemoveRef, whatever they are called. The first one after these, I believe I found in some research was CreateDevice.
So, by calling HookCode on CreateDevice, we should be able to get 2 more interface pointers. One for the Keyboard and one for the Mouse. It's entirely possible you could also get pointers for Joysticks and I believe ForceFeedback devices as well if you wanted to go that far. My concern right now is Mouse and Keyboard, with Mouse being more important.
Okay, so let's assume now we have piDIKeyboard and piDIMouse, being pointers to interfaces of the DirectInput Keyboard and DirectInput Mouse that the program has Created. Some internal workings of madHookCode demand that we declare a Next hook, which is actually the original hook before we hook into it. So, by calling the original hook for these first, DirectInput does it's job, creates the device and before we return from the hooks, we can call the next hook in the chain. Once we have those 2 pointers, we have to figure out what index the GetDeviceState method is in order to hook it.
Right now, my latest post to Madshi is requesting some information on how you find out the index of method's to pass to HookCode... He explained PEBrowse to find the initial export, but I'm not sure how to calculate the index of the interface methods after that. It may be as simple as opening a specific header file like dinput.h and counting the methods on the DirectInput interface types... That's going to be my next stop to see if it seems to make sense.
Wingfat, feel free to contact me, unfortunately forums and email are a very slow means of communication, I'm hoping ICQ or MSN are a viable option outside of work hours for you? My profile contains my ICQ and MSN but just in case, it's 2447380 or
astaelan@hotmail.com and the email I check most frequently is
astaelan@telus.net
Hope to hear from you soon. I'm hell-bent on figuring this out, happy to have someone on the team!
