 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Tryst Expert Cheater
Reputation: 0
Joined: 05 Jan 2009 Posts: 156
|
Posted: Thu Jun 10, 2010 2:10 am Post subject: Need help with PostMessage in C# |
|
|
Hey guys, I'm trying to make a simple auto-attack bot and I'm struggling with PostMessage (which I think is the function I need to use to send keystrokes over to the game).
I am able to post keys, but it doesn't affect the in-game hotkeys. For example, if I open messenger (or anything I can type into in-game) and send "a", using the below code, it will work:
Code: | PostMessage(hWnd, WM_KEYDOWN, VK_A, 0); |
But if I assign my attack key, for example, to "a" and use the same code, my character just does nothing.
I'm a total beginner at C# so I apologise if I've missed something really obvious!
_________________
|
|
Back to top |
|
 |
Uzeil Moderator
Reputation: 6
Joined: 21 Oct 2006 Posts: 2411
|
Posted: Thu Jun 10, 2010 3:17 am Post subject: |
|
|
It isn't C#, it's the game. I remember in one game I had the exact same issue as you, but once I wrote a wrapper for PMA to set up the call frame then call the address afterwards(so I could skip a hook), it worked. Another possibility being that they use a keyboard hook to read your key presses for the game instead of processing messages to try and counter the everyday bot-maker.
Ah, another possibility is that you need to get a handle for what you can think of as a window inside your window, and use that as your hWnd instead.
_________________
|
|
Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Jun 10, 2010 4:05 am Post subject: |
|
|
I'm guessing you should left shifting the key
umm.. i haven't used it for ages, it's something like
Code: |
PostMessage( hWnd, WM_KEYDOWN, VK_A, ( MapVirtualKey( VK_A, 0 ) << 16 ) + 1 );
|
or something
_________________
Stylo |
|
Back to top |
|
 |
Tryst Expert Cheater
Reputation: 0
Joined: 05 Jan 2009 Posts: 156
|
Posted: Thu Jun 10, 2010 7:47 am Post subject: |
|
|
Okay, I now have this, but I'm getting 2 errors:
Code: | [DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll")]
static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll")]
static extern byte VkKeyScan(char ch);
const uint WM_KEYDOWN = 0x100;
private const int VK_A = 0x41;
private void btAttackOn_Click(object sender, EventArgs e)
{
PostMessage(hWnd, WM_KEYDOWN, VK_A, (MapVirtualKey(VK_A, 0) << 16) + 1);
} |
The errors I'm getting are:
Code: | Error 1 The best overloaded method match for 'Trainer.Form1.PostMessage(System.IntPtr, uint, int, int)' has some invalid arguments Form1.cs 503 13 Sample Trainer
Error 2 Argument 4: cannot convert from 'uint' to 'int' Form1.cs 503 49 Sample Trainer
|
Column 13 is the start of the PostMessage line, and 49 is the start of the (MapVirtualKey... part.
Again, I'm a complete beginner at this so apologies again if I'm missing something really obvious!
_________________
|
|
Back to top |
|
 |
blitz02 Cheater
Reputation: 0
Joined: 28 Feb 2007 Posts: 44
|
Posted: Thu Jun 10, 2010 7:49 am Post subject: |
|
|
Hi Tryst!
I was about to post an exact same topic like this.
Basically we have the same issues regarding this matter.
So to extend your information about that,
I would share this what I have researched.
From my understandings(Correct me if I'm wrong).
A simple PostMessage code like that won't run inside a Game who uses DIRECTINPUT.
So even you test the PMA code outside, it'll be different inside the game.
If that game doesn't use Gameguard or any Anti-Hack. You can try SendInput which is the only API that sends the DirectInput keys.(Based on my researches).
But if it uses Gameguard or any Anti-Hack, for sure SendInput would be hooked. From my researches, we cannot use the 5-byte Trampoline to SendInput and the last resort would be creating a driver.
So like I said I was here to post a new topic again, but I just saw yours. I guess I'll just collide my question here.
Can PMA/SMA use DirectInput as the keystrokes we we're sending?
I used PMA to test some keystrokes(with the normal code at the first post), only spacebar worked properly the way I like. Unlike other( Arrow Key, Control Key ), they aren't working.
Majority of the statements at google, SendInput was the only one(Among PMA/SMA) who can use the DirectInputs. But I guess I won't believe it until I heard it from here.
If there is an alternative way(except from coding a driver), please help us.
@Tryst
I hope the information levels our confused mind.
|
|
Back to top |
|
 |
Tryst Expert Cheater
Reputation: 0
Joined: 05 Jan 2009 Posts: 156
|
Posted: Thu Jun 10, 2010 8:06 am Post subject: |
|
|
I had read up about SendInput, but from what I gathered I think that requires the game to be the active window in order to work. I'd much prefer my bot to allow minimised botting.
I wasn't aware that this was a DirectInput issue though, and I'm pretty sure there's a way around it!
_________________
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Jun 10, 2010 3:18 pm Post subject: |
|
|
SendInput will work if you feed it DirectInput scan codes.
|
|
Back to top |
|
 |
blitz02 Cheater
Reputation: 0
Joined: 28 Feb 2007 Posts: 44
|
Posted: Thu Jun 10, 2010 9:46 pm Post subject: |
|
|
slovach wrote: | SendInput will work if you feed it DirectInput scan codes. |
But how about if SendInput is not available. Like it's being hooked by gameguard.
I tried this :
Quote: |
UINT WINAPI SendInputX(UINT nInputs, LPINPUT pInputs, int cbSize)
{
__asm //2nd try.
{
mov eax,000011F6h
mov edx,7FFe0300h
call dword ptr [edx]
ret 000ch
}
}
|
But it crashes.
|
|
Back to top |
|
 |
|
|
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 vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|