Skip to content

Commit 53fd18f

Browse files
committed
rage:input/gta:core: fixes SetCursorLocation native by temporarily re-enabling SetCursorPos during native invocation
1 parent 2a24424 commit 53fd18f

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

code/components/gta-core-five/component.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"rage:allocator:five",
77
"rage:nutsnbolts:five",
88
"rage:scripting:five",
9+
"rage:input:five",
910
"vendor:minhook"
1011
],
1112
"provides": []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include "StdInc.h"
2+
3+
#include "scrEngine.h"
4+
#include "InputHook.h"
5+
6+
rage::scrEngine::NativeHandler m_origSetCursorLocation;
7+
static HookFunction hookFunction([]()
8+
{
9+
//_SET_CURSOR_LOCATION
10+
rage::scrEngine::OnScriptInit.Connect([]()
11+
{
12+
m_origSetCursorLocation = rage::scrEngine::GetNativeHandler(0xFC695459D4D0E219);
13+
rage::scrEngine::RegisterNativeHandler(0xFC695459D4D0E219, [](rage::scrNativeCallContext* context)
14+
{
15+
InputHook::EnableSetCursorPos(true);
16+
(*m_origSetCursorLocation)(context);
17+
InputHook::EnableSetCursorPos(false);
18+
});
19+
});
20+
21+
});

code/components/rage-input-five/include/InputHook.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ namespace InputHook
1313
extern INPUT_DECL fwEvent<int&> QueryMayLockCursor;
1414

1515
INPUT_DECL void SetGameMouseFocus(bool focus);
16-
}
16+
17+
INPUT_DECL void EnableSetCursorPos(bool enabled);
18+
}

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
static WNDPROC origWndProc;
77

88
static bool g_isFocused = true;
9+
static bool g_enableSetCursorPos = false;
910
static bool g_isFocusStolen = false;
1011

1112
static void(*disableFocus)();
@@ -35,6 +36,10 @@ void InputHook::SetGameMouseFocus(bool focus)
3536
return (focus) ? enableFocus() : disableFocus();
3637
}
3738

39+
void InputHook::EnableSetCursorPos(bool enabled) {
40+
g_enableSetCursorPos = enabled;
41+
}
42+
3843
static char* g_gameKeyArray;
3944

4045
#include <LaunchMode.h>
@@ -121,14 +126,16 @@ HKL WINAPI ActivateKeyboardLayoutWrap(IN HKL hkl, IN UINT flags)
121126

122127
BOOL WINAPI SetCursorPosWrap(int X, int Y)
123128
{
124-
if (!g_isFocused)
129+
if (!g_isFocused || g_enableSetCursorPos)
125130
{
126131
return SetCursorPos(X, Y);
127132
}
128133

129134
return TRUE;
130135
}
131136

137+
138+
132139
static HookFunction hookFunction([] ()
133140
{
134141
// window procedure

0 commit comments

Comments
 (0)