Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KionX committed Aug 21, 2022
1 parent e35f167 commit cb74e52
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 252 deletions.
2 changes: 2 additions & 0 deletions FALuaFuncs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//LUA funcs map github.com/Eximius/forged_jit

namespace gpg
{
class RRef {public: void* d; void* t;};
Expand Down
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ This are just the patch files for this game. I decided to separate them from pat
- hooks/CameraPerf.cpp
- Fix replays desyncing when a player leaves the game
- hooks/DesyncFix.cpp
- section/ext_sector.cpp
- section/gpg_net.cpp
- section/moho_decode.cpp
- section/moho_input.cpp
Expand All @@ -36,7 +35,7 @@ This are just the patch files for this game. I decided to separate them from pat
- hooks/Kill_maploader_except.cpp
- Make xact3d the error message print once
- hooks/xact_3dapply.cpp
- section/ext_sector.cpp
- section/xact_3d_fix.cpp
- Prevent blueprint editor being used without cheat mode
- hooks/FixOpenBPEditor.cpp
- Can't become an observer while your human allies are still alive
Expand All @@ -57,19 +56,18 @@ This are just the patch files for this game. I decided to separate them from pat
- GetSessionClients also output maximum sim speed(maxSP)
- hooks/HOutputMaxSP.cpp
- section/OutputMaxSP.cpp
- Console command: "cam_DefaultMiniLOD 0" now completely disable mesh renderer for minimap
- Console command: "cam_DefaultMiniLOD 0" now disable mesh renderer for minimap
- hooks/MinimapMesh.cpp
- section/MinimapMesh.cpp
- Allow players to double-click to select Walls
- hooks/Walls.cpp
- Similar to GetSystemTimeSecondsOnlyForProfileUse
Allows to deal with the loss of accuracy. It is present in the Sim and UI
- Adds GetTimeForProfile to Sim and UI. Allows to deal with the loss of accuracy
- section/GetTimeForProfile.cpp
- section/ext_sector.cpp
- section/LuaFuncRegs.cpp
- Adds optimized table.getsize2(~25 times faster) and table.empty2
Added getn2 as alias getn. Entry point to math functions queue
Adds getn2 as alias getn. Entry point to math functions queue
- hooks/GetTableSize.cpp
- section/ext_sector.cpp
- section/LuaFuncRegs.cpp
- Maximum sim rate up to 50
- hooks/DelClampMaxSimRate.cpp
- Adds an amphibious mode toggle to the Salem
Expand All @@ -78,18 +76,27 @@ This are just the patch files for this game. I decided to separate them from pat
- Make `LOWSELECTPRIO` apply to units under construction
- hooks/selectionPriority.cpp
- section/selectionPriority.cpp
- Allow the getting of Mass or Energy spots around a location & Entry point to ui functions queue
- Adds GetDepositsAroundPoint to Sim and UI & Entry point to ui functions queue
Allow the getting of Mass or Energy spots around a location
- hooks/UserGetDepositsAroundPoint.cpp
- section/SimGetDepositsAroundPoint.cpp
- section/ext_sector.cpp
- section/LuaFuncRegs.cpp
- Allow devs to write console commands to the log
- hooks/ConsoleLog.cpp
- section/ConsoleLog.cpp
- Unlock an "Ultra" graphics preset
- hooks/UnlockUltraPreset.cpp
- Allow armies to be shared by multiple players & Entry point to sim functions queue
- Adds SetCommandSource to Sim. Allow armies to be shared by multiple players
- section/SimSetCommandSource.cpp
- section/LuaFuncRegs.cpp
- Adds SessionIsReplay to Sim
- section/SimIsReplay.cpp
- section/LuaFuncRegs.cpp
- Adds SetFocusArmy to Sim. Sets focus without restrictions
Entry point to sim functions queue
- hooks/SimSetFocusArmy.cpp
- section/SimSetFocusArmy.cpp
- section/LuaFuncRegs.cpp
- Allow upgrades to be queued on units under construction
- hooks/BuildUnit.cpp
- section/BuildUnit.cpp
Expand Down
143 changes: 1 addition & 142 deletions section/ext_sector.cpp → section/LuaFuncRegs.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#include "include/moho.h"
#include "include/desync_fix_global.h"

// New unit categories.
//const char* sCQUEMOV = "CQUEMOV";
//const char* sSTAYONWATSUR = "STAYONWATSUR";

int SimSessionIsReplay(void* L);
luaFuncDescReg SSIRRegDesc = {0x00E45E90, // Std register func
Expand Down Expand Up @@ -68,140 +63,4 @@ luaFuncDescReg UGDAPRegDesc = {0x00E45E90,
s_GDAPDesc,
&UGTFPRegDesc, // Next reg desc
SimGetDepositsAroundPoint,
0x00000000};

register int eax asm("eax");

bool game_ended = false;

void EndGame()
{
game_ended = true;
asm("mov dword ptr [0x011FD23F], 0xB;"); //remove block when last player remains.
asm
(
"push esi;"
"mov esi,eax;"
"mov eax,dword ptr [esi];"
"push edi;"
"mov edi,dword ptr [0x10BA600];"
"push eax;"
"call 0x90C590;"
"add esp,0x4;"
"test eax,eax;"
"je L0xABEL_0x0074B8DB;"
"push eax;"
"push 0x0;"
"push edi;"
"push 0xE0A220;"
"push esi;"
"call 0x90C1D0;"
"add esp,0x14;"
"L0xABEL_0x0074B8DB:;"
"mov esi,dword ptr [esi];"
"push esi;"
"call 0x924050;"
"mov edx,dword ptr [eax];"
"mov ecx,eax;"
"mov eax,dword ptr [edx+0x5C];"
"add esp,0x4;"
"call eax;"
"pop edi;"
"xor eax,eax;"
"pop esi;"
"ret;"
);
}

void xact_3d_apply()
{
static bool once = true;
asm
(
"push ebx;"
"push edi;"
"mov ebx,ecx;"
"mov edi,eax;"
"mov eax,dword ptr [ebx];"
"cmp dword ptr [eax+0x34],0x0;"
"je L0xABEL_0x004D9B2A;"
"push esi;"
"push 0x64;"
"lea esi,dword ptr [eax+0xAC];"
"push 0x0;"
"push esi;"
"call 0xA89110;"
"xorps xmm0,xmm0;"
"mov dword ptr [esi+0x3C],0x1;"
"mov dword ptr [esi],0x0;"
"fld dword ptr [edi];"
"fstp dword ptr [esi+0x1C];"
"fld dword ptr [edi+0x4];"
"fstp dword ptr [esi+0x20];"
"fld dword ptr [edi+0x8];"
"movss dword ptr [esi+0x28],xmm0;"
"movss dword ptr [esi+0x2C],xmm0;"
"fstp dword ptr [esi+0x24];"
"movss dword ptr [esi+0x30],xmm0;"
"movss xmm0,dword ptr [0xDFEC20];"
"movss dword ptr [esi+0x5C],xmm0;"
"movss dword ptr [esi+0xC],xmm0;"
"movss dword ptr [esi+0x14],xmm0;"
"mov ecx,dword ptr [ebx];"
"lea edi,dword ptr [ecx+0x7C];"
"lea eax,dword ptr [ecx+0xAC];"
"lea edx,dword ptr [ecx+0x38];"
"add ecx,0x110;"
"push ecx;"
"call 0x4D81E0;"
"add esp,0x10;"
"test eax,eax;"
"jge L0xABEL_0x004D9B04;"
"call 0x4D8A50;"
);

asm
(
"push eax;"
"push 0xE0B410;"
"call 0x937D30;"
"add esp,0x8;"
);

asm
(
"pop esi;"
"pop edi;"
"pop ebx;"
"ret 0x4;"
"L0xABEL_0x004D9B04:;"
"mov ebx,dword ptr [ebx];"
"mov esi,dword ptr [esp+0x10];"
"lea edi,dword ptr [ebx+0x7C];"
"call 0x4D82A0;"
"test eax,eax;"
"jge L0xABEL_0x004D9B29;"
"call 0x4D8A50;"
);
if(once)
{
asm
(
"push eax;"
"push 0xE0B430;"
"call 0x937D30;"
"add esp,0x8;"
);
once = false;
}

asm
(
"L0xABEL_0x004D9B29:;"
"pop esi;"
"L0xABEL_0x004D9B2A:;"
"pop edi;"
"pop ebx;"
"ret 0x4;"
);
}
0x00000000};
4 changes: 2 additions & 2 deletions section/RangeRings2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void* _thiscall HeightCylinders(char* this_)
if (*Heights > MaxH) MaxH = *Heights;
Heights++;
}
MinCHeight = MinH * 0.0078125 - 5;
MaxCHeight = MaxH * 0.0078125;
MinCHeight = MinH * 0.0078125f - 5.f;
MaxCHeight = MaxH * 0.0078125f;
this_ = (char*)*(uint32_t*)(0x10C7C28);
reinterpret_cast<void (_thiscall *)(void*)>(0x7EDFE0)(this_ + 0x37C);
reinterpret_cast<void (_thiscall *)(void*)>(0x81C0C0)(this_ + 0x410);
Expand Down
40 changes: 40 additions & 0 deletions section/gpg_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ uint32_t p_index = 0;
uint32_t sender_sock = 1;
uint32_t sync_buffer[17];
uint32_t discard = 0;
bool game_ended = false;

__attribute__((noinline)) void p_SetEvent()
{
Expand Down Expand Up @@ -847,4 +848,43 @@ void Gpg_Net_Entry()
"add esp,0x64;"
"ret 0x8;"
);
}

void EndGame()
{
game_ended = true;
asm("mov dword ptr [0x011FD23F], 0xB;"); //remove block when last player remains.
asm
(
"push esi;"
"mov esi,eax;"
"mov eax,dword ptr [esi];"
"push edi;"
"mov edi,dword ptr [0x10BA600];"
"push eax;"
"call 0x90C590;"
"add esp,0x4;"
"test eax,eax;"
"je L0xABEL_0x0074B8DB;"
"push eax;"
"push 0x0;"
"push edi;"
"push 0xE0A220;"
"push esi;"
"call 0x90C1D0;"
"add esp,0x14;"
"L0xABEL_0x0074B8DB:;"
"mov esi,dword ptr [esi];"
"push esi;"
"call 0x924050;"
"mov edx,dword ptr [eax];"
"mov ecx,eax;"
"mov eax,dword ptr [edx+0x5C];"
"add esp,0x4;"
"call eax;"
"pop edi;"
"xor eax,eax;"
"pop esi;"
"ret;"
);
}
4 changes: 4 additions & 0 deletions section/include/LuaAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ typedef struct {
int tt;
Value value;
} TObject;
VALIDATE_SIZE(TObject, 8)

//namespace gpg
class RRef {public: void* d; void* t;};
Expand All @@ -127,6 +128,7 @@ typedef struct {
LuaState* m_state;
int m_stackIndex;
};
VALIDATE_SIZE(LuaStackObject, 8)

namespace CLuaStackObject
{
Expand All @@ -142,6 +144,7 @@ typedef struct {
LuaState* m_state;
TObject m_object;
};
VALIDATE_SIZE(LuaObject, 0x14)

namespace CLuaObject
{
Expand Down Expand Up @@ -242,6 +245,7 @@ typedef struct {
LuaObject* m_prev; // only valid when in used list
} m_headObject, m_tailObject;
};
VALIDATE_SIZE(LuaState, 0x34)

namespace CLuaState
{
Expand Down
Loading

0 comments on commit cb74e52

Please sign in to comment.