Fix TraderControllerClass.ExecutePossibleAction to not drop unsimulated operations on the floor
This commit is contained in:
82
Patches/FixTraderControllerSimulateFalsePatch.cs
Normal file
82
Patches/FixTraderControllerSimulateFalsePatch.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -53,6 +53,7 @@ namespace UIFixes
|
|||||||
new FixUnloadLastBulletPatch().Enable();
|
new FixUnloadLastBulletPatch().Enable();
|
||||||
StackMoveGreedyPatches.Enable();
|
StackMoveGreedyPatches.Enable();
|
||||||
UnloadAmmoPatches.Enable();
|
UnloadAmmoPatches.Enable();
|
||||||
|
new FixTraderControllerSimulateFalsePatch().Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool InRaid()
|
public static bool InRaid()
|
||||||
|
|||||||
Reference in New Issue
Block a user