From e76ee6f2ccfa16f09dcb462664c75b4c2b3d5424 Mon Sep 17 00:00:00 2001 From: Lacyway Date: Thu, 19 Sep 2024 16:58:47 +0000 Subject: [PATCH] 310-dev (!168) This adds a patch that enforces PMC AI to be hostile towards scavs. From my testing they were not attacking random scavs and the player because the boolean failed at the attached screenshot due to PMCs being bosses and the loyalty check. Now it checks if the initial bot type of the group was a PMC Bear or USEC and then if the player it checks for is a scav, they will be forced to be an enemy (which to me seemed natural). ![image](/attachments/4a73df0f-7030-4c61-869f-0a20ba804d8b) I've tested this on 3 raids on customs and it seems to work fine. Feel free to edit the PR if the logic is flawed, and please test the patch thoroughly to ensure my tests were not just lucky. Thanks! Co-authored-by: Lacyway <20912169+Lacyway@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT/Modules/pulls/168 Co-authored-by: Lacyway Co-committed-by: Lacyway --- .../ScavMode/ScavIsPlayerEnemyPatch.cs | 29 +++++++++++++++++++ .../SPT.SinglePlayer/SPTSingleplayerPlugin.cs | 1 + 2 files changed, 30 insertions(+) create mode 100644 project/SPT.SinglePlayer/Patches/ScavMode/ScavIsPlayerEnemyPatch.cs diff --git a/project/SPT.SinglePlayer/Patches/ScavMode/ScavIsPlayerEnemyPatch.cs b/project/SPT.SinglePlayer/Patches/ScavMode/ScavIsPlayerEnemyPatch.cs new file mode 100644 index 0000000..1f4611b --- /dev/null +++ b/project/SPT.SinglePlayer/Patches/ScavMode/ScavIsPlayerEnemyPatch.cs @@ -0,0 +1,29 @@ +using EFT; +using HarmonyLib; +using SPT.Reflection.Patching; +using System.Reflection; + +namespace SPT.SinglePlayer.Patches.ScavMode +{ + /// + /// This patch ensures that PMC AI is always hostile towards the player and scavs if the player it checks is a (scav) + /// + public class ScavIsPlayerEnemyPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(BotsGroup), nameof(BotsGroup.IsPlayerEnemy)); + } + + [PatchPrefix] + public static bool Prefix(BotsGroup __instance, IPlayer player, ref bool __result) + { + if (player.Side is EPlayerSide.Savage && __instance.InitialBotType is WildSpawnType.pmcBEAR or WildSpawnType.pmcUSEC) + { + __result = true; + return false; + } + return true; + } + } +} diff --git a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs index 8d79316..f98f134 100644 --- a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs +++ b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs @@ -60,6 +60,7 @@ namespace SPT.SinglePlayer new RemoveStashUpgradeLabelPatch().Enable(); new RemoveClothingItemExternalObtainLabelPatch().Enable(); new FixLocalRaidPatch().Enable(); + new ScavIsPlayerEnemyPatch().Enable(); } catch (Exception ex) {