From fb795e61c2d2013eb891d7f23d3cf3e8defa3b1a Mon Sep 17 00:00:00 2001 From: cdozdil Date: Thu, 18 Sep 2025 16:41:34 +0300 Subject: [PATCH] Added enable/disable FG shortcut key --- OptiScaler.ini | 5 +++++ OptiScaler/Config.cpp | 6 ++++++ OptiScaler/Config.h | 1 + OptiScaler/dllmain.cpp | 4 ---- OptiScaler/menu/menu_common.cpp | 38 +++++++++++++++++++++++++++------ 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/OptiScaler.ini b/OptiScaler.ini index c0bde946..32d02eab 100644 --- a/OptiScaler.ini +++ b/OptiScaler.ini @@ -581,6 +581,11 @@ FpsOverlayHorizontal=auto ; 0.0 to 1.0 - Default (auto) is 0.4 FpsOverlayAlpha=auto +; Shortcut key for enable/disable FG +; Integer value - Default (auto) is 0x23 -> VK_END +; -1 -> No shortcut key +FGShortcutKey=auto + ; ------------------------------------------------------- diff --git a/OptiScaler/Config.cpp b/OptiScaler/Config.cpp index 3630dd53..ae9a0ce6 100644 --- a/OptiScaler/Config.cpp +++ b/OptiScaler/Config.cpp @@ -333,6 +333,8 @@ bool Config::Reload(std::filesystem::path iniPath) FpsScale.set_from_config(std::clamp(setting.value(), 0.5f, 2.0f)); TTFFontPath.set_from_config(readWString("Menu", "TTFFontPath")); + + FGShortcutKey.set_from_config(readInt("Menu", "FGShortcutKey")); } // Hooks @@ -836,6 +838,10 @@ bool Config::SaveIni() ini.SetValue("Menu", "UseHQFont", GetBoolValue(Instance()->UseHQFont.value_for_config()).c_str()); ini.SetValue("Menu", "DisableSplash", GetBoolValue(Instance()->DisableSplash.value_for_config()).c_str()); + setting = Instance()->FGShortcutKey.value_for_config(); + ini.SetValue("Menu", "FGShortcutKey", + GetIntValue(Instance()->FGShortcutKey.value_for_config(), setting > 0).c_str()); + setting = Instance()->FpsShortcutKey.value_for_config(); ini.SetValue("Menu", "FpsShortcutKey", GetIntValue(Instance()->FpsShortcutKey.value_for_config(), setting > 0).c_str()); diff --git a/OptiScaler/Config.h b/OptiScaler/Config.h index e4042c80..ef29c902 100644 --- a/OptiScaler/Config.h +++ b/OptiScaler/Config.h @@ -243,6 +243,7 @@ class Config CustomOptional UseHQFont { true }; CustomOptional DisableSplash { false }; CustomOptional TTFFontPath; + CustomOptional FGShortcutKey { VK_END }; // Hooks CustomOptional HookOriginalNvngxOnly { false }; diff --git a/OptiScaler/dllmain.cpp b/OptiScaler/dllmain.cpp index 21ae63b6..92ed52ec 100644 --- a/OptiScaler/dllmain.cpp +++ b/OptiScaler/dllmain.cpp @@ -677,8 +677,6 @@ static void CheckWorkingMode() { LOG_DEBUG("dxgi.dll already in memory"); - CheckForGPU(); - DxgiProxy::Init(dxgiModule); if (Config::Instance()->DxgiSpoofing.value_or_default()) @@ -692,8 +690,6 @@ static void CheckWorkingMode() { LOG_DEBUG("dxgi.dll already in memory"); - CheckForGPU(); - if (Config::Instance()->DxgiSpoofing.value_or_default()) HookDxgiForSpoofing(); diff --git a/OptiScaler/menu/menu_common.cpp b/OptiScaler/menu/menu_common.cpp index f9fb1c29..10b2dba8 100644 --- a/OptiScaler/menu/menu_common.cpp +++ b/OptiScaler/menu/menu_common.cpp @@ -10,7 +10,7 @@ #include -#include +#include #include #include @@ -28,6 +28,7 @@ static bool _hdrTonemapApplied = false; static ImVec4 SdrColors[ImGuiCol_COUNT]; static bool receivingWmInputs = false; static bool inputMenu = false; +static bool inputFG = false; static bool inputFps = false; static bool inputFpsCycle = false; static bool hasGamepad = false; @@ -683,6 +684,9 @@ LRESULT MenuCommon::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) if (!inputFps) inputFps = rawData.data.keyboard.VKey == Config::Instance()->FpsShortcutKey.value_or_default(); + if (!inputFG) + inputFG = rawData.data.keyboard.VKey == Config::Instance()->FGShortcutKey.value_or_default(); + if (!inputFpsCycle) inputFpsCycle = rawData.data.keyboard.VKey == Config::Instance()->FpsCycleShortcutKey.value_or_default(); @@ -698,6 +702,9 @@ LRESULT MenuCommon::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) if (!inputFps) inputFps = msg == WM_KEYUP && wParam == Config::Instance()->FpsShortcutKey.value_or_default(); + if (!inputFG) + inputFG = msg == WM_KEYUP && wParam == Config::Instance()->FGShortcutKey.value_or_default(); + if (!inputFpsCycle) inputFpsCycle = msg == WM_KEYUP && wParam == Config::Instance()->FpsCycleShortcutKey.value_or_default(); @@ -855,6 +862,7 @@ void KeyUp(UINT vKey) { inputMenu = vKey == Config::Instance()->ShortcutKey.value_or_default(); inputFps = vKey == Config::Instance()->FpsShortcutKey.value_or_default(); + inputFG = vKey == Config::Instance()->FGShortcutKey.value_or_default(); inputFpsCycle = vKey == Config::Instance()->FpsCycleShortcutKey.value_or_default(); } @@ -1350,6 +1358,21 @@ bool MenuCommon::RenderMenu() // Handle Inputs { + if (inputFG) + { + inputFG = false; + + if (State::Instance().activeFgInput != FGInput::NoFG && + State::Instance().activeFgOutput != FGOutput::NoFG && + (State::Instance().api != API::Vulkan || State::Instance().activeFgInput == FGInput::Nukems)) + { + Config::Instance()->FGEnabled = !Config::Instance()->FGEnabled.value_or_default(); + + if (Config::Instance()->FGEnabled.value_or_default()) + State::Instance().FGchanged = true; + } + } + if (inputFps) { inputFps = false; @@ -1853,6 +1876,9 @@ bool MenuCommon::RenderMenu() if (!_isVisible) return false; + // Check for gpu support + CheckForGPU(); + { // Overlay font if (Config::Instance()->UseHQFont.value_or_default()) @@ -3024,11 +3050,9 @@ bool MenuCommon::RenderMenu() ImGui::TreePop(); } - FSRFG_Dx12* fsrFG = nullptr; - if (State::Instance().currentFG != nullptr) - fsrFG = reinterpret_cast(State::Instance().currentFG); - - if (fsrFG != nullptr && FfxApiProxy::VersionDx12() >= feature_version { 3, 1, 3 }) + auto fg = State::Instance().currentFG; + if (fg != nullptr && strcmp(fg->Name(), "FSR-FG") == 0 && + FfxApiProxy::VersionDx12() >= feature_version { 3, 1, 3 }) { ImGui::Spacing(); if (ImGui::TreeNode("Frame Pacing Tuning")) @@ -4743,10 +4767,12 @@ bool MenuCommon::RenderMenu() static auto menu = Keybind("Menu", 10); static auto fpsOverlay = Keybind("FPS Overlay", 11); static auto fpsOverlayCycle = Keybind("FPS Overlay Cycle", 12); + static auto fgEnable = Keybind("Frame Generation", 13); menu.Render(Config::Instance()->ShortcutKey); fpsOverlay.Render(Config::Instance()->FpsShortcutKey); fpsOverlayCycle.Render(Config::Instance()->FpsCycleShortcutKey); + fgEnable.Render(Config::Instance()->FGShortcutKey); } ImGui::EndTable();