一个老的单机游戏,自己想写个修改器,可是返回的是0
不知道是哪不对?帮我看看吧using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
[DllImport("User32.dll")]
public static extern int FindWindow(string s,string ss); [DllImport("Kernel32.dll")]
public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle,int dwProcessId); [DllImport("user32.dll",EntryPoint = "GetWindowThreadProcessId")]
public static extern int GetWindowThreadProcessId(int hWnd,ref int lpdwProcessId); [DllImport("kernel32.dll")]
static extern bool ReadProcessMemory(uint hProcess,IntPtr lpBaseAddress, IntPtr lpBuffer, uint nSize, ref uint lpNumberOfBytesRead); [DllImport("Kernel32.dll")]
public static extern int CloseHandle(int handle); public void game()
{
const int PROCESS_VM_READ = 16;
int pid=0;
GetWindowThreadProcessId(Phandle,ref pid);
pro2=OpenProcess(PROCESS_VM_READ, false,pid);
textBox2.Text = pro2.ToString();
textBox4.Text = pid.ToString();
timer2.Enabled = true;
} public Form1()
{
InitializeComponent();
} int Phandle,pro2;
//uint pro2;
private void button1_Click(object sender, EventArgs e)
{
} private void Form1_Load(object sender, EventArgs e)
{
} private void timer1_Tick(object sender, EventArgs e)
{
Phandle = FindWindow("Sword3 Class", null);
if (Phandle != 0)
{
label1.Text = "游戏运行!";
game();
textBox1.Text = Phandle.ToString();
timer1.Interval=10000;
}
else
{
label1.Text = "游戏未运行!";
timer1.Interval=2000;
}
} private void textBox1_TextChanged(object sender, EventArgs e)
{ } private void timer2_Tick(object sender, EventArgs e)
{
byte[] vBuffer = new byte[4];
IntPtr vBytesAddress = Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0); // 得到缓冲区的地址
uint vNumberOfBytesRead = 0;
ReadProcessMemory((uint)pro2, (IntPtr)0xc0890c0, vBytesAddress, (uint)vBuffer.Length, ref vNumberOfBytesRead);
int vInt = Marshal.ReadInt32(vBytesAddress);
textBox5.Text = vInt.ToString();
} private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
CloseHandle(pro2);
}
}
}
不知道是哪不对?帮我看看吧using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
[DllImport("User32.dll")]
public static extern int FindWindow(string s,string ss); [DllImport("Kernel32.dll")]
public static extern int OpenProcess(int dwDesiredAccess, bool bInheritHandle,int dwProcessId); [DllImport("user32.dll",EntryPoint = "GetWindowThreadProcessId")]
public static extern int GetWindowThreadProcessId(int hWnd,ref int lpdwProcessId); [DllImport("kernel32.dll")]
static extern bool ReadProcessMemory(uint hProcess,IntPtr lpBaseAddress, IntPtr lpBuffer, uint nSize, ref uint lpNumberOfBytesRead); [DllImport("Kernel32.dll")]
public static extern int CloseHandle(int handle); public void game()
{
const int PROCESS_VM_READ = 16;
int pid=0;
GetWindowThreadProcessId(Phandle,ref pid);
pro2=OpenProcess(PROCESS_VM_READ, false,pid);
textBox2.Text = pro2.ToString();
textBox4.Text = pid.ToString();
timer2.Enabled = true;
} public Form1()
{
InitializeComponent();
} int Phandle,pro2;
//uint pro2;
private void button1_Click(object sender, EventArgs e)
{
} private void Form1_Load(object sender, EventArgs e)
{
} private void timer1_Tick(object sender, EventArgs e)
{
Phandle = FindWindow("Sword3 Class", null);
if (Phandle != 0)
{
label1.Text = "游戏运行!";
game();
textBox1.Text = Phandle.ToString();
timer1.Interval=10000;
}
else
{
label1.Text = "游戏未运行!";
timer1.Interval=2000;
}
} private void textBox1_TextChanged(object sender, EventArgs e)
{ } private void timer2_Tick(object sender, EventArgs e)
{
byte[] vBuffer = new byte[4];
IntPtr vBytesAddress = Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0); // 得到缓冲区的地址
uint vNumberOfBytesRead = 0;
ReadProcessMemory((uint)pro2, (IntPtr)0xc0890c0, vBytesAddress, (uint)vBuffer.Length, ref vNumberOfBytesRead);
int vInt = Marshal.ReadInt32(vBytesAddress);
textBox5.Text = vInt.ToString();
} private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
CloseHandle(pro2);
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货