Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Simple help question with PostMessageA(Updated)

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ssaccount
Master Cheater
Reputation: 0

Joined: 29 Aug 2007
Posts: 391
Location: Finland

PostPosted: Wed Oct 01, 2008 12:42 pm    Post subject: [C++] Simple help question with PostMessageA(Updated) Reply with quote

I managed to fix my error but however this isn't working as it should.
When im ingame and run the code it starts to spam "A" but my character doesn't attack(My attack key is "A")

(The game is MapleStory btw.)

my code looks like this now:

Code:

Code:
#include "windows.h"
#include <tchar.h>
#include <iostream>

using namespace std;

LRESULT InjectMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
   WNDPROC WndProc;
   LRESULT lRET = 0;

   WndProc = (WNDPROC)GetWindowLong(hWnd, GWL_WNDPROC);
   if (WndProc != NULL)
      lRET = CallWindowProc(WndProc, hWnd, uMsg, wParam, lParam);
   return lRET;
}

int main() {
   
   while (true) {
       

         HWND hWndE = FindWindow(_T("MapleStoryClass"),0); 

         PostMessage(hWndE, WM_CHAR, 'A', 0);


      Sleep(1);
   }
}

_________________
Programming in C++
(Or at least trying to Very Happy)


Last edited by ssaccount on Thu Oct 02, 2008 6:15 am; edited 1 time in total
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Wed Oct 01, 2008 12:49 pm    Post subject: Reply with quote

use L"MapleStoryClass" instead and btw the 2nd parameter is the window name not the class name so switch them
another thing you can use is
Code:

#include <tchar.h>

and then you can use it like this
Code:

FindWindow(_T("MapleStoryClass"),0);

_________________
Stylo
Back to top
View user's profile Send private message
ssaccount
Master Cheater
Reputation: 0

Joined: 29 Aug 2007
Posts: 391
Location: Finland

PostPosted: Wed Oct 01, 2008 1:02 pm    Post subject: Reply with quote

1qaz wrote:
use L"MapleStoryClass" instead and btw the 2nd parameter is the window name not the class name so switch them
another thing you can use is
Code:

#include <tchar.h>

and then you can use it like this
Code:

FindWindow(_T("MapleStoryClass"),0);



Thank you very much it works now Very Happy

_________________
Programming in C++
(Or at least trying to Very Happy)
Back to top
View user's profile Send private message
ElJEffro
Grandmaster Cheater Supreme
Reputation: 0

Joined: 15 Apr 2007
Posts: 1881
Location: La Tierra

PostPosted: Wed Oct 01, 2008 6:33 pm    Post subject: Reply with quote

Keep in mind that there are 2 versions of most windows API, the ones that end in W are for unicode char and the ones ending in A are ansi encoded char. If you look in windows.h you see #define FindWindow FindWindowW.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Oct 02, 2008 9:18 am    Post subject: Reply with quote

of course it won't attack cuz you send wm_char and it sends the virtual key of 'A' and doesn't actually press on A
to press on a key use WM_KEYDOWN

_________________
Stylo
Back to top
View user's profile Send private message
ssaccount
Master Cheater
Reputation: 0

Joined: 29 Aug 2007
Posts: 391
Location: Finland

PostPosted: Thu Oct 02, 2008 11:41 am    Post subject: Reply with quote

1qaz wrote:
of course it won't attack cuz you send wm_char and it sends the virtual key of 'A' and doesn't actually press on A
to press on a key use WM_KEYDOWN



Ok i changed this:

Code:
PostMessage(hWndE, WM_CHAR, 'A', 0);


to this which presses 0 (I changed my attack to "0") but still it doesen't attack Sad

Code:
PostMessage(hWndE, WM_KEYDOWN, 0x71, 0);

_________________
Programming in C++
(Or at least trying to Very Happy)
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Oct 02, 2008 12:26 pm    Post subject: Reply with quote

cuz you need to bypass the hook of user32 API's or however it called
why aren't you using InjectMessage that you implemented before
or you can bypass it yourself by jumping 5 bytes over the hook

_________________
Stylo
Back to top
View user's profile Send private message
ssaccount
Master Cheater
Reputation: 0

Joined: 29 Aug 2007
Posts: 391
Location: Finland

PostPosted: Thu Oct 02, 2008 12:32 pm    Post subject: Reply with quote

1qaz wrote:
cuz you need to bypass the hook of user32 API's or however it called
why aren't you using InjectMessage that you implemented before
or you can bypass it yourself by jumping 5 bytes over the hook






Actually i have the bypass. Here is the full code:
(and im not yet very experienced with C++ so im making little mistakes of course)

Code:
#include "windows.h"
#include <tchar.h>
#include <iostream>

using namespace std;
DWORD _PMA = NULL;

 

LRESULT InjectMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
   WNDPROC WndProc;
   LRESULT lRET = 0;

   WndProc = (WNDPROC)GetWindowLong(hWnd, GWL_WNDPROC);
   if (WndProc != NULL)
      lRET = CallWindowProc(WndProc, hWnd, uMsg, wParam, lParam);
   return lRET;
}

__declspec(naked) BOOL WINAPI _PostMessageA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)

{
    __asm
    {
        mov    edi, edi
        push   ebp
        mov    ebp, esp
        jmp    dword ptr ds:[_PMA]
    }
}

int main() {
 

     if(HWND hWndE = FindWindow(_T("MapleStoryClass"),0))
     {
   
   cout << "MapleStory window found!", cout << endl;

     }

   while (true) {
       
if(HWND hWndE = FindWindow(_T("MapleStoryClass"),0))
{

       //  HWND hWndE = FindWindow(_T("MapleStoryClass"),0); 

         PostMessage(hWndE, WM_KEYDOWN, 0x30, 1);
       Sleep(10);
         PostMessage(hWndE, WM_KEYUP, 0x30, 1);

      Sleep(10);
}
else
{
cout << "MapleStory window not found!", cout << endl;

Sleep(5000);



}
   }
}

_________________
Programming in C++
(Or at least trying to Very Happy)
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Oct 02, 2008 12:45 pm    Post subject: Reply with quote

still i don't see u use the bypassed API,
it's good that you bypassed the hook but u don't use it
u still use PostMessage instead of _PostMessage, plus your _PMA variable contains a NULL value, to get the the API Address use this
Code:

_PMA = GetProcAddress(LoadLibraryA("User32.Dll"),"PostMessageA") + 5;

then it should work fine
edit: to send the key perfectly to the game you need to use also MapVirtualKey plus shifting left 16 bits of the key
Code:

_PostMessage(hWnd,WM_KEYDOWN,0x71,(MapVirtualKey(0x71,0)) << 16);

_________________
Stylo
Back to top
View user's profile Send private message
ssaccount
Master Cheater
Reputation: 0

Joined: 29 Aug 2007
Posts: 391
Location: Finland

PostPosted: Thu Oct 02, 2008 1:06 pm    Post subject: Reply with quote

1qaz wrote:
still i don't see u use the bypassed API,
it's good that you bypassed the hook but u don't use it
u still use PostMessage instead of _PostMessage, plus your _PMA variable contains a NULL value, to get the the API Address use this
Code:

_PMA = GetProcAddress(LoadLibraryA("User32.Dll"),"PostMessageA") + 5;

then it should work fine
edit: to send the key perfectly to the game you need to use also MapVirtualKey plus shifting left 16 bits of the key
Code:

_PostMessage(hWnd,WM_KEYDOWN,0x71,(MapVirtualKey(0x71,0)) << 16);




Thank you, your a pro Smile it's working now

_________________
Programming in C++
(Or at least trying to Very Happy)
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Oct 02, 2008 1:12 pm    Post subject: Reply with quote

you're welcome,
it's not that i pro it's just was your mistakes that i fixed
u implemented a function but you used another one so agree with me that it doesn't make any sens
and you wished to jump over the hook to _PMA value, but the thing is that u left it NULL and it can't jump to 0 address, there's no such thing
anyway keep practicing,have a nice day =]

_________________
Stylo
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites