public void WriteInt(int addr, int value, bool addToBase = false)
{
if (addToBase)
addr += (int) this.baseAddress;
this.WriteMem(addr, 4, BitConverter.GetBytes(value));
}
public void WriteUInt(int addr, uint value, bool addToBase = false)
{
if (addToBase)
addr += (int) this.baseAddress;
this.WriteMem(addr, 4, BitConverter.GetBytes(value));
}
public void WriteFloat(int addr, float value, bool addToBase = false)
{
if (addToBase)
addr += (int) this.baseAddress;
this.WriteMem(addr, 4, BitConverter.GetBytes(value));
}
public void WriteBytes(int addr, byte[] data)
{
this.WriteMem(addr, data.Length, data);
}
public void WriteString(int addr, string s, int len)
{
this.WriteMem(addr, len, Encoding.ASCII.GetBytes(s.ToCharArray()));
}
[DllImport("kernel32.dll")]
private static void WriteProcessMemory(IntPtr hProcess, IntPtr baseAddress, byte[] buffer, int size, int bytesRead);
private void WriteMem(int addr, int size, byte[] buf)
{
MemoryManager.WriteProcessMemory(this.processHandle, (IntPtr) addr, buf, size, 0);
}
[DllImport("kernel32")]
public static uint VirtualAllocEx(IntPtr hProcess, uint dwAddress, int nSize, uint dwAllocationType, uint dwProtect);
[DllImport("kernel32")]
public static bool VirtualFreeEx(IntPtr hProcess, uint dwAddress, int nSize, uint dwFreeType);
[DllImport("user32.dll")]
public static IntPtr GetForegroundWindow();
}