0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/SPT.Custom/Patches/BotOwnerDisposePatch.cs

29 lines
769 B
C#
Raw Normal View History

2024-05-21 19:10:17 +01:00
using SPT.Reflection.Patching;
using EFT;
using HarmonyLib;
using System.Reflection;
2024-05-21 19:10:17 +01:00
namespace SPT.Custom.Patches
{
/**
* BotOwner doesn't call SetOff on the CalledData object when a bot is disposed, this can result
* in bots that are no longer alive having their `OnEnemyAdd` method called
*/
2024-08-01 21:01:25 +01:00
public class BotOwnerDisposePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotOwner), nameof(BotOwner.Dispose));
}
[PatchPrefix]
private static void PatchPrefix(BotOwner __instance)
{
if (__instance.CalledData != null)
{
__instance.CalledData.SetOff();
}
}
}
}