I have this code,
but when I pass structure Unit to the function, wc3 crash or it return "No Unit"
Can anyone help me?
Code:
UINT hUnit = ...;
GetUnitName(hUnit); // It works fine
char* GetUnitName(UINT hUnit)
{
char* retaddr = "No Unit";
__asm
{
mov ecx, hUnit;
mov eax, GameDll;
lea eax, dword ptr ds:[eax + 0x3BDCB0];
call eax;
test eax,eax
je NoUnit;
mov ecx,[eax + 0x30]
xor edx,edx
mov eax, GameDll;
lea eax, dword ptr ds:[eax + 0x32DBE0];
call eax
mov retaddr, eax;
NoUnit:
}
return retaddr;
}
Code:
struct Unit
{
DWORD dwDummy[3];
DWORD dwID1;
DWORD dwID2;
BYTE _1[0x1C];
DWORD dwClassId;
BYTE _2[0x1C];
DWORD HealthBar;
DWORD UNK;
DWORD dwOwnerSlot;
};
Unit* unit = ..;
GetUnitName((DWORD)unit); // return "No Unit"
// Or I change from char* GetUnitName(UINT hUnit) to char* GetUnitName(Unit* hUnit)
GetUnitName(unit); // WC3 crash...