#include <iostream>
#include <windows.h>
using namespace std;
/*声明变量*/
HWND hand=NULL;
DWORD pid=0;
HANDLE hProcess=NULL;
DWORD BaseValue=0;
DWORD SunshineAddress;
/*声明方法/函数 */
bool startGame();
bool initSunshine();
int getSunshineValue();
void setSunshineValue(int value);
int main(int argc, char** argv) {
system("cls");
int sun_zhi;
cout<<"***1.增加阳光值***"<<endl;
bool Result=false;
Result=startGame();
if(Result==false){
return 0;
}
int zhu;
while(1){
switch(zhu){
case 1:
cout<<"请输入充值阳光的数目:";
initSunshine();
getSunshineValue();
cin>>sun_zhi;
setSunshineValue(sun_zhi);
}
}
return 0;
}
bool startGame(){
//查找电脑是否运行了植物大战僵尸
hand=FindWindow("MainWindow","植物大战僵尸中文版");
//cout<<hand<<endl;
if(hand==NULL){
cout<<"游戏没有运行";
return false;
}
//cout<<"窗口:"<<hand<<endl;
GetWindowThreadProcessId(hand,&pid);
if(pid==0){
cout<<"无法找到植物大战僵尸进程";
return false;
}
//cout<<"进程:"<<pid<<endl;
hProcess=OpenProcess(PROCESS_ALL_ACCESS,false,pid);
if(hProcess==NULL){
cout<<"无法打开进程"<<endl;
return false;
}
//cout<<"打开进程"<<hProcess<<endl;
DWORD BaseAddress=0x006A9EC0; //获取游戏数据的基础地址
bool Result=ReadProcessMemory(
hProcess,//读取哪一个进程
(LPVOID)BaseAddress,//内存地址是多少
&BaseValue,
4,//数据存储长度
NULL//实际读取的长度
);
if(Result==false){
cout<<"初始基础地址失败";
return false;
}
return true;
}
//初始化阳光地址———寻找真实的阳光地址
bool initSunshine(){
DWORD _Address=BaseValue+0x768;//一级偏移地址
DWORD _Value=0;
bool Result= ReadProcessMemory(
hProcess, //读取哪一个进程
(LPVOID)_Address,//内存地址是多少
&_Value, //读取数据在哪
4, //数据存储长度
NULL //实际读取的长度
);
if(Result==false){
cout<<"初始化阳光地址失败";
return false;
}
SunshineAddress=_Value+0x5560;
return true;
}
//获取阳光值
int getSunshineValue(){
//阳光内存变量的真正名称
DWORD value=0;
bool Result= ReadProcessMemory(
hProcess, //读取哪一个进程
(LPVOID)SunshineAddress,//阳光内存地址
&value, //读取数据在哪
4, //数据存储长度
NULL //实际读取的长度
);
if(Result==false){
cout<<"初始化阳光地址失败";
return false;
}
return (int)value;
}
//设置阳光值
void setSunshineValue(int value){
WriteProcessMemory(hProcess,(LPVOID)SunshineAddress,&value,4,NULL);
}