 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Radeyo How do I cheat?
Reputation: 0
Joined: 22 Feb 2012 Posts: 1
|
Posted: Thu Feb 23, 2012 12:20 am Post subject: [C#/Help] Editing Memory via Pointers (ProcessMemoryReader) |
|
|
After creating trainers using the CheatEngine trainer generator for so long, I wanted to finally jump in to making the trainers in C# instead of CE for more flexibility. Here is my problem.
I have a list of pointers in Cheat Engine. In C#, I'm loading the game process via ProcessMemoryReaderLib like this,
| Code: |
using ProcessMemoryReaderLib;
ProcessMemoryReader Reader = new ProcessMemoryReader();
Process[] gameclient = Process.GetProcessesByName("gameclient");
ProcessModule mainModule;
int gameBaseAddress;
int bytesReadSize;
Reader.ReadProcess = gameclient[0];
Reader.OpenProcess();
mainModule = gameclient[0].MainModule;
gameBaseAddress = (int)mainModule.BaseAddress; |
Everything loads up fine. I can get the address of the value from the pointers and use the address directly in the code like so,
| Code: |
int pointer1 = BitConverter.ToInt32(Reader.ReadProcessMemory((IntPtr)(0x2528131C), 4, out bytesReadSize), 0);
|
The value returns correctly, and I'm able to edit using Reader.WriteProcessMemory. All good!
Well obviously memory addresses change when you restart the game, which is why we use pointers. My problem however is that I can not seem to get my program to load the correct pointer addresses.
In my code, gameBaseAddress returns to "0x00400000". However, in Cheat Engine, when I load up the pointer and change the address to "gameclient_release.exe", the base address it gives me is different from the one I get in my code. Here is a picture to explain it better.
| Code: | | http :// screensnapr. com/v/JruBLG.png |
(remove the spaces)
My question is how can I go from using the direct address to using pointers to make my program able to load the correct values every time the game is restarted?
I tried baseAddress + 0x[pointer] + 0x[offset] but it isn't matching what I'm getting in Cheat Engine.
Thanks for the help!
Edit-
So using this in Cheat Engine,
Address of Pointer: 00400000+00493dd8
Offset: 5f4
.. brings me to the correct pointer, however using the same code in my program,
| Code: | int pointer1 = BitConverter.ToInt32(Reader.ReadProcessMemory((IntPtr)(0x00400000 + 0x00493dd8 + 0x5f4), 4, out bytesReadSize), 0);
byte[] pointer2 = BitConverter.GetBytes(pointer1);
float value = BitConverter.ToSingle(pointer2, 0); |
The value returns as a zero.
Any ideas?
Edit again-
Found out the issue. Instead of the pointer updating the correct value, its updating the following address,
00400000+4943CC
Any tips on how to make the pointer update the proper address? Right now its updating the memory region instead of using the pointer at the memory region.
|
|
| Back to top |
|
 |
Pingo Grandmaster Cheater
Reputation: 8
Joined: 12 Jul 2007 Posts: 571
|
Posted: Thu Feb 23, 2012 8:16 am Post subject: |
|
|
| Code: | Address of Pointer: 00400000+00493dd8
Offset: 5f4 |
Try
| Code: | //Read the value of the base
int _Base = BitConverter.ToInt32(Reader.ReadProcessMemory((IntPtr)(0x893DD8), 4, out bytesReadSize), 0);
//Add offset for pointer location
int _Address = BitConverter.ToInt32(Reader.ReadProcessMemory((IntPtr)(_Base + 0x5F4), 4, out bytesReadSize), 0); |
Your pointer
| Code: |
int pointer1 = BitConverter.ToInt32(Reader.ReadProcessMemory((IntPtr)(0x00400000 + 0x00493dd8 + 0x5f4), 4, out bytesReadSize), 0); |
You would only see the value at address 8943CC.
These added 0x00400000 + 0x00493dd8 + 0x5f4
The value of 0x00400000 + 0x00493dd8 is your base for the pointer, then you just add the offset to either read or write to it.
Using your process handle you could make something like this
| Code: | //Read
public byte[] ReadBytes(int _Addy, int _Size)
{
byte[] _buffer = new byte[_Size];
ReadProcessMemory(gameclient[0].Handle, _Addy, _buffer, _Size, 0);
return _buffer;
}
public float ReadFloat(int _Addy)
{
return BitConverter.ToSingle(ReadBytes(_Addy, 4), 0);
}
public int ReadInt(int _Addy)
{
return BitConverter.ToInt32(ReadBytes(_Addy, 4), 0);
}
//Write
public void WriteBytes(int _Addy, byte[] _Bytes)
{
WriteProcessMemory(gameclient[0].Handle, _Addy, _Bytes, _Bytes.Length, 0);
}
public void WriteInt(int _Addy, int _Val)
{
WriteBytes(_Addy, BitConverter.GetBytes(_Val));
}
public void WriteFloat(int _Addy, float _Val)
{
WriteBytes(_Addy, BitConverter.GetBytes(_Val));
} |
Now your code would be easier to read.
| Code: | int _Base = ReadInt(0x893DD8);
float _Value = ReadFloat(_Base + 0x5F4);
or
WriteFloat(_Base + 0x5F4,10);//That would write the value 10 to your pointer |
_________________
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|