private static IEnumerator InitializeQMods(IEnumerator result)
        {
            while (result.MoveNext())
            {
                yield return(result);
            }

#if BELOWZERO
            if (!SpriteManager.hasInitialized)
            {
                yield return(new WaitUntil(() => SpriteManager.hasInitialized));
            }
#endif

            Initializer.InitializeMods(QModsToLoad, PatchingOrder.NormalInitialize);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.PostInitialize);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.MetaPostInitialize);

            SummaryLogger.ReportIssues(QModsToLoad);
            SummaryLogger.LogSummaries(QModsToLoad);
            foreach (Dialog dialog in Patcher.Dialogs)
            {
                dialog.Show();
            }
#endif
        }
        private void PreInitializeQMods()
        {
            Patcher.Patch(); // Run QModManager patch

            if (QModsToLoad is null)
            {
                Logger.LogWarning("QModsToLoad is null!");
                return;
            }

            Initializer = new Initializer(Patcher.CurrentlyRunningGame);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.MetaPreInitialize);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.PreInitialize);

#if SUBNAUTICA_STABLE
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.NormalInitialize);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.PostInitialize);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.MetaPostInitialize);

            SummaryLogger.ReportIssues(QModsToLoad);
            SummaryLogger.LogSummaries(QModsToLoad);
            foreach (Dialog dialog in Patcher.Dialogs)
            {
                dialog.Show();
            }
#else
            var harmony = new Harmony(PluginGuid);
            harmony.Patch(
                AccessTools.Method(
                    typeof(PlatformUtils), nameof(PlatformUtils.PlatformInitAsync)
                    ),
                postfix: new HarmonyMethod(AccessTools.Method(typeof(QMMLoader), nameof(QMMLoader.InitializeQMods)))
                );
        }
Example #3
0
        private static void InitializeQMods()
        {
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.NormalInitialize);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.PostInitialize);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.MetaPostInitialize);

            SummaryLogger.ReportIssues(QModsToLoad);
            SummaryLogger.LogSummaries(QModsToLoad);

            foreach (Dialog dialog in Patcher.Dialogs)
            {
                dialog.Show();
            }
        }
Example #4
0
        private static IEnumerator InitializeQMods(IEnumerator result)
        {
            yield return(result);

            Initializer.InitializeMods(QModsToLoad, PatchingOrder.NormalInitialize);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.PostInitialize);
            Initializer.InitializeMods(QModsToLoad, PatchingOrder.MetaPostInitialize);

            SummaryLogger.ReportIssues(QModsToLoad);
            SummaryLogger.LogSummaries(QModsToLoad);
            foreach (Dialog dialog in Patcher.Dialogs)
            {
                dialog.Show();
            }
        }
Example #5
0
        internal static void Patch()
        {
            try
            {
                if (Patched)
                {
                    Logger.Warn("Patch method was called multiple times!");
                    return; // Halt patching
                }

                Patched = true;

                Logger.Info("Game Version: " + SNUtils.GetPlasticChangeSetOfBuild() + " Build Date: " + SNUtils.GetDateTimeOfBuild().ToLongDateString());
                Logger.Info($"Loading QModManager v{Assembly.GetExecutingAssembly().GetName().Version.ToStringParsed()}...");
                Logger.Info($"Today is {DateTime.Today:dd-MMMM-yyyy}");

                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!");

                    new Dialog()
                    {
                        message     = "A fatal error has occurred. QModManager could not be initialized.",
                        color       = Dialog.DialogColor.Red,
                        leftButton  = Dialog.Button.SeeLog,
                        rightButton = Dialog.Button.Close,
                    }.Show();

                    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);
                }

                PirateCheck.IsPirate(Environment.CurrentDirectory);

                var gameDetector = new GameDetector();

                if (!gameDetector.IsValidGameRunning)
                {
                    return;
                }

                CurrentlyRunningGame = gameDetector.CurrentlyRunningGame;

                try
                {
                    PatchHarmony();
                }
                catch (Exception e)
                {
                    Logger.Error("There was an error while trying to apply Harmony patches.");
                    Logger.Exception(e);
                }

                if (NitroxCheck.IsInstalled)
                {
                    Logger.Fatal($"Nitrox was detected!");

                    new Dialog()
                    {
                        message     = "Both QModManager and Nitrox detected. QModManager is not compatible with Nitrox. Please uninstall one of them.",
                        leftButton  = Dialog.Button.Disabled,
                        rightButton = Dialog.Button.Disabled,
                        color       = Dialog.DialogColor.Red,
                    }.Show();

                    return;
                }

                VersionCheck.Check();

                Logger.Info("Started loading mods");

                AddAssemblyResolveEvent();

                IQModFactory modFactory = new QModFactory();
                List <QMod>  modsToLoad = modFactory.BuildModLoadingList(QModBaseDir);

                QModServices.LoadKnownMods(modsToLoad);

                var initializer = new Initializer(CurrentlyRunningGame);
                initializer.InitializeMods(modsToLoad);

                SummaryLogger.ReportIssues(modsToLoad);

                SummaryLogger.LogSummaries(modsToLoad);
            }
            catch (FatalPatchingException pEx)
            {
                Logger.Fatal($"A fatal patching exception has been caught! Patching ended prematurely!");
                Logger.Exception(pEx);

                new Dialog()
                {
                    message    = "A fatal patching exception has been caught. QModManager could not be initialized.",
                    color      = Dialog.DialogColor.Red,
                    leftButton = Dialog.Button.SeeLog,
                }.Show();
            }
            catch (Exception e)
            {
                Logger.Fatal("An unhandled exception has been caught! Patching ended prematurely!");
                Logger.Exception(e);

                new Dialog()
                {
                    message    = "An unhandled exception has been caught. QModManager could not be initialized.",
                    color      = Dialog.DialogColor.Red,
                    leftButton = Dialog.Button.SeeLog,
                }.Show();
            }
        }
		void printSummary(SummaryLogger logger, ProjectInstance[] allProjects)
		{
			var results = logger.ProjectResults;
			var filenamesOfProjects = new HashSet<string>(allProjects.Select(pi => pi.FullPath));
			// we must group by filename and not by project id, it seems that we get multiple results with different project ids for the same project.
			// and even that list may include projects that we did not actually build explicitly.
			var projectResults = 
				results
				.GroupBy(result => result.Filename)
				.Select(rs => rs.Last())
				.Where(rs => filenamesOfProjects.Contains(rs.Filename))
				.ToArray();
			var succeded = projectResults.Count(result => result.Succeeded);
			var failed = projectResults.Count(result => !result.Succeeded);

			coreToIDE(() => _pane.OutputString($"========== BuildOnSave: {succeded} succeeded, {failed} failed ==========\n"));
		}
		BuildStatus buildCore(BuildRequest request, CancellationToken cancellation)
		{
#if DEBUG
			var verbosity = LoggerVerbosity.Minimal;
#else
			var verbosity = LoggerVerbosity.Quiet;
#endif
			var consoleLogger = new ConsoleLogger(verbosity,
				str =>
					coreToIDE(() => _pane.OutputString(str)),
				color => { },
				() => { })
			{
				SkipProjectStartedText = true,
				ShowSummary = false
			};

			var summaryLogger = new SummaryLogger();

			var parameters = new BuildParameters()
			{
				Loggers = new ILogger[] {consoleLogger, summaryLogger},
				EnableNodeReuse = true,
				ShutdownInProcNodeOnBuildFinish = false,
				DetailedSummary = false,
			};
			
			printIntro(request);
			var status = buildCore(request, cancellation, parameters);
			printSummary(summaryLogger, request.AllProjectsToBuildOrdered);
			return status;
		}
Example #8
0
        internal static void Patch()
        {
            try
            {
                if (patched)
                {
                    Logger.Warn("Patch method was called multiple times!");
                    return; // Halt patching
                }

                Patched = true;

                Logger.Info($"Loading QModManager v{Assembly.GetExecutingAssembly().GetName().Version.ToStringParsed()}...");
                Logger.Info($"Today is {DateTime.Today:dd-MMMM-yyyy}");

                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!");

                    Dialog.Show("A fatal error has occurred. QModManager could not be initialized.", Dialog.Button.close, Dialog.Button.Disabled, false);

                    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);
                }

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

                PirateCheck.IsPirate(Environment.CurrentDirectory);

                var gameDetector = new GameDetector();

                if (!gameDetector.IsValidGameRunning)
                {
                    return;
                }

                CurrentlyRunningGame = gameDetector.CurrentlyRunningGame;

                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;
                }

                VersionCheck.Check();

                Logger.Info("Started loading mods");

                AddAssemblyResolveEvent();

                IQModFactory modFactory = new QModFactory();
                List <QMod>  modsToLoad = modFactory.BuildModLoadingList(QModBaseDir);

                QModServices.LoadKnownMods(modsToLoad);

                var initializer = new Initializer(CurrentlyRunningGame);
                initializer.InitializeMods(modsToLoad);

                int loadedMods  = 0;
                int erroredMods = 0;
                foreach (QMod mod in modsToLoad)
                {
                    if (mod.IsLoaded)
                    {
                        loadedMods++;
                    }
                    else if (mod.Enable)
                    {
                        erroredMods++;
                    }
                }

                ErrorModCount = erroredMods;

                Logger.Info($"Finished loading QModManager. Loaded {loadedMods} mods");

                if (ErrorModCount > 0)
                {
                    string msg = $"A total of {ErrorModCount} mods failed to load";
                    Logger.Warn(msg);
                    Dialog.Show(msg + "\nSee log file for details.", Dialog.Button.close, Dialog.Button.Disabled, false);
                }

                SummaryLogger.LogSummaries(modsToLoad);
            }
            catch (FatalPatchingException pEx)
            {
                Logger.Fatal($"A fatal patching exception has been caught! Patching ended prematurely!");
                Logger.Exception(pEx);

                Dialog.Show("A fatal patching exception has been caught. QModManager could not be initialized.", Dialog.Button.close, Dialog.Button.Disabled, false);
            }
            catch (Exception e)
            {
                Logger.Fatal("An unhandled exception has been caught! - Patching ended prematurely!");
                Logger.Exception(e);

                Dialog.Show("An unhandled exception has been caught. QModManager could not be initialized.", Dialog.Button.close, Dialog.Button.Disabled, false);
            }
        }