be3dae46bb
Added RitualObligationTriggers analyzer category, Fixed defs from other mods with broken market value breaking fish's storage patches, Fixed storage caches not updating for quality, rotting and similar changes to stored things, Fixed storage caches not updating capacity when reinstalling storage, Fixed prison labor compatibility, Improved multiplayer compatibility, Fixed ideology style dominance and altar sharing patches throwing errors instead of defaulting to disabled when not having ideology, Fixed compatibility with RIMMSqol's world pawn GC patch by disabling that patch, Fixed rare threading issues throwing errors on startup
98 lines
3.3 KiB
C#
98 lines
3.3 KiB
C#
// Copyright (c) 2023 bradson
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
using PerformanceFish.Prepatching;
|
|
|
|
namespace PerformanceFish.Hauling;
|
|
|
|
public sealed class HaulDestinationManagerPatches : ClassWithFishPrepatches
|
|
{
|
|
public sealed class Notify_HaulDestinationChangedPriorityPatch : FishPrepatch
|
|
{
|
|
public override bool ShowSettings => false;
|
|
|
|
public override MethodBase TargetMethodBase { get; }
|
|
= AccessTools.DeclaredMethod(typeof(HaulDestinationManager),
|
|
nameof(HaulDestinationManager.Notify_HaulDestinationChangedPriority));
|
|
|
|
public static void Postfix(HaulDestinationManager __instance)
|
|
=> __instance.Cache().OnPriorityChanged(__instance);
|
|
}
|
|
|
|
public sealed class AddHaulDestinationPatch : FishPrepatch
|
|
{
|
|
public override bool ShowSettings => false;
|
|
|
|
public override MethodBase TargetMethodBase { get; }
|
|
= AccessTools.DeclaredMethod(typeof(HaulDestinationManager),
|
|
nameof(HaulDestinationManager.AddHaulDestination));
|
|
|
|
public static void Postfix(HaulDestinationManager __instance, IHaulDestination haulDestination)
|
|
{
|
|
if (haulDestination is not ISlotGroupParent slotGroupParent)
|
|
return;
|
|
|
|
__instance.Cache().OnPriorityChanged(__instance);
|
|
slotGroupParent.GetSlotGroup().NotifyCellCountChanged();
|
|
}
|
|
}
|
|
|
|
public sealed class RemoveHaulDestinationPatch : FishPrepatch
|
|
{
|
|
public override bool ShowSettings => false;
|
|
|
|
public override MethodBase TargetMethodBase { get; }
|
|
= AccessTools.DeclaredMethod(typeof(HaulDestinationManager),
|
|
nameof(HaulDestinationManager.RemoveHaulDestination));
|
|
|
|
public static void Postfix(HaulDestinationManager __instance, IHaulDestination haulDestination)
|
|
{
|
|
if (haulDestination is not ISlotGroupParent slotGroupParent)
|
|
return;
|
|
|
|
__instance.Cache().OnPriorityChanged(__instance);
|
|
slotGroupParent.GetSlotGroup().ResetDistricts();
|
|
}
|
|
}
|
|
|
|
public sealed class CompareSlotGroupPrioritiesDescendingPatch : FishPrepatch
|
|
{
|
|
public override List<Type> LinkedPatches { get; }
|
|
= [typeof(StoreUtilityPrepatches.TryFindBestBetterStoreCellForPatch)];
|
|
|
|
public override string? Description { get; }
|
|
= "Modifies storage sort order within the haul destination manager to put groups of linked storages first "
|
|
+ "within their priority, descending by size and then loadID. "
|
|
+ "StoreUtilityPrepatches:TryFindBestBetterStoreCellFor requires this";
|
|
|
|
public override MethodBase TargetMethodBase { get; }
|
|
= methodof(HaulDestinationManager.CompareSlotGroupPrioritiesDescending);
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static int Postfix(int __result, SlotGroup a, SlotGroup b)
|
|
{
|
|
if (__result != 0)
|
|
return __result;
|
|
|
|
var storageSettingsGroupA = a.TryGetStorageGroup();
|
|
var storageSettingsGroupB = b.TryGetStorageGroup();
|
|
|
|
return storageSettingsGroupA == null
|
|
? storageSettingsGroupB == null
|
|
? 0
|
|
: 1
|
|
: storageSettingsGroupB == null
|
|
? -1
|
|
: CompareStorageSettingsGroups(storageSettingsGroupA, storageSettingsGroupB);
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
|
public static int CompareStorageSettingsGroups(StorageGroup a, StorageGroup b)
|
|
{
|
|
var result = b.MemberCount.CompareTo(a.MemberCount);
|
|
return result != 0 ? result : a.loadID.CompareTo(b.loadID);
|
|
}
|
|
}
|
|
} |