diff --git a/CyberXeSS/imgui/Imgui_Base.cpp b/CyberXeSS/imgui/Imgui_Base.cpp index 2b83e4f8..f216fb11 100644 --- a/CyberXeSS/imgui/Imgui_Base.cpp +++ b/CyberXeSS/imgui/Imgui_Base.cpp @@ -6,7 +6,11 @@ #pragma comment(lib, "../detours/detours.lib") PFN_SetCursorPos pfn_SetCursorPos = nullptr; +PFN_mouse_event pfn_mouse_event = nullptr; +PFN_SendInput pfn_SendInput = nullptr; bool pfn_SetCursorPos_hooked = false; +bool pfn_mouse_event_hooked = false; +bool pfn_SendInput_hooked = false; bool _isVisible = false; WNDPROC _oWndProc = nullptr; @@ -19,6 +23,22 @@ BOOL WINAPI hkSetCursorPos(int x, int y) return pfn_SetCursorPos(x, y); } +void WINAPI hkmouse_event(DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo) +{ + if (_isVisible) + return; + else + pfn_mouse_event(dwFlags, dx, dy, dwData, dwExtraInfo); +} + +UINT WINAPI hkSendInput(UINT cInputs, LPINPUT pInputs, int cbSize) +{ + if (_isVisible) + return 0; + else + return pfn_SendInput(cInputs, pInputs, cbSize); +} + void AttachHooks() { DetourTransactionBegin(); @@ -26,10 +46,18 @@ void AttachHooks() // Detour the functions pfn_SetCursorPos = reinterpret_cast(DetourFindFunction("user32.dll", "SetCursorPos")); + pfn_mouse_event = reinterpret_cast(DetourFindFunction("user32.dll", "mouse_event")); + pfn_SendInput = reinterpret_cast(DetourFindFunction("user32.dll", "SendInput")); if (pfn_SetCursorPos) pfn_SetCursorPos_hooked = (DetourAttach(&(PVOID&)pfn_SetCursorPos, hkSetCursorPos) == 0); + if (pfn_mouse_event) + pfn_mouse_event_hooked = (DetourAttach(&(PVOID&)pfn_mouse_event, hkmouse_event) == 0); + + if (pfn_SendInput) + pfn_SendInput_hooked = (DetourAttach(&(PVOID&)pfn_SendInput, hkSendInput) == 0); + DetourTransactionCommit(); } @@ -41,6 +69,20 @@ void DetachHooks() if (pfn_SetCursorPos_hooked) DetourDetach(&(PVOID&)pfn_SetCursorPos, hkSetCursorPos); + if (pfn_mouse_event_hooked) + DetourDetach(&(PVOID&)pfn_mouse_event, hkmouse_event); + + if (pfn_SendInput_hooked) + DetourDetach(&(PVOID&)pfn_SendInput, hkSendInput); + + pfn_SetCursorPos_hooked = false; + pfn_mouse_event_hooked = false; + pfn_SendInput_hooked = false; + + pfn_SetCursorPos = nullptr; + pfn_mouse_event = nullptr; + pfn_SendInput = nullptr; + DetourTransactionCommit(); } @@ -59,7 +101,6 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) io.MouseDrawCursor = _isVisible; io.WantCaptureKeyboard = _isVisible; io.WantCaptureMouse = _isVisible; - io.WantSetMousePos = _isVisible; return true; } @@ -641,10 +682,10 @@ Imgui_Base::~Imgui_Base() SetWindowLongPtr((HWND)ImGui::GetMainViewport()->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)_oWndProc); _oWndProc = nullptr; - ImGui_ImplWin32_Shutdown(); - if (pfn_SetCursorPos_hooked) DetachHooks(); + + ImGui_ImplWin32_Shutdown(); } ImGui::DestroyContext(context); diff --git a/CyberXeSS/imgui/Imgui_Base.h b/CyberXeSS/imgui/Imgui_Base.h index 2d3792dd..e0e5120a 100644 --- a/CyberXeSS/imgui/Imgui_Base.h +++ b/CyberXeSS/imgui/Imgui_Base.h @@ -3,6 +3,8 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); typedef BOOL(WINAPI* PFN_SetCursorPos)(int x, int y); +typedef UINT(WINAPI* PFN_SendInput)(UINT cInputs, LPINPUT pInputs, int cbSize); +typedef void(WINAPI* PFN_mouse_event)(DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo); class Imgui_Base {