diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/MaxBotPatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/MaxBotPatch.cs deleted file mode 100644 index 4d6499a..0000000 --- a/project/SPT.SinglePlayer/Patches/RaidFix/MaxBotPatch.cs +++ /dev/null @@ -1,54 +0,0 @@ -using Comfort.Common; -using EFT; -using SPT.Common.Http; -using SPT.Reflection.Patching; -using SPT.Reflection.Utils; -using System.Reflection; - -namespace SPT.SinglePlayer.Patches.RaidFix -{ - /// - /// Alter the max bot cap with value stored in server, if value is -1, use existing value - /// - public class MaxBotPatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; - const string methodName = "SetSettings"; - var desiredType = PatchConstants.EftTypes.SingleCustom(x => x.GetMethod(methodName, flags) != null && IsTargetMethod(x.GetMethod(methodName, flags))); - var desiredMethod = desiredType.GetMethod(methodName, flags); - - Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}"); - Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}"); - - return desiredMethod; - } - - private static bool IsTargetMethod(MethodInfo mi) - { - var parameters = mi.GetParameters(); - return parameters.Length == 3 - && parameters[0].Name == "maxCount" - && parameters[1].Name == "botPresets" - && parameters[2].Name == "botScatterings"; - } - - [PatchPrefix] - public static void PatchPreFix(ref int maxCount) - { - var gameWorld = Singleton.Instance; - var location = gameWorld.MainPlayer.Location; - - if (int.TryParse(RequestHandler.GetJson($"/singleplayer/settings/bot/maxCap/{location ?? "default"}"), out int parsedMaxCount)) - { - Logger.LogWarning($"Set max bot cap to: {parsedMaxCount}"); - maxCount = parsedMaxCount; - } - else - { - Logger.LogWarning($"Unable to parse data from singleplayer/settings/bot/maxCap, using existing map max of {maxCount}"); - } - } - } -} \ No newline at end of file diff --git a/project/SPT.SinglePlayer/Patches/RaidFix/OverrideMaxAiAliveInRaidValuePatch.cs b/project/SPT.SinglePlayer/Patches/RaidFix/OverrideMaxAiAliveInRaidValuePatch.cs new file mode 100644 index 0000000..ebaca7e --- /dev/null +++ b/project/SPT.SinglePlayer/Patches/RaidFix/OverrideMaxAiAliveInRaidValuePatch.cs @@ -0,0 +1,49 @@ +using Comfort.Common; +using EFT; +using SPT.Common.Http; +using SPT.Reflection.Patching; +using System.Reflection; +using HarmonyLib; + +namespace SPT.SinglePlayer.Patches.RaidFix +{ + /// + /// Alter the max bot cap with value stored in servers config/bot.json/maxBotCap, if value is -1, use existing value + /// Adjusted value is set by client when 'botamount' is chosen in pre-raid dropdown, + /// AsOnline = 20, Low = 15, Medium 20, High = 25, horde = 35 + /// Does not affect ALL bots, some bot types (e.g. bosses) are exempt + /// + public class OverrideMaxAiAliveInRaidValuePatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(BotsController), nameof(BotsController.SetSettings)); + } + + private static bool IsTargetMethod(MethodInfo mi) + { + var parameters = mi.GetParameters(); + return parameters.Length == 3 + && parameters[0].Name == "maxCount" + && parameters[1].Name == "botPresets" + && parameters[2].Name == "botScatterings"; + } + + [PatchPrefix] + public static void PatchPreFix(ref int maxCount) + { + var gameWorld = Singleton.Instance; + var location = gameWorld.MainPlayer?.Location ?? "default"; + + if (int.TryParse(RequestHandler.GetJson($"/singleplayer/settings/bot/maxCap/{location}"), out var parsedMaxCount)) + { + Logger.LogError($"Set max bot cap for: {location} from: {maxCount} to: {parsedMaxCount}"); + maxCount = parsedMaxCount; + } + else + { + Logger.LogError($"Unable to parse data from singleplayer/settings/bot/maxCap, using existing: {location} max: {maxCount}"); + } + } + } +} \ No newline at end of file diff --git a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs index cc7e157..a5b28fe 100644 --- a/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs +++ b/project/SPT.SinglePlayer/SPTSingleplayerPlugin.cs @@ -21,7 +21,7 @@ namespace SPT.SinglePlayer // TODO: check if these patches are needed new TinnitusFixPatch().Enable(); // Probably needed //new EmptyInfilFixPatch().Enable(); - new MaxBotPatch().Enable(); // Custom code, needed + new OverrideMaxAiAliveInRaidValuePatch().Enable(); //new PostRaidHealingPricePatch().Enable(); // Client handles this now //new HideoutQuestIgnorePatch().Enable(); // Was only needed because FixQuestAchieveControllersPatch was causing issues //new SpawnProcessNegativeValuePatch().Enable(); // Client handles this edge case, revisit if bot count keeps going up