From 9518c139564b222cc5e147dc508916d3ebedcc06 Mon Sep 17 00:00:00 2001 From: Maximilian Wittfeld Date: Thu, 16 Jan 2025 18:22:08 +0100 Subject: [PATCH] fix(input/five): DirectInput mouseDev unacquire --- .../rage-input-five/src/InputHook.cpp | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/code/components/rage-input-five/src/InputHook.cpp b/code/components/rage-input-five/src/InputHook.cpp index a52751081a..8eb8bde631 100644 --- a/code/components/rage-input-five/src/InputHook.cpp +++ b/code/components/rage-input-five/src/InputHook.cpp @@ -1,5 +1,4 @@ #include "StdInc.h" -#include "CrossLibraryInterfaces.h" #include "InputHook.h" #include "Hooking.h" @@ -12,9 +11,13 @@ #include #include +#include static WNDPROC origWndProc; +typedef IDirectInputDeviceW* LPDIRECTINPUTDEVICEW; +static LPDIRECTINPUTDEVICEW* g_diMouseDevice = nullptr; + static bool g_isFocused = true; static bool g_enableSetCursorPos = false; static bool g_isFocusStolen = false; @@ -64,6 +67,16 @@ static void EnableFocus() } } +static void (*recaptureLostDevices)(); + +static void RecaptureLostDevices() +{ + if (!g_isFocusStolen) + { + recaptureLostDevices(); + } +} + static bool g_useHostCursor; void EnableHostCursor() @@ -149,6 +162,10 @@ void InputHook::SetGameMouseFocus(bool focus) if (g_isFocusStolen) { + if (*g_diMouseDevice) + { + (*g_diMouseDevice)->Unacquire(); + } memset(g_gameKeyArray, 0, 256); } @@ -720,6 +737,12 @@ static HookFunction hookFunction([]() hook::set_call(&enableFocus, patternMatch); hook::call(patternMatch, EnableFocus); + patternMatch = hook::pattern("48 83 EC ? 8B 0D ? ? ? ? 85 C9 74 ? FF C9 74 ? FF C9 75").count(1).get(0).get(53); + hook::set_call(&recaptureLostDevices, patternMatch); + hook::call(patternMatch, RecaptureLostDevices); + + g_diMouseDevice = hook::get_address(hook::get_pattern("48 8B 0D ? ? ? ? 48 8B 01 FF 50 ? 83 F8 ? 7F ? 48 83 C4", 3)); + // game key array location = hook::pattern("BF 00 01 00 00 48 8D 1D ? ? ? ? 48 3B 05").count(1).get(0).get(8);