From c8507fb6003578483d225b92595ccf2b53318ae4 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Thu, 15 Feb 2024 08:55:41 +0000 Subject: [PATCH] Synchronize scav encyclopedia with PMC at raid start, and inspect any items in scav inventory (!81) This makes SPT mimic live in how scav encyclopedia is handled Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/81 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- .../Aki.SinglePlayer/AkiSingleplayerPlugin.cs | 1 + .../Patches/ScavMode/ScavEncyclopediaPatch.cs | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 project/Aki.SinglePlayer/Patches/ScavMode/ScavEncyclopediaPatch.cs diff --git a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs index 430c2fc..2e18a34 100644 --- a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs +++ b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs @@ -64,6 +64,7 @@ namespace Aki.SinglePlayer new ScavSellAllRequestPatch().Enable(); new HideoutQuestIgnorePatch().Enable(); new LightKeeperServicesPatch().Enable(); + new ScavEncyclopediaPatch().Enable(); } catch (Exception ex) { diff --git a/project/Aki.SinglePlayer/Patches/ScavMode/ScavEncyclopediaPatch.cs b/project/Aki.SinglePlayer/Patches/ScavMode/ScavEncyclopediaPatch.cs new file mode 100644 index 0000000..e0694ca --- /dev/null +++ b/project/Aki.SinglePlayer/Patches/ScavMode/ScavEncyclopediaPatch.cs @@ -0,0 +1,47 @@ +using Aki.Reflection.Patching; +using Aki.Reflection.Utils; +using Aki.SinglePlayer.Utils.InRaid; +using EFT; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Aki.SinglePlayer.Patches.ScavMode +{ + /** + * At the start of a scav raid, copy the PMC encyclopedia to the scav profile, and + * make sure the scav knows all of the items it has in its inventory + */ + internal class ScavEncyclopediaPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted)); + } + + [PatchPostfix] + public static void PatchPostFix() + { + if (RaidChangesUtil.IsScavRaid) + { + var scavProfile = PatchConstants.BackEndSession.ProfileOfPet; + var pmcProfile = PatchConstants.BackEndSession.Profile; + + // Handle old profiles where the scav doesn't have an encyclopedia + if (scavProfile.Encyclopedia == null) + { + scavProfile.Encyclopedia = new Dictionary(); + } + + // Sync the PMC encyclopedia to the scav profile + foreach (var item in pmcProfile.Encyclopedia.Where(item => !scavProfile.Encyclopedia.ContainsKey(item.Key))) + { + scavProfile.Encyclopedia.Add(item.Key, item.Value); + } + + // Auto examine any items the scav doesn't know that are in their inventory + scavProfile.LearnAll(); + } + } + } +}