Skip to content

Commit c496729

Browse files
committed
UnitForceReclaim
Addded Unit:ForceReclaim(bool) When enabled engineer will continue reclaiming even if storage is full.
1 parent 689caa7 commit c496729

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,5 +363,11 @@ These new features have been added in a backwards compatible manner
363363
- section/SimArmyCreate.cpp
364364

365365
- Add `Unit:ForceAltFootPrint` that forces game to use AltFootprint for the unit (applied to Salem in particular)
366+
- hooks/MohoEntityVariableData.hook
366367
- hooks/EntityGetFootprint.cpp
367368
- section/EntityGetFootprint.cpp
369+
370+
- Add `Unit:ForceReclaim(bool)` When 'true' engineer will continue reclaiming even if both (mass and energy) storages are full
371+
- hooks/MohoEntityVariableData.hook
372+
- hooks/UnitForceReclaim.hook
373+
- section/UnitForceReclaim.cpp

hooks/EntityGetFootprint.hook

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
//Moho::SSTIEntityVariableData::SSTIEntityVariableData
2-
0x00558823:
3-
mov dword ptr [eax+0x0A4], ecx // 0x0A5 bool forceAltFootprint
4-
5-
61
// Moho::Entity::GetFootprint
72
0x006788A5:
83
jmp @asm__GetFootprint

hooks/MohoEntityVariableData.hook

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//Moho::SSTIEntityVariableData::SSTIEntityVariableData
2+
0x00558823:
3+
mov dword ptr [eax+0x0A4], ecx // 0x0A5 bool forceAltFootprint
4+
// 0x0A6 bool isForceReclaim
5+
// 0x0A7 bool empty

hooks/UnitForceReclaim.hook

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0x0061BC07:
2+
jmp @asm__IsForceReclaim
3+
nop
4+
nop

section/UnitForceReclaim.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "CObject.h"
2+
#include "magic_classes.h"
3+
#include "moho.h"
4+
5+
6+
void asm__IsForceReclaim()
7+
{
8+
asm(
9+
"mov eax, dword ptr ds:[ebp+0x1C];" // entity
10+
"mov al, byte ptr ss:[eax+0x126];" // entity->isForceReclaim
11+
12+
"test al, al;"
13+
"jz Exit;"
14+
15+
"mov byte ptr ss:[esp+0x13], 0x0;" // energyStorageIsFull = false
16+
"mov byte ptr ss:[esp+0x12], 0x0;" // massStorageIsFull = false
17+
18+
"Exit:;"
19+
"lea edx, ss:[esp+0x94];" //default code
20+
"jmp 0x0061BC0E;"
21+
);
22+
}
23+
24+
25+
int ForceReclaim(lua_State *L)
26+
{
27+
if (lua_gettop(L) != 2)
28+
L->LuaState->Error(s_ExpectedButGot, __FUNCTION__, 2, lua_gettop(L));
29+
auto res = GetCScriptObject<Unit>(L, 1);
30+
if (res.IsFail())
31+
L->LuaState->Error("%s", res.reason);
32+
33+
void *unit = res.object;
34+
bool flag = lua_toboolean(L, 2);
35+
36+
GetField<bool>(unit, 8+0x11E) = flag; // bool isForceReclaim
37+
38+
return 0;
39+
}
40+
using UnitMethodReg = SimRegFuncT<0x00E2D550, 0x00F8D704>;
41+
42+
UnitMethodReg ForceReclaimReg{
43+
"ForceReclaim",
44+
"",
45+
ForceReclaim,
46+
"Unit"};

0 commit comments

Comments
 (0)