Refactoring, cleanup

This commit is contained in:
Tyfon
2024-04-18 16:39:16 -07:00
parent b39959230d
commit 656e970ca4
5 changed files with 77 additions and 48 deletions

View File

@@ -1,9 +1,8 @@
using Aki.Reflection.Patching; using Aki.Reflection.Patching;
using System; using System;
using System.Reflection; using System.Reflection;
using EFT.UI; using EFT.UI;
using System.Threading.Tasks; using System.Threading.Tasks;
using EFT.UI.Chat;
namespace UIFixes namespace UIFixes
{ {
@@ -39,12 +38,12 @@ namespace UIFixes
[PatchPrefix] [PatchPrefix]
private static bool Prefix(ref Task<bool> __result) private static bool Prefix(ref Task<bool> __result)
{ {
if (MoveForward && Plugin.WeaponPresetConfirmOnNavigate.Value) if (MoveForward && Settings.WeaponPresetConfirmOnNavigate.Value)
{ {
return true; return true;
} }
if (!MoveForward && Plugin.WeaponPresetConfirmOnClose.Value) if (!MoveForward && Settings.WeaponPresetConfirmOnClose.Value)
{ {
return true; 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<bool> __result)
{
if (Plugin.TransferConfirmOnClose.Value)
{
return true;
}
__result = Task.FromResult<bool>(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;
}
}
} }

View File

@@ -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;
}
}
}

View File

@@ -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<bool> __result)
{
if (Settings.TransferConfirmOnClose.Value)
{
return true;
}
__result = Task.FromResult<bool>(true);
return false;
}
}
}

View File

@@ -6,15 +6,9 @@ namespace UIFixes
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin public class Plugin : BaseUnityPlugin
{ {
public static ConfigEntry<bool> WeaponPresetConfirmOnNavigate { get; set; }
public static ConfigEntry<bool> WeaponPresetConfirmOnClose { get; set; }
public static ConfigEntry<bool> TransferConfirmOnClose { get; set; }
private void Awake() private void Awake()
{ {
WeaponPresetConfirmOnNavigate = Config.Bind<bool>("Weapon Presets", "Confirm on screen change", false, "Whether to confirm unsaved changes when you change screens without closing the preset"); Settings.Init(Config);
WeaponPresetConfirmOnClose = Config.Bind<bool>("Weapon Presets", "Confirm on close", true, "Whether to still confirm unsaved changes when you actually close the preset");
TransferConfirmOnClose = Config.Bind<bool>("Transfer items", "Confirm untransfered items", false, "Whether to pointlessly confirm that you're leaving the item transfer with literally no consequences");
new EditBuildScreenPatch.CloseScreenInterruptionPatch().Enable(); new EditBuildScreenPatch.CloseScreenInterruptionPatch().Enable();
new EditBuildScreenPatch.ConfirmDiscardPatch().Enable(); new EditBuildScreenPatch.ConfirmDiscardPatch().Enable();

19
Settings.cs Normal file
View File

@@ -0,0 +1,19 @@
using BepInEx.Configuration;
namespace UIFixes
{
internal class Settings
{
public static ConfigEntry<bool> WeaponPresetConfirmOnNavigate { get; set; }
public static ConfigEntry<bool> WeaponPresetConfirmOnClose { get; set; }
public static ConfigEntry<bool> TransferConfirmOnClose { get; set; }
public static void Init(ConfigFile config)
{
WeaponPresetConfirmOnNavigate = config.Bind<bool>("Weapon Presets", "Confirm on screen change", false, "Whether to confirm unsaved changes when you change screens without closing the preset");
WeaponPresetConfirmOnClose = config.Bind<bool>("Weapon Presets", "Confirm on close", true, "Whether to still confirm unsaved changes when you actually close the preset");
TransferConfirmOnClose = config.Bind<bool>("Transfer items", "Confirm untransfered items", false, "Whether to pointlessly confirm that you're leaving the item transfer with literally no consequences");
}
}
}