0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:10:44 -05:00
modules/project/Aki.Custom/Patches/AddEnemyPatch.cs
2023-03-03 18:52:31 +00:00

35 lines
1.1 KiB
C#

using Aki.Reflection.Patching;
using EFT;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Aki.Custom.Patches
{
/// <summary>
/// If a bot being added has an ID found in list_1, it means its trying to add itself to its enemy list
/// Dont add bot to enemy list if its in list_1 and skip the rest of the AddEnemy() function
/// </summary>
public class AddSelfAsEnemyPatch : ModulePatch
{
private static readonly string methodName = "AddEnemy";
protected override MethodBase GetTargetMethod()
{
return typeof(BotGroupClass).GetMethod(methodName);
}
[PatchPrefix]
private static bool PatchPrefix(BotGroupClass __instance, IAIDetails person)
{
var botOwners = (List<BotOwner>)__instance.GetType().GetField("list_1", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
if (botOwners.Any(x => x.Id == person.Id))
{
return false;
}
return true;
}
}
}