Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions Source/ProjectRimFactory/Common/ConditionalPatchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using RimWorld;
using Verse;
using Verse.AI;

Expand Down Expand Up @@ -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) }),
Expand All @@ -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)
Expand Down
48 changes: 8 additions & 40 deletions Source/ProjectRimFactory/Common/HarmonyPatches/PatchStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down