0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/SPT.Custom/Patches/BotSelfEnemyPatch.cs

41 lines
1.0 KiB
C#
Raw Normal View History

2024-05-21 19:10:17 +01:00
using SPT.Reflection.Patching;
2023-03-03 18:52:31 +00:00
using EFT;
using System.Reflection;
using HarmonyLib;
2023-03-03 18:52:31 +00:00
2024-05-21 19:10:17 +01:00
namespace SPT.Custom.Patches
2023-03-03 18:52:31 +00:00
{
/// <summary>
/// Goal: patch removes the current bot from its own enemy list - occurs when adding bots type to its enemy array in difficulty settings
/// </summary>
internal class BotSelfEnemyPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotOwner), nameof(BotOwner.PreActivate));
2023-03-03 18:52:31 +00:00
}
[PatchPrefix]
private static bool PatchPrefix(BotOwner __instance, BotsGroup group)
2023-03-03 18:52:31 +00:00
{
IPlayer selfToRemove = null;
2023-03-03 18:52:31 +00:00
foreach (var enemy in group.Enemies)
{
if (enemy.Key.Id == __instance.Id)
{
selfToRemove = enemy.Key;
break;
}
}
if (selfToRemove != null)
{
group.Enemies.Remove(selfToRemove);
}
return true;
}
}
}