Skip to content

Commit

Permalink
Alternative fix for the toggle of the Salem (#94)
Browse files Browse the repository at this point in the history
Depends on: FAForever/fa#6499
  • Loading branch information
4z0t authored Nov 7, 2024
1 parent 9e15840 commit 03cf904
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 112 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ These new features have been added in a backwards compatible manner
- section/LuaFuncRegs.cpp
- Maximum sim rate up to 50
- hooks/DelClampMaxSimRate.cpp
- Adds an amphibious mode toggle to the Salem
- hooks/luaSimGetStat.cpp
- section/luaSimGetStat.cpp
- Adds GetDepositsAroundPoint to Sim and UI
- section/SimGetDepositsAroundPoint.cpp
- section/LuaFuncRegs.cpp
Expand All @@ -225,3 +222,6 @@ These new features have been added in a backwards compatible manner
- section/BuildUnit.cpp
- section/SelectUnit.cpp
- section/SimArmyCreate.cpp
- Add `Unit:ForceAltFootPrint` that forces game to use AltFootprint for the unit (applied to Salem in particular)
- hooks/EntityGetFootprint.cpp
- section/EntityGetFootprint.cpp
14 changes: 14 additions & 0 deletions hooks/EntityGetFootprint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#define SECTION(index, address) ".section h"#index"; .set h"#index","#address";"
#include "../define.h"

asm(
// Moho::Entity::Entity
SECTION(0, 0x00677BC9)
"mov dword ptr [esi+0x1F8], ebx;" // 0x1F9 bool forceAltFootprint
// Moho::Entity::GetFootprint
SECTION(1, 0x006788A5)
"jmp "QU(asm__GetFootprint)";"
"nop;"
"nop;"
);
7 changes: 0 additions & 7 deletions hooks/luaSimGetStat.cpp

This file was deleted.

39 changes: 39 additions & 0 deletions section/EntityGetFootprint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "include/CObject.h"
#include "include/magic_classes.h"
#include "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+0x1F9) = flag; // bool forceAltFootprint

return 0;
}
using UnitMethodReg = SimRegFunc<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+0x1F9], 0;" // bool forceAltFootprint
"jnz 0x006788AE;"
"jmp 0x006788C2;"
);
}
14 changes: 13 additions & 1 deletion section/include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,16 @@ struct Result {
constexpr static Result<T> Success(void *data) { return {(T *)data, nullptr}; }

inline bool IsFail() { return reason != nullptr; }
};
};

template <typename T>
T Offset(void *ptr, size_t offset)
{
return (T)(((char *)ptr) + offset);
}

template <typename T>
T &GetField(void *ptr, size_t offset)
{
return *Offset<T *>(ptr, offset);
}
1 change: 1 addition & 0 deletions section/include/moho.h
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ struct UnitIntel

struct Unit : WeakObject
{//0x006A5422, 0x6A8 bytes
using Type = ObjectType<0x010C6FC8, 0x00F6A1E4>;
//WeakObject WeakObject;
// at 0x8
//Entity Entity; to 0x278
Expand Down
101 changes: 0 additions & 101 deletions section/luaSimGetStat.cpp

This file was deleted.

0 comments on commit 03cf904

Please sign in to comment.