From f8258b61d5e423f1b9d51950c6ca75eb7b09ddff Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 20 Sep 2015 22:25:10 +0200 Subject: [PATCH] Mouse recentering fix for VC --- SilentPatchVC/SilentPatchVC.cpp | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/SilentPatchVC/SilentPatchVC.cpp b/SilentPatchVC/SilentPatchVC.cpp index d20671c..f97692f 100644 --- a/SilentPatchVC/SilentPatchVC.cpp +++ b/SilentPatchVC/SilentPatchVC.cpp @@ -16,6 +16,12 @@ struct RsGlobalType void* pad; }; +struct RwV2d +{ + float x; /**< X value*/ + float y; /**< Y value */ +}; + bool* bSnapShotActive; static const void* RosieAudioFix_JumpBack; @@ -49,6 +55,37 @@ void __declspec(naked) RosiesAudioFix() } } +static bool bGameInFocus = true; + +static LRESULT (CALLBACK **OldWndProc)(HWND, UINT, WPARAM, LPARAM); +LRESULT CALLBACK CustomWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch ( uMsg ) + { + case WM_KILLFOCUS: + bGameInFocus = false; + break; + case WM_SETFOCUS: + bGameInFocus = true; + break; + } + + return (*OldWndProc)(hwnd, uMsg, wParam, lParam); +} +static auto* pCustomWndProc = CustomWndProc; + +static void (* const ConstructRenderList)() = AddressByVersion(0x4CA260, 0x4CA280, 0x4CA120); +static void (* const RsMouseSetPos)(RwV2d*) = AddressByVersion(0x6030C0, 0x6030A0, 0x602CE0); +void ResetMousePos() +{ + if ( bGameInFocus ) + { + RwV2d vecPos = { RsGlobal->MaximumWidth * 0.5f, RsGlobal->MaximumHeight * 0.5f }; + RsMouseSetPos(&vecPos); + } + ConstructRenderList(); +} + void __stdcall Recalculate(float& fX, float& fY, signed int nShadow) { fX = nShadow * GetWidthMult() * RsGlobal->MaximumWidth; @@ -222,6 +259,13 @@ void Patch_VC_10(const RECT& desktop) InjectHook(0x601A40, GetMyDocumentsPath, PATCH_CALL); InjectHook(0x601A45, 0x601B2F, PATCH_JUMP); + + // RsMouseSetPos call (SA style fix) + InjectHook(0x4A5E45, ResetMousePos); + + // New wndproc + OldWndProc = *(LRESULT (CALLBACK***)(HWND, UINT, WPARAM, LPARAM))0x601727; + Patch(0x601727, &pCustomWndProc); } void Patch_VC_11(const RECT& desktop) @@ -308,6 +352,13 @@ void Patch_VC_11(const RECT& desktop) InjectHook(0x601A70, GetMyDocumentsPath, PATCH_CALL); InjectHook(0x601A75, 0x601B5F, PATCH_JUMP); + + // RsMouseSetPos call (SA style fix) + InjectHook(0x4A5E65, ResetMousePos); + + // New wndproc + OldWndProc = *(LRESULT (CALLBACK***)(HWND, UINT, WPARAM, LPARAM))0x601757; + Patch(0x601757, &pCustomWndProc); } void Patch_VC_Steam(const RECT& desktop) @@ -394,6 +445,13 @@ void Patch_VC_Steam(const RECT& desktop) InjectHook(0x6016B0, GetMyDocumentsPath, PATCH_CALL); InjectHook(0x6016B5, 0x60179F, PATCH_JUMP); + + // RsMouseSetPos call (SA style fix) + InjectHook(0x4A5D15, ResetMousePos); + + // New wndproc + OldWndProc = *(LRESULT (CALLBACK***)(HWND, UINT, WPARAM, LPARAM))0x601397; + Patch(0x601397, &pCustomWndProc); } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)