From ecd372360c4828d224e756608d1fa2e0cde99f95 Mon Sep 17 00:00:00 2001 From: 4z0t Date: Thu, 5 Dec 2024 20:37:27 +0300 Subject: [PATCH] C++ implementation for Moho__Entity__GetFootprint --- hooks/EntityGetFootprint.hook | 6 ++--- section/EntityGetFootprint.cpp | 39 --------------------------- section/EntityGetFootprint.cxx | 48 ++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 43 deletions(-) delete mode 100644 section/EntityGetFootprint.cpp create mode 100644 section/EntityGetFootprint.cxx diff --git a/hooks/EntityGetFootprint.hook b/hooks/EntityGetFootprint.hook index 08350be..8aa7173 100644 --- a/hooks/EntityGetFootprint.hook +++ b/hooks/EntityGetFootprint.hook @@ -4,7 +4,5 @@ // Moho::Entity::GetFootprint -0x006788A5: - jmp @asm__GetFootprint - nop - nop \ No newline at end of file +0x00678880: + jmp @Moho__Entity__GetFootprint \ No newline at end of file diff --git a/section/EntityGetFootprint.cpp b/section/EntityGetFootprint.cpp deleted file mode 100644 index 26ab2ea..0000000 --- a/section/EntityGetFootprint.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "CObject.h" -#include "magic_classes.h" -#include "moho.h" - -int ForceAltFootprint(lua_State *L) -{ - - if (lua_gettop(L) != 2) - L->LuaState->Error(s_ExpectedButGot, __FUNCTION__, 2, lua_gettop(L)); - auto res = GetCScriptObject(L, 1); - if (res.IsFail()) - L->LuaState->Error("%s", res.reason); - - void *unit = res.object; - bool flag = lua_toboolean(L, 2); - - GetField(unit, 8+0x11D) = flag; // bool forceAltFootprint - - return 0; -} -using UnitMethodReg = SimRegFuncT<0x00E2D550, 0x00F8D704>; - -UnitMethodReg UseAltFootprintReg{ - "ForceAltFootprint", - "", - ForceAltFootprint, - "Unit"}; - - -void asm__GetFootprint() -{ - asm( - "cmp byte ptr [ecx+0x11C], 0;" // this->sstiData.usingAltFp - "jnz 0x006788AE;" - "cmp byte ptr [ecx+0x11D], 0;" // bool forceAltFootprint - "jnz 0x006788AE;" - "jmp 0x006788C2;" - ); -} \ No newline at end of file diff --git a/section/EntityGetFootprint.cxx b/section/EntityGetFootprint.cxx new file mode 100644 index 0000000..4b3b993 --- /dev/null +++ b/section/EntityGetFootprint.cxx @@ -0,0 +1,48 @@ +#include "CObject.h" +#include "magic_classes.h" +#include "moho.h" + +int ForceAltFootprint(lua_State *L) +{ + + if (lua_gettop(L) != 2) + L->LuaState->Error(s_ExpectedButGot, __FUNCTION__, 2, lua_gettop(L)); + auto res = GetCScriptObject(L, 1); + if (res.IsFail()) + L->LuaState->Error("%s", res.reason); + + void *unit = res.object; + bool flag = lua_toboolean(L, 2); + + GetField(unit, 8 + 0x11D) = flag; // bool forceAltFootprint + + return 0; +} +using UnitMethodReg = SimRegFuncT<0x00E2D550, 0x00F8D704>; + +UnitMethodReg UseAltFootprintReg{ + "ForceAltFootprint", + "", + ForceAltFootprint, + "Unit"}; + +SHARED void *__thiscall Moho__Entity__GetFootprint(Entity *entity) +{ + void *bp = GetField(entity, 0x6C); + if (!bp) + { + runtime_error err(string{"Attempt to get footprint on nameless entity"}); + _CXXThrowException(&err, (void *)0xEC210C); + } + void *sstiData = Offset(entity, 0x78); + bool usingAltFp = GetField(sstiData, 0xA4); + bool forceAltFp = GetField(sstiData, 0xA5); + if (usingAltFp || forceAltFp) + { + return Offset(bp, 0xE8); + } + else + { + return Offset(bp, 0xD8); + } +} \ No newline at end of file