Skip to content

Commit 7a6ab03

Browse files
committed
Merge DirectInput mouseDev unacquire (pr-3072)
9518c13 - fix(input/five): DirectInput mouseDev unacquire
2 parents 7b6e04d + 9518c13 commit 7a6ab03

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

code/components/rage-input-five/src/InputHook.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212

1313
#include <ICoreGameInit.h>
1414
#include <GlobalInput.h>
15+
#include <dinput.h>
1516

1617
#include "ffx_antilag2_dx11.h"
1718

1819
static WNDPROC origWndProc;
1920

21+
typedef IDirectInputDeviceW* LPDIRECTINPUTDEVICEW;
22+
static LPDIRECTINPUTDEVICEW* g_diMouseDevice = nullptr;
23+
2024
static bool g_isFocused = true;
2125
static bool g_enableSetCursorPos = false;
2226
static bool g_isFocusStolen = false;
@@ -66,6 +70,16 @@ static void EnableFocus()
6670
}
6771
}
6872

73+
static void (*recaptureLostDevices)();
74+
75+
static void RecaptureLostDevices()
76+
{
77+
if (!g_isFocusStolen)
78+
{
79+
recaptureLostDevices();
80+
}
81+
}
82+
6983
static bool g_useHostCursor;
7084

7185
void EnableHostCursor()
@@ -151,6 +165,10 @@ void InputHook::SetGameMouseFocus(bool focus)
151165

152166
if (g_isFocusStolen)
153167
{
168+
if (*g_diMouseDevice)
169+
{
170+
(*g_diMouseDevice)->Unacquire();
171+
}
154172
memset(g_gameKeyArray, 0, 256);
155173
}
156174

@@ -736,6 +754,12 @@ static HookFunction hookFunction([]()
736754
hook::set_call(&enableFocus, patternMatch);
737755
hook::call(patternMatch, EnableFocus);
738756

757+
patternMatch = hook::pattern("48 83 EC ? 8B 0D ? ? ? ? 85 C9 74 ? FF C9 74 ? FF C9 75").count(1).get(0).get<void>(53);
758+
hook::set_call(&recaptureLostDevices, patternMatch);
759+
hook::call(patternMatch, RecaptureLostDevices);
760+
761+
g_diMouseDevice = hook::get_address<LPDIRECTINPUTDEVICEW*>(hook::get_pattern("48 8B 0D ? ? ? ? 48 8B 01 FF 50 ? 83 F8 ? 7F ? 48 83 C4", 3));
762+
739763
// game key array
740764
location = hook::pattern("BF 00 01 00 00 48 8D 1D ? ? ? ? 48 3B 05").count(1).get(0).get<char>(8);
741765

0 commit comments

Comments
 (0)