C# - SendMessage/PostMessage

12/07/2013 03:25 Santa#1
Hello, I have recently started to toy around with the idea of sending a mouse click, or other events, to a conquer client that is minimized, or just not in focus. I have been using Spy++ to help along in all the messages the client receives and what not. I have got it kind of working and was wondering if anyone here could give me a hand.
Code:
//WM_PARENTNOTIFY-SendMessage-ParentWindow
bool seven = MouseClickHandler.SendMessage(new IntPtr(0x004F04CA), (int)0x0210, new IntPtr(0x00000201), new IntPtr(MouseClickHandler.getHiLoWord(730, 719)));

//WM_SETCURSOR-Sendmessage-"Macromdia" window
bool two = MouseClickHandler.SendMessage(new IntPtr(0x00140210), (int)0x0020, new IntPtr(0x00140210), new IntPtr(0x02000001));

//WM_MOUSEMOVE-PostMessage-"Macromedia" window
bool four = MouseClickHandler.PostMessage(new IntPtr(0x00140210), (uint)0x200, IntPtr.Zero, new IntPtr(MouseClickHandler.getHiLoWord(730, 719)));

//WM_MOUSEACTIVATE-SendMessage-"Macromedia" window
bool one = MouseClickHandler.SendMessage(new IntPtr(0x00140210), (int)0x021, new IntPtr(0x004F04CA), new IntPtr(0x02010001));

//WM_LBUTTONDOWN-PostMessage-"Macromedia" window
bool three = MouseClickHandler.PostMessage(new IntPtr(0x00140210), (uint)0x201, new IntPtr(0x00000001), new IntPtr(MouseClickHandler.getHiLoWord(730, 719)));

//WM_MOUSEMOVE-PostMessage-"Macromedia" window
bool six = MouseClickHandler.PostMessage(new IntPtr(0x00140210), (uint)0x200, new IntPtr(0x00000001), new IntPtr(MouseClickHandler.getHiLoWord(730, 719)));

//WM_LBUTTONUP-PostMessage-"Macromedia" window
bool five =  MouseClickHandler.PostMessage(new IntPtr(0x00140210), (uint)0x202, IntPtr.Zero, new IntPtr(MouseClickHandler.getHiLoWord(730, 719)));
This is what I have so far, I haven't worried about finding the hWnd of any of the necessary windows yet because I don't want to spend the time if it doesn't work. So basically I open the client then my windows form and click the button. I have the simulated mouse click click the "enter" button so there is a pop up. If I send the messages multiple times rapidly the button gets clicked. When I don't send it rapidly you can just see the enter button get highlighted so I know the SETCURSOR and MOUSEMOVE messages are moving.

I'm not sure if anyone has messed with this before, and actually got it working, but the other threads I have found didn't provide any good information. Any help appreciated.

Edit: So I still have not figured it out but I logged in and did a mouse click in game and it works. Would still be interested in if anyone has a reason why the above code only works when its sent repeatedly. thanks.

Thanks
12/07/2013 13:48 { Angelius }#2
The reason you have to send the message rapidly/repeatedly is that the message you are sending is not the only message the client is expecting/waiting for to process..
There are hundreds of internal messages that the client has to handle and since you are an intruder sneaking through the backdoor your message is most likely being lost and not reaching its destination...

Now i could be wrong since that is not the only reason your messages are not being processed right away..


However all you need to send is...
WM_LBUTTONDOWN -> WM_LBUTTONUP On the desired X/Y the rest is useless... And if by "button" you mean the Enter button on the login screen then follow the mouse clicks with a WM_KEYDOWN with a VK_RETURN for the wParam.

Edit..
And by the way the client pretty much sleeps when its minimized and the sleeping states also includes/restricts many messages from being processed.. So don't get your hopes up unless you are planing something simple.
12/08/2013 01:40 Santa#3
Quote:
Originally Posted by { Angelius } View Post
The reason you have to send the message rapidly/repeatedly is that the message you are sending is not the only message the client is expecting/waiting for to process..
There are hundreds of internal messages that the client has to handle and since you are an intruder sneaking through the backdoor your message is most likely being lost and not reaching its destination...

Now i could be wrong since that is not the only reason your messages are not being processed right away..


However all you need to send is...
WM_LBUTTONDOWN -> WM_LBUTTONUP On the desired X/Y the rest is useless... And if by "button" you mean the Enter button on the login screen then follow the mouse clicks with a WM_KEYDOWN with a VK_RETURN for the wParam.

Edit..
And by the way the client pretty much sleeps when its minimized and the sleeping states also includes/restricts many messages from being processed.. So don't get your hopes up unless you are planing something simple.

I figured it was because I was missing some of the messages, I tried sendinge every message received around the time of the click in all windows.

Either way its working when logged into the game, and mouse clicks work just fine when screen is minimized.

Thanks
12/21/2013 03:16 Kid Nieh#4
I'm actually working on a bot that uses sendmessage/postmessage as well. Currently it pathfinds and jumps to specified coordinates, uses xp skill automatically when the bar reaches 100, and autopots. As of right now, I don't know how to read memory structures or have in-depth knowledge of memory so I can't scan for monsters and their coordinates to automate accurate attacks so I have done a horrible way to just click in circular motions around the player to attack mobs that surround and then jump to the next spawn spot.