diff --git a/Patches/FixTraderControllerSimulateFalsePatch.cs b/Patches/FixTraderControllerSimulateFalsePatch.cs new file mode 100644 index 0000000..c4222be --- /dev/null +++ b/Patches/FixTraderControllerSimulateFalsePatch.cs @@ -0,0 +1,82 @@ +using Aki.Reflection.Patching; +using Diz.LanguageExtensions; +using EFT.InventoryLogic; +using HarmonyLib; +using System.Reflection; + +namespace UIFixes +{ + public class FixTraderControllerSimulateFalsePatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(TraderControllerClass), nameof(TraderControllerClass.ExecutePossibleAction), [typeof(ItemContextAbstractClass), typeof(Item), typeof(bool), typeof(bool)]); + } + + // Recreatign this function to add the comment section, so calling this with simulate = false doesn't break everything + [PatchPrefix] + [HarmonyPriority(Priority.Last)] + public static bool Prefix(TraderControllerClass __instance, ItemContextAbstractClass itemContext, Item targetItem, bool partialTransferOnly, bool simulate, ref GStruct413 __result) + { + TraderControllerClass.Struct754 opStruct; + opStruct.targetItem = targetItem; + opStruct.gclass2758_0 = __instance; + opStruct.simulate = simulate; + opStruct.item = itemContext.Item; + + Error error = new GClass3293(opStruct.item); + bool mergeAvailable = itemContext.MergeAvailable; + bool splitAvailable = itemContext.SplitAvailable; + partialTransferOnly &= splitAvailable; + + if (mergeAvailable) + { + if (partialTransferOnly) + { + __result = __instance.method_24(ref error, ref opStruct); + return false; + } + + GStruct413 operation = __instance.method_22(ref error, ref opStruct); + if (operation.Succeeded) + { + __result = operation; + return false; + } + } + + if (opStruct.targetItem is GInterface306 applicable) + { + GStruct413 operation = __instance.method_23(applicable, ref error, ref opStruct); + if (operation.Succeeded) + { + if (itemContext.IsOperationAllowed(operation.Value)) + { + __result = operation; + return false; + } + // Begin added section + else if (!simulate && operation.Value != null) + { + // BSG dropped this operation on the floor, but it needs to be rolled back if it's not going to be returned + operation.Value.RollBack(); + } + // End added section + } + } + + if (mergeAvailable && splitAvailable) + { + GStruct413 operation = __instance.method_24(ref error, ref opStruct); + if (operation.Succeeded) + { + __result = operation; + return false; + } + } + + __result = error; + return false; + } + } +} diff --git a/Plugin.cs b/Plugin.cs index 9186fd3..e9f553c 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -53,6 +53,7 @@ namespace UIFixes new FixUnloadLastBulletPatch().Enable(); StackMoveGreedyPatches.Enable(); UnloadAmmoPatches.Enable(); + new FixTraderControllerSimulateFalsePatch().Enable(); } public static bool InRaid()