static void Write(int Address, object Val, object MemType)
{
int Index = Array.IndexOf(new object[] { typeof(byte), typeof(int), typeof(uint), typeof(float), typeof(double) }, MemType);
if (Index == -1) return;
uint _Old = 0, tmp;
byte[] Bytes = null;
switch (Index)
{
case 0:
Bytes = BitConverter.GetBytes(Convert.ToByte(Val));
break;
case 1:
Bytes = BitConverter.GetBytes(Convert.ToInt32(Val));
break;
case 2:
Bytes = BitConverter.GetBytes(Convert.ToUInt32(Val));
break;
case 3:
Bytes = BitConverter.GetBytes(Convert.ToSingle(Val));
break;
case 4:
Bytes = BitConverter.GetBytes(Convert.ToDouble(Val));
break;
}
if (Bytes == null) return;
VirtualProtectEx(ProHandle, new IntPtr(Address), Bytes.Length, 0x40, out _Old);
Marshal.Copy(Bytes, 0, new IntPtr(Address), Bytes.Length);
VirtualProtectEx(ProHandle, new IntPtr(Address), Bytes.Length, _Old, out tmp);
}
static void WriteByte(int Address, byte Val)
{
Write(Address, Val, typeof(byte));
}
static void WriteInt(int Address, int Val)
{
Write(Address, Val, typeof(int));
}
WriteInt(0x4000000, 10);