2024-05-21 19:10:17 +01:00
|
|
|
using SPT.Reflection.Patching;
|
|
|
|
using SPT.Reflection.Utils;
|
2023-10-10 10:58:33 +00:00
|
|
|
using EFT;
|
|
|
|
using System;
|
2023-07-17 13:11:22 +01:00
|
|
|
using System.Reflection;
|
2024-01-13 22:08:29 +00:00
|
|
|
using HarmonyLib;
|
2023-07-17 13:11:22 +01:00
|
|
|
|
2024-05-21 19:10:17 +01:00
|
|
|
namespace SPT.SinglePlayer.Patches.RaidFix
|
2023-07-17 13:11:22 +01:00
|
|
|
{
|
|
|
|
/// <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>
|
2024-03-02 15:50:50 +00:00
|
|
|
public class SpawnProcessNegativeValuePatch : ModulePatch
|
2023-07-17 13:11:22 +01:00
|
|
|
{
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
|
|
{
|
2024-01-13 22:08:29 +00:00
|
|
|
return AccessTools.Method(typeof(BotSpawner), nameof(BotSpawner.CheckOnMax));
|
2023-07-17 13:11:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
[PatchPrefix]
|
2023-10-10 10:58:33 +00:00
|
|
|
private static bool PatchPreFix(int wantSpawn, ref int toDelay, ref int toSpawn, ref int ____maxBots, int ____allBotsCount, int ____inSpawnProcess)
|
2023-07-17 13:11:22 +01:00
|
|
|
{
|
2023-10-10 10:58:33 +00:00
|
|
|
// 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)
|
2023-07-17 13:11:22 +01:00
|
|
|
{
|
2023-10-10 10:58:33 +00:00
|
|
|
toDelay += wantSpawn;
|
|
|
|
toSpawn = 0;
|
|
|
|
|
|
|
|
return false; // Skip original
|
2023-07-17 13:11:22 +01:00
|
|
|
}
|
2023-10-10 10:58:33 +00:00
|
|
|
|
|
|
|
return true; // Do original
|
2023-07-17 13:11:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|