Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed multi instance not working #1159

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Nitrox.Bootloader/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ public static class Main
{
private static readonly Lazy<string> nitroxLauncherDir = new Lazy<string>(() =>
{
// Get path from command args.
string[] args = Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length - 1; i++)
{
if (args[i].Equals("-nitrox", StringComparison.OrdinalIgnoreCase) && Directory.Exists(args[i + 1]))
{
return Path.GetFullPath(args[i + 1]);
}
}

// Get path from AppData file.
string nitroxAppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Nitrox");
if (!Directory.Exists(nitroxAppData))
{
Expand Down Expand Up @@ -44,7 +55,7 @@ public static class Main
}
return null;
});

public static void Execute()
{
string error = ValidateNitroxSetup();
Expand All @@ -61,15 +72,14 @@ public static void Execute()

BootstrapNitrox();
}

private static void BootstrapNitrox()
{
Assembly core = Assembly.Load(new AssemblyName("NitroxPatcher"));
Type mainType = core.GetType("NitroxPatcher.Main");
mainType.InvokeMember("Execute", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, null);
}


private static string ValidateNitroxSetup()
{
if (nitroxLauncherDir.Value == null)
Expand Down Expand Up @@ -98,12 +108,12 @@ private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEve
{
dllPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), dllFileName);
}

if (!File.Exists(dllPath))
{
Console.WriteLine($"Nitrox dll missing: {dllPath}");
}
return Assembly.LoadFile(dllPath);
}
}
}
}
9 changes: 8 additions & 1 deletion NitroxLauncher/LauncherLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,14 @@ internal async Task StartMultiplayerAsync()

// TODO: The launcher should override FileRead win32 API for the Subnautica process to give it the modified Assembly-CSharp from memory
string bootloaderName = "Nitrox.Bootloader.dll";
File.Copy(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), bootloaderName), Path.Combine(subnauticaPath, "Subnautica_Data", "Managed", bootloaderName), true);
try
{
File.Copy(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), bootloaderName), Path.Combine(subnauticaPath, "Subnautica_Data", "Managed", bootloaderName), true);
}
catch (IOException)
{
// ignored
}

nitroxEntryPatch.Remove(); // Remove any previous instances first.
nitroxEntryPatch.Apply();
Expand Down