日期:2014-05-18 浏览次数:20878 次
/// <summary> /// 从指定地址读取数据 /// </summary> /// <param name="address">读取数据的地址</param> /// <returns>返回读取的数值</returns> public int ReadValueFromAddress(int pid, int address) { IntPtr handle = CheatAPI.OpenProcess(CheatAPI.PROCESS_ALL_ACCESS, false, pid); byte[] buffer = new byte[4]; IntPtr byteAddress = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); //获取缓冲区地址 bool read = CheatAPI.ReadProcessMemory(handle, (IntPtr)address, byteAddress, 4, IntPtr.Zero); CheatAPI.CloseHandle(handle); return Marshal.ReadInt32(byteAddress); } /// <summary> /// 向指定地址写数据 /// </summary> /// <param name="address">写数据的地址</param> /// <param name="name">是修改的名称</param> /// <param name="StartOrNo">修改还是还原 true修改 false 还原 </param> /// <returns>写入成功返回true</returns> public bool WriteValueToAddress(int pid, string name, bool StartOrNo) { //无限 修改 开启 try { IntPtr handle = CheatAPI.OpenProcess(CheatAPI.PROCESS_ALL_ACCESS, false, pid); if (StartOrNo) { foreach (DevilClass item in ChangeList) { string ne = item.CheatName.Substring(0, item.CheatName.IndexOf('_')); if (ne == name) { CheatAPI.WriteProcessMemory(handle, (IntPtr)item.Address, item.Data, item.Data.Length, IntPtr.Zero); } } if (name == "无限魔人") { int ad1 = ReadValueFromAddress(pid, ReadValueFromAddress(pid, 0x00e558b8) + 0x24); CheatAPI.WriteProcessMemory(handle, (IntPtr)(ad1 + 0x1f24), new byte[] { 0x00, 0x40, 0x1c, 0x46 }, 4, IntPtr.Zero); //魔法量 CheatAPI.WriteProcessMemory(handle, (IntPtr)(ad1 + 0x1f28), new byte[] { 0x00, 0x40, 0x1c, 0x46 }, 4, IntPtr.Zero);//格子数 } if (name == "无限灾厄") { int ad2 = ReadValueFromAddress(pid, ReadValueFromAddress(pid, 0x00e558b8) + 0x24); CheatAPI.WriteProcessMemory(handle, (IntPtr)(ad2 + 0x151f4), new byte[] { 0x00, 0x34, 0x1c, 0x46 }, 4, IntPtr.Zero); } if (name == "瞬间加速") { int ad3 = ReadValueFromAddress(pid, ReadValueFromAddress(pid, 0x00e558b8) + 0x24); CheatAPI.WriteProcessMemory(handle, (IntPtr)(ad3 + 0x2834), new byte[] { 0x23, 0xFF, 0x61, 0x43 }, 4, IntPtr.Zero); } if (name == "无限RG") { int ad4 = ReadValueFromAddress(pid, ReadValueFromAddress(pid, 0x00E558B8) + 0x24); CheatAPI.WriteProcessMemory(handle, (IntPtr)(ad4 + 0x14dac), new byte[] { 0x46, 0x65 }, 4, IntPtr.Zero); } } else { foreach (DevilClass item in RecoverList) { string na=item.CheatName.Substring(3, item.CheatName.IndexOf('_') - 3); if (na == name)