Example #1
0
        private void MultiplayerButton_Click(object sender, EventArgs e)
        {
            string subnauticaPath = "";

            if (ErrorConfiguringLaunch(ref subnauticaPath))
            {
                return;
            }

            if (PirateDetection.IsPirate(subnauticaPath))
            {
                PirateDetected();
                return;
            }

            SyncAssembliesBetweenSubnauticaManagedAndLib(subnauticaPath);

            NitroxEntryPatch nitroxEntryPatch = new NitroxEntryPatch(subnauticaPath);

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

            StartSubnautica(subnauticaPath);

            //TODO: maybe an async callback to remove when the app closes.
        }
Example #2
0
        internal void StartMultiplayer()
        {
            gameStarting = true;
            string subnauticaPath = "";

            if (ErrorConfiguringLaunch(ref subnauticaPath))
            {
                return;
            }

            if (PirateDetection.IsPirate(subnauticaPath))
            {
                if (PirateDetectedEvent != null)
                {
                    PirateDetectedEvent(this, new EventArgs());
                }
                return;
            }

            SyncAssembliesBetweenSubnauticaManagedAndLib(subnauticaPath);

            NitroxEntryPatch nitroxEntryPatch = new NitroxEntryPatch(subnauticaPath);

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

            StartSubnautica(subnauticaPath);
            Thread thread = new Thread(new ThreadStart(AsyncGetProcess));

            thread.Start();
        }
Example #3
0
        private void SinglePlayerButton_Click(object sender, EventArgs e)
        {
            string subnauticaPath = "";

            if (ErrorConfiguringLaunch(ref subnauticaPath))
            {
                return;
            }

            if (PirateDetection.IsPirate(subnauticaPath))
            {
                PirateDetected();
                return;
            }

            SyncAssembliesBetweenSubnauticaManagedAndLib(subnauticaPath);

            NitroxEntryPatch nitroxEntryPatch = new NitroxEntryPatch(subnauticaPath);

            nitroxEntryPatch.Remove();

            string subnauticaExe = Path.Combine(subnauticaPath, "Subnautica.exe");

            Process.Start(subnauticaExe);
        }
Example #4
0
        internal async Task StartMultiplayerAsync()
        {
            if (PirateDetection.TriggerOnDirectory(subnauticaPath))
            {
                return;
            }
            if (Process.GetProcessesByName("Subnautica").Length > 0)
            {
                throw new Exception("An instance of Subnautica is already running");
            }

            try
            {
                gameStarting = true;

                SyncAssetBundles();
                SyncMonoAssemblies();
                SyncAssembliesBetweenSubnauticaManagedAndLib();

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

                gameProcess = StartSubnautica() ?? await WaitForProcessAsync();
            }
            catch (Exception)
            {
                gameStarting = false;
                throw;
            }
        }
Example #5
0
        internal void StartSingleplayer()
        {
            string subnauticaPath = "";

            if (ErrorConfiguringLaunch(ref subnauticaPath))
            {
                return;
            }

            if (PirateDetection.IsPirate(subnauticaPath))
            {
                if (PirateDetectedEvent != null)
                {
                    PirateDetectedEvent(this, new EventArgs());
                }
                return;
            }
            SyncAssembliesBetweenSubnauticaManagedAndLib(subnauticaPath);

            NitroxEntryPatch nitroxEntryPatch = new NitroxEntryPatch(subnauticaPath);

            nitroxEntryPatch.Remove();

            StartSubnautica(subnauticaPath);
        }
Example #6
0
        private void SyncAssembliesBetweenSubnauticaManagedAndLib()
        {
            if (PirateDetection.TriggerOnDirectory(subnauticaPath))
            {
                return;
            }

            string subnauticaManagedPath = Path.Combine(subnauticaPath, "Subnautica_Data", "Managed");
            string libDirectory          = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "lib");

            List <string> ignoreNitroxBinaries = new List <string>
            {
                "NitroxModel.dll",
                "NitroxServer.dll",
                "NitroxServer-Subnautica.dll",
                "NitroxModel-Subnautica.dll",
                "NitroxPatcher.dll",
                "NitroxClient.dll",
                "0Harmony.dll",
                "Autofac.dll",
                "log4net.dll",
                "protobuf-net.dll",
                "LitJson.dll",
                "dnlib.dll",
                "AssetsTools.NET.dll",
                "LiteNetLib.dll"
            };

            CopyAllAssemblies(subnauticaManagedPath, libDirectory, ignoreNitroxBinaries);

            List <string> ignoreNoBinaries = new List <string>();

            CopyAllAssemblies(libDirectory, subnauticaManagedPath, ignoreNoBinaries);
        }
Example #7
0
        private void SyncAssetBundles()
        {
            string NormalizePath(string path)
            {
                return(Path.GetFullPath(new Uri(path).LocalPath)
                       .TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
                       .ToUpperInvariant());
            }

            if (PirateDetection.TriggerOnDirectory(subnauticaPath))
            {
                return;
            }

            string currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            // Don't try to sync Asset Bundles if the user placed the launcher in the root of the Subnautica folder.
            if (NormalizePath(currentDirectory) == NormalizePath(subnauticaPath))
            {
                return;
            }

            string subnauticaAssetsPath       = Path.Combine(subnauticaPath, "AssetBundles");
            string currentDirectoryAssetsPath = Path.Combine(currentDirectory, "AssetBundles");

            string[] assetBundles = Directory.GetFiles(currentDirectoryAssetsPath);
            Log.Info($"Copying asset files from Launcher directory '{currentDirectoryAssetsPath}' to Subnautica '{subnauticaAssetsPath}'");
            foreach (string assetBundle in assetBundles)
            {
                string from = Path.Combine(currentDirectoryAssetsPath, Path.GetFileName(assetBundle));
                string to   = Path.Combine(subnauticaAssetsPath, Path.GetFileName(assetBundle));
                Log.Debug($"Copying asset file '{from}' to '{to}'");
                File.Copy(from, to, true);
            }
        }
Example #8
0
        private Process StartSubnautica()
        {
            if (PirateDetection.TriggerOnDirectory(subnauticaPath))
            {
                return(null);
            }

            string           subnauticaExe = Path.Combine(subnauticaPath, "Subnautica.exe");
            ProcessStartInfo startInfo     = new ProcessStartInfo
            {
                WorkingDirectory = subnauticaPath,
                FileName         = subnauticaExe
            };

            if (PlatformDetection.IsEpic(subnauticaPath))
            {
                startInfo.Arguments = "-EpicPortal";
            }
            else if (PlatformDetection.IsSteam(subnauticaPath))
            {
                startInfo.FileName = "steam://run/264710";
            }

            return(Process.Start(startInfo));
        }
Example #9
0
        internal void StartMultiplayer()
        {
            string subnauticaPath = "";

            if (ErrorConfiguringLaunch(ref subnauticaPath))
            {
                return;
            }

            if (PirateDetection.IsPirate(subnauticaPath))
            {
                if (PirateDetectedEvent != null)
                {
                    PirateDetectedEvent(this, new EventArgs());
                }
                return;
            }

            SyncAssembliesBetweenSubnauticaManagedAndLib(subnauticaPath);

            NitroxEntryPatch nitroxEntryPatch = new NitroxEntryPatch(subnauticaPath);

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

            StartSubnautica(subnauticaPath);

            //TODO: maybe an async callback to remove when the app closes.
        }
Example #10
0
        private void CopyAllAssemblies(string source, string destination, List <string> dllsToIgnore)
        {
            if (PirateDetection.TriggerOnDirectory(subnauticaPath))
            {
                return;
            }

            foreach (string sourceFilePath in Directory.GetFiles(source))
            {
                string fileName = Path.GetFileName(sourceFilePath);
                if (dllsToIgnore.Contains(fileName))
                {
                    continue;
                }

                string destinationFilePath = Path.Combine(destination, fileName);
                if (File.Exists(destinationFilePath) && fileName.EndsWith("dll"))
                {
                    try
                    {
                        Version  sourceVersion      = AssemblyName.GetAssemblyName(sourceFilePath).Version;
                        Version  destinationVersion = AssemblyName.GetAssemblyName(destinationFilePath).Version;
                        FileInfo destFileInfo       = new FileInfo(destinationFilePath);
                        FileInfo sourceFileInfo     = new FileInfo(sourceFilePath);

                        if (sourceVersion != destinationVersion || destFileInfo.LastWriteTime != sourceFileInfo.LastWriteTime)
                        {
                            File.Delete(destinationFilePath);
                            File.Copy(sourceFilePath, destinationFilePath, true);
                        }
                    }
                    catch (BadImageFormatException)
                    {
                        // note: discord-rpc.dll has no version information and will fail with BadImageFormatException.
                        // This means the discord-rpc.dll is already present in the destination folder and will be ignored.
                        // Only in case of other dll's the error will be logged.
                        if (!fileName.Equals("discord-rpc.dll"))
                        {
                            Log.Error($"There was an BadImageFormatException determining the version of the assembly: {fileName}");
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error($"There was error during copying the assembly: {fileName}", e);
                    }
                }
                else if (!File.Exists(destinationFilePath))
                {
                    File.Copy(sourceFilePath, destinationFilePath, true);
                }
            }
        }
Example #11
0
        public async Task <string> SetTargetedSubnauticaPath(string path)
        {
            if (Config.SubnauticaPath == path || !Directory.Exists(path))
            {
                return(null);
            }

            Config.SubnauticaPath = path;

            if (lastFindSubnauticaTask != null)
            {
                await lastFindSubnauticaTask;
            }

            lastFindSubnauticaTask = Task.Factory.StartNew(() =>
            {
                PirateDetection.TriggerOnDirectory(path);

                if (!FileSystem.Instance.IsWritable(Directory.GetCurrentDirectory()) || !FileSystem.Instance.IsWritable(path))
                {
                    // TODO: Move this check to another place where Nitrox installation can be verified. (i.e: another page on the launcher in order to check permissions, network setup, ...)
                    if (!FileSystem.Instance.SetFullAccessToCurrentUser(Directory.GetCurrentDirectory()) || !FileSystem.Instance.SetFullAccessToCurrentUser(path))
                    {
                        Dispatcher.CurrentDispatcher.BeginInvoke(() =>
                        {
                            MessageBox.Show(Application.Current.MainWindow !, "Restart Nitrox Launcher as admin to allow Nitrox to change permissions as needed. This is only needed once. Nitrox will close after this message.", "Required file permission error", MessageBoxButton.OK,
                                            MessageBoxImage.Error);
                            Environment.Exit(1);
                        }, DispatcherPriority.ApplicationIdle);
                    }
                }

                // Save game path as preferred for future sessions.
                NitroxUser.PreferredGamePath = path;

                if (nitroxEntryPatch?.IsApplied == true)
                {
                    nitroxEntryPatch.Remove();
                }
                nitroxEntryPatch = new NitroxEntryPatch(() => Config.SubnauticaPath);

                if (Path.GetFullPath(path).StartsWith(WindowsHelper.ProgramFileDirectory, StringComparison.OrdinalIgnoreCase))
                {
                    WindowsHelper.RestartAsAdmin();
                }

                return(path);
            }, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());

            return(await lastFindSubnauticaTask);
        }
Example #12
0
        internal async Task StartSingleplayerAsync()
        {
            if (PirateDetection.TriggerOnDirectory(subnauticaPath))
            {
                return;
            }
            if (Process.GetProcessesByName("Subnautica").Length > 0)
            {
                throw new Exception("An instance of Subnautica is already running");
            }

            SyncAssembliesBetweenSubnauticaManagedAndLib();
            nitroxEntryPatch.Remove();
            gameProcess = StartSubnautica() ?? await WaitForProcessAsync();
        }
Example #13
0
        internal Process StartServer(bool standalone)
        {
            if (PirateDetection.TriggerOnDirectory(subnauticaPath))
            {
                return(null);
            }
            if (ServerRunning)
            {
                throw new Exception("An instance of Nitrox Server is already running");
            }

            SyncAssembliesBetweenSubnauticaManagedAndLib();

            string           serverPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "lib", "NitroxServer-Subnautica.exe");
            ProcessStartInfo startInfo  = new ProcessStartInfo(serverPath);

            if (!standalone)
            {
                startInfo.UseShellExecute        = false;
                startInfo.RedirectStandardOutput = true;
                startInfo.RedirectStandardInput  = true;
                startInfo.CreateNoWindow         = true;
            }

            serverProcess = Process.Start(startInfo);
            if (serverProcess != null)
            {
                serverProcess.EnableRaisingEvents = true; // Required for 'Exited' event from process.

                if (!standalone)
                {
                    serverProcess.OutputDataReceived += ServerProcessOnOutputDataReceived;
                    serverProcess.BeginOutputReadLine();
                }
                serverProcess.Exited += (sender, args) => OnEndServer();
                OnStartServer(!standalone);
            }
            return(serverProcess);
        }
Example #14
0
        private void SyncAssetBundles()
        {
            if (PirateDetection.TriggerOnDirectory(subnauticaPath))
            {
                return;
            }

            string currentDirectory = Directory.GetCurrentDirectory();

            // Don't try to sync Asset Bundles if the user placed the launcher in the root
            // of the Subnautica folder.
            if (NormalizePath(currentDirectory) == NormalizePath(subnauticaPath))
            {
                return;
            }

            string subnauticaAssetsPath = Path.Combine(subnauticaPath, "AssetBundles");

            string[] assetBundles = Directory.GetFiles("AssetBundles");
            foreach (string assetBundle in assetBundles)
            {
                File.Copy(assetBundle, Path.Combine(subnauticaAssetsPath, Path.GetFileName(assetBundle)), true);
            }
        }
Example #15
0
 private LauncherLogic(string subnauticaPath)
 {
     this.subnauticaPath = subnauticaPath;
     PirateDetection.TriggerOnDirectory(subnauticaPath);
     nitroxEntryPatch = new NitroxEntryPatch(subnauticaPath);
 }