C#单机游戏作弊器,因为网上现成的码字,所以占下来,居然爽爽的,被作弊的游戏就是植物大战僵尸(中文)了!

CE工具比不可少,本人觉得最难的也就在此了,怎么找地址是整个修改器的核心,好在网上的资料堆积成山,当然这个需要积累和一些悟性,不是一时半晌能够搞定的。

至于所说的基地址,什么1级,2级地址,都是用上面的CE搞定的,都在程序代码中了,至于在其他机器上是不是这个值,我可没有验证过。

至于代码全部是网上粘贴,只是在vs2010 c#中添加了相应的按钮而已。

最后,代码来自网络,如有雷同,纯属粘贴(偷懒),请大咖谅解。

 可否想过有这么多钱,还有无限阳关的心态。(再次感谢网络大咖无私奉献代码!)

 

第一个文件:

// Helper.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication3
{
    public abstract class Helper
    {
        [DllImportAttribute("kernel32.dll", EntryPoint = "ReadProcessMemory")]
        public static extern bool ReadProcessMemory
        (
        IntPtr hProcess,
        IntPtr lpBaseAddress,
        IntPtr lpBuffer,
        int nSize,
        IntPtr lpNumberOfBytesRead
        );
        [DllImportAttribute("kernel32.dll", EntryPoint = "OpenProcess")]
        public static extern IntPtr OpenProcess
        (
        int dwDesiredAccess,
        bool bInheritHandle,
        int dwProcessId
        );
        [DllImport("kernel32.dll")]
        private static extern void CloseHandle
        (
        IntPtr hObject
        );
        //写内存
        [DllImportAttribute("kernel32.dll", EntryPoint = "WriteProcessMemory")]
        public static extern bool WriteProcessMemory
        (
        IntPtr hProcess,
        IntPtr lpBaseAddress,
        int[] lpBuffer,
        int nSize,
        IntPtr lpNumberOfBytesWritten
        );
        //获取窗体的进程标识ID
        public static int GetPid(string windowTitle)
        {
            int rs = 0;
            Process[] arrayProcess = Process.GetProcesses();
            foreach (Process p in arrayProcess)
            {
                if (p.MainWindowTitle.IndexOf(windowTitle) != -1)
                {
                    rs = p.Id;
                    break;
                }
            }
            return rs;
        }
        //根据进程名获取PID
        public static int GetPidByProcessName(string processName)
        {
            Process[] arrayProcess = Process.GetProcessesByName(processName);
            foreach (Process p in arrayProcess)
            {
                return p.Id;
            }
            return 0;
        }
        //根据窗体标题查找窗口句柄(支持模糊匹配)
        public static IntPtr FindWindow(string title)
        {
            Process[] ps = Process.GetProcesses();
            foreach (Process p in ps)
            {
                if (p.MainWindowTitle.IndexOf(title) != -1)
                {
                    return p.MainWindowHandle;
                }
            }
            return IntPtr.Zero;
        }
        //读取内存中的值
        public static int ReadMemoryValue(int baseAddress, string processName)
        {
            try
            {
                byte[] buffer = new byte[4];
                IntPtr byteAddress = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); //获取缓冲区地址
                IntPtr hProcess = OpenProcess(0x1F0FFF, false, GetPidByProcessName(processName));
                ReadProcessMemory(hProcess, (IntPtr)baseAddress, byteAddress, 4, IntPtr.Zero); //将制定内存中的值读入缓冲区
                CloseHandle(hProcess);
                return Marshal.ReadInt32(byteAddress);
            }
            catch
            {
                return 0;
            }
        }
        //将值写入指定内存地址中
        public static void WriteMemoryValue(int baseAddress, string processName, int value)
        {
            IntPtr hProcess = OpenProcess(0x1F0FFF, false, GetPidByProcessName(processName)); //0x1F0FFF 最高权限
            WriteProcessMemory(hProcess, (IntPtr)baseAddress, new int[] { value }, 4, IntPtr.Zero);
            CloseHandle(hProcess);
        }
    }
}

第二个文件:

//Program.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

 

        //启动无线金钱
        private void btnMoney_Click_1(object sender, EventArgs e)
        {
            if (Helper.GetPidByProcessName(processName) == 0)
            {
                MessageBox.Show("哥们启用之前游戏总该运行吧!");
                return;
            }
            if (btnMoney.Text == "启用-金钱无限")
            {
                timer2.Enabled = true;
                btnMoney.Text = "关闭-金钱无限";
            }
            else
            {
                timer2.Enabled = false;
                btnMoney.Text = "启用-金钱无限";
            }
        }


        //读取制定内存中的值
        public int ReadMemoryValue(int baseAdd)
        {
            return Helper.ReadMemoryValue(baseAdd, processName);
        }
        //将值写入指定内存中
        public void WriteMemory(int baseAdd, int value)
        {
            Helper.WriteMemoryValue(baseAdd, processName, value);
        }
        private int baseAddress = 0x00779618;           //游戏内存基址
        private string processName = "PlantsVsZombies";




        private void btnGet_Click(object sender, EventArgs e)
        {

            if (Helper.GetPidByProcessName(processName) == 0)
            {
                MessageBox.Show("哥们启用之前游戏总该运行吧!");
                return;
            }
            if (btnGet.Text == "启用-阳光无限")
            {
                timer1.Enabled = true;
                btnGet.Text = "关闭-阳光无限";
            }
            else
            {
                timer1.Enabled = false;
                btnGet.Text = "启用-阳光无限";
            }
  
        }

        private void btnGo_Click(object sender, EventArgs e)
        {

            if (Helper.GetPidByProcessName(processName) == 0)
            {
                MessageBox.Show("哥们启用之前游戏总该运行吧!");
                return;
            }
            int address = ReadMemoryValue(baseAddress);             //读取基址(该地址不会改变)
            address = address + 0x950;                              //获取2级地址
            address = ReadMemoryValue(address);
            address = address + 0x4c;
            int lev = 1;
            try
            {
                lev = int.Parse(txtLev.Text.Trim());
            }
            catch
            {
                MessageBox.Show("输入的关卡格式不真确!默认设置为1");
            }
            WriteMemory(address, lev);

        }


        private void timer1_Tick_1(object sender, EventArgs e)
        {
            if (Helper.GetPidByProcessName(processName) == 0)
            {
                timer1.Enabled = false;
                btnGet.Text = "启用-阳光无限";
            }
            int address = ReadMemoryValue(baseAddress);             //读取基址(该地址不会改变)
            address = address + 0x868;                              //获取2级地址
            address = ReadMemoryValue(address);
            address = address + 0x5578;                             //获取存放阳光数值的地址
            WriteMemory(address, 10000);                          //写入数据到地址(0x1869F表示99999)
            timer1.Interval = 1000;
        }



        private void timer2_Tick(object sender, EventArgs e)
        {

            if (Helper.GetPidByProcessName(processName) == 0)
            {
                timer2.Enabled = false;
                btnMoney.Text = "启用-金钱无限";
            }
            int address = ReadMemoryValue(baseAddress);             //读取基址(该地址不会改变)
            address = address + 0x950;                              //获取2级地址
            address = ReadMemoryValue(address);
            address = address + 0x50;                               //得到金钱地址
            WriteMemory(address, 0x1869F);                          //写入数据到地址(0x1869F表示99999)
            timer2.Interval = 1000;
        }
 
    }
}

 

 

 

©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页