From 5a551b80b91d176c6787a19ac6e408f7b4649e45 Mon Sep 17 00:00:00 2001 From: Robert Krawczyk Date: Sat, 13 Mar 2021 17:54:49 +0100 Subject: [PATCH] Fix mouse input when using DXVK --- d3d9ex/AutoFix.cpp | 13 +++++++++++-- d3d9ex/Context.cpp | 20 ++++---------------- d3d9ex/Context.h | 5 ++--- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/d3d9ex/AutoFix.cpp b/d3d9ex/AutoFix.cpp index 60c0f59..d2ae0ef 100644 --- a/d3d9ex/AutoFix.cpp +++ b/d3d9ex/AutoFix.cpp @@ -136,12 +136,14 @@ HRESULT MainContext::CreateVertexBuffer(IDirect3DDevice9* pIDirect3DDevice9, UIN return pIDirect3DDevice9->CreateVertexBuffer(Length, Usage, FVF, Pool, ppVertexBuffer, pSharedHandle); } -bool MainContext::OneTimeFixInit(std::unique_ptr& className) +bool MainContext::OneTimeFixInit(std::unique_ptr& className, HWND hWnd) { if (wcscmp(className.get(), L"SQEX.CDev.Engine.Framework.MainWindow") == 0) { otf_init = true; + hWndFF13 = hWnd; + return true; } - return otf_init; + return false; } void MainContext::OneTimeFix() @@ -201,6 +203,10 @@ void MainContext::FF13_InitializeGameAddresses() } void MainContext::FF13_OneTimeFixes() { + + if (IsDXVK()) + SetForegroundWindow(hWndFF13); + FF13_NOPIngameFrameRateLimitSetter(); FF13_RemoveContinuousControllerScan(); FF13_FixScissorRect(); @@ -305,6 +311,9 @@ void MainContext::FF13_SetFrameRateVariables() void MainContext::FF13_2_OneTimeFixes() { + if (IsDXVK()) + SetForegroundWindow(hWndFF13); + if (*ff13_2_frame_pacer_ptr_address) { **ff13_2_frame_pacer_ptr_address = MAX_FRAME_RATE_LIMIT; PrintLog("Frame pacer disabled"); diff --git a/d3d9ex/Context.cpp b/d3d9ex/Context.cpp index f4f0974..b538ed3 100644 --- a/d3d9ex/Context.cpp +++ b/d3d9ex/Context.cpp @@ -203,25 +203,14 @@ bool MainContext::CheckWindow(HWND hWnd) bool class_found = config.GetWindowWindowClass().compare(className.get()) == 0; bool window_found = config.GetWindowWindowName().compare(windowName.get()) == 0; bool force = config.GetBorderlessAllWindows(); - bool ff13fix = OneTimeFixInit(className); + bool ff13fix = OneTimeFixInit(className, hWnd); return class_found || window_found || force || ff13fix; } void MainContext::ApplyWindow(HWND hWnd) { - HWND insertAfter = HWND_TOP; - if (config.GetWindowTopMost() && !context.IsDXVK()) - insertAfter = HWND_TOPMOST; - - SetWindowPos(hWnd, insertAfter, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOCOPYBITS | SWP_NOSENDCHANGING); - SetFocus(hWnd); - - // fixes DXVK window in background, no need to click anymore - if (context.IsDXVK()) - SetForegroundWindow(hWnd); - - if (config.GetOptionsAlwaysActive() || config.GetOptionsHideCursor() || IsDXVK()) + if (config.GetOptionsAlwaysActive() || config.GetOptionsHideCursor()) { context.oldWndProc = (WNDPROC)context.TrueSetWindowLongA(hWnd, GWLP_WNDPROC, (LONG_PTR)context.WindowProc); } @@ -273,7 +262,7 @@ LRESULT CALLBACK MainContext::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP if (context.config.GetOptionsAlwaysActive()) return TRUE; - if (!context.config.GetOptionsForceHideCursor() || context.IsDXVK()) + if (!context.config.GetOptionsForceHideCursor()) while (::ShowCursor(TRUE) < 0); break; } @@ -281,10 +270,9 @@ LRESULT CALLBACK MainContext::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP case WM_ACTIVATEAPP: if (context.config.GetOptionsAlwaysActive()) return TRUE; - } - if (context.config.GetOptionsForceHideCursor() || context.IsDXVK()) + if (context.config.GetOptionsForceHideCursor()) while (::ShowCursor(FALSE) >= 0); return CallWindowProc(context.oldWndProc, hWnd, uMsg, wParam, lParam); diff --git a/d3d9ex/Context.h b/d3d9ex/Context.h index ffe67d6..5f84a54 100644 --- a/d3d9ex/Context.h +++ b/d3d9ex/Context.h @@ -65,8 +65,6 @@ private: enum class AutoFixes : u32 { NONE = 0, - RESIDENT_EVIL_4, - KINGS_BOUNTY_LEGEND, FINAL_FANTASY_XIII, FINAL_FANTASY_XIII2, }; @@ -74,6 +72,7 @@ private: void EnableAutoFix(); AutoFixes autofix = AutoFixes::NONE; + HWND hWndFF13 = 0; std::mutex fix_mutex; @@ -140,7 +139,7 @@ private: void FF13_2_OneTimeFixes(); void FF13_2_EnableControllerVibration(); - bool OneTimeFixInit(std::unique_ptr& className); + bool OneTimeFixInit(std::unique_ptr& className, HWND hWnd); std::atomic_bool otf_init = false; static void Fix_Thread();