Hello there, i am trying to make a trainer for GTA:SA and i have some problems:
First of all, i am newbie at writing and reading memory, but not so much at c#, i mean i know my way around. Here are my methods:
ReadMemory, WriteMemory, DecToHex, HexToDex
Code:
public byte[] ReadMemoryAtAdress(IntPtr MemoryAddress, uint bytesToRead)
{
byte[] buffer = new byte[bytesToRead];
IntPtr ptrBytesRead;
ReadProcessMemory(handleProcess, MemoryAddress, buffer, bytesToRead, out ptrBytesRead);
// bytesRead = ptrBytesRead.ToInt32();
return buffer;
}
public int WriteMemoryAtAdress(IntPtr MemoryAddress, byte[] bytesToWrite)
{
IntPtr ptrBytesWritten;
WriteProcessMemory(handleProcess, MemoryAddress, bytesToWrite, (uint)bytesToWrite.Length, out ptrBytesWritten);
return ptrBytesWritten.ToInt32();
}
public static string DecToHex(int s)
{
return s.ToString("X");
}
public static int HexToDec(string hexValue)
{
return int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
}
Ok. First Problem is that whe i try to activate a cheat like HESOYAM thorugh the memory address: 0x969133, it doesn't work, but if i try reading the memory it says that the value is 1 but nothing happens. BTW: If is get or set the money(0xB7CE50) it works.
Code:
int addr = 0x969133
byte[] val = = BitConverter.GetBytes(1);
WriteMemoryAtAdress((IntPtr)addr , val);
The second problem is when i try to get the player's health. When full hp, i get 1120000000(aprox), but if i lose hp and write that value(1120000000) in memory it works, i get full hp. Isn't there any way to get the hp like float? or the real value? Already tried BitConverter.ToSingle, i get 4,321E3 = nonsense.
Code:
int pointeraddr = 0xB6F5F0;
byte[] valueOut = ReadMemoryAtAdress((IntPtr)pointeraddr, 4);
int value = BitConverter.ToInt32(valueOut, 0);
string newAddr = DecToHex(value);
IntPtr mpAddr = (IntPtr)HexToDec(newAddr);
IntPtr mpAddr2 = IntPtr.Add(mpAddr, 0x540);
int newmpAddr = mpAddr2.ToInt32();
byte[] value2 = ReadMemoryAtAdress((IntPtr)newmpAddr, 4);
int value2Out = BitConverter.ToInt32(value2,0);
MessageBox.Show(value2Out.ToString());
Thank You!