Exemple #1
0
 /// <summary>
 /// Updates XML configuration file with current settings.
 /// </summary>
 internal static void SaveXML()
 {
     // Write to file.
     try
     {
         WG_XMLBaseVersion xml = new XML_VersionTwo();
         xml.WriteXML(Loading.currentFileLocation);
     }
     catch (Exception e)
     {
         Logging.LogException(e, "exception saving XML configuation file");
     }
 }
Exemple #2
0
 /// <summary>
 /// Updates XML configuration file with current settings.
 /// </summary>
 internal static void SaveXML()
 {
     // Write to file.
     try
     {
         WG_XMLBaseVersion xml = new XML_VersionTwo();
         xml.writeXML(Loading.currentFileLocation);
     }
     catch (Exception e)
     {
         Debugging.LogException(e);
     }
 }
        /// <summary>
        ///
        /// </summary>
        public static void readFromXML()
        {
            // Switch to default which is the cities skylines in the application data area.
            currentFileLocation = ColossalFramework.IO.DataLocation.localApplicationData + Path.DirectorySeparatorChar + XML_FILE;

            if (File.Exists(currentFileLocation))
            {
                // Load in from XML - Designed to be flat file for ease
                WG_XMLBaseVersion reader = new XML_VersionTwo();
                XmlDocument       doc    = new XmlDocument();
                try
                {
                    doc.Load(currentFileLocation);
                    int version = Convert.ToInt32(doc.DocumentElement.Attributes["version"].InnerText);
                    if (version == 1)
                    {
                        reader = new XML_VersionOne();

                        // Make a back up copy of the old system to be safe
                        File.Copy(currentFileLocation, currentFileLocation + ".ver1", true);
                        string error = "Detected an old version of the XML (v1). " + currentFileLocation + ".ver1 has been created for future reference and will be upgraded to the new version.";
                        Debugging.bufferWarning(error);
                        Debugging.Message(error);
                    }
                    else if (version <= 0) // Uh oh... version 0 was a while back..
                    {
                        string error = "Detected an unsupported version of the XML (v0 or less). Backing up for a new configuration as :" + currentFileLocation + ".ver0";
                        Debugging.bufferWarning(error);
                        Debugging.Message(error);
                        File.Copy(currentFileLocation, currentFileLocation + ".ver0", true);
                        return;
                    }
                    reader.readXML(doc);
                }
                catch (Exception e)
                {
                    // Game will now use defaults
                    Debugging.bufferWarning("The following exception(s) were detected while loading the XML file. Some (or all) values may not be loaded.");
                    Debugging.bufferWarning(e.Message);
                }
            }
            else
            {
                Debugging.Message("configuration file not found. Will output new file to : " + currentFileLocation);
            }
        }
Exemple #4
0
        /// <summary>
        /// Called by the game when level loading is complete.
        /// </summary>
        /// <param name="mode">Loading mode (e.g. game, editor, scenario, etc.)</param>
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);

            // Check to see if a conflicting mod has been detected.
            if (conflictingMod)
            {
                // Mod conflict detected - display warning notification and exit.
                ListMessageBox modConflictBox = MessageBoxBase.ShowModal <ListMessageBox>();

                // Key text items.
                modConflictBox.AddParas(Translations.Translate("ERR_CON0"), Translations.Translate("LBR_ERR_FAT"), Translations.Translate("LBR_ERR_CON0"), Translations.Translate("ERR_CON1"));

                // Add conflicting mod name(s).
                modConflictBox.AddList(ModUtils.conflictingModNames.ToArray());

                // Closing para.
                modConflictBox.AddParas(Translations.Translate("LBR_ERR_CON1"));
            }

            // Don't do anything if we're not enabled or we've already been here.
            if (isModEnabled && !isModCreated)
            {
                // Wait for Harmony if it hasn't already happened.
                //if (!Patcher.patched)
                {
                    // Set timeout counter, just in case.
                    DateTime startTime = DateTime.Now;

                    try
                    {
                        Logging.Message("waiting for Harmony");
                        while (!Patcher.patched)
                        {
                            if (CitiesHarmony.API.HarmonyHelper.IsHarmonyInstalled)
                            {
                                Patcher.PatchAll();
                                break;
                            }

                            // Three minutes should be sufficient wait.
                            if (DateTime.Now > startTime.AddMinutes(3))
                            {
                                throw new TimeoutException("Harmony loading timeout: " + startTime.ToString() + " : " + DateTime.Now.ToString());
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Logging.LogException(e, "Harmony loading exception");

                        // Harmony 2 wasn't loaded; display warning notification and exit.
                        ListMessageBox harmonyBox = MessageBoxBase.ShowModal <ListMessageBox>();

                        // Key text items.
                        harmonyBox.AddParas(Translations.Translate("ERR_HAR0"), Translations.Translate("LBR_ERR_HAR"), Translations.Translate("LBR_ERR_FAT"), Translations.Translate("ERR_HAR1"));

                        // List of dot points.
                        harmonyBox.AddList(Translations.Translate("ERR_HAR2"), Translations.Translate("ERR_HAR3"));

                        // Closing para.
                        harmonyBox.AddParas(Translations.Translate("MES_PAGE"));
                    }
                }

                Logging.Message("Harmony ready, proceeding");

                // Set flag.
                isModCreated = true;

                // Load and apply mod settings (configuration file loaded above).
                settingsFile = Configuration <SettingsFile> .Load();

                ModSettings.VanillaCalcs      = settingsFile.UseVanilla;
                ModSettings.LegacyCalcs       = settingsFile.UseLegacy;
                ModSettings.CustomRetirement  = settingsFile.CustomRetirement;
                ModSettings.RetirementYear    = settingsFile.RetirementYear;
                ModSettings.UseTransportModes = settingsFile.UseTransportModes;
                ModSettings.randomImmigrantEd = settingsFile.RandomImmigrantEd;
                Logging.UseDeathLog           = settingsFile.LogDeaths;
                Logging.UseImmigrationLog     = settingsFile.LogImmigrants;
                Logging.UseTransportLog       = settingsFile.LogTransport;
                Logging.UseSicknessLog        = settingsFile.LogSickness;

                // Apply sickness probabilities.
                CalculateSicknessProbabilities();

                // Report status.
                Logging.Message("death logging ", Logging.UseDeathLog ? "enabled" : "disabled", ", immigration logging ", Logging.UseImmigrationLog ? "enabled" : "disabled", ", transportation logging ", Logging.UseTransportLog ? "enabled" : "disabled");

                // Prime Threading.counter to continue from frame index.
                int temp = (int)(Singleton <SimulationManager> .instance.m_currentFrameIndex / 4096u);
                Threading.counter = temp % DataStore.lifeSpanMultiplier;
                try
                {
                    WG_XMLBaseVersion xml = new XML_VersionTwo();
                    xml.WriteXML(currentFileLocation);
                }
                catch (Exception e)
                {
                    Logging.LogException(e, "XML configuration file error");
                }

                // Set up options panel event handler.
                OptionsPanel.OptionsEventHook();

                Logging.KeyMessage("successfully loaded");

                // Display update notifications.
                WhatsNew.ShowWhatsNew();
            }
        }
        /// <summary>
        /// Called by the game when level loading is complete.
        /// </summary>
        /// <param name="mode">Loading mode (e.g. game, editor, scenario, etc.)</param>
        public override void OnLevelLoaded(LoadMode mode)
        {
            // Don't do anything if not in game.
            if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame)
            {
                Debugging.Message("not loading into game; exiting");
                return;
            }

            // Don't do anything if we've already been here.
            if (!isModCreated)
            {
                // Check for mod conflicts.
                ModConflicts modConflicts = new ModConflicts();
                if (modConflicts.CheckConflicts())
                {
                    // Conflict detected.  Unpatch everything before exiting without doing anything further.
                    Patcher.UnpatchAll();
                    return;
                }

                Debugging.Message("v" + LifecycleRebalance.Version + " loading");

                // Wait for Harmony if it hasn't already happened.
                if (!Patcher.patched)
                {
                    // Set timeout counter, just in case.
                    DateTime startTime = DateTime.Now;

                    try
                    {
                        Debugging.Message("waiting for Harmony");
                        while (!Patcher.patched)
                        {
                            if (CitiesHarmony.API.HarmonyHelper.IsHarmonyInstalled)
                            {
                                Patcher.PatchAll();
                                break;
                            }

                            // Three minutes should be sufficient wait.
                            if (DateTime.Now > startTime.AddMinutes(3))
                            {
                                throw new TimeoutException("Harmony loading timeout: " + startTime.ToString() + " : " + DateTime.Now.ToString());
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debugging.Message("Harmony loading exception");
                        Debugging.LogException(e);

                        // Show error notification to user.
                        ErrorNotification notification = new ErrorNotification();
                        notification.Create();
                        ErrorNotification.headerText  = "Harmony loading error!";
                        ErrorNotification.messageText = "Lifecycle Rebalance Revisited can't load properly because the required Harmony mod dependency didn't load.  In most cases, a simple game restart should be enough to fix this.\r\n\r\nIf this notification persists, please manually subscribe to the Harmony mod on the Steam workshop (if you're already subscribed, try unsubscribing and re-subscribing) and restart your game again.";
                        notification.Show();
                        return;
                    }
                }

                Debugging.Message("Harmony ready, proceeding");

                // Set flag.
                isModCreated = true;

                // Load and apply mod settings (configuration file loaded above).
                settingsFile = Configuration <SettingsFile> .Load();

                ModSettings.VanillaCalcs      = settingsFile.UseVanilla;
                ModSettings.LegacyCalcs       = settingsFile.UseLegacy;
                ModSettings.CustomRetirement  = settingsFile.CustomRetirement;
                ModSettings.RetirementYear    = settingsFile.RetirementYear;
                ModSettings.UseTransportModes = settingsFile.UseTransportModes;
                ModSettings.randomImmigrantEd = settingsFile.RandomImmigrantEd;
                Debugging.UseDeathLog         = settingsFile.LogDeaths;
                Debugging.UseImmigrationLog   = settingsFile.LogImmigrants;
                Debugging.UseTransportLog     = settingsFile.LogTransport;
                Debugging.UseSicknessLog      = settingsFile.LogSickness;

                // Apply sickness probabilities.
                CalculateSicknessProbabilities();

                // Report status and any debugging messages.
                Debugging.Message("death logging " + (Debugging.UseDeathLog ? "enabled" : "disabled") + ", immigration logging " + (Debugging.UseImmigrationLog ? "enabled" : "disabled") + ", transportation logging " + (Debugging.UseTransportLog ? "enabled" : "disabled"));
                Debugging.ReleaseBuffer();

                // Prime Threading.counter to continue from frame index.
                int temp = (int)(Singleton <SimulationManager> .instance.m_currentFrameIndex / 4096u);
                Threading.counter = temp % DataStore.lifeSpanMultiplier;
                try
                {
                    WG_XMLBaseVersion xml = new XML_VersionTwo();
                    xml.writeXML(currentFileLocation);
                }
                catch (Exception e)
                {
                    Debugging.LogException(e);
                }

                // Set up options panel event handler.
                OptionsPanel.OptionsEventHook();

                Debugging.Message("successfully loaded");

                // Check if we need to display update notification.
                if (settingsFile.NotificationVersion != 3)
                {
                    // No update notification "Don't show again" flag found; show the notification.
                    UpdateNotification notification = new UpdateNotification();
                    notification.Create();
                    notification.Show();
                }
            }
        }