Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5.  
  6. using Harmony;
  7.  
  8. using Verse;
  9.  
  10. namespace ZPatches
  11. {
  12. [HarmonyPatch (typeof (ModContentPack))]
  13. [HarmonyPatch ("LoadDefs")]
  14. [HarmonyPatch (new Type [] { typeof (IEnumerable<PatchOperation>) })]
  15. public static class ModContentPack_Patch
  16. {
  17. static FieldInfo defPackagesField = AccessTools.Field (typeof (ModContentPack), "defPackages");
  18.  
  19. public static bool Prefix (ModContentPack __instance, IEnumerable<PatchOperation> patches)
  20. {
  21. DeepProfiler.Start ("Loading all defs");
  22. List<LoadableXmlAsset> list = DirectXmlLoader.XmlAssetsInModFolder (__instance, "Defs/").ToList<LoadableXmlAsset> ();
  23. foreach (LoadableXmlAsset current in list) {
  24. foreach (PatchOperation current2 in patches) {
  25. current2.Apply (current.xmlDoc);
  26. }
  27. }
  28. DumpXML (list);
  29. for (int i = 0; i < list.Count; i++) {
  30. XmlInheritance.TryRegisterAllFrom (list [i], __instance);
  31. }
  32. XmlInheritance.Resolve ();
  33. for (int j = 0; j < list.Count; j++) {
  34. string relFolder = GenFilePaths.FolderPathRelativeToDefsFolder (list [j].fullFolderPath, __instance);
  35. DefPackage defPackage = new DefPackage (list [j].name, relFolder);
  36. foreach (Def current3 in DirectXmlLoader.AllDefsFromAsset (list [j])) {
  37. defPackage.defs.Add (current3);
  38. }
  39. var defPackages = defPackagesField.GetValue (__instance) as List<DefPackage>;
  40. defPackages.Add (defPackage);
  41. }
  42. DeepProfiler.End ();
  43.  
  44. return false;
  45. }
  46.  
  47. public static void DumpXML(List<LoadableXmlAsset> list) {
  48. Log.Message ("> " + list.Count);
  49. foreach (var asset in list) {
  50. Log.Message ("\t" + asset.name);
  51. }
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement