From 9482040d082619a49c04251b21d0a5f9a19e524e Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 17 Jul 2023 13:11:22 +0100 Subject: [PATCH] Resolve issue with bots spawning well beyond the maxbotcap value --- .../Aki.SinglePlayer/AkiSingleplayerPlugin.cs | 1 + .../RaidFix/SpawnProcessNegativeValuePatch.cs | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 project/Aki.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs diff --git a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs index 8b5f43a..e6e4b5a 100644 --- a/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs +++ b/project/Aki.SinglePlayer/AkiSingleplayerPlugin.cs @@ -50,6 +50,7 @@ namespace Aki.SinglePlayer new SmokeGrenadeFuseSoundFixPatch().Enable(); new PlayerToggleSoundFixPatch().Enable(); new PluginErrorNotifierPatch().Enable(); + new SpawnProcessNegativeValuePatch().Enable(); } catch (Exception ex) { diff --git a/project/Aki.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs b/project/Aki.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs new file mode 100644 index 0000000..dec3ec5 --- /dev/null +++ b/project/Aki.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs @@ -0,0 +1,41 @@ +using Aki.Common.Http; +using Aki.Reflection.Patching; +using Aki.Reflection.Utils; +using System.Linq; +using System.Reflection; + +namespace Aki.SinglePlayer.Patches.RaidFix +{ + /// + /// Prevent BotSpawnerClass from adjusting the spawn process value to be below 0 + /// This fixes aiamount = high spawning 80+ bots on maps like streets/customs + /// int_0 = all bots alive + /// int_1 = followers alive + /// int_2 = bosses currently alive + /// int_3 = spawn process? - current guess is open spawn positions - bsg doesnt seem to handle negative vaues well + /// int_4 = max bots + /// + class SpawnProcessNegativeValuePatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + var desiredType = typeof(BotSpawnerClass); + var desiredMethod = desiredType.GetMethod("CheckOnMax", PatchConstants.PublicFlags); + + Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}"); + Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}"); + + return desiredMethod; + } + + [PatchPrefix] + private static void PatchPreFix(ref int ___int_3) + { + // Spawn process + if (___int_3 < 0) + { + ___int_3 = 0; + } + } + } +} \ No newline at end of file