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 


Can some1 tells me what's wrong with that code? (C++)
Goto page 1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Jun 05, 2008 7:37 am    Post subject: Can some1 tells me what's wrong with that code? (C++) Reply with quote

i'm trying to make an auto looter for maple story as part of my msBot
now i used registerhotkey function to register F2 to turn on AutoLoot
and when it turns on a timer is running and i inside the WM_TIMER message i use the bypassed PostMessage function to post the 'Z' key
but when i press F2 for some reason the bot is crushing Confused
i checked things out and the problem is in the postMessage area
here's a part of the code:
Code:

      case WM_TIMER:
         switch (wParam)
         {
            case TIMER_SEC:
               if (lootFLAG)
               {
                  if (hMS != NULL)
                  {
                     myPostMessage(hMS,WM_CHAR,0x5A,NULL); // crushing is happening here i think
                  }
               }
               break;
         }
         break;


any ideas Confused

_________________
Stylo
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Jun 05, 2008 8:06 am    Post subject: Reply with quote

1. For the lParam of the PostMessage use the value of the virtual key shifted by 16 bits

here's a definition i created for easy LPARAM's

Code:
#define MAKELKEY(vk) (MapVirtualKey( (UINT)(vk), 0 ) << 16)


and for your PostMessage do:

Code:
myPostMessage(hMS,WM_CHAR,0x5A,MAKELKEY(0x5A));


2. Don't use timer's. There extremely inefficient. Use Threading API instead. (CreateThread, ExitThread, etc.) And then just loop within it.

_________________
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 Jun 05, 2008 8:44 am    Post subject: Reply with quote

ohh, right! i need to sheeft the key 16 bits
but i didnt understand the code you wrote there:
Code:

#define MAKELKEY(vk) (MapVirtualKey( (UINT)(vk), 0 ) << 16)

and
Code:

myPostMessage(hMS,WM_CHAR,0x5A,MAKELKEY(0x5A));


isn't the lParam suppose to be null at this function ?

about the Threading API can u make an example code of doing it ?
thx anyways Very Happy

_________________
Stylo
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Thu Jun 05, 2008 8:49 am    Post subject: Reply with quote

You also need to send WM_KEYDOWN, not WM_CHAR.
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 Jun 05, 2008 9:00 am    Post subject: Reply with quote

oh right cuz i want it to press the key. . thx:D
edit: the bot keeps crushing :\
look at the code now:
Code:

LPARAM lParam = ((int)MapVirtualKey(0x5A,0) << 16) + 1;
myPostMessage(hMS,WM_KEYDOWN,0,lParam);

_________________
Stylo
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Thu Jun 05, 2008 10:16 am    Post subject: Reply with quote

1qaz wrote:
oh right cuz i want it to press the key. . thx:D
edit: the bot keeps crushing :\
look at the code now:
Code:

LPARAM lParam = ((int)MapVirtualKey(0x5A,0) << 16) + 1;
myPostMessage(hMS,WM_KEYDOWN,0,lParam);


Lurc just told you to do

Code:

myPostMessage(hMS, WM_KEYDOWN, 0x5A, MAKELKEY(0x5A));


Even if you don't want to use his define, aren't you missing something in your code? Rolling Eyes

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
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 Jun 05, 2008 10:25 am    Post subject: Reply with quote

i dont think i'm missing anything
cuz when i created my previous bot at C# i used the same method and it works fine :\ Rolling Eyes

_________________
Stylo
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Thu Jun 05, 2008 10:37 am    Post subject: Reply with quote

I think he was talking about wParam...
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Thu Jun 05, 2008 1:49 pm    Post subject: Reply with quote

CreateThread and ExitThread:

CreateThread - http://msdn.microsoft.com/en-us/library/ms682453.aspx
ExitThread - http://msdn.microsoft.com/en-us/library/ms682659.aspx


Code Snippet:
Code:
void AutoLoot()
{
    while ( bLoot )
    {
         _PostMessageA( hMaple, WM_KEYDOWN, 0x5A, MAKELKEY(0x5A) );
         Sleep( 100 );
    }
    ExitThread(0);
}

void CreateMyThread()
{
    CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)AutoLoot, 0, 0, 0 );
}

_________________
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 Jun 05, 2008 11:02 pm    Post subject: Reply with quote

the bot still curshing Sad
Code:

void AutoLoot()
{
   BOOL bLoot = TRUE;
   while (bLoot)
   {
      LPARAM lParam = ((int)MapVirtualKey(0x5A,0) << 16) + 1;
      if (hMS != NULL)
         PostMessageX(hMS,WM_KEYDOWN,0,lParam);
   }
   ExitThread(0);
}
//
//
//
      case WM_HOTKEY:
         if (0x71)
         {
            DestroyWindow(hLoot);
            lootFLAG = !lootFLAG;
            if (lootFLAG)
            {
               hLoot = CreateWindowEx(NULL,L"STATIC",L"Auto Loot - Enabled",WS_CHILD | WS_VISIBLE,20,10,130,18,hWnd,(HMENU)IDC_STATIC_LOOT,GetModuleHandle(NULL),NULL);
               SetFont();
               hMS = FindWindow(L"MapleStoryClass",NULL);
               CreateThread(0,0,(LPTHREAD_START_ROUTINE)AutoLoot,0,0,0);
            }
            else
            {
               hLoot = CreateWindowEx(NULL,L"STATIC",L"Auto Loot - Disabled",WS_CHILD | WS_VISIBLE,20,10,130,18,hWnd,(HMENU)IDC_STATIC_LOOT,GetModuleHandle(NULL),NULL);
               SetFont();
            }
         }
         break;

_________________
Stylo
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Thu Jun 05, 2008 11:28 pm    Post subject: Reply with quote

samuri25404 wrote:

Code:

myPostMessage(hMS, WM_KEYDOWN, 0x5A, MAKELKEY(0x5A));


1qaz wrote:

Code:

         PostMessageX(hMS,WM_KEYDOWN,0,lParam);


You don't see ANYTHING different about the parameters?

myPostMessage(hMS, WM_KEYDOWN, 0x5A, MAKELKEY(0x5A));
PostMessageX(hMS, WM_KEYDOWN, 0, lParam);

NOTHING?

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Thu Jun 05, 2008 11:34 pm    Post subject: Reply with quote

THat shouldn't make it crash, samuri.
_________________
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Fri Jun 06, 2008 12:09 am    Post subject: Reply with quote

No, and why are you creating the static control all the time, again and again?

Just call SetDlgItemText.

Try debugging the bot to find out why it crashes, maybe the problem is PostMessageX and not the parameters.
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: Fri Jun 06, 2008 5:03 am    Post subject: Reply with quote

samurai, the parameters i use aren't suppose to crush the bot
i use it the same way with my previous bot and it did just fine :\

about the static control symbol, thx didnt know that i'll fix it :>
btw what does the 2nd parameter at SetDlgItemText contains i didnt understand that

_________________
Stylo
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Fri Jun 06, 2008 7:45 am    Post subject: Reply with quote

Code:

SetDlgItemText(hWnd, IDC_STATIC_LOOT, &lpString);

//or

SetDlgItemText(hWnd, IDC_STATIC_LOOT, "yourtexthere");

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2, 3, 4, 5  Next
Page 1 of 5

 
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