Apply autostack FiR rules to Top Up action

This commit is contained in:
Tyfon
2024-05-28 14:56:54 -07:00
parent e5f18ec25d
commit cba5871671
2 changed files with 75 additions and 37 deletions

View File

@@ -8,7 +8,15 @@ using System.Reflection;
namespace UIFixes
{
public class StackFirItemsPatch : ModulePatch
public static class StackFirItemsPatches
{
public static void Enable()
{
new ContainerStackPatch().Enable();
new TopUpStackPatch().Enable();
}
public class ContainerStackPatch : ModulePatch
{
private static Type MergeableItemType;
@@ -59,4 +67,34 @@ namespace UIFixes
return false;
}
}
public class TopUpStackPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(Item), nameof(Item.IsSameItem));
}
[PatchPrefix]
public static bool Prefix(Item __instance, Item other, ref bool __result)
{
bool ignoreSpawnedInSession;
if (__instance.Template is MoneyClass)
{
ignoreSpawnedInSession = Settings.MergeFIRMoney.Value;
}
else if (__instance.Template is AmmoTemplate)
{
ignoreSpawnedInSession = Settings.MergeFIRAmmo.Value;
}
else
{
ignoreSpawnedInSession = Settings.MergeFIROther.Value;
}
__result = __instance.TemplateId == other.TemplateId && __instance.Id != other.Id && (ignoreSpawnedInSession || __instance.SpawnedInSession == other.SpawnedInSession);
return false;
}
}
}
}

View File

@@ -24,7 +24,7 @@ namespace UIFixes
InspectWindowStatsPatches.Enable();
new RemoveDoorActionsPatch().Enable();
ScrollPatches.Enable();
new StackFirItemsPatch().Enable();
StackFirItemsPatches.Enable();
SwapPatches.Enable();
SyncScrollPositionPatches.Enable();
new TransferConfirmPatch().Enable();