read the names of the characters in delphi

05/07/2012 05:03 kilua_xxxx#1
function ReadPlayerName (hProcess, data: DWord): string;
var
i, rw: DWord;
ch: WideChar;
wch: array [0 .. 255] of WideChar;
str: string;
begin
i:= 0;
repeat
ReadProcessMemory (hProcess, ptr (data),@ch,2,rw);
data:= data +2;
wch [i]:= ch;
inc (i);
until
(Ord (ch) = 0) or (i>= 255);
i:= 0;
str:='';
repeat
str:= str + wch [i];
inc (i);
until
wch [i]='';
result:= str;
end;

...
var
hp2,hpmax2,mp2,mpmax2,nama: integer;
whp2,whpmax2,wmp2,wmpmax2,nob2,wnama2: dword;
begin
ReadProcessMemory (hProses, Pointer($b29184), @wnama, sizeof

(wnama),NoB);
//ReadProcessMemory (hProses, Pointer($1c), @wnama, sizeof(wnama),

NoB);
ReadProcessMemory (hProses, Pointer($34), @wnama, sizeof(wnama),

NoB);
ReadProcessMemory(hProses, Pointer($638), @nama, sizeof(nama), NoB);

label6.Caption:=ReadPlayerName(hproses,wnama);
( I just got a character like this = 깤 ¡)

how to get the character's name correctly

thanks for the help
05/07/2012 13:26 Sᴡoosh#2
AAhhhh use code tags next time please....

Some things.

First of - I don't think you know what you're doing :)

You aren't resolving any part of the whole pointer chain - you need to add your prior value to the new offset - that will be the chain. Your code just overwrites each value.

Base + 1C + 34 + 638 + 0

Then - I think you where thinking the right way, but kind of messed up :) Yes, Widestring is two bytes, so you need to read two bytes of memory - but this x length!

A better/much simpler way of doing this would be the following ( 1:1 copy from my bot) :

Code:
function THostchar.Name: String;
var
  eax, written, Base: cardinal;
  TName : array [0..49] of widechar;
begin

  ReadProcessMemory(Self.Handle, ptr(self.Offsets.Addresses_base_Address), @eax, 4, written);
  ReadProcessMemory(Self.Handle, ptr(eax + $1C), @eax, 4, written);
  ReadProcessMemory(Self.Handle, ptr(eax + self.Offsets.Structural_Character), @eax, 4, written);
  ReadProcessMemory(Self.Handle, ptr(eax + self.Offsets.Character_Name), @eax, 4, written);
  ReadProcessMemory(Self.Handle, ptr(eax), @Tname, 100, written);

  Result := WideCharToString(TName);

end;
And even 50 characters is overkill, but 256!? Who has that long of a name :D

So, copy 100 bytes of data into an array of WideChar(you where correct there), then just cast this into a string - quite simple, you where thinking too complex I think :)

Cheers
05/08/2012 11:58 kilua_xxxx#3
Quote:
Originally Posted by Sᴡoosh View Post
AAhhhh use code tags next time please....

Some things.

First of - I don't think you know what you're doing :)

You aren't resolving any part of the whole pointer chain - you need to add your prior value to the new offset - that will be the chain. Your code just overwrites each value.

Base + 1C + 34 + 638 + 0

Then - I think you where thinking the right way, but kind of messed up :) Yes, Widestring is two bytes, so you need to read two bytes of memory - but this x length!

A better/much simpler way of doing this would be the following ( 1:1 copy from my bot) :

Code:
function THostchar.Name: String;
var
  eax, written, Base: cardinal;
  TName : array [0..49] of widechar;
begin

  ReadProcessMemory(Self.Handle, ptr(self.Offsets.Addresses_base_Address), @eax, 4, written);
  ReadProcessMemory(Self.Handle, ptr(eax + $1C), @eax, 4, written);
  ReadProcessMemory(Self.Handle, ptr(eax + self.Offsets.Structural_Character), @eax, 4, written);
  ReadProcessMemory(Self.Handle, ptr(eax + self.Offsets.Character_Name), @eax, 4, written);
  ReadProcessMemory(Self.Handle, ptr(eax), @Tname, 100, written);

  Result := WideCharToString(TName);

end;
And even 50 characters is overkill, but 256!? Who has that long of a name :D

So, copy 100 bytes of data into an array of WideChar(you where correct there), then just cast this into a string - quite simple, you where thinking too complex I think :)

Cheers
thanks, it worked
05/08/2012 17:53 amineurin#4
4 times memory read for 1 name ?
or did i miss something, im not familiar with delphi :D

Quote:
;autoit :D
Global $NAME = _MemoryRead(_MemoryRead($CHAR_DATA_BASE + $OFFSET_NAME, $PROCESS_INFORMATION), $PROCESS_INFORMATION, 'wchar[30]')
2 memory read should do the same, or ?
05/08/2012 19:02 Sᴡoosh#5
Quote:
Originally Posted by amineurin View Post
4 times memory read for 1 name ?
or did i miss something, im not familiar with delphi :D



2 memory read should do the same, or ?
The process of reading game's memory is language independant - offset chains need to be traversed anyways.

And about your script :

$CHAR_DATA_BASE needs to be populated somewhere to, hm? ;) So there's your other two (three if you use "real" base) memory reads.
05/08/2012 21:48 Interest07#6
Quote:
Originally Posted by Sᴡoosh View Post
The process of reading game's memory is language independant - offset chains need to be traversed anyways.

And about your script :

$CHAR_DATA_BASE needs to be populated somewhere to, hm? ;) So there's your other two (three if you use "real" base) memory reads.
As far as I know the player pointer should remain constant at least until you log out. So it is possible to save on some memory reading there. It's prolly not really much improvement, but in theory it could be. I personally don't bother with it since it's all premature optimization, but some find great pleasure in optimizing stuff like that :)
05/08/2012 22:40 Sᴡoosh#7
Yeah, that's stuff which people won't even notice if you optimize. Some people don't stop bot while switching characters, for whatever reason, so this is the safest way to go in my opinion.

Yepp, we all know somebody who is a crazy optimizator.

*Looking at someone specifically*
05/09/2012 00:39 dumbfck#8
Can't be me... I barely ever finish anything, let alone optimise it lol :D
05/09/2012 11:55 Interest07#9
Quote:
Originally Posted by dumbfck View Post
Can't be me... I barely ever finish anything, let alone optimise it lol :D
lmao, I know that feeling :p

Optimizing is overrated, at least with small programs like bots :rolleyes:
05/10/2012 07:02 kilua_xxxx#10
Now I have a problem, how to get target name ?
05/10/2012 09:48 Sᴡoosh#11
Read monster array, get WID of closest named monster, and target that. Sorry, no source this time, others will need to decide about posting theirs - I still want to sell stuff :D
05/10/2012 10:14 Interest07#12
Quote:
Originally Posted by kilua_xxxx View Post
Now I have a problem, how to get target name ?
get your current targetId from your player struct and compare that to the ids of the mobs around you.