Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input/five): DirectInput mouseDev unacquire #3072

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion code/components/rage-input-five/src/InputHook.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "StdInc.h"
#include "CrossLibraryInterfaces.h"
#include "InputHook.h"
#include "Hooking.h"

Expand All @@ -12,9 +11,13 @@

#include <ICoreGameInit.h>
#include <GlobalInput.h>
#include <dinput.h>

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;
Expand Down Expand Up @@ -64,6 +67,16 @@ static void EnableFocus()
}
}

static void (*recaptureLostDevices)();

static void RecaptureLostDevices()
{
if (!g_isFocusStolen)
{
recaptureLostDevices();
}
}

static bool g_useHostCursor;

void EnableHostCursor()
Expand Down Expand Up @@ -149,6 +162,10 @@ void InputHook::SetGameMouseFocus(bool focus)

if (g_isFocusStolen)
{
if (*g_diMouseDevice)
{
(*g_diMouseDevice)->Unacquire();
}
memset(g_gameKeyArray, 0, 256);
}

Expand Down Expand Up @@ -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<void>(53);
hook::set_call(&recaptureLostDevices, patternMatch);
hook::call(patternMatch, RecaptureLostDevices);

g_diMouseDevice = hook::get_address<LPDIRECTINPUTDEVICEW*>(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<char>(8);

Expand Down
Loading