As you're using C#, i'm going to post my code.
I've create a Class just to keep the methods and functions to read the memory.
Code:
static class Memoria
{
public static byte[] ReadBytes(IntPtr handle, long address, uint bytesToRead)
{
IntPtr ptrBytesRead;
byte[] buffer = new byte[bytesToRead];
WinApi.ReadProcessMemory(handle, new IntPtr(address), buffer, bytesToRead, out ptrBytesRead);
return buffer;
}
public static byte ReadByte(IntPtr handle, long address)
{
return ReadBytes(handle, address, 1)[0];
}
public static short ReadInt16(IntPtr handle, long address)
{
return BitConverter.ToInt16(ReadBytes(handle, address, 2), 0);
}
public static ushort ReadUInt16(IntPtr handle, long address)
{
return BitConverter.ToUInt16(ReadBytes(handle, address, 2), 0);
}
public static string ReadString(IntPtr handle, long address, uint length)
{
if (length > 0)
{
byte[] buffer;
buffer = ReadBytes(handle, address, length);
return System.Text.ASCIIEncoding.Default.GetString(buffer).Split(new Char())[0];
}
else
{
string s = "";
byte temp = ReadByte(handle, address++);
while (temp != 0)
{
s += (char)temp;
temp = ReadByte(handle, address++);
}
return s;
}
}
}
Then, on my main form, i've created a Client class, to save some data:
Code:
public class Cliente
{
public int ID { get; set; }
public int Base { get; set; }
public IntPtr processHandle { get; set; }
public int LerMemoria(int endereco)
{
return ((int)Memoria.ReadUInt16(processHandle, Base + endereco));
}
}
FInally, on my main form, i search for the Tibia Client and save it's ID, base address and handle
Code:
private void EscolheCliente()
{
foreach (Process p in Process.GetProcesses())
{
StringBuilder classname = new StringBuilder();
WinApi.GetClassName(p.MainWindowHandle, classname, 12);
if (classname.ToString().Equals("TibiaClient", StringComparison.CurrentCultureIgnoreCase))
{
if (p.MainModule.FileVersionInfo.FileVersion == "9.10") // Here you set the Tibia Version
{
client = new Cliente();
client.processHandle = WinApi.OpenProcess(WinApi.PROCESS_ALL_ACCESS, 0, (uint)p.Id);
client.ID = p.Id;
client.Base = (int)p.MainModule.BaseAddress;
return;
}
}
}
}
And then, i read the addresses like this:
Code:
int LookId = 0x5B34B4;
client.LerMemoria(LookId);