diff --git a/OptiScaler/Config.cpp b/OptiScaler/Config.cpp index 1cdb3a3f..98156a13 100644 --- a/OptiScaler/Config.cpp +++ b/OptiScaler/Config.cpp @@ -32,11 +32,8 @@ Config::Config(std::wstring fileName) bool Config::Reload(std::filesystem::path iniPath) { auto pathWStr = iniPath.wstring(); - std::string pathStr(pathWStr.length(), 0); - std::transform(pathWStr.begin(), pathWStr.end(), pathStr.begin(), [](wchar_t c) { return (char)c; }); - - spdlog::info("Trying to load ini from: {0}", pathStr); + spdlog::info("Trying to load ini from: {0}", wstring_to_string(pathWStr)); if (ini.LoadFile(iniPath.c_str()) == SI_OK) { // Upscalers @@ -601,10 +598,8 @@ bool Config::SaveIni() } auto pathWStr = absoluteFileName.wstring(); - std::string pathStr(pathWStr.length(), 0); - std::transform(pathWStr.begin(), pathWStr.end(), pathStr.begin(), [](wchar_t c) { return (char)c; }); - spdlog::info("Trying to save ini to: {0}", pathStr); + spdlog::info("Trying to save ini to: {0}", wstring_to_string(pathWStr)); return ini.SaveFile(absoluteFileName.wstring().c_str()) >= 0; } diff --git a/OptiScaler/NVNGX_DLSS_Dx11.cpp b/OptiScaler/NVNGX_DLSS_Dx11.cpp index e92b7d48..cd541dff 100644 --- a/OptiScaler/NVNGX_DLSS_Dx11.cpp +++ b/OptiScaler/NVNGX_DLSS_Dx11.cpp @@ -60,10 +60,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_Ext(unsigned long long InApp spdlog::info("NVSDK_NGX_D3D11_Init_Ext SDK: {0:x}", (int)InSDKVersion); std::wstring string(InApplicationDataPath); - std::string str(string.length(), 0); - std::transform(string.begin(), string.end(), str.begin(), [](wchar_t c) { return (char)c; }); - - spdlog::debug("NVSDK_NGX_D3D11_Init_Ext InApplicationDataPath {0}", str); + spdlog::debug("NVSDK_NGX_D3D11_Init_Ext InApplicationDataPath {0}", wstring_to_string(string)); Config::Instance()->NVNGX_FeatureInfo_Paths.clear(); @@ -74,11 +71,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D11_Init_Ext(unsigned long long InApp const wchar_t* path = InFeatureInfo->PathListInfo.Path[i]; std::wstring iniPathW(path); - std::string iniPath(iniPathW.length(), 0); - std::transform(iniPathW.begin(), iniPathW.end(), iniPath.begin(), [](wchar_t c) { return (char)c; }); - Config::Instance()->NVNGX_FeatureInfo_Paths.push_back(iniPathW); - spdlog::debug("NVSDK_NGX_D3D11_Init_Ext PathListInfo[{0}]: {1}", i, iniPath); + spdlog::debug("NVSDK_NGX_D3D11_Init_Ext PathListInfo[{0}]: {1}", i, wstring_to_string(iniPathW)); } } diff --git a/OptiScaler/NVNGX_DLSS_Dx12.cpp b/OptiScaler/NVNGX_DLSS_Dx12.cpp index c28ffcba..99c0832b 100644 --- a/OptiScaler/NVNGX_DLSS_Dx12.cpp +++ b/OptiScaler/NVNGX_DLSS_Dx12.cpp @@ -226,10 +226,7 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(unsigned long long InApp spdlog::info("NVSDK_NGX_D3D12_Init_Ext SDK: {0:x}", (unsigned int)InSDKVersion); appDataPath = InApplicationDataPath; - std::string str(appDataPath.length(), 0); - std::transform(appDataPath.begin(), appDataPath.end(), str.begin(), [](wchar_t c) { return (char)c; }); - - spdlog::info("NVSDK_NGX_D3D12_Init_Ext InApplicationDataPath {0}", str); + spdlog::info("NVSDK_NGX_D3D12_Init_Ext InApplicationDataPath {0}", wstring_to_string(appDataPath)); Config::Instance()->NVNGX_FeatureInfo_Paths.clear(); @@ -243,13 +240,10 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_D3D12_Init_Ext(unsigned long long InApp std::wstring iniPathW(path); - std::string iniPath(iniPathW.length(), 0); - std::transform(iniPathW.begin(), iniPathW.end(), iniPath.begin(), [](wchar_t c) { return (char)c; }); - - spdlog::debug("NVSDK_NGX_D3D12_Init_Ext PathListInfo[{1}] checking nvngx.ini file in: {0}", iniPath, i); + spdlog::debug("NVSDK_NGX_D3D12_Init_Ext PathListInfo[{1}] checking nvngx.ini file in: {0}", wstring_to_string(iniPathW), i); if (Config::Instance()->LoadFromPath(path)) - spdlog::info("NVSDK_NGX_D3D12_Init_Ext PathListInfo[{1}] nvngx.ini file reloaded from: {0}", iniPath, i); + spdlog::info("NVSDK_NGX_D3D12_Init_Ext PathListInfo[{1}] nvngx.ini file reloaded from: {0}", wstring_to_string(iniPathW), i); } } diff --git a/OptiScaler/NVNGX_DLSS_Vk.cpp b/OptiScaler/NVNGX_DLSS_Vk.cpp index d04bdb53..97b06882 100644 --- a/OptiScaler/NVNGX_DLSS_Vk.cpp +++ b/OptiScaler/NVNGX_DLSS_Vk.cpp @@ -98,22 +98,16 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_Ext2(unsigned long long InA } spdlog::info("NVSDK_NGX_VULKAN_Init_Ext2 InApplicationId: {0}", InApplicationId); - spdlog::info("NVSDK_NGX_VULKAN_Init_Ext2 InSDKVersion: {0:x}", (unsigned int)InSDKVersion); + spdlog::info("NVSDK_NGX_VULKAN_Init_Ext2 InSDKVersion: {0:x}", (UINT)InSDKVersion); std::wstring string(InApplicationDataPath); - std::string str(string.length(), 0); - std::transform(string.begin(), string.end(), str.begin(), [](wchar_t c) { return (char)c; }); - - spdlog::debug("NVSDK_NGX_VULKAN_Init_Ext2 InApplicationDataPath {0}", str); + spdlog::debug("NVSDK_NGX_VULKAN_Init_Ext2 InApplicationDataPath {0}", wstring_to_string(string)); if (Config::Instance()->NVNGX_FeatureInfo_Paths.size() > 0) { for (size_t i = 0; i < Config::Instance()->NVNGX_FeatureInfo_Paths.size(); ++i) { - std::string str(Config::Instance()->NVNGX_FeatureInfo_Paths[i].length(), 0); - std::transform(Config::Instance()->NVNGX_FeatureInfo_Paths[i].begin(), Config::Instance()->NVNGX_FeatureInfo_Paths[i].end(), str.begin(), [](wchar_t c) { return (char)c; }); - - spdlog::debug("NVSDK_NGX_VULKAN_Init_Ext2 PathListInfo[{0}]: {1}", i, str); + spdlog::debug("NVSDK_NGX_VULKAN_Init_Ext2 PathListInfo[{0}]: {1}", i, wstring_to_string(Config::Instance()->NVNGX_FeatureInfo_Paths[i])); } } diff --git a/OptiScaler/NVNGX_Proxy.h b/OptiScaler/NVNGX_Proxy.h index 708da793..500bab41 100644 --- a/OptiScaler/NVNGX_Proxy.h +++ b/OptiScaler/NVNGX_Proxy.h @@ -542,11 +542,7 @@ public: for (size_t i = 0; i < Config::Instance()->NVNGX_FeatureInfo_Paths.size(); ++i) { paths[i] = Config::Instance()->NVNGX_FeatureInfo_Paths[i].c_str(); - - std::string str(Config::Instance()->NVNGX_FeatureInfo_Paths[i].length(), 0); - std::transform(Config::Instance()->NVNGX_FeatureInfo_Paths[i].begin(), Config::Instance()->NVNGX_FeatureInfo_Paths[i].end(), str.begin(), [](wchar_t c) { return (char)c; }); - - spdlog::debug("NVNGXProxy::GetFeatureCommonInfo paths[{0}]: {1}", i, str); + spdlog::debug("NVNGXProxy::GetFeatureCommonInfo paths[{0}]: {1}", i, wstring_to_string(Config::Instance()->NVNGX_FeatureInfo_Paths[i])); } fcInfo->PathListInfo.Path = paths; diff --git a/OptiScaler/OptiScaler.vcxproj b/OptiScaler/OptiScaler.vcxproj index a1b322c2..9f3f03aa 100644 --- a/OptiScaler/OptiScaler.vcxproj +++ b/OptiScaler/OptiScaler.vcxproj @@ -81,8 +81,8 @@ $(SolutionDir)external\vulkan\include;$(SolutionDir)external\nvngx_dlss_sdk;$(SolutionDir)external\xess\inc\xess;$(SolutionDir)external\FidelityFX-SDK\ffx-api\include\ffx_api;$(SolutionDir)external\simpleini;$(SolutionDir)external\unordered_dense\include;$(SolutionDir)external\spdlog\include;$(IncludePath) $(ProjectDir)fsr2\lib;$(ProjectDir)fsr2_212\lib;$(ProjectDir)vulkan;$(ProjectDir)d3dx;$(ProjectDir)detours;$(SolutionDir)external\xess\lib;$(LibraryPath) - winmm - D:\Folders\Games\Deep Rock Galactic\FSD\Binaries\Win64\ + dxgi + D:\Folders\Games\SteamLibrary\steamapps\common\EVERSPACEā„¢ 2 - Demo\ES2\Binaries\Win64\ .\x64\Debug diff --git a/OptiScaler/backends/fsr2/FSR2Feature.h b/OptiScaler/backends/fsr2/FSR2Feature.h index cb9eeb41..67fba1c8 100644 --- a/OptiScaler/backends/fsr2/FSR2Feature.h +++ b/OptiScaler/backends/fsr2/FSR2Feature.h @@ -30,15 +30,13 @@ inline static std::string ResultToString(FfxErrorCode result) inline static void FfxLogCallback(FfxFsr2MsgType type, const wchar_t* message) { std::wstring string(message); - std::string str(string.length(), 0); - std::transform(string.begin(), string.end(), str.begin(), [](wchar_t c) { return (char)c; }); //if (type == FFX_FSR2_MESSAGE_TYPE_ERROR) // spdlog::error("FSR2Feature::LogCallback FSR Runtime: {0}", str); //else if (type == FFX_FSR2_MESSAGE_TYPE_WARNING) // spdlog::warn("FSR2Feature::LogCallback FSR Runtime: {0}", str); //else - spdlog::debug("FSR2Feature::LogCallback FSR Runtime: {0}", str); + spdlog::debug("FSR2Feature::LogCallback FSR Runtime: {0}", wstring_to_string(string)); } class FSR2Feature : public virtual IFeature diff --git a/OptiScaler/backends/fsr31/FSR31Feature.h b/OptiScaler/backends/fsr31/FSR31Feature.h index 1aae82af..f5941ac6 100644 --- a/OptiScaler/backends/fsr31/FSR31Feature.h +++ b/OptiScaler/backends/fsr31/FSR31Feature.h @@ -23,15 +23,13 @@ inline static std::string ResultToString(ffxReturnCode_t result) inline static void FfxLogCallback(uint32_t type, const wchar_t* message) { std::wstring string(message); - std::string str(string.length(), 0); - std::transform(string.begin(), string.end(), str.begin(), [](wchar_t c) { return (char)c; }); //if (type == FFX_API_MESSAGE_TYPE_ERROR) // spdlog::error("FSR31Feature::LogCallback FSR Runtime: {0}", str); //else if (type == FFX_API_MESSAGE_TYPE_WARNING) // spdlog::warn("FSR31Feature::LogCallback FSR Runtime: {0}", str); //else - spdlog::debug("FSR31Feature::LogCallback FSR Runtime: {0}", str); + spdlog::debug("FSR31Feature::LogCallback FSR Runtime: {0}", wstring_to_string(string)); } class FSR31Feature : public virtual IFeature diff --git a/OptiScaler/dllmain.cpp b/OptiScaler/dllmain.cpp index cb82c2ef..c8f8db05 100644 --- a/OptiScaler/dllmain.cpp +++ b/OptiScaler/dllmain.cpp @@ -228,8 +228,7 @@ static HMODULE hkLoadLibraryW(LPCWSTR lpLibFileName) for (size_t i = 0; i < lcaseLibName.size(); i++) lcaseLibName[i] = std::tolower(lcaseLibName[i]); - std::string lcaseLibNameA(lcaseLibName.length(), 0); - std::transform(lcaseLibName.begin(), lcaseLibName.end(), lcaseLibNameA.begin(), [](wchar_t c) { return (char)c; }); + auto lcaseLibNameA = wstring_to_string(lcaseLibName); #ifdef DEBUG spdlog::trace("hkLoadLibraryW call: {0}", lcaseLibNameA); @@ -452,8 +451,7 @@ static HMODULE hkLoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFla for (size_t i = 0; i < lcaseLibName.size(); i++) lcaseLibName[i] = std::tolower(lcaseLibName[i]); - std::string lcaseLibNameA(lcaseLibName.length(), 0); - std::transform(lcaseLibName.begin(), lcaseLibName.end(), lcaseLibNameA.begin(), [](wchar_t c) { return (char)c; }); + auto lcaseLibNameA = wstring_to_string(lcaseLibName); #ifdef DEBUG spdlog::trace("hkLoadLibraryExW call: {0}", lcaseLibNameA); diff --git a/OptiScaler/imgui/imgui_overlay_dx12.cpp b/OptiScaler/imgui/imgui_overlay_dx12.cpp index c734e3c1..455a3be0 100644 --- a/OptiScaler/imgui/imgui_overlay_dx12.cpp +++ b/OptiScaler/imgui/imgui_overlay_dx12.cpp @@ -1424,7 +1424,7 @@ static bool CheckDx12(ID3D12Device* InDevice) if (result != S_OK) { - spdlog::error("ImGuiOverlayDx12::CheckDx12 D3D12CreateDevice: {0:X}", (unsigned long)result); + spdlog::error("ImGuiOverlayDx12::CheckDx12 D3D12CreateDevice: {0:X}", (UINT)result); return false; } } @@ -1435,7 +1435,7 @@ static bool CheckDx12(ID3D12Device* InDevice) result = device->CreateCommandQueue(&desc, IID_PPV_ARGS(&cq)); if (result != S_OK) { - spdlog::error("ImGuiOverlayDx12::CheckDx12 CreateCommandQueue: {0:X}", (unsigned long)result); + spdlog::error("ImGuiOverlayDx12::CheckDx12 CreateCommandQueue: {0:X}", (UINT)result); return false; } @@ -1484,7 +1484,7 @@ static bool CheckFSR3() if (offxCreateFrameinterpolationSwapchainForHwndDX12_Mod != nullptr) { - spdlog::info("ImGuiOverlayDx12::CheckMods Uniscaler's ffxCreateFrameinterpolationSwapchainForHwndDX12 found"); + spdlog::info("ImGuiOverlayDx12::CheckFSR3 Uniscaler's ffxCreateFrameinterpolationSwapchainForHwndDX12 found"); _bindedFSR3_Uniscaler = true; _bindedFSR3_Mod = true; } @@ -1496,7 +1496,7 @@ static bool CheckFSR3() if (offxCreateFrameinterpolationSwapchainForHwndDX12_Mod != nullptr) { - spdlog::info("ImGuiOverlayDx12::CheckMods Nukem's ffxCreateFrameinterpolationSwapchainForHwndDX12 found"); + spdlog::info("ImGuiOverlayDx12::CheckFSR3 Nukem's ffxCreateFrameinterpolationSwapchainForHwndDX12 found"); _bindedFSR3_Mod = true; } } @@ -1523,7 +1523,7 @@ static bool CheckFSR3() // Hook FSR3 ffxGetDX12SwapchainPtr methods if (offxCreateFrameinterpolationSwapchainForHwndDX12_FSR3) { - spdlog::info("ImGuiOverlayDx12::CheckMods FSR3's ffxCreateFrameinterpolationSwapchainForHwndDX12 found"); + spdlog::info("ImGuiOverlayDx12::CheckFSR3 FSR3's ffxCreateFrameinterpolationSwapchainForHwndDX12 found"); _bindedFSR3_Native = true; DetourTransactionBegin(); @@ -1542,7 +1542,7 @@ static bool CheckFSR3() if (oFfxCreateContext_FSR3) { - spdlog::info("ImGuiOverlayDx12::CheckMods FSR3's ffxCreateContext found"); + spdlog::info("ImGuiOverlayDx12::CheckFSR3 FSR3's ffxCreateContext found"); _bindedFSR3_Native = true; DetourTransactionBegin(); @@ -1573,7 +1573,6 @@ static bool BindAll(HWND InHWnd, ID3D12Device* InDevice) do { - if (!CheckDx12(InDevice)) break; diff --git a/OptiScaler/pch.h b/OptiScaler/pch.h index c2eb0a94..c20b31e4 100644 --- a/OptiScaler/pch.h +++ b/OptiScaler/pch.h @@ -28,19 +28,11 @@ inline HMODULE dllModule; inline DWORD processId; -inline static std::string wstring_to_string(const std::wstring& wstr) +inline static std::string wstring_to_string(const std::wstring& wide_str) { - size_t len = std::wcstombs(nullptr, wstr.c_str(), 0); - - if (len == static_cast(-1)) - { - throw std::runtime_error("Conversion error"); - } - - std::vector str(len + 1); - std::wcstombs(str.data(), wstr.c_str(), len + 1); - - return std::string(str.data()); + std::string str(wide_str.length(), 0); + std::transform(wide_str.begin(), wide_str.end(), str.begin(), [](wchar_t c) { return (char)c; }); + return str; } inline static std::wstring string_to_wstring(const std::string& str)