Deprecated: The behavior of unparenthesized expressions containing both '.' and '+'/'-' will change in PHP 8: '+'/'-' will take a higher precedence in /home/iano/public_html/tpforums-vb5/forum/includes/class_core.php on line 5842

PHP Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: Use of undefined constant MYSQL_BOTH - assumed 'MYSQL_BOTH' (this will throw an Error in a future version of PHP) in ..../includes/init.php on line 165

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 588

PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in ..../includes/functions_navigation.php on line 612

PHP Warning: Use of undefined constant archive_postsperpage - assumed 'archive_postsperpage' (this will throw an Error in a future version of PHP) in ..../archive/index.php on line 456
C++ Read creature name from ID [Archive] - Forums

PDA

View Full Version : C++ Read creature name from ID



Arkamek
09-14-2014, 07:05 PM
Hello i have small problem, because i don't know how to read any info about player from ID.
i define creature id by:


#define CONTEXT_MENU_CREATUREID 0x792E54;

for example i have variable pid with creatureid:


DWORD* pid = (DWORD*)CONTEXT_MENU_CREATUREID;

but how can i read creature name from this?


// Tibia 8.54
Thanks

wgrzelak
09-14-2014, 08:23 PM
You need add offset for name
probably


CONTEXT_MENU_CREATUREID + 0x4

Arkamek
09-14-2014, 08:52 PM
Don't work ;/

Milice
09-15-2014, 11:17 PM
Shouldn't 0x4 be 0x04 ? wouldn't it count it as 0x40 otherwise?

XtrmJash
09-15-2014, 11:31 PM
Shouldn't 0x4 be 0x04 ? wouldn't it count it as 0x40 otherwise?

Nope. 0x simply says that the following number is hexidecimal. The leading 0 is typically added for situations where you have addresses of varying lengths, to make code look pretty, e.g:



Address1 = 0x0005
Address2 = 0x1234


Looks nicer than



Address1 = 0x5
Address2 = 0x1234


Regarding reading creature name using CID, this is how it's done in the battle list, displayed in some sort of C# pseudocode mashup:



int playerCID = GetCID();
int myCreatureIndex = 0;

for (int i = 0; i < battleListMax; i++)
{
int currentCID = ReadInt(battleListStart + battleListStep * i);
if (currentCID == playerCID)
{
myCreatureIndex = i;
break;
}
}

// Do whatever here, e.g:
string playerName = ReadString(battleListStart + battleListStep * i + 0x4);


It now strikes me that you're using an injected dll, so you'll need to replace all calls to ReadInt etc to casting.... That shit is too confusing for me at this time of night, but basically you just need to do what you have already, but casting to type of wchar_t * as opposed to DWORD *, or whatever char array you'll be using (I can't remember).

szulak
09-16-2014, 06:32 AM
for (int i = 0; i++; i < battleListMax)




This will cause infinite loop.

XtrmJash
09-16-2014, 07:33 AM
This will cause infinite loop.

Ooooooops.

Arkamek
09-16-2014, 02:57 PM
ok thanks, i will check in night and msg if it working

Arkamek
09-16-2014, 07:49 PM
void gadaj()
{
/*
This i have defined in external file
#define SELF_EXPERIENCE 0x635F04
#define SELFID (SELF_EXPERIENCE + 12)
*/

int playerCID = SELFID;
int myCreatureIndex = 0;
for (int i = 0; i < MaxCreatures; i++)
{
int currentCID = ReadMemoryInt(FindWindow("ARKAMECZEK ", NULL),(BattlelistBegin + BattlelistStep * i),sizeof(int32_t));
if (currentCID == playerCID)
{
myCreatureIndex = i;

break;
}
}
char value[32];
ReadMemoryChars(FindWindow("ARKAMECZEK ", NULL),(BattlelistBegin + BattlelistStep * myCreatureIndex + 0x4),value,32);
string str = string(value);
Say(0x01, const_cast<char*>(str.c_str()));
}

+ reading functions:


inline int ReadMemoryInt(HWND h, int address, int size)
{
int ret = 0;
ReadProcessMemory(h, (LPVOID)address, &ret, size, 0);
return ret;
}

inline void ReadMemoryChars(HWND h, int address, char* ret, int size)
{
ReadProcessMemory(h, (LPVOID)address, &ret, size, 0);
}

resolut of this code is randomly:



21:45 Arkam: í
21:47 Arkam:
21:47 Arkam:


/\ Arkam is name ingame, i testing it on ContextMenu then resolut is empty [] :(

XtrmJash
09-16-2014, 08:56 PM
FindWindow("ARKAMECZEK ", NULL)

Is the clients class name ARKAMECZEK?

Arkamek
09-16-2014, 08:59 PM
yea, it's good i tested it in this script and its finding this window

Arkamek
09-17-2014, 02:01 AM
omg 4:00 am... anyway i made:

int readByte(int address, int byte)
{
int value;
if(ReadProcessMemory(processHandle, (LPVOID)address, &value, byte, NULL))
return value;
return 0;
}

and


HANDLE processHandle;
DWORD procId;
HWND hwnd;

hwnd = FindWindow("ARKAMECZEK ", NULL);
GetWindowThreadProcessId(hwnd, &procId);
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procId);
if(hwnd)
{
//start
int playerCID = SELFID;
int myCreatureIndex = 0;
for (int i = 1; i < MaxCreatures; i++)
{
int currentCID = readByte(BattlelistBegin + BattlelistStep * i, 4);
if (currentCID == readByte(playerCID,4))
{
myCreatureIndex = i;
break;
}
}

CloseHandle(processHandle);
}

and it working, but now i think how to make this what you said:

// Do whatever here, e.g:
string playerName = ReadString(battleListStart + battleListStep * i + 0x4);

maybe cuz im zombie now :D anyway, if you have any idea to do this msg. Thanks :)

//for test i made:


test = readByte(BattlelistBegin + BattlelistStep * myCreatureIndex, 4);
and its ok, i have right ID's of creatures, but how can i get name from that addresses?

XtrmJash
09-17-2014, 08:50 AM
omg 4:00 am... anyway i made:

int readByte(int address, int byte)
{
int value;
if(ReadProcessMemory(processHandle, (LPVOID)address, &value, byte, NULL))
return value;
return 0;
}

and


HANDLE processHandle;
DWORD procId;
HWND hwnd;

hwnd = FindWindow("ARKAMECZEK ", NULL);
GetWindowThreadProcessId(hwnd, &procId);
processHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procId);
if(hwnd)
{
//start
int playerCID = SELFID;
int myCreatureIndex = 0;
for (int i = 1; i < MaxCreatures; i++)
{
int currentCID = readByte(BattlelistBegin + BattlelistStep * i, 4);
if (currentCID == readByte(playerCID,4))
{
myCreatureIndex = i;
break;
}
}

CloseHandle(processHandle);
}

and it working, but now i think how to make this what you said:

maybe cuz im zombie now :D anyway, if you have any idea to do this msg. Thanks :)

//for test i made:


test = readByte(BattlelistBegin + BattlelistStep * myCreatureIndex, 4);
and its ok, i have right ID's of creatures, but how can i get name from that addresses?

Ahhh, I just read your last post and noticed you were passing the window handle not the process handle, sense made.

Regarding ReadString, you'll basically want to return a pointer to a char array, containing the address of the bytes you read.

Are you doing this from an injected DLL? Or are you doing it from a standalone console application or something? If it's injected, you really don't need to do all this ReadProcessMemory crap.

Arkamek
09-17-2014, 09:12 AM
yea Injected DLL, then how can i do it without readprocessmemory?

wgrzelak
09-17-2014, 09:22 AM
read


DWORD currentCID = *(DWORD *)(BattlelistBegin + BattlelistStep * i);

write


int new_id = 99999;
memcpy((LPVOID)(BattlelistBegin + BattlelistStep * i, new_id, 4);

Arkamek
09-17-2014, 09:41 AM
Thanks bro

void test()
{
int playerCID = SELFID;
int myCreatureIndex = 0;
for (int i = 1; i < MaxCreatures; i++)
{
DWORD currentCID = *(DWORD *)(BattlelistBegin + BattlelistStep * i);
if (currentCID == *(DWORD *)(playerCID))
{
//My character ID
myCreatureIndex = i;
break;
}
}
domin = *(DWORD *)(BattlelistBegin + BattlelistStep * myCreatureIndex);
}

Arkamek
09-17-2014, 10:21 AM
i trying make:

char domin[32];
domin[32] = *(char*)((char*)((BattlelistBegin + BattlelistStep * myCreatureIndex) + 0x04));
but don't work
result is 0/empty

wgrzelak
09-17-2014, 12:59 PM
i trying make:
but don't work
result is 0/empty



char* name = (char*)((BattlelistBegin + BattlelistStep * myCreatureIndex) + 0x04));

Arkamek
09-17-2014, 01:48 PM
Thanks Man!

Working code:



string tekst;



void dominik()
{
int playerCID = SELFID;
int myCreatureIndex = 0;
for (int i = 0; i < MaxCreatures; i++)
{
DWORD currentCID = *(DWORD *)(BattlelistBegin + BattlelistStep * i);
if (currentCID == *(DWORD *)(playerCID))
{
//My character ID
myCreatureIndex = i;
break;
}
}
char* name = (char*)((BattlelistBegin + BattlelistStep * myCreatureIndex) + 0x04);
tekst = name;
}


and result = "Arkam"

Thanks again :)
I have the last question now, how can i read level of character, because i can't find address from it.

wgrzelak
09-17-2014, 02:22 PM
the correct code


string SelfName()
{
int playerCID = SELFID;
for (int i = 0; i < MaxCreatures; i++)
{
DWORD currentCID = *(DWORD *)(BattlelistBegin + BattlelistStep * i);
if (currentCID == *(DWORD *)(playerCID))
{
return (char*)((BattlelistBegin + BattlelistStep * i) + 0x04);
}
}
return NULL;
}


about read level of character


http://youtu.be/NcZXDcrCZFA?t=24m13s

Arkamek
09-17-2014, 02:48 PM
Thanks, i have another question then :D

i have this:


string ContextTargetName()
{
for (int i = 0; i < MaxCreatures; i++)
{
DWORD currentCID = *(DWORD *)(BattlelistBegin + BattlelistStep * i);
if (currentCID == *(DWORD *)(CONTEXT_MENU_CREATUREID))
{
return (char*)((BattlelistBegin + BattlelistStep * i) + 0x04);
}
}
return NULL;
}

And ok by
GuiHandle.addLabel(CHARACTER, 10, 80, 80, const_cast<char*>(ContextTargetName().c_str()), 235, 235, 235); i get name of creature where i used context menu. But this name reset only when i reset client. For example: i use Righ click mouse on monster "Dragon" , choose "Check" and i see label with name "Dragon", probably ok, but after this i trying use this on Demon and still i see "Dragon", when i reset client and use it on Demon i see "Demon" but when i try again on another monster i see again name of character which i used first after run client. How i can clean this from memory, / refresh?

Arkamek
09-17-2014, 06:48 PM
ok you can close topic. Error was cuase i forgot refresh label when i hide container. Thanks all for help :)

XtrmJash
09-17-2014, 09:42 PM
ok you can close topic. Error was cuase i forgot refresh label when i hide container. Thanks all for help :)

Just want to say:

1. Thanks for your questions, they gave me something to think about.
2. Thanks for posting your answers, they confirmed and confused me, which is fucking awesome.
3. Keep at it, I think you'll go far ;)