QT实现植物大战僵尸中文版工具代码

简介: QT实现植物大战僵尸中文版工具代码

.h文件

/*
 * @Author: Stylle
 * @Date: 2020-07-19 21:21:46
 * @LastEditors: Stylle
 * @LastEditTime: 2020-07-22 10:43:15
 * @FilePath: \tool-mastar\stylle_toolV1.8\tool_pvz.h
 */
#ifndef TOOL_PVZ_H
#define TOOL_PVZ_H
#include <QWidget>
//定时器
#include <QTimer>
//消息弹窗
#include <QMessageBox>
//跳转网页
#include <QDesktopServices>
#include <QUrl>
//window api调用
#include <windows.h>
namespace Ui
{
    class tool_pvz;
}
class tool_pvz : public QWidget
{
    Q_OBJECT
public:
    explicit tool_pvz(QWidget *parent = 0);
    ~tool_pvz();
    void printCs();
    void System_Init();
    void openBlog();
    void modifyGold();
    void modifySunshine();
    void NoCd_on(bool);
    void NoCd_stop(bool);
    void Auto_on(bool);
    void Auto_stop(bool);
private slots:
    void modifyNoCd();
    void modifyAuto();
    //    void on_btn_home_clicked();
private:
    QTimer *timer = new QTimer(this);
    QTimer *timer1 = new QTimer(this);
    Ui::tool_pvz *ui;
};
#endif // TOOL_PVZ_H

.c文件

#include "tool_pvz.h"
#include "ui_tool_pvz.h"
tool_pvz::tool_pvz(QWidget *parent) : QWidget(parent),
                                      ui(new Ui::tool_pvz)
{
    ui->setupUi(this);
    System_Init();
}
tool_pvz::~tool_pvz()
{
    delete timer;
    delete timer1;
    delete ui;
}
/***子函数代码区****/
void tool_pvz::System_Init()
{
    // 禁止最大化按钮
    setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint);
    // 禁止拖动窗口大小
    setFixedSize(this->width(), this->height());
    //绑定按钮事件
    connect(ui->btn_openUrl, &QPushButton::clicked, this, &tool_pvz::openBlog);
    connect(ui->PrintCs, &QPushButton::clicked, this, &tool_pvz::printCs);
    connect(ui->btn_gold, &QPushButton::clicked, this, &tool_pvz::modifyGold);
    connect(ui->btn_sun, &QPushButton::clicked, this, &tool_pvz::modifySunshine);
    //冷却取消  关闭冷却按钮
    connect(ui->btn_auto_off, &QPushButton::clicked, this, &tool_pvz::NoCd_stop);
    //开启冷却  恢复冷却
    connect(ui->btn_auto_on, &QPushButton::clicked, this, &tool_pvz::NoCd_on);
    //定时器
    connect(timer, SIGNAL(timeout()), this, SLOT(modifyNoCd()));
    //自动收集资源  自动收集按钮
    connect(ui->btn_sungon, &QPushButton::clicked, this, &tool_pvz::Auto_on);
    //取消自动收集资源  取消收集按钮
    connect(ui->btn_sungoff, &QPushButton::clicked, this, &tool_pvz::Auto_stop);
    //定时器1
    connect(timer1, SIGNAL(timeout()), this, SLOT(modifyAuto()));
}
void tool_pvz::printCs()
{
    long tmp = 0;
    do
    {
        QMessageBox box(QMessageBox::NoIcon, "你就说", "   刘露是不是渣男?");
        box.setStandardButtons(QMessageBox::Ok | QMessageBox::No);
        box.setButtonText(QMessageBox::Ok, QString("必须是"));
        box.setButtonText(QMessageBox::No, QString("不是?"));
        tmp = box.exec();
    } while (QMessageBox::No == tmp);
}
/*   下载游戏  */
void tool_pvz::openBlog()
{
    QDesktopServices::openUrl(QUrl("https://wws.lanzous.com/ifeDLemqjqh"));
}
/*  修改金币类  */
void tool_pvz::modifyGold()
{
    //检测游戏是否在运行
    HWND hGameWnd = FindWindow(L"MainWindow", L"植物大战僵尸中文版");
    if (hGameWnd == NULL)
        ui->hGameWnd->setText("未找到游戏");
    else
        ui->hGameWnd->setText("已找到游戏");
    DWORD dwPID = 0;
    //根据窗口句柄获取进程IPD
    GetWindowThreadProcessId(hGameWnd, &dwPID);
    //根据PID获取进程句柄
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);
    //从指定进程内存区去读取数据:读取进程,读取的基地址,接受进程地址数据,读取进程字节大小,实际读取字节数
    DWORD dwGoldBaseAddress = 0x6A9EC0;
    DWORD dwGoldAddressValue = 0;
    DWORD dwSize = 0;
    ReadProcessMemory(hProcess, (void *)dwGoldBaseAddress, &dwGoldAddressValue, sizeof(DWORD), &dwSize);
    //获取一级偏移地址
    DWORD dwGoldoffsetFirst = 0x82c;
    DWORD dwGoldoffsetValue = 0;
    ReadProcessMemory(hProcess, (void *)(dwGoldoffsetFirst + dwGoldAddressValue), &dwGoldoffsetValue, sizeof(DWORD), &dwSize);
    //获取二级偏移地址
    DWORD dwGoldoffsetsecond = 0x28;
    DWORD dwGold = 0;
    ReadProcessMemory(hProcess, (void *)(dwGoldoffsetValue + dwGoldoffsetsecond), &dwGold, sizeof(DWORD), &dwSize);
    DWORD addProcess = dwGoldoffsetValue + dwGoldoffsetsecond;
    DWORD tem = ui->edit_gold->text().toInt();
    WriteProcessMemory(hProcess, (void *)addProcess, &tem, sizeof(DWORD), &dwSize);
    //释放进程
    CloseHandle(hProcess);
}
/*  修改阳光类  */
void tool_pvz::modifySunshine()
{
    //检测游戏是否在运行
    HWND hGameWnd = FindWindow(L"MainWindow", L"植物大战僵尸中文版");
    if (hGameWnd == NULL)
        ui->hGameWnd->setText("未找到游戏");
    else
        ui->hGameWnd->setText("已找到游戏");
    DWORD dwPID = 0;
    //根据窗口句柄获取进程IPD
    GetWindowThreadProcessId(hGameWnd, &dwPID);
    //根据PID获取进程句柄
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);
    //从指定进程内存区去读取数据:读取进程,读取的基地址,接受进程地址数据,读取进程字节大小,实际读取字节数
    DWORD dwSunshineBaseAddress = 0x6A9EC0;
    DWORD dwSunshineAddressValue = 0;
    DWORD dwSize = 0;
    ReadProcessMemory(hProcess, (void *)dwSunshineBaseAddress, &dwSunshineAddressValue, sizeof(DWORD), &dwSize);
    //获取一级偏移地址
    DWORD dwSunshineoffsetFirst = 0x768;
    DWORD dwSunshineoffsetValue = 0;
    ReadProcessMemory(hProcess, (void *)(dwSunshineoffsetFirst + dwSunshineAddressValue), &dwSunshineoffsetValue, sizeof(DWORD), &dwSize);
    //获取二级偏移地址
    DWORD dwSunshineoffsetsecond = 0x5560;
    DWORD dwSunshine = 0;
    ReadProcessMemory(hProcess, (void *)(dwSunshineoffsetValue + dwSunshineoffsetsecond), &dwSunshine, sizeof(DWORD), &dwSize);
    DWORD addProcess = dwSunshineoffsetValue + dwSunshineoffsetsecond;
    DWORD tem = ui->edit_sun->text().toInt();
    WriteProcessMemory(hProcess, (void *)addProcess, &tem, sizeof(DWORD), &dwSize);
    //释放进程
    CloseHandle(hProcess);
}
/*  无CD类  */
void tool_pvz::modifyNoCd()
{
    //检测游戏是否在运行
    HWND hGameWnd = FindWindow(L"MainWindow", L"植物大战僵尸中文版");
    if (hGameWnd == NULL)
        ui->hGameWnd->setText("未找到游戏");
    else
        ui->hGameWnd->setText("已找到游戏");
    DWORD dwPID = 0;
    //根据窗口句柄获取进程IPD
    GetWindowThreadProcessId(hGameWnd, &dwPID);
    //根据PID获取进程句柄
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);
    //从指定进程内存区去读取数据:读取进程,读取的基地址,接受进程地址数据,读取进程字节大小,实际读取字节数
    DWORD dwBaseaddress = 0x6A9EC0;
    DWORD dwAddressValue = 0;
    int t = 1;
    ReadProcessMemory(hProcess, (LPVOID)dwBaseaddress, &dwAddressValue, 4, 0);
    DWORD offset1;
    ReadProcessMemory(hProcess, (LPVOID)(dwAddressValue + 0x768), &dwAddressValue, 4, 0);
    ReadProcessMemory(hProcess, (LPVOID)(dwAddressValue + 0x144), &dwAddressValue, 4, 0);
    int len = 10;
    for (int i = 0; i < len; i++)
    {
        offset1 = i * 0x50 + 0x70;
        WriteProcessMemory(hProcess, (LPVOID)(dwAddressValue + offset1), &t, 4, 0);
    }
    //释放进程
    CloseHandle(hProcess);
}
/*  自动收集资源类  */
void tool_pvz::modifyAuto()
{
    //检测游戏是否在运行
    HWND hGameWnd = FindWindow(L"MainWindow", L"植物大战僵尸中文版");
    if (hGameWnd == NULL)
        ui->hGameWnd->setText("未找到游戏");
    else
        ui->hGameWnd->setText("已找到游戏");
    DWORD dwPID = 0;
    //根据窗口句柄获取进程IPD
    GetWindowThreadProcessId(hGameWnd, &dwPID);
    //根据PID获取进程句柄
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);
    //从指定进程内存区去读取数据:读取进程,读取的基地址,接受进程地址数据,读取进程字节大小,实际读取字节数
    DWORD dwBaseaddress = 0x006A9EC0;
    DWORD dwAddressValue = 0;
    int t = 1;
    ReadProcessMemory(hProcess, (LPVOID)dwBaseaddress, &dwAddressValue, 4, 0);
    ReadProcessMemory(hProcess, (LPVOID)(dwAddressValue + 0x00000768), &dwAddressValue, 4, 0);
    ReadProcessMemory(hProcess, (LPVOID)(dwAddressValue + 0xE4), &dwAddressValue, 4, 0);
    int Numb = 50;
    for (int i = 0; i < Numb; i++)
    {
        DWORD object = dwAddressValue + 0x50 + i * 0xD8;
        DWORD objectType = dwAddressValue + 0x58 + i * 0xD8;
        DWORD Value1 = 0;
        DWORD Value2 = 0;
        ReadProcessMemory(hProcess, (LPVOID)object, &Value1, 4, 0);
        ReadProcessMemory(hProcess, (LPVOID)objectType, &Value2, 4, 0);
        if (Value1 == 0 && Value2 < 7)
        {
            WriteProcessMemory(hProcess, (LPVOID)object, &t, 4, 0);
        }
    }
    //释放进程
    CloseHandle(hProcess);
}
//无CD函数
void tool_pvz::NoCd_on(bool)
{
    //按钮可用控制
    int ms = 500;
    timer->start(ms);
    ui->btn_auto_on->setEnabled(false);
    ui->btn_auto_off->setEnabled(true);
}
void tool_pvz::NoCd_stop(bool)
{
    timer->stop();
    //按钮可用控制
    ui->btn_auto_off->setEnabled(false);
    ui->btn_auto_on->setEnabled(true);
}
//自动收集函数
void tool_pvz::Auto_on(bool)
{
    //按钮可用控制
    int ms = 500;
    timer1->start(ms);
    ui->btn_sungon->setEnabled(false);
    ui->btn_sungoff->setEnabled(true);
}
void tool_pvz::Auto_stop(bool)
{
    timer1->stop();
    //按钮可用控制
    ui->btn_sungoff->setEnabled(false);
    ui->btn_sungon->setEnabled(true);
}
/***子函数代码结束****/


相关文章
|
6月前
【Qt 学习笔记】使用QtCreator创建及运行项目 | 项目初始代码解释
【Qt 学习笔记】使用QtCreator创建及运行项目 | 项目初始代码解释
975 1
|
6月前
|
存储 C++
基于Qt的简易文件压缩与解压缩工具设计与实现
基于Qt的简易文件压缩与解压缩工具设计与实现
304 1
|
6月前
QT中按钮格式QSS代码
QT中按钮格式QSS代码
|
6月前
|
存储 测试技术 UED
Qt中实现界面回放的艺术:从理论到代码“ (“The Art of Implementing UI Playback in Qt: From Theory to Code
Qt中实现界面回放的艺术:从理论到代码“ (“The Art of Implementing UI Playback in Qt: From Theory to Code
153 1
|
3月前
|
XML Linux 程序员
【Qt】项目代码
【Qt】项目代码
|
6月前
|
安全
Qt日志工具--QsLog
Qt日志工具--QsLog
164 1
|
6月前
|
程序员 开发工具 索引
【Qt 学习笔记】认识QtSDK中的重要工具
【Qt 学习笔记】认识QtSDK中的重要工具
82 0
|
6月前
Qt程序打包发布记录使用windeployqt工具
Qt程序打包发布记录使用windeployqt工具
|
6月前
使用代码实现QT自定义布局
使用代码实现QT自定义布局
|
6月前
Qt 按行追加文本代码
Qt 按行追加文本代码
75 0

相关实验场景

更多