Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace TibiaInfo
{
public partial class Form1 : Form
{
#region DLLImports
//Import WindowsAPI function to read process memory
[DllImport("kernel32.dll")]
public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr IpBaseAddress, [In, Out]byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
#endregion
#region Global Vars
public static UInt32 Base = 0; // Base Address
public static Process Tibia = null; // Tibia process
Int32 HealthPointsL = 0x7B6EF0;
Int32 XorL = 0x94C000;
//Player Item Slot Address
UInt32 RingSlotL = 0x5DA548;
UInt32 BootsSlotL = 0x5DA554;
UInt32 LegsSlotL = 0x5DA560;
UInt32 WeaponSlotL = 0x5DA56C;
UInt32 ShieldSlotL = 0x5DA578;
UInt32 ArmourSlotL = 0x5DA584;
UInt32 BagSlotL = 0x5DA590;
UInt32 NecklessSlotL = 0x5DA59C;
UInt32 HelmetSlotL = 0x5DA5A8;
UInt32 HandSlotL = 0x5DA53C;
#endregion
#region Init Code
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Process[] TibiaProcess = Process.GetProcessesByName("Tibia");
Tibia = TibiaProcess[0];
Base = Convert.ToUInt32(Tibia.MainModule.BaseAddress.ToInt32());
//TODO: Fills in combobox (cmbTibiaClient) with all running tibia clients, this will be used later on for muticlient support
Dictionary<string, Process> filterItems = new Dictionary<string, Process>();
for (int x = 0; x < TibiaProcess.Count(); x++)
{
filterItems.Add("[" + TibiaProcess[x].Handle.ToString() + "] " + TibiaProcess[x].MainModule.FileName.ToString(), TibiaProcess[x]);
}
this.cmbTibiaClient.DataSource = new BindingSource(filterItems, null);
this.cmbTibiaClient.DisplayMember = "Key";
this.cmbTibiaClient.ValueMember = "Value";
}
#endregion
#region Main Code
public static byte[] ReadBytes(IntPtr Handle, Int64 Address, uint BytesToRead)
{
IntPtr ptrBytesRead;
//Declare a bugger, this is the no mans land in which the information travels to get from the memory address to our programs memory
byte[] buffer = new byte[BytesToRead];
ReadProcessMemory(Handle, new IntPtr(Address), buffer, BytesToRead, out ptrBytesRead);
return buffer;
}
//Convert the contents of "buffer", or any other byte variable to a usable Int32
public static int ReadInt32(IntPtr Handle, long Address)
{
return BitConverter.ToInt32(ReadBytes(Handle, Address, 4), 0);
}
private void button1_Click(object sender, EventArgs e)
{
scan();
}
private void scan()
{
//MessageBox.Show(Convert.ToString(ReadInt32(Tibia.Handle, 0x5DA56C + Base))); //2752512
this.txtRing.Text = Convert.ToString(ReadInt32(Tibia.Handle, RingSlotL + Base));
this.txtBoots.Text = Convert.ToString(ReadInt32(Tibia.Handle, BootsSlotL + Base));
this.txtLegs.Text = Convert.ToString(ReadInt32(Tibia.Handle, LegsSlotL + Base));
this.txtWeapon.Text = Convert.ToString(ReadInt32(Tibia.Handle, WeaponSlotL + Base));
this.txtShield.Text = Convert.ToString(ReadInt32(Tibia.Handle, ShieldSlotL + Base));
this.txtArmour.Text = Convert.ToString(ReadInt32(Tibia.Handle, ArmourSlotL + Base));
this.txtBag.Text = Convert.ToString(ReadInt32(Tibia.Handle, BagSlotL + Base));
this.txtNeckless.Text = Convert.ToString(ReadInt32(Tibia.Handle, NecklessSlotL + Base));
this.txtHelmet.Text = Convert.ToString(ReadInt32(Tibia.Handle, HelmetSlotL + Base));
this.txtHand.Text = Convert.ToString(ReadInt32(Tibia.Handle, HandSlotL + Base));
Int32 Xor = ReadInt32(Tibia.Handle, Base - 0x400000 + XorL);
txtxorKey.Text = Convert.ToString(Xor);
Int32 HealthPointsEncrypted = ReadInt32(Tibia.Handle, Base - 0x400000 + HealthPointsL);
txtlifeEncrypted.Text = Convert.ToString(HealthPointsEncrypted);
Int32 HealthPointsDecrypted = HealthPointsEncrypted ^ Xor;
txtlifeDecrypted.Text = Convert.ToString(HealthPointsDecrypted);
}
private void cmbTibiaClient_SelectedIndexChanged(object sender, EventArgs e)
{
KeyValuePair<string, Process> selectProcess = (KeyValuePair<string, Process>)cmbTibiaClient.SelectedItem;
Tibia = (Process)selectProcess.Value;
Base = Convert.ToUInt32(Tibia.MainModule.BaseAddress.ToInt32());
}
#endregion
}
}