From bbc8e4d1c83f335f1a955add083235145b17e60a Mon Sep 17 00:00:00 2001 From: chomp Date: Sun, 6 Aug 2023 07:09:49 +0000 Subject: [PATCH] Add patch to fix post-raid screen not showing scav xp gained during raid (!17) Co-authored-by: Kaeno Co-authored-by: Dev Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/17 --- .../Aki.SinglePlayer/AkiSingleplayerPlugin.cs | 1 + .../Progression/ScavExperienceGainPatch.cs | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 project/Aki.SinglePlayer/Patches/Progression/ScavExperienceGainPatch.cs diff --git a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs index 943549a..9e2a0b1 100644 --- a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs +++ b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs @@ -22,6 +22,7 @@ namespace Aki.SinglePlayer new OfflineSaveProfilePatch().Enable(); new OfflineSpawnPointPatch().Enable(); new ExperienceGainPatch().Enable(); + new ScavExperienceGainPatch().Enable(); new MainMenuControllerPatch().Enable(); new PlayerPatch().Enable(); new SelectLocationScreenPatch().Enable(); diff --git a/project/Aki.SinglePlayer/Patches/Progression/ScavExperienceGainPatch.cs b/project/Aki.SinglePlayer/Patches/Progression/ScavExperienceGainPatch.cs new file mode 100644 index 0000000..0dd1076 --- /dev/null +++ b/project/Aki.SinglePlayer/Patches/Progression/ScavExperienceGainPatch.cs @@ -0,0 +1,55 @@ +using Aki.Reflection.Patching; +using Aki.Reflection.Utils; +using EFT; +using EFT.Counters; +using EFT.UI.SessionEnd; +using System.Linq; +using System.Reflection; + +namespace Aki.SinglePlayer.Patches.Progression +{ + /// + /// Fix xp gained value being 0 after a scav raid + /// + public class ScavExperienceGainPatch : ModulePatch + { + /// + /// Looking for SessionResultExitStatus Show() (private) + /// + /// + protected override MethodBase GetTargetMethod() + { + var desiredType = typeof(SessionResultExitStatus); + var desiredMethod = desiredType.GetMethods(PatchConstants.PrivateFlags).FirstOrDefault(IsTargetMethod); + + Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}"); + Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}"); + + return desiredMethod; + } + + private static bool IsTargetMethod(MethodInfo mi) + { + var parameters = mi.GetParameters(); + return (parameters.Length == 7 + && parameters[0].Name == "activeProfile" + && parameters[1].Name == "lastPlayerState" + && parameters[2].Name == "side" + && parameters[3].Name == "exitStatus" + && parameters[4].Name == "raidTime"); + } + + [PatchPrefix] + private static bool PatchPrefix(ref Profile activeProfile,ref EPlayerSide side) + { + if (activeProfile.Side == EPlayerSide.Savage) + { + side = EPlayerSide.Savage; // Also set side to correct value (defaults to usec/bear when playing as scav) + int xpGainedInSession = activeProfile.Stats.SessionCounters.GetAllInt(new object[] { CounterTag.Exp }); + activeProfile.Stats.TotalSessionExperience = (int)(xpGainedInSession * activeProfile.Stats.SessionExperienceMult * activeProfile.Stats.ExperienceBonusMult); + } + + return true; // Always do original method + } + } +} \ No newline at end of file