-
Member
A question to CanAttack memory
Hello, friends.
Tell me, please, what am I doing wrong?
When the delegate is called, the CanAttack returns true | false
Code:
_BOOL1 __thiscall CGUnit_C::CanAttack(int this, _DWORD *a2)
But when I use it for non-strategic or hostile units (which I cannot attack), Tru returns.
Tried to swap units - still returns true
Code:
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private delegate bool IsCanAttackDelegate(IntPtr Player, IntPtr Unit);
...
bool IsCanAttack()
{
CanAttack = Memory.RegisterDelegate<IsCanAttackDelegate>((IntPtr)IsCanAttack); // 3.3.5a 00729740
return CanAttack(Player.Ptr, Unit.Ptr);
}
At the same time, Lua_UnitCanAttack () returns true and false depending on the sequence of the specified units.
On these screenshots are indicated the units whose CanAttack returns true
here's a dump from the IDA function Lua_UnitCanAttack
Code:
signed int __cdecl Lua_UnitCanAttack(int a1)
{
char *v1; // eax
void *v2; // edi
char *v3; // eax
_DWORD *v4; // eax
signed int result; // eax
if ( FrameScript::IsString(a1, 1) && FrameScript::IsString(a1, 2) )
{
v1 = (char *)FrameScript::ToLString(a1, 1, 0);
v2 = GetUnitFromName(v1);
v3 = (char *)FrameScript::ToLString(a1, 2, 0);
v4 = GetUnitFromName(v3);
if ( v2 && v4 && CGUnit_C::CanAttack((int)v2, v4) )
{
FrameScript::PushNumber(a1, 1.0);
result = 1;
}
else
{
FrameScript::pushnil(a1);
result = 1;
}
}
else
{
FrameScript::DisplayError(a1, "Usage: UnitCanAttack(\"unit\", \"otherUnit\")");
result = 0;
}
return result;
}
-
Member
I see caller and callee use al register, low word. Maybe c# bool read whole eax and gets wrong result?
What if you change delegate return type to uint and then print returned value?
-
Member
Originally Posted by
Alex__
What if you change delegate return type to uint and then print returned value?
Checked uint, int, byte, bool - returns 1 value of all netral and enemy units
for neutral units it always shows the truth regardless of whether it is attacked or not
Last edited by NightlyBlooD; 06-17-2019 at 01:41 PM.
-
Member
I dont know, have not checked myself.
Try read descriptor unit flags, test if it has NotAttackable flag
-
Member
I confirm that Lua: UnitCanAttack might return results different from CGUnit_C::CanAttack
npcs with NotAttackable (0x100) flag make it happen and enemy players in sanctuary zone.
Looks like If you want to use CGUnit_C::CanAttack, additional checks are required (at least for this flag presence).
Players do not have this flag though.
But UnitReaction gives me expected results (Lua = CGUnit_C::UnitReaction+1)
Last edited by Alex__; 06-17-2019 at 08:44 PM.
-
Post Thanks / Like - 1 Thanks
Corthezz (1 members gave Thanks to Alex__ for this useful post)