From 5f8a454e3f45294194ea5f9627df11a75f52af7f Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Sat, 6 Feb 2021 22:38:51 -0500 Subject: [PATCH] Fixed mouse getting stuck in the middle of the overlay in some games. --- overlay_experimental/windows/Windows_Hook.cpp | 16 +++++++++++++++- overlay_experimental/windows/Windows_Hook.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/overlay_experimental/windows/Windows_Hook.cpp b/overlay_experimental/windows/Windows_Hook.cpp index f273c5e7..4127aeca 100644 --- a/overlay_experimental/windows/Windows_Hook.cpp +++ b/overlay_experimental/windows/Windows_Hook.cpp @@ -18,13 +18,15 @@ bool Windows_Hook::start_hook() { GetRawInputBuffer = ::GetRawInputBuffer; GetRawInputData = ::GetRawInputData; + SetCursorPos = ::SetCursorPos; PRINT_DEBUG("Hooked Windows\n"); BeginHook(); HookFuncs( std::make_pair(&(PVOID&)GetRawInputBuffer, &Windows_Hook::MyGetRawInputBuffer), - std::make_pair(&(PVOID&)GetRawInputData , &Windows_Hook::MyGetRawInputData) + std::make_pair(&(PVOID&)GetRawInputData , &Windows_Hook::MyGetRawInputData), + std::make_pair(&(PVOID&)SetCursorPos , &Windows_Hook::MySetCursorPos) ); EndHook(); @@ -169,6 +171,18 @@ UINT WINAPI Windows_Hook::MyGetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, return 0; } + +BOOL WINAPI Windows_Hook::MySetCursorPos(int x, int y) +{ + if (get_steam_client()->steam_overlay->ShowOverlay()) { + POINT p; + GetCursorPos(&p); + x = p.x; + y = p.y; + } + + return Windows_Hook::Inst()->SetCursorPos(x, y); +} ///////////////////////////////////////////////////////////////////////////////////// Windows_Hook::Windows_Hook() : diff --git a/overlay_experimental/windows/Windows_Hook.h b/overlay_experimental/windows/Windows_Hook.h index 631edf30..0547dfc3 100644 --- a/overlay_experimental/windows/Windows_Hook.h +++ b/overlay_experimental/windows/Windows_Hook.h @@ -26,11 +26,13 @@ private: // Hook to Windows window messages decltype(GetRawInputBuffer)* GetRawInputBuffer; decltype(GetRawInputData)* GetRawInputData; + decltype(SetCursorPos)* SetCursorPos; static LRESULT CALLBACK HookWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static UINT WINAPI MyGetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader); static UINT WINAPI MyGetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader); + static BOOL WINAPI MySetCursorPos(int x, int y); public: virtual ~Windows_Hook();