0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 08:30:45 -05:00
modules/project/SPT.Custom/Patches/BotSelfEnemyPatch.cs
Dev 2faf204d77 Revert "Removed unused patches:"
This reverts commit cc674f5d4816e98d4b84d52f364cb867bfa30def.
2024-08-02 17:25:50 +01:00

41 lines
1.0 KiB
C#

using SPT.Reflection.Patching;
using EFT;
using System.Reflection;
using HarmonyLib;
namespace SPT.Custom.Patches
{
/// <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>
public class BotSelfEnemyPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotOwner), nameof(BotOwner.PreActivate));
}
[PatchPrefix]
private static bool PatchPrefix(BotOwner __instance, BotsGroup group)
{
IPlayer selfToRemove = null;
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;
}
}
}