Exemplo n.º 1
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);

            //if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame)
            //return;

            //Load xml only from main menu.
            if (xmlManager == null)
            {
                xmlManager = new RICOPrefabManager();
                xmlManager.Run();
            }

            //Assign xml settings to prefabs.
            convertPrefabs = new ConvertPrefabs();
            convertPrefabs.run();

            //Init GUI
            PloppableTool.Initialize();
            RICOSettingsPanel.Initialize();

            //Deploy Detour
            Detour.BuildingToolDetour.Deploy();
            Debug.Log("Detour Deployed");
        }
        /// <summary>
        /// Called by the game when the mod is initialised at the start of the loading process.
        /// </summary>
        /// <param name="loading">Loading mode (e.g. game, editor, scenario, etc.)</param>
        public override void OnCreated(ILoading loading)
        {
            base.OnCreated(loading);

            // Don't do anything if not in game (e.g. if we're going into an editor).
            if (loading.currentMode != AppMode.Game)
            {
                isModEnabled = false;
                Logging.KeyMessage("not loading into game, skipping activation");

                // Set harmonyLoaded flag to suppress Harmony warning when e.g. loading into editor.
                harmonyLoaded = true;

                // Unload Harmony patches and exit before doing anything further.
                Patcher.UnpatchAll();
                return;
            }

            // Ensure that Harmony patches have been applied.
            harmonyLoaded = Patcher.Patched;
            if (!harmonyLoaded)
            {
                isModEnabled = false;
                Logging.Error("Harmony patches not applied; aborting");
                return;
            }

            // Check for mod conflicts.
            if (ModUtils.IsModConflict())
            {
                // Conflict detected.
                conflictingMod = true;
                isModEnabled   = false;

                // Unload Harmony patches and exit before doing anything further.
                Patcher.UnpatchAll();
                return;
            }

            // Passed all checks - okay to load (if we haven't already fo some reason).
            if (!isModEnabled)
            {
                isModEnabled = true;
                Logging.KeyMessage("v " + PloppableRICOMod.Version + " loading");

                // Check for other mods, including any soft conflicts.
                softModConflct = ModUtils.CheckMods();

                // Check for Advanced Building Level Control.
                ModUtils.ABLCReflection();

                // Create instances if they don't already exist.
                if (convertPrefabs == null)
                {
                    convertPrefabs = new ConvertPrefabs();
                }

                if (xmlManager == null)
                {
                    xmlManager = new RICOPrefabManager
                    {
                        prefabHash = new Dictionary <BuildingInfo, BuildingData>(),
                    };
                }

                // Reset broken prefabs list.
                brokenPrefabs = new List <BuildingInfo>();

                // Read any local RICO settings.
                string ricoDefPath = "LocalRICOSettings.xml";
                localRicoDef = null;

                if (!File.Exists(ricoDefPath))
                {
                    Logging.Message("no ", ricoDefPath, " file found");
                }
                else
                {
                    localRicoDef = RICOReader.ParseRICODefinition(ricoDefPath, isLocal: true);

                    if (localRicoDef == null)
                    {
                        Logging.Message("no valid definitions in ", ricoDefPath);
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called by the game when the mod is initialised at the start of the loading process.
        /// </summary>
        /// <param name="loading">Loading mode (e.g. game, editor, scenario, etc.)</param>
        public override void OnCreated(ILoading loading)
        {
            // Don't do anything if not in game (e.g. if we're going into an editor).
            if (loading.currentMode != AppMode.Game)
            {
                isModEnabled = false;
                Debugging.Message("not loading into game, skipping activation");
            }
            else
            {
                // Check for conflicting (and other) mods.
                isModEnabled = ModUtils.CheckMods();
            }

            // If we're not enabling the mod due to one of the above checks failing, unapply Harmony patches before returning without doing anything.
            if (!isModEnabled)
            {
                Patcher.UnpatchAll();
                return;
            }

            // Make sure patches have been applied before proceeding.
            if (!Patcher.Patched)
            {
                Debugging.Message("Harmony patches not applied, exiting");
                isModEnabled = false;
                return;
            }

            // Otherwise, game on!
            Debugging.Message("v" + PloppableRICOMod.Version + " loading");

            // Ensure patch watchdog flag is properly initialised.
            patchOperating = false;

            // Create instances if they don't already exist.
            if (convertPrefabs == null)
            {
                convertPrefabs = new ConvertPrefabs();
            }

            if (xmlManager == null)
            {
                xmlManager = new RICOPrefabManager
                {
                    prefabHash = new Dictionary <BuildingInfo, BuildingData>(),
                    prefabList = new List <BuildingData>()
                };
            }

            // Read mod settings.
            SettingsFile settingsFile = Configuration <SettingsFile> .Load();

            Settings.plainThumbs  = settingsFile.PlainThumbs;
            Settings.debugLogging = settingsFile.DebugLogging;
            Settings.resetOnLoad  = settingsFile.ResetOnLoad;

            // Read any local RICO settings.
            string ricoDefPath = "LocalRICOSettings.xml";

            localRicoDef = null;

            if (!File.Exists(ricoDefPath))
            {
                Debugging.Message("no " + ricoDefPath + " file found");
            }
            else
            {
                localRicoDef = RICOReader.ParseRICODefinition("", ricoDefPath, insanityOK: true);

                if (localRicoDef == null)
                {
                    Debugging.Message("no valid definitions in " + ricoDefPath);
                }
            }

            base.OnCreated(loading);
        }