using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Harmony; using Verse; namespace ZPatches { [HarmonyPatch (typeof (ModContentPack))] [HarmonyPatch ("LoadDefs")] [HarmonyPatch (new Type [] { typeof (IEnumerable) })] public static class ModContentPack_Patch { static FieldInfo defPackagesField = AccessTools.Field (typeof (ModContentPack), "defPackages"); public static bool Prefix (ModContentPack __instance, IEnumerable patches) { DeepProfiler.Start ("Loading all defs"); List list = DirectXmlLoader.XmlAssetsInModFolder (__instance, "Defs/").ToList (); foreach (LoadableXmlAsset current in list) { foreach (PatchOperation current2 in patches) { current2.Apply (current.xmlDoc); } } DumpXML (list); for (int i = 0; i < list.Count; i++) { XmlInheritance.TryRegisterAllFrom (list [i], __instance); } XmlInheritance.Resolve (); for (int j = 0; j < list.Count; j++) { string relFolder = GenFilePaths.FolderPathRelativeToDefsFolder (list [j].fullFolderPath, __instance); DefPackage defPackage = new DefPackage (list [j].name, relFolder); foreach (Def current3 in DirectXmlLoader.AllDefsFromAsset (list [j])) { defPackage.defs.Add (current3); } var defPackages = defPackagesField.GetValue (__instance) as List; defPackages.Add (defPackage); } DeepProfiler.End (); return false; } public static void DumpXML(List list) { Log.Message ("> " + list.Count); foreach (var asset in list) { Log.Message ("\t" + asset.name); } } } }