From fdeb5912d3e1373999f1a43c63296c08002ea1c0 Mon Sep 17 00:00:00 2001 From: Nemirtingas Date: Sun, 18 Aug 2019 14:29:08 +0200 Subject: [PATCH] Try to Disable all inputs when overlay is on --- overlay_experimental/steam_overlay.cpp | 44 ++++++++++++++++++++------ overlay_experimental/steam_overlay.h | 2 ++ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/overlay_experimental/steam_overlay.cpp b/overlay_experimental/steam_overlay.cpp index ed53221..8a69180 100644 --- a/overlay_experimental/steam_overlay.cpp +++ b/overlay_experimental/steam_overlay.cpp @@ -16,6 +16,9 @@ #include "notification.h" +static decltype(GetRawInputBuffer)* _GetRawInputBuffer = GetRawInputBuffer; +static decltype(GetRawInputData)* _GetRawInputData = GetRawInputData; + extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); bool Steam_Overlay::IgnoreMsg(UINT uMsg) @@ -134,20 +137,43 @@ void Steam_Overlay::SetupOverlay() Hook_Manager::Inst().HookRenderer(this); } +UINT WINAPI Steam_Overlay::MyGetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader) +{ + Steam_Overlay* _this = Hook_Manager::Inst().GetOverlay(); + if( !_this->show_overlay ) + return _GetRawInputBuffer(pData, pcbSize, cbSizeHeader); + + return -1; +} + +UINT WINAPI Steam_Overlay::MyGetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader) +{ + Steam_Overlay* _this = Hook_Manager::Inst().GetOverlay(); + if (!_this->show_overlay) + return _GetRawInputData(hRawInput, uiCommand, pData, pcbSize, cbSizeHeader); + + return -1; +} + void Steam_Overlay::HookReady(void* hWnd) { if (game_hwnd != hWnd) { if (!is_ready) // If this is the first time we are ready, hook directinput and xinput, so we can intercept em and disable mouse. { - //window_hooks.BeginHook(); - // - //window_hooks.HookFuncs(std::make_pair(&(PVOID&)_DispatchMessageA, &Steam_Overlay::MyDispatchMessageA), - // std::make_pair(&(PVOID&)_DispatchMessageW, &Steam_Overlay::MyDispatchMessageW) - // // Add XInput and DirectInput hooks to catch all mouse & controllers input when overlay is on - // ); - // - //window_hooks.EndHook(); + window_hooks.BeginHook(); + + window_hooks.HookFuncs(std::make_pair(&(PVOID&)_GetRawInputBuffer, &MyGetRawInputBuffer), + std::make_pair(&(PVOID&)_GetRawInputData, &MyGetRawInputData) + ); + + window_hooks.EndHook(); + + // TODO: Uncomment this and draw our own cursor (cosmetics) + //ImGuiIO &io = ImGui::GetIO(); + //io.WantSetMousePos = false; + //io.MouseDrawCursor = false; + //io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange; is_ready = true; } @@ -181,7 +207,7 @@ void Steam_Overlay::ShowOverlay(bool state) if (!Ready() || show_overlay == state) return; - + show_overlay = state; if (show_overlay) { diff --git a/overlay_experimental/steam_overlay.h b/overlay_experimental/steam_overlay.h index 914e7f0..fde2b9e 100644 --- a/overlay_experimental/steam_overlay.h +++ b/overlay_experimental/steam_overlay.h @@ -73,6 +73,8 @@ class Steam_Overlay bool IgnoreMsg(UINT uMsg); 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 void steam_overlay_run_every_runcb(void* object); static void steam_overlay_callback(void* object, Common_Message* msg);