I'm currently working on small codes to experiment with WoW and came to a snag trying to loop through the object manager to find my current target.
Offsets declared at the start of the code:
Code:
DWORD GameBase = 0x0100000;
DWORD isLooting = 0xE54980;
DWORD LocalPlayer = 0xDC0BC8;
DWORD EntityList = GameBase+0xD3B358;
DWORD FirstObj = 0x0C;
DWORD NextObj = 0x3C;
DWORD TargetGuid = GameBase+0xE35F20;
DWORD MoneyPointer = 0x1804;
DWORD Money = 0x18CC;
HANDLE hProc;
DWORD proc_id;
Function to find my target:
Code:
DWORD findTarget()
{
DWORD list = ReadDword(EntityList);
DWORD firstObj = ReadDword(list+FirstObj);
unsigned long long TargetId = ReadUInt(TargetGuid);
DWORD curObj = firstObj;
while(curObj != 0)
{
unsigned long long GlobalId = ReadUInt(curObj);
if(GlobalId == TargetId)
{
return curObj;
}
DWORD nextObj = ReadDword(curObj+NextObj);
if(nextObj == curObj)
{
break;
}
else
{
curObj = nextObj;
}
}
return 0;
}
Reading functions; (UInt is what I was originally using to store GUIDs, I just haven't renamed the function to suit using a long long now)
Code:
long ReadUInt(DWORD addr)
{
unsigned long long read;
ReadProcessMemory(hProc, (LPVOID)(addr), (LPVOID) &read, sizeof(read), 0);
return read;
}
DWORD ReadDword(DWORD addr)
{
DWORD read;
ReadProcessMemory(hProc, (LPVOID)(addr), (LPVOID) &read, sizeof(read), 0);
return read;
}
Code I'm calling the findTarget function from:
Code:
void MainWindow::on_pushButton_clicked()
{
HWND hwnd = FindWindowA(NULL, "World of Warcraft");
if(hwnd != NULL)
{
ui->output->addItem("Found window");
GetWindowThreadProcessId(hwnd, &proc_id);
hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proc_id);
char buf[64];
sprintf_s(buf, "Target obj; %x", findTarget());
ui->output->addItem(buf);
char targGuid[128];
sprintf_s(targGuid, "Target GUID; %d", ReadUInt(TargetGuid));
ui->output->addItem(targGuid);
}
}
I've done my best to try finding a solution to the problem and can't seem to find anything. Im assuming its either because im handing GUIDs incorrectly(using long long currently), or because im just doing something wrong in my loop in general. The program starts just fine, but upon pressing the button which I showed the code it calls, it freezes and crashes.
I'm aware that there is probably much better and cleaner ways of what I've done, but I'm just looking to start simple and work my way up. I've managed to read stuff such as my gold/copper/silver, health, etc just fine, I just can't seem to understand what im doing wrong with the object manager.
Any help would be greatly appreciated