From c234e0d1d69d3184c27463f703ee46d5af0c5f2f Mon Sep 17 00:00:00 2001 From: CWX Date: Fri, 2 Aug 2024 15:01:44 +0100 Subject: [PATCH] Remove patches that are now covered by BSG --- .../Patches/AddEnemyTryCallFailureFixPatch.cs | 49 ----------------- .../BotCallForHelpWrongTargetLocationPatch.cs | 53 ------------------- .../Patches/BotOwnerDisposePatch.cs | 28 ---------- project/SPT.Custom/SPTCustomPlugin.cs | 5 +- 4 files changed, 1 insertion(+), 134 deletions(-) delete mode 100644 project/SPT.Custom/Patches/AddEnemyTryCallFailureFixPatch.cs delete mode 100644 project/SPT.Custom/Patches/BotCallForHelpWrongTargetLocationPatch.cs delete mode 100644 project/SPT.Custom/Patches/BotOwnerDisposePatch.cs diff --git a/project/SPT.Custom/Patches/AddEnemyTryCallFailureFixPatch.cs b/project/SPT.Custom/Patches/AddEnemyTryCallFailureFixPatch.cs deleted file mode 100644 index c164c30..0000000 --- a/project/SPT.Custom/Patches/AddEnemyTryCallFailureFixPatch.cs +++ /dev/null @@ -1,49 +0,0 @@ -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; - } - } -} diff --git a/project/SPT.Custom/Patches/BotCallForHelpWrongTargetLocationPatch.cs b/project/SPT.Custom/Patches/BotCallForHelpWrongTargetLocationPatch.cs deleted file mode 100644 index 866a4de..0000000 --- a/project/SPT.Custom/Patches/BotCallForHelpWrongTargetLocationPatch.cs +++ /dev/null @@ -1,53 +0,0 @@ -using SPT.Reflection.Patching; -using EFT; -using HarmonyLib; -using System.Reflection; -using UnityEngine; - -namespace SPT.Custom.Patches -{ - /** - * BSG passes the wrong target location into the TryCall method for BotCallForHelp, it's passing in - * the bots current target instead of the target of the bot calling for help - * - * This results in both an NRE, and the called bots target location being wrong - */ - public class BotCallForHelpWrongTargetLocationPatch : ModulePatch - { - private static FieldInfo _originalPanicTypeField; - - protected override MethodBase GetTargetMethod() - { - _originalPanicTypeField = AccessTools.Field(typeof(BotCallForHelp), "_originalPanicType"); - - return AccessTools.FirstMethod(typeof(BotCallForHelp), IsTargetMethod); - } - - protected bool IsTargetMethod(MethodBase method) - { - var parameters = method.GetParameters(); - return (parameters.Length == 1 - && parameters[0].Name == "calledBot"); - } - - [PatchPrefix] - private static bool PatchPrefix(ref bool __result, BotCallForHelp __instance, BotOwner calledBot, BotOwner ___botOwner_0) - { - if (__instance.method_2(calledBot) && ___botOwner_0.Memory.GoalEnemy != null) - { - _originalPanicTypeField.SetValue(calledBot.CallForHelp, calledBot.DangerPointsData.PanicType); - calledBot.DangerPointsData.PanicType = PanicType.none; - calledBot.Brain.BaseBrain.CalcActionNextFrame(); - // Note: This differs from BSG's implementation in that we pass in botOwner_0's enemy pos instead of calledBot's enemy pos - calledBot.CalledData.TryCall(new Vector3?(___botOwner_0.Memory.GoalEnemy.Person.Position), ___botOwner_0, true); - __result = true; - } - else - { - __result = false; - } - - return false; // Skip original - } - } -} diff --git a/project/SPT.Custom/Patches/BotOwnerDisposePatch.cs b/project/SPT.Custom/Patches/BotOwnerDisposePatch.cs deleted file mode 100644 index 9242e71..0000000 --- a/project/SPT.Custom/Patches/BotOwnerDisposePatch.cs +++ /dev/null @@ -1,28 +0,0 @@ -using SPT.Reflection.Patching; -using EFT; -using HarmonyLib; -using System.Reflection; - -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 - */ - 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(); - } - } - } -} diff --git a/project/SPT.Custom/SPTCustomPlugin.cs b/project/SPT.Custom/SPTCustomPlugin.cs index 8731c83..8fd3e1e 100644 --- a/project/SPT.Custom/SPTCustomPlugin.cs +++ b/project/SPT.Custom/SPTCustomPlugin.cs @@ -22,10 +22,7 @@ namespace SPT.Custom new EasyBundlePatch().Enable(); // TODO: check if these patches are needed - //new AddEnemyTryCallFailureFixPatch().Enable(); // NOT NEEDED bsg do it now - new BotCallForHelpWrongTargetLocationPatch().Enable(); - //new BotOwnerDisposePatch().Enable(); // NOT NEEDED bsg do it now - new BotsGroupLetBossesShootPmcsPatch().Enable(); + // new BotsGroupLetBossesShootPmcsPatch().Enable(); new CustomAiPatch().Enable(); new AddTraitorScavsPatch().Enable(); new PmcTakesAgesToHealLimbsPatch().Enable();