Advertisement
Guest User

code.css

a guest
Feb 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1.  
  2. //Should be Dialog_LoadTransporters but no override of PostClose
  3. //[HarmonyPatch(typeof(Window), "PostClose")]
  4. public static class PodsSaveManifest
  5. {
  6. public static FieldInfo transferablesInfo = AccessTools.Field(typeof(Dialog_LoadTransporters), "transferables");
  7. public static List<TransferableOneWay> Transferables(this Dialog_LoadTransporters dialog) =>
  8. (List<TransferableOneWay>)transferablesInfo.GetValue(dialog);
  9.  
  10. //This should also be 'Map ___map' but THE PATCH IS NOT ACTUALLY Dialog_LoadTransporters NOW IS IT?
  11. public static FieldInfo mapInfo = AccessTools.Field(typeof(Dialog_LoadTransporters), "map");
  12. public static Map Map(this Dialog_LoadTransporters dialog) =>
  13. (Map)mapInfo.GetValue(dialog);
  14.  
  15. public static void Prefix(Window __instance)
  16. {
  17. if (__instance is Dialog_LoadTransporters dialog)
  18. {
  19. if (!Settings.Get().caravanSaveManifest) return;
  20.  
  21. SaveManifest.caravan = false;
  22. SaveManifest.savedManifest = new List<ThingCountUNLIMITED>();
  23.  
  24. foreach (TransferableOneWay tr in dialog.Transferables())
  25. {
  26. if (tr.CountToTransfer > 0)
  27. {
  28. Log.Message($"Saving {tr.AnyThing}:{tr.CountToTransfer}");
  29. SaveManifest.savedManifest.Add(new ThingCountUNLIMITED(tr.AnyThing, tr.CountToTransfer));
  30. }
  31. }
  32.  
  33. if (SaveManifest.savedManifest.Count == 0)
  34. {
  35. SaveManifest.savedManifest = null;
  36. SaveManifest.savedMap = null;
  37. }
  38. else
  39. SaveManifest.savedMap = dialog.Map();
  40. }
  41. }
  42. }
  43.  
  44.  
  45. //[HarmonyPatch(typeof(Dialog_LoadTransporters), "PostOpen")]
  46. static class PodsLoadManifest
  47. {
  48. public static void Postfix(Dialog_LoadTransporters __instance, Map ___map)
  49. {
  50. //Add manifest
  51. if (Settings.Get().caravanSaveManifest && !SaveManifest.caravan &&
  52. ___map == SaveManifest.savedMap && SaveManifest.savedMap != null)
  53. {
  54. foreach (ThingCountUNLIMITED thingCount in SaveManifest.savedManifest)
  55. {
  56. Log.Message($"Loading {thingCount.thing}:{thingCount.count}");
  57. TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatching<TransferableOneWay>(thingCount.thing, __instance.Transferables(), TransferAsOneMode.PodsOrCaravanPacking);
  58. transferableOneWay?.AdjustTo(transferableOneWay.ClampAmount(transferableOneWay.CountToTransfer + thingCount.count));
  59. }
  60. }
  61. //No selection like caravans - you're already selecting pods!
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement