From 83c82bfcd0fdbef01688dd932f00ccee7e975ad6 Mon Sep 17 00:00:00 2001 From: cdozdil Date: Thu, 19 Sep 2024 01:40:19 +0300 Subject: [PATCH] added specialk loading option --- OptiScaler/Config.cpp | 3 +++ OptiScaler/Config.h | 1 + OptiScaler/dllmain.cpp | 31 ++++++++++++++++--------------- OptiScaler/imgui/imgui_common.cpp | 3 +++ nvngx.ini | 5 +++++ 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/OptiScaler/Config.cpp b/OptiScaler/Config.cpp index b7c95696..f33da179 100644 --- a/OptiScaler/Config.cpp +++ b/OptiScaler/Config.cpp @@ -323,6 +323,8 @@ bool Config::Reload(std::filesystem::path iniPath) { PluginPath = string_to_wstring(pluginsPathA.value()); } + + LoadSpecialK = readBool("Plugins", "LoadSpecialK"); } // DLSS Enabler @@ -608,6 +610,7 @@ bool Config::SaveIni() // Plugins { ini.SetValue("Plugins", "Path", Instance()->PluginPath.has_value() ? wstring_to_string(Instance()->PluginPath.value()).c_str() : "auto"); + ini.SetValue("Plugins", "LoadSpecialK", GetBoolValue(Instance()->LoadSpecialK).c_str()); } auto pathWStr = absoluteFileName.wstring(); diff --git a/OptiScaler/Config.h b/OptiScaler/Config.h index 2f04c332..982f0b16 100644 --- a/OptiScaler/Config.h +++ b/OptiScaler/Config.h @@ -151,6 +151,7 @@ public: // plugins std::optional PluginPath; + std::optional LoadSpecialK; // nvngx init parameters unsigned long long NVNGX_ApplicationId = 1337; diff --git a/OptiScaler/dllmain.cpp b/OptiScaler/dllmain.cpp index 904c4f4b..443f9639 100644 --- a/OptiScaler/dllmain.cpp +++ b/OptiScaler/dllmain.cpp @@ -917,6 +917,12 @@ static VkResult hkvkEnumerateInstanceExtensionProperties(const char* pLayerName, static void DetachHooks() { + if (!isNvngxMode) + { + ImGuiOverlayDx::UnHookDx(); + ImGuiOverlayVk::UnHookVk(); + } + if (o_LoadLibraryA != nullptr || o_LoadLibraryW != nullptr || o_LoadLibraryExA != nullptr || o_LoadLibraryExW != nullptr) { DetourTransactionBegin(); @@ -1026,12 +1032,6 @@ static void DetachHooks() FreeLibrary(shared.dll); } - - if (!isNvngxMode) - { - ImGuiOverlayDx::UnHookDx(); - ImGuiOverlayVk::UnHookVk(); - } } static void AttachHooks() @@ -1497,7 +1497,7 @@ static void CheckWorkingMode() if (modeFound) { AttachHooks(); - + Config::Instance()->OverlayMenu = (!isNvngxMode || isWorkingWithEnabler) && Config::Instance()->OverlayMenu.value_or(true); if (Config::Instance()->OverlayMenu.value()) { @@ -1515,7 +1515,6 @@ static void CheckWorkingMode() BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { - switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: @@ -1525,13 +1524,14 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv return TRUE; } - DisableThreadLibraryCalls(hModule); - - loadCount++; dllModule = hModule; processId = GetCurrentProcessId(); + DisableThreadLibraryCalls(hModule); + + loadCount++; + #ifdef VER_PRE_RELEASE // Enable file logging for pre builds Config::Instance()->LogToFile = true; @@ -1599,13 +1599,14 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv break; case DLL_PROCESS_DETACH: -#ifdef _DEBUG - LOG_TRACE("DLL_PROCESS_DETACH from module: {0:X}, count: {1}", (UINT64)hModule, loadCount); -#endif + DetachHooks(); + + if (skHandle != nullptr) + FreeLibrary(skHandle); + spdlog::info(""); spdlog::info("Unloading OptiScaler"); CloseLogger(); - DetachHooks(); break; diff --git a/OptiScaler/imgui/imgui_common.cpp b/OptiScaler/imgui/imgui_common.cpp index 1e459733..9c9531cd 100644 --- a/OptiScaler/imgui/imgui_common.cpp +++ b/OptiScaler/imgui/imgui_common.cpp @@ -2036,6 +2036,9 @@ void ImGuiCommon::Init(HWND InHwnd) _selectedScale = (int)((Config::Instance()->MenuScale.value_or(1.0f) - 1.0f) / 0.1f); _isInited = true; + + if (Config::Instance()->LoadSpecialK.value_or(false)) + skHandle = LoadLibrary(L"SpecialK64.dll"); } void ImGuiCommon::Shutdown() diff --git a/nvngx.ini b/nvngx.ini index a4322083..b2bef3b6 100644 --- a/nvngx.ini +++ b/nvngx.ini @@ -223,6 +223,11 @@ VulkanExtensionSpoofing=auto ; Default is .\plugins Path=auto +; Loads SpecialK64.dll from game's exe folder +; Please put a SpecialK.dxgi file next to SpecialK64.dll +; to set SpecialK's working mode otherwise it will not be activated +; true or false - Default (auto) is false +LoadSpecialK=auto