aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2022-02-17 08:04:02 -0500
committerGitHub <noreply@github.com>2022-02-17 13:04:02 +0000
commitf3c8dba536329e2907e12b80f6774467d93779cf (patch)
tree3951d1fc468f4c952f87f836bdf97c301eb18825
parent1a7b41cc722c05eb97006d29e124c17559c45324 (diff)
downloadNorthstarLauncher-f3c8dba536329e2907e12b80f6774467d93779cf.tar.gz
NorthstarLauncher-f3c8dba536329e2907e12b80f6774467d93779cf.zip
Implement stub loading (#81)
When starting the dedicated server from NorthstarLauncher, always default to loading the d3d11 and gfsdk stubs from `bin/x64_dedi`. If the stubs fail to load or `-nostubs` is specified, the launcher reverts to the old behaviour of using the GPU, or WARP if `-softwared3d11` is specified. updates #79
-rw-r--r--LauncherInjector/main.cpp80
-rw-r--r--NorthstarDedicatedTest/dedicatedmaterialsystem.cpp1
2 files changed, 71 insertions, 10 deletions
diff --git a/LauncherInjector/main.cpp b/LauncherInjector/main.cpp
index a52b71fe..e62f83db 100644
--- a/LauncherInjector/main.cpp
+++ b/LauncherInjector/main.cpp
@@ -227,29 +227,89 @@ bool LoadNorthstar()
return true;
}
+HMODULE LoadDediStub(const char* name)
+{
+ // this works because materialsystem_dx11.dll uses relative imports, and even a DLL loaded with an absolute path will take precedence
+ printf("[*] Loading %s\n", name);
+ swprintf_s(buffer, L"%s\\bin\\x64_dedi\\%hs", exePath, name);
+ HMODULE h = LoadLibraryExW(buffer, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
+ if (!h)
+ {
+ wprintf(L"[*] Failed to load stub %hs from \"%ls\": %hs\n", name, buffer, std::system_category().message(GetLastError()).c_str());
+ }
+ return h;
+}
+
int main(int argc, char* argv[])
{
+ if (!GetExePathWide(exePath, sizeof(exePath)))
+ {
+ MessageBoxA(
+ GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.", "Northstar Launcher Error",
+ 0);
+ return 1;
+ }
- // checked to avoid starting origin, Northstar.dll will check for -dedicated as well on its own
bool noOriginStartup = false;
+ bool dedicated = false;
+ bool nostubs = false;
+
for (int i = 0; i < argc; i++)
- if (!strcmp(argv[i], "-noOriginStartup") || !strcmp(argv[i], "-dedicated"))
+ if (!strcmp(argv[i], "-noOriginStartup"))
noOriginStartup = true;
+ else if (!strcmp(argv[i], "-dedicated")) // also checked by Northstar.dll
+ dedicated = true;
+ else if (!strcmp(argv[i], "-nostubs"))
+ nostubs = true;
- if (!noOriginStartup)
- {
+ if (!noOriginStartup && !dedicated)
EnsureOriginStarted();
- }
+ if (dedicated && !nostubs)
{
- if (!GetExePathWide(exePath, sizeof(exePath)))
+ // clang-format keeps messing with the easy-to-read if statements, so
+ // clang-format off
+ printf("[*] Loading stubs\n");
+ HMODULE gssao, gtxaa, d3d11;
+ if (!(gssao = GetModuleHandleA("GFSDK_SSAO.win64.dll")) &&
+ !(gtxaa = GetModuleHandleA("GFSDK_TXAA.win64.dll")) &&
+ !(d3d11 = GetModuleHandleA("d3d11.dll")))
{
- MessageBoxA(
- GetForegroundWindow(), "Failed getting game directory.\nThe game cannot continue and has to exit.",
- "Northstar Launcher Error", 0);
- return 1;
+ if (!(gssao = LoadDediStub("GFSDK_SSAO.win64.dll")) ||
+ !(gtxaa = LoadDediStub("GFSDK_TXAA.win64.dll")) ||
+ !(d3d11 = LoadDediStub("d3d11.dll")))
+ {
+ if ((!gssao || FreeLibrary(gssao)) &&
+ (!gtxaa || FreeLibrary(gtxaa)) &&
+ (!d3d11 || FreeLibrary(d3d11)))
+ {
+ printf(
+ "[*] WARNING: Failed to load d3d11/gfsdk stubs from bin/x64_dedi. "
+ "The stubs have been unloaded and the original libraries will be used instead.\n");
+ }
+ else
+ {
+ // this is highly unlikely
+ MessageBoxA(
+ GetForegroundWindow(),
+ "Failed to load one or more stubs, but could not unload them either.\n"
+ "The game cannot continue and has to exit.",
+ "Northstar Launcher Error", 0);
+ return 1;
+ }
+ }
}
+ else
+ {
+ // this should never happen
+ printf(
+ "[*] WARNING: Failed to load stubs because conflicting modules are already loaded, so those will be used instead "
+ "(did Northstar initialize too late?).\n");
+ }
+ // clang-format on
+ }
+ {
PrependPath();
printf("[*] Loading tier0.dll\n");
diff --git a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp
index 5db3d629..0689bc74 100644
--- a/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp
+++ b/NorthstarDedicatedTest/dedicatedmaterialsystem.cpp
@@ -20,6 +20,7 @@ HRESULT __stdcall D3D11CreateDeviceHook(
// atm, i think the play might be to run d3d in software, and then just stub out any calls that allocate memory/use alot of resources
// (e.g. createtexture and that sorta thing)
+ // note: this has been succeeded by the d3d11 and gfsdk stubs, and is only being kept around for posterity and as a fallback option
if (CommandLine()->CheckParm("-softwared3d11"))
DriverType = 5; // D3D_DRIVER_TYPE_WARP