Ejemplo n.º 1
0
        internal static void Patch()
        {
            try
            {
                if (patched)
                {
                    Logger.Warn("Patch method was called multiple times!");
                    return;
                }
                patched = true;

                Logger.Info($"Loading QModManager v{Assembly.GetExecutingAssembly().GetName().Version.ToStringParsed()}...");

                if (QModBaseDir == null)
                {
                    Logger.Fatal("A fatal error has occurred.");
                    Logger.Fatal("There was an error with the QMods directory");
                    Logger.Fatal("Please make sure that you ran Subnautica from Steam/Epic/Discord, and not from the executable file!");
                    return;
                }

                try
                {
                    Logger.Info($"Folder structure:\n{IOUtilities.GetFolderStructureAsTree()}\n");
                }
                catch (Exception e)
                {
                    Logger.Error("There was an error while trying to display the folder structure.");
                    Logger.Exception(e);
                }

                QModHooks.Load();
#pragma warning disable CS0618 // Type or member is obsolete
                Hooks.Load();
#pragma warning restore CS0618 // Type or member is obsolete

                PirateCheck.IsPirate(Environment.CurrentDirectory);

                if (!DetectGame())
                {
                    return;
                }

                PatchHarmony();

                if (NitroxCheck.IsInstalled)
                {
                    Logger.Fatal($"Nitrox was detected!");
                    Dialog.Show("Both QModManager and Nitrox detected. QModManager is not compatible with Nitrox. Please uninstall one of them.", Dialog.Button.disabled, Dialog.Button.disabled, false);
                    return;
                }

                StartLoadingMods();
                ShowErroredMods();

                VersionCheck.Check();

                QModHooks.Start += PrefabDebugger.Main;

                QModHooks.OnLoadEnd?.Invoke();
#pragma warning disable CS0618 // Type or member is obsolete
                Hooks.OnLoadEnd?.Invoke();
#pragma warning restore CS0618 // Type or member is obsolete

                Logger.Info($"Finished loading QModManager. Loaded {loadedMods.Count} mods");
            }
            catch (Exception e)
            {
                Logger.Error("EXCEPTION CAUGHT!");
                Logger.Exception(e);
            }
        }