public static (IEnumerable <DefXMLNode> nodes, IEnumerable <string> loadingErrors) LoadUpdateFeatureDefNodes() { var nodes = new List <DefXMLNode>(); var loadingErrors = new List <string>(0); foreach (var modContentPack in LoadedModManager.RunningMods) { try { var modNewsXmlAssets = DirectXmlLoader.XmlAssetsInModFolder(modContentPack, UpdateFeatureManager.UpdateFeatureDefFolder); foreach (var xmlAsset in modNewsXmlAssets) { var rootElement = xmlAsset.xmlDoc?.DocumentElement; if (rootElement != null) { foreach (var childNode in rootElement.ChildNodes.OfType <XmlNode>()) { nodes.Add(new DefXMLNode(modContentPack, childNode, xmlAsset)); } } } } catch (Exception e) { loadingErrors.Add("Failed to load UpdateFeatureDefs for mod " + $"{modContentPack.PackageIdPlayerFacing}: {e}"); } } return(nodes, loadingErrors); }
internal static void Work() { var mod = LoadedModManager.RunningMods.First(m => m.Name == "No Water, No Life."); CreateCompatibilityXml(mod); var list = DirectXmlLoader.XmlAssetsInModFolder(mod, DirectoryName + @"\").ToList <LoadableXmlAsset>(); foreach (var item in list) { if (item == null || item.xmlDoc == null || item.xmlDoc.DocumentElement == null) { Log.Error(string.Format("{0}: unknown parse failure", item.fullFolderPath + @"\" + item.name)); } else if (item.xmlDoc.DocumentElement.Name != "Defs") { Log.Error(string.Format("{0}: root element named {1}; should be named Defs", item.fullFolderPath + @"\" + item.name, item.xmlDoc.DocumentElement.Name)); } XmlInheritance.TryRegisterAllFrom(item, mod); } XmlInheritance.Resolve(); foreach (var item in list) { foreach (Def def in DirectXmlLoader.AllDefsFromAsset(item)) { Log.Message($"Added def {def.defName}"); DefDatabase <ThinkTreeDef> .Add(def as ThinkTreeDef); } } foreach (var def in DefDatabase <ThinkTreeDef> .AllDefs.Where(d => d.insertTag == "Humanlike_PostDuty").OrderByDescending(d => d.insertPriority)) { Log.Message($" ThinkTree {def.defName}"); } }
private static void LoadSaveGamePatchesFor(ModContentPack mod) //Taken from Verse.ModContentPack.LoadPatches() { List <LoadableXmlAsset> list = DirectXmlLoader.XmlAssetsInModFolder(mod, "SaveGamePatches/").ToList <LoadableXmlAsset> (); for (int i = 0; i < list.Count; i++) { XmlElement documentElement = list [i].xmlDoc.DocumentElement; if (documentElement.Name != "Patch") { Log.Error(string.Format("Unexpected document element in patch XML; got {0}, expected 'Patch'", documentElement.Name)); } else { for (int j = 0; j < documentElement.ChildNodes.Count; j++) { XmlNode xmlNode = documentElement.ChildNodes [j]; if (xmlNode.NodeType == XmlNodeType.Element) { if (xmlNode.Name != "Operation") { Log.Error(string.Format("Unexpected element in patch XML; got {0}, expected 'Operation'", documentElement.ChildNodes [j].Name)); } else { PatchOperation patchOperation = DirectXmlToObject.ObjectFromXml <PatchOperation> (xmlNode, false); patchOperation.sourceFile = list [i].FullFilePath; SaveGamePatches.patches.Add(patchOperation); } } } } } }
internal static SettingsPSI LoadPSISettings([NotNull] string path = "ColonistBar_PSIKF.xml") { string configFolder = Path.GetDirectoryName(GenFilePaths.ModsConfigFilePath); SettingsPSI __result = DirectXmlLoader.ItemFromXmlFile <SettingsPSI>(configFolder + "/" + path); return(__result); }
public static void LoadAllBios() { foreach (PawnBio pawnBio in DirectXmlLoader.LoadXmlDataInResourcesFolder <PawnBio>("Backstories/Solid")) { pawnBio.name.ResolveMissingPieces(null); if (pawnBio.childhood == null || pawnBio.adulthood == null) { PawnNameDatabaseSolid.AddPlayerContentName(pawnBio.name, pawnBio.gender); } else { pawnBio.PostLoad(); pawnBio.ResolveReferences(); foreach (string text in pawnBio.ConfigErrors()) { Log.Error(text, false); } SolidBioDatabase.allBios.Add(pawnBio); pawnBio.childhood.shuffleable = false; pawnBio.childhood.slot = BackstorySlot.Childhood; pawnBio.adulthood.shuffleable = false; pawnBio.adulthood.slot = BackstorySlot.Adulthood; BackstoryHardcodedData.InjectHardcodedData(pawnBio); BackstoryDatabase.AddBackstory(pawnBio.childhood); BackstoryDatabase.AddBackstory(pawnBio.adulthood); } } }
public static void LoadAllBios() { foreach (PawnBio item in DirectXmlLoader.LoadXmlDataInResourcesFolder <PawnBio>("Backstories/Solid")) { item.name.ResolveMissingPieces(null); if (item.childhood == null || item.adulthood == null) { PawnNameDatabaseSolid.AddPlayerContentName(item.name, item.gender); } else { item.PostLoad(); item.ResolveReferences(); foreach (string item2 in item.ConfigErrors()) { Log.Error(item2); } SolidBioDatabase.allBios.Add(item); item.childhood.shuffleable = false; item.childhood.slot = BackstorySlot.Childhood; item.adulthood.shuffleable = false; item.adulthood.slot = BackstorySlot.Adulthood; BackstoryHardcodedData.InjectHardcodedData(item); BackstoryDatabase.AddBackstory(item.childhood); BackstoryDatabase.AddBackstory(item.adulthood); } } }
public static PersistentXmlSettings LoadDefaultSettings() { var xmlSettings = new PersistentXmlSettings(); var settingsXmls = new List <LoadableXmlAsset>(); foreach (ModContentPack modContentPack in LoadedModManager.RunningMods) { settingsXmls.AddRange(DirectXmlLoader.XmlAssetsInModFolder(modContentPack, "XmlSettings/") .ToList()); } foreach (var asset in settingsXmls) { string modName; XmlModSettings modSettings; modName = asset.mod.Identifier; using (var reader = File.OpenText(asset.FullFilePath)) { modSettings = XmlSettingsSerializer.DeserializeModSettings(reader); } xmlSettings.ModSettings[modName] = modSettings; } return(xmlSettings); }
public async void FetchManifest(string manifestUri) { var client = new WebClient(); try { downloading = true; var raw = await client.DownloadStringTaskAsync(manifestUri); onlineManifest = DirectXmlLoader.ItemFromXmlString <Manifest>(raw, manifestUri); } catch (WebException ex) { exception = ex; if (Prefs.DevMode) { Log.Warning($"Failed to fetch {manifestUri} ({ex.Status}:\n{ex.Message}"); } } catch (Exception ex) { exception = ex; Log.Error($"Exception fetching {manifestUri}:\n{ex}"); } finally { downloading = false; completed = true; client.Dispose(); } }
public static void LoadAllBios() { foreach (PawnBio current in DirectXmlLoader.LoadXmlDataInResourcesFolder <PawnBio>("Backstories/Solid")) { current.name.ResolveMissingPieces(null); if (current.childhood == null || current.adulthood == null) { PawnNameDatabaseSolid.AddPlayerContentName(current.name, current.gender); } else { current.PostLoad(); current.ResolveReferences(); foreach (string current2 in current.ConfigErrors()) { Log.Error(current2, false); } SolidBioDatabase.allBios.Add(current); current.childhood.shuffleable = false; current.childhood.slot = BackstorySlot.Childhood; current.adulthood.shuffleable = false; current.adulthood.slot = BackstorySlot.Adulthood; BackstoryHardcodedData.InjectHardcodedData(current); BackstoryDatabase.AddBackstory(current.childhood); BackstoryDatabase.AddBackstory(current.adulthood); } } }
private void Load() { if (File.Exists(filepath)) { this.modSettings = DirectXmlLoader.ItemFromXmlFile <SaveableSettings>(filepath, true); } }
public static void Init() { var flag = !new FileInfo(prefsFilePath).Exists; data = new BadPeoplePerfsData(); data = DirectXmlLoader.ItemFromXmlFile <BadPeoplePerfsData>(prefsFilePath, true); }
public static void Init() { var flag = !new FileInfo(prefsFilePath).Exists; data = new PrisonLaborPrefsData(); data = DirectXmlLoader.ItemFromXmlFile <PrisonLaborPrefsData>(prefsFilePath, true); Apply(); }
public static void ReloadAndRebind() { data = DirectXmlLoader.ItemFromXmlFile <ConceptKnowledge>(GenFilePaths.ConceptKnowledgeFilePath); foreach (ConceptDef allDef in DefDatabase <ConceptDef> .AllDefs) { if (!data.knowledge.ContainsKey(allDef.defName)) { Log.Warning("Knowledge data was missing key " + allDef + ". Adding it..."); data.knowledge.Add(allDef.defName, 0f); } } }
public static void ReloadAndRebind() { PlayerKnowledgeDatabase.data = DirectXmlLoader.ItemFromXmlFile <PlayerKnowledgeDatabase.ConceptKnowledge>(GenFilePaths.ConceptKnowledgeFilePath, true); foreach (ConceptDef current in DefDatabase <ConceptDef> .AllDefs) { if (!PlayerKnowledgeDatabase.data.knowledge.ContainsKey(current)) { Log.Warning("Knowledge data was missing key " + current + ". Adding it...", false); PlayerKnowledgeDatabase.data.knowledge.Add(current, 0f); } } }
public static bool Prefix() { if (REB_Initializer.REB_Backstories.Count < 1) { return(true); } foreach (PawnBio pawnBio in DirectXmlLoader.LoadXmlDataInResourcesFolder <PawnBio>("Backstories/Solid")) { pawnBio.name.ResolveMissingPieces(null); PawnNameDatabaseSolid.AddPlayerContentName(pawnBio.name, pawnBio.gender); } return(false); }
public static void ReloadAllBackstories() { foreach (Backstory current in DirectXmlLoader.LoadXmlDataInResourcesFolder <Backstory>("Backstories/Shuffled")) { current.PostLoad(); current.ResolveReferences(); foreach (string current2 in current.ConfigErrors(false)) { Log.Error(current.Title + ": " + current2); } BackstoryDatabase.AddBackstory(current); } SolidBioDatabase.LoadAllBios(); }
public static void ReloadAllBackstories() { foreach (Backstory backstory in DirectXmlLoader.LoadXmlDataInResourcesFolder <Backstory>("Backstories/Shuffled")) { backstory.PostLoad(); backstory.ResolveReferences(); foreach (string str in backstory.ConfigErrors(false)) { Log.Error(backstory.title + ": " + str, false); } BackstoryDatabase.AddBackstory(backstory); } SolidBioDatabase.LoadAllBios(); }
public static void ReloadAllBackstories() { foreach (Backstory item in DirectXmlLoader.LoadXmlDataInResourcesFolder <Backstory>("Backstories/Shuffled")) { item.PostLoad(); item.ResolveReferences(); foreach (string item2 in item.ConfigErrors(false)) { Log.Error(item.Title + ": " + item2); } BackstoryDatabase.AddBackstory(item); } SolidBioDatabase.LoadAllBios(); }
private static IEnumerable <UpdateFeatureDef> ResolveUpdateFeatureDefsFromNodes(IEnumerable <DefXMLNode> nodes) { // The following replicates most of the vanilla Def loading mechanism, albeit without patches. // Patch metadata has already been cleared, and parsing it again would add too much overhead. // Def resolution can't be offloaded to a worker thread, since XmlInheritance is not thread safe. var defNodes = nodes.ToArray(); // register for inheritance XmlInheritance.Clear(); foreach (var(modContent, node, _) in defNodes) { if (node != null && node.NodeType == XmlNodeType.Element) { XmlInheritance.TryRegister(node, modContent); } } XmlInheritance.Resolve(); // resolve defs from nodes var resolvedDefs = new List <UpdateFeatureDef>(); foreach (var(pack, node, asset) in defNodes) { try { var def = DirectXmlLoader.DefFromNode(node, asset) as UpdateFeatureDef; if (def != null) { def.modContentPack = pack; def.ResolveReferences(); resolvedDefs.Add(def); } } catch (Exception e) { HugsLibController.Logger.Error( $"Failed to parse UpdateFeatureDef from mod {pack.PackageIdPlayerFacing}:\n" + $"{GetExceptionChainMessage(e)}\n" + $"Context: {node?.OuterXml.ToStringSafe()}\n" + $"File: {asset?.FullFilePath.ToStringSafe()}\n" + $"Exception: {e}"); } } XmlInheritance.Clear(); return(resolvedDefs); }
static bool Prefix(XmlDocument xmlDoc, Dictionary <XmlNode, LoadableXmlAsset> assetlookup) { XmlNodeList childNodes = xmlDoc.DocumentElement.ChildNodes; foreach (XmlNode n in childNodes) { if (n.NodeType == XmlNodeType.Element) { LoadableXmlAsset loadableXmlAsset = assetlookup.TryGetValue(n, null); XmlInheritance.TryRegister(n, (loadableXmlAsset == null) ? null : loadableXmlAsset.mod); } } XmlInheritance.Resolve(); DefPackage defPackage = new DefPackage("Unknown", string.Empty); ModContentPack modContentPack = LoadedModManager.RunningMods.FirstOrFallback <ModContentPack>(); modContentPack.AddDefPackage(defPackage); IEnumerator enumerator = xmlDoc.DocumentElement.ChildNodes.GetEnumerator(); try { while (enumerator.MoveNext()) { XmlNode xmlNode = (XmlNode)enumerator.Current; LoadableXmlAsset loadableXmlAsset2 = assetlookup.TryGetValue(xmlNode, null); DefPackage defPackage2 = (loadableXmlAsset2 == null) ? defPackage : loadableXmlAsset2.defPackage; Def def = DirectXmlLoader.DefFromNode(xmlNode, loadableXmlAsset2); if (def != null) { def.modContentPack = ((loadableXmlAsset2 == null) ? modContentPack : loadableXmlAsset2.mod); defPackage2.AddDef(def); } } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } return(false); }
public void LoadModCheckPatches() { DeepProfiler.Start("Loading all ModCheck patches"); this.patches = new List <PatchOperation>(); int modIndex = -1; foreach (ModContentPack mod in LoadedModManager.RunningMods) { ++modIndex; List <LoadableXmlAsset> list = DirectXmlLoader.XmlAssetsInModFolder(mod, "ModCheckPatches/").ToList <LoadableXmlAsset>(); for (int i = 0; i < list.Count; i++) { XmlElement documentElement = list[i].xmlDoc.DocumentElement; if (documentElement.Name != "Patch") { Log.Error(string.Format("Unexpected document element in patch XML; got {0}, expected 'Patch'", documentElement.Name), false); } else { for (int j = 0; j < documentElement.ChildNodes.Count; j++) { XmlNode xmlNode = documentElement.ChildNodes[j]; if (xmlNode.NodeType == XmlNodeType.Element) { if (xmlNode.Name != "Operation") { Log.Error(string.Format("Unexpected element in patch XML; got {0}, expected 'Operation'", documentElement.ChildNodes[j].Name), false); } else { PatchOperation patchOperation = DirectXmlToObject.ObjectFromXml <PatchOperation>(xmlNode, false); patchOperation.sourceFile = list[i].FullFilePath; this.patches.Add(patchOperation); PatchMemory.Add(new PatchMemoryModule(modIndex, mod.Name, patchOperation, true)); } } } } } } DeepProfiler.End(); }
private static ContainerRow ParseSettingRows(ModContentPack content) { var r = new ContainerRow(); var xmlDoc = DirectXmlLoader.XmlAssetsInModFolder(content, "Settings")?.Where(x => x.name == "Settings.xml")?.ToList().FirstOrDefault(); if (xmlDoc == null || xmlDoc.xmlDoc == null) { Log.Error("Settings/Settings.xml not found or invalid xml."); return(r); } var rootElem = xmlDoc.xmlDoc.DocumentElement; if (rootElem.Name != "SettingRows") { Log.Error("SettingRows not found. name=" + rootElem.Name); return(r); } r.Rows.LoadDataFromXmlCustom(rootElem); return(r); }
static bool Prefix(Verse.ModContentPack __instance) { DeepProfiler.Start("Loading all patches"); List <PatchOperation> lst = new List <PatchOperation>(); typeof(ModContentPack).GetField("patches", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance) .SetValue(__instance, lst); List <LoadableXmlAsset> list = DirectXmlLoader.XmlAssetsInModFolder(__instance, "Patches/").ToList <LoadableXmlAsset>(); for (int i = 0; i < list.Count; i++) { XmlElement documentElement = list[i].xmlDoc.DocumentElement; if (documentElement.Name != "Patch") { Log.Error(string.Format("Unexpected document element in patch XML; got {0}, expected 'Patch'", documentElement.Name), false); } else { foreach (XmlNode xmlNode in documentElement.ChildNodes) { if (xmlNode.NodeType == XmlNodeType.Element) { if (xmlNode.Name != "Operation") { Log.Error(string.Format("Unexpected element in patch XML; got {0}, expected 'Operation'", xmlNode.Name), false); } else { PatchOperation patchOperation = DirectXmlToObject.ObjectFromXml <PatchOperation>(xmlNode, false); patchOperation.sourceFile = list[i].FullFilePath; lst.Add(patchOperation); } } } } } DeepProfiler.End(); return(false); }
public static bool Prefix() { PawnBioAndBacktoryUtility.duplicateCount = new Dictionary <string, int>(); PawnBioAndBacktoryUtility.pendingResolveNames = new Dictionary <string, NameTriple>(); foreach (PawnBio curPawnBio in DirectXmlLoader.LoadXmlDataInResourcesFolder <PawnBio>("Backstories/Solid")) { string curDefName = curPawnBio.name.ToDefName(curPawnBio.gender); if (PawnBioAndBacktoryUtility.duplicateCount.ContainsKey(curDefName)) { PawnBioAndBacktoryUtility.duplicateCount[curDefName]++; curDefName += "_" + PawnBioAndBacktoryUtility.duplicateCount[curDefName]; } else { PawnBioAndBacktoryUtility.duplicateCount.Add(curDefName, 0); } PawnBioAndBacktoryUtility.pendingResolveNames.Add(curDefName, curPawnBio.name); if (curPawnBio.childhood == null || curPawnBio.adulthood == null) { PawnNameDatabaseSolid.AddPlayerContentName(curPawnBio.name, curPawnBio.gender); } else { curPawnBio.PostLoad(); curPawnBio.ResolveReferences(); foreach (string curError in curPawnBio.ConfigErrors()) { Log.Error(curError); } SolidBioDatabase.allBios.Add(curPawnBio); curPawnBio.childhood.shuffleable = false; curPawnBio.childhood.slot = BackstorySlot.Childhood; BackstoryDatabase.AddBackstory(curPawnBio.childhood); curPawnBio.adulthood.shuffleable = false; curPawnBio.adulthood.slot = BackstorySlot.Adulthood; BackstoryDatabase.AddBackstory(curPawnBio.adulthood); } } return(false); }
public static void ReloadAllBackstories() { foreach (Backstory item in DirectXmlLoader.LoadXmlDataInResourcesFolder <Backstory>("Backstories/Shuffled")) { DeepProfiler.Start("Backstory.PostLoad"); try { item.PostLoad(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Backstory.ResolveReferences"); try { item.ResolveReferences(); } finally { DeepProfiler.End(); } foreach (string item2 in item.ConfigErrors(ignoreNoSpawnCategories: false)) { Log.Error(item.title + ": " + item2); } DeepProfiler.Start("AddBackstory"); try { AddBackstory(item); } finally { DeepProfiler.End(); } } SolidBioDatabase.LoadAllBios(); }
// Load from XML file Settings/SpecialSculpture.xml; called from ModComponent static public List <SpecialSculpture> LoadAvailableSpecialSculptures(ModContentPack content) { try { var xml = DirectXmlLoader.XmlAssetsInModFolder(content, "Settings")?. Where(x => x.name == "SpecialSculpture.xml")?.FirstOrDefault(); if (xml == null || xml.xmlDoc == null) { Log.Warning("PRF could not load special sculpture data"); return(null); } List <SpecialSculpture> list = DirectXmlToObject .ObjectFromXml <List <SpecialSculpture> >(xml.xmlDoc.DocumentElement, false); #if DEBUG Log.Message("PRF: loaded " + ((list == null) ? "zero" : (list.Count.ToString())) + " special Sculptures"); #endif return(list); } catch (Exception e) { Log.Error("PRF was unable to extract Special Sculpture data from XML; \n" + " Exception: " + e); return(null); } }
internal static ModsConfigData ReadModList(string filepath) { return(DirectXmlLoader.ItemFromXmlFile <ModsConfigData>(filepath, true)); }
public static Manifest For(ModMetaData mod) { Manifest manifest; if (_manifestCache.TryGetValue(mod, out manifest)) { return(manifest); } manifest = new Manifest(); manifest.mod = mod; // get from file. var manifestPath = Path.Combine(mod.AboutDir(), ManifestFileName); var modsyncPath = Path.Combine(mod.AboutDir(), ModSyncFileName); // manifest is first choice if (File.Exists(manifestPath)) { try { manifest = DirectXmlLoader.ItemFromXmlFile <Manifest>(manifestPath); manifest.mod = mod; manifest.dependencies.ForEach(d => d.Owner = manifest); manifest.loadBefore.ForEach(d => d.Owner = manifest); manifest.loadAfter.ForEach(d => d.Owner = manifest); if (!manifest.manifestUri.NullOrEmpty()) { try { manifest.ManifestUri = new Uri(manifest.manifestUri); } catch (Exception e) { Log.Warning($"Error parsing manifestUri: {e.Message}\n\n{e.StackTrace}"); } } if (!manifest.targetVersions.NullOrEmpty()) { manifest.TargetVersions = new List <Version>(); foreach (var targetVersion in manifest.targetVersions) { manifest.TargetVersions.Add(manifest.ParseVersion(targetVersion)); } } } catch (Exception e) { manifest = new Manifest(mod); Log.Error($"Error loading manifest for '{mod.Name}':\n{e.Message}\n\n{e.StackTrace}"); } } // modsync manifest can provide some info else if (File.Exists(modsyncPath)) { try { ModSync modsync = DirectXmlLoader.ItemFromXmlFile <ModSync>(modsyncPath); manifest = modsync.Manifest(mod); } catch (Exception e) { manifest = new Manifest(mod); Log.Error($"Error loading ModSync into manifest for '{mod.Name}': {e.Message}\n\n{e.StackTrace}"); } } // resolve version - if set in manifest or modsync that takes priority, // otherwise try to read version from assemblies. manifest.SetVersion(); _manifestCache.Add(mod, manifest); return(manifest); }
private static IEnumerable <UpdateFeatureDef> LoadAndParseNewsFeatureDefs() { XmlInheritance.Clear(); // As we're moving the updates out of /Defs and into /News, we can no longer rely on the DefDatabase to magically // load all the UpdateFeatureDefs. Instead, we'll have to manually point the reader to the relevant folders. // Overall, we'll stick as much as we can to the vanilla def loading experience, albeit without patches. // Patch metadata has already been cleared, and parsing it again would add too much overhead. // First, gather all XML nodes that represent an UpdateFeatureDef, and remember where they came from // We can't parse them info defs on the spot, because there is inheritance to consider. var newsItemNodes = new List <(ModContentPack pack, XmlNode node, LoadableXmlAsset asset)>(); foreach (var modContentPack in LoadedModManager.RunningMods) { try { var modNewsXmlAssets = DirectXmlLoader.XmlAssetsInModFolder(modContentPack, UpdateFeatureDefFolder); foreach (var xmlAsset in modNewsXmlAssets) { var rootElement = xmlAsset.xmlDoc?.DocumentElement; if (rootElement != null) { foreach (var childNode in rootElement.ChildNodes.OfType <XmlNode>()) { newsItemNodes.Add((modContentPack, childNode, xmlAsset)); } } } } catch (Exception e) { HugsLibController.Logger.Error("Failed to load UpdateFeatureDefs for mod " + $"{modContentPack.PackageIdPlayerFacing}: {e}"); throw; } } // deal with inheritance foreach (var(modContent, node, _) in newsItemNodes) { if (node != null && node.NodeType == XmlNodeType.Element) { XmlInheritance.TryRegister(node, modContent); } } XmlInheritance.Resolve(); var parsedFeatureDefs = new List <UpdateFeatureDef>(); foreach (var(pack, node, asset) in newsItemNodes) { // parse defs try { var def = DirectXmlLoader.DefFromNode(node, asset) as UpdateFeatureDef; if (def != null) { def.modContentPack = pack; def.ResolveReferences(); parsedFeatureDefs.Add(def); } } catch (Exception e) { HugsLibController.Logger.Error($"Failed to parse UpdateFeatureDef from mod {pack.PackageIdPlayerFacing}:\n" + $"{GetExceptionChainMessage(e)}\n" + $"Context: {node?.OuterXml.ToStringSafe()}\n" + $"File: {asset?.FullFilePath.ToStringSafe()}\n" + $"Exception: {e}"); } } XmlInheritance.Clear(); return(parsedFeatureDefs); }
/// <summary> /// Gets an object from an xml file /// </summary> /// <typeparam name="T">The object type</typeparam> /// <param name="filepath">The xml file path</param> /// <param name="resolveCrossRefs">Set true to resolve cross refs[Optional](Default:false)</param> /// <returns></returns> public static T ItemFromXmlFile <T>(string filepath, bool resolveCrossRefs = false) where T : new() { return(DirectXmlLoader.ItemFromXmlFile <T>(filepath, resolveCrossRefs)); }