Skip to content

Commit 951b260

Browse files
authored
Allow changing sl plugin requirements (#510)
* Allow for sl plugin requirements modifications also make sure DLSSG can be enabled in NMS on AMD * Rename sl hooks * Rename sl file * Refactor streamline hooks * Formatting
1 parent 36ada62 commit 951b260

File tree

9 files changed

+26069
-231
lines changed

9 files changed

+26069
-231
lines changed

OptiScaler/DllNames.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ DEFINE_NAME_VECTORS(vk, "vulkan-1");
115115
DEFINE_NAME_VECTORS(nvngx, "nvngx");
116116
DEFINE_NAME_VECTORS(nvngxDlss, "nvngx_dlss");
117117
DEFINE_NAME_VECTORS(nvapi, "nvapi64");
118-
DEFINE_NAME_VECTORS(streamline, "sl.interposer");
118+
DEFINE_NAME_VECTORS(slInterposer, "sl.interposer");
119+
DEFINE_NAME_VECTORS(slDlss, "sl.dlss");
120+
DEFINE_NAME_VECTORS(slDlssg, "sl.dlss_g");
119121

120122
DEFINE_NAME_VECTORS(xess, "libxess");
121123
DEFINE_NAME_VECTORS(xessDx11, "libxess_dx11");

OptiScaler/OptiScaler.vcxproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@
111111
<LibraryPath>$(XESS_SDK)\lib;$(LibraryPath)</LibraryPath>
112112
</PropertyGroup>
113113
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
114-
<IncludePath>$(ProjectDir);$(ProjectDir)include\;$(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;$(SolutionDir)external\freetype;$(SolutionDir)external\streamline;$(SolutionDir)external\streamline1;$(SolutionDir)external\nvapi;$(IncludePath)</IncludePath>
114+
<IncludePath>$(ProjectDir);$(ProjectDir)include\;$(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;$(SolutionDir)external\freetype;$(SolutionDir)external\streamline;$(SolutionDir)external\streamline1;$(SolutionDir)external\nvapi;$(SolutionDir)external\nlohmann;$(IncludePath)</IncludePath>
115115
<LibraryPath>$(ProjectDir)library\fsr2;$(ProjectDir)library\fsr2_212;$(ProjectDir)library\fsr31;$(ProjectDir)library\vulkan;$(ProjectDir)library\d3dx;$(ProjectDir)library\detours;$(SolutionDir)external\xess\lib;$(SolutionDir)external\freetype;$(LibraryPath)</LibraryPath>
116116
<IntDir>.\x64\Debug</IntDir>
117117
<TargetExt>.dll</TargetExt>
118118
</PropertyGroup>
119119
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
120-
<IncludePath>$(ProjectDir);$(ProjectDir)include\;$(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;$(SolutionDir)external\freetype;$(SolutionDir)external\streamline;$(SolutionDir)external\streamline1;$(SolutionDir)external\nvapi;$(IncludePath)</IncludePath>
120+
<IncludePath>$(ProjectDir);$(ProjectDir)include\;$(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;$(SolutionDir)external\freetype;$(SolutionDir)external\streamline;$(SolutionDir)external\streamline1;$(SolutionDir)external\nvapi;$(SolutionDir)external\nlohmann;$(IncludePath)</IncludePath>
121121
<LibraryPath>$(ProjectDir)library\fsr2;$(ProjectDir)library\fsr2_212;$(ProjectDir)library\fsr31;$(ProjectDir)library\vulkan;$(ProjectDir)library\d3dx;$(ProjectDir)library\detours;$(SolutionDir)external\xess\lib;$(SolutionDir)external\freetype;$(LibraryPath)</LibraryPath>
122122
</PropertyGroup>
123123
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDebug|x64'">
124-
<IncludePath>$(ProjectDir);$(ProjectDir)include\;$(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;$(SolutionDir)external\freetype;$(SolutionDir)external\streamline;$(SolutionDir)external\streamline1;$(SolutionDir)external\nvapi;$(IncludePath)</IncludePath>
124+
<IncludePath>$(ProjectDir);$(ProjectDir)include\;$(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;$(SolutionDir)external\freetype;$(SolutionDir)external\streamline;$(SolutionDir)external\streamline1;$(SolutionDir)external\nvapi;$(SolutionDir)external\nlohmann;$(IncludePath)</IncludePath>
125125
<LibraryPath>$(ProjectDir)library\fsr2;$(ProjectDir)library\fsr2_212;$(ProjectDir)library\fsr31;$(ProjectDir)library\vulkan;$(ProjectDir)library\d3dx;$(ProjectDir)library\detours;$(SolutionDir)external\xess\lib;$(SolutionDir)external\freetype;$(LibraryPath)</LibraryPath>
126126
</PropertyGroup>
127127
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@@ -457,6 +457,7 @@ copy NUL "$(SolutionDir)x64\Release\a\!! EXTRACT ALL FILES TO GAME FOLDER !!" /Y
457457
<ClCompile Include="framegen\ffx\FSRFG_Dx12.cpp" />
458458
<ClCompile Include="framegen\IFGFeature.cpp" />
459459
<ClCompile Include="framegen\IFGFeature_Dx12.cpp" />
460+
<ClCompile Include="hooks\Streamline_Hooks.cpp" />
460461
<ClCompile Include="hudfix\Hudfix_Dx12.cpp" />
461462
<ClCompile Include="include\imgui\imgui_impl_dx11.cpp" />
462463
<ClCompile Include="include\imgui\imgui_impl_dx12.cpp" />

OptiScaler/OptiScaler.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@
791791
<ClCompile Include="include\imgui\imgui_impl_win32.cpp">
792792
<Filter>Source Files</Filter>
793793
</ClCompile>
794+
<ClCompile Include="hooks\Streamline_Hooks.cpp">
795+
<Filter>Source Files</Filter>
796+
</ClCompile>
794797
</ItemGroup>
795798
<ItemGroup>
796799
<ResourceCompile Include="OptiScaler.rc" />

OptiScaler/dllmain.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,23 @@ static void CheckWorkingMode()
701701
if (slModule != nullptr)
702702
{
703703
LOG_DEBUG("sl.interposer.dll already in memory");
704-
hookStreamline(slModule);
704+
StreamlineHooks::hookInterposer(slModule);
705+
}
706+
707+
HMODULE slDlss = nullptr;
708+
slDlss = KernelBaseProxy::GetModuleHandleW_()(L"sl.dlss.dll");
709+
if (slDlss != nullptr)
710+
{
711+
LOG_DEBUG("sl.dlss.dll already in memory");
712+
StreamlineHooks::hookDlss(slDlss);
713+
}
714+
715+
HMODULE slDlssg = nullptr;
716+
slDlssg = KernelBaseProxy::GetModuleHandleW_()(L"sl.dlss_g.dll");
717+
if (slDlssg != nullptr)
718+
{
719+
LOG_DEBUG("sl.dlss_g.dll already in memory");
720+
StreamlineHooks::hookDlssg(slDlssg);
705721
}
706722

707723
// XeSS

OptiScaler/hooks/Kernel_Hooks.h

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class KernelHooks
5252
inline static Kernel32Proxy::PFN_LoadLibraryExA o_K32_LoadLibraryExA = nullptr;
5353
inline static Kernel32Proxy::PFN_LoadLibraryExW o_K32_LoadLibraryExW = nullptr;
5454
inline static Kernel32Proxy::PFN_GetProcAddress o_K32_GetProcAddress = nullptr;
55+
inline static Kernel32Proxy::PFN_GetModuleHandleA o_K32_GetModuleHandleA = nullptr;
5556
inline static Kernel32Proxy::PFN_GetFileAttributesW o_K32_GetFileAttributesW = nullptr;
5657
inline static Kernel32Proxy::PFN_CreateFileW o_K32_CreateFileW = nullptr;
5758

@@ -141,13 +142,13 @@ class KernelHooks
141142

142143
// sl.interposer.dll
143144
if (Config::Instance()->FGType.value_or_default() == FGType::Nukems &&
144-
CheckDllName(&lcaseLibName, &streamlineNames))
145+
CheckDllName(&lcaseLibName, &slInterposerNames))
145146
{
146147
auto streamlineModule = KernelBaseProxy::LoadLibraryExA_()(lpLibFullPath, NULL, 0);
147148

148149
if (streamlineModule != nullptr)
149150
{
150-
hookStreamline(streamlineModule);
151+
StreamlineHooks::hookInterposer(streamlineModule);
151152
}
152153
else
153154
{
@@ -157,6 +158,40 @@ class KernelHooks
157158
return streamlineModule;
158159
}
159160

161+
// sl.dlss.dll
162+
if (CheckDllName(&lcaseLibName, &slDlssNames))
163+
{
164+
auto dlssModule = KernelBaseProxy::LoadLibraryExA_()(lpLibFullPath, NULL, 0);
165+
166+
if (dlssModule != nullptr)
167+
{
168+
StreamlineHooks::hookDlss(dlssModule);
169+
}
170+
else
171+
{
172+
LOG_ERROR("Trying to load dll: {}", lcaseLibName);
173+
}
174+
175+
return dlssModule;
176+
}
177+
178+
// sl.dlss_g.dll
179+
if (CheckDllName(&lcaseLibName, &slDlssgNames))
180+
{
181+
auto dlssgModule = KernelBaseProxy::LoadLibraryExA_()(lpLibFullPath, NULL, 0);
182+
183+
if (dlssgModule != nullptr)
184+
{
185+
StreamlineHooks::hookDlssg(dlssgModule);
186+
}
187+
else
188+
{
189+
LOG_ERROR("Trying to load dll: {}", lcaseLibName);
190+
}
191+
192+
return dlssgModule;
193+
}
194+
160195
// nvngx_dlss
161196
if (Config::Instance()->DLSSEnabled.value_or_default() && Config::Instance()->NVNGX_DLSS_Library.has_value() &&
162197
CheckDllName(&lcaseLibName, &nvngxDlssNames))
@@ -529,13 +564,13 @@ class KernelHooks
529564

530565
// sl.interposer.dll
531566
if (Config::Instance()->FGType.value_or_default() == FGType::Nukems &&
532-
CheckDllNameW(&lcaseLibName, &streamlineNamesW))
567+
CheckDllNameW(&lcaseLibName, &slInterposerNamesW))
533568
{
534569
auto streamlineModule = KernelBaseProxy::LoadLibraryExW_()(lpLibFullPath, NULL, 0);
535570

536571
if (streamlineModule != nullptr)
537572
{
538-
hookStreamline(streamlineModule);
573+
StreamlineHooks::hookInterposer(streamlineModule);
539574
}
540575
else
541576
{
@@ -545,6 +580,40 @@ class KernelHooks
545580
return streamlineModule;
546581
}
547582

583+
// sl.dlss.dll
584+
if (CheckDllNameW(&lcaseLibName, &slDlssNamesW))
585+
{
586+
auto dlssModule = KernelBaseProxy::LoadLibraryExW_()(lpLibFullPath, NULL, 0);
587+
588+
if (dlssModule != nullptr)
589+
{
590+
StreamlineHooks::hookDlss(dlssModule);
591+
}
592+
else
593+
{
594+
LOG_ERROR("Trying to load dll: {}", lcaseLibNameA);
595+
}
596+
597+
return dlssModule;
598+
}
599+
600+
// sl.dlss_g.dll
601+
if (CheckDllNameW(&lcaseLibName, &slDlssgNamesW))
602+
{
603+
auto dlssgModule = KernelBaseProxy::LoadLibraryExW_()(lpLibFullPath, NULL, 0);
604+
605+
if (dlssgModule != nullptr)
606+
{
607+
StreamlineHooks::hookDlssg(dlssgModule);
608+
}
609+
else
610+
{
611+
LOG_ERROR("Trying to load dll: {}", lcaseLibNameA);
612+
}
613+
614+
return dlssgModule;
615+
}
616+
548617
if (Config::Instance()->DisableOverlays.value_or_default() && CheckDllNameW(&lcaseLibName, &blockOverlayNamesW))
549618
{
550619
LOG_DEBUG("Blocking overlay dll: {}", wstring_to_string(lcaseLibName));
@@ -1546,6 +1615,18 @@ class KernelHooks
15461615
return o_K32_GetProcAddress(hModule, lpProcName);
15471616
}
15481617

1618+
static HMODULE hk_K32_GetModuleHandleA(LPCSTR lpModuleName)
1619+
{
1620+
if (lpModuleName != NULL && strcmp(lpModuleName, "nvngx_dlssg.dll") == 0)
1621+
{
1622+
LOG_TRACE("Trying to get module handle of {}, caller: {}", lpModuleName,
1623+
Util::WhoIsTheCaller(_ReturnAddress()));
1624+
return dllModule;
1625+
}
1626+
1627+
return o_K32_GetModuleHandleA(lpModuleName);
1628+
}
1629+
15491630
static FARPROC hk_KB_GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
15501631
{
15511632
if ((size_t) lpProcName < 0x000000000000F000)
@@ -1660,6 +1741,7 @@ class KernelHooks
16601741
o_K32_LoadLibraryExA = Kernel32Proxy::Hook_LoadLibraryExA(hk_K32_LoadLibraryExA);
16611742
o_K32_LoadLibraryExW = Kernel32Proxy::Hook_LoadLibraryExW(hk_K32_LoadLibraryExW);
16621743
o_K32_GetProcAddress = Kernel32Proxy::Hook_GetProcAddress(hk_K32_GetProcAddress);
1744+
o_K32_GetModuleHandleA = Kernel32Proxy::Hook_GetModuleHandleA(hk_K32_GetModuleHandleA);
16631745
o_K32_GetFileAttributesW = Kernel32Proxy::Hook_GetFileAttributesW(hk_K32_GetFileAttributesW);
16641746
o_K32_CreateFileW = Kernel32Proxy::Hook_CreateFileW(hk_K32_CreateFileW);
16651747
}

0 commit comments

Comments
 (0)