View unanswered posts | View active topics It is currently May 22nd, '13, 05:44




Reply to topic  [ 4 posts ] 
 Hook type question 
Author Message

Joined: Jul 24th, '10, 16:11
Posts: 3
Post Hook type question
I'm having trouble getting mouse/keyboard input into a directx game.

I'm using macromonkey to launch the game with a dll injected, the dll hooks the games packet functions and relays them to macromonkey via shared memory, lua takes care of the logic.

The bot communicates for the most part with packets, but I was trying to get movement controlled by the client so it would look more natural but still be able to run in the background.

Anyways, the game won't respond to macromonkeys mouse/key inputs unless the game is focused and only if the messages are sent without using handle, so I have the dll hooking directinput which works sort of..,

key pressing works but is unstable, randomly the key will get stuck so I decided to try to just get it to left click somewhere in the game through direct input.

When you left click in the game, the client takes care of the moving and auto moves to the location, after the click you can edit a memory address and have the bot move wherever you want and the client takes care of it, I just needed it to left click.

Basically it left clicks, but not on anything in the game, if i move the mouse over the window when the click is sent via directinput, it'll click in the corners despite the coordinates I put.

Anyways that was really long winded and sorry, I was just wondering if you knew of a easier way or if you had solved a problem like that before. I was thinking hooking the client function that automoves might be less hacky but hoping the simple mouse click would just work.


Aug 31st, '10, 13:01
Profile
Site Moderator
User avatar

Joined: Aug 18th, '09, 03:32
Posts: 1201
Post Re: Hook type question
With directinput hooks it will either work or it won't because there is not a lot to hook.
The inputs will be polled via "GetDeviceState()", or via "GetDeviceData()" for event input setups.
The polled kind if obviously easier to virtualize/emulate, luckily I've never had to do the 2nd kind it might be tricky.

Most do the polled kind. You can just keep your own array and OR it with the real read.

Some games that use DirectInput will often use it only for mouse inputs and use WM_KEYDOWN type message for key inputs.
But then other games might use DirectInput for both.

You have to understand how "cooperative levels" work with DirectInput.
Study the "SetCooperativeLevel()" method.
You will might have to hook it and force/filter "DISCL_BACKGROUND" and "DISCL_NONEXCLUSIVE".

Also it's typical that games will act differently when in focus and out (minimized, etc).
Look at what your target does with messages WM_ACTIVATE and WM_SIZE (see: http://blogs.msdn.com/b/jfoscoding/arch ... 86141.aspx).
You might have to patch or hook someplace to still allow inputs while minimized.


Aug 31st, '10, 20:55
Profile

Joined: Jul 24th, '10, 16:11
Posts: 3
Post Re: Hook type question
Ty man, that was a good article.

I've been using the GetDeviceState, and that works just not reliably, I tried GetDeviceDafa which probably would be mre reliable but the game doesn't use it at all.

I've messed with the cooperative thing but didn't try both that and stopping it from disabling the window, anyways thanks for sparking some different ideas to go about this


Sep 1st, '10, 17:00
Profile
Site Moderator
User avatar

Joined: Aug 18th, '09, 03:32
Posts: 1201
Post Re: Hook type question
Np, but I forgot something.
Maybe a better way is to just find your targets input event/polling routines.
Typically a game will have some kind of input queue for keyboard inputs.

It will be a layer or more below the DirectInput functions. You will have to reverse to find it/them.
You should be able to put a memory break-point on the input buffer after a DirectInput poll and watch what reads it, etc.

Then maybe you won't need any hooks at all.
You could just send your inputs directly to a game "input" function from your DLL.
And a nice thing, typically games will look for inputs from such a function regardless if it's minimized or not.

Finally a level above this then is to figure out how to do skills, etc., directly from functions still layers above this.
There is typically a "DoSkillOnTarget()" kind of function.
Then you could activate skills, etc., by some sort of ID and disregarding inputs.
But then this can get complicated. There can be different kind of skills and actions from different functions.
"Age of Conan" is like this.
It would be easier in this case to just press a hot bar key from some main input function.


Sep 3rd, '10, 20:21
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Based on design by STSoftware, modded by Sirmabus Copyright© 2009-2011