using file-scoped namespaces
This commit is contained in:
@@ -4,79 +4,78 @@ using HarmonyLib;
|
||||
using SPT.Reflection.Patching;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UIFixes
|
||||
namespace UIFixes;
|
||||
|
||||
public class FixTraderControllerSimulateFalsePatch : ModulePatch
|
||||
{
|
||||
public class FixTraderControllerSimulateFalsePatch : ModulePatch
|
||||
protected override MethodBase GetTargetMethod()
|
||||
{
|
||||
protected override MethodBase GetTargetMethod()
|
||||
return AccessTools.Method(typeof(TraderControllerClass), nameof(TraderControllerClass.ExecutePossibleAction), [typeof(ItemContextAbstractClass), typeof(Item), typeof(bool), typeof(bool)]);
|
||||
}
|
||||
|
||||
// Recreating 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 ItemOperation __result)
|
||||
{
|
||||
TargetItemOperation opStruct;
|
||||
opStruct.targetItem = targetItem;
|
||||
opStruct.traderControllerClass = __instance;
|
||||
opStruct.simulate = simulate;
|
||||
opStruct.item = itemContext.Item;
|
||||
|
||||
Error error = new NoPossibleActionsError(opStruct.item);
|
||||
bool mergeAvailable = itemContext.MergeAvailable;
|
||||
bool splitAvailable = itemContext.SplitAvailable;
|
||||
partialTransferOnly &= splitAvailable;
|
||||
|
||||
if (mergeAvailable)
|
||||
{
|
||||
return AccessTools.Method(typeof(TraderControllerClass), nameof(TraderControllerClass.ExecutePossibleAction), [typeof(ItemContextAbstractClass), typeof(Item), typeof(bool), typeof(bool)]);
|
||||
if (partialTransferOnly)
|
||||
{
|
||||
__result = __instance.method_24(ref error, ref opStruct);
|
||||
return false;
|
||||
}
|
||||
|
||||
var operation = __instance.method_22(ref error, ref opStruct);
|
||||
if (operation.Succeeded)
|
||||
{
|
||||
__result = operation;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Recreating 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 ItemOperation __result)
|
||||
if (opStruct.targetItem is IApplicable applicable)
|
||||
{
|
||||
TargetItemOperation opStruct;
|
||||
opStruct.targetItem = targetItem;
|
||||
opStruct.traderControllerClass = __instance;
|
||||
opStruct.simulate = simulate;
|
||||
opStruct.item = itemContext.Item;
|
||||
|
||||
Error error = new NoPossibleActionsError(opStruct.item);
|
||||
bool mergeAvailable = itemContext.MergeAvailable;
|
||||
bool splitAvailable = itemContext.SplitAvailable;
|
||||
partialTransferOnly &= splitAvailable;
|
||||
|
||||
if (mergeAvailable)
|
||||
var operation = __instance.method_23(applicable, ref error, ref opStruct);
|
||||
if (operation.Succeeded)
|
||||
{
|
||||
if (partialTransferOnly)
|
||||
{
|
||||
__result = __instance.method_24(ref error, ref opStruct);
|
||||
return false;
|
||||
}
|
||||
|
||||
var operation = __instance.method_22(ref error, ref opStruct);
|
||||
if (operation.Succeeded)
|
||||
if (itemContext.IsOperationAllowed(operation.Value))
|
||||
{
|
||||
__result = operation;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (opStruct.targetItem is IApplicable applicable)
|
||||
{
|
||||
var operation = __instance.method_23(applicable, ref error, ref opStruct);
|
||||
if (operation.Succeeded)
|
||||
// Begin added section
|
||||
else if (!simulate && operation.Value != null)
|
||||
{
|
||||
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
|
||||
// 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)
|
||||
{
|
||||
var operation = __instance.method_24(ref error, ref opStruct);
|
||||
if (operation.Succeeded)
|
||||
{
|
||||
__result = operation;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__result = error;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mergeAvailable && splitAvailable)
|
||||
{
|
||||
var operation = __instance.method_24(ref error, ref opStruct);
|
||||
if (operation.Succeeded)
|
||||
{
|
||||
__result = operation;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
__result = error;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user