public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; switch (num) { case 0u: ModLister.EnsureInit(); i = 0; break; case 1u: i++; break; default: return(false); } if (i < ModsConfig.data.activeMods.Count) { this.$current = ModLister.GetModWithIdentifier(ModsConfig.data.activeMods[i]); if (!this.$disposing) { this.$PC = 1; } return(true); } this.$PC = -1; return(false); }
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; }
public override void OnClicked(Page_ModsConfig window) { ModMetaData modWithIdentifier = ModLister.GetModWithIdentifier(packageId, ignorePostfix: true); if (modWithIdentifier != null && modWithIdentifier.Active) { window.SelectMod(modWithIdentifier); } }
public List <string> GetIssueList(ModMetaData mod) { List <string> list = new List <string>(); if (foldersForVersion.Count > 0) { string text = null; { foreach (string key in foldersForVersion.Keys) { if (foldersForVersion[key].Count == 0) { list.Add("ModLoadFolderListEmpty".Translate(key)); } foreach (LoadFolder item in from f in foldersForVersion[key] group f by f into g where g.Count() > 1 select g.Key) { list.Add("ModLoadFolderRepeatingFolder".Translate(key, item.folderName)); } if (!VersionControl.IsWellFormattedVersionString(key) && !key.Equals("default", StringComparison.InvariantCultureIgnoreCase)) { list.Add("ModLoadFolderMalformedVersion".Translate(key)); } if (key.Equals("default") && text != null) { list.Add("ModLoadFolderOutOfOrderDefault".Translate()); } if (text != null && VersionControl.TryParseVersionString(key, out Version version) && VersionControl.TryParseVersionString(text, out Version version2) && version < version2) { list.Add("ModLoadFolderOutOfOrder".Translate(key, text)); } for (int i = 0; i < foldersForVersion[key].Count; i++) { LoadFolder loadFolder = foldersForVersion[key][i]; if (!Directory.Exists(Path.Combine(mod.RootDir.FullName, loadFolder.folderName))) { list.Add("ModLoadFolderDoesntExist".Translate(loadFolder.folderName, key)); } } if (VersionControl.TryParseVersionString(key, out Version version3) && !mod.SupportedVersionsReadOnly.Contains(version3)) { list.Add("ModLoadFolderDefinesUnsupportedGameVersion".Translate(key)); } text = key; } return(list); } } return(list); }
private static List <string> FindConflicts(List <ModMetaData> allMods, List <string> modsToCheck, Func <ModMetaData, bool> predicate) { List <string> list = new List <string>(); foreach (string modId in modsToCheck) { ModMetaData modMetaData = allMods.FirstOrDefault((ModMetaData m) => m.SamePackageId(modId, ignorePostfix: true)); if (modMetaData != null && (predicate == null || predicate(modMetaData))) { list.Add(modMetaData.Name); } } return(list); }
private static void LoadedFilesForMod() { List <DebugMenuOption> list = new List <DebugMenuOption>(); foreach (ModContentPack item in LoadedModManager.RunningModsListForReading) { ModContentPack mod = item; list.Add(new DebugMenuOption(mod.Name, DebugMenuOptionMode.Action, delegate { ModMetaData metaData = ModLister.GetModWithIdentifier(mod.PackageId); if (metaData.loadFolders != null && metaData.loadFolders.DefinedVersions().Count != 0) { Find.WindowStack.Add(new Dialog_DebugOptionListLister(from ver in metaData.loadFolders.DefinedVersions() select new DebugMenuOption(ver, DebugMenuOptionMode.Action, delegate { ShowTable((from f in metaData.loadFolders.FoldersForVersion(ver) select Path.Combine(mod.RootDir, f.folderName)).Reverse().ToList()); }))); } else { ShowTable(null); } })); void ShowTable(List <string> loadFolders) { List <Pair <string, string> > list2 = new List <Pair <string, string> >(); list2.AddRange(from f in DirectXmlLoader.XmlAssetsInModFolder(mod, "Defs/", loadFolders) select new Pair <string, string>(f.FullFilePath, "-")); list2.AddRange(from f in DirectXmlLoader.XmlAssetsInModFolder(mod, "Patches/", loadFolders) select new Pair <string, string>(f.FullFilePath, "-")); list2.AddRange(from f in ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <Texture2D>(), ModContentLoader <Texture2D> .IsAcceptableExtension, loadFolders) select new Pair <string, string>(f.Value.FullName, f.Key)); list2.AddRange(from f in ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <AudioClip>(), ModContentLoader <AudioClip> .IsAcceptableExtension, loadFolders) select new Pair <string, string>(f.Value.FullName, f.Key)); list2.AddRange(from f in ModContentPack.GetAllFilesForMod(mod, GenFilePaths.ContentPath <string>(), ModContentLoader <string> .IsAcceptableExtension, loadFolders) select new Pair <string, string>(f.Value.FullName, f.Key)); list2.AddRange(from f in ModContentPack.GetAllFilesForModPreserveOrder(mod, "Assemblies/", (string e) => e.ToLower() == ".dll", loadFolders) select new Pair <string, string>(f.Item2.FullName, f.Item1)); DebugTables.MakeTablesDialog(list2, new List <TableDataGetter <Pair <string, string> > > { new TableDataGetter <Pair <string, string> >("full path", (Pair <string, string> f) => f.First), new TableDataGetter <Pair <string, string> >("internal path", (Pair <string, string> f) => f.Second) }.ToArray()); } } Find.WindowStack.Add(new Dialog_DebugOptionListLister(list)); }
public override void OnClicked(Page_ModsConfig window) { ModMetaData modWithIdentifier = ModLister.GetModWithIdentifier(packageId, ignorePostfix: true); if (modWithIdentifier == null) { if (!Url.NullOrEmpty()) { SteamUtility.OpenUrl(Url); } } else if (!modWithIdentifier.Active) { window.SelectMod(modWithIdentifier); } }
public static void DeactivateNotInstalledMods(Action <string> logCallback = null) { for (int num = data.activeMods.Count - 1; num >= 0; num--) { ModMetaData modWithIdentifier = ModLister.GetModWithIdentifier(data.activeMods[num]); if (modWithIdentifier == null && TryGetPackageIdWithoutExtraSteamPostfix(data.activeMods[num], out var nonSteamPackageId)) { modWithIdentifier = ModLister.GetModWithIdentifier(nonSteamPackageId); } if (modWithIdentifier == null) { logCallback?.Invoke("Deactivating " + data.activeMods[num]); data.activeMods.RemoveAt(num); } } RecacheActiveMods(); }
public bool ModifiesDefFromModOrNullCore(ModMetaData mod, Type defType) { Def defSilentFail = GenDefDatabase.GetDefSilentFail(defType, DefName); if (defSilentFail == null) { return(mod.IsCoreMod); } if (mod == null) { return(defSilentFail.modContentPack == null); } if (defSilentFail.modContentPack != null) { return(defSilentFail.modContentPack.FolderName == mod.FolderName); } return(false); }
public static List <string> GetModWarnings() { List <string> list = new List <string>(); List <ModMetaData> mods = ActiveModsInLoadOrder.ToList(); for (int i = 0; i < mods.Count; i++) { int index = i; ModMetaData modMetaData = mods[index]; StringBuilder stringBuilder = new StringBuilder(""); for (int j = 0; j < mods.Count; j++) { if (i != j && mods[j].PackageId != "" && mods[j].SamePackageId(mods[i].PackageId)) { stringBuilder.AppendLine("ModWithSameIdAlreadyActive".Translate(mods[j].Name)); } } List <string> list2 = FindConflicts(mods, modMetaData.IncompatibleWith, null); if (list2.Any()) { stringBuilder.AppendLine("ModIncompatibleWithTip".Translate(list2.ToCommaList(useAnd: true))); } List <string> list3 = FindConflicts(mods, modMetaData.LoadBefore, (ModMetaData beforeMod) => mods.IndexOf(beforeMod) < index); if (list3.Any()) { stringBuilder.AppendLine("ModMustLoadBefore".Translate(list3.ToCommaList(useAnd: true))); } List <string> list4 = FindConflicts(mods, modMetaData.LoadAfter, (ModMetaData afterMod) => mods.IndexOf(afterMod) > index); if (list4.Any()) { stringBuilder.AppendLine("ModMustLoadAfter".Translate(list4.ToCommaList(useAnd: true))); } if (modMetaData.Dependencies.Any()) { List <string> list5 = modMetaData.UnsatisfiedDependencies(); if (list5.Any()) { stringBuilder.AppendLine("ModUnsatisfiedDependency".Translate(list5.ToCommaList(useAnd: true))); } } list.Add(stringBuilder.ToString().TrimEndNewlines()); } return(list); }
public static bool ModHasAnyOrderingIssues(ModMetaData mod) { List <ModMetaData> mods = ActiveModsInLoadOrder.ToList(); int index = mods.IndexOf(mod); if (index == -1) { return(false); } if (FindConflicts(mods, mod.LoadBefore, (ModMetaData beforeMod) => mods.IndexOf(beforeMod) < index).Count > 0) { return(true); } if (FindConflicts(mods, mod.LoadAfter, (ModMetaData afterMod) => mods.IndexOf(afterMod) > index).Count > 0) { return(true); } return(false); }
public IEnumerable <ModRequirement> GetRequirements() { for (int j = 0; j < Dependencies.Count; j++) { yield return(Dependencies[j]); } for (int j = 0; j < meta.incompatibleWith.Count; j++) { ModMetaData modWithIdentifier = ModLister.GetModWithIdentifier(meta.incompatibleWith[j]); if (modWithIdentifier != null) { yield return(new ModIncompatibility { packageId = modWithIdentifier.PackageIdPlayerFacing, displayName = modWithIdentifier.Name }); } } }
private static bool TryAddMod(ModMetaData mod) { if (mod.Official && !mod.IsCoreMod && SteamManager.Initialized && mod.SteamAppId != 0) { bool flag = true; try { flag = SteamApps.BIsDlcInstalled(new AppId_t((uint)mod.SteamAppId)); } catch (Exception arg) { Log.Error("Could not determine if a DLC is installed: " + arg); } if (!flag) { return(false); } } ModMetaData modWithIdentifier = GetModWithIdentifier(mod.PackageId); if (modWithIdentifier != null) { if (mod.RootDir.FullName != modWithIdentifier.RootDir.FullName) { if (mod.OnSteamWorkshop != modWithIdentifier.OnSteamWorkshop) { ModMetaData modMetaData = mod.OnSteamWorkshop ? mod : modWithIdentifier; if (!modMetaData.appendPackageIdSteamPostfix) { modMetaData.appendPackageIdSteamPostfix = true; return(TryAddMod(mod)); } } Log.Error("Tried loading mod with the same packageId multiple times: " + mod.PackageIdPlayerFacing + ". Ignoring the duplicates.\n" + mod.RootDir.FullName + "\n" + modWithIdentifier.RootDir.FullName); return(false); } return(false); } mods.Add(mod); return(true); }
private static bool ReorderConflict(int modIndex, int newIndex) { ModMetaData modWithIdentifier = ModLister.GetModWithIdentifier(data.activeMods[modIndex]); for (int i = 0; i < data.activeMods.Count; i++) { if (i != modIndex) { ModMetaData modWithIdentifier2 = ModLister.GetModWithIdentifier(data.activeMods[i]); if (modWithIdentifier.IsCoreMod && modWithIdentifier2.Source == ContentSource.OfficialModsFolder && i < newIndex) { return(true); } if (modWithIdentifier.Source == ContentSource.OfficialModsFolder && modWithIdentifier2.IsCoreMod) { return(i >= newIndex); } } } return(false); }
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); } }
public static void TrySortMods() { List <ModMetaData> list = ActiveModsInLoadOrder.ToList(); DirectedAcyclicGraph directedAcyclicGraph = new DirectedAcyclicGraph(list.Count); for (int i = 0; i < list.Count; i++) { ModMetaData modMetaData = list[i]; foreach (string before in modMetaData.LoadBefore) { ModMetaData modMetaData2 = list.FirstOrDefault((ModMetaData m) => m.SamePackageId(before, ignorePostfix: true)); if (modMetaData2 != null) { directedAcyclicGraph.AddEdge(list.IndexOf(modMetaData2), i); } } foreach (string after in modMetaData.LoadAfter) { ModMetaData modMetaData3 = list.FirstOrDefault((ModMetaData m) => m.SamePackageId(after, ignorePostfix: true)); if (modMetaData3 != null) { directedAcyclicGraph.AddEdge(i, list.IndexOf(modMetaData3)); } } } int num = directedAcyclicGraph.FindCycle(); if (num != -1) { Find.WindowStack.Add(new Dialog_MessageBox("ModCyclicDependency".Translate(list[num].Name))); } else { Reorder(directedAcyclicGraph.TopologicalSort()); } }
public static bool IsActive(ModMetaData mod) { return(ModsConfig.data.activeMods.Contains(mod.Identifier)); }
private static bool <get_AllActiveModDirs> m__0(ModMetaData mod) { return(mod.Active); }
public static void SetActive(ModMetaData mod, bool active) { ModsConfig.SetActive(mod.Identifier, active); }
private static DirectoryInfo <get_AllActiveModDirs> m__1(ModMetaData mod) { return(mod.RootDir); }
private static bool <RebuildModList> m__4(ModMetaData m) { return(m.Active); }
public static void SetActive(ModMetaData mod, bool active) { SetActive(mod.PackageId, active); }
private static bool <RebuildModList> m__5(ModMetaData m) { return(m.IsCoreMod); }
static ModsConfig() { activeModsHashSet = new HashSet <string>(); activeModsInLoadOrderCached = new List <ModMetaData>(); bool flag = false; bool flag2 = false; data = DirectXmlLoader.ItemFromXmlFile <ModsConfigData>(GenFilePaths.ModsConfigFilePath); if (data.version != null) { bool flag3 = false; int result; if (data.version.Contains(".")) { int num = VersionControl.MinorFromVersionString(data.version); if (VersionControl.MajorFromVersionString(data.version) != VersionControl.CurrentMajor || num != VersionControl.CurrentMinor) { flag3 = true; } } else if (data.version.Length > 0 && data.version.All((char x) => char.IsNumber(x)) && int.TryParse(data.version, out result) && result <= 2009) { flag3 = true; } if (flag3) { Log.Message("Mods config data is from version " + data.version + " while we are running " + VersionControl.CurrentVersionStringWithRev + ". Resetting."); data = new ModsConfigData(); flag = true; } } for (int i = 0; i < data.activeMods.Count; i++) { string packageId = data.activeMods[i]; if (ModLister.GetModWithIdentifier(packageId) == null) { ModMetaData modMetaData = ModLister.AllInstalledMods.FirstOrDefault((ModMetaData m) => m.FolderName == packageId); if (modMetaData != null) { data.activeMods[i] = modMetaData.PackageId; flag2 = true; } if (TryGetPackageIdWithoutExtraSteamPostfix(packageId, out var nonSteamPackageId) && ModLister.GetModWithIdentifier(nonSteamPackageId) != null) { data.activeMods[i] = nonSteamPackageId; } } } HashSet <string> hashSet = new HashSet <string>(); foreach (ModMetaData allInstalledMod in ModLister.AllInstalledMods) { if (allInstalledMod.Active) { if (hashSet.Contains(allInstalledMod.PackageIdNonUnique)) { allInstalledMod.Active = false; Log.Warning("There was more than one enabled instance of mod with PackageID: " + allInstalledMod.PackageIdNonUnique + ". Disabling the duplicates."); continue; } hashSet.Add(allInstalledMod.PackageIdNonUnique); } if (!allInstalledMod.IsCoreMod && allInstalledMod.Official && IsExpansionNew(allInstalledMod.PackageId)) { SetActive(allInstalledMod.PackageId, active: true); AddKnownExpansion(allInstalledMod.PackageId); flag2 = true; } } if (!File.Exists(GenFilePaths.ModsConfigFilePath) || flag) { Reset(); } else if (flag2) { Save(); } RecacheActiveMods(); }
private void InitLoadFolders() { foldersToLoadDescendingOrder = new List <string>(); ModMetaData modWithIdentifier = ModLister.GetModWithIdentifier(PackageId); if (modWithIdentifier?.loadFolders != null && modWithIdentifier.loadFolders.DefinedVersions().Count > 0) { List <LoadFolder> list = modWithIdentifier.LoadFoldersForVersion(VersionControl.CurrentVersionStringWithoutBuild); if (list != null && list.Count > 0) { AddFolders(list); return; } int num = VersionControl.CurrentVersion.Major; int num2 = VersionControl.CurrentVersion.Minor; while (true) { if (num2 == 0) { num--; num2 = 9; } else { num2--; } if (num < 1) { break; } List <LoadFolder> list2 = modWithIdentifier.LoadFoldersForVersion(num + "." + num2); if (list2 != null) { AddFolders(list2); return; } } List <LoadFolder> list3 = modWithIdentifier.LoadFoldersForVersion("default"); if (list3 != null) { AddFolders(list3); return; } } if (foldersToLoadDescendingOrder.Count != 0) { return; } string text = Path.Combine(RootDir, VersionControl.CurrentVersionStringWithoutBuild); if (Directory.Exists(text)) { foldersToLoadDescendingOrder.Add(text); } else { Version version = new Version(0, 0); DirectoryInfo[] directories = rootDirInt.GetDirectories(); for (int i = 0; i < directories.Length; i++) { if (VersionControl.TryParseVersionString(directories[i].Name, out var version2) && version2 > version) { version = version2; } } if (version.Major > 0) { foldersToLoadDescendingOrder.Add(Path.Combine(RootDir, version.ToString())); } } string text2 = Path.Combine(RootDir, CommonFolderName); if (Directory.Exists(text2)) { foldersToLoadDescendingOrder.Add(text2); } foldersToLoadDescendingOrder.Add(RootDir); void AddFolders(List <LoadFolder> folders) { for (int num3 = folders.Count - 1; num3 >= 0; num3--) { if (folders[num3].ShouldLoad) { foldersToLoadDescendingOrder.Add(Path.Combine(RootDir, folders[num3].folderName)); } } } }
private static void CleanupDefInjectionsForDefType(Type defType, string defInjectionsFolderPath, ModMetaData mod) { List <KeyValuePair <string, DefInjectionPackage.DefInjection> > list = (from x in LanguageDatabase.activeLanguage.defInjections.Where((DefInjectionPackage x) => x.defType == defType).SelectMany((DefInjectionPackage x) => x.injections) where !x.Value.isPlaceholder && x.Value.ModifiesDefFromModOrNullCore(mod, defType) select x).ToList(); Dictionary <string, DefInjectionPackage.DefInjection> dictionary = new Dictionary <string, DefInjectionPackage.DefInjection>(); foreach (KeyValuePair <string, DefInjectionPackage.DefInjection> item2 in list) { if (!dictionary.ContainsKey(item2.Value.normalizedPath)) { dictionary.Add(item2.Value.normalizedPath, item2.Value); } } List <PossibleDefInjection> possibleDefInjections = new List <PossibleDefInjection>(); DefInjectionUtility.ForEachPossibleDefInjection(defType, delegate(string suggestedPath, string normalizedPath, bool isCollection, string str, IEnumerable <string> collection, bool translationAllowed, bool fullListTranslationAllowed, FieldInfo fieldInfo, Def def) { if (translationAllowed) { PossibleDefInjection item = new PossibleDefInjection { suggestedPath = suggestedPath, normalizedPath = normalizedPath, isCollection = isCollection, fullListTranslationAllowed = fullListTranslationAllowed, curValue = str, curValueCollection = collection, fieldInfo = fieldInfo, def = def }; possibleDefInjections.Add(item); } }, mod); if (!possibleDefInjections.Any() && !list.Any()) { return; } List <KeyValuePair <string, DefInjectionPackage.DefInjection> > source = list.Where((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => !x.Value.injected).ToList(); foreach (string fileName in possibleDefInjections.Select((PossibleDefInjection x) => GetSourceFile(x.def)).Concat(source.Select((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => x.Value.fileSource)).Distinct()) { try { XDocument xDocument = new XDocument(); bool flag = false; try { XElement xElement = new XElement("LanguageData"); xDocument.Add(xElement); xElement.Add(new XComment("NEWLINE")); List <PossibleDefInjection> source2 = possibleDefInjections.Where((PossibleDefInjection x) => GetSourceFile(x.def) == fileName).ToList(); List <KeyValuePair <string, DefInjectionPackage.DefInjection> > source3 = source.Where((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => x.Value.fileSource == fileName).ToList(); foreach (string defName in from x in source2.Select((PossibleDefInjection x) => x.def.defName).Concat(source3.Select((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => x.Value.DefName)).Distinct() orderby x select x) { try { IEnumerable <PossibleDefInjection> enumerable = source2.Where((PossibleDefInjection x) => x.def.defName == defName); IEnumerable <KeyValuePair <string, DefInjectionPackage.DefInjection> > enumerable2 = source3.Where((KeyValuePair <string, DefInjectionPackage.DefInjection> x) => x.Value.DefName == defName); if (enumerable.Any()) { bool flag2 = false; foreach (PossibleDefInjection item3 in enumerable) { if (item3.isCollection) { IEnumerable <string> englishList = GetEnglishList(item3.normalizedPath, item3.curValueCollection, dictionary); bool flag3 = false; if (englishList != null) { int num = 0; foreach (string item4 in englishList) { _ = item4; if (dictionary.ContainsKey(item3.normalizedPath + "." + num)) { flag3 = true; break; } num++; } } if (flag3 || !item3.fullListTranslationAllowed) { if (englishList == null) { continue; } int num2 = -1; foreach (string item5 in englishList) { num2++; string text = item3.normalizedPath + "." + num2; string suggestedPath2 = item3.suggestedPath + "." + num2; if (TKeySystem.TrySuggestTKeyPath(text, out var tKeyPath)) { suggestedPath2 = tKeyPath; } if (!dictionary.TryGetValue(text, out var value)) { value = null; } if (value == null && !DefInjectionUtility.ShouldCheckMissingInjection(item5, item3.fieldInfo, item3.def)) { continue; } flag2 = true; flag = true; try { if (!item5.NullOrEmpty()) { xElement.Add(new XComment(SanitizeXComment(" EN: " + item5.Replace("\n", "\\n") + " "))); } } catch (Exception ex) { Log.Error("Could not add comment node in " + fileName + ": " + ex); } xElement.Add(GetDefInjectableFieldNode(suggestedPath2, value)); } continue; } bool flag4 = false; if (englishList != null) { foreach (string item6 in englishList) { if (DefInjectionUtility.ShouldCheckMissingInjection(item6, item3.fieldInfo, item3.def)) { flag4 = true; break; } } } if (!dictionary.TryGetValue(item3.normalizedPath, out var value2)) { value2 = null; } if (value2 == null && !flag4) { continue; } flag2 = true; flag = true; try { string text2 = ListToLiNodesString(englishList); if (!text2.NullOrEmpty()) { xElement.Add(new XComment(SanitizeXComment(" EN:\n" + text2.Indented() + "\n "))); } } catch (Exception ex2) { Log.Error("Could not add comment node in " + fileName + ": " + ex2); } xElement.Add(GetDefInjectableFieldNode(item3.suggestedPath, value2)); continue; } if (!dictionary.TryGetValue(item3.normalizedPath, out var value3)) { value3 = null; } string text3 = ((value3 != null && value3.injected) ? value3.replacedString : item3.curValue); if (value3 == null && !DefInjectionUtility.ShouldCheckMissingInjection(text3, item3.fieldInfo, item3.def)) { continue; } flag2 = true; flag = true; try { if (!text3.NullOrEmpty()) { xElement.Add(new XComment(SanitizeXComment(" EN: " + text3.Replace("\n", "\\n") + " "))); } } catch (Exception ex3) { Log.Error("Could not add comment node in " + fileName + ": " + ex3); } xElement.Add(GetDefInjectableFieldNode(item3.suggestedPath, value3)); } if (flag2) { xElement.Add(new XComment("NEWLINE")); } } if (!enumerable2.Any()) { continue; } flag = true; xElement.Add(new XComment(" UNUSED ")); foreach (KeyValuePair <string, DefInjectionPackage.DefInjection> item7 in enumerable2) { xElement.Add(GetDefInjectableFieldNode(item7.Value.path, item7.Value)); } xElement.Add(new XComment("NEWLINE")); } catch (Exception ex4) { Log.Error("Could not process def-injections for def " + defName + ": " + ex4); } } } finally { if (flag) { string text4 = Path.Combine(defInjectionsFolderPath, defType.Name); Directory.CreateDirectory(text4); SaveXMLDocumentWithProcessedNewlineTags(xDocument, Path.Combine(text4, fileName)); } } } catch (Exception ex5) { Log.Error("Could not process def-injections for file " + fileName + ": " + ex5); } } }
public static void ForEachPossibleDefInjection(Type defType, PossibleDefInjectionTraverser action, ModMetaData onlyFromMod = null) { foreach (Def item in GenDefDatabase.GetAllDefsInDatabaseForDef(defType)) { if (onlyFromMod == null || (item.modContentPack != null && !(item.modContentPack.PackageId != onlyFromMod.PackageId))) { ForEachPossibleDefInjectionInDef(item, action); } } }
public static bool IsActive(ModMetaData mod) { return(IsActive(mod.PackageId)); }