0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/SPT.SinglePlayer/Patches/ScavMode/SendPlayerScavProfileToServerAfterRaidPatch.cs
2024-11-17 21:48:45 +00:00

66 lines
2.1 KiB
C#

using EFT;
using HarmonyLib;
using SPT.Reflection.Patching;
using System.Reflection;
using System.Linq;
using SPT.Common.Http;
namespace SPT.SinglePlayer.Patches.ScavMode
{
/// <summary>
/// Get Profile at LocalGame End to use in SendPlayerScavProfileToServerAfterRaidPatch
/// </summary>
public class GetProfileAtEndOfRaidPatch : ModulePatch
{
public static GClass1962 ProfileDescriptor { get; private set; }
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(LocalGame), nameof(LocalGame.Stop));
}
[PatchPrefix]
public static void PatchPrefix(LocalGame __instance)
{
ProfileDescriptor = new GClass1962(__instance.Profile_0, GClass1971.Instance);
}
}
/// <summary>
/// Get profile from other patch (GetProfileAtEndOfRaidPatch)
/// If our profile is savage Create new Session.AllProfiles and pass in our own profile to allow us to use the ScavengerInventoryScreen
/// </summary>
public class SendPlayerScavProfileToServerAfterRaidPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(PostRaidHealthScreenClass), nameof(PostRaidHealthScreenClass.method_2));
}
[PatchPrefix]
public static void PatchPrefix(ref ISession ___iSession)
{
Profile profile = new(GetProfileAtEndOfRaidPatch.ProfileDescriptor);
// Player is PMC, skip patch
if (profile.Side != EPlayerSide.Savage)
{
return;
}
// Only do below when player is a scav
var session = (ProfileEndpointFactoryAbstractClass)___iSession;
session.AllProfiles =
[
session.AllProfiles.First(x => x.Side != EPlayerSide.Savage),
profile
];
session.ProfileOfPet.LearnAll();
// Send scav profile to server so it knows of the items we might transfer
RequestHandler.PutJson("/raid/profile/scavsave",
GetProfileAtEndOfRaidPatch.ProfileDescriptor.ToUnparsedData([]).JObject.ToString());
}
}
}