Skip to content

Commit

Permalink
Added GetMouseWorldPos & SetInvertMidMouseButton(RutreD & KionX)
Browse files Browse the repository at this point in the history
  • Loading branch information
KionX committed Aug 22, 2022
1 parent cb74e52 commit 88dc4dd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ This are just the patch files for this game. I decided to separate them from pat
- hooks/UserGetDepositsAroundPoint.cpp
- section/SimGetDepositsAroundPoint.cpp
- section/LuaFuncRegs.cpp
- Adds SetInvertMidMouseButton to UI
- section/InvertMidMouseButton.cpp
- section/LuaFuncRegs.cpp
- Allow devs to write console commands to the log
- hooks/ConsoleLog.cpp
- section/ConsoleLog.cpp
Expand All @@ -89,6 +92,8 @@ This are just the patch files for this game. I decided to separate them from pat
- Adds SetCommandSource to Sim. Allow armies to be shared by multiple players
- section/SimSetCommandSource.cpp
- section/LuaFuncRegs.cpp
- Adds GetMouseWorldPos to Sim
- section/LuaFuncRegs.cpp
- Adds SessionIsReplay to Sim
- section/SimIsReplay.cpp
- section/LuaFuncRegs.cpp
Expand Down
22 changes: 22 additions & 0 deletions section/InvertMidMouseButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "include/LuaAPI.h"

int SetInvertMidMouseButton(lua_State *L)
{
auto ptr = GetProcAddress(GetModuleHandle("KERNEL32"), "VirtualProtect");
auto VirtualProtect = reinterpret_cast<bool (__stdcall *)(void*, size_t, uint32_t, uint32_t*)>(ptr);

if (lua_gettop(L) != 1)
WarningF("%s\n expected %d args, but got %d", __FUNCTION__, 1, lua_gettop(L));
if (!lua_isboolean(L, 1))
WarningF("%s\n invalid argument %d, use as boolean", __FUNCTION__, 1);

bool status = lua_toboolean(L, 1);

uint32_t oldProt;
VirtualProtect(reinterpret_cast<void *>(0x0086E01F), 9, 0x40, &oldProt);
*reinterpret_cast<uint8_t*>(0x0086E01F) = status ? 0x29 : 0x01; // asm sub or add
*reinterpret_cast<uint8_t*>(0x0086E027) = status ? 0x29 : 0x01; // asm sub or add
VirtualProtect(reinterpret_cast<void *>(0x0086E027), 9, oldProt, &oldProt);

return 0;
}
35 changes: 26 additions & 9 deletions section/LuaFuncRegs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "include/moho.h"

int SimSessionIsReplay(void* L);
int SimSessionIsReplay(void *L); // End Sim chain
luaFuncDescReg SSIRRegDesc = {0x00E45E90, // Std register func
0x00E4AFBC, // "SessionIsReplay"
0x00E00D90, // "<global>"
Expand All @@ -9,7 +9,7 @@ luaFuncDescReg SSIRRegDesc = {0x00E45E90, // Std register func
SimSessionIsReplay, // Func ptr
0x00000000}; // C++ class vtable ptr

int SimSetCommandSource(void* L);
int SimSetCommandSource(void *L);
luaFuncDescReg SSCSRegDesc = {0x00E45E90,
"SetCommandSource",
0x00E00D90,
Expand All @@ -20,7 +20,7 @@ luaFuncDescReg SSCSRegDesc = {0x00E45E90,

#define s_GDAPName "GetDepositsAroundPoint"
#define s_GDAPDesc "(X, Z, Radius, Type)"
int SimGetDepositsAroundPoint(void* L);
int SimGetDepositsAroundPoint(void *L);
luaFuncDescReg SGDAPRegDesc = {0x00E45E90,
s_GDAPName,
0x00E00D90,
Expand All @@ -31,7 +31,7 @@ luaFuncDescReg SGDAPRegDesc = {0x00E45E90,

#define s_GTFPName "GetTimeForProfile"
#define s_GTFPDesc "(OriginTime)"
int GetTimeForProfile(void* L);
int GetTimeForProfile(void *L);
luaFuncDescReg SGTFPRegDesc = {0x00E45E90,
s_GTFPName,
0x00E00D90,
Expand All @@ -40,27 +40,44 @@ luaFuncDescReg SGTFPRegDesc = {0x00E45E90,
GetTimeForProfile,
0x00000000};

int SimSetFocusArmy(void* L);
luaFuncDescReg SGMWPRegDesc = {0x00E45E90,
0x00E451A4, // "GetMouseWorldPos"
0x00E00D90,
0x00E45188,
&SGTFPRegDesc,
0x00842BB0,
0x00000000};

int SimSetFocusArmy(void *L); // Sim chain entry
luaFuncDescReg SSFARegDesc = {0x00E45E90, // Std register func
0x00E43408, // "SetFocusArmy"
0x00E00D90, // "<global>"
0x00E451FC, // "SetFocusArmy(armyIndex or -1)"
&SGTFPRegDesc, // Next reg desc
&SGMWPRegDesc, // Next reg desc
SimSetFocusArmy, // Func ptr
0x00000000}; // C++ class vtable ptr

luaFuncDescReg UGTFPRegDesc = {0x00E45E90,
luaFuncDescReg UGTFPRegDesc = {0x00E45E90, // UI chain end
s_GTFPName,
0x00E00D90,
s_GTFPDesc,
0x010C3CA4, // Next reg desc: SetFocusArmy
GetTimeForProfile,
0x00000000};

luaFuncDescReg UGDAPRegDesc = {0x00E45E90,
int SetInvertMidMouseButton(lua_State *L);
luaFuncDescReg USIMMBRegDesc = {0x00E45E90,
"SetInvertMidMouseButton",
0x00E00D90,
"(bool)",
&UGTFPRegDesc,
SetInvertMidMouseButton,
0x00000000};

luaFuncDescReg UGDAPRegDesc = {0x00E45E90, // UI chain entry
s_GDAPName,
0x00E00D90,
s_GDAPDesc,
&UGTFPRegDesc, // Next reg desc
&USIMMBRegDesc, // Next reg desc
SimGetDepositsAroundPoint,
0x00000000};

0 comments on commit 88dc4dd

Please sign in to comment.