From f4c5434491096c3fa98d0b501d97b6dbf02ec279 Mon Sep 17 00:00:00 2001 From: Trap Date: Wed, 1 Jan 2025 01:08:39 +0100 Subject: [PATCH] fix(client): quests/achievements related to exitName The PTT custom extract name is used only at the end of the process. In other words, we use the custom extract name only for the server-side and let the client handle his stuff with the vanilla exitName value. --- PTT-Plugin/Patches/LocalRaidEndedPatch.cs | 30 +++++++++++++++++++ PTT-Plugin/Plugin.cs | 1 + PTT-Plugin/Services/CustomExfilService.cs | 9 ++---- PTT-Plugin/Services/CustomExfilServiceFika.cs | 13 +++----- PTT-Plugin/Services/ExfilPromptService.cs | 6 ++-- PTT-Plugin/Services/ExfilsTargetsService.cs | 14 +++++++++ 6 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 PTT-Plugin/Patches/LocalRaidEndedPatch.cs diff --git a/PTT-Plugin/Patches/LocalRaidEndedPatch.cs b/PTT-Plugin/Patches/LocalRaidEndedPatch.cs new file mode 100644 index 00000000..a2ca3a5c --- /dev/null +++ b/PTT-Plugin/Patches/LocalRaidEndedPatch.cs @@ -0,0 +1,30 @@ +using Comfort.Common; +using EFT; +using SPT.Reflection.Patching; +using System.Reflection; +using PTT.Services; +using System.Linq; +using System.Collections.Generic; + +namespace PTT.Patches; + +internal class LocalRaidEndedPatch() : ModulePatch +{ + protected override MethodBase GetTargetMethod() + { + return typeof(Class301).GetMethod(nameof(Class301.LocalRaidEnded)); + } + + [PatchPrefix] + public static bool PatchPrefix(Class301 __instance, LocalRaidSettings settings, ref GClass1924 results, GClass1301[] lostInsuredItems, Dictionary transferItems) + { + string customExtractName = Plugin.ExfilsTargetsService.ConsumeExtractName(); + + if (customExtractName != null) + { + results.exitName = customExtractName; + } + + return true; + } +} diff --git a/PTT-Plugin/Plugin.cs b/PTT-Plugin/Plugin.cs index ee238741..c2ceef50 100644 --- a/PTT-Plugin/Plugin.cs +++ b/PTT-Plugin/Plugin.cs @@ -48,6 +48,7 @@ protected void Awake() new Patches.ScavExfiltrationPointPatch().Enable(); new Patches.OnGameStartedPatch().Enable(); new Patches.LocalRaidStartedPatch().Enable(); + new Patches.LocalRaidEndedPatch().Enable(); new Patches.MenuScreenAwakePatch().Enable(); Helpers.Logger.Info($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); diff --git a/PTT-Plugin/Services/CustomExfilService.cs b/PTT-Plugin/Services/CustomExfilService.cs index 38c0d3b6..9218ec50 100644 --- a/PTT-Plugin/Services/CustomExfilService.cs +++ b/PTT-Plugin/Services/CustomExfilService.cs @@ -21,9 +21,7 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget) LocalGame localGame = Singleton.Instance as LocalGame; Player player = Singleton.Instance.MainPlayer; - string customExtractName = exfilTarget.GetCustomExitName(exfil); - - Logger.Info($"started extraction on '{customExtractName}'"); + Logger.Info($"started extraction on '{exfilTarget.GetCustomExitName(exfil)}'"); if (localGame == null) { @@ -38,7 +36,7 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget) } float delay = 0f; - localGame.Stop(player.ProfileId, ExitStatus.Survived, customExtractName, delay); + localGame.Stop(player.ProfileId, ExitStatus.Survived, exfil.Settings.Name, delay); Logger.Info($"local game stopped for profile '${player.ProfileId}'"); } @@ -51,8 +49,7 @@ public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget) } TransitPoint transit = Transit.Create(exfil, exfilTarget); - string customTransitName = transit.parameters.name; - Logger.Info($"started transit on '{customTransitName}'"); + Logger.Info($"started transit on '{transit.parameters.name}'"); if (!TransitControllerAbstractClass.Exist(out GClass1642 vanillaTransitController)) { diff --git a/PTT-Plugin/Services/CustomExfilServiceFika.cs b/PTT-Plugin/Services/CustomExfilServiceFika.cs index 842a1d9c..40f9118d 100644 --- a/PTT-Plugin/Services/CustomExfilServiceFika.cs +++ b/PTT-Plugin/Services/CustomExfilServiceFika.cs @@ -16,9 +16,7 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget) { CoopGame coopGame = (CoopGame)Singleton.Instance; CoopPlayer coopPlayer = (CoopPlayer)Singleton.Instance.MainPlayer; - - string customExtractName = exfilTarget.GetCustomExitName(exfil); - Logger.Info($"(FIKA) started extraction on '{customExtractName}'"); + Logger.Info($"(FIKA) started extraction on '{exfilTarget.GetCustomExitName(exfil)}'"); if (coopGame == null) { @@ -32,19 +30,16 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget) return; } - coopGame.ExitLocation = customExtractName; // not sure if it's needed + coopGame.ExitLocation = exfil.Settings.Name; coopGame.Extract(coopPlayer, exfil, null); Logger.Info($"(FIKA) extraction done for profile {coopPlayer.ProfileId}"); - } public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget) { CoopGame coopGame = (CoopGame)Singleton.Instance; CoopPlayer coopPlayer = (CoopPlayer)Singleton.Instance.MainPlayer; - - string customTransitName = exfilTarget.GetCustomExitName(exfil); - Logger.Info($"started transit on '{customTransitName}'"); + Logger.Info($"started transit on '{exfilTarget.GetCustomExitName(exfil)}'"); if (coopGame == null) { @@ -92,7 +87,7 @@ public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget) transitController.alreadyTransits.Add(coopPlayer.ProfileId, transitPayload); // 3. trigger extract - coopGame.ExitLocation = customTransitName; // not sure if it's needed + coopGame.ExitLocation = exfil.Settings.Name; coopGame.Extract(coopPlayer, null, transit); Logger.Info($"(FIKA) transit done for profile '${coopPlayer.ProfileId}'"); } diff --git a/PTT-Plugin/Services/ExfilPromptService.cs b/PTT-Plugin/Services/ExfilPromptService.cs index 337b408c..1bb1efc0 100644 --- a/PTT-Plugin/Services/ExfilPromptService.cs +++ b/PTT-Plugin/Services/ExfilPromptService.cs @@ -73,8 +73,9 @@ private CustomExfilAction CreateCustomExfilAction(ExfiltrationPoint exfil, Exfil { _actionToExecuteOnConfirm = () => { - Sound.PlayTransitConfirm(); + Plugin.ExfilsTargetsService.SaveExfil(exfil, exfilTarget); CustomExfilService.TransitTo(exfil, exfilTarget); + Sound.PlayTransitConfirm(); }; Sound.PlayMenuEnter(); SelectFirstPromptItem(); @@ -84,8 +85,9 @@ private CustomExfilAction CreateCustomExfilAction(ExfiltrationPoint exfil, Exfil { _actionToExecuteOnConfirm = () => { - Sound.PlayExtractConfirm(); + Plugin.ExfilsTargetsService.SaveExfil(exfil, exfilTarget); CustomExfilService.ExtractTo(exfil, exfilTarget); + Sound.PlayExtractConfirm(); }; Sound.PlayMenuEnter(); SelectFirstPromptItem(); diff --git a/PTT-Plugin/Services/ExfilsTargetsService.cs b/PTT-Plugin/Services/ExfilsTargetsService.cs index e61cc282..562506ee 100644 --- a/PTT-Plugin/Services/ExfilsTargetsService.cs +++ b/PTT-Plugin/Services/ExfilsTargetsService.cs @@ -3,18 +3,32 @@ using PTT.Data; using PTT.Helpers; using Comfort.Common; +using EFT.Interactive; namespace PTT.Services; public class ExfilsTargetsService { public ExfilsTargetsResponse ExfilsTargets { get; private set; } = new() { data = { } }; + private string UsedCustomExtractName { get; set; } = null; public void Init() { FetchExfilsTargetsForCurrentLocation(); } + public void SaveExfil(ExfiltrationPoint exfil, ExfilTarget exfilTarget) + { + UsedCustomExtractName = exfilTarget.GetCustomExitName(exfil); + } + + public string ConsumeExtractName() + { + string extractName = UsedCustomExtractName; + UsedCustomExtractName = null; + return extractName; + } + private void FetchExfilsTargetsForCurrentLocation() { string locationId = Singleton.Instance?.LocationId;