Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Should be Dialog_LoadTransporters but no override of PostClose
- //[HarmonyPatch(typeof(Window), "PostClose")]
- public static class PodsSaveManifest
- {
- public static FieldInfo transferablesInfo = AccessTools.Field(typeof(Dialog_LoadTransporters), "transferables");
- public static List<TransferableOneWay> Transferables(this Dialog_LoadTransporters dialog) =>
- (List<TransferableOneWay>)transferablesInfo.GetValue(dialog);
- //This should also be 'Map ___map' but THE PATCH IS NOT ACTUALLY Dialog_LoadTransporters NOW IS IT?
- public static FieldInfo mapInfo = AccessTools.Field(typeof(Dialog_LoadTransporters), "map");
- public static Map Map(this Dialog_LoadTransporters dialog) =>
- (Map)mapInfo.GetValue(dialog);
- public static void Prefix(Window __instance)
- {
- if (__instance is Dialog_LoadTransporters dialog)
- {
- if (!Settings.Get().caravanSaveManifest) return;
- SaveManifest.caravan = false;
- SaveManifest.savedManifest = new List<ThingCountUNLIMITED>();
- foreach (TransferableOneWay tr in dialog.Transferables())
- {
- if (tr.CountToTransfer > 0)
- {
- Log.Message($"Saving {tr.AnyThing}:{tr.CountToTransfer}");
- SaveManifest.savedManifest.Add(new ThingCountUNLIMITED(tr.AnyThing, tr.CountToTransfer));
- }
- }
- if (SaveManifest.savedManifest.Count == 0)
- {
- SaveManifest.savedManifest = null;
- SaveManifest.savedMap = null;
- }
- else
- SaveManifest.savedMap = dialog.Map();
- }
- }
- }
- //[HarmonyPatch(typeof(Dialog_LoadTransporters), "PostOpen")]
- static class PodsLoadManifest
- {
- public static void Postfix(Dialog_LoadTransporters __instance, Map ___map)
- {
- //Add manifest
- if (Settings.Get().caravanSaveManifest && !SaveManifest.caravan &&
- ___map == SaveManifest.savedMap && SaveManifest.savedMap != null)
- {
- foreach (ThingCountUNLIMITED thingCount in SaveManifest.savedManifest)
- {
- Log.Message($"Loading {thingCount.thing}:{thingCount.count}");
- TransferableOneWay transferableOneWay = TransferableUtility.TransferableMatching<TransferableOneWay>(thingCount.thing, __instance.Transferables(), TransferAsOneMode.PodsOrCaravanPacking);
- transferableOneWay?.AdjustTo(transferableOneWay.ClampAmount(transferableOneWay.CountToTransfer + thingCount.count));
- }
- }
- //No selection like caravans - you're already selecting pods!
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement