Hello, I made a simple code and I can not get the mana / health of the character.
I'll post the code:
Code:
unit uPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, PsApi;
type
TForm1 = class(TForm)
Button1: TButton;
lbHealth: TLabel;
lbMana: TLabel;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Offset: Integer;
PH: THandle;
PID, Thid: Dword;
TibiaH: THandle;
implementation
{$R *.dfm}
uses uAddress;
{ Função para pegar a base do endereço }
function GetTibiaBaseAddress(ProcessID: Cardinal): Pointer;
var
Modules: Array of HMODULE;
cbNeeded, i: Cardinal;
ModuleInfo: TModuleInfo;
ModuleName: Array [0 .. MAX_PATH] of Char;
PHandle: THandle;
begin
Result := nil;
SetLength(Modules, 1024);
PHandle := OpenProcess(PROCESS_QUERY_INFORMATION + PROCESS_VM_READ, FALSE,
ProcessID);
if (PHandle <> 0) then
begin
EnumProcessModules(PHandle, @Modules[0], 1024 * SizeOf(HMODULE),
cbNeeded);
SetLength(Modules, cbNeeded div SizeOf(HMODULE));
for i := 0 to Length(Modules) - 1 do
begin
GetModuleBaseName(PHandle, Modules[i], ModuleName, SizeOf(ModuleName)
);
if AnsiCompareText('Tibia.exe', ModuleName) = 0 then
begin
GetModuleInformation(PHandle, Modules[i], @ModuleInfo, SizeOf
(ModuleInfo));
Result := ModuleInfo.lpBaseOfDll;
CloseHandle(PHandle);
Exit;
end;
end;
end;
end;
{ Função para ler os endereços de memoria }
function ReadInteger(Address: Integer): Integer;
var
value: Integer;
ler: Dword;
begin
Thid := GetWindowThreadProcessId(TibiaH, @PID);
PH := OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
ReadProcessMemory(PH, Ptr(Address), @value, 4, ler);
Result := value;
end;
{ Função para pegar o ProcessID }
function ProcessID: Integer;
begin
TibiaH := FindWindow('TibiaClient', nil);
Thid := GetWindowThreadProcessId(TibiaH, @PID);
PH := OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
Result := PID;
end;
//Função para ler o health do player.
function PlayerHealth: Integer;
var
HP: Integer;
uXor: Integer;
begin
Offset := Integer(GetTibiaBaseAddress(ProcessID));
HP := ReadInteger((adrMyHP + Offset) - $400000);
uXor := ReadInteger((adrXOR + Offset) - $400000);
Result := HP xor uXor;
end;
//Função para ler a mana do player.
function PlayerMana: Integer;
var
Mana: Integer;
uXor: Integer;
begin
Offset := Integer(GetTibiaBaseAddress(ProcessID));
Mana := ReadInteger((adrMyMana + Offset) - $400000);
uXor := ReadInteger((adrXOR + Offset) - $400000);
Result := Mana xor uXor;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
lbHealth.Caption := 'Health: ' + IntToStr(PlayerHealth);
lbMana.Caption := 'Mana: ' + IntToStr(PlayerMana);
end;
end.
The addresses used were:
Code:
adrXor = $57E1D0;
adrMyHP = $713000;
adrMyMana = $57E224;
Who can help me understand where I am going wrong. Thank you!
I took also the source of one of NeoBot Cloner to study, to see if I can decipher this error.