Skip to content

Commit

Permalink
Attempted fix for Kingdom Come Deliverance 2 mouse cursor issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Feb 16, 2025
1 parent b8e1efa commit bae50e5
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 10 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
25.2.13
25.2.15
=======
+ Attempted fix for Kingdom Come Deliverance 2 mouse cursor issues.

25.2.13
=======
+ Added BsSndRpt64.exe to internal injection blacklist; some kind of bs
crash handler for Kingdom Come Deliverance 2.
Expand Down
2 changes: 1 addition & 1 deletion include/SpecialK/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#define SK_YEAR 25
#define SK_MONTH 2
#define SK_DATE 13
#define SK_DATE 15
#define SK_REV_N 0
#define SK_REV 0

Expand Down
1 change: 1 addition & 0 deletions include/SpecialK/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,7 @@ struct sk_config_t
bool capture_keyboard = false; // ^^^ Disabled by default because it interferes with cursor auto-hide
bool capture_gamepad = false;
bool use_hw_cursor = true;
bool ignore_set_cursor = false;
bool center_cursor = false;
bool nav_moves_mouse = false;
int game_set_hw_cursor = 0; // Not stored in INI, the number of times
Expand Down
2 changes: 1 addition & 1 deletion include/imgui/imgui_user.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ ImGui_WndProcHandler ( HWND hWnd, UINT msg,
}
}

if (msg == WM_SETCURSOR)
if (msg == WM_SETCURSOR && (! config.input.ui.ignore_set_cursor))
{
//SK_LOG0 ( (L"ImGui Witnessed WM_SETCURSOR"), L"Window Mgr" );

Expand Down
1 change: 1 addition & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,7 @@ auto DeclKeybind =

config.input.ui.use_hw_cursor = false; // Prevent the game's cursor from doing whatever
config.render.d3d12.force_anisotropic = false;
config.input.ui.ignore_set_cursor = true;

// Sick of users complaining about bugs that -were- fixed because they can't be bothered to
// reset their INI after defaults are changed to fix the problems... so we're going to be
Expand Down
4 changes: 4 additions & 0 deletions src/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8822,6 +8822,9 @@ SK_ImGui_Toggle (void)

static auto Send_WM_SETCURSOR = [&](void)
{
if (config.input.ui.ignore_set_cursor)
return;

SK_COMPAT_SafeCallProc (&game_window,
game_window.hWnd, WM_SETCURSOR,
(WPARAM)game_window.hWnd, MAKELPARAM (HTCLIENT, WM_MOUSEMOVE));
Expand Down Expand Up @@ -8879,6 +8882,7 @@ SK_ImGui_Toggle (void)
SK_CreateEvent (nullptr, FALSE, FALSE, nullptr)
);

if (! config.input.ui.ignore_set_cursor)
SK_RunOnce (
SK_Thread_CreateEx ([](LPVOID) -> DWORD
{
Expand Down
31 changes: 29 additions & 2 deletions src/input/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ HCURSOR
WINAPI
SK_SendMsgSetCursor (HCURSOR hCursor)
{
if (config.input.ui.ignore_set_cursor)
return SK_GetCursor ();

if (game_window.hWnd != 0 && IsWindow (game_window.hWnd))
{
HCURSOR hLastCursor =
Expand Down Expand Up @@ -873,6 +876,9 @@ ImGui_ToggleCursor (void)
// Restore the game's cursor
static auto Send_WM_SETCURSOR = [&](void)
{
if (config.input.ui.ignore_set_cursor)
return;

SK_COMPAT_SafeCallProc (&game_window,
game_window.hWnd, WM_SETCURSOR,
(WPARAM)game_window.hWnd, MAKELPARAM (HTCLIENT, WM_MOUSEMOVE));
Expand Down Expand Up @@ -950,6 +956,12 @@ SetCursor_Detour (
{
SK_LOG_FIRST_CALL

if (config.input.ui.ignore_set_cursor)
{
return
SetCursor_Original (hCursor);
}

if (hCursor != 0)
SK_ImGui_Cursor.times_set++;

Expand All @@ -972,8 +984,11 @@ GetCursor_Detour (VOID)
{
SK_LOG_FIRST_CALL

//return
// GetCursor_Original ();
if (config.input.ui.ignore_set_cursor)
{
return
GetCursor_Original ();
}

static auto& io =
ImGui::GetIO ();
Expand Down Expand Up @@ -1025,6 +1040,12 @@ GetCursorInfo_Detour (PCURSORINFO pci)
{
SK_LOG_FIRST_CALL

if (config.input.ui.ignore_set_cursor)
{
return
SK_GetCursorInfo (pci);
}

POINT pt = pci->ptScreenPos;
BOOL ret = SK_GetCursorInfo (pci);

Expand Down Expand Up @@ -1344,6 +1365,9 @@ SK_Window_IsCursorActive (void)
bool
SK_Window_ActivateCursor (bool changed)
{
if (config.input.ui.ignore_set_cursor)
return true;

const bool was_active = last_mouse.cursor;

if (! was_active)
Expand Down Expand Up @@ -1373,6 +1397,9 @@ SK_Window_ActivateCursor (bool changed)
bool
SK_Window_DeactivateCursor (bool ignore_imgui)
{
if (config.input.ui.ignore_set_cursor)
return true;

if (! ignore_imgui)
{
if ( SK_ImGui_WantMouseCaptureEx (0xFFFFFFFF & ~REASON_DISABLED) ||
Expand Down
9 changes: 6 additions & 3 deletions src/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,12 @@ SK_ImGui_HandlesMessage (MSG *lpMsg, bool /*remove*/, bool /*peek*/)

case WM_SETCURSOR:
{
handled =
( 0 != ImGui_WndProcHandler (lpMsg->hwnd, lpMsg->message,
lpMsg->wParam, lpMsg->lParam) );
if (! config.input.ui.ignore_set_cursor)
{
handled =
( 0 != ImGui_WndProcHandler (lpMsg->hwnd, lpMsg->message,
lpMsg->wParam, lpMsg->lParam) );
}
} break;


Expand Down
4 changes: 2 additions & 2 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5963,7 +5963,7 @@ SK_DetourWindowProc ( _In_ HWND hWnd,

case WM_SETCURSOR:
{
if (hWnd == game_window.hWnd && HIWORD (lParam) != WM_NULL)
if ((! config.input.ui.ignore_set_cursor) && hWnd == game_window.hWnd && HIWORD (lParam) != WM_NULL)
{
if (LOWORD (lParam) == HTCLIENT)
{
Expand Down Expand Up @@ -8628,7 +8628,7 @@ SK_Win32_BackgroundWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
}
break;
case WM_SETCURSOR:
if (game_window.active)
if (game_window.active && (! config.input.ui.ignore_set_cursor))
{
SetCursor (NULL);
return TRUE;
Expand Down

0 comments on commit bae50e5

Please sign in to comment.