Beispiel #1
0
        internal void Awake()
        {
            if (LoadingScreen.Instance == null)
            {
                Destroy(gameObject);
                return;
            }

            // Ensure that only one copy of the service is run per scene change.
            if (loadedInScene || !ElectionAndCheck())
            {
                Assembly currentAssembly = Assembly.GetExecutingAssembly();
                Log("Multiple copies of current version. Using the first copy. Version: " +
                    currentAssembly.GetName().Version);
                Destroy(gameObject);
                return;
            }

            totalTime.Start();

            Debug.unityLogger.logHandler = new InterceptLogHandler(Debug.unityLogger.logHandler);

            // Allow loading the background in the loading screen
            Application.runInBackground = true;
            QualitySettings.vSyncCount  = 0;
            Application.targetFrameRate = -1;

            // More cool loading screen. Less 4 stoke logo.
            for (int i = 0; i < LoadingScreen.Instance.Screens.Count; i++)
            {
                var state = LoadingScreen.Instance.Screens[i];
                state.fadeInTime  = i < 3 ? 0.1f : 1;
                state.displayTime = i < 3 ? 1 : 3;
                state.fadeOutTime = i < 3 ? 0.1f : 1;
            }

            TextMeshProUGUI[] texts = LoadingScreen.Instance.gameObject.GetComponentsInChildren <TextMeshProUGUI>();
            foreach (var text in texts)
            {
                textPos = Mathf.Min(textPos, text.rectTransform.localPosition.y);
            }
            DontDestroyOnLoad(gameObject);

            // Subscribe to the RnD center spawn/deSpawn events
            GameEvents.onGUIRnDComplexSpawn.Add(OnRnDCenterSpawn);
            GameEvents.onGUIRnDComplexDespawn.Add(OnRnDCenterDeSpawn);


            LoadingScreen screen = FindObjectOfType <LoadingScreen>();

            if (screen == null)
            {
                Log("Can't find LoadingScreen type. Aborting ModuleManager execution");
                return;
            }
            List <LoadingSystem> list = LoadingScreen.Instance.loaders;

            if (list != null)
            {
                // So you can insert a LoadingSystem object in this list at any point.
                // GameDatabase is first in the list, and PartLoader is second
                // We could insert ModuleManager after GameDatabase to get it to run there
                // and SaveGameFixer after PartLoader.

                int gameDatabaseIndex = list.FindIndex(s => s is GameDatabase);

                GameObject aGameObject = new GameObject("ModuleManager");
                DontDestroyOnLoad(aGameObject);

                Log(string.Format("Adding post patch to the loading screen {0}", list.Count));
                list.Insert(gameDatabaseIndex + 1, aGameObject.AddComponent <PostPatchLoader>());

                patchRunner = new MMPatchRunner(new PrefixLogger("ModuleManager", new UnityLogger(Debug.unityLogger)));
                StartCoroutine(patchRunner.Run());

                // Workaround for 1.6.0 Editor bug after a PartDatabase rebuild.
                if (Versioning.version_major == 1 && Versioning.version_minor == 6 && Versioning.Revision == 0)
                {
                    Fix16 fix16 = aGameObject.AddComponent <Fix16>();
                    list.Add(fix16);
                }
            }

            bool foolsDay = (DateTime.Now.Month == 4 && DateTime.Now.Day == 1);
            bool catDay   = (DateTime.Now.Month == 2 && DateTime.Now.Day == 22);

            nyan = foolsDay ||
                   Environment.GetCommandLineArgs().Contains("-nyan-nyan");

            nCats = catDay ||
                    Environment.GetCommandLineArgs().Contains("-ncats");

            dumpPostPatch = Environment.GetCommandLineArgs().Contains("-mm-dump");

            DontCopyLogs = Environment.GetCommandLineArgs().Contains("-mm-dont-copy-logs");

            loadedInScene = true;
        }
Beispiel #2
0
        /* Not required anymore. At least
         * public static bool IsABadIdea()
         * {
         *  return (intPtr.ToInt64() == long.MaxValue) && (Environment.OSVersion.Platform == PlatformID.Win32NT);
         * }
         */

        private IEnumerator DataBaseReloadWithMM(bool dump = false)
        {
            QualitySettings.vSyncCount  = 0;
            Application.targetFrameRate = -1;

            patchRunner = new MMPatchRunner(new PrefixLogger("ModuleManager", new UnityLogger(Debug.unityLogger)));

            float totalLoadWeight = GameDatabase.Instance.LoadWeight() + PartLoader.Instance.LoadWeight();
            bool  startedReload   = false;

            UISkinDef skinDef           = HighLogic.UISkin;
            UIStyle   centeredTextStyle = new UIStyle(skinDef.label)
            {
                alignment = TextAnchor.UpperCenter
            };

            PopupDialog reloadingDialog = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
                                                                       new Vector2(0.5f, 0.5f),
                                                                       new MultiOptionDialog(
                                                                           "ModuleManagerReloading",
                                                                           "",
                                                                           "ModuleManager - Reloading Database",
                                                                           skinDef,
                                                                           new Rect(0.5f, 0.5f, 600f, 60f),
                                                                           new DialogGUIFlexibleSpace(),
                                                                           new DialogGUIVerticalLayout(
                                                                               new DialogGUIFlexibleSpace(),
                                                                               new DialogGUILabel(delegate()
            {
                float progressFraction;
                if (!startedReload)
                {
                    progressFraction = 0f;
                }
                else if (!GameDatabase.Instance.IsReady() || !PostPatchLoader.Instance.IsReady())
                {
                    progressFraction  = GameDatabase.Instance.ProgressFraction() * GameDatabase.Instance.LoadWeight();
                    progressFraction /= totalLoadWeight;
                }
                else if (!PartLoader.Instance.IsReady())
                {
                    progressFraction  = GameDatabase.Instance.LoadWeight() + (PartLoader.Instance.ProgressFraction() * GameDatabase.Instance.LoadWeight());
                    progressFraction /= totalLoadWeight;
                }
                else
                {
                    progressFraction = 1f;
                }

                return($"Overall progress: {progressFraction:P0}");
            }, centeredTextStyle, expandW : true),
                                                                               new DialogGUILabel(delegate()
            {
                if (!startedReload)
                {
                    return("Starting");
                }
                else if (!GameDatabase.Instance.IsReady())
                {
                    return(GameDatabase.Instance.ProgressTitle());
                }
                else if (!PostPatchLoader.Instance.IsReady())
                {
                    return(PostPatchLoader.Instance.ProgressTitle());
                }
                else if (!PartLoader.Instance.IsReady())
                {
                    return(PartLoader.Instance.ProgressTitle());
                }
                else
                {
                    return("");
                }
            }),
                                                                               new DialogGUISpace(5f),
                                                                               new DialogGUILabel(() => patchRunner.Status)
                                                                               )
                                                                           ),
                                                                       false,
                                                                       skinDef);

            yield return(null);

            GameDatabase.Instance.Recompile = true;
            GameDatabase.Instance.StartLoad();

            startedReload = true;

            yield return(null);

            StartCoroutine(patchRunner.Run());

            // wait for it to finish
            while (!GameDatabase.Instance.IsReady())
            {
                yield return(null);
            }

            PostPatchLoader.Instance.StartLoad();

            while (!PostPatchLoader.Instance.IsReady())
            {
                yield return(null);
            }

            if (dump)
            {
                OutputAllConfigs();
            }

            PartLoader.Instance.StartLoad();

            while (!PartLoader.Instance.IsReady())
            {
                yield return(null);
            }

            // Needs more work.
            //ConfigNode game = HighLogic.CurrentGame.config.GetNode("GAME");

            //if (game != null && ResearchAndDevelopment.Instance != null)
            //{
            //    ScreenMessages.PostScreenMessage("GAME found");
            //    ConfigNode scenario = game.GetNodes("SCENARIO").FirstOrDefault((ConfigNode n) => n.name == "ResearchAndDevelopment");
            //    if (scenario != null)
            //    {
            //        ScreenMessages.PostScreenMessage("SCENARIO found");
            //        ResearchAndDevelopment.Instance.OnLoad(scenario);
            //    }
            //}

            QualitySettings.vSyncCount  = GameSettings.SYNC_VBL;
            Application.targetFrameRate = GameSettings.FRAMERATE_LIMIT;

            reloadingDialog.Dismiss();
        }