植物大战僵尸3.0

发布时间 2023-12-24 09:46:07作者: 爱吃泡面的皮卡
#include <iostream>
#include <windows.h>
using namespace std;
//声明变量
DWORD ZombiesAddress;
HWND hand = NULL;
DWORD pid = 0;
HANDLE hProcess = NULL;
DWORD BaseValue = 0;
DWORD SunshineAddress = 0;
DWORD MoneyshineAddress = 0;
void a();
void chushihua();
bool startGame();
bool initSunshine();
int getSunshineValue();
void setSunshineValue(int value);
bool initMoneyshine();
int getMoneyshineValue();
void setMoneyshineValue(int value);
void initCDshine();
void noCoolDown();
bool initZombies();
bool killZombies();
int main(){
    system("title 植物大战僵尸外挂程序");
    system("color 0B");
    do{
        bool Result = false;
        Result = startGame();
        if(Result==false){
            system(    "start C:/Users/Administrator/Desktop/植物大战僵尸1电脑版/PlantsVsZombies.exe");
            Sleep(3000);
        }else{
            break;
        }
    }while(true);
    int n;
    while(1){
        system("cls");
        chushihua();
        int zhi;
        cin>>n;
        switch(n){
            case 1:
                initSunshine();
                getSunshineValue();
                cout<<"请输入你要修改的阳光值:";
                cin>>zhi;
                setSunshineValue(zhi);
                cout<<"修改成功"<<endl;
                break;
            case 2:
                initMoneyshine();
                getMoneyshineValue();
                cout<<"请输入你要修改的金币值:";
                cin>>zhi;
                setMoneyshineValue(zhi);
                cout<<"修改成功"<<endl;
                break;
            case 3:
                noCoolDown();
                break;
            case 4:
                initZombies();
                killZombies();
                    break;
            case 5:
                a();
                break;
            case 6:
                system("pause"); 
                return 0;
        }
        system("pause"); 
    }
    return 0;
}
//免暂停 
void a(){
    //免暂停时间代码
    DWORD BASE = 0x4502C0;
    //打开进程
    DWORD pianyi = 0xC3;
    WriteProcessMemory(hProcess,(LPVOID)BASE,&pianyi,4,NULL);
}
void chushihua(){
    cout<<"植物大战僵尸外挂程序"<<endl
        <<"****1.修改阳光值****"<<endl
        <<"****2.修改金币值****"<<endl
        <<"****3.种植无冷却****"<<endl
        <<"****4.僵尸被秒杀****"<<endl
        <<"****5.程序免暂停****"<<endl
        <<"****6.关闭此外挂****"<<endl;
}
bool startGame(){
    //查找电脑是否运行了植物大战僵尸
    hand = FindWindow("MainWindow","植物大战僵尸中文版");
    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<<"无法打开进程";
        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 0;
    } 
    cout<<"当前阳光值:"<<value<<endl;
    return (int)value;
}
//修改阳光值 
void setSunshineValue(int value){
    WriteProcessMemory(hProcess,(LPVOID)SunshineAddress,&value,4,NULL);
}
//寻找真实的金币地址
bool initMoneyshine(){
    DWORD _address = BaseValue+0x82c;//一级偏移地址 
    DWORD _value = 0;
    bool Result = ReadProcessMemory(hProcess,(LPVOID)_address,&_value,4,NULL);
    if(Result==false){
        cout<<"初始化金币地址失败";
        return false;
    }
    MoneyshineAddress = _value+0xac;//二级偏移地址 
    return true;
}
//获取金币值 
int getMoneyshineValue(){
    //金币存变量的真正名称
    DWORD Vvalue = 0;
    bool Result = ReadProcessMemory(hProcess,(LPVOID)MoneyshineAddress,&Vvalue,4,NULL);
    if(Result==false){
        cout<<"获取金币数据失败";
        return 0;
    } 
    cout<<"当前金币值:"<<Vvalue<<endl;
    return (int)Vvalue;
}
//修改金币值 
void setMoneyshineValue(int value){
    WriteProcessMemory(hProcess,(LPVOID)MoneyshineAddress,&value,4,NULL);
}
void noCoolDown(){
    //无冷却时间代码
    DWORD base = 0x00488e73;
    //打开进程
    DWORD PIANYI = 0x80;
    WriteProcessMemory(hProcess,(LPVOID)base,&PIANYI,1,NULL); 
    cout<<"种植无冷却"<<endl;
}
bool initZombies(){
    //僵尸
    DWORD _Address=BaseValue+0x768;
    DWORD _Value=0;
    bool Result=ReadProcessMemory(
    hProcess,
    (LPVOID)_Address,
    &_Value,
    4,
    NULL
    );
    if(Result==false){
        cout<<"初始化将是地址失败";
        return false;
    }
    ZombiesAddress=_Value+0x90;
    Result=ReadProcessMemory(
    hProcess,
    (LPVOID)ZombiesAddress,
    &_Value,
    4,
    NULL
    );
    if(Result==false){
        cout<<"僵尸二次偏移失败";
        return false;
    }
    ZombiesAddress=_Value;
    cout<<"僵尸地址:"<<ZombiesAddress<<endl;
    return true; 
}
bool killZombies(){
    for(int i=0;i<100;i++){
        DWORD _address=ZombiesAddress+0x28+i*0x15c;
        DWORD _Value=0;
        bool Result=ReadProcessMemory(
        hProcess,
        (LPVOID)_address,
        &_Value,
        4,
        NULL
        );
        if(Result==false){
            cout<<"僵尸血量获取失败";
            continue;
        }
        int value=3;
        if(_Value<100){
            WriteProcessMemory(hProcess,(LPVOID)_address,&value,4,NULL);
        }else{
            cout<<"疑似僵尸血量:"<<_Value<<endl;
        }
    }
return true;
}