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/CheckAndAddEnemyPatch.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

66 lines
1.9 KiB
C#

using Aki.Reflection.Patching;
using Aki.Reflection.Utils;
using EFT;
using System;
using System.Linq;
using System.Reflection;
namespace Aki.Custom.Patches
{
public class CheckAndAddEnemyPatch : ModulePatch
{
private static Type _targetType;
private readonly string _targetMethodName = "CheckAndAddEnemy";
/// <summary>
/// BotGroupClass.CheckAndAddEnemy()
/// </summary>
public CheckAndAddEnemyPatch()
{
_targetType = PatchConstants.EftTypes.Single(IsTargetType);
}
private bool IsTargetType(Type type)
{
if (type.GetMethod("AddEnemy") != null && type.GetMethod("AddEnemyGroupIfAllowed") != null)
{
return true;
}
return false;
}
protected override MethodBase GetTargetMethod()
{
return _targetType.GetMethod(_targetMethodName);
}
/// <summary>
/// CheckAndAddEnemy()
/// Goal: This patch lets bosses shoot back once a PMC has shot them
/// removes the !player.AIData.IsAI check
/// </summary>
[PatchPrefix]
private static bool PatchPrefix(BotsGroup __instance, IPlayer player, ref bool ignoreAI)
{
// Z already has player as enemy BUT Enemies dict is empty, adding them again causes 'existing key' errors
if (__instance.InitialBotType == WildSpawnType.bossZryachiy || __instance.InitialBotType == WildSpawnType.followerZryachiy)
{
return false;
}
if (!player.HealthController.IsAlive)
{
return false; // Skip original
}
if (!__instance.Enemies.ContainsKey(player))
{
__instance.AddEnemy(player, EBotEnemyCause.checkAddTODO);
}
return false; // Skip original
}
}
}