From a5636bef12cef8f5a5f4df9924e77e671fb91fb2 Mon Sep 17 00:00:00 2001 From: narzoul Date: Sun, 30 Jun 2024 10:42:49 +0200 Subject: [PATCH] Fixed hotkeys not working with default dinput8 keyboard hook Fixes hotkeys not working in Beach Life after intro movie. --- DDrawCompat/Common/Log.cpp | 3 +-- DDrawCompat/Input/Input.cpp | 20 ++++++++++++++++++++ DDrawCompat/Win32/Log.cpp | 9 +++++++++ DDrawCompat/Win32/Log.h | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/DDrawCompat/Common/Log.cpp b/DDrawCompat/Common/Log.cpp index 873608f..a12ea1b 100644 --- a/DDrawCompat/Common/Log.cpp +++ b/DDrawCompat/Common/Log.cpp @@ -10,8 +10,7 @@ namespace { Compat::CriticalSection g_logCs; std::ofstream g_logFile; - static std::ostringstream g_initialLogStream; - + std::ostringstream g_initialLogStream; } namespace Compat diff --git a/DDrawCompat/Input/Input.cpp b/DDrawCompat/Input/Input.cpp index 2bb5fad..0b6e8cd 100644 --- a/DDrawCompat/Input/Input.cpp +++ b/DDrawCompat/Input/Input.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -249,6 +250,24 @@ namespace return { MulDiv(pt.x, 100, dpiScale), MulDiv(pt.y, 100, dpiScale) }; } + BOOL WINAPI registerRawInputDevices(PCRAWINPUTDEVICE pRawInputDevices, UINT uiNumDevices, UINT cbSize) + { + LOG_FUNC("RegisterRawInputDevices", Compat::array(pRawInputDevices, uiNumDevices), uiNumDevices, cbSize); + if (1 == uiNumDevices && + HID_USAGE_PAGE_GENERIC == pRawInputDevices->usUsagePage && + HID_USAGE_GENERIC_KEYBOARD == pRawInputDevices->usUsage && + pRawInputDevices->hwndTarget) + { + char className[32] = {}; + GetClassNameA(pRawInputDevices->hwndTarget, className, sizeof(className)); + if (0 == strcmp(className, "DIEmWin")) + { + return LOG_RESULT(FALSE); + } + } + return LOG_RESULT(CALL_ORIG_FUNC(RegisterRawInputDevices)(pRawInputDevices, uiNumDevices, cbSize)); + } + void resetKeyboardHook() { Gdi::GuiThread::execute([]() @@ -421,6 +440,7 @@ namespace Input g_physicalToLogicalPointForPerMonitorDPI = reinterpret_cast( GetProcAddress(GetModuleHandle("user32"), "PhysicalToLogicalPointForPerMonitorDPI")); + HOOK_FUNCTION(user32, RegisterRawInputDevices, registerRawInputDevices); HOOK_FUNCTION(user32, SetCursorPos, setCursorPos); HOOK_FUNCTION(user32, SetWindowsHookExA, setWindowsHookExA); HOOK_FUNCTION(user32, SetWindowsHookExW, setWindowsHookExW); diff --git a/DDrawCompat/Win32/Log.cpp b/DDrawCompat/Win32/Log.cpp index 5ec97dc..ff4ca0d 100644 --- a/DDrawCompat/Win32/Log.cpp +++ b/DDrawCompat/Win32/Log.cpp @@ -462,6 +462,15 @@ std::ostream& operator<<(std::ostream& os, const POINTS& p) << p.y; } +std::ostream& operator<<(std::ostream& os, const RAWINPUTDEVICE& input) +{ + return Compat::LogStruct(os) + << Compat::hex(input.usUsagePage) + << Compat::hex(input.usUsage) + << Compat::hex(input.dwFlags) + << input.hwndTarget; +} + std::ostream& operator<<(std::ostream& os, const RECT& rect) { return Compat::LogStruct(os) diff --git a/DDrawCompat/Win32/Log.h b/DDrawCompat/Win32/Log.h index bdd0c20..08bc1b4 100644 --- a/DDrawCompat/Win32/Log.h +++ b/DDrawCompat/Win32/Log.h @@ -42,6 +42,7 @@ std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOEXA& vi); std::ostream& operator<<(std::ostream& os, const OSVERSIONINFOEXW& vi); std::ostream& operator<<(std::ostream& os, const POINT& p); std::ostream& operator<<(std::ostream& os, const POINTS& p); +std::ostream& operator<<(std::ostream& os, const RAWINPUTDEVICE& input); std::ostream& operator<<(std::ostream& os, const RECT& rect); std::ostream& operator<<(std::ostream& os, const SIZE& size); std::ostream& operator<<(std::ostream& os, const STYLESTRUCT& ss);