mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 09:50:43 -05:00
![Lacyway](/assets/img/avatar_default.png)
Some patches are `internal` that should be `public` so that mods can disable them when altering AI. Co-authored-by: Lacyway <20912169+Lacyway@users.noreply.github.com> Reviewed-on: SPT/Modules#152 Co-authored-by: Lacyway <lacyway@noreply.dev.sp-tarkov.com> Co-committed-by: Lacyway <lacyway@noreply.dev.sp-tarkov.com>
50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
using SPT.Reflection.Patching;
|
|
using EFT;
|
|
using HarmonyLib;
|
|
using System.Reflection;
|
|
|
|
namespace SPT.Custom.Patches
|
|
{
|
|
/**
|
|
* It's possible for `AddEnemy` to return false, in that case, further code in TryCall will fail,
|
|
* so we do the first bit of `TryCall` ourselves, and skip the original function if AddEnemy fails
|
|
*/
|
|
public class BotCalledDataTryCallPatch : ModulePatch
|
|
{
|
|
protected override MethodBase GetTargetMethod()
|
|
{
|
|
return AccessTools.Method(typeof(BotCalledData), nameof(BotCalledData.TryCall));
|
|
}
|
|
|
|
[PatchPrefix]
|
|
private static bool PatchPrefix(ref bool __result, BotOwner caller, BotOwner ___botOwner_0, BotOwner ____caller)
|
|
{
|
|
if (___botOwner_0.EnemiesController.IsEnemy(caller.AIData.Player) || ____caller != null)
|
|
{
|
|
__result = false;
|
|
|
|
// Skip original
|
|
return false;
|
|
}
|
|
|
|
if (caller.Memory.GoalEnemy != null)
|
|
{
|
|
IPlayer person = caller.Memory.GoalEnemy.Person;
|
|
if (!___botOwner_0.BotsGroup.Enemies.ContainsKey(person))
|
|
{
|
|
if (!___botOwner_0.BotsGroup.AddEnemy(person, EBotEnemyCause.callBot))
|
|
{
|
|
__result = false;
|
|
|
|
// Skip original
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Allow original
|
|
return true;
|
|
}
|
|
}
|
|
}
|