C#开发 植物大战僵尸 修改阳光值 源码无私分享
C#开发 植物大战僵尸 修改阳光值 源码无私分享
编程码农 发表于1年前
C#开发 植物大战僵尸 修改阳光值 源码无私分享
  • 发表于 1年前
  • 阅读 15
  • 收藏 0
  • 点赞 2
  • 评论 0

腾讯云 十分钟定制你的第一个小程序>>>   

源代码:

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;
//Win32 API
using System.Runtime.InteropServices;
using System.Timers;

/**
 *uint PROCESS_ALL_ACCESS = 0x001F0FFF; 
 */

namespace plantsVsZombiesAux
{
    public partial class Form1 : Form
    {
        public bool isStart = false;
        public bool isCheckStar = false;
        public uint processGame;
        public const string gameName = "PlantsVsZombies";
        public const uint PROCESS_ALL_ACCESS  = 0x001F0FFF;
        public const uint lpGameBaseAddr = 0x007794f8;
        public uint lpGameAddr = 0;
        public uint smallThreshold = 500;
        public uint bigThreshold = 50000;

        //导入win32 API
        [DllImport("kernel32.dll")]
        /**/
        public static extern uint ReadProcessMemory(
        uint hProcess,
        uint lpBaseAddress,
        uint[] lpBuffer,
        uint nSize,
        uint lpNumberOfBytesWritten
        );
        [DllImport("kernel32.dll")]
        public static extern uint OpenProcess(
        uint dwDesiredAccess, //渴望得到的访问权限(标志)
        bool bInheritHandle, // 是否继承句柄
        uint dwProcessId// 进程标示符
        );
        [DllImport("kernel32.dll")]
        public static extern uint WriteProcessMemory(
            uint hProcess,
            uint lpBaseAddress,
            string lpBuffer,
            UInt32 nSize,
            uint lpNumberOfBytesWritten
        );
        /**/
        public Form1()
        {
            InitializeComponent();
            
        }
        public static uint readMemory(uint processId,uint add)
        {
            uint[] r = new uint[1];
            try
            {
                ReadProcessMemory(processId, add, r, 4, 0);
                return r[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return 0;
            }
        }

        public void initGamesInfo()
        {
            uint lpBuffer = 0;
            lpBuffer = readMemory(this.processGame, lpGameBaseAddr);
            uint lpBufferSec;
            lpBufferSec = lpBuffer + 0x868;
            lpBufferSec = readMemory(this.processGame, lpBufferSec);
            lpBuffer = lpBufferSec + 0x5578;
            //Convert.ToInt32(lpBuffer, 16);
            this.lpGameAddr = lpBuffer;
        }
        public uint getGamesSonValue(string sonVal = "")
        {
            if (sonVal.Length > 0)
            {
                WriteProcessMemory(this.processGame, this.lpGameAddr, sonVal, (UInt32)sonVal.Length, 0);
                return 1;
            }
            uint lpBuffer = 0;
            try
            {
                lpBuffer = readMemory(this.processGame,this.lpGameAddr);
               
                string valStr = lpBuffer.ToString();
                //更新控件变量
                sonValTextInput.Text = valStr;
                uint resVal = 0;
                uint.TryParse(valStr, out resVal);
                //更新控件
                Refresh();
                return resVal;

            }catch(Exception ex){
                MessageBox.Show(ex.ToString());
                return 0;
            }
            
        }
        //定时器自动修改阳光值
        private void autoSetTimer_Tick(object sender, EventArgs e)
        {
            this.isCheckStar = autoSetcheckBox.Checked;
            if (this.isStart && this.isCheckStar)
            {
                uint currSonVal = getGamesSonValue();
                if(currSonVal <= smallThreshold)
                {
                    getGamesSonValue(bigThreshold.ToString());
                }
            }
        }
        //点击开始按钮
        private void startButton_Click(object sender, EventArgs e)
        {
            this.isStart = true;
            /**/
            System.Diagnostics.Process[] GamesProcess
                = System.Diagnostics.Process.GetProcessesByName(gameName);
            if (GamesProcess.Length == 0)
            {
                MessageBox.Show("请运行植物大战僵尸!再启动本辅助!!");
                return;
            }
            uint ProcessID = (uint)GamesProcess[0].Id;
            /* */
            /*
            IntPtr hWnd = ::FindWindow(0,gameName);  //查找窗口句柄
            if(hWnd.ToInt32() == 0) return;
            
            uint ProcessID;
            GetWindowThreadProcessId(hWnd,&ProcessID);  //取得进程ID
             */
            this.processGame = OpenProcess(PROCESS_ALL_ACCESS, false, ProcessID);
            this.isCheckStar = autoSetcheckBox.Checked;
            //初始化游戏相关基址
            initGamesInfo();
            //获取阳光的值
            getGamesSonValue();

        }
        //暂停按钮
        private void pauseButton_Click(object sender, EventArgs e)
        {
            this.isStart = false;
        }
    }
}

效果图:

 

 

 

 

 

 

 

 

游戏参考:

http://www.pc6.com/z/zwdzjs2/

 

源码下载:

http://www.oschina.net/code/snippet_2697322_56153

 

标签: C#辅助开发
共有 人打赏支持
粉丝 2
博文 19
码字总数 13170
×
编程码农
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: