Skip to content

Commit

Permalink
Prevent unit:SetStat() from crashing the game (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
4z0t authored Jul 22, 2023
1 parent 74dc0f5 commit d9a6e16
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ This are just the patch files for this game. I decided to separate them from pat

# Change List
## Fixes
- Fix `Unit:SetStat` function, crashed before. Now returns true if value must be set.
- hooks/SetStatFix.cpp
- section/SetStatFix.cpp
- Upgrade Progress Fix
- hooks/HUpgradeProgressFix.cpp
- section/UpgradeProgressFix.cpp
Expand Down
7 changes: 7 additions & 0 deletions hooks/SetStatFix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "../define.h"
asm(
".section h0; .set h0,0x6CCA2A;"
"jmp "QU(SetStatCheck)";"
"nop;"
"nop;"
);
31 changes: 31 additions & 0 deletions section/SetStatFix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "include/moho.h"

void PushTrue()
{
register lua_State *l asm("eax");
lua_pushboolean(l, true);
}

void SetStatCheck()
{
asm(
// mov ebx, eax //pointer to our stat in other thread
"mov eax, [edi];" // pointer to lua state
"cmp ebx, 0;"
"je SetStatCheck_invalid;" // go to return 1
"mov esi, 3;"
"jmp 0x6CCA31;" // get back into normal function flow
"SetStatCheck_invalid:"
"call %[PushTrue];"
"mov eax, 1;"
"pop edi;"
"pop esi;"
"pop ebx;"
"mov esp, ebp;"
"pop ebp;"
"ret;"
:
: [PushTrue] "i"(PushTrue)
:
);
}

0 comments on commit d9a6e16

Please sign in to comment.