// TODO: 在此添加控件通知处理程序代码
HWND game_hwnd = FindWindowA(NULL,"植物大战僵尸"); //找到游戏的窗口
if(game_hwnd == NULL){
MessageBoxA(0,"请先运行游戏","error",0);
return ;
}
DWORD game_pid = 0;
GetWindowThreadProcessId(game_hwnd,&game_pid);//得到游戏的pid
if(game_pid != 0){
HANDLE game_handle = OpenProcess(PROCESS_ALL_ACCESS,0,game_pid);
//先判断一下地址的有效性
WORD read_data;
if(ReadProcessMemory(game_handle,reinterpret_cast<PVOID>(0x0227BC22),&read_data,2,0) && read_data == 0x840F)
{
//开启功能
BYTE start_data[] = {0xE9, 0x06, 0x01, 0x00};
WriteProcessMemory(game_handle,reinterpret_cast<PVOID>(0x0227BC22),start_data,sizeof(start_data),0);
MessageBoxA(0,"开启成功",0,0);
}
else
{
//关闭功能
BYTE end_data[] = {0x0F, 0x84, 0x05,0x1};
WriteProcessMemory(game_handle,reinterpret_cast<PVOID>(0x0227BC22),end_data,sizeof(end_data),0);
MessageBoxA(0,"关闭成功",0,0);
}
}
}