From 148c45666aa415f1f284afb9c4adafab4118455a Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 21 Oct 2024 14:23:41 +0100 Subject: [PATCH] Fixed bosses not spawning when player chooses `medium` ai amount on pre-raid screen --- ...BossesHavingNoFollowersOnMediumAiAmount.cs | 50 +++++++++++++++++++ project/SPT.Custom/SPTCustomPlugin.cs | 1 + 2 files changed, 51 insertions(+) create mode 100644 project/SPT.Custom/Patches/FixBossesHavingNoFollowersOnMediumAiAmount.cs diff --git a/project/SPT.Custom/Patches/FixBossesHavingNoFollowersOnMediumAiAmount.cs b/project/SPT.Custom/Patches/FixBossesHavingNoFollowersOnMediumAiAmount.cs new file mode 100644 index 0000000..37117ba --- /dev/null +++ b/project/SPT.Custom/Patches/FixBossesHavingNoFollowersOnMediumAiAmount.cs @@ -0,0 +1,50 @@ +using SPT.Reflection.Patching; +using System.Reflection; +using EFT; +using EFT.Bots; +using HarmonyLib; + +namespace SPT.Custom.Patches +{ + /// + /// Fix bosses not spawning with any followers because BSG subtract the escort amount from itself + /// + public class FixBossesHavingNoFollowersOnMediumAiAmount: ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(LocalGame), nameof(LocalGame.smethod_8)); + } + + [PatchPrefix] + public static void PatchPrefix(LocalGame __instance, WavesSettings wavesSettings, ref BossLocationSpawn[] bossLocationSpawn) + { + // Not a boss and set to medium, skip + if (wavesSettings is not { IsBosses: true, BotAmount: EBotAmount.Medium }) + { + return; + } + + foreach (var locationSpawn in bossLocationSpawn) + { + // Only adjust bosses with single escort amount value, skip others + if (locationSpawn.BossEscortAmount.Length != 1) + { + continue; + } + + // Only add new value when existing value is > 0 + var existingAmount = int.Parse(locationSpawn.BossEscortAmount); + if (existingAmount == 0) + { + // Don't add more data to boss with 0 followers + continue; + } + + // Add second value to property, when client does (max - min / 2), it won't be 0 + // e.g. reshala has value of "4", we add value "(existing)*3 (=12)", which means the client does "(12 - 4) / 2" giving us 4 escorts - same as high/as online ai amount + locationSpawn.BossEscortAmount += $",{existingAmount * 3}"; + } + } + } +} diff --git a/project/SPT.Custom/SPTCustomPlugin.cs b/project/SPT.Custom/SPTCustomPlugin.cs index 7eda07e..b2c81df 100644 --- a/project/SPT.Custom/SPTCustomPlugin.cs +++ b/project/SPT.Custom/SPTCustomPlugin.cs @@ -38,6 +38,7 @@ namespace SPT.Custom new FixScavWarNullErrorWithMarkOfUnknownPatch().Enable(); new MergeScavPmcQuestsOnInventoryLoadPatch().Enable(); new CopyPmcQuestsToPlayerScavPatch().Enable(); + new FixBossesHavingNoFollowersOnMediumAiAmount().Enable(); //new AllowAirdropsInPvEPatch().Enable(); HookObject.AddOrGetComponent();