From f9e7681fec1bc10776a6fb0b8baceb3ddc8980ab Mon Sep 17 00:00:00 2001 From: Kaeno Date: Sat, 1 Apr 2023 10:39:12 +0000 Subject: [PATCH] Add: New RaidSettingsWindowPatch to make Raidsettingswindow to not default inraid values to BSG defaults on game settings click. (!7) Co-authored-by: Kaeno <> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Modules/pulls/7 Reviewed-by: Terkoiz Co-authored-by: Kaeno Co-committed-by: Kaeno --- project/Aki.Custom/AkiCustomPlugin.cs | 1 + .../Patches/RaidSettingsWindowPatch.cs | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 project/Aki.Custom/Patches/RaidSettingsWindowPatch.cs diff --git a/project/Aki.Custom/AkiCustomPlugin.cs b/project/Aki.Custom/AkiCustomPlugin.cs index 1c045d4..979d786 100644 --- a/project/Aki.Custom/AkiCustomPlugin.cs +++ b/project/Aki.Custom/AkiCustomPlugin.cs @@ -24,6 +24,7 @@ namespace Aki.Custom new BotDifficultyPatch().Enable(); new CoreDifficultyPatch().Enable(); new OfflineRaidMenuPatch().Enable(); + new RaidSettingsWindowPatch().Enable(); new OfflineRaidSettingsMenuPatch().Enable(); new SessionIdPatch().Enable(); new VersionLabelPatch().Enable(); diff --git a/project/Aki.Custom/Patches/RaidSettingsWindowPatch.cs b/project/Aki.Custom/Patches/RaidSettingsWindowPatch.cs new file mode 100644 index 0000000..a7c8976 --- /dev/null +++ b/project/Aki.Custom/Patches/RaidSettingsWindowPatch.cs @@ -0,0 +1,43 @@ +using Aki.Common.Http; +using Aki.Common.Utils; +using Aki.Reflection.Patching; +using Aki.Custom.Models; +using EFT.UI; +using EFT.UI.Matchmaker; +using System.Reflection; + +namespace Aki.Custom.Patches +{ + /// + /// The purpose of this patch is to make RaidSettingsWindow not reset the values to BSG default + /// Keeping our own from InRaid.json therefore not defaulting to bosses being disabled. + /// + public class RaidSettingsWindowPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + var desiredType = typeof(RaidSettingsWindow); + var desiredMethod = desiredType.GetMethod("method_9", BindingFlags.NonPublic | BindingFlags.Instance); + + Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}"); + Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}"); + + return desiredMethod; + } + + [PatchPrefix] + private static bool PatchPreFix(UpdatableToggle ____enableBosses, UpdatableToggle ____scavWars, UpdatableToggle ____taggedAndCursed, DropDownBox ____aiDifficultyDropdown, DropDownBox ____aiAmountDropdown) + { + var json = RequestHandler.GetJson("/singleplayer/settings/raid/menu"); + var settings = Json.Deserialize(json); + + ____enableBosses.UpdateValue(settings.BossEnabled); + ____scavWars.UpdateValue(false); + ____taggedAndCursed.UpdateValue(settings.TaggedAndCursed); + ____aiDifficultyDropdown.UpdateValue((int)settings.AiDifficulty); + ____aiAmountDropdown.UpdateValue((int)(settings.AiAmount)); + + return false; + } + } +} \ No newline at end of file