From 656e970ca4a23a296fb4db7343ecb87e55bfd3bf Mon Sep 17 00:00:00 2001 From: Tyfon <29051038+tyfon7@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:39:16 -0700 Subject: [PATCH] Refactoring, cleanup --- Patch.cs => Patches/EditBuildScreenPatch.cs | 44 ++------------------- Patches/MailReceiveAllPatch.cs | 24 +++++++++++ Patches/TransferConfirmPatch.cs | 30 ++++++++++++++ Plugin.cs | 8 +--- Settings.cs | 19 +++++++++ 5 files changed, 77 insertions(+), 48 deletions(-) rename Patch.cs => Patches/EditBuildScreenPatch.cs (53%) create mode 100644 Patches/MailReceiveAllPatch.cs create mode 100644 Patches/TransferConfirmPatch.cs create mode 100644 Settings.cs diff --git a/Patch.cs b/Patches/EditBuildScreenPatch.cs similarity index 53% rename from Patch.cs rename to Patches/EditBuildScreenPatch.cs index 3503614..1cc11f6 100644 --- a/Patch.cs +++ b/Patches/EditBuildScreenPatch.cs @@ -1,9 +1,8 @@ -using Aki.Reflection.Patching; +using Aki.Reflection.Patching; using System; using System.Reflection; using EFT.UI; using System.Threading.Tasks; -using EFT.UI.Chat; namespace UIFixes { @@ -39,12 +38,12 @@ namespace UIFixes [PatchPrefix] private static bool Prefix(ref Task __result) { - if (MoveForward && Plugin.WeaponPresetConfirmOnNavigate.Value) + if (MoveForward && Settings.WeaponPresetConfirmOnNavigate.Value) { return true; } - if (!MoveForward && Plugin.WeaponPresetConfirmOnClose.Value) + if (!MoveForward && Settings.WeaponPresetConfirmOnClose.Value) { return true; } @@ -54,42 +53,5 @@ namespace UIFixes } } } - - public class TransferConfirmPatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - Type type = typeof(TransferItemsScreen); - return type.GetMethod("method_4", BindingFlags.Public | BindingFlags.Instance); - } - - [PatchPrefix] - private static bool Prefix(ref Task __result) - { - if (Plugin.TransferConfirmOnClose.Value) - { - return true; - } - - __result = Task.FromResult(true); - return false; - } - } - - public class MailReceiveAllPatch : ModulePatch - { - protected override MethodBase GetTargetMethod() - { - Type type = typeof(ChatMessageSendBlock); - return type.GetMethod("Show", BindingFlags.Public | BindingFlags.Instance); - } - - [PatchPrefix] - private static void Prefix(DialogueClass dialogue) - { - // Force this false will recalculate each time. This is less than ideal, but the way the code is structured makes it very difficult to do correctly. - dialogue.HasMessagesWithRewards = false; - } - } } diff --git a/Patches/MailReceiveAllPatch.cs b/Patches/MailReceiveAllPatch.cs new file mode 100644 index 0000000..740c40a --- /dev/null +++ b/Patches/MailReceiveAllPatch.cs @@ -0,0 +1,24 @@ +using Aki.Reflection.Patching; +using System; +using System.Reflection; +using EFT.UI.Chat; + +namespace UIFixes +{ + public class MailReceiveAllPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + Type type = typeof(ChatMessageSendBlock); + return type.GetMethod("Show", BindingFlags.Public | BindingFlags.Instance); + } + + [PatchPrefix] + private static void Prefix(DialogueClass dialogue) + { + // Force this false will recalculate each time. This is less than ideal, but the way the code is structured makes it very difficult to do correctly. + dialogue.HasMessagesWithRewards = false; + } + } +} + diff --git a/Patches/TransferConfirmPatch.cs b/Patches/TransferConfirmPatch.cs new file mode 100644 index 0000000..f0c7fe5 --- /dev/null +++ b/Patches/TransferConfirmPatch.cs @@ -0,0 +1,30 @@ +using Aki.Reflection.Patching; +using System; +using System.Reflection; +using EFT.UI; +using System.Threading.Tasks; + +namespace UIFixes +{ + public class TransferConfirmPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + Type type = typeof(TransferItemsScreen); + return type.GetMethod("method_4", BindingFlags.Public | BindingFlags.Instance); + } + + [PatchPrefix] + private static bool Prefix(ref Task __result) + { + if (Settings.TransferConfirmOnClose.Value) + { + return true; + } + + __result = Task.FromResult(true); + return false; + } + } +} + diff --git a/Plugin.cs b/Plugin.cs index d918a85..b76160c 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -6,15 +6,9 @@ namespace UIFixes [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] public class Plugin : BaseUnityPlugin { - public static ConfigEntry WeaponPresetConfirmOnNavigate { get; set; } - public static ConfigEntry WeaponPresetConfirmOnClose { get; set; } - public static ConfigEntry TransferConfirmOnClose { get; set; } - private void Awake() { - WeaponPresetConfirmOnNavigate = Config.Bind("Weapon Presets", "Confirm on screen change", false, "Whether to confirm unsaved changes when you change screens without closing the preset"); - WeaponPresetConfirmOnClose = Config.Bind("Weapon Presets", "Confirm on close", true, "Whether to still confirm unsaved changes when you actually close the preset"); - TransferConfirmOnClose = Config.Bind("Transfer items", "Confirm untransfered items", false, "Whether to pointlessly confirm that you're leaving the item transfer with literally no consequences"); + Settings.Init(Config); new EditBuildScreenPatch.CloseScreenInterruptionPatch().Enable(); new EditBuildScreenPatch.ConfirmDiscardPatch().Enable(); diff --git a/Settings.cs b/Settings.cs new file mode 100644 index 0000000..ba37b14 --- /dev/null +++ b/Settings.cs @@ -0,0 +1,19 @@ +using BepInEx.Configuration; + +namespace UIFixes +{ + internal class Settings + { + public static ConfigEntry WeaponPresetConfirmOnNavigate { get; set; } + public static ConfigEntry WeaponPresetConfirmOnClose { get; set; } + public static ConfigEntry TransferConfirmOnClose { get; set; } + + public static void Init(ConfigFile config) + { + WeaponPresetConfirmOnNavigate = config.Bind("Weapon Presets", "Confirm on screen change", false, "Whether to confirm unsaved changes when you change screens without closing the preset"); + WeaponPresetConfirmOnClose = config.Bind("Weapon Presets", "Confirm on close", true, "Whether to still confirm unsaved changes when you actually close the preset"); + TransferConfirmOnClose = config.Bind("Transfer items", "Confirm untransfered items", false, "Whether to pointlessly confirm that you're leaving the item transfer with literally no consequences"); + + } + } +}