0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.Custom/Patches/AddEnemyPatch.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

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(BotZoneGroupsDictionary).GetMethod(methodName);
}
[PatchPrefix]
private static bool PatchPrefix(BotZoneGroupsDictionary __instance, IPlayer 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;
}
}
}