植物大战僵尸

发布时间 2023-12-17 09:26:22作者: fushuxuan1

#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 getSunshineValse();
void setSunshineValue(int value);
int main(){
bool result=false;
result=startGame();
if(result==false){
return 0;
}
int a;
initSunshine();
getSunshineValse();
cin>>a;
setSunshineValue(a);
return 0;
}
bool startGame(){
hand=FindWindow("MainWindow","植物大战僵尸中文版");
if(hand==NULL){
cout<<"游戏未运行"<<endl;
return false;
}
cout<<"窗口:"<<hand<<endl;
GetWindowThreadProcessId(hand,&pid);
if(pid==0){
cout<<"未找到进程"<<endl;
return false;
}
cout<<"进程:"<<pid<<endl;
hProcess=OpenProcess(PROCESS_ALL_ACCESS,
false,
pid);
if(hProcess==NULL){
cout<<"无法打开进程"<<endl;
return false;
}
DWORD BaseAddress=0x006A9EC0;
bool Result=ReadProcessMemory(
hProcess,
(LPVOID)BaseAddress,
&BaseValue,
4,
NULL);
if(Result==false){
cout<<"初始化基础地址失败"<<endl;
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<<"初始化阳光地址失败"<<endl;
return false;
}
SunshineAddress=_Value+0x5560;//二级偏移
return true;
}
//获取阳光值
int getSunshineValse(){
DWORD value=0;//阳光内存变量的真正名称
bool Result=ReadProcessMemory(
hProcess,
(LPVOID)SunshineAddress,
&value,
4,
NULL);
if(Result==false){
cout<<"获取阳光数据失败";
return 0;
}
cout<<"阳光:"<<value<<endl;
return (int)value;
}
//设置阳光值
void setSunshineValue(int value){
WriteProcessMemory(hProcess,(LPVOID)SunshineAddress,&value,4,NULL);
}