11#include " Hooking/Hooks.h"
2+ #include " Util.h"
23
34//
45// sl.interposer.dll loads sl.common.dll
@@ -20,27 +21,8 @@ bool PatchImportsForModule(const wchar_t *Path, HMODULE ModuleHandle);
2021void *LoadImplementationDll ()
2122{
2223 // Use the same directory as the current DLL
23- wchar_t path[2048 ] = {};
24- HMODULE thisModuleHandle = nullptr ;
25-
26- if (GetModuleHandleExW (
27- GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
28- reinterpret_cast <LPCWSTR>(&LoadImplementationDll),
29- &thisModuleHandle))
30- {
31- if (GetModuleFileNameW (thisModuleHandle, path, ARRAYSIZE (path)))
32- {
33- // Chop off the file name
34- for (auto i = static_cast <ptrdiff_t >(wcslen (path)) - 1 ; i > 0 ; i--)
35- {
36- if (path[i] == L' \\ ' || path[i] == L' /' )
37- {
38- path[i + 1 ] = 0 ;
39- break ;
40- }
41- }
42- }
43- }
24+ wchar_t path[2048 ];
25+ Util::GetModulePath (path, true , nullptr );
4426
4527 // Do not cache a handle to the implementation DLL. It might be unloaded and reloaded.
4628 wcscat_s (path, RelplacementImplementationDll);
@@ -132,22 +114,22 @@ bool PatchImportsForModule(const wchar_t *Path, HMODULE ModuleHandle)
132114 if (!Path || !ModuleHandle)
133115 return false ;
134116
135- std::wstring_view libFileName (Path);
136-
137117 const bool isMatch = std::any_of (
138118 TargetLibrariesToHook.begin (),
139119 TargetLibrariesToHook.end (),
140- [& ](const wchar_t *Target)
120+ [path = std::wstring_view (Path) ](const wchar_t *Target)
141121 {
142- return libFileName .ends_with (Target);
122+ return path .ends_with (Target);
143123 });
144124
145125 if (!isMatch || !ModuleRequiresPatching (ModuleHandle))
146126 return false ;
147127
128+ #if 0
148129 OutputDebugStringW(L"Patching imports for a new module: ");
149130 OutputDebugStringW(Path);
150131 OutputDebugStringW(L"...\n");
132+ #endif
151133
152134 Hooks::RedirectImport (ModuleHandle, " KERNEL32.dll" , " LoadLibraryW" , &HookedLoadLibraryW, nullptr );
153135 Hooks::RedirectImport (ModuleHandle, " KERNEL32.dll" , " LoadLibraryExW" , &HookedLoadLibraryExW, nullptr );
@@ -169,17 +151,44 @@ BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
169151 TargetLibrariesToHook.push_back (TargetEGSServicesDll);
170152 LoadLibraryW (TargetEGSServicesDll);
171153
172- if (!LoadLibraryW (L" sl.interposer.dll" ))
154+ //
155+ // Aggressive hooking tries to force SL's interposer to load early. It's not always present
156+ // in the local directory. A bit of guesswork is required.
157+ //
158+ // "Dying Light 2\ ph\work\bin\x64\DyingLightGame_x64_rwdi.exe"
159+ // "Returnal\ Returnal\ Binaries\Win64\Returnal-Win64-Shipping.exe"
160+ // "Hogwarts Legacy\ Phoenix\ Binaries\Win64\HogwartsLegacy.exe"
161+ // "SW Jedi Survivor\ SwGame\ Binaries\Win64\JediSurvivor.exe"
162+ // "Atomic Heart\ AtomicHeart\ Binaries\Win64\AtomicHeart-Win64-Shipping.exe
163+ // "MMS\ MidnightSuns\ Binaries\Win64\MidnightSuns-Win64-Shipping.exe"
164+ //
165+ // "Dying Light 2\ ph\work\bin\x64\sl.interposer.dll"
166+ // "Returnal\ Engine\Plugins\Streamline\Binaries\ThirdParty\Win64\sl.interposer.dll"
167+ // "Hogwarts Legacy\ Engine\Plugins\Runtime\Nvidia\Streamline\Binaries\ThirdParty\Win64\sl.interposer.dll"
168+ // "SW Jedi Survivor\ Engine\Plugins\Runtime\Nvidia\Streamline\Binaries\ThirdParty\Win64\sl.interposer.dll"
169+ // "Atomic Heart\ Engine\Plugins\Runtime\Nvidia\Streamline\Binaries\ThirdParty\Win64\sl.interposer.dll"
170+ // "MMS\ Engine\Plugins\Runtime\Nvidia\Streamline\Binaries\ThirdParty\Win64\sl.interposer.dll"
171+ //
172+ constinit static const wchar_t *bruteInterposerPaths[] = {
173+ L" sl.interposer.dll" ,
174+ L" ..\\ ..\\ ..\\ Engine\\ Plugins\\ Streamline\\ Binaries\\ ThirdParty\\ Win64\\ sl.interposer.dll" ,
175+ L" ..\\ ..\\ ..\\ Engine\\ Plugins\\ Runtime\\ Nvidia\\ Streamline\\ Binaries\\ ThirdParty\\ Win64\\ sl.interposer.dll" ,
176+ };
177+
178+ if (!LoadLibraryW (bruteInterposerPaths[0 ]))
173179 {
174- // "Returnal\Returnal\Binaries\Win64\Returnal-Win64-Shipping.exe"
175- // "Returnal\Engine\Plugins\Streamline\Binaries\ThirdParty\Win64\sl.interposer.dll"
176- //
177- // "Hogwarts Legacy\Phoenix\Binaries\Win64\HogwartsLegacy.exe"
178- // "Hogwarts Legacy\Engine\Plugins\Runtime\Nvidia\Streamline\Binaries\ThirdParty\Win64\sl.interposer.dll"
179- //
180- // Insanity. A dedicated configuration file is going to be required at this rate. HL is okay but
181- // Returnal needs some help.
182- LoadLibraryW (L" ..\\ ..\\ ..\\ Engine\\ Plugins\\ Streamline\\ Binaries\\ ThirdParty\\ Win64\\ sl.interposer.dll" );
180+ wchar_t path[2048 ];
181+
182+ for (auto interposer : bruteInterposerPaths)
183+ {
184+ if (!Util::GetModulePath (path, true , GetModuleHandleW (nullptr )))
185+ break ;
186+
187+ wcscat_s (path, interposer);
188+
189+ if (LoadLibraryW (path))
190+ break ;
191+ }
183192 }
184193 }
185194
0 commit comments