public static void InitializeMods()
        {
            int num = 0;

            foreach (ModMetaData modMetaData in ModsConfig.ActiveModsInLoadOrder.ToList <ModMetaData>())
            {
                DeepProfiler.Start("Initializing " + modMetaData);
                if (!modMetaData.RootDir.Exists)
                {
                    ModsConfig.SetActive(modMetaData.Identifier, false);
                    Log.Warning(string.Concat(new object[]
                    {
                        "Failed to find active mod ",
                        modMetaData.Name,
                        "(",
                        modMetaData.Identifier,
                        ") at ",
                        modMetaData.RootDir
                    }), false);
                    DeepProfiler.End();
                }
                else
                {
                    ModContentPack item = new ModContentPack(modMetaData.RootDir, num, modMetaData.Name);
                    num++;
                    LoadedModManager.runningMods.Add(item);
                    DeepProfiler.End();
                }
            }
        }
Exemplo n.º 2
0
        public static void InitializeMods()
        {
            int num = 0;

            foreach (ModMetaData item2 in ModsConfig.ActiveModsInLoadOrder.ToList())
            {
                DeepProfiler.Start("Initializing " + item2);
                try
                {
                    if (!item2.RootDir.Exists)
                    {
                        ModsConfig.SetActive(item2.PackageId, active: false);
                        Log.Warning("Failed to find active mod " + item2.Name + "(" + item2.PackageIdPlayerFacing + ") at " + item2.RootDir);
                    }
                    else
                    {
                        ModContentPack item = new ModContentPack(item2.RootDir, item2.PackageId, item2.PackageIdPlayerFacing, num, item2.Name);
                        num++;
                        runningMods.Add(item);
                    }
                }
                catch (Exception arg)
                {
                    Log.Error("Error initializing mod: " + arg);
                    ModsConfig.SetActive(item2.PackageId, active: false);
                }
                finally
                {
                    DeepProfiler.End();
                }
            }
        }
Exemplo n.º 3
0
        static ModsConfig()
        {
            bool flag = false;

            ModsConfig.data = DirectXmlLoader.ItemFromXmlFile <ModsConfig.ModsConfigData>(GenFilePaths.ModsConfigFilePath, true);
            if (ModsConfig.data.buildNumber < VersionControl.CurrentBuild)
            {
                Log.Message(string.Concat(new object[]
                {
                    "Mods config data is from build ",
                    ModsConfig.data.buildNumber,
                    " while we are at build ",
                    VersionControl.CurrentBuild,
                    ". Resetting."
                }), false);
                ModsConfig.data = new ModsConfig.ModsConfigData();
                flag            = true;
            }
            ModsConfig.data.buildNumber = VersionControl.CurrentBuild;
            bool flag2 = File.Exists(GenFilePaths.ModsConfigFilePath);

            if (!flag2 || flag)
            {
                ModsConfig.data.activeMods.Add(ModContentPack.CoreModIdentifier);
                ModsConfig.Save();
            }
        }
Exemplo n.º 4
0
        public static void RebuildModList()
        {
            nestedRebuildInProgress = rebuildingModList;
            rebuildingModList       = true;
            string s = "Rebuilding mods list";

            mods.Clear();
            WorkshopItems.EnsureInit();
            s += "\nAdding official mods from content folder:";
            foreach (string item in from d in new DirectoryInfo(GenFilePaths.OfficialModsFolderPath).GetDirectories()
                     select d.FullName)
            {
                ModMetaData modMetaData = new ModMetaData(item, official: true);
                if (TryAddMod(modMetaData))
                {
                    s = s + "\n  Adding " + modMetaData.ToStringLong();
                }
            }
            s += "\nAdding mods from mods folder:";
            foreach (string item2 in from d in new DirectoryInfo(GenFilePaths.ModsFolderPath).GetDirectories()
                     select d.FullName)
            {
                ModMetaData modMetaData2 = new ModMetaData(item2);
                if (TryAddMod(modMetaData2))
                {
                    s = s + "\n  Adding " + modMetaData2.ToStringLong();
                }
            }
            s += "\nAdding mods from Steam:";
            foreach (WorkshopItem item3 in WorkshopItems.AllSubscribedItems.Where((WorkshopItem it) => it is WorkshopItem_Mod))
            {
                ModMetaData modMetaData3 = new ModMetaData(item3);
                if (TryAddMod(modMetaData3))
                {
                    s = s + "\n  Adding " + modMetaData3.ToStringLong();
                }
            }
            s += "\nDeactivating not-installed mods:";
            ModsConfig.DeactivateNotInstalledMods(delegate(string log)
            {
                s = s + "\n   " + log;
            });
            if (Prefs.SimulateNotOwningRoyalty)
            {
                ModsConfig.SetActive(ModContentPack.RoyaltyModPackageId, active: false);
            }
            if (mods.Count((ModMetaData m) => m.Active) == 0)
            {
                s += "\nThere are no active mods. Activating Core mod.";
                mods.First((ModMetaData m) => m.IsCoreMod).Active = true;
            }
            RecacheRoyaltyInstalled();
            if (Prefs.LogVerbose)
            {
                Log.Message(s);
            }
            rebuildingModList       = false;
            nestedRebuildInProgress = false;
        }
Exemplo n.º 5
0
        public static bool TryCreateDialogsForVersionMismatchWarnings(Action confirmedAction)
        {
            string text  = null;
            string text2 = null;

            if (!BackCompatibility.IsSaveCompatibleWith(ScribeMetaHeaderUtility.loadedGameVersion) && !ScribeMetaHeaderUtility.VersionsMatch())
            {
                text2 = "VersionMismatch".Translate();
                string text3 = (!ScribeMetaHeaderUtility.loadedGameVersion.NullOrEmpty()) ? ScribeMetaHeaderUtility.loadedGameVersion : ("(" + "UnknownLower".Translate() + ")");
                text = ((ScribeMetaHeaderUtility.lastMode != ScribeHeaderMode.Map) ? ((ScribeMetaHeaderUtility.lastMode != ScribeHeaderMode.World) ? "FileIncompatibleWarning".Translate(text3, VersionControl.CurrentVersionString) : "WorldFileVersionMismatch".Translate(text3, VersionControl.CurrentVersionString)) : "SaveGameIncompatibleWarningText".Translate(text3, VersionControl.CurrentVersionString));
            }
            bool   flag  = false;
            string text4 = default(string);
            string text5 = default(string);

            if (!ScribeMetaHeaderUtility.LoadedModsMatchesActiveMods(out text4, out text5))
            {
                flag = true;
                string text6 = "ModsMismatchWarningText".Translate(text4, text5);
                text = ((text != null) ? (text + "\n\n" + text6) : text6);
                if (text2 == null)
                {
                    text2 = "ModsMismatchWarningTitle".Translate();
                }
            }
            if (text != null)
            {
                string            text7  = text;
                string            title  = text2;
                Dialog_MessageBox dialog = Dialog_MessageBox.CreateConfirmation(text7, confirmedAction, false, title);
                dialog.buttonAText = "LoadAnyway".Translate();
                if (flag)
                {
                    dialog.buttonCText   = "ChangeLoadedMods".Translate();
                    dialog.buttonCAction = delegate
                    {
                        int num = ModLister.InstalledModsListHash(false);
                        ModsConfig.SetActiveToList(ScribeMetaHeaderUtility.loadedModIdsList);
                        ModsConfig.Save();
                        if (num == ModLister.InstalledModsListHash(false))
                        {
                            IEnumerable <string> items = from id in Enumerable.Range(0, ScribeMetaHeaderUtility.loadedModIdsList.Count)
                                                         where ModLister.GetModWithIdentifier(ScribeMetaHeaderUtility.loadedModIdsList[id]) == null
                                                         select ScribeMetaHeaderUtility.loadedModNamesList[id];
                            Messages.Message(string.Format("{0}: {1}", "MissingMods".Translate(), GenText.ToCommaList(items, true)), MessageTypeDefOf.RejectInput);
                            dialog.buttonCClose = false;
                        }
                        else
                        {
                            ModsConfig.RestartFromChangedMods();
                        }
                    };
                }
                Find.WindowStack.Add(dialog);
                return(true);
            }
            return(false);
        }
        public static void LoadAllActiveMods()
        {
            XmlInheritance.Clear();
            int num = 0;

            foreach (ModMetaData item2 in ModsConfig.ActiveModsInLoadOrder.ToList())
            {
                DeepProfiler.Start("Initializing " + item2);
                if (!item2.RootDir.Exists)
                {
                    ModsConfig.SetActive(item2.Identifier, false);
                    Log.Warning("Failed to find active mod " + item2.Name + "(" + item2.Identifier + ") at " + item2.RootDir);
                    DeepProfiler.End();
                }
                else
                {
                    ModContentPack item = new ModContentPack(item2.RootDir, num, item2.Name);
                    num++;
                    LoadedModManager.runningMods.Add(item);
                    DeepProfiler.End();
                }
            }
            for (int i = 0; i < LoadedModManager.runningMods.Count; i++)
            {
                ModContentPack modContentPack = LoadedModManager.runningMods[i];
                DeepProfiler.Start("Loading " + modContentPack + " content");
                modContentPack.ReloadContent();
                DeepProfiler.End();
            }
            foreach (Type item3 in typeof(Mod).InstantiableDescendantsAndSelf())
            {
                if (!LoadedModManager.runningModClasses.ContainsKey(item3))
                {
                    ModContentPack modContentPack2 = (from modpack in LoadedModManager.runningMods
                                                      where modpack.assemblies.loadedAssemblies.Contains(item3.Assembly)
                                                      select modpack).FirstOrDefault();
                    LoadedModManager.runningModClasses[item3] = (Mod)Activator.CreateInstance(item3, modContentPack2);
                }
            }
            for (int j = 0; j < LoadedModManager.runningMods.Count; j++)
            {
                ModContentPack modContentPack3 = LoadedModManager.runningMods[j];
                DeepProfiler.Start("Loading " + modContentPack3);
                modContentPack3.LoadDefs(LoadedModManager.runningMods.SelectMany((ModContentPack rm) => rm.Patches));
                DeepProfiler.End();
            }
            foreach (ModContentPack runningMod in LoadedModManager.runningMods)
            {
                foreach (PatchOperation patch in runningMod.Patches)
                {
                    patch.Complete(runningMod.Name);
                }
                runningMod.ClearPatchesCache();
            }
            XmlInheritance.Clear();
        }
 public static void LoadAllPlayData(bool recovering = false)
 {
     if (PlayDataLoader.loadedInt)
     {
         Log.Error("Loading play data when already loaded. Call ClearAllPlayData first.");
     }
     else
     {
         DeepProfiler.Start("LoadAllPlayData");
         try
         {
             PlayDataLoader.DoPlayLoad();
         }
         catch (Exception arg)
         {
             if (!Prefs.ResetModsConfigOnCrash)
             {
                 throw;
             }
             if (recovering)
             {
                 Log.Warning("Could not recover from errors loading play data. Giving up.");
                 throw;
             }
             IEnumerable <ModMetaData> activeModsInLoadOrder = ModsConfig.ActiveModsInLoadOrder;
             if (activeModsInLoadOrder.Count() == 1 && activeModsInLoadOrder.First().IsCoreMod)
             {
                 throw;
             }
             Log.Warning("Caught exception while loading play data but there are active mods other than Core. Resetting mods config and trying again.\nThe exception was: " + arg);
             try
             {
                 PlayDataLoader.ClearAllPlayData();
             }
             catch
             {
                 Log.Warning("Caught exception while recovering from errors and trying to clear all play data. Ignoring it.\nThe exception was: " + arg);
             }
             ModsConfig.Reset();
             DirectXmlCrossRefLoader.Clear();
             PlayDataLoader.LoadAllPlayData(true);
             return;
         }
         finally
         {
             DeepProfiler.End();
         }
         PlayDataLoader.loadedInt = true;
         if (recovering)
         {
             Log.Message("Successfully recovered from errors and loaded play data.");
             DelayedErrorWindowRequest.Add("RecoveredFromErrorsText".Translate(), "RecoveredFromErrorsDialogTitle".Translate());
         }
     }
 }
        public static bool TryCreateDialogsForVersionMismatchWarnings(Action confirmedAction)
        {
            string text  = null;
            string text2 = null;

            if (!BackCompatibility.IsSaveCompatibleWith(loadedGameVersion) && !VersionsMatch())
            {
                text2 = "VersionMismatch".Translate();
                string value = loadedGameVersion.NullOrEmpty() ? ("(" + "UnknownLower".TranslateSimple() + ")") : loadedGameVersion;
                text = ((lastMode == ScribeHeaderMode.Map) ? ((string)"SaveGameIncompatibleWarningText".Translate(value, VersionControl.CurrentVersionString)) : ((lastMode != ScribeHeaderMode.World) ? ((string)"FileIncompatibleWarning".Translate(value, VersionControl.CurrentVersionString)) : ((string)"WorldFileVersionMismatch".Translate(value, VersionControl.CurrentVersionString))));
            }
            bool flag = false;

            if (!LoadedModsMatchesActiveMods(out string loadedModsSummary, out string runningModsSummary))
            {
                flag = true;
                string text3 = "ModsMismatchWarningText".Translate(loadedModsSummary, runningModsSummary);
                text = ((text != null) ? (text + "\n\n" + text3) : text3);
                if (text2 == null)
                {
                    text2 = "ModsMismatchWarningTitle".Translate();
                }
            }
            if (text != null)
            {
                Dialog_MessageBox dialog = Dialog_MessageBox.CreateConfirmation(text, confirmedAction, destructive: false, text2);
                dialog.buttonAText = "LoadAnyway".Translate();
                if (flag)
                {
                    dialog.buttonCText   = "ChangeLoadedMods".Translate();
                    dialog.buttonCAction = delegate
                    {
                        if (Current.ProgramState == ProgramState.Entry)
                        {
                            ModsConfig.SetActiveToList(loadedModIdsList);
                        }
                        ModsConfig.SaveFromList(loadedModIdsList);
                        IEnumerable <string> enumerable = from id in Enumerable.Range(0, loadedModIdsList.Count)
                                                          where ModLister.GetModWithIdentifier(loadedModIdsList[id]) == null
                                                          select loadedModNamesList[id];
                        if (enumerable.Any())
                        {
                            Messages.Message(string.Format("{0}: {1}", "MissingMods".Translate(), enumerable.ToCommaList()), MessageTypeDefOf.RejectInput, historical: false);
                            dialog.buttonCClose = false;
                        }
                        ModsConfig.RestartFromChangedMods();
                    };
                }
                Find.WindowStack.Add(dialog);
                return(true);
            }
            return(false);
        }
Exemplo n.º 9
0
        public static int InstalledModsListHash(bool activeOnly)
        {
            int num  = 17;
            int num2 = 0;

            foreach (ModMetaData item in ModsConfig.ActiveModsInLoadOrder)
            {
                if (!activeOnly || ModsConfig.IsActive(item.PackageId))
                {
                    num = num * 31 + item.GetHashCode();
                    num = num * 31 + num2 * 2654241;
                    num2++;
                }
            }
            return(num);
        }
Exemplo n.º 10
0
        static ModsConfig()
        {
            bool flag = false;

            ModsConfig.data = DirectXmlLoader.ItemFromXmlFile <ModsConfigData>(GenFilePaths.ModsConfigFilePath, true);
            if (ModsConfig.data.buildNumber < VersionControl.CurrentBuild)
            {
                Log.Message("Mods config data is from build " + ModsConfig.data.buildNumber + " while we are at build " + VersionControl.CurrentBuild + ". Resetting.");
                ModsConfig.data = new ModsConfigData();
                flag            = true;
            }
            ModsConfig.data.buildNumber = VersionControl.CurrentBuild;
            if (File.Exists(GenFilePaths.ModsConfigFilePath) && !flag)
            {
                return;
            }
            ModsConfig.data.activeMods.Add(ModContentPack.CoreModIdentifier);
            ModsConfig.Save();
        }
Exemplo n.º 11
0
        public static void InitializeMods()
        {
            int num = 0;

            foreach (ModMetaData current in ModsConfig.ActiveModsInLoadOrder.ToList <ModMetaData>())
            {
                DeepProfiler.Start("Initializing " + current);
                try
                {
                    if (!current.RootDir.Exists)
                    {
                        ModsConfig.SetActive(current.Identifier, false);
                        Log.Warning(string.Concat(new object[]
                        {
                            "Failed to find active mod ",
                            current.Name,
                            "(",
                            current.Identifier,
                            ") at ",
                            current.RootDir
                        }), false);
                    }
                    else
                    {
                        ModContentPack item = new ModContentPack(current.RootDir, num, current.Name);
                        num++;
                        LoadedModManager.runningMods.Add(item);
                    }
                }
                catch (Exception arg)
                {
                    Log.Error("Error initializing mod: " + arg, false);
                    ModsConfig.SetActive(current.Identifier, false);
                }
                finally
                {
                    DeepProfiler.End();
                }
            }
        }
Exemplo n.º 12
0
        internal static void RebuildModList()
        {
            string s = "Rebuilding mods list";

            ModLister.mods.Clear();
            s += "\nAdding mods from mods folder:";
            foreach (string current in from d in new DirectoryInfo(GenFilePaths.CoreModsFolderPath).GetDirectories()
                     select d.FullName)
            {
                ModMetaData modMetaData = new ModMetaData(current);
                ModLister.mods.Add(modMetaData);
                s = s + "\n  Adding " + modMetaData.ToStringLong();
            }
            s += "\nAdding mods from Steam:";
            foreach (WorkshopItem current2 in from it in WorkshopItems.AllSubscribedItems
                     where it is WorkshopItem_Mod
                     select it)
            {
                ModMetaData modMetaData2 = new ModMetaData(current2);
                ModLister.mods.Add(modMetaData2);
                s = s + "\n  Adding " + modMetaData2.ToStringLong();
            }
            s += "\nDeactivating not-installed mods:";
            ModsConfig.DeactivateNotInstalledMods(delegate(string log)
            {
                s = s + "\n   " + log;
            });
            if (ModLister.mods.Count((ModMetaData m) => m.Active) == 0)
            {
                s += "\nThere are no active mods. Activating Core mod.";
                ModLister.mods.First((ModMetaData m) => m.IsCoreMod).Active = true;
            }
            if (Prefs.LogVerbose)
            {
                Log.Message(s);
            }
        }
Exemplo n.º 13
0
 public static void Reset()
 {
     ModsConfig.data.activeMods.Clear();
     ModsConfig.data.activeMods.Add(ModContentPack.CoreModIdentifier);
     ModsConfig.Save();
 }
Exemplo n.º 14
0
 public static void SetActive(ModMetaData mod, bool active)
 {
     ModsConfig.SetActive(mod.Identifier, active);
 }
            public override bool TryResolve(FailMode failReportMode)
            {
                bool flag = false;

                for (int i = 0; i < defNames.Count; i++)
                {
                    bool flag2 = mayRequireMods != null && i < mayRequireMods.Count && !mayRequireMods[i].NullOrEmpty() && !ModsConfig.IsActive(mayRequireMods[i]);
                    T    val   = TryResolveDef <T>(defNames[i], (!flag2) ? failReportMode : FailMode.Silent, debugWanterInfo);
                    if (val != null)
                    {
                        ((List <T>)wanter).Add(val);
                        defNames.RemoveAt(i);
                        if (mayRequireMods != null && i < mayRequireMods.Count)
                        {
                            mayRequireMods.RemoveAt(i);
                        }
                        i--;
                    }
                    else
                    {
                        flag = true;
                    }
                }
                return(!flag);
            }
        private static List <T> ListFromXml <T>(XmlNode listRootNode)
        {
            List <T> list = new List <T>();

            try
            {
                bool flag = typeof(Def).IsAssignableFrom(typeof(T));
                foreach (XmlNode childNode in listRootNode.ChildNodes)
                {
                    if (!ValidateListNode(childNode, listRootNode, typeof(T)))
                    {
                        continue;
                    }
                    XmlAttribute xmlAttribute = childNode.Attributes["MayRequire"];
                    if (flag)
                    {
                        DirectXmlCrossRefLoader.RegisterListWantsCrossRef(list, childNode.InnerText, listRootNode.Name, xmlAttribute?.Value);
                        continue;
                    }
                    try
                    {
                        if (xmlAttribute == null || xmlAttribute.Value.NullOrEmpty() || ModsConfig.IsActive(xmlAttribute.Value))
                        {
                            list.Add(ObjectFromXml <T>(childNode, doPostLoad: true));
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(string.Concat("Exception loading list element from XML: ", ex, "\nXML:\n", listRootNode.OuterXml));
                    }
                }
                return(list);
            }
            catch (Exception ex2)
            {
                Log.Error(string.Concat("Exception loading list from XML: ", ex2, "\nXML:\n", listRootNode.OuterXml));
                return(list);
            }
        }
Exemplo n.º 17
0
        public static void LoadAllActiveMods()
        {
            XmlInheritance.Clear();
            int num = 0;

            foreach (ModMetaData current in ModsConfig.ActiveModsInLoadOrder.ToList <ModMetaData>())
            {
                DeepProfiler.Start("Initializing " + current);
                if (!current.RootDir.Exists)
                {
                    ModsConfig.SetActive(current.Identifier, false);
                    Log.Warning(string.Concat(new object[]
                    {
                        "Failed to find active mod ",
                        current.Name,
                        "(",
                        current.Identifier,
                        ") at ",
                        current.RootDir
                    }));
                    DeepProfiler.End();
                }
                else
                {
                    ModContentPack item = new ModContentPack(current.RootDir, num, current.Name);
                    num++;
                    LoadedModManager.runningMods.Add(item);
                    DeepProfiler.End();
                }
            }
            for (int i = 0; i < LoadedModManager.runningMods.Count; i++)
            {
                ModContentPack modContentPack = LoadedModManager.runningMods[i];
                DeepProfiler.Start("Loading " + modContentPack + " content");
                modContentPack.ReloadContent();
                DeepProfiler.End();
            }
            foreach (Type type in typeof(Mod).InstantiableDescendantsAndSelf())
            {
                if (!LoadedModManager.runningModClasses.ContainsKey(type))
                {
                    ModContentPack modContentPack2 = (from modpack in LoadedModManager.runningMods
                                                      where modpack.assemblies.loadedAssemblies.Contains(type.Assembly)
                                                      select modpack).FirstOrDefault <ModContentPack>();
                    LoadedModManager.runningModClasses[type] = (Mod)Activator.CreateInstance(type, new object[]
                    {
                        modContentPack2
                    });
                }
            }
            for (int j = 0; j < LoadedModManager.runningMods.Count; j++)
            {
                ModContentPack modContentPack3 = LoadedModManager.runningMods[j];
                DeepProfiler.Start("Loading " + modContentPack3);
                modContentPack3.LoadDefs(LoadedModManager.runningMods.SelectMany((ModContentPack rm) => rm.Patches));
                DeepProfiler.End();
            }
            foreach (ModContentPack current2 in LoadedModManager.runningMods)
            {
                foreach (PatchOperation current3 in current2.Patches)
                {
                    current3.Complete(current2.Name);
                }
                current2.ClearPatchesCache();
            }
            XmlInheritance.Clear();
        }