Skip to content

Commit

Permalink
C++ implementation for Moho__Entity__GetFootprint
Browse files Browse the repository at this point in the history
  • Loading branch information
4z0t committed Dec 5, 2024
1 parent 9a98a71 commit ecd3723
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 43 deletions.
6 changes: 2 additions & 4 deletions hooks/EntityGetFootprint.hook
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@


// Moho::Entity::GetFootprint
0x006788A5:
jmp @asm__GetFootprint
nop
nop
0x00678880:
jmp @Moho__Entity__GetFootprint
39 changes: 0 additions & 39 deletions section/EntityGetFootprint.cpp

This file was deleted.

48 changes: 48 additions & 0 deletions section/EntityGetFootprint.cxx
Original file line number Diff line number Diff line change
@@ -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<Unit>(L, 1);
if (res.IsFail())
L->LuaState->Error("%s", res.reason);

void *unit = res.object;
bool flag = lua_toboolean(L, 2);

GetField<bool>(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<void *>(entity, 0x6C);
if (!bp)
{
runtime_error err(string{"Attempt to get footprint on nameless entity"});
_CXXThrowException(&err, (void *)0xEC210C);
}
void *sstiData = Offset<void *>(entity, 0x78);
bool usingAltFp = GetField<bool>(sstiData, 0xA4);
bool forceAltFp = GetField<bool>(sstiData, 0xA5);
if (usingAltFp || forceAltFp)
{
return Offset<void *>(bp, 0xE8);
}
else
{
return Offset<void *>(bp, 0xD8);
}
}

0 comments on commit ecd3723

Please sign in to comment.