implemented more patches

This commit is contained in:
itsmattkc 2021-10-18 10:15:56 -07:00
parent f0904e54b9
commit 7daa030991
6 changed files with 86 additions and 2 deletions

View file

@ -1,6 +1,8 @@
#include "config.h"
#include <SHLWAPI.H>
#include <SSTREAM>
#include <STRING>
#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;
}

View file

@ -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<TCHAR> m_configFile;

View file

@ -1,5 +1,6 @@
#include "hooks.h"
#include <MATH.H>
#include <STDIO.H>
#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);
}*/
}

View file

@ -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

View file

@ -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);

View file

@ -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;