From 3853a413f63948e29481acee8511feff47862828 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Sat, 10 Feb 2024 08:31:18 +0000 Subject: [PATCH] Fix quest counters triggering while ending the HideoutGame (!78) When exiting the hideout, the HideoutPlayer class ends up triggering a call in Player that calculates quest counter changes. This causes issues with quests that require not dying The Player class however wraps these calls in a null check on the QuestController, so we can set it to null before ending the hideout session, and restore it afterwards to skip quest counter calculations As Hideout Game end only triggers on start of a new raid, and not when you actually close the hideout, I can't think of any reason that quest counters should trigger in this scenario Resolves: https://dev.sp-tarkov.com/SPT-AKI/Issues/issues/471 Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/78 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- .../Aki.SinglePlayer/AkiSingleplayerPlugin.cs | 1 + .../Progression/HideoutQuestIgnorePatch.cs | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 project/Aki.SinglePlayer/Patches/Progression/HideoutQuestIgnorePatch.cs diff --git a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs index ac846b6..c4eb11a 100644 --- a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs +++ b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs @@ -62,6 +62,7 @@ namespace Aki.SinglePlayer new PurchaseTraderServicePatch().Enable(); new ScavSellAllPriceStorePatch().Enable(); new ScavSellAllRequestPatch().Enable(); + new HideoutQuestIgnorePatch().Enable(); } catch (Exception ex) { diff --git a/project/Aki.SinglePlayer/Patches/Progression/HideoutQuestIgnorePatch.cs b/project/Aki.SinglePlayer/Patches/Progression/HideoutQuestIgnorePatch.cs new file mode 100644 index 0000000..b669a2b --- /dev/null +++ b/project/Aki.SinglePlayer/Patches/Progression/HideoutQuestIgnorePatch.cs @@ -0,0 +1,35 @@ +using Aki.Reflection.Patching; +using EFT; +using HarmonyLib; +using System.Reflection; + +namespace Aki.SinglePlayer.Patches.Progression +{ + /** + * There is no reason to update quest counters when exiting the hideout, so set the + * player's QuestController to null while calling HideoutPlayer.OnGameSessionEnd to + * avoid the quest controller counters from being triggered + * + * Note: Player.OnGameSessionEnd handles the player's quest controller not being set gracefully + */ + public class HideoutQuestIgnorePatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(HideoutPlayer), nameof(HideoutPlayer.OnGameSessionEnd)); + } + + [PatchPrefix] + private static void PatchPrefix(AbstractQuestControllerClass __state, ref AbstractQuestControllerClass ____questController) + { + __state = ____questController; + ____questController = null; + } + + [PatchPostfix] + private static void PatchPostfix(AbstractQuestControllerClass __state, ref AbstractQuestControllerClass ____questController) + { + ____questController = __state; + } + } +}