Example #1
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)
        {
            Logging.Message("commencing loading checks");

            base.OnLevelLoaded(mode);

            // Don't do anything further if we're not operating.
            if (!isModEnabled)
            {
                Logging.Message("exiting");
                return;
            }

            // Check to see that Harmony 2 was properly loaded.
            if (!Patcher.Patched)
            {
                // Harmony 2 wasn't loaded; abort.
                Logging.Error("Harmony patches not applied; aborting");
                isModEnabled = false;

                // Display warning message.
                ListMessageBox harmonyBox = MessageBoxBase.ShowModal <ListMessageBox>();

                // Key text items.
                harmonyBox.AddParas(Translations.Translate("ERR_HAR0"), Translations.Translate("BOB_ERR_HAR"), Translations.Translate("BOB_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"));

                // Don't do anything further.
                return;
            }

            Logging.Message("loading checks passed");

            // Build lists of loaded prefabs.
            PrefabLists.BuildLists();

            // Load prop packs.
            new NetworkPackReplacement();

            // Load configuration file.
            ConfigurationUtils.LoadConfig();

            // Set up BOB tool.
            ToolsModifierControl.toolController.gameObject.AddComponent <BOBTool>();

            // Display update notification.
            WhatsNew.ShowWhatsNew();

            // Set up Network Skins 2 reflection.
            ModUtils.NS2Reflection();

            // Enable thin wires, if applicable.
            if (ModSettings.ThinnerWires)
            {
                ElectricalWires.Instance.ApplyThinnerWires();
            }

            // Force update of any dirty net or building prefabs from replacement process.
            Logging.Message("updating dirty prefabs");
            BuildingData.Update();
            NetData.Update();

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

            // Display any exception message that occured during load.
            InfoPanelManager.CheckException();

            // Activate tool hotkey.
            UIThreading.Operating = true;

            Logging.Message("loading complete");
        }
Example #2
0
        /// <summary>
        /// Save current configuration to the specified config file.
        /// </summary>
        /// <param name="config">Configuration file name; null for default file (default null)</param>
        /// <param name="clean">Set to true to generate a blank file (default false)</param>
        internal static void SaveConfig(string config = null, bool clean = false)
        {
            // Default file location is the general config file.
            string fileName = GeneralConfigFile;

            try
            {
                // Check if we've got an assigned custom config.
                if (config != null)
                {
                    // Custom config assigned - use this filename in the configuration settings directory (creating directory if it doesn't already exist).
                    if (!Directory.Exists(ConfigDirectory))
                    {
                        Directory.CreateDirectory(ConfigDirectory);
                    }
                    fileName = FullConfigPath(config);
                }

                // Open specified file.
                using (StreamWriter textWriter = new StreamWriter(fileName, append: false))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(BOBConfigurationFile));

                    // Create new config if there isn't one.
                    if (CurrentConfig == null)
                    {
                        CurrentConfig = new BOBConfigurationFile
                        {
                            // Version 1.
                            version = 1
                        };
                    }

                    // Don't populate file if we're doing a clean save.
                    if (!clean)
                    {
                        // Serialise scales.
                        try
                        {
                            CurrentConfig.propScales = Scaling.Instance.propScales.Values.ToList();
                            CurrentConfig.treeScales = Scaling.Instance.treeScales.Values.ToList();
                        }
                        catch (Exception e)
                        {
                            // Don't let a single failure stop us.
                            Logging.LogException(e, "exception serializing scaling elements");
                        }

                        // Serialise active replacement packs.
                        try
                        {
                            CurrentConfig.activePacks = NetworkPackReplacement.Instance.SerializeActivePacks();
                        }
                        catch (Exception e)
                        {
                            // Don't let a single failure stop us.
                            Logging.LogException(e, "exception serializing active replacement packs");
                        }
                    }

                    // Write to file.
                    xmlSerializer.Serialize(textWriter, CurrentConfig);

                    // Delete any old config.
                    if (File.Exists(GeneralConfigName))
                    {
                        File.Delete(GeneralConfigName);
                    }
                }
            }
            catch (Exception e)
            {
                Logging.LogException(e, "exception saving XML configuration file ", fileName ?? "null");
            }

            // Display any exception message that occured during save.
            InfoPanelManager.CheckException();
        }
Example #3
0
        /// <summary>
        /// Checks for and displays any exception message.
        /// Called by the game every update cycle.
        /// </summary>
        public override void Update()
        {
            base.Update();

            InfoPanelManager.CheckException();
        }