2024-05-21 19:10:17 +01:00
|
|
|
|
using SPT.Reflection.Patching;
|
|
|
|
|
using SPT.SinglePlayer.Models.ScavMode;
|
2024-02-08 09:11:22 +00:00
|
|
|
|
using Comfort.Common;
|
|
|
|
|
using EFT.InventoryLogic;
|
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-08-20 20:25:53 +01:00
|
|
|
|
using EFT;
|
2024-02-08 09:11:22 +00:00
|
|
|
|
|
2024-05-21 19:10:17 +01:00
|
|
|
|
namespace SPT.SinglePlayer.Patches.ScavMode
|
2024-02-08 09:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* When the user clicks "Sell All" after a scav raid, create a custom request object
|
|
|
|
|
* that includes the calculated sell price
|
|
|
|
|
*/
|
|
|
|
|
public class ScavSellAllRequestPatch : ModulePatch
|
|
|
|
|
{
|
|
|
|
|
private static MethodInfo _sendOperationMethod;
|
|
|
|
|
|
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
|
|
|
{
|
2024-06-07 18:25:19 +00:00
|
|
|
|
_sendOperationMethod = AccessTools.Method(typeof(ProfileEndpointFactoryAbstractClass), nameof(ProfileEndpointFactoryAbstractClass.SendOperationRightNow));
|
2024-02-08 09:11:22 +00:00
|
|
|
|
|
2024-06-07 18:25:19 +00:00
|
|
|
|
// NEEDS FIXING
|
|
|
|
|
return AccessTools.Method(typeof(ProfileEndpointFactoryAbstractClass), nameof(ProfileEndpointFactoryAbstractClass.SellAllFromSavage));
|
2024-02-08 09:11:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[PatchPrefix]
|
2024-08-02 16:57:59 +01:00
|
|
|
|
public static bool PatchPrefix(ProfileEndpointFactoryAbstractClass __instance, ref Task<IResult> __result, string playerId, string petId)
|
2024-02-08 09:11:22 +00:00
|
|
|
|
{
|
|
|
|
|
// Build request with additional information
|
2024-08-20 20:25:53 +01:00
|
|
|
|
OwnerInfo fromOwner = new OwnerInfo(petId, EOwnerType.Profile);
|
|
|
|
|
OwnerInfo toOwner = new OwnerInfo(playerId, EOwnerType.Profile);
|
2024-02-08 09:11:22 +00:00
|
|
|
|
|
|
|
|
|
SellAllRequest request = new SellAllRequest
|
|
|
|
|
{
|
|
|
|
|
Action = "SellAllFromSavage",
|
|
|
|
|
TotalValue = ScavSellAllPriceStorePatch.StoredPrice, // Retrieve value stored in earlier patch
|
|
|
|
|
FromOwner = fromOwner, // Scav
|
|
|
|
|
ToOwner = toOwner // PMC
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// We'll re-use the same logic/methods that the base code used
|
|
|
|
|
TaskCompletionSource<IResult> taskCompletionSource = new TaskCompletionSource<IResult>();
|
|
|
|
|
_sendOperationMethod.Invoke(__instance, new object[] { request, new Callback(taskCompletionSource.SetResult) });
|
|
|
|
|
__result = taskCompletionSource.Task;
|
|
|
|
|
|
|
|
|
|
// Skip original
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|