Send Messages to a Game.

07/03/2012 15:14 jackicola#1
Hey,
I'm trying to send a mouseclick-message to a game, like this:

Code:
#include <iostream>
#include <Windows.h>

using namespace std;

int main()
{

	HWND hWnd = FindWindowA(NULL, "GAME");
	if(!hWnd)
	{
		cout << "HWND Failed" << endl;
		getchar();
		getchar();
		exit(1);
	}


	Sleep(5000);

	SendMessage(hWnd,WM_LBUTTONDOWN,0,0);
	Sleep(100);
    SendMessage(hWnd,WM_LBUTTONUP,0,0); 
}
But nothing happens. Any suggestions??
07/03/2012 15:26 tnd0#2
because it is using directinput instead of the windows message queue i guess. so the window itself doesnt care about anything it receives unless it is a quitmessage.
07/03/2012 15:58 atx3e#3
Quote:
Originally Posted by jackicola View Post
Hey,
I'm trying to send a mouseclick-message to a game, like this:

Code:
...
	SendMessage(hWnd,WM_LBUTTONDOWN,0,0);
	Sleep(100);
        SendMessage(hWnd,WM_LBUTTONUP,0,0); 
}
But nothing happens. Any suggestions??
[Only registered and activated users can see links. Click Here To Register...]

You should specify the coordinates of the cursor in lParam (and maybe set wParam to 1 when you send the WM_LBUTTONDOWN message)
07/03/2012 16:13 jackicola#4
THX, but it's still not working.. I read that DirectX games in most cases ignore this kind of Messages. What can I do?
07/03/2012 16:24 tnd0#5
get the handle of the directinput device and send your messages there. you won't find that one with FindWindow, you gotta query its GUID from the process and the try to copy the handle with full access, a rather complex process.
07/03/2012 18:19 Dr. Coxxy#6
if its not necessary that the window is in the background you can try SendInput with DInput keycodes.

otherwise you should do what tnd0 said, or hook dinput like this:
[Only registered and activated users can see links. Click Here To Register...]

if you want to make a bot which works in the background, you should reverse the game and call the functions which get called when you press a key on your own.
07/04/2012 14:00 jackicola#7
Thx for that link! I coded my DLL, but I get 2 Errors:

1: LPDIRECTINPUTDEVICE is not defined. (Maybe include a .dll/.lib?)
2: DI_OK is not defined.

How can I fix that?
Greets!
07/04/2012 14:25 Dr. Coxxy#8
include dinput.h

its in the dx sdk:
[Only registered and activated users can see links. Click Here To Register...]
07/04/2012 17:03 jackicola#9
Okay, I included this file and now it says:
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800

How to fix that?
Greets!
07/04/2012 17:07 tnd0#10
before including dxinput.h:

Code:
#define DIRECTINPUT_VERSION 2048
07/04/2012 19:09 jackicola#11
THX for ur help it's working now (Atleast with that test-program).
I tried to inject it in "Aion", a MMORPG, and the Log looks like this:

Code:
Log Added (07/04/12 19:04:55): ==========LOG START==========
Log Added (07/04/12 19:04:55): DLL Attached
Log Added (07/04/12 19:04:55): Creating Thread...
Log Added (07/04/12 19:04:55): Thread Created
Log Added (07/04/12 19:04:55): Searching dinput8.dll...
Log Added (07/04/12 19:04:55): Found dinput8.dll: 58690000 !
Log Added (07/04/12 19:04:55): Searching GetDeviceState...
Log Added (07/04/12 19:04:55): Found DirectInput8Create: 5869cc8e !
Log Added (07/04/12 19:04:55): GetDevicestate is here (DirectInput8Create - 0x62B1): 586969dd
Log Added (07/04/12 19:04:55): Hooking GetDeviceState...
Log Added (07/04/12 19:04:55): Hooked GetDeviceState - Trampolin: 3b4b14c0 - New: 58541177 !
Log Added (07/04/12 19:06:06): DLL Detached
Log Added (07/04/12 19:06:06): ==========LOG END==========
And I changed the new Function to this:
Code:
HRESULT __stdcall hkGetDeviceState(LPDIRECTINPUTDEVICE lpDevice, DWORD cbData, LPVOID lpvData) 
{
	static BYTE buffer[256]; 
	HRESULT temp = DI_OK;
	------------------>add_log("LOOP"); <------------------
	if (!Freeze) 
	{
		temp = pGetDeviceState(lpDevice, cbData, lpvData);
		memcpy(buffer, lpvData, cbData);
		
	} else {
		memcpy(lpvData, buffer, cbData); 
	} 
	return temp; 
}
But it doesn't say "LOOP" a single time in the Log. So something is going wrong. Can you please help me again? :)
07/04/2012 19:28 tnd0#12
Im pretty positive Aion has some complex anti-cheat mechanisms. Rule #2 on asian software: it's not what it looks like. (rule #1: never trust it)

Try it on some other games, preferably singleplayer indie-games.
07/04/2012 20:36 jackicola#13
Yeah,ok, but my goal was to make a bot for Aion. Do you have any ideas how I could make this work?
THX!
07/04/2012 21:39 Dr. Coxxy#14
check if your detour installed correctly.
if not, try vtable replacing, mid-function hooks, etc.
07/04/2012 21:59 jackicola#15
And how can I check this? Doesn't the Log say it was installed correctly?