From 7daa0309918a00ddd2bdd5a2f4c32689edcab2ea Mon Sep 17 00:00:00 2001 From: itsmattkc <34096995+itsmattkc@users.noreply.github.com> Date: Mon, 18 Oct 2021 10:15:56 -0700 Subject: [PATCH] implemented more patches --- lib/config.cpp | 26 ++++++++++++++++++++++++++ lib/config.h | 4 ++++ lib/hooks.cpp | 16 +++++++++++++++- lib/hooks.h | 2 ++ lib/worker.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/patchgrid.cpp | 2 +- 6 files changed, 86 insertions(+), 2 deletions(-) diff --git a/lib/config.cpp b/lib/config.cpp index 4a4490e..aafc216 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -1,6 +1,8 @@ #include "config.h" #include +#include +#include #include "../cmn/path.h" @@ -22,3 +24,27 @@ UINT Config::GetInt(LPCTSTR name, UINT defaultValue) { return GetPrivateProfileInt(appName, name, defaultValue, m_configFile.c_str()); } + +float Config::GetFloat(LPCTSTR name, float defaultValue) +{ + // Convert float to string + std::ostringstream oss; + oss << defaultValue; + std::string defaultStr = oss.str(); + + std::string currentStr = GetString(name, defaultStr); + + // Convert to float + return atof(currentStr.c_str()); +} + +std::string Config::GetString(LPCTSTR name, const std::string &defaultValue) +{ + const int max_string_sz = 100; + std::string s; + s.resize(max_string_sz); + + GetPrivateProfileString(appName, name, defaultValue.c_str(), &s[0], max_string_sz, m_configFile.c_str()); + + return s; +} diff --git a/lib/config.h b/lib/config.h index d4e80bc..33b5e87 100644 --- a/lib/config.h +++ b/lib/config.h @@ -14,6 +14,10 @@ public: UINT GetInt(LPCTSTR name, UINT defaultValue = 0); + float GetFloat(LPCTSTR name, float defaultValue = 0.0f); + + std::string GetString(LPCTSTR name, const std::string &defaultValue = std::string()); + private: std::basic_string m_configFile; diff --git a/lib/hooks.cpp b/lib/hooks.cpp index 68a23f4..6425acc 100644 --- a/lib/hooks.cpp +++ b/lib/hooks.cpp @@ -1,5 +1,6 @@ #include "hooks.h" +#include #include #include "../cmn/path.h" @@ -172,9 +173,22 @@ LONG WINAPI InterceptRegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpR // Pass through } else { - MessageBoxA(isleWindow, lpValueName, "ISLE asked for...", 0); + + printf("Passed through requested registry key \"%s\"\n", lpValueName); + } // Pass these through return RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData); } + +void WINAPI InterceptSleep(DWORD dwMilliseconds) +{ + // Do nothing + /*std::string fps_behavior = config.GetString(_T("FPSLimit")); + + if (fps_behavior != "Uncapped") { + // Pass through to default function unless uncapped, in which case no sleep is done at all + Sleep(dwMilliseconds); + }*/ +} diff --git a/lib/hooks.h b/lib/hooks.h index 80f6ee6..986c2a2 100644 --- a/lib/hooks.h +++ b/lib/hooks.h @@ -40,4 +40,6 @@ HRESULT WINAPI InterceptDirectDrawCreate(GUID *lpGUID, LPDIRECTDRAW *lplpDD, IUn HRESULT WINAPI InterceptSurfaceGetDesc(LPDIRECTDRAWSURFACE lpDDSurface, LPDDSURFACEDESC lpDDSurfaceDesc); +VOID WINAPI InterceptSleep(DWORD dwMilliseconds); + #endif // HOOKS_H diff --git a/lib/worker.cpp b/lib/worker.cpp index a2904f9..0f11000 100644 --- a/lib/worker.cpp +++ b/lib/worker.cpp @@ -22,6 +22,8 @@ DWORD WINAPI Patch() OverwriteImport(exeBase, "CreateWindowExA", (LPVOID)InterceptCreateWindowExA); OverwriteImport(dllBase, "OutputDebugStringA", (LPVOID)InterceptOutputDebugStringA); OverwriteImport(exeBase, "RegQueryValueExA", (LPVOID)InterceptRegQueryValueExA); + OverwriteImport(dllBase, "Sleep", (LPVOID)InterceptSleep); + OverwriteImport(exeBase, "Sleep", (LPVOID)InterceptSleep); ddCreateOriginal = (ddCreateFunction)OverwriteImport(dllBase, "DirectDrawCreate", (LPVOID)InterceptDirectDrawCreate); // Stay active when defocused @@ -50,9 +52,45 @@ DWORD WINAPI Patch() SearchReplacePattern(dllBase, "OGEL", "\x0GEL", 4, TRUE); } + // Patch navigation + { + const int nav_block_sz = 0x30; + const char *nav_block_src = "\x28\x00\x00\x00\x6F\x12\x83\x3A\x00\x00\x20\x42\x00\x00\xA0\x41\x00\x00\x70\x41\x00\x00\xF0\x41\x00\x00\x80\x40\x00\x00\x70\x41\x00\x00\x48\x42\x00\x00\x48\x42\xCD\xCC\xCC\x3E\x00\x00\x00\x00"; + char nav_block_dst[nav_block_sz]; + memcpy(nav_block_dst, nav_block_src, nav_block_sz); + UINT32 mouse_deadzone = config.GetInt(_T("MouseDeadzone"), 40); + memcpy(nav_block_dst+0x0, &mouse_deadzone, sizeof(mouse_deadzone)); + float movement_max_spd = config.GetFloat(_T("MovementMaxSpeed"), 40.0f); + memcpy(nav_block_dst+0x8, &movement_max_spd, sizeof(movement_max_spd)); + float turn_max_spd = config.GetFloat(_T("TurnMaxSpeed"), 20.0f); + memcpy(nav_block_dst+0xC, &turn_max_spd, sizeof(turn_max_spd)); + + float movement_max_accel = config.GetFloat(_T("MovementMaxAcceleration"), 15.0f); + memcpy(nav_block_dst+0x10, &movement_max_accel, sizeof(movement_max_accel)); + + float turn_max_accel = config.GetFloat(_T("TurnMaxAcceleration"), 30.0f); + memcpy(nav_block_dst+0x14, &turn_max_accel, sizeof(turn_max_accel)); + + float movement_min_accel = config.GetFloat(_T("MovementMinAcceleration"), 4.0f); + memcpy(nav_block_dst+0x18, &movement_min_accel, sizeof(movement_min_accel)); + + float turn_min_accel = config.GetFloat(_T("TurnMinAcceleration"), 15.0f); + memcpy(nav_block_dst+0x1C, &turn_min_accel, sizeof(turn_min_accel)); + + float movement_decel = config.GetFloat(_T("MovementDeceleration"), 50.0f); + memcpy(nav_block_dst+0x20, &movement_decel, sizeof(movement_decel)); + + float turn_decel = config.GetFloat(_T("TurnDeceleration"), 50.0f); + memcpy(nav_block_dst+0x24, &turn_decel, sizeof(turn_decel)); + + UINT32 turn_use_velocity = config.GetInt(_T("TurnUseVelocity"), FALSE); + memcpy(nav_block_dst+0x2C, &turn_use_velocity, sizeof(turn_use_velocity)); + + SearchReplacePattern(dllBase, nav_block_src, nav_block_dst, nav_block_sz); + } // DDRAW GetSurfaceDesc Override OverwriteCall((LPVOID) ((UINT_PTR)dllBase+0xBA7D5), (LPVOID)InterceptSurfaceGetDesc); diff --git a/src/patchgrid.cpp b/src/patchgrid.cpp index 3c267d4..0aa8370 100644 --- a/src/patchgrid.cpp +++ b/src/patchgrid.cpp @@ -155,12 +155,12 @@ BOOL PatchGrid::SaveConfiguration(LPCTSTR filename) case IT_TEXT: case IT_FILE: case IT_FOLDER: + case IT_COMBO: value = item->m_strValue; break; case IT_BOOLEAN: value = toString(item->m_bValue); break; - case IT_COMBO: case IT_INTEGER: value = toString(item->m_nValue); break;