In 3.1.2 (and maybe versions before it), an object's type does not appear to be where it used to be [[objBase + 0x8] + 0x8]. Some have posted that the offset for object type is now 0x2, or [[objBase + 0x8] + 0x2]. I have found neither of these to be accurate.
To attempt to solve my problem, I thought I would try to reverse 'GetUnitType' which in 3.1.2 is at 0x005A55C0.
ASM code:
Code:
005A55C0 80B9 F0090000 00 CMP BYTE PTR DS:[ECX+9F0],0
005A55C7 74 04 JE SHORT WoW.005A55CD
005A55C9 33C0 XOR EAX,EAX
005A55CB EB 0D JMP SHORT WoW.005A55DA
005A55CD 8B81 D0000000 MOV EAX,DWORD PTR DS:[ECX+D0]
005A55D3 0FB680 D3010000 MOVZX EAX,BYTE PTR DS:[EAX+1D3]
005A55DA 8B15 8083A300 MOV EDX,DWORD PTR DS:[A38380]
005A55E0 3BC2 CMP EAX,EDX
005A55E2 7C 1E JL SHORT WoW.005A5602
005A55E4 3B05 7C83A300 CMP EAX,DWORD PTR DS:[A3837C]
005A55EA 7F 16 JG SHORT WoW.005A5602
005A55EC 2BC2 SUB EAX,EDX
005A55EE 8B15 9083A300 MOV EDX,DWORD PTR DS:[A38390]
005A55F4 8B0482 MOV EAX,DWORD PTR DS:[EDX+EAX*4]
005A55F7 85C0 TEST EAX,EAX
005A55F9 74 07 JE SHORT WoW.005A5602
005A55FB 8B40 10 MOV EAX,DWORD PTR DS:[EAX+10]
005A55FE 85C0 TEST EAX,EAX
005A5600 7F 42 JG SHORT WoW.005A5644
005A5602 8B81 68090000 MOV EAX,DWORD PTR DS:[ECX+968]
005A5608 85C0 TEST EAX,EAX
005A560A 74 04 JE SHORT WoW.005A5610
005A560C 8B40 10 MOV EAX,DWORD PTR DS:[EAX+10]
005A560F C3 RETN
005A5610 8B81 D0000000 MOV EAX,DWORD PTR DS:[ECX+D0]
005A5616 0FB640 40 MOVZX EAX,BYTE PTR DS:[EAX+40]
005A561A 8B0D F86EA300 MOV ECX,DWORD PTR DS:[A36EF8]
005A5620 3BC1 CMP EAX,ECX
005A5622 7C 1E JL SHORT WoW.005A5642
005A5624 3B05 F46EA300 CMP EAX,DWORD PTR DS:[A36EF4]
005A562A 7F 16 JG SHORT WoW.005A5642
005A562C 2BC1 SUB EAX,ECX
005A562E 8B0D 086FA300 MOV ECX,DWORD PTR DS:[A36F08]
005A5634 8B0481 MOV EAX,DWORD PTR DS:[ECX+EAX*4]
005A5637 85C0 TEST EAX,EAX
005A5639 74 07 JE SHORT WoW.005A5642
005A563B 8B40 24 MOV EAX,DWORD PTR DS:[EAX+24]
005A563E 85C0 TEST EAX,EAX
005A5640 7F 02 JG SHORT WoW.005A5644
005A5642 33C0 XOR EAX,EAX
005A5644 C3 RETN
To try and understand this better, I re-wrote it as I read through it in psuedo-code. This is what I came up with:
Code:
if ([ecx+0x9F0] == NULL)
{
eax = [ecx + 0xD0]
eax = [eax + 0x1D3]
}
else
eax = 0
edx = [0xA38380]
if (eax < edx || eax > [0x00A3837C])
{
eax = eax - edx
edx = [0xA38390]
eax = [edx + eax*4]
}
eax = [ecx + 0x968]
eax = [ecx+0xD0]
eax = [eax+0x40]
ecx = [0xA36EF8]
if (eax < ecx || eax > [0xA36EF4)
return 0
eax = eax - ecx
ecx = [0xA36F08]
eax = [ecx + eax*4]
return 0
I have to confess that this has created more questions and provided no real answers for me. In particular, it seems like the function always returns 0! I know this can't be true, but of the two RETNs, this is the one which seems to return an actual value:
Code:
005A5608 85C0 TEST EAX,EAX
005A560A 74 04 JE SHORT WoW.005A5610
005A560C 8B40 10 MOV EAX,DWORD PTR DS:[EAX+10]
005A560F C3 RETN
Obviously eax always equals eax, so this jump to 0x005A5610 will always be performed. Moreover, there is no jump to 0x005A560C in this function. To me that means this code will never be executed. The second RETN is here:
Code:
005A563E 85C0 TEST EAX,EAX
005A5640 7F 02 JG SHORT WoW.005A5644
005A5642 33C0 XOR EAX,EAX
005A5644 C3 RETN
Again, obviously, eax > eax is always false, so, eax will be zero'd. While in this case there is one other place where we can jump to 0x005A5644, it also follows an always-false eax > eax statement at 0x005A55FE. So while this code will be executed, eax will always equal 0 when it does.
Can someone please tell me what I'm doing wrong? And though my reason for doing this is ultimately just to get an object's type (player, npc, corpse, etc.), after putting this effort in I'm more interested in learning what my mistake is so that I can be more self-sufficient with these sorts of efforts.