diff --git a/Patches/KeepOfferWindowOpenPatches.cs b/Patches/KeepOfferWindowOpenPatches.cs new file mode 100644 index 0000000..50f69ea --- /dev/null +++ b/Patches/KeepOfferWindowOpenPatches.cs @@ -0,0 +1,81 @@ +using Aki.Reflection.Patching; +using EFT.UI.Ragfair; +using HarmonyLib; +using System.Reflection; +using System.Threading.Tasks; + +namespace UIFixes +{ + public static class KeepOfferWindowOpenPatches + { + private static bool BlockClose = false; + + public static void Enable() + { + new PlaceOfferClickPatch().Enable(); + new ClosePatch().Enable(); + new ManageTaskPatch().Enable(); + } + + public class PlaceOfferClickPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(AddOfferWindow), nameof(AddOfferWindow.method_1)); + } + + [PatchPrefix] + public static void Prefix() + { + BlockClose = Settings.KeepAddOfferOpen.Value; + } + + [PatchPostfix] + public static void Postfix() + { + BlockClose = false; + } + } + + public class ClosePatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(AddOfferWindow), nameof(AddOfferWindow.Close)); + } + + [PatchPrefix] + public static bool Prefix() + { + return !BlockClose; + } + } + + // The window has a task completion source that completes when closing window or upon successful offer placement (which assumes window closes too) + // Replace implementation to ensure it only completes when window is closed, or placement is successful AND window has since closed + public class ManageTaskPatch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(AddOfferWindow), nameof(AddOfferWindow.method_16)); + } + + [PatchPrefix] + public static bool Prefix(AddOfferWindow __instance, TaskCompletionSource ___taskCompletionSource_0, ref bool ___bool_2) + { + if (!Settings.KeepAddOfferOpen.Value) + { + return true; + } + + ___bool_2 = false; + if (!__instance.gameObject.activeInHierarchy) + { + ___taskCompletionSource_0.SetResult(null); + } + + return false; + } + } + } +} diff --git a/Plugin.cs b/Plugin.cs index 2251e21..b4775c5 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -30,6 +30,7 @@ namespace UIFixes new MoveTaskbarPatch().Enable(); FixFleaPatches.Enable(); FleaPrevSearchPatches.Enable(); + KeepOfferWindowOpenPatches.Enable(); } } } diff --git a/Settings.cs b/Settings.cs index 81daf9c..721bcce 100644 --- a/Settings.cs +++ b/Settings.cs @@ -59,6 +59,7 @@ namespace UIFixes public static ConfigEntry EnableFleaHistory { get; set; } public static ConfigEntry ShowRequiredQuest { get; set; } public static ConfigEntry AutoExpandCategories { get; set; } + public static ConfigEntry KeepAddOfferOpen { get; set; } // Advanced public static ConfigEntry StyleItemPanel { get; set; } @@ -244,6 +245,15 @@ namespace UIFixes null, new ConfigurationManagerAttributes { }))); + configEntries.Add(KeepAddOfferOpen = config.Bind( + FleaMarketSection, + "Keep Add Offer Window Open", + false, + new ConfigDescription( + "Don't close the Add Offer window after you place an offer", + null, + new ConfigurationManagerAttributes { }))); + // Advanced configEntries.Add(StyleItemPanel = config.Bind( AdvancedSection,