diff --git a/Code/immersive_launcher/Launcher.cpp b/Code/immersive_launcher/Launcher.cpp index 48d69ec68..27dd557e8 100644 --- a/Code/immersive_launcher/Launcher.cpp +++ b/Code/immersive_launcher/Launcher.cpp @@ -10,6 +10,7 @@ #include "Utils/FileVersion.inl" #include "oobe/PathSelection.h" +#include "SystemDllPreload.h" #include "oobe/PathArgument.h" #include "oobe/SupportChecks.h" #include "steam/SteamLoader.h" @@ -70,6 +71,7 @@ void SetMaxstdio() int StartUp(int argc, char** argv) { + PreloadSystemDlls(); bool askSelect = (GetAsyncKeyState(VK_SPACE) & 0x8000); if (!HandleArguments(argc, argv, askSelect)) return -1; diff --git a/Code/immersive_launcher/SystemDllPreload.h b/Code/immersive_launcher/SystemDllPreload.h new file mode 100644 index 000000000..c99465baa --- /dev/null +++ b/Code/immersive_launcher/SystemDllPreload.h @@ -0,0 +1,28 @@ +#pragma once + +// Pre-binds System32 copies of DLLs that could otherwise be shadowed by the +// extra DLL directories STR registers (the Steam folder, see +// steam/SteamLoader.cpp). Windows reuses an already-loaded module for +// same-name imports, so a later import of dwmapi.dll gets this one. +// Call at the very start of launcher::StartUp(). +// +// Deliberately NOT listed: d3d11/dxgi/d3d9/dinput8/version, which ENB, +// ReShade etc. intentionally proxy from the game folder. + +#include + +namespace launcher +{ +inline void PreloadSystemDlls() +{ + static const wchar_t* const kSystemOnly[] = { + L"dwmapi.dll", + }; + + for (const wchar_t* name : kSystemOnly) + { + // Searches System32 only. Never freed, so it stays resident. + LoadLibraryExW(name, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); + } +} +} // namespace launcher