diff --git a/Source/ProjectRimFactory/Common/ConditionalPatchHelper.cs b/Source/ProjectRimFactory/Common/ConditionalPatchHelper.cs index d307fe68..fb2c1179 100644 --- a/Source/ProjectRimFactory/Common/ConditionalPatchHelper.cs +++ b/Source/ProjectRimFactory/Common/ConditionalPatchHelper.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using RimWorld; using Verse; using Verse.AI; @@ -82,13 +83,9 @@ public void PatchHandler(bool patch) AccessTools.Method(typeof(RimWorld.FloatMenuMakerMap), "ChoicesAtFor", new Type[] { typeof(UnityEngine.Vector3), typeof(Pawn), typeof(bool) }), AccessTools.Method(typeof(ProjectRimFactory.Common.HarmonyPatches.Patch_FloatMenuMakerMap_ChoicesAtFor), "Prefix") ); - public static TogglePatch Patch_Building_Storage_Accepts = new TogglePatch( - AccessTools.Method(typeof(RimWorld.Building_Storage), "Accepts", new Type[] { typeof(Verse.Thing) }), - AccessTools.Method(typeof(ProjectRimFactory.Common.HarmonyPatches.Patch_Building_Storage_Accepts), "Prefix") - ); - public static TogglePatch Patch_StorageSettings_AllowedToAccept = new TogglePatch( - AccessTools.Method(typeof(RimWorld.StorageSettings), "AllowedToAccept", new Type[] { typeof(Verse.Thing) }), - AccessTools.Method(typeof(ProjectRimFactory.Common.HarmonyPatches.Patch_StorageSettings_AllowedToAccept), "Prefix") + public static TogglePatch Patch_StoreUtility_TryFindBestBetterStoreCellForWorker = new TogglePatch( + AccessTools.Method(typeof(RimWorld.StoreUtility), "TryFindBestBetterStoreCellForWorker"), + AccessTools.Method(typeof(ProjectRimFactory.Common.HarmonyPatches.Patch_StoreUtility_TryFindBestBetterStoreCellForWorker), "Prefix") ); public static TogglePatch Patch_ForbidUtility_IsForbidden = new TogglePatch( AccessTools.Method(typeof(RimWorld.ForbidUtility), "IsForbidden", new Type[] { typeof(Thing), typeof(Pawn) }), @@ -115,9 +112,8 @@ private static void updatePatchStorage() Patch_ThingWithComps_DrawGUIOverlay.PatchHandler(state); Patch_Thing_DrawGUIOverlay.PatchHandler(state); Patch_FloatMenuMakerMap_ChoicesAtFor.PatchHandler(state); - Patch_Building_Storage_Accepts.PatchHandler(state); Patch_ForbidUtility_IsForbidden.PatchHandler(state); - Patch_StorageSettings_AllowedToAccept.PatchHandler(state); + Patch_StoreUtility_TryFindBestBetterStoreCellForWorker.PatchHandler(state); } public static void Register(Building_MassStorageUnit building) diff --git a/Source/ProjectRimFactory/Common/HarmonyPatches/PatchStorage.cs b/Source/ProjectRimFactory/Common/HarmonyPatches/PatchStorage.cs index fad30724..3b693b53 100644 --- a/Source/ProjectRimFactory/Common/HarmonyPatches/PatchStorage.cs +++ b/Source/ProjectRimFactory/Common/HarmonyPatches/PatchStorage.cs @@ -28,49 +28,17 @@ static bool Prefix(Thing t, Pawn pawn, out bool __result) } } - // TODO Check if we still need that in 1.5 - class Patch_Building_Storage_Accepts + class Patch_StoreUtility_TryFindBestBetterStoreCellForWorker { - static bool Prefix(Building_Storage __instance, Thing t, out bool __result) + static bool Prefix(Thing t, Pawn carrier, Map map, Faction faction, ISlotGroup slotGroup, + bool needAccurateResult, ref IntVec3 closestSlot, ref float closestDistSquared, + ref StoragePriority foundPriority) { - __result = false; - //Check if pawn input is forbidden - if (!PatchStorageUtil.SkippAcceptsPatch && ((__instance as IForbidPawnInputItem)?.ForbidPawnInput ?? false)) - { - //#699 #678 - //This check is needed to support the use of the Limit function for the IO Ports - if (__instance.Position != t.Position) - { - return false; - } - } - return true; - } - } - - // 1.5 Stuff - class Patch_StorageSettings_AllowedToAccept - { - static bool Prefix(IStoreSettingsParent ___owner, Thing t, out bool __result) - { - __result = false; - if (___owner is Building_Storage storage) - { - //Check if pawn input is forbidden - if (!PatchStorageUtil.SkippAcceptsPatch && ((storage as IForbidPawnInputItem)?.ForbidPawnInput ?? false)) - { - //#699 #678 - //This check is needed to support the use of the Limit function for the IO Ports - if (storage.Position != t.Position) - { - return false; - } - } - } - - - return true; + if (slotGroup is not SlotGroup sg) return true; + if (sg.parent is not Building_Storage storage) return true; + return !((storage as IForbidPawnInputItem)?.ForbidPawnInput ?? false); } + } class Patch_FloatMenuMakerMap_ChoicesAtFor