C ++ plug-ins read and write game memory

Source: Internet
Author: User

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 );
}
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.