/// <summary> /// Clears the current active mods /// </summary> /// <param name="removeCore">Set to true to remove core [Optional](Default:false)</param> private static void ClearLoadedMods(bool removeCore = false) { ModsConfigAPI.Reset(); if (removeCore) { ModsConfigAPI.SetActive(ModContentPack.CoreModIdentifier, false); } }
/// <summary> /// Set the current active mods /// </summary> /// <param name="modsToActivate">The mods to set as active</param> internal static void SetActiveMods(List <string> modsToActivate) { ClearLoadedMods(true); foreach (string modID in modsToActivate) { ModsConfigAPI.SetActive(modID, true); } ModsConfigAPI.Save(); }
/// <summary> /// Gets a list of active mods in load order /// </summary> /// <returns>A list of the active mods identifier</returns> private static List <string> GetActiveMods() { List <string> result = new List <string>(); foreach (ModMetaData mod in ModsConfigAPI.ActiveModsInLoadOrder()) { result.Add(mod.Identifier); } return(result); }
/// <summary> /// Saves or Loads the state /// </summary> /// <param name="filepath">The filepath to the state</param> private static void ExposeData(string filepath, bool useUndoAction = false) { try { if (CurrentMode == Mode.Saving) { Main.LogDebug("Saving state to {0}", filepath); Data = new ModsConfigData { buildNumber = RimWorld.VersionControl.CurrentBuild, activeMods = GetActiveMods() }; XmlSaverAPI.SaveDataObject((object)Data, filepath); } else if (CurrentMode == Mode.Loading) { Main.LogDebug("Loading state from {0}", filepath); List <string> current = new List <string>(); Data = ReadState(filepath); ClearLoadedMods(true); foreach (string modID in Data.activeMods) { ModsConfigAPI.SetActive(modID, true); } } } catch (System.Exception e) { //An error occurred, output to log and reset loaded mods Main.Log.ReportException(e, Globals.MOD_IDENTIFIER, true, "ExposeData"); ClearLoadedMods(); } }