From b801cf9c78fe23e1f50ba780cd80720d0c908a14 Mon Sep 17 00:00:00 2001 From: Kaldaien Date: Sat, 21 Dec 2024 04:53:02 -0500 Subject: [PATCH] Static analysis code cleanup --- CHANGELOG.txt | 9 +- SpecialK.suppress | 40 +++ include/SpecialK/DLL_VERSION.H | 4 +- include/SpecialK/render/dxgi/dxgi_swapchain.h | 10 +- src/imgui/backends/imgui_d3d12.cpp | 4 +- src/input/game_input.cpp | 16 +- src/input/raw_input.cpp | 280 +++++++++--------- src/input/windows.gaming.input.cpp | 15 +- src/input/winhook_input.cpp | 203 ++++++------- src/input/winmm_joystick.cpp | 3 +- src/plugins/elden_ring.cpp | 3 - src/plugins/octopath_traveler.cpp | 12 - src/plugins/sekiro.cpp | 2 + src/popups/achievement.cpp | 6 +- src/render/d3d11/d3d11_screenshot.cpp | 40 +-- src/render/d3d11/d3d11_shader.cpp | 25 +- src/render/d3d11/hdr/d3d11_hdr.cpp | 15 +- .../d3d11/hooks/d3d11_devctx_vftable.cpp | 4 - src/render/d3d11/hooks/d3d11_device.cpp | 3 +- src/render/d3d11/utility/d3d11_map.cpp | 6 +- src/render/d3d12/d3d12_command_queue.cpp | 45 ++- src/render/d3d12/d3d12_device.cpp | 44 ++- src/render/dxgi/dxgi_swapchain.cpp | 12 +- 23 files changed, 403 insertions(+), 398 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 19f89280c..17259945d 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,11 @@ -24.12.21.1 +24.12.21.2 +========== + + Fixed typo that has been preventing SK's D3D11 texture cache from evaluating + the list of freeable textures when cache capacity exceeds user-defined + limit for several years... oops? + + Fixed various other small issues, nothing as serious as the one above. + +24.12.21.1 ========== + Fixed cursor auto-hide changes accidentally introduced in 24.12.21 diff --git a/SpecialK.suppress b/SpecialK.suppress index 12d407634..b68124f76 100644 --- a/SpecialK.suppress +++ b/SpecialK.suppress @@ -313,6 +313,22 @@ 3170002416 125 + + d3d11_shader.cpp + V568 + It's odd that 'sizeof()' operator evaluates the size of a pointer to a class, but not the size of the 'pDesc' class object. + 0 + 460572845 + 0 + + + d3d11_shader.cpp + V568 + It's odd that 'sizeof()' operator evaluates the size of a pointer to a class, but not the size of the 'pDesc' class object. + 4051175878 + 1335475529 + 7328300 + d3d11_tex_mgr.cpp V112 @@ -361,6 +377,22 @@ 844435421 0 + + d3d11_tex_mgr.cpp + V547 + Expression 'initial != initial_after_release + _' is always true. + 0 + 2953353297 + 123 + + + d3d11_tex_mgr.cpp + V779 + Unreachable code detected. It is possible that an error is present. + 0 + 3525957960 + 9417071 + d3d11_tex_mgr.cpp V821 @@ -593,6 +625,14 @@ 5116 261911641 + + playstation.cpp + V547 + Expression 'pDevice->pPreparsedData != nullptr' is always false. + 123 + 3170116418 + 17733 + screenshot.h V3509 diff --git a/include/SpecialK/DLL_VERSION.H b/include/SpecialK/DLL_VERSION.H index aae09bdda..11881952a 100644 --- a/include/SpecialK/DLL_VERSION.H +++ b/include/SpecialK/DLL_VERSION.H @@ -3,8 +3,8 @@ #define SK_YEAR 24 #define SK_MONTH 12 #define SK_DATE 21 -#define SK_REV_N 1 -#define SK_REV 1 +#define SK_REV_N 2 +#define SK_REV 2 #ifndef _A2 #define _A2(a) #a diff --git a/include/SpecialK/render/dxgi/dxgi_swapchain.h b/include/SpecialK/render/dxgi/dxgi_swapchain.h index f1999f172..a4fc4e7ea 100644 --- a/include/SpecialK/render/dxgi/dxgi_swapchain.h +++ b/include/SpecialK/render/dxgi/dxgi_swapchain.h @@ -104,7 +104,8 @@ IWrapDXGISwapChain : IDXGISwapChain4 if (ver_ != 0) { - ((IDXGISwapChain1 *)pReal)->GetHwnd (&hWnd_); + static_cast + (pReal)->GetHwnd (&hWnd_); SK_ReleaseAssert (sd.OutputWindow == 0 || sd.OutputWindow == hWnd_); @@ -124,7 +125,7 @@ IWrapDXGISwapChain : IDXGISwapChain4 sd.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL ); flip_model.native = rb.active_traits.bOriginallyFlip; - this->IWrapDXGISwapChain::SetPrivateDataInterface (IID_IUnwrappedDXGISwapChain, pReal); + SetPrivateDataInterface (IID_IUnwrappedDXGISwapChain, pReal); SK_DXGI_SetDebugName ( pReal, SK_FormatStringW ( L"SK_IWrapDXGISwapChain: pReal=%p", pReal ) ); @@ -229,7 +230,8 @@ IWrapDXGISwapChain : IDXGISwapChain4 InterlockedIncrement (&SK_DXGI_LiveWrappedSwapChain1s); - ((IDXGISwapChain1 *)pReal)->GetHwnd (&hWnd_); + static_cast + (pReal)->GetHwnd (&hWnd_); SK_ReleaseAssert (sd.OutputWindow == 0 || sd.OutputWindow == hWnd_); @@ -242,7 +244,7 @@ IWrapDXGISwapChain : IDXGISwapChain4 sd.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL ); flip_model.native = rb.active_traits.bOriginallyFlip; - this->IWrapDXGISwapChain::SetPrivateDataInterface (IID_IUnwrappedDXGISwapChain, pReal); + SetPrivateDataInterface (IID_IUnwrappedDXGISwapChain, pReal); SK_DXGI_SetDebugName ( pReal, SK_FormatStringW ( L"SK_IWrapDXGISwapChain: pReal=%p", pReal ) ); diff --git a/src/imgui/backends/imgui_d3d12.cpp b/src/imgui/backends/imgui_d3d12.cpp index b451b788a..74a803b52 100644 --- a/src/imgui/backends/imgui_d3d12.cpp +++ b/src/imgui/backends/imgui_d3d12.cpp @@ -3199,8 +3199,8 @@ SK_D3D12_RenderCtx::init (IDXGISwapChain3 *pSwapChain, ID3D12CommandQueue *pComm { frames_.clear (); - DXGI_SWAP_CHAIN_DESC1 swapDesc1 = { }; - pSwapChain->GetDesc1 (&swapDesc1); + DXGI_SWAP_CHAIN_DESC1 swapDesc1 = { }; + _pSwapChain->GetDesc1 (&swapDesc1); SK_ReleaseAssert (swapDesc1.BufferCount > 0); frames_.resize (swapDesc1.BufferCount); // Resize does not clear, if the size is the same diff --git a/src/input/game_input.cpp b/src/input/game_input.cpp index c39c849dd..1edc4cf36 100644 --- a/src/input/game_input.cpp +++ b/src/input/game_input.cpp @@ -697,7 +697,7 @@ SK_IWrapGameInput::UnregisterCallback (_In_ GameInputCallbackToken callbackToken SK_LOG_FIRST_CALL return - pReal == nullptr ? S_OK : + pReal == nullptr ? true : pReal->UnregisterCallback (callbackToken, timeoutInMicroseconds); } @@ -708,7 +708,7 @@ SK_IWrapGameInput::CreateDispatcher (_COM_Outptr_ IGameInputDispatcher **dispatc SK_LOG_FIRST_CALL return - pReal == nullptr ? S_OK : + pReal == nullptr ? S_OK : pReal->CreateDispatcher (dispatcher); } @@ -720,7 +720,7 @@ SK_IWrapGameInput::CreateAggregateDevice (_In_ GameInputKind inputK SK_LOG_FIRST_CALL return - pReal == nullptr ? S_OK : + pReal == nullptr ? S_OK : pReal->CreateAggregateDevice (inputKind, device); } @@ -732,7 +732,7 @@ SK_IWrapGameInput::FindDeviceFromId (_In_ APP_LOCAL_DEVICE_ID const *va SK_LOG_FIRST_CALL return - pReal == nullptr ? S_OK : + pReal == nullptr ? S_OK : pReal->FindDeviceFromId (value, device); } @@ -744,7 +744,7 @@ SK_IWrapGameInput::FindDeviceFromObject (_In_ IUnknown *value, SK_LOG_FIRST_CALL return - pReal == nullptr ? S_OK : + pReal == nullptr ? S_OK : pReal->FindDeviceFromObject (value, device); } @@ -756,7 +756,7 @@ SK_IWrapGameInput::FindDeviceFromPlatformHandle (_In_ HANDLE SK_LOG_FIRST_CALL return - pReal == nullptr ? S_OK : + pReal == nullptr ? S_OK : pReal->FindDeviceFromPlatformHandle (value, device); } @@ -768,7 +768,7 @@ SK_IWrapGameInput::FindDeviceFromPlatformString (_In_ LPCWSTR SK_LOG_FIRST_CALL return - pReal == nullptr ? S_OK : + pReal == nullptr ? S_OK : pReal->FindDeviceFromPlatformString (value, device); } @@ -782,7 +782,7 @@ SK_IWrapGameInput::EnableOemDeviceSupport (_In_ uint16_t vendorId, SK_LOG_FIRST_CALL return - pReal == nullptr ? S_OK : + pReal == nullptr ? S_OK : pReal->EnableOemDeviceSupport (vendorId, productId, interfaceNumber, collectionNumber); } diff --git a/src/input/raw_input.cpp b/src/input/raw_input.cpp index 2ccede967..e3d72183e 100644 --- a/src/input/raw_input.cpp +++ b/src/input/raw_input.cpp @@ -697,173 +697,167 @@ GetRawInputBuffer_Detour (_Out_opt_ PRAWINPUT pData, using QWORD = __int64; - if (pData != nullptr) + const int max_items = (((size_t)*pcbSize * 16) / sizeof (RAWINPUT)); + int count = 0; + auto *pTemp = + (RAWINPUT *)SK_TLS_Bottom ()->raw_input->allocData ((size_t)*pcbSize * 16); + RAWINPUT *pInput = pTemp; + RAWINPUT *pOutput = pData; + UINT cbSize = *pcbSize; + *pcbSize = 0; + + int temp_ret = + GetRawInputBuffer_Original ( pTemp, &cbSize, cbSizeHeader ); + + // Common usage involves calling this with a wrong sized buffer, then calling it again... + // early-out if it returns -1. + if (sk::narrow_cast (temp_ret) < 0 || max_items == 0) + return temp_ret; + + auto* pItem = + pInput; + + // Sanity check required array storage even though TLS will + // allocate more than enough. + SK_ReleaseAssert (temp_ret < max_items); + + for (int i = 0; i < temp_ret; i++) { - const int max_items = (((size_t)*pcbSize * 16) / sizeof (RAWINPUT)); - int count = 0; - auto *pTemp = - (RAWINPUT *)SK_TLS_Bottom ()->raw_input->allocData ((size_t)*pcbSize * 16); - RAWINPUT *pInput = pTemp; - RAWINPUT *pOutput = pData; - UINT cbSize = *pcbSize; - *pcbSize = 0; - - int temp_ret = - GetRawInputBuffer_Original ( pTemp, &cbSize, cbSizeHeader ); - - // Common usage involves calling this with a wrong sized buffer, then calling it again... - // early-out if it returns -1. - if (sk::narrow_cast (temp_ret) < 0 || max_items == 0) - return temp_ret; - - auto* pItem = - pInput; - - // Sanity check required array storage even though TLS will - // allocate more than enough. - SK_ReleaseAssert (temp_ret < max_items); - - for (int i = 0; i < temp_ret; i++) - { - bool remove = false; + bool remove = false; - switch (pItem->header.dwType) + switch (pItem->header.dwType) + { + case RIM_TYPEKEYBOARD: { - case RIM_TYPEKEYBOARD: + SK_RAWINPUT_READ (sk_input_dev_type::Keyboard) + if (filter || SK_ImGui_WantKeyboardCapture ()) { - SK_RAWINPUT_READ (sk_input_dev_type::Keyboard) - if (filter || SK_ImGui_WantKeyboardCapture ()) - { - SK_RAWINPUT_HIDE (sk_input_dev_type::Keyboard); - remove = true; - } - else - SK_RAWINPUT_VIEW (sk_input_dev_type::Keyboard); + SK_RAWINPUT_HIDE (sk_input_dev_type::Keyboard); + remove = true; + } + else + SK_RAWINPUT_VIEW (sk_input_dev_type::Keyboard); - //// Leads to double-input processing, left here in case Legacy Messages are disabled and this is needed - //// + //// Leads to double-input processing, left here in case Legacy Messages are disabled and this is needed + //// #if 0 - USHORT VKey = - (((RAWINPUT *)pData)->data.keyboard.VKey & 0xFF); - - static auto* pConsole = - SK_Console::getInstance (); - - //if (!(((RAWINPUT *) pItem)->data.keyboard.Flags & RI_KEY_BREAK)) - //{ - // pConsole->KeyDown (VKey & 0xFF, MAXDWORD); - // io.KeysDown [VKey & 0xFF] = SK_IsGameWindowActive (); - //} - if (game_window.active) + USHORT VKey = + (((RAWINPUT *)pData)->data.keyboard.VKey & 0xFF); + + static auto* pConsole = + SK_Console::getInstance (); + + //if (!(((RAWINPUT *) pItem)->data.keyboard.Flags & RI_KEY_BREAK)) + //{ + // pConsole->KeyDown (VKey & 0xFF, MAXDWORD); + // io.KeysDown [VKey & 0xFF] = SK_IsGameWindowActive (); + //} + if (game_window.active) + { + switch (((RAWINPUT *) pData)->data.keyboard.Message) { - switch (((RAWINPUT *) pData)->data.keyboard.Message) - { - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - io.KeysDown [VKey & 0xFF] = SK_IsGameWindowActive (); - pConsole->KeyDown (VKey & 0xFF, MAXDWORD); - break; - - case WM_KEYUP: - case WM_SYSKEYUP: - io.KeysDown [VKey & 0xFF] = false; - pConsole->KeyUp (VKey & 0xFF, MAXDWORD); - break; - } + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + io.KeysDown [VKey & 0xFF] = SK_IsGameWindowActive (); + pConsole->KeyDown (VKey & 0xFF, MAXDWORD); + break; + + case WM_KEYUP: + case WM_SYSKEYUP: + io.KeysDown [VKey & 0xFF] = false; + pConsole->KeyUp (VKey & 0xFF, MAXDWORD); + break; } + } #endif - } break; + } break; - case RIM_TYPEMOUSE: - SK_RAWINPUT_READ (sk_input_dev_type::Mouse) - if (filter || SK_ImGui_WantMouseCapture ()) - { - SK_RAWINPUT_HIDE (sk_input_dev_type::Mouse); - remove = true; - } - else - SK_RAWINPUT_VIEW (sk_input_dev_type::Mouse); - break; + case RIM_TYPEMOUSE: + SK_RAWINPUT_READ (sk_input_dev_type::Mouse) + if (filter || SK_ImGui_WantMouseCapture ()) + { + SK_RAWINPUT_HIDE (sk_input_dev_type::Mouse); + remove = true; + } + else + SK_RAWINPUT_VIEW (sk_input_dev_type::Mouse); + break; - default: - SK_RAWINPUT_READ (sk_input_dev_type::Gamepad) - if (filter || SK_ImGui_WantGamepadCapture () || config.input.gamepad.disable_hid) - { - SK_RAWINPUT_HIDE (sk_input_dev_type::Gamepad); - remove = true; - } - else - SK_RAWINPUT_VIEW (sk_input_dev_type::Gamepad); - break; - } + default: + SK_RAWINPUT_READ (sk_input_dev_type::Gamepad) + if (filter || SK_ImGui_WantGamepadCapture () || config.input.gamepad.disable_hid) + { + SK_RAWINPUT_HIDE (sk_input_dev_type::Gamepad); + remove = true; + } + else + SK_RAWINPUT_VIEW (sk_input_dev_type::Gamepad); + break; + } - if (config.input.ui.capture) - remove = true; + if (config.input.ui.capture) + remove = true; - // If item is not removed, append it to the buffer of RAWINPUT - // packets we are allowing the game to see - if (! remove) - { - memcpy (pOutput, pItem, pItem->header.dwSize); - pOutput = NEXTRAWINPUTBLOCK (pOutput); + // If item is not removed, append it to the buffer of RAWINPUT + // packets we are allowing the game to see + if (! remove) + { + memcpy (pOutput, pItem, pItem->header.dwSize); + pOutput = NEXTRAWINPUTBLOCK (pOutput); - ++count; - } + ++count; + } - else + else + { + bool keyboard = pItem->header.dwType == RIM_TYPEKEYBOARD; + bool mouse = pItem->header.dwType == RIM_TYPEMOUSE; + + // Clearing all bytes above would have set the type to mouse, and some games + // will actually read data coming from RawInput even when the size returned is 0! + pItem->header.dwType = keyboard ? RIM_TYPEKEYBOARD : + mouse ? RIM_TYPEMOUSE : + RIM_TYPEHID; + + // Supplying an invalid device will early-out SDL before it calls HID APIs to try + // and get an input report that we don't want it to see... + pItem->header.hDevice = nullptr; + + //SK_ReleaseAssert (*pcbSize >= static_cast (size) && + // *pcbSize >= sizeof (RAWINPUTHEADER)); + + pItem->header.wParam = RIM_INPUTSINK; + + if (keyboard) { - bool keyboard = pItem->header.dwType == RIM_TYPEKEYBOARD; - bool mouse = pItem->header.dwType == RIM_TYPEMOUSE; - - // Clearing all bytes above would have set the type to mouse, and some games - // will actually read data coming from RawInput even when the size returned is 0! - pItem->header.dwType = keyboard ? RIM_TYPEKEYBOARD : - mouse ? RIM_TYPEMOUSE : - RIM_TYPEHID; - - // Supplying an invalid device will early-out SDL before it calls HID APIs to try - // and get an input report that we don't want it to see... - pItem->header.hDevice = nullptr; + if (! (pItem->data.keyboard.Flags & RI_KEY_BREAK)) + pItem->data.keyboard.VKey = 0; - //SK_ReleaseAssert (*pcbSize >= static_cast (size) && - // *pcbSize >= sizeof (RAWINPUTHEADER)); + // Fake key release + pItem->data.keyboard.Flags |= RI_KEY_BREAK; + } - pItem->header.wParam = RIM_INPUTSINK; - - if (keyboard) - { - if (! (pItem->data.keyboard.Flags & RI_KEY_BREAK)) - pItem->data.keyboard.VKey = 0; - - // Fake key release - pItem->data.keyboard.Flags |= RI_KEY_BREAK; - } - - // Block mouse input in The Witness by zeroing-out the memory; most other - // games will see *pcbSize=0 and RIM_INPUTSINK and not process input... - else - { - RtlZeroMemory ( &pItem->data.mouse, - pItem->header.dwSize - sizeof (RAWINPUTHEADER) ); - } - - memcpy (pOutput, pItem, pItem->header.dwSize); - pOutput = NEXTRAWINPUTBLOCK (pOutput); - - ++count; + // Block mouse input in The Witness by zeroing-out the memory; most other + // games will see *pcbSize=0 and RIM_INPUTSINK and not process input... + else + { + RtlZeroMemory ( &pItem->data.mouse, + pItem->header.dwSize - sizeof (RAWINPUTHEADER) ); } - pItem = NEXTRAWINPUTBLOCK (pItem); - } + memcpy (pOutput, pItem, pItem->header.dwSize); + pOutput = NEXTRAWINPUTBLOCK (pOutput); - *pcbSize = - (UINT)((uintptr_t)pOutput - (uintptr_t)pData); + ++count; + } - return count; + pItem = NEXTRAWINPUTBLOCK (pItem); } - return - GetRawInputBuffer_Original (pData, pcbSize, cbSizeHeader); + *pcbSize = + (UINT)((uintptr_t)pOutput - (uintptr_t)pData); + + return count; } INT diff --git a/src/input/windows.gaming.input.cpp b/src/input/windows.gaming.input.cpp index 6e5be98b4..0fc7db17d 100644 --- a/src/input/windows.gaming.input.cpp +++ b/src/input/windows.gaming.input.cpp @@ -423,7 +423,7 @@ WGI_Gamepad_GetCurrentReading_Override (ABI::Windows::Gaming::Input::IGamepad config.input.gamepad.xinput.emulate ? S_OK : hr_real; - if (SUCCEEDED (hr)) + if (SUCCEEDED (hr) && value != nullptr) { SK_WGI_HIDE (SK_WGI_Backend, sk_input_dev_type::Gamepad); @@ -436,6 +436,9 @@ WGI_Gamepad_GetCurrentReading_Override (ABI::Windows::Gaming::Input::IGamepad value->RightTrigger = 0.0; } + else + SK_ReleaseAssert (FAILED (hr) || value != nullptr); + return hr; } @@ -518,7 +521,7 @@ WGI_Gamepad_GetCurrentReading_Override (ABI::Windows::Gaming::Input::IGamepad return hr; } - else if (config.input.gamepad.xinput.emulate && (! config.input.gamepad.xinput.blackout_api)) + else if (! config.input.gamepad.xinput.blackout_api) { XINPUT_STATE xi_state = { }; @@ -837,7 +840,7 @@ WGI_VectorView_Gamepads_GetAt_Override ( IVectorViewz_get_rc_name_impl (), L"Windows.Foundation.Collections.IVectorView`1")) + if (0 != _wcsicmp (This->z_get_rc_name_impl (), L"Windows.Foundation.Collections.IVectorView`1")) return hr; // All controllers not found in the real list of controllers will be substituted with SK's @@ -864,7 +867,7 @@ WGI_VectorView_Gamepads_get_Size_Override ( IVectorViewz_get_rc_name_impl (), L"Windows.Foundation.Collections.IVectorView`1")) + if (0 != _wcsicmp (This->z_get_rc_name_impl (), L"Windows.Foundation.Collections.IVectorView`1")) return hr; // Add 1 to the size so that games never see an empty list @@ -889,7 +892,7 @@ WGI_VectorView_Gamepads_IndexOf_Override ( IVectorViewz_get_rc_name_impl (), L"Windows.Foundation.Collections.IVectorView`1")) + if (0 != _wcsicmp (This->z_get_rc_name_impl (), L"Windows.Foundation.Collections.IVectorView`1")) return hr; // All failing controllers will map to the end of the list @@ -1143,7 +1146,7 @@ class SK_HID_WGI_GamepadListener_Impl : public __FIEventHandler_1_Windows__CGami return S_OK; } - ABI::Windows::Gaming::Input::IGamepadStatics* factory; + ABI::Windows::Gaming::Input::IGamepadStatics* factory = nullptr; private: volatile ULONG ulRefs = 1; diff --git a/src/input/winhook_input.cpp b/src/input/winhook_input.cpp index bef5c9dbc..74e586134 100644 --- a/src/input/winhook_input.cpp +++ b/src/input/winhook_input.cpp @@ -115,12 +115,9 @@ SK_Proxy_MouseProc ( // Install a mouse tracker to get WM_MOUSELEAVE if (! (game_window.mouse.tracking && game_window.mouse.inside)) { - if (wParam != WM_NCMOUSEMOVE) + if (SK_ImGui_WantMouseCapture ()) { - if (SK_ImGui_WantMouseCapture ()) - { - SK_ImGui_UpdateMouseTracker (); - } + SK_ImGui_UpdateMouseTracker (); } } @@ -648,39 +645,34 @@ SetWindowsHookExW_Detour ( L" Low-Level " : L" " ), L"Input Hook" ); - // Game seems to be using keyboard hooks instead of a normal Window Proc; - // that makes life more complicated for SK/ImGui... but we got this! - if (idHook == WH_KEYBOARD || idHook == WH_KEYBOARD_LL) - { - bool install = false; - - if (dwThreadId != 0) - { - if ( !__hooks._RealKeyboardProcs.count (dwThreadId) || - __hooks._RealKeyboardProcs [dwThreadId] == nullptr) - { __hooks._RealKeyboardProcs [dwThreadId] = lpfn; - hook =&__hooks._RealKeyboardHooks [dwThreadId]; - install = true; - } - - else - SK_LOGi0 ( L" * A keyboard hook already exists for thread %d", - dwThreadId ); - } + bool install = false; - else if (__hooks._RealKeyboardProc == nullptr) - { __hooks._RealKeyboardProc = lpfn; - hook =&__hooks._RealKeyboardHook; - install = true; + if (dwThreadId != 0) + { + if ( !__hooks._RealKeyboardProcs.count (dwThreadId) || + __hooks._RealKeyboardProcs [dwThreadId] == nullptr) + { __hooks._RealKeyboardProcs [dwThreadId] = lpfn; + hook =&__hooks._RealKeyboardHooks [dwThreadId]; + install = true; } else - SK_LOGi0 (L" * A global keyboard hook already exists"); + SK_LOGi0 ( L" * A keyboard hook already exists for thread %d", + dwThreadId ); + } - if (install) - lpfn = (idHook == WH_KEYBOARD ? SK_Proxy_KeyboardProc - : SK_Proxy_LLKeyboardProc); + else if (__hooks._RealKeyboardProc == nullptr) + { __hooks._RealKeyboardProc = lpfn; + hook =&__hooks._RealKeyboardHook; + install = true; } + + else + SK_LOGi0 (L" * A global keyboard hook already exists"); + + if (install) + lpfn = (idHook == WH_KEYBOARD ? SK_Proxy_KeyboardProc + : SK_Proxy_LLKeyboardProc); } break; case WH_MOUSE: @@ -692,39 +684,34 @@ SetWindowsHookExW_Detour ( L" Low-Level " : L" " ), L"Input Hook" ); - // Game seems to be using mouse hooks instead of a normal Window Proc; - // that makes life more complicated for SK/ImGui... but we got this! - if (idHook == WH_MOUSE || idHook == WH_MOUSE_LL) - { - bool install = false; - - if (dwThreadId != 0) - { - if ( !__hooks._RealMouseProcs.count (dwThreadId) || - __hooks._RealMouseProcs [dwThreadId] == nullptr) - { __hooks._RealMouseProcs [dwThreadId] = lpfn; - hook =&__hooks._RealMouseHooks [dwThreadId]; - install = true; - } - - else - SK_LOGi0 ( L" * A global mouse hook already exists for thread %d", - dwThreadId ); - } + bool install = false; - else if (__hooks._RealMouseProc == nullptr) - { __hooks._RealMouseProc = lpfn; - hook =&__hooks._RealMouseHook; - install = true; + if (dwThreadId != 0) + { + if ( !__hooks._RealMouseProcs.count (dwThreadId) || + __hooks._RealMouseProcs [dwThreadId] == nullptr) + { __hooks._RealMouseProcs [dwThreadId] = lpfn; + hook =&__hooks._RealMouseHooks [dwThreadId]; + install = true; } else - SK_LOGi0 (L" * A global mouse hook already exists"); + SK_LOGi0 ( L" * A global mouse hook already exists for thread %d", + dwThreadId ); + } - if (install) - lpfn = (idHook == WH_MOUSE ? SK_Proxy_MouseProc - : SK_Proxy_LLMouseProc); + else if (__hooks._RealMouseProc == nullptr) + { __hooks._RealMouseProc = lpfn; + hook =&__hooks._RealMouseHook; + install = true; } + + else + SK_LOGi0 (L" * A global mouse hook already exists"); + + if (install) + lpfn = (idHook == WH_MOUSE ? SK_Proxy_MouseProc + : SK_Proxy_LLMouseProc); } break; } @@ -764,39 +751,34 @@ SetWindowsHookExA_Detour ( L" Low-Level " : L" " ), L"Input Hook" ); - // Game seems to be using keyboard hooks instead of a normal Window Proc; - // that makes life more complicated for SK/ImGui... but we got this! - if (idHook == WH_KEYBOARD || idHook == WH_KEYBOARD_LL) - { - bool install = false; - - if (dwThreadId != 0) - { - if ( !__hooks._RealKeyboardProcs.count (dwThreadId) || - __hooks._RealKeyboardProcs [dwThreadId] == nullptr) - { __hooks._RealKeyboardProcs [dwThreadId] = lpfn; - hook =&__hooks._RealKeyboardHooks [dwThreadId]; - install = true; - } - - else - SK_LOGi0 ( L" * A keyboard hook already exists for thread %d", - dwThreadId ); - } + bool install = false; - else if (__hooks._RealKeyboardProc == nullptr) - { __hooks._RealKeyboardProc = lpfn; - hook =&__hooks._RealKeyboardHook; - install = true; + if (dwThreadId != 0) + { + if ( !__hooks._RealKeyboardProcs.count (dwThreadId) || + __hooks._RealKeyboardProcs [dwThreadId] == nullptr) + { __hooks._RealKeyboardProcs [dwThreadId] = lpfn; + hook =&__hooks._RealKeyboardHooks [dwThreadId]; + install = true; } else - SK_LOGi0 (L" * A global keyboard hook already exists"); + SK_LOGi0 ( L" * A keyboard hook already exists for thread %d", + dwThreadId ); + } - if (install) - lpfn = (idHook == WH_KEYBOARD ? SK_Proxy_KeyboardProc - : SK_Proxy_LLKeyboardProc); + else if (__hooks._RealKeyboardProc == nullptr) + { __hooks._RealKeyboardProc = lpfn; + hook =&__hooks._RealKeyboardHook; + install = true; } + + else + SK_LOGi0 (L" * A global keyboard hook already exists"); + + if (install) + lpfn = (idHook == WH_KEYBOARD ? SK_Proxy_KeyboardProc + : SK_Proxy_LLKeyboardProc); } break; case WH_MOUSE: @@ -808,39 +790,34 @@ SetWindowsHookExA_Detour ( L" Low-Level " : L" " ), L"Input Hook" ); - // Game seems to be using mouse hooks instead of a normal Window Proc; - // that makes life more complicated for SK/ImGui... but we got this! - if (idHook == WH_MOUSE || idHook == WH_MOUSE_LL) - { - bool install = false; - - if (dwThreadId != 0) - { - if ( !__hooks._RealMouseProcs.count (dwThreadId) || - __hooks._RealMouseProcs [dwThreadId] == nullptr) - { __hooks._RealMouseProcs [dwThreadId] = lpfn; - hook =&__hooks._RealMouseHooks [dwThreadId]; - install = true; - } - - else - SK_LOGi0 ( L" * A mouse hook already exists for thread %d", - dwThreadId ); - } + bool install = false; - else if (__hooks._RealMouseProc == nullptr) - { __hooks._RealMouseProc = lpfn; - hook =&__hooks._RealMouseHook; - install = true; + if (dwThreadId != 0) + { + if ( !__hooks._RealMouseProcs.count (dwThreadId) || + __hooks._RealMouseProcs [dwThreadId] == nullptr) + { __hooks._RealMouseProcs [dwThreadId] = lpfn; + hook =&__hooks._RealMouseHooks [dwThreadId]; + install = true; } else - SK_LOGi0 (L" * A global mouse hook already exists"); + SK_LOGi0 ( L" * A mouse hook already exists for thread %d", + dwThreadId ); + } - if (install) - lpfn = (idHook == WH_MOUSE ? SK_Proxy_MouseProc - : SK_Proxy_LLMouseProc); + else if (__hooks._RealMouseProc == nullptr) + { __hooks._RealMouseProc = lpfn; + hook =&__hooks._RealMouseHook; + install = true; } + + else + SK_LOGi0 (L" * A global mouse hook already exists"); + + if (install) + lpfn = (idHook == WH_MOUSE ? SK_Proxy_MouseProc + : SK_Proxy_LLMouseProc); } break; } diff --git a/src/input/winmm_joystick.cpp b/src/input/winmm_joystick.cpp index be84a2d07..a5fcd99b5 100644 --- a/src/input/winmm_joystick.cpp +++ b/src/input/winmm_joystick.cpp @@ -196,8 +196,7 @@ joyGetPosEx_Detour (_In_ UINT uJoyID, // Forward the data we polled *pjiUINT = joyInfo; - if (result == JOYERR_NOERROR) - SK_WinMM_Backend->markRead (sk_input_dev_type::Gamepad); + SK_WinMM_Backend->markRead (sk_input_dev_type::Gamepad); return result; } diff --git a/src/plugins/elden_ring.cpp b/src/plugins/elden_ring.cpp index 1d0b7971e..a1fb87f78 100644 --- a/src/plugins/elden_ring.cpp +++ b/src/plugins/elden_ring.cpp @@ -744,9 +744,6 @@ SK_ER_DeferredInit (void) if (static bool init = false; SK_GetFramesDrawn () > 15 && std::exchange (init, true) == false) { - std::wstring game_ver_str = - SK_GetDLLVersionStr (SK_GetHostApp ()); - SK_ER_InitConfig (); auto& addr_cache = diff --git a/src/plugins/octopath_traveler.cpp b/src/plugins/octopath_traveler.cpp index dd8584de8..7632fb683 100644 --- a/src/plugins/octopath_traveler.cpp +++ b/src/plugins/octopath_traveler.cpp @@ -199,18 +199,6 @@ SK_OPT_PlugInCfg (void) if (mouse_exit) { - if (config.window.unconfine_cursor) - { - config.window.confine_cursor = 0; - config.window.unconfine_cursor = 1; - } - - else - { - config.window.confine_cursor = 0; - config.window.unconfine_cursor = 0; - } - SK_ImGui_AdjustCursor (); changed = true; diff --git a/src/plugins/sekiro.cpp b/src/plugins/sekiro.cpp index 0d9c2dcc0..0d687a2f9 100644 --- a/src/plugins/sekiro.cpp +++ b/src/plugins/sekiro.cpp @@ -791,6 +791,7 @@ SK_Sekiro_InitPlugin (void) // Decomissioned as of 5/30/24 return; +#if 0 plugin_mgr->config_fns.emplace (SK_Sekiro_PlugInCfg); plugin_mgr->first_frame_fns.emplace (SK_Sekiro_PresentFirstFrame); @@ -813,4 +814,5 @@ SK_Sekiro_InitPlugin (void) SK_WinSock_GoOffline (); SK_ApplyQueuedHooks (); +#endif } \ No newline at end of file diff --git a/src/popups/achievement.cpp b/src/popups/achievement.cpp index e06567685..315f33df3 100644 --- a/src/popups/achievement.cpp +++ b/src/popups/achievement.cpp @@ -91,8 +91,8 @@ class SK_ImGui_AchievementPopup : SK_ImGui_PopupWindow { struct { struct { - double global; - double friends; + double global = 0.0; + double friends = 0.0; } unlock_percent; bool has_unlock_stats = false; @@ -100,7 +100,7 @@ class SK_ImGui_AchievementPopup : SK_ImGui_PopupWindow { struct { struct epic_s { - uint16_t xp; + uint16_t xp = 0; enum class trophy_type diff --git a/src/render/d3d11/d3d11_screenshot.cpp b/src/render/d3d11/d3d11_screenshot.cpp index f32d6739c..011e6b50b 100644 --- a/src/render/d3d11/d3d11_screenshot.cpp +++ b/src/render/d3d11/d3d11_screenshot.cpp @@ -299,7 +299,7 @@ SK_D3D11_Screenshot::SK_D3D11_Screenshot (const SK_ComPtr & pDevic if (! title.empty ()) { framebuffer.file_name = SK_UTF8ToWideChar (title); - framebuffer.title = title; + framebuffer.title = std::move (title); PathStripPathA (framebuffer.title.data ()); @@ -1108,7 +1108,7 @@ SK_D3D11_CaptureScreenshot ( SK_ScreenshotStage when = if (! title.empty ()) { - enqueued_titles.stages [stage] = title; + enqueued_titles.stages [stage] = std::move (title); } return true; @@ -1897,29 +1897,29 @@ SK_D3D11_ProcessScreenshotQueueEx ( SK_ScreenshotStage stage_, rb.screenshot_mgr->getBasePath (), _TRUNCATE ); - bool hdr = - ( SK_GetCurrentRenderBackend ().isHDRCapable () && - SK_GetCurrentRenderBackend ().isHDRActive () ); - - if (hdr) - { - PathAppendW ( wszAbsolutePathToLossless, - SK_FormatStringW ( L"HDR\\%ws.jxr", - pFrameData->file_name.c_str () ).c_str () ); - } - - else - { - PathAppendW ( wszAbsolutePathToLossless, - SK_FormatStringW ( L"Lossless\\%ws.png", - pFrameData->file_name.c_str () ).c_str () ); - } - // Why's it on the wait-queue if it's not finished?! assert (pFrameData != nullptr); if (pFrameData != nullptr) { + bool hdr = + ( SK_GetCurrentRenderBackend ().isHDRCapable () && + SK_GetCurrentRenderBackend ().isHDRActive () ); + + if (hdr) + { + PathAppendW ( wszAbsolutePathToLossless, + SK_FormatStringW ( L"HDR\\%ws.jxr", + pFrameData->file_name.c_str () ).c_str () ); + } + + else + { + PathAppendW ( wszAbsolutePathToLossless, + SK_FormatStringW ( L"Lossless\\%ws.png", + pFrameData->file_name.c_str () ).c_str () ); + } + using namespace DirectX; Image raw_img = { }; diff --git a/src/render/d3d11/d3d11_shader.cpp b/src/render/d3d11/d3d11_shader.cpp index 3367f1b57..ffb1e9b89 100644 --- a/src/render/d3d11/d3d11_shader.cpp +++ b/src/render/d3d11/d3d11_shader.cpp @@ -765,12 +765,7 @@ SK_D3D11_SetShaderResources_Impl ( SK_WRAP_AND_HOOK #undef pDevCtx - // Static analysis seems to think this is possible: - // ( Both are FALSE or Both are TRUE ), - // but I am pretty sure it never happens. - SK_ReleaseAssert (hooked ^ ( _vftable != nullptr ) ); - - if ((! hooked) && (! _vftable)) + if (! (hooked || _vftable)) return; SK_Thread_HybridSpinlock* @@ -908,7 +903,7 @@ SK_D3D11_SetShaderResources_Impl ( } - if (ppShaderResourceViews != nullptr && NumViews > 0 && shader_base != nullptr) + if (ppShaderResourceViews != nullptr && NumViews > 0) { auto&& newResourceViews = shader_base->current.tmp_views [dev_idx]; @@ -2463,7 +2458,7 @@ SK_LiveShaderClassView (sk_shader_class shader_type, bool& can_scroll) } static list_base; auto GetShaderList = - [](const sk_shader_class& type) -> + [](const sk_shader_class type) -> shader_class_imp_s* { switch (type) @@ -2485,7 +2480,7 @@ SK_LiveShaderClassView (sk_shader_class shader_type, bool& can_scroll) list = GetShaderList (shader_type); auto GetShaderTracker = - [](const sk_shader_class& type) -> + [](const sk_shader_class type) -> d3d11_shader_tracking_s* { switch (type) @@ -3496,12 +3491,12 @@ SK_LiveShaderClassView (sk_shader_class shader_type, bool& can_scroll) if (comments_end != nullptr) *comments_end = '\0'; if (footer_begins!= nullptr) *footer_begins = '\0'; - disassembly->emplace ( ReadAcquire ((volatile LONG *)&tracker->crc32c), - shader_disasm_s { szDisasm, - comments_end ? comments_end + 1 : szDisasmEnd, - footer_begins ? footer_begins + 1 : szDisasmEnd - } - ); + disassembly->try_emplace ( ReadAcquire ((volatile LONG *)&tracker->crc32c), + shader_disasm_s { szDisasm, + comments_end ? comments_end + 1 : szDisasmEnd, + footer_begins ? footer_begins + 1 : szDisasmEnd + } + ); if (pReflect != nullptr) { diff --git a/src/render/d3d11/hdr/d3d11_hdr.cpp b/src/render/d3d11/hdr/d3d11_hdr.cpp index 4d91e41a9..258fa68f9 100644 --- a/src/render/d3d11/hdr/d3d11_hdr.cpp +++ b/src/render/d3d11/hdr/d3d11_hdr.cpp @@ -241,8 +241,7 @@ struct SK_HDR_FIXUP auto pDev = rb.getDevice (); - SK_ComQIPtr pSwapChain (rb.swapchain); - SK_ComQIPtr pDevCtx (rb.d3d11.immediate_ctx); + SK_ComQIPtr pSwapChain (rb.swapchain); // These things aren't updated atomically, apparently :) // @@ -255,6 +254,9 @@ struct SK_HDR_FIXUP if (! recompileShaders ()) return; + SK_ComQIPtr + pDevCtx (rb.d3d11.immediate_ctx); + D3D11_FEATURE_DATA_D3D11_OPTIONS FeatureOpts = { }; SK_ComQIPtr @@ -280,15 +282,8 @@ struct SK_HDR_FIXUP desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; desc.MiscFlags = 0; - - pDev->CreateBuffer (&desc, nullptr, &mainSceneCBuffer); - + pDev->CreateBuffer (&desc, nullptr, &mainSceneCBuffer); desc.ByteWidth = sizeof (HDR_COLORSPACE_PARAMS); - desc.Usage = D3D11_USAGE_DYNAMIC; - desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - desc.MiscFlags = 0; - pDev->CreateBuffer (&desc, nullptr, &colorSpaceCBuffer); } diff --git a/src/render/d3d11/hooks/d3d11_devctx_vftable.cpp b/src/render/d3d11/hooks/d3d11_devctx_vftable.cpp index 4dac4e87d..240b8325c 100644 --- a/src/render/d3d11/hooks/d3d11_devctx_vftable.cpp +++ b/src/render/d3d11/hooks/d3d11_devctx_vftable.cpp @@ -668,15 +668,11 @@ D3D11_ExecuteCommandList_Override ( _In_ ID3D11CommandList *pCommandList, BOOL RestoreContextState ) { - if (pCommandList == nullptr) - return; - SK_ComPtr pDevice; This->GetDevice ( &pDevice.p); if (pDevice.IsEqualObject (SK_GetCurrentRenderBackend ().device)) { - SK_LOG_FIRST_CALL SK_ComPtr diff --git a/src/render/d3d11/hooks/d3d11_device.cpp b/src/render/d3d11/hooks/d3d11_device.cpp index ffa0287f4..55b40000c 100644 --- a/src/render/d3d11/hooks/d3d11_device.cpp +++ b/src/render/d3d11/hooks/d3d11_device.cpp @@ -857,8 +857,7 @@ D3D11Dev_CreateDepthStencilView_Override ( HRESULT hr = E_UNEXPECTED; - if ( pDesc != nullptr && - pResource != nullptr ) + if (pDesc != nullptr) { D3D11_RESOURCE_DIMENSION dim; pResource->GetType (&dim); diff --git a/src/render/d3d11/utility/d3d11_map.cpp b/src/render/d3d11/utility/d3d11_map.cpp index 8396fc8d2..b67c8c23d 100644 --- a/src/render/d3d11/utility/d3d11_map.cpp +++ b/src/render/d3d11/utility/d3d11_map.cpp @@ -184,8 +184,8 @@ SK_D3D11_Map_Impl ( auto& map_ctx = (*mapped_resources)[pDevCtx]; - map_ctx.textures.emplace (std::make_pair (pResource, *pMappedResource)); - map_ctx.texture_times.emplace (std::make_pair (pResource, SK_QueryPerf ().QuadPart)); + map_ctx.textures.try_emplace (pResource, *pMappedResource); + map_ctx.texture_times.try_emplace (pResource, SK_QueryPerf ().QuadPart); //dll_log->Log (L"[DX11TexMgr] Mapped 2D texture..."); } @@ -506,7 +506,7 @@ SK_D3D11_Unmap_Impl ( map_ctx.dynamic_times2 [checksum] = time_elapsed; map_ctx.dynamic_sizes2 [checksum] = size; - map_ctx.dynamic_files2 [checksum] = filename; + map_ctx.dynamic_files2 [checksum] = std::move (filename); } } } diff --git a/src/render/d3d12/d3d12_command_queue.cpp b/src/render/d3d12/d3d12_command_queue.cpp index aaae45c6b..3a8f68a92 100644 --- a/src/render/d3d12/d3d12_command_queue.cpp +++ b/src/render/d3d12/d3d12_command_queue.cpp @@ -68,30 +68,27 @@ D3D12CommandQueue_ExecuteCommandLists_Detour ( pLazyD3D12Device ) ) { - if (rb.d3d12.command_queue.p == nullptr) - { - SK_ComPtr pDevice; - SK_ComPtr pSwapChain; - SK_ComPtr pCmdQueue; - - if (SK_slGetNativeInterface (pLazyD3D12Device, (void **)&pDevice.p ) != sl::Result::eOk) - pDevice = pLazyD3D12Device; - if (SK_slGetNativeInterface (pLazyD3D12Chain, (void **)&pSwapChain.p) != sl::Result::eOk) - pSwapChain = pLazyD3D12Chain; - if (SK_slGetNativeInterface (This, (void **)&pCmdQueue.p ) != sl::Result::eOk) - pCmdQueue = This; - - // Now we are holding a ref... - rb.setDevice (pDevice.p); - rb.swapchain = pSwapChain.p; - rb.d3d12.command_queue = pCmdQueue.p; - rb.api = SK_RenderAPI::D3D12; - - _d3d12_rbk->init ( - (IDXGISwapChain3 *)pSwapChain.p, - pCmdQueue.p - ); - } + SK_ComPtr pDevice; + SK_ComPtr pSwapChain; + SK_ComPtr pCmdQueue; + + if (SK_slGetNativeInterface (pLazyD3D12Device, (void **)&pDevice.p ) != sl::Result::eOk) + pDevice = pLazyD3D12Device; + if (SK_slGetNativeInterface (pLazyD3D12Chain, (void **)&pSwapChain.p) != sl::Result::eOk) + pSwapChain = pLazyD3D12Chain; + if (SK_slGetNativeInterface (This, (void **)&pCmdQueue.p ) != sl::Result::eOk) + pCmdQueue = This; + + // Now we are holding a ref... + rb.setDevice (pDevice.p); + rb.swapchain = pSwapChain.p; + rb.d3d12.command_queue = pCmdQueue.p; + rb.api = SK_RenderAPI::D3D12; + + _d3d12_rbk->init ( + (IDXGISwapChain3 *)pSwapChain.p, + pCmdQueue.p + ); } else once = false; diff --git a/src/render/d3d12/d3d12_device.cpp b/src/render/d3d12/d3d12_device.cpp index 32b89d525..0a7e3662a 100644 --- a/src/render/d3d12/d3d12_device.cpp +++ b/src/render/d3d12/d3d12_device.cpp @@ -116,7 +116,7 @@ struct SK_D3D12_ShaderRepo { // std::hash // - size_t operator ()( const DxilContainerHash& h ) const + size_t operator ()( const DxilContainerHash h ) const { size_t __h = 0; for (size_t __i = 0; __i < DxilContainerHashSize; ++__i) @@ -131,8 +131,8 @@ struct SK_D3D12_ShaderRepo // std::equal_to // - bool operator ()( const DxilContainerHash& h1, - const DxilContainerHash& h2 ) const + bool operator ()( const DxilContainerHash h1, + const DxilContainerHash h2 ) const { return ( 0 == memcmp ( h1.Digest, @@ -374,8 +374,11 @@ _COM_Outptr_ void **ppPipelineState ) riid, ppPipelineState ); + // We changed this up when the weird thing at line 343 was introduced +#if 0 if (pDesc == nullptr) return hrPipelineCreate; +#endif #ifdef D3D12_STATE_TRACK static const @@ -578,15 +581,17 @@ struct CD3DX12_PIPELINE_STATE_STREAM_PARSE_HELPER_SK : public ID3DX12PipelinePar inline HRESULT D3DX12ParsePipelineStream_SK(D3D12_PIPELINE_STATE_STREAM_DESC& Desc, ID3DX12PipelineParserCallbacks_SK* pCallbacks) { - if (Desc.SizeInBytes == 0 || Desc.pPipelineStateSubobjectStream == nullptr) + if (pCallbacks == nullptr) { - pCallbacks->ErrorBadInputParameter(1); // first parameter issue + // This was a known bug in D3DX12, consider updating the code at some point!! + // + /////////pCallbacks->ErrorBadInputParameter(2); // second parameter issue return E_INVALIDARG; } - if (pCallbacks == nullptr) + if (Desc.SizeInBytes == 0 || Desc.pPipelineStateSubobjectStream == nullptr) { - pCallbacks->ErrorBadInputParameter(2); // second parameter issue + pCallbacks->ErrorBadInputParameter(1); // first parameter issue return E_INVALIDARG; } @@ -1788,6 +1793,8 @@ concurrency::concurrent_queue _resourcesToWrite_Upstr void SK_D3D12_EnqueueResource_Down (SK_ITrackD3D12Resource* pResource) { + if (! pResource) return; + pResource->pReal->AddRef (); pResource->AddRef (); _resourcesToWrite_Downstream.push (pResource); @@ -1796,6 +1803,8 @@ SK_D3D12_EnqueueResource_Down (SK_ITrackD3D12Resource* pResource) void SK_D3D12_EnqueueResource_Up (SK_ITrackD3D12Resource* pResource) { + if (! pResource) return; + pResource->pReal->AddRef (); pResource->AddRef (); _resourcesToWrite_Upstream.push (pResource); @@ -1852,11 +1861,14 @@ bool SK_D3D12_IsTextureInjectionNeeded (void) { for ( auto const& file : std::filesystem::directory_iterator { load_path, ec } ) { - if ( file.path ().has_extension () && - file.path ().extension ().compare (L".dds") == 0 ) + auto& file_path = + file.path (); + + if ( file_path.has_extension () && + file_path.extension ().compare (L".dds") == 0 ) { std::string name = - file.path ().stem ().string (); + file_path.stem ().string (); if (name.find ("d3d12_sk0_crc32c_") != std::string::npos) { @@ -1885,11 +1897,14 @@ bool SK_D3D12_IsTextureInjectionNeeded (void) { for ( auto const& file : std::filesystem::directory_iterator { path, ec } ) { - if ( file.path ().has_extension () && - file.path ().extension ().compare (L".dds") == 0 ) + auto& file_path = + file.path (); + + if ( file_path.has_extension () && + file_path.extension ().compare (L".dds") == 0 ) { std::string name = - file.path ().stem ().string (); + file_path.stem ().string (); if (name.find ("d3d12_sk0_crc32c_") != std::string::npos) { @@ -1946,8 +1961,6 @@ SK_D3D12_WriteResources (void) load_path = SK_Resource_GetRoot () / LR"(inject\textures)"; - std::error_code ec = { }; - if (pRes->uiFence == 0 && pRes->NextFrame <= SK_GetFramesDrawn () - 5) { auto &[pFence, uiFenceVal, ulNextFrame] = @@ -1991,6 +2004,7 @@ SK_D3D12_WriteResources (void) 0x0, image.GetPixels (), image.GetPixelsSize () ); + std::error_code ec = { }; if (! std::filesystem::is_directory (path, ec)) std::filesystem::create_directories (path, ec); diff --git a/src/render/dxgi/dxgi_swapchain.cpp b/src/render/dxgi/dxgi_swapchain.cpp index a5ecbf413..f0a90db80 100644 --- a/src/render/dxgi/dxgi_swapchain.cpp +++ b/src/render/dxgi/dxgi_swapchain.cpp @@ -2171,14 +2171,14 @@ SK_DXGI_SwapChain_ResizeBuffers_Impl ( if (Width == 0) Width = rcClient.right - rcClient.left; if (Height == 0) Height = rcClient.bottom - rcClient.top; - auto origWidth = Width; - auto origHeight = Height; + const auto origWidth = Width; + const auto origHeight = Height; const bool fake_fullscreen = rb.isFakeFullscreen (); - bool borderless = config.window.borderless || fake_fullscreen; - bool fullscreen = config.window.fullscreen || fake_fullscreen; + const bool borderless = config.window.borderless || fake_fullscreen; + const bool fullscreen = config.window.fullscreen || fake_fullscreen; if ( borderless && fullscreen && (! rb.fullscreen_exclusive) ) @@ -2196,8 +2196,8 @@ SK_DXGI_SwapChain_ResizeBuffers_Impl ( Width = w; Height = h; - if ( swap_desc.BufferDesc.Width != static_cast (w) || - swap_desc.BufferDesc.Height != static_cast (h) ) + if ( swap_desc.BufferDesc.Width != sk::narrow_cast (w) || + swap_desc.BufferDesc.Height != sk::narrow_cast (h) ) { if (w != 0 && h != 0) {