diff --git a/include/SpecialK/render/d3d11/d3d11_core.h b/include/SpecialK/render/d3d11/d3d11_core.h index 156fc3826..04916bc59 100644 --- a/include/SpecialK/render/d3d11/d3d11_core.h +++ b/include/SpecialK/render/d3d11/d3d11_core.h @@ -297,7 +297,7 @@ SK_D3D11_IgnoreWrappedOrDeferred ( bool bWrapped, pLastVerdict = _pLastVerdict; } - const SK_RenderBackend& rb = + SK_RenderBackend& rb = SK_GetCurrentRenderBackend (); if ((! bWrapped) && ( rb.d3d11.immediate_ctx == nullptr || (pDevCtx != rb.d3d11.immediate_ctx && !config.reshade.is_addon))) [[unlikely]] @@ -305,14 +305,17 @@ SK_D3D11_IgnoreWrappedOrDeferred ( bool bWrapped, if ( rb.d3d11.immediate_ctx == nullptr || rb.device.p == nullptr ) { - if (config.system.log_level > 2) + if (rb.swapchain.p != nullptr) { - SK_ReleaseAssert (!"Hooked command ignored while render backend is uninitialized"); - } + if (config.system.log_level > 2) + { + SK_ReleaseAssert (!"Hooked command ignored while render backend is uninitialized"); + } - pLastVerdict->first = nullptr; + pLastVerdict->first = nullptr; - return true; + return true; + } } #if 1 @@ -343,7 +346,12 @@ SK_D3D11_IgnoreWrappedOrDeferred ( bool bWrapped, //if (! rb.getDevice ().IsEqualObject (pDevice)) if (rb.device.p != pDev && (! config.reshade.is_addon)) { - if (! SK_D3D11_EnsureMatchingDevices ((ID3D11Device *)rb.device.p, pDev)) + if (rb.device.p == nullptr) + { + rb.device = pDev; + } + + else if (! SK_D3D11_EnsureMatchingDevices ((ID3D11Device *)rb.device.p, pDev)) { if (config.system.log_level > 2) { diff --git a/src/core.cpp b/src/core.cpp index c9a14b945..829d41b01 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -991,7 +991,8 @@ SK_InitFinishCallback (void) SK_EnableApplyQueuedHooks (); - if (ReadULongAcquire (&SK_MinHook_HooksQueuedButNotApplied) > 0) + if (int32_t hooks_queued = (int32_t)ReadULongAcquire (&SK_MinHook_HooksQueuedButNotApplied); + hooks_queued > 0) { SK_ApplyQueuedHooks (); } @@ -2445,7 +2446,8 @@ SK_StartupCore (const wchar_t* backend, void* callback) &init_ ) ); // Avoid the temptation to wait on this thread - if (ReadULongAcquire (&SK_MinHook_HooksQueuedButNotApplied) > 0) + if (int32_t hooks_queued = (int32_t)ReadULongAcquire (&SK_MinHook_HooksQueuedButNotApplied); + hooks_queued > 0) { SK_ApplyQueuedHooks (); } @@ -4133,11 +4135,6 @@ HRESULT __stdcall SK_EndBufferSwap (HRESULT hr, IUnknown* device, SK_TLS* pTLS) { - if (ReadULongAcquire (&SK_MinHook_HooksQueuedButNotApplied) > 0) - { - SK_ApplyQueuedHooks (); - } - auto qpcTimeOfSwap = SK_QueryPerf (); @@ -4239,6 +4236,12 @@ SK_EndBufferSwap (HRESULT hr, IUnknown* device, SK_TLS* pTLS) SK_StartPerfMonThreads (); + if (int32_t hooks_queued = (int32_t)ReadULongAcquire (&SK_MinHook_HooksQueuedButNotApplied); + hooks_queued > 0) + { + SK_ApplyQueuedHooks (); + } + if (pTLS == nullptr) pTLS = diff --git a/src/diagnostics/debug_utils.cpp b/src/diagnostics/debug_utils.cpp index d678e77ea..63a62b284 100644 --- a/src/diagnostics/debug_utils.cpp +++ b/src/diagnostics/debug_utils.cpp @@ -290,7 +290,7 @@ SK_Module_IsProcAddrLocal ( HMODULE hModExpected, // DefWindowProc{A|W} being located in ntdll.dll is // a known thing, we don't need log spam. - if (! StrStrIW (ucs_full.c_str (), L"DefWindowProc")) + if (! StrStrIA (lpProcName, "DefWindowProc")) { SK_LOG0 ( ( LR"(Procedure: '%hs' located by NtLdr in '%ws')", lpProcName, ucs_full.c_str () ), diff --git a/src/hooks.cpp b/src/hooks.cpp index d655fea23..20b9565cc 100644 --- a/src/hooks.cpp +++ b/src/hooks.cpp @@ -103,7 +103,8 @@ MH_STATUS WINAPI SK_QueueEnableHook (LPVOID pTarget) { - SK_MinHook_HooksEnqueued++; + InterlockedIncrement (&SK_MinHook_HooksEnqueued); + InterlockedIncrement (&SK_MinHook_HooksQueuedButNotApplied); return MH_QueueEnableHookEx (pTarget, 0); @@ -1556,8 +1557,6 @@ SK_ApplyQueuedHooks (void) { if (! SKinHookCtx.ApplyQueuedHooks.enabled) { - InterlockedIncrement (&SK_MinHook_HooksQueuedButNotApplied); - SK_MinHook_HooksQueuedButNotApplied++; return MH_OK; } @@ -1567,10 +1566,6 @@ SK_ApplyQueuedHooks (void) return MH_ERROR_DISABLED; } - InterlockedDecrement (&SK_MinHook_HooksQueuedButNotApplied); - SK_MinHook_HooksActive += - std::exchange (SK_MinHook_HooksEnqueued, 0); - UINT uiHookCount = 0; if ( MH_OK == SH_HookCount (&uiHookCount) ) @@ -1604,6 +1599,20 @@ SK_ApplyQueuedHooks (void) SK_LOG ((L" >> %lu ms", SK_timeGetTime () - dwStart), lvl, L" Min Hook "); + if (status == MH_OK) + { + auto enqueued = + ReadULongAcquire (&SK_MinHook_HooksEnqueued); + + InterlockedExchangeSubtract ( + &SK_MinHook_HooksQueuedButNotApplied, + enqueued); + InterlockedExchangeAdd ( + &SK_MinHook_HooksActive, enqueued); + InterlockedExchangeSubtract ( + &SK_MinHook_HooksEnqueued, enqueued); + } + return status; } diff --git a/src/input/hid.cpp b/src/input/hid.cpp index f47372a07..b93f2acd8 100644 --- a/src/input/hid.cpp +++ b/src/input/hid.cpp @@ -2273,10 +2273,10 @@ SK_Input_HookHID (void) static_cast_p2p (&CreateFile2_Original) ); } - SK_CreateDLLHook2 ( L"kernel32.dll", - "DeviceIoControl", - DeviceIoControl_Detour, - static_cast_p2p (&DeviceIoControl_Original) ); + //SK_CreateDLLHook2 ( L"kernel32.dll", + // "DeviceIoControl", + // DeviceIoControl_Detour, + // static_cast_p2p (&DeviceIoControl_Original) ); #define _HOOK_READ_FILE #ifdef _HOOK_READ_FILE diff --git a/src/window.cpp b/src/window.cpp index 4f5c7cd28..4002bf4c1 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -5097,28 +5097,6 @@ GetFocus_Detour (void) } } - ///// Overriding this is not a great idea, - ///// it will enable input to slip through during Alt-Tab. - ///if (config.window.background_render) - ///{ - /// // Keep a cache of non-NULL focus HWNDs for this thread - /// concurrency::concurrent_unordered_map - /// focus_windows; - /// - /// HWND hWndFocus = - /// SK_GetFocus ( ); - /// DWORD dwTid = - /// SK_GetCurrentThreadId (); - /// - /// if ( hWndFocus != nullptr ) - /// focus_windows [dwTid] = hWndFocus; - /// else if (focus_windows.count (dwTid) && - /// focus_windows [dwTid] == SK_GetGameWindow ()) - /// return focus_windows [dwTid]; - /// else - /// return SK_GetGameWindow (); - ///} - return SK_GetFocus (); } @@ -5175,7 +5153,7 @@ BOOL WINAPI SK_IsWindowUnicode (HWND hWnd, SK_TLS *pTLS) { - UNREFERENCED_PARAMETER (pTLS); + std::ignore = pTLS; // Faster if (hWnd == game_window.hWnd) @@ -5189,23 +5167,7 @@ HWND WINAPI SK_GetActiveWindow (SK_TLS *pTLS) { - UNREFERENCED_PARAMETER (pTLS); - ////if (pTLS == nullptr) - //// pTLS = SK_TLS_Bottom (); - //// - ////if (pTLS != nullptr) - ////{ - //// if ((uintptr_t)pTLS->win32->active == (uintptr_t)-1) - //// { - //// pTLS->win32->active = - //// GetActiveWindow_Original != nullptr ? - //// GetActiveWindow_Original () : - //// GetActiveWindow (); - //// } - //// - //// return - //// pTLS->win32->active; - ////} + std::ignore = pTLS; return GetActiveWindow_Original != nullptr ? @@ -5219,6 +5181,7 @@ GetActiveWindow_Detour (void) { SK_LOG_FIRST_CALL +#if 0 // This function is hooked before we actually know the game's HWND, // this would be catastrophic. if (game_window.hWnd != 0 && IsWindow (game_window.hWnd)) @@ -5274,6 +5237,7 @@ GetActiveWindow_Detour (void) /////// else /////// return SK_GetGameWindow (); ///////} +#endif return SK_GetActiveWindow (/*pTLS*/nullptr);