/// <summary> /// Called by the game when the mod is enabled. /// </summary> public void OnEnabled() { // Apply Harmony patches via Cities Harmony. // Called here instead of OnCreated to allow the auto-downloader to do its work prior to launch. HarmonyHelper.DoOnHarmonyReady(() => Patcher.PatchAll()); // Load settings file. SettingsUtils.LoadSettings(); // Check to see if UIView is ready. if (UIView.GetAView() != null) { // It's ready - attach the hook now. OptionsPanel.OptionsEventHook(); } else { // Otherwise, queue the hook for when the intro's finished loading. LoadingManager.instance.m_introLoaded += OptionsPanel.OptionsEventHook; } }
/// <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); } } } }
/// <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); }