mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 09:50:43 -05:00
1) The called bot's enemy position is being passed to TryCall, instead of the calling bot's enemy position. This is both incorrect and can lead to an NRE if the called bot has no enemy. Fix by passing in the calling bot's enemy position 2) In the TryCall method, the caller's enemy is added to the called bot, however the code doesn't verify that it was added before accessing it in the `EnemyInfos` array. This can throw a missing key exception if the bot failed to add to the enemies list. Fix by making sure the enemy is added to the enemy list before executing TryCall 3) When a BotOwner is disposed, the CalledData is never properly cleaned up, resulting in a bot's OnEnemyAdd being triggered after the bot has been killed, this can throw an NRE. Fix by calling CalledData.SetOff before BotOwner.Dispose Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: SPT-AKI/Modules#84 Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com> Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
29 lines
771 B
C#
29 lines
771 B
C#
using Aki.Reflection.Patching;
|
|
using EFT;
|
|
using HarmonyLib;
|
|
using System.Reflection;
|
|
|
|
namespace Aki.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
|
|
*/
|
|
internal 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();
|
|
}
|
|
}
|
|
}
|
|
}
|