mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 09:50:43 -05:00
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 AddEnemyTryCallFailureFixPatch : 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;
|
|
}
|
|
}
|
|
}
|