Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rage:input/gta:core: fixes SetCursorLocation native by temporarily re…
…-enabling SetCursorPos during native invocation
  • Loading branch information
bladecoding committed Apr 29, 2019
1 parent 2a24424 commit 53fd18f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions code/components/gta-core-five/component.json
Expand Up @@ -6,6 +6,7 @@
"rage:allocator:five",
"rage:nutsnbolts:five",
"rage:scripting:five",
"rage:input:five",
"vendor:minhook"
],
"provides": []
Expand Down
21 changes: 21 additions & 0 deletions code/components/gta-core-five/src/SetCursorLocation.cpp
@@ -0,0 +1,21 @@
#include "StdInc.h"

#include "scrEngine.h"
#include "InputHook.h"

rage::scrEngine::NativeHandler m_origSetCursorLocation;
static HookFunction hookFunction([]()
{
//_SET_CURSOR_LOCATION
rage::scrEngine::OnScriptInit.Connect([]()
{
m_origSetCursorLocation = rage::scrEngine::GetNativeHandler(0xFC695459D4D0E219);
rage::scrEngine::RegisterNativeHandler(0xFC695459D4D0E219, [](rage::scrNativeCallContext* context)
{
InputHook::EnableSetCursorPos(true);
(*m_origSetCursorLocation)(context);
InputHook::EnableSetCursorPos(false);
});
});

});
4 changes: 3 additions & 1 deletion code/components/rage-input-five/include/InputHook.h
Expand Up @@ -13,4 +13,6 @@ namespace InputHook
extern INPUT_DECL fwEvent<int&> QueryMayLockCursor;

INPUT_DECL void SetGameMouseFocus(bool focus);
}

INPUT_DECL void EnableSetCursorPos(bool enabled);
}
9 changes: 8 additions & 1 deletion code/components/rage-input-five/src/InputHook.cpp
Expand Up @@ -6,6 +6,7 @@
static WNDPROC origWndProc;

static bool g_isFocused = true;
static bool g_enableSetCursorPos = false;
static bool g_isFocusStolen = false;

static void(*disableFocus)();
Expand Down Expand Up @@ -35,6 +36,10 @@ void InputHook::SetGameMouseFocus(bool focus)
return (focus) ? enableFocus() : disableFocus();
}

void InputHook::EnableSetCursorPos(bool enabled) {
g_enableSetCursorPos = enabled;
}

static char* g_gameKeyArray;

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

BOOL WINAPI SetCursorPosWrap(int X, int Y)
{
if (!g_isFocused)
if (!g_isFocused || g_enableSetCursorPos)
{
return SetCursorPos(X, Y);
}

return TRUE;
}



static HookFunction hookFunction([] ()
{
// window procedure
Expand Down

0 comments on commit 53fd18f

Please sign in to comment.