From 60ccc542206cb1b58bba5397cad62b37c0967995 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 11 Jul 2024 10:48:25 +0100 Subject: [PATCH] Reduced patch complexity and rename --- .../BotsGroupLetBossesShootPmcsPatch.cs | 30 +++++++++++++++++++ .../Patches/CheckAndAddEnemyPatch.cs | 29 ------------------ project/SPT.Custom/SPTCustomPlugin.cs | 2 +- 3 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 project/SPT.Custom/Patches/BotsGroupLetBossesShootPmcsPatch.cs delete mode 100644 project/SPT.Custom/Patches/CheckAndAddEnemyPatch.cs diff --git a/project/SPT.Custom/Patches/BotsGroupLetBossesShootPmcsPatch.cs b/project/SPT.Custom/Patches/BotsGroupLetBossesShootPmcsPatch.cs new file mode 100644 index 0000000..10c515a --- /dev/null +++ b/project/SPT.Custom/Patches/BotsGroupLetBossesShootPmcsPatch.cs @@ -0,0 +1,30 @@ +using SPT.Reflection.Patching; +using System.Reflection; +using HarmonyLib; + +namespace SPT.Custom.Patches +{ + public class BotsGroupLetBossesShootPmcsPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(BotsGroup), nameof(BotsGroup.CheckAndAddEnemy)); + } + + /// + /// CheckAndAddEnemy() + /// Goal: This patch lets bosses shoot back once a PMC has shot them + /// Force method to always run the code + /// + [PatchPrefix] + private static bool PatchPrefix(ref bool ignoreAI) + { + // original + // return player.HealthController.IsAlive && (!player.AIData.IsAI || ignoreAI) && !this.Enemies.ContainsKey(player) && this.AddEnemy(player, EBotEnemyCause.checkAddTODO); + ignoreAI = true; + + + return true; // Do Original + } + } +} diff --git a/project/SPT.Custom/Patches/CheckAndAddEnemyPatch.cs b/project/SPT.Custom/Patches/CheckAndAddEnemyPatch.cs deleted file mode 100644 index 3a4cf20..0000000 --- a/project/SPT.Custom/Patches/CheckAndAddEnemyPatch.cs +++ /dev/null @@ -1,29 +0,0 @@ -using SPT.Reflection.Patching; -using EFT; -using System.Reflection; -using HarmonyLib; - -namespace SPT.Custom.Patches -{ - public class CheckAndAddEnemyPatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - return AccessTools.Method(typeof(BotsGroup), nameof(BotsGroup.CheckAndAddEnemy)); - } - - /// - /// CheckAndAddEnemy() - /// Goal: This patch lets bosses shoot back once a PMC has shot them - /// Removes the !player.AIData.IsAI check - /// BSG changed the way CheckAndAddEnemy Works in 14.0 Returns a bool now - /// - [PatchPrefix] - private static bool PatchPrefix(BotsGroup __instance, IPlayer player, ref bool __result) - { - // Set result to not include !player.AIData.IsAI checks - __result = player.HealthController.IsAlive && !__instance.Enemies.ContainsKey(player) && __instance.AddEnemy(player, EBotEnemyCause.checkAddTODO); - return false; // Skip Original - } - } -} diff --git a/project/SPT.Custom/SPTCustomPlugin.cs b/project/SPT.Custom/SPTCustomPlugin.cs index 5075700..642e87e 100644 --- a/project/SPT.Custom/SPTCustomPlugin.cs +++ b/project/SPT.Custom/SPTCustomPlugin.cs @@ -26,7 +26,7 @@ namespace SPT.Custom new BotCalledDataTryCallPatch().Enable(); new BotCallForHelpCallBotPatch().Enable(); new BotOwnerDisposePatch().Enable(); - new CheckAndAddEnemyPatch().Enable(); + new BotsGroupLetBossesShootPmcsPatch().Enable(); new AddEnemyToAllGroupsInBotZonePatch().Enable(); new CustomAiPatch().Enable(); new AddTraitorScavsPatch().Enable();