植物大战僵尸无限阳光C实现

// zwdzjs.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include <stdio.h>
#include "windows.h"
int main()
{

    DWORD PID=0;
    HANDLE Process = 0;
    DWORD SumTotal = 0;
    DWORD  BaseAddress = 0x0075799C;


    //1.首先我们需要获取到游戏的进程pid,然后读取游戏的内存

    HWND Hwnd  = FindWindow(NULL, L"Plants vs. Zombies 1.2.0.1073 RELEASE");
    if (Hwnd == NULL)
    {
        printf("植物大战僵尸僵尸没有运行,请先运行游戏\n");
        return 0;
    }

    //2 获取进程PID
    GetWindowThreadProcessId(Hwnd, &PID);				//获取进程PID

    if ( PID == 0 )
    {
        printf_s("获取PID失败\n");
        return 0;
    }
    //打开进程
    Process = OpenProcess(PROCESS_ALL_ACCESS, 0, PID);
    if (NULL == Process)
    {
        printf_s("进程打开失败\n");
        GetLastError();
        return 0;
    }
    //读取进程内容

    //获取内存地址
    DWORD SunAddressValue = 0;
    
    if (ReadProcessMemory(Process, (char*)BaseAddress, &SunAddressValue, 4, 0) == false)
    {
        GetLastError();
        return 0;
    }
   //获取一级偏移地址
   
    DWORD SunAddressFirstValue = 0;
    if (ReadProcessMemory(Process, (char*)(SunAddressValue + 0x868), &SunAddressFirstValue, 4, 0) == false)
    {
        GetLastError();
        return 0;
    }


    //获取二级偏移地址 也就是阳光的内存地址

    if (ReadProcessMemory(Process, (char*)(SunAddressFirstValue + 0x5578), &SumTotal, 4, 0) == false)
    {
        GetLastError();
        return 0;
    }
       
    printf("阳光的地址%d", SumTotal);
   
    //如果阳光小于9999
    while (SumTotal < 9999)
    {
        DWORD WriteSumTotal = 9999;
        printf_s("没有阳光了");
        WriteProcessMemory(Process, (char*)(SunAddressFirstValue + 0x5578),&WriteSumTotal , 4, 0);
        Sleep(5000);
    }

}
发表评论 / Comment

用心评论~