植物大战僵尸修改器(第二版)

前提需要用CE找到游戏中阳光的基址,我的是win10 64位操作系统,找的阳光基址和偏移是:
Base = 0x00755E0C;
Offset[0] = 0x868;
Offset[1] = 0x5578;
有了基址和偏移以后,即使游戏关掉重启,我们依然可以用此程序来修改阳光的数值。

#include  
#include

using namespace std;
HWND hwnd_Game;
DWORD ProcessID;
HANDLE h_process;
int Base;
int Offset[10];

void GetGameInfo()
{
    hwnd_Game = FindWindow(NULL, L"Plants vs. Zombies");
    GetWindowThreadProcessId(hwnd_Game, &ProcessID);
    h_process = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessID);
    Base = 0x00755E0C;
    Offset[0] = 0x868;
    Offset[1] = 0x5578;
}

//通过基址加偏移得到动态地址
int GetDymThroughBase(int Base, int Offset[], int len)
{
    int Dym_temp;
    ReadProcessMemory(h_process, (LPVOID)Base, &Dym_temp, 4, NULL);
    for (int i = 0; i < len; i++)
    {
        if (i == len - 1)
            Dym_temp += Offset[i];
        else
            ReadProcessMemory(h_process, (LPVOID)(Dym_temp + Offset[i]), &Dym_temp, 4, NULL);
    }
    return Dym_temp;
}
void ChangeSunshine(int num)
{
    int DymnamicAddress = GetDymThroughBase(Base, Offset, 2);
    int ret = WriteProcessMemory(h_process, (LPVOID)DymnamicAddress, &num, 4, NULL);
    if (ret == 0)
    {
        cout << "修改失败!" << endl;
    }
    else
    {
        cout << "修改成功!" << endl;
    }
}

int main()
{
    int n_sunshine_change;
    while(1)
    { 
        cout << "欢迎使用植物大战僵尸外挂,请输入你要修改的阳光值(-1退出):";
        cin >> n_sunshine_change;
        if (-1 == n_sunshine_change)
        {
            exit(-1);
        }
        GetGameInfo();
        ChangeSunshine(n_sunshine_change);
        system("pause");
    }

    return 0;
}

你可能感兴趣的:(植物大战僵尸修改器(第二版))