From b6aeea95a2f867af61cde4d973c6ca3bc2019b96 Mon Sep 17 00:00:00 2001 From: chomp Date: Thu, 6 Jun 2024 16:59:53 +0000 Subject: [PATCH] Migrate PMCs (sptBear/sptUsec) To Bsg Types (pmcBEAR/pmcUSEC) (!135) Co-authored-by: Dev Co-authored-by: Kaeno Reviewed-on: https://dev.sp-tarkov.com/SPT/Modules/pulls/135 --- project/SPT.Custom/CustomAI/AiHelpers.cs | 4 +- .../Patches/AddSptBotSettingsPatch.cs | 52 +++++++++---------- project/SPT.Custom/Patches/CustomAiPatch.cs | 8 +-- .../Patches/LocationLootCacheBustingPatch.cs | 1 + .../SPT.Custom/Patches/PMCSpawnParamPatch.cs | 29 +++++++++++ .../SPT.Custom/Patches/PmcFirstAidPatch.cs | 2 +- project/SPT.Custom/SPTCustomPlugin.cs | 3 +- .../Patches/PMCBotSpawnLocationPatch.cs | 6 +-- project/SPT.PrePatch/SPTPrePatcher.cs | 26 +--------- 9 files changed, 68 insertions(+), 63 deletions(-) create mode 100644 project/SPT.Custom/Patches/PMCSpawnParamPatch.cs diff --git a/project/SPT.Custom/CustomAI/AiHelpers.cs b/project/SPT.Custom/CustomAI/AiHelpers.cs index 82c2263..804f848 100644 --- a/project/SPT.Custom/CustomAI/AiHelpers.cs +++ b/project/SPT.Custom/CustomAI/AiHelpers.cs @@ -6,7 +6,7 @@ namespace SPT.Custom.CustomAI public static class AiHelpers { /// - /// Bot is a PMC when it has IsStreamerModeAvailable flagged and has a wildspawn type of 'sptBear' or 'sptUsec' + /// Bot is a PMC when it has IsStreamerModeAvailable flagged and has a wildspawn type of 'pmcBEAR' or 'pmcUSEC' /// /// Bots role /// Bot details @@ -19,7 +19,7 @@ namespace SPT.Custom.CustomAI return true; } - return (int)botRoleToCheck == SPTPrePatcher.sptBearValue || (int)botRoleToCheck == SPTPrePatcher.sptUsecValue; + return botRoleToCheck == WildSpawnType.pmcBEAR || botRoleToCheck == WildSpawnType.pmcUSEC; } public static bool BotIsPlayerScav(WildSpawnType role, string nickname) diff --git a/project/SPT.Custom/Patches/AddSptBotSettingsPatch.cs b/project/SPT.Custom/Patches/AddSptBotSettingsPatch.cs index 250d9a7..59d6b10 100644 --- a/project/SPT.Custom/Patches/AddSptBotSettingsPatch.cs +++ b/project/SPT.Custom/Patches/AddSptBotSettingsPatch.cs @@ -1,29 +1,29 @@ -using System.Collections.Generic; -using System.Reflection; -using SPT.PrePatch; -using SPT.Reflection.Patching; -using EFT; -using HarmonyLib; +//using System.Collections.Generic; +//using System.Reflection; +//using SPT.PrePatch; +//using SPT.Reflection.Patching; +//using EFT; +//using HarmonyLib; -namespace SPT.Custom.Patches -{ - public class AddSptBotSettingsPatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - return AccessTools.Method(typeof(BotSettingsRepoClass), nameof(BotSettingsRepoClass.Init)); - } +//namespace SPT.Custom.Patches +//{ +// public class AddSptBotSettingsPatch : ModulePatch +// { +// protected override MethodBase GetTargetMethod() +// { +// return AccessTools.Method(typeof(BotSettingsRepoClass), nameof(BotSettingsRepoClass.Init)); +// } - [PatchPrefix] - private static void PatchPrefix(ref Dictionary ___dictionary_0) - { - if (___dictionary_0.ContainsKey((WildSpawnType)SPTPrePatcher.sptUsecValue)) - { - return; - } +// [PatchPrefix] +// private static void PatchPrefix(ref Dictionary ___dictionary_0) +// { +// if (___dictionary_0.ContainsKey((WildSpawnType)SPTPrePatcher.sptUsecValue)) +// { +// return; +// } - ___dictionary_0.Add((WildSpawnType)SPTPrePatcher.sptUsecValue, new BotSettingsValuesClass(false, false, false, EPlayerSide.Savage.ToStringNoBox())); - ___dictionary_0.Add((WildSpawnType)SPTPrePatcher.sptBearValue, new BotSettingsValuesClass(false, false, false, EPlayerSide.Savage.ToStringNoBox())); - } - } -} \ No newline at end of file +// ___dictionary_0.Add((WildSpawnType)SPTPrePatcher.sptUsecValue, new BotSettingsValuesClass(false, false, false, EPlayerSide.Savage.ToStringNoBox())); +// ___dictionary_0.Add((WildSpawnType)SPTPrePatcher.sptBearValue, new BotSettingsValuesClass(false, false, false, EPlayerSide.Savage.ToStringNoBox())); +// } +// } +//} \ No newline at end of file diff --git a/project/SPT.Custom/Patches/CustomAiPatch.cs b/project/SPT.Custom/Patches/CustomAiPatch.cs index 5aa51cb..657dd56 100644 --- a/project/SPT.Custom/Patches/CustomAiPatch.cs +++ b/project/SPT.Custom/Patches/CustomAiPatch.cs @@ -70,7 +70,7 @@ namespace SPT.Custom.Patches } /// - /// the client sometimes replaces PMC roles with 'assaultGroup', give PMCs their original role back (sptBear/sptUsec) + /// the client sometimes replaces PMC roles with 'assaultGroup', give PMCs their original role back (pmcBEAR/pmcUSEC) /// /// WildSpawnType private static WildSpawnType FixAssaultGroupPmcsRole(BotOwner botOwner) @@ -81,8 +81,8 @@ namespace SPT.Custom.Patches // Its a PMC, figure out what the bot originally was and return it return botOwner.Profile.Info.Side == EPlayerSide.Bear - ? (WildSpawnType)SPTPrePatcher.sptBearValue - : (WildSpawnType)SPTPrePatcher.sptUsecValue; + ? WildSpawnType.pmcBEAR + : WildSpawnType.pmcUSEC; } // Not broken pmc, return original role @@ -99,7 +99,7 @@ namespace SPT.Custom.Patches { if (AiHelpers.BotIsSptPmc(__state, ___botOwner_0)) { - // Set spt bot bot back to original type + // Set spt pmc bot back to original type ___botOwner_0.Profile.Info.Settings.Role = __state; } else if (AiHelpers.BotIsPlayerScav(__state, ___botOwner_0.Profile.Info.Nickname)) diff --git a/project/SPT.Custom/Patches/LocationLootCacheBustingPatch.cs b/project/SPT.Custom/Patches/LocationLootCacheBustingPatch.cs index 1ad340e..4fd83e8 100644 --- a/project/SPT.Custom/Patches/LocationLootCacheBustingPatch.cs +++ b/project/SPT.Custom/Patches/LocationLootCacheBustingPatch.cs @@ -21,6 +21,7 @@ namespace SPT.Custom.Patches return desiredMethod; } + // method_6 private static bool IsTargetMethod(MethodInfo mi) { var parameters = mi.GetParameters(); diff --git a/project/SPT.Custom/Patches/PMCSpawnParamPatch.cs b/project/SPT.Custom/Patches/PMCSpawnParamPatch.cs new file mode 100644 index 0000000..e622a3d --- /dev/null +++ b/project/SPT.Custom/Patches/PMCSpawnParamPatch.cs @@ -0,0 +1,29 @@ +using EFT; +using HarmonyLib; +using SPT.Reflection.Patching; +using System.Reflection; + +namespace SPT.Custom.Patches +{ + public class PMCSpawnParamPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(BotSpawner), nameof(BotSpawner.GetGroupAndSetEnemies)); + } + + [PatchPrefix] + private static void PatchPrefix(BotOwner bot) + { + if (bot.SpawnProfileData.SpawnParams != null + && (bot.Profile.Info.Settings.Role != WildSpawnType.pmcBEAR || bot.Profile.Info.Settings.Role != WildSpawnType.pmcUSEC)) + { + return; + } + + // Add SpawnParams to PMC bots that are missing them + bot.SpawnProfileData.SpawnParams = new BotSpawnParams(); + bot.SpawnProfileData.SpawnParams.ShallBeGroup = new ShallBeGroupParams(false, false); + } + } +} diff --git a/project/SPT.Custom/Patches/PmcFirstAidPatch.cs b/project/SPT.Custom/Patches/PmcFirstAidPatch.cs index beb9e74..a5db7da 100644 --- a/project/SPT.Custom/Patches/PmcFirstAidPatch.cs +++ b/project/SPT.Custom/Patches/PmcFirstAidPatch.cs @@ -43,7 +43,7 @@ namespace SPT.Custom.Patches [PatchPrefix] private static bool PatchPrefix(BotOwner ___botOwner_0) { - if (___botOwner_0.IsRole((WildSpawnType)SPTPrePatcher.sptUsecValue) || ___botOwner_0.IsRole((WildSpawnType)SPTPrePatcher.sptBearValue)) + if (___botOwner_0.IsRole((WildSpawnType.pmcUSEC)) || ___botOwner_0.IsRole(WildSpawnType.pmcBEAR)) { var healthController = ___botOwner_0.GetPlayer.ActiveHealthController; diff --git a/project/SPT.Custom/SPTCustomPlugin.cs b/project/SPT.Custom/SPTCustomPlugin.cs index 6c53df2..ce307c7 100644 --- a/project/SPT.Custom/SPTCustomPlugin.cs +++ b/project/SPT.Custom/SPTCustomPlugin.cs @@ -44,7 +44,7 @@ namespace SPT.Custom new AddEnemyToAllGroupsInBotZonePatch().Enable(); new AirdropPatch().Enable(); new AirdropFlarePatch().Enable(); - new AddSptBotSettingsPatch().Enable(); + //new AddSptBotSettingsPatch().Enable(); new CustomAiPatch().Enable(); new AddTraitorScavsPatch().Enable(); new ExitWhileLootingPatch().Enable(); @@ -80,6 +80,7 @@ namespace SPT.Custom new DisablePvEPatch().Enable(); new InsurancePlaceItem().Enable(); new FileCachePatch().Enable(); + new PMCSpawnParamPatch().Enable(); HookObject.AddOrGetComponent(); } diff --git a/project/SPT.Debugging/Patches/PMCBotSpawnLocationPatch.cs b/project/SPT.Debugging/Patches/PMCBotSpawnLocationPatch.cs index 10f89ca..27e186e 100644 --- a/project/SPT.Debugging/Patches/PMCBotSpawnLocationPatch.cs +++ b/project/SPT.Debugging/Patches/PMCBotSpawnLocationPatch.cs @@ -7,7 +7,6 @@ using HarmonyLib; using System.Collections.Generic; using EFT.Game.Spawning; using System; -using SPT.PrePatch; namespace SPT.Debugging.Patches { @@ -17,7 +16,7 @@ namespace SPT.Debugging.Patches { private readonly List playerSpawnPoints; private readonly Random _rnd = new Random(); - private readonly GStruct381 _spawnSettings = new GStruct381(); + //private readonly GStruct381 _spawnSettings = new GStruct381(); public SptSpawnHelper() { @@ -64,9 +63,8 @@ namespace SPT.Debugging.Patches [PatchPrefix] public static bool PatchPrefix(GClass1483 __instance, GClass591 data) { - var firstBotRole = data.Profiles[0].Info.Settings.Role; - if ((int)firstBotRole != SPTPrePatcher.sptBearValue || (int)firstBotRole != SPTPrePatcher.sptUsecValue) + if (firstBotRole != WildSpawnType.pmcBEAR || firstBotRole != WildSpawnType.pmcUSEC) { ConsoleScreen.Log("[SPT PMC Bot spawn] Spawning a set of Scavs. Skipping..."); return true; diff --git a/project/SPT.PrePatch/SPTPrePatcher.cs b/project/SPT.PrePatch/SPTPrePatcher.cs index 499bb79..beda79c 100644 --- a/project/SPT.PrePatch/SPTPrePatcher.cs +++ b/project/SPT.PrePatch/SPTPrePatcher.cs @@ -11,16 +11,11 @@ namespace SPT.PrePatch public static class SPTPrePatcher { public static IEnumerable TargetDLLs { get; } = new[] { "Assembly-CSharp.dll" }; - - public static int sptUsecValue = 100; - public static int sptBearValue = 101; - - private static string _sptPluginFolder = "plugins/spt"; + private static readonly string _sptPluginFolder = "plugins/spt"; public static void Patch(ref AssemblyDefinition assembly) { PerformPreValidation(); - AddCustomBotTypes(assembly); ChangeAppDataPath(assembly); } @@ -44,25 +39,6 @@ namespace SPT.PrePatch } } - private static void AddCustomBotTypes(AssemblyDefinition assembly) - { - // Add custom EFT.WildSpawnTypes - var botEnums = assembly.MainModule.GetType("EFT.WildSpawnType"); - - var sptUsec = new FieldDefinition("sptUsec", - FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal | FieldAttributes.HasDefault, - botEnums) - { Constant = sptUsecValue }; - - var sptBear = new FieldDefinition("sptBear", - FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal | FieldAttributes.HasDefault, - botEnums) - { Constant = sptBearValue }; - - botEnums.Fields.Add(sptUsec); - botEnums.Fields.Add(sptBear); - } - private static List GetCacheInstructions(AssemblyDefinition assembly) { return new List