0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.SinglePlayer/Patches/RaidFix/SpawnProcessNegativeValuePatch.cs
chomp 1e238c426e 0.13.5.0 (!33)
Co-authored-by: Dev <dev@dev.sp-tarkov.com>
Co-authored-by: CWX <CWX@noreply.dev.sp-tarkov.com>
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-authored-by: RaiRaiTheRaichu <rairaitheraichu@noreply.dev.sp-tarkov.com>
Co-authored-by: CWX <cwx@noreply.dev.sp-tarkov.com>
Co-authored-by: Kaeno <e>
Reviewed-on: SPT-AKI/Modules#33
2023-10-10 10:58:33 +00:00

48 lines
1.7 KiB
C#

using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
using EFT;
using System;
using System.Reflection;
namespace Aki.SinglePlayer.Patches.RaidFix
{
/// <summary>
/// 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
/// </summary>
class SpawnProcessNegativeValuePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
var desiredType = typeof(BotSpawner);
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 bool PatchPreFix(int wantSpawn, ref int toDelay, ref int toSpawn, ref int ____maxBots, int ____allBotsCount, int ____inSpawnProcess)
{
// Set bots to delay if alive bots + spawning bots count > maxbots
// ____inSpawnProcess can be negative, don't go below 0 when calculating
if ((____allBotsCount + Math.Max(____inSpawnProcess, 0)) > ____maxBots)
{
toDelay += wantSpawn;
toSpawn = 0;
return false; // Skip original
}
return true; // Do original
}
}
}