From 88dc4ddaffbc06ff2bcff051dfe20d1dbaf18727 Mon Sep 17 00:00:00 2001 From: KionX <> Date: Mon, 22 Aug 2022 13:15:54 +0500 Subject: [PATCH] Added GetMouseWorldPos & SetInvertMidMouseButton(RutreD & KionX) --- README.md | 5 +++++ section/InvertMidMouseButton.cpp | 22 ++++++++++++++++++++ section/LuaFuncRegs.cpp | 35 ++++++++++++++++++++++++-------- 3 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 section/InvertMidMouseButton.cpp diff --git a/README.md b/README.md index 6ed73e6a..08f31e68 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/section/InvertMidMouseButton.cpp b/section/InvertMidMouseButton.cpp new file mode 100644 index 00000000..774a3892 --- /dev/null +++ b/section/InvertMidMouseButton.cpp @@ -0,0 +1,22 @@ +#include "include/LuaAPI.h" + +int SetInvertMidMouseButton(lua_State *L) +{ + auto ptr = GetProcAddress(GetModuleHandle("KERNEL32"), "VirtualProtect"); + auto VirtualProtect = reinterpret_cast(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(0x0086E01F), 9, 0x40, &oldProt); + *reinterpret_cast(0x0086E01F) = status ? 0x29 : 0x01; // asm sub or add + *reinterpret_cast(0x0086E027) = status ? 0x29 : 0x01; // asm sub or add + VirtualProtect(reinterpret_cast(0x0086E027), 9, oldProt, &oldProt); + + return 0; +} \ No newline at end of file diff --git a/section/LuaFuncRegs.cpp b/section/LuaFuncRegs.cpp index 5d7624c7..31599a5e 100644 --- a/section/LuaFuncRegs.cpp +++ b/section/LuaFuncRegs.cpp @@ -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, // "" @@ -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, @@ -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, @@ -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, @@ -40,16 +40,24 @@ 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, // "" 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, @@ -57,10 +65,19 @@ luaFuncDescReg UGTFPRegDesc = {0x00E45E90, 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}; \ No newline at end of file