Plants vs. Zombies
#include <iostream>
#include <windows.h>
using namespace std;
/*声明变量 */
HWND hand=NULL; //游戏窗口
DWORD pid=0;//游戏进程ID
HANDLE hProcess=NULL;//进程对象
DWORD BaseValue=0;//游戏数据存放的基础值
DWORD SunshineAddress;//阳光地址
/*声明方法/函数 */
bool startGame(); //初始化游戏数据
bool Sunshine();
int getSunshine();
void setSunshine(int value);
int main() {
bool Result=true;
Result=startGame();
if(Result==false){
return 0;
}
Sunshine();
int yangguang=getSunshine();
cout<<"阳光值是:"<<yangguang<<endl;
cout<<"you want many"<<endl;
cin>>yangguang;
setSunshine(yangguang);
return 0;
}
bool startGame(){
//查找电脑是否运行了植物大战僵尸
hand= FindWindow("MainWindow","植物大战僵尸中文版");
if(hand==NULL){
cout<<"游戏没有运行";
return false;
}
cout<<"窗口:"<<hand<<endl;
GetWindowThreadProcessId(hand,&pid);
if(pid==0){
cout<<"no" ;
return false;
}
cout<<"进程"<<pid<<endl;
hProcess=OpenProcess(PROCESS_ALL_ACCESS,false,pid);
if(hProcess==NULL){
cout<<"no open process";
return false;
}
cout<<"打开进程:"<<hProcess<<endl;
DWORD BaseAddress=0x006A9EC0;
bool Result=ReadProcessMemory(hProcess,(LPVOID)BaseAddress,&BaseValue,4,NULL);
if(Result==false)
{
cout<<"lose";
return false;
}
return true;
}
bool Sunshine()
{
DWORD _address=BaseValue+0x768;
DWORD _value=0;
bool Result=ReadProcessMemory(hProcess,(LPVOID)_address,&_value,4,NULL);
if(Result==false)
{
cout<<"sunaddress lose";
return false;
}
SunshineAddress=_value+0x5560;
return true;
}
int getSunshine()
{
DWORD value = 0;
bool Result=ReadProcessMemory(hProcess,(LPVOID)SunshineAddress,&value,4,NULL);
if(Result==false)
{
cout<<"sun lose";
return 0;
}
cout<<"阳光数据:"<<value<<endl;
return (int)value;
}
void setSunshine(int value)
{
WriteProcessMemory(hProcess,(LPVOID)SunshineAddress,&value,4,NULL);
}