The following are the key code:
Setwindowtext ("Plants vs. zombie sun modifier -- sman"); // set the window title
Gamehwnd =: findwindow ("mainwindow", "Chinese version of Plants vs. Zombies"); // get handle
Getwindowthreadprocessid (gamehwnd, & hprocid); // obtain the process ID
Mprocid = OpenProcess (process_all_access, false, hprocid); // open the process
If (mprocid = 0) {// exit if the process ID is equal to 0
MessageBox ("First Run Plants vs. botnets ");
Postquitmessage (0 );
Return false;
}
// 0x006a9ec0 is the game base address 768, and 5560 is the offset. The real address equals to the game base address + offset.
Readprocessmemory (mprocid, lpcvoid (0x006a9ec0), & eax, sizeof (DWORD), 0 );
Readprocessmemory (mprocid, maid (eax + 0x00000768), & ECx, sizeof (DWORD), 0 );
Readprocessmemory (mprocid, maid (ECx + 0x00005560), & HP, sizeof (DWORD), 0 );
Cstring STR;
Str. Format ("% d", HP );
Getdlgitem (idc_edit1)-> setwindowtext (STR );
========================================================== ======================================
// Write Memory Data
Void cobjectchidlg: writememory (){
Int sunnum;
Cstring STR;
// Obtain the value of the input box
Getdlgitem (idc_edit2)-> getwindowtext (STR );
// Convert to an integer
Sunnum = atoi (STR );
// Write memory
Bool rc = writeprocessmemory (mprocid, (lpvoid) (ECx + 0x00005560), & sunnum, 4, null );
If (RC ){
MessageBox ("modified successfully ");
Getdlgitem (idc_edit1)-> setwindowtext (STR );
} Else {
Int ncode = getlasterror ();
Cstring errorinfo;
Errorinfo. Format ("% d error code: % d", & HP, ncode );
MessageBox (errorinfo );
}
}