diff --git a/OptiScaler/FSR4Upgrade.h b/OptiScaler/FSR4Upgrade.h
index ca34cac8..54f64a8b 100644
--- a/OptiScaler/FSR4Upgrade.h
+++ b/OptiScaler/FSR4Upgrade.h
@@ -197,9 +197,9 @@ struct AmdExtFfxApi : public IAmdExtFfxApi
if (pfnUpdateFfxApiProvider != nullptr)
{
- State::DisableChecks();
+ State::DisableChecks(1);
auto result = pfnUpdateFfxApiProvider(pData, dataSizeInBytes);
- State::EnableChecks();
+ State::EnableChecks(1);
return result;
}
diff --git a/OptiScaler/Logger.cpp b/OptiScaler/Logger.cpp
index 9c146139..48abe519 100644
--- a/OptiScaler/Logger.cpp
+++ b/OptiScaler/Logger.cpp
@@ -49,13 +49,19 @@ static bool InitializeConsole()
// Make C++ standard streams point to console as well.
std::ios::sync_with_stdio();
+ WaitForEnter();
+
+ return true;
+}
+
+
+void WaitForEnter()
+{
if (Config::Instance()->DebugWait.value_or_default())
{
std::cout << "Press ENTER to continue..." << std::endl;
std::cin.get();
}
-
- return true;
}
void PrepareLogger()
diff --git a/OptiScaler/Logger.h b/OptiScaler/Logger.h
index 71b36e2c..6d0a4944 100644
--- a/OptiScaler/Logger.h
+++ b/OptiScaler/Logger.h
@@ -4,6 +4,7 @@
void PrepareLogger();
void CloseLogger();
+void WaitForEnter();
#ifdef DLSS_PARAM_DUMP
diff --git a/OptiScaler/OptiScaler.vcxproj b/OptiScaler/OptiScaler.vcxproj
index 0522655a..c7573afc 100644
--- a/OptiScaler/OptiScaler.vcxproj
+++ b/OptiScaler/OptiScaler.vcxproj
@@ -199,7 +199,7 @@
Windows
true
false
- libMinHook.x64.lib;WindowsApp.lib;Dbghelp.lib;dxgi.lib;d3d11.lib;d3d12.lib;vulkan-1.lib;dxguid.lib;freetype.lib;ffx_fsr2_api_x64d.lib;ffx_fsr2_api_dx11_x64d.lib;ffx_fsr2_api_dx12_x64d.lib;ffx_fsr2_api_vk_x64d.lib;ffx_fsr2_212_api_dx12_x64d.lib;ffx_fsr2_212_api_vk_x64d.lib;ffx_fsr2_212_api_x64d.lib;d3dcompiler.lib;d3dx11.lib;ffx_backend_dx11_x64d.lib;ffx_fsr3_x64d.lib;ffx_fsr3upscaler_x64d.lib;ffx_opticalflow_x64d.lib;ffx_frameinterpolation_x64d.lib;%(AdditionalDependencies)
+ WindowsApp.lib;Dbghelp.lib;dxgi.lib;d3d11.lib;d3d12.lib;vulkan-1.lib;dxguid.lib;freetype.lib;ffx_fsr2_api_x64d.lib;ffx_fsr2_api_dx11_x64d.lib;ffx_fsr2_api_dx12_x64d.lib;ffx_fsr2_api_vk_x64d.lib;ffx_fsr2_212_api_dx12_x64d.lib;ffx_fsr2_212_api_vk_x64d.lib;ffx_fsr2_212_api_x64d.lib;d3dcompiler.lib;d3dx11.lib;ffx_backend_dx11_x64d.lib;ffx_fsr3_x64d.lib;ffx_fsr3upscaler_x64d.lib;ffx_opticalflow_x64d.lib;ffx_frameinterpolation_x64d.lib;%(AdditionalDependencies)
Source.def
vulkan-1.dll;dxgi.dll;d3d12.dll;D3DCOMPILER_47.dll;Dbghelp.dll
@@ -236,7 +236,7 @@
true
false
false
- libMinHook.x64.lib;WindowsApp.lib;Dbghelp.lib;dxgi.lib;d3d11.lib;d3d12.lib;vulkan-1.lib;dxguid.lib;freetype.lib;ffx_fsr2_api_x64.lib;ffx_fsr2_api_dx11_x64.lib;ffx_fsr2_api_dx12_x64.lib;ffx_fsr2_api_vk_x64.lib;ffx_fsr2_212_api_dx12_x64.lib;ffx_fsr2_212_api_vk_x64.lib;ffx_fsr2_212_api_x64.lib;d3dcompiler.lib;ffx_backend_dx11_x64.lib;ffx_fsr3_x64.lib;ffx_frameinterpolation_x64.lib;ffx_fsr3upscaler_x64.lib;ffx_opticalflow_x64.lib;%(AdditionalDependencies)
+ WindowsApp.lib;Dbghelp.lib;dxgi.lib;d3d11.lib;d3d12.lib;vulkan-1.lib;dxguid.lib;freetype.lib;ffx_fsr2_api_x64.lib;ffx_fsr2_api_dx11_x64.lib;ffx_fsr2_api_dx12_x64.lib;ffx_fsr2_api_vk_x64.lib;ffx_fsr2_212_api_dx12_x64.lib;ffx_fsr2_212_api_vk_x64.lib;ffx_fsr2_212_api_x64.lib;d3dcompiler.lib;ffx_backend_dx11_x64.lib;ffx_fsr3_x64.lib;ffx_frameinterpolation_x64.lib;ffx_fsr3upscaler_x64.lib;ffx_opticalflow_x64.lib;%(AdditionalDependencies)
UseLinkTimeCodeGeneration
Source.def
vulkan-1.dll;dxgi.dll;d3d12.dll;D3DCOMPILER_47.dll;Dbghelp.dll
@@ -286,7 +286,7 @@ copy NUL "$(SolutionDir)x64\Release\a\!! EXTRACT ALL FILES TO GAME FOLDER !!" /Y
true
true
false
- libMinHook.x64.lib;WindowsApp.lib;Dbghelp.lib;dxgi.lib;d3d11.lib;d3d12.lib;vulkan-1.lib;dxguid.lib;freetype.lib;ffx_fsr2_api_x64.lib;ffx_fsr2_api_dx11_x64.lib;ffx_fsr2_api_dx12_x64.lib;ffx_fsr2_api_vk_x64.lib;ffx_fsr2_212_api_dx12_x64.lib;ffx_fsr2_212_api_vk_x64.lib;ffx_fsr2_212_api_x64.lib;d3dcompiler.lib;ffx_backend_dx11_x64.lib;ffx_fsr3_x64.lib;ffx_frameinterpolation_x64.lib;ffx_fsr3upscaler_x64.lib;ffx_opticalflow_x64.lib;%(AdditionalDependencies)
+ WindowsApp.lib;Dbghelp.lib;dxgi.lib;d3d11.lib;d3d12.lib;vulkan-1.lib;dxguid.lib;freetype.lib;ffx_fsr2_api_x64.lib;ffx_fsr2_api_dx11_x64.lib;ffx_fsr2_api_dx12_x64.lib;ffx_fsr2_api_vk_x64.lib;ffx_fsr2_212_api_dx12_x64.lib;ffx_fsr2_212_api_vk_x64.lib;ffx_fsr2_212_api_x64.lib;d3dcompiler.lib;ffx_backend_dx11_x64.lib;ffx_fsr3_x64.lib;ffx_frameinterpolation_x64.lib;ffx_fsr3upscaler_x64.lib;ffx_opticalflow_x64.lib;%(AdditionalDependencies)
UseLinkTimeCodeGeneration
Source.def
vulkan-1.dll;dxgi.dll;d3d12.dll;D3DCOMPILER_47.dll;Dbghelp.dll
diff --git a/OptiScaler/State.h b/OptiScaler/State.h
index 3b785bda..53d59e8c 100644
--- a/OptiScaler/State.h
+++ b/OptiScaler/State.h
@@ -168,16 +168,28 @@ public:
/// Enables skipping of LoadLibrary checks
///
/// Lower case dll name without `.dll` at the end. Leave blank for skipping all dll's
- static void DisableChecks(std::string dllName = "")
+ static void DisableChecks(UINT owner, std::string dllName = "")
{
- _skipChecks = true;
- _skipDllName = dllName;
+ if (_skipOwner == 0)
+ {
+ _skipOwner = owner;
+ _skipChecks = true;
+ _skipDllName = dllName;
+ }
+ else
+ {
+ _skipDllName = ""; // Hack for multiple skip calls
+ }
};
- static void EnableChecks()
+ static void EnableChecks(UINT owner)
{
- _skipChecks = false;
- _skipDllName = "";
+ if (_skipOwner == 0 || _skipOwner == owner)
+ {
+ _skipChecks = false;
+ _skipDllName = "";
+ _skipOwner = 0;
+ }
};
static bool SkipDllChecks() { return _skipChecks; }
@@ -187,6 +199,7 @@ public:
private:
inline static bool _skipChecks = false;
inline static std::string _skipDllName = "";
+ inline static UINT _skipOwner = 0;
State() = default;
};
\ No newline at end of file
diff --git a/OptiScaler/dllmain.cpp b/OptiScaler/dllmain.cpp
index dbac7a60..5876f374 100644
--- a/OptiScaler/dllmain.cpp
+++ b/OptiScaler/dllmain.cpp
@@ -29,8 +29,6 @@
#include
-#include
-
#pragma warning (disable : 4996)
typedef const char* (CDECL* PFN_wine_get_version)(void);
@@ -97,10 +95,6 @@ static void CheckWorkingMode()
break;
}
- // Hook kernel32 & kernelbase methods
- InitFSR4Update();
- KernelHooks::Hook();
-
// version.dll
if (lCaseFilename == "version.dll")
{
@@ -496,12 +490,13 @@ static void CheckWorkingMode()
if (!State::Instance().enablerAvailable && Config::Instance()->DxgiSpoofing.value_or_default())
HookDxgiForSpoofing();
- if (Config::Instance()->OverlayMenu.value())
+ if (Config::Instance()->OverlayMenu.value())
HooksDx::HookDxgi();
}
}
else
{
+ LOG_DEBUG("dxgi.dll already in memory");
if (!State::Instance().enablerAvailable && Config::Instance()->DxgiSpoofing.value_or_default())
HookDxgiForSpoofing();
@@ -523,6 +518,7 @@ static void CheckWorkingMode()
}
else
{
+ LOG_DEBUG("d3d12.dll already in memory");
HooksDx::HookDx12();
}
@@ -557,6 +553,10 @@ static void CheckWorkingMode()
if (Config::Instance()->OverlayMenu.value() && vulkanModule != nullptr)
HooksVk::HookVk(vulkanModule);
+ // Hook kernel32 & kernelbase methods
+ InitFSR4Update();
+ KernelHooks::Hook();
+
// NVAPI
HMODULE nvapi64 = nullptr;
nvapi64 = KernelBaseProxy::GetModuleHandleW_()(L"nvapi64.dll");
diff --git a/OptiScaler/exports/dxgi.h b/OptiScaler/exports/dxgi.h
index 77e1e160..a0b96249 100644
--- a/OptiScaler/exports/dxgi.h
+++ b/OptiScaler/exports/dxgi.h
@@ -49,12 +49,12 @@ struct dxgi_dll
HRESULT _CreateDXGIFactory(REFIID riid, IDXGIFactory** ppFactory)
{
- return DxgiProxy::CreateDxgiFactory_Hooked()(riid, ppFactory);
+ return DxgiProxy::CreateDxgiFactory_()(riid, ppFactory);
}
HRESULT _CreateDXGIFactory1(REFIID riid, IDXGIFactory1** ppFactory)
{
- return DxgiProxy::CreateDxgiFactory1_Hooked()(riid, ppFactory);
+ return DxgiProxy::CreateDxgiFactory1_()(riid, ppFactory);
}
HRESULT _CreateDXGIFactory2(UINT Flags, REFIID riid, IDXGIFactory2** ppFactory)
@@ -64,12 +64,12 @@ HRESULT _CreateDXGIFactory2(UINT Flags, REFIID riid, IDXGIFactory2** ppFactory)
HRESULT _DXGIDeclareAdapterRemovalSupport()
{
- return DxgiProxy::DeclareAdepterRemovalSupport_Hooked()();
+ return DxgiProxy::DeclareAdepterRemovalSupport_()();
}
HRESULT _DXGIGetDebugInterface1(UINT Flags, REFIID riid, void** pDebug)
{
- return DxgiProxy::GetDebugInterface_Hooked()(Flags, riid, pDebug);
+ return DxgiProxy::GetDebugInterface_()(Flags, riid, pDebug);
}
void _ApplyCompatResolutionQuirking()
diff --git a/OptiScaler/hooks/HooksDx.cpp b/OptiScaler/hooks/HooksDx.cpp
index 7b29a930..bb32fae2 100644
--- a/OptiScaler/hooks/HooksDx.cpp
+++ b/OptiScaler/hooks/HooksDx.cpp
@@ -2317,6 +2317,8 @@ static void CheckAdapter(IUnknown* unkAdapter)
static void AttachToFactory(IUnknown* unkFactory)
{
+ return;
+
PVOID* pVTable = *(PVOID**)unkFactory;
IDXGIFactory* factory;
@@ -3229,17 +3231,15 @@ static HRESULT hkCreateDXGIFactory1(REFIID riid, IDXGIFactory1** ppFactory)
oCreateSwapChain = (PFN_CreateSwapChain)pFactoryVTable[10];
- // Hook CreateSwapChainForHwnd & CreateSwapChainForCoreWindow here
- // Because GoW only create a IDXGIFactory1 and query it
- IDXGIFactory2* factory2 = nullptr;
- if (real->QueryInterface(IID_PPV_ARGS(&factory2)) == S_OK && factory2 != nullptr)
- {
- pFactoryVTable = *reinterpret_cast(factory2);
- factory2->Release();
+ //IDXGIFactory2* factory2 = nullptr;
+ //if (real->QueryInterface(IID_PPV_ARGS(&factory2)) == S_OK && factory2 != nullptr)
+ //{
+ // pFactoryVTable = *reinterpret_cast(factory2);
+ // factory2->Release();
- oCreateSwapChainForHwnd = (PFN_CreateSwapChainForHwnd)pFactoryVTable[15];
- oCreateSwapChainForCoreWindow = (PFN_CreateSwapChainForCoreWindow)pFactoryVTable[16];
- }
+ // oCreateSwapChainForHwnd = (PFN_CreateSwapChainForHwnd)pFactoryVTable[15];
+ // oCreateSwapChainForCoreWindow = (PFN_CreateSwapChainForCoreWindow)pFactoryVTable[16];
+ //}
if (oCreateSwapChain != nullptr)
{
@@ -3319,15 +3319,16 @@ static HRESULT hkCreateDXGIFactory2(UINT Flags, REFIID riid, IDXGIFactory2** ppF
static HRESULT hkEnumAdapterByGpuPreference(IDXGIFactory6* This, UINT Adapter, DXGI_GPU_PREFERENCE GpuPreference, REFIID riid, IUnknown** ppvAdapter)
{
- LOG_FUNC();
+ LOG_TRACE("HooksDx Adapter: {}, GpuPreference: {}", Adapter, (UINT)GpuPreference);
- State::DisableChecks("dxgi");
+ State::DisableChecks(2, "dxgi");
auto result = o_EnumAdapterByGpuPreference(This, Adapter, GpuPreference, riid, ppvAdapter);
- State::EnableChecks();
+ State::EnableChecks(2);
if (result == S_OK)
CheckAdapter(*ppvAdapter);
+ LOG_TRACE("HooksDx result: {:X}, Adapter: {:X}", (UINT)result, (size_t)*ppvAdapter);
return result;
}
@@ -3335,9 +3336,9 @@ static HRESULT hkEnumAdapterByLuid(IDXGIFactory4* This, LUID AdapterLuid, REFIID
{
LOG_FUNC();
- State::DisableChecks("dxgi");
+ State::DisableChecks(3, "dxgi");
auto result = o_EnumAdapterByLuid(This, AdapterLuid, riid, ppvAdapter);
- State::EnableChecks();
+ State::EnableChecks(3);
if (result == S_OK)
CheckAdapter(*ppvAdapter);
@@ -3349,9 +3350,9 @@ static HRESULT hkEnumAdapters1(IDXGIFactory1* This, UINT Adapter, IUnknown** ppA
{
LOG_TRACE("HooksDx");
- State::DisableChecks("dxgi");
+ State::DisableChecks(4, "dxgi");
HRESULT result = o_EnumAdapters1(This, Adapter, ppAdapter);
- State::EnableChecks();
+ State::EnableChecks(4);
if (result == S_OK)
CheckAdapter(*ppAdapter);
@@ -3363,9 +3364,9 @@ static HRESULT hkEnumAdapters(IDXGIFactory* This, UINT Adapter, IUnknown** ppAda
{
LOG_FUNC();
- State::DisableChecks("dxgi");
+ State::DisableChecks(5, "dxgi");
HRESULT result = o_EnumAdapters(This, Adapter, ppAdapter);
- State::EnableChecks();
+ State::EnableChecks(5);
if (result == S_OK)
CheckAdapter(*ppAdapter);
@@ -3808,8 +3809,7 @@ static void CALLBACK D3D12DebugCallback(D3D12_MESSAGE_CATEGORY Category, D3D12_M
static HRESULT hkD3D12CreateDevice(IDXGIAdapter* pAdapter, D3D_FEATURE_LEVEL MinimumFeatureLevel, REFIID riid, void** ppDevice)
{
- LOG_FUNC();
-
+ LOG_TRACE("Adapter: {:X}, Level: {:X}", (size_t)pAdapter, (UINT)MinimumFeatureLevel);
#ifdef ENABLE_DEBUG_LAYER_DX12
LOG_WARN("Debug layers active!");
@@ -3824,11 +3824,23 @@ static HRESULT hkD3D12CreateDevice(IDXGIAdapter* pAdapter, D3D_FEATURE_LEVEL Min
}
#endif
+#if _DEBUG
+ State::Instance().skipSpoofing = true;
+ DXGI_ADAPTER_DESC desc;
+ if (pAdapter->GetDesc(&desc) == S_OK)
+ {
+ std::wstring szName(desc.Description);
+ LOG_INFO("Adapter Desc: {}", wstring_to_string(szName));
+ }
+ State::Instance().skipSpoofing = false;
+#endif
+
auto minLevel = MinimumFeatureLevel;
if (Config::Instance()->SpoofFeatureLevel.value_or_default())
minLevel = D3D_FEATURE_LEVEL_11_0;
- HRESULT result = o_D3D12CreateDevice(pAdapter, minLevel, riid, ppDevice);
+ auto result = o_D3D12CreateDevice(pAdapter, minLevel, riid, ppDevice);
+ LOG_DEBUG("o_D3D12CreateDevice result: {:X}", (UINT)result);
if (result == S_OK && ppDevice != nullptr && *ppDevice != nullptr)
{
@@ -3867,8 +3879,7 @@ static HRESULT hkD3D12CreateDevice(IDXGIAdapter* pAdapter, D3D_FEATURE_LEVEL Min
#endif
}
- LOG_DEBUG("result: {:X}", (UINT)result);
-
+ LOG_DEBUG("final result: {:X}", (UINT)result);
return result;
}
diff --git a/OptiScaler/hooks/Kernel_Hooks.h b/OptiScaler/hooks/Kernel_Hooks.h
index 44f3372a..0d3b9d4d 100644
--- a/OptiScaler/hooks/Kernel_Hooks.h
+++ b/OptiScaler/hooks/Kernel_Hooks.h
@@ -59,6 +59,12 @@ private:
{
LOG_TRACE("{}", lcaseLibName);
+ if (lcaseLibName.rfind("driverstore") != std::string::npos)
+ {
+ LOG_DEBUG("Skip driver call: {}", lcaseLibName);
+ return nullptr;
+ }
+
// If Opti is not loading as nvngx.dll
if (!State::Instance().enablerAvailable && !State::Instance().isWorkingAsNvngx)
{
@@ -236,7 +242,7 @@ private:
if (module != nullptr)
{
DxgiProxy::Init(module);
-
+
if (!State::Instance().enablerAvailable && Config::Instance()->DxgiSpoofing.value_or_default())
HookDxgiForSpoofing();
@@ -341,6 +347,12 @@ private:
auto lcaseLibNameA = wstring_to_string(lcaseLibName);
LOG_TRACE("{}", lcaseLibNameA);
+ if (lcaseLibNameA.rfind("driverstore") != std::string::npos)
+ {
+ LOG_DEBUG("Skip driver call: {}", lcaseLibNameA);
+ return nullptr;
+ }
+
// If Opti is not loading as nvngx.dll
if (!State::Instance().enablerAvailable && !State::Instance().isWorkingAsNvngx)
{
@@ -725,7 +737,7 @@ private:
{
if (State::SkipDllName() == "")
{
- LOG_INFO("Skip checks for: {}", lcaseLibName);
+ LOG_TRACE("Skip checks for: {}", lcaseLibName);
return o_KB_LoadLibraryExA(lpLibFileName, hFile, dwFlags);
}
@@ -735,7 +747,7 @@ private:
// -4 for extension `.dll`
if (pos == (lcaseLibName.length() - dllName.length()) || pos == (lcaseLibName.length() - dllName.length() - 4))
{
- LOG_INFO("Skip checks for: {}", lcaseLibName);
+ LOG_TRACE("Skip checks for: {}", lcaseLibName);
return o_KB_LoadLibraryExA(lpLibFileName, hFile, dwFlags);
}
}
@@ -773,7 +785,7 @@ private:
{
if (State::SkipDllName() == "")
{
- LOG_INFO("Skip checks for: {}", wstring_to_string(lcaseLibName));
+ LOG_TRACE("Skip checks for: {}", wstring_to_string(lcaseLibName));
return o_KB_LoadLibraryExW(lpLibFileName, hFile, dwFlags);
}
@@ -783,7 +795,7 @@ private:
// -4 for extension `.dll`
if (pos == (lcaseLibName.length() - dllName.length()) || pos == (lcaseLibName.length() - dllName.length() - 4))
{
- LOG_INFO("Skip checks for: {}", wstring_to_string(lcaseLibName));
+ LOG_TRACE("Skip checks for: {}", wstring_to_string(lcaseLibName));
return o_KB_LoadLibraryExW(lpLibFileName, hFile, dwFlags);
}
}
@@ -812,8 +824,6 @@ private:
std::string libName(lpLibFileName);
std::string lcaseLibName(libName);
- LOG_DEBUG("{}", lcaseLibName);
-
for (size_t i = 0; i < lcaseLibName.size(); i++)
lcaseLibName[i] = std::tolower(lcaseLibName[i]);
@@ -821,7 +831,7 @@ private:
{
if (State::SkipDllName() == "")
{
- LOG_INFO("Skip checks for: {}", lcaseLibName);
+ LOG_TRACE("Skip checks for: {}", lcaseLibName);
return o_K32_LoadLibraryExA(lpLibFileName, hFile, dwFlags);
}
@@ -831,11 +841,15 @@ private:
// -4 for extension `.dll`
if (pos == (lcaseLibName.length() - dllName.length()) || pos == (lcaseLibName.length() - dllName.length() - 4))
{
- LOG_INFO("Skip checks for: {}", lcaseLibName);
+ LOG_TRACE("Skip checks for: {}", lcaseLibName);
return o_K32_LoadLibraryExA(lpLibFileName, hFile, dwFlags);
}
}
+#if _DEBUG
+ LOG_DEBUG("{}", lcaseLibName);
+#endif
+
auto moduleHandle = LoadLibraryCheck(lcaseLibName, lpLibFileName);
// skip loading of dll
@@ -860,8 +874,6 @@ private:
std::wstring libName(lpLibFileName);
std::wstring lcaseLibName(libName);
- LOG_DEBUG("{}", wstring_to_string(lcaseLibName));
-
for (size_t i = 0; i < lcaseLibName.size(); i++)
lcaseLibName[i] = std::tolower(lcaseLibName[i]);
@@ -869,7 +881,7 @@ private:
{
if (State::SkipDllName() == "")
{
- LOG_INFO("Skip checks for: {}", wstring_to_string(lcaseLibName));
+ LOG_TRACE("Skip checks for: {}", wstring_to_string(lcaseLibName));
return o_K32_LoadLibraryExW(lpLibFileName, hFile, dwFlags);
}
@@ -879,11 +891,15 @@ private:
// -4 for extension `.dll`
if (pos == (lcaseLibName.length() - dllName.length()) || pos == (lcaseLibName.length() - dllName.length() - 4))
{
- LOG_INFO("Skip checks for: {}", wstring_to_string(lcaseLibName));
+ LOG_TRACE("Skip checks for: {}", wstring_to_string(lcaseLibName));
return o_K32_LoadLibraryExW(lpLibFileName, hFile, dwFlags);
}
}
+#if _DEBUG
+ LOG_DEBUG("{}", wstring_to_string(lcaseLibName));
+#endif
+
auto moduleHandle = LoadLibraryCheckW(lcaseLibName, lpLibFileName);
// skip loading of dll
@@ -908,8 +924,6 @@ private:
std::string libName(lpLibFileName);
std::string lcaseLibName(libName);
- LOG_DEBUG("{}", lcaseLibName);
-
for (size_t i = 0; i < lcaseLibName.size(); i++)
lcaseLibName[i] = std::tolower(lcaseLibName[i]);
@@ -917,7 +931,7 @@ private:
{
if (State::SkipDllName() == "")
{
- LOG_INFO("Skip checks for: {}", lcaseLibName);
+ LOG_TRACE("Skip checks for: {}", lcaseLibName);
return o_K32_LoadLibraryA(lpLibFileName);
}
@@ -927,11 +941,14 @@ private:
// -4 for extension `.dll`
if (pos == (lcaseLibName.length() - dllName.length()) || pos == (lcaseLibName.length() - dllName.length() - 4))
{
- LOG_INFO("Skip checks for: {}", lcaseLibName);
+ LOG_TRACE("Skip checks for: {}", lcaseLibName);
return o_K32_LoadLibraryA(lpLibFileName);
}
}
+#if _DEBUG
+ LOG_DEBUG("{}", lcaseLibName);
+#endif
auto moduleHandle = LoadLibraryCheck(lcaseLibName, lpLibFileName);
// skip loading of dll
@@ -962,7 +979,7 @@ private:
{
if (State::SkipDllName() == "")
{
- LOG_INFO("Skip checks for: {}", wstring_to_string(lcaseLibName));
+ LOG_TRACE("Skip checks for: {}", wstring_to_string(lcaseLibName));
return o_K32_LoadLibraryW(lpLibFileName);
}
@@ -972,11 +989,15 @@ private:
// -4 for extension `.dll`
if (pos == (lcaseLibName.length() - dllName.length()) || pos == (lcaseLibName.length() - dllName.length() - 4))
{
- LOG_INFO("Skip checks for: {}", wstring_to_string(lcaseLibName));
+ LOG_TRACE("Skip checks for: {}", wstring_to_string(lcaseLibName));
return o_K32_LoadLibraryW(lpLibFileName);
}
}
+#if _DEBUG
+ LOG_DEBUG("{}", wstring_to_string(lcaseLibName));
+#endif
+
auto moduleHandle = LoadLibraryCheckW(lcaseLibName, lpLibFileName);
// skip loading of dll
diff --git a/OptiScaler/proxies/Dxgi_Proxy.h b/OptiScaler/proxies/Dxgi_Proxy.h
index 90bda23c..b0a9d23b 100644
--- a/OptiScaler/proxies/Dxgi_Proxy.h
+++ b/OptiScaler/proxies/Dxgi_Proxy.h
@@ -63,66 +63,66 @@ public:
static PFN_CreateDxgiFactory Hook_CreateDxgiFactory(PVOID method)
{
- auto addr = CreateDxgiFactory_Hooked();
+ auto addr = CreateDxgiFactory_ForHook();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)addr, method);
DetourTransactionCommit();
- _CreateDxgiFactory = addr;
+ //_CreateDxgiFactory = addr;
return addr;
}
static PFN_CreateDxgiFactory1 Hook_CreateDxgiFactory1(PVOID method)
{
- auto addr = CreateDxgiFactory1_Hooked();
+ auto addr = CreateDxgiFactory1_ForHook();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)addr, method);
DetourTransactionCommit();
- _CreateDxgiFactory1 = addr;
+ //_CreateDxgiFactory1 = addr;
return addr;
}
static PFN_CreateDxgiFactory2 Hook_CreateDxgiFactory2(PVOID method)
{
- auto addr = CreateDxgiFactory2_Hooked();
+ auto addr = CreateDxgiFactory2_ForHook();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)addr, method);
DetourTransactionCommit();
- _CreateDxgiFactory2 = addr;
+ //_CreateDxgiFactory2 = addr;
return addr;
}
static PFN_DeclareAdepterRemovalSupport Hook_DeclareAdepterRemovalSupport(PVOID method)
{
- auto addr = DeclareAdepterRemovalSupport_Hooked();
+ auto addr = DeclareAdepterRemovalSupport_ForHook();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)addr, method);
DetourTransactionCommit();
- _DeclareAdepterRemovalSupport = addr;
+ //_DeclareAdepterRemovalSupport = addr;
return addr;
}
static PFN_GetDebugInterface Hook_GetDebugInterface(PVOID method)
{
- auto addr = GetDebugInterface_Hooked();
+ auto addr = GetDebugInterface_ForHook();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)addr, method);
DetourTransactionCommit();
- _GetDebugInterface = addr;
+ //_GetDebugInterface = addr;
return addr;
}
@@ -142,4 +142,18 @@ private:
inline static PFN_CreateDxgiFactory2 _CreateDxgiFactory2 = nullptr;
inline static PFN_DeclareAdepterRemovalSupport _DeclareAdepterRemovalSupport = nullptr;
inline static PFN_GetDebugInterface _GetDebugInterface = nullptr;
+
+ inline static HMODULE HookModule()
+ {
+ if (State::Instance().isDxgiMode)
+ return dllModule;
+
+ return _dll;
+ }
+
+ static PFN_CreateDxgiFactory CreateDxgiFactory_ForHook() { return (PFN_CreateDxgiFactory)KernelBaseProxy::GetProcAddress_()(HookModule(), "CreateDXGIFactory"); }
+ static PFN_CreateDxgiFactory1 CreateDxgiFactory1_ForHook() { return (PFN_CreateDxgiFactory1)KernelBaseProxy::GetProcAddress_()(HookModule(), "CreateDXGIFactory1"); }
+ static PFN_CreateDxgiFactory2 CreateDxgiFactory2_ForHook() { return (PFN_CreateDxgiFactory2)KernelBaseProxy::GetProcAddress_()(HookModule(), "CreateDXGIFactory2"); }
+ static PFN_DeclareAdepterRemovalSupport DeclareAdepterRemovalSupport_ForHook() { return (PFN_DeclareAdepterRemovalSupport)KernelBaseProxy::GetProcAddress_()(HookModule(), "DXGIDeclareAdepterRemovalSupport"); }
+ static PFN_GetDebugInterface GetDebugInterface_ForHook() { return (PFN_GetDebugInterface)KernelBaseProxy::GetProcAddress_()(HookModule(), "DXGIGetDebugInterface1"); }
};
diff --git a/OptiScaler/proxies/Streamline_Proxy.h b/OptiScaler/proxies/Streamline_Proxy.h
index d6e77eab..ffe12eff 100644
--- a/OptiScaler/proxies/Streamline_Proxy.h
+++ b/OptiScaler/proxies/Streamline_Proxy.h
@@ -150,7 +150,7 @@ static void hookStreamline(HMODULE slInterposer) {
// Looks like when reading DLL version load methods are called
// To prevent loops disabling checks for sl.interposer.dll
- State::DisableChecks("sl.interposer");
+ State::DisableChecks(7, "sl.interposer");
if (o_slSetTag || o_slInit || o_slInit_sl1)
unhookStreamline();
@@ -192,6 +192,6 @@ static void hookStreamline(HMODULE slInterposer) {
}
}
- State::EnableChecks();
+ State::EnableChecks(7);
}
diff --git a/OptiScaler/spoofing/Dxgi_Spoofing.h b/OptiScaler/spoofing/Dxgi_Spoofing.h
index affa6810..02757e79 100644
--- a/OptiScaler/spoofing/Dxgi_Spoofing.h
+++ b/OptiScaler/spoofing/Dxgi_Spoofing.h
@@ -158,6 +158,11 @@ inline static bool SkipSpoofing()
inline static HRESULT detGetDesc3(IDXGIAdapter4 * This, DXGI_ADAPTER_DESC3 * pDesc)
{
auto result = o_GetDesc3(This, pDesc);
+
+#if _DEBUG
+ LOG_TRACE("result: {:X}", (UINT)result);
+#endif
+
if (result == S_OK)
{
if (pDesc->VendorId != 0x1414 && !State::Instance().adapterDescs.contains(pDesc->AdapterLuid.HighPart | pDesc->AdapterLuid.LowPart))
@@ -194,6 +199,11 @@ inline static HRESULT detGetDesc3(IDXGIAdapter4 * This, DXGI_ADAPTER_DESC3 * pDe
inline static HRESULT detGetDesc2(IDXGIAdapter2 * This, DXGI_ADAPTER_DESC2 * pDesc)
{
auto result = o_GetDesc2(This, pDesc);
+
+#if _DEBUG
+ LOG_TRACE("result: {:X}", (UINT)result);
+#endif
+
if (result == S_OK)
{
if (pDesc->VendorId != 0x1414 && !State::Instance().adapterDescs.contains(pDesc->AdapterLuid.HighPart | pDesc->AdapterLuid.LowPart))
@@ -230,6 +240,11 @@ inline static HRESULT detGetDesc2(IDXGIAdapter2 * This, DXGI_ADAPTER_DESC2 * pDe
inline static HRESULT detGetDesc1(IDXGIAdapter1 * This, DXGI_ADAPTER_DESC1 * pDesc)
{
auto result = o_GetDesc1(This, pDesc);
+
+#if _DEBUG
+ LOG_TRACE("result: {:X}", (UINT)result);
+#endif
+
if (result == S_OK)
{
if (pDesc->VendorId != 0x1414 && !State::Instance().adapterDescs.contains(pDesc->AdapterLuid.HighPart | pDesc->AdapterLuid.LowPart))
@@ -266,6 +281,11 @@ inline static HRESULT detGetDesc1(IDXGIAdapter1 * This, DXGI_ADAPTER_DESC1 * pDe
inline static HRESULT detGetDesc(IDXGIAdapter * This, DXGI_ADAPTER_DESC * pDesc)
{
auto result = o_GetDesc(This, pDesc);
+
+#if _DEBUG
+ LOG_TRACE("result: {:X}", (UINT)result);
+#endif
+
if (result == S_OK)
{
if (pDesc->VendorId != 0x1414 && !State::Instance().adapterDescs.contains(pDesc->AdapterLuid.HighPart | pDesc->AdapterLuid.LowPart))
@@ -314,6 +334,10 @@ inline static HRESULT detEnumAdapterByGpuPreference(IDXGIFactory6 * This, UINT A
if (result == S_OK)
AttachToAdapter(*ppvAdapter);
+#if _DEBUG
+ LOG_TRACE("result: {:X}, Adapter: {}, pAdapter: {:X}", (UINT)result, Adapter, (size_t)*ppvAdapter);
+#endif
+
return result;
}
@@ -328,6 +352,10 @@ inline static HRESULT detEnumAdapterByLuid(IDXGIFactory4 * This, LUID AdapterLui
if (result == S_OK)
AttachToAdapter(*ppvAdapter);
+#if _DEBUG
+ LOG_TRACE("result: {:X}, pAdapter: {:X}", (UINT)result, (size_t)*ppvAdapter);
+#endif
+
return result;
}
@@ -341,6 +369,8 @@ inline static HRESULT detEnumAdapters1(IDXGIFactory1 * This, UINT Adapter, IDXGI
if (!skipHighPerfCheck && Config::Instance()->PreferDedicatedGpu.value_or_default())
{
+ LOG_WARN("High perf GPU selection");
+
if (Config::Instance()->PreferFirstDedicatedGpu.value_or_default() && Adapter > 0)
{
LOG_DEBUG("{}, returning not found", Adapter);
@@ -399,6 +429,10 @@ inline static HRESULT detEnumAdapters1(IDXGIFactory1 * This, UINT Adapter, IDXGI
if (result == S_OK)
AttachToAdapter(*ppAdapter);
+#if _DEBUG
+ LOG_TRACE("result: {:X}, Adapter: {}, pAdapter: {:X}", (UINT)result, Adapter, (size_t)*ppAdapter);
+#endif
+
return result;
}
@@ -468,6 +502,10 @@ inline static HRESULT detEnumAdapters(IDXGIFactory * This, UINT Adapter, IDXGIAd
if (result == S_OK)
AttachToAdapter(*ppAdapter);
+#if _DEBUG
+ LOG_TRACE("result: {:X}, Adapter: {}, pAdapter: {:X}", (UINT)result, Adapter, (size_t)*ppAdapter);
+#endif
+
return result;
}
@@ -511,6 +549,9 @@ inline static HRESULT hkCreateDXGIFactory2(UINT Flags, REFIID riid, IDXGIFactory
inline static void AttachToAdapter(IUnknown * unkAdapter)
{
+ if (o_GetDesc != nullptr && o_GetDesc1 != nullptr && o_GetDesc2 != nullptr && o_GetDesc3 != nullptr)
+ return;
+
const GUID guid = { 0x907bf281,0xea3c,0x43b4,{0xa8,0xe4,0x9f,0x23,0x11,0x07,0xb4,0xff} };
PVOID* pVTable = *(PVOID**)unkAdapter;
@@ -608,6 +649,9 @@ inline static void AttachToAdapter(IUnknown * unkAdapter)
inline static void AttachToFactory(IUnknown * unkFactory)
{
+ if (o_EnumAdapters != nullptr && o_EnumAdapters1 != nullptr && o_EnumAdapterByLuid != nullptr && o_EnumAdapterByGpuPreference != nullptr)
+ return;
+
PVOID* pVTable = *(PVOID**)unkFactory;
IDXGIFactory* factory;
@@ -667,7 +711,7 @@ inline static void AttachToFactory(IUnknown * unkFactory)
DetourTransactionCommit();
- factory6->Release();
+ factory6->Release();
}
}