diff --git a/AetherBags/Monitoring/InventoryMonitor.cs b/AetherBags/Monitoring/InventoryMonitor.cs index aaf0d68..39de8ca 100644 --- a/AetherBags/Monitoring/InventoryMonitor.cs +++ b/AetherBags/Monitoring/InventoryMonitor.cs @@ -28,7 +28,6 @@ public static unsafe class DragDropState public class InventoryMonitor : IDisposable { - public InventoryMonitor() { var bags = new[] { "Inventory", "InventoryLarge", "InventoryExpansion" }; @@ -42,6 +41,8 @@ public class InventoryMonitor : IDisposable Services.AddonLifecycle.RegisterListener(AddonEvent.PreFinalize, retainer, OnPreFinalize); Services.AddonLifecycle.RegisterListener(AddonEvent.PreFinalize, bags, OnInventoryPreFinalize); + Services.AddonLifecycle.RegisterListener(AddonEvent.PreHide, bags, OnInventoryPreHide); + // PreRefresh Handlers Services.AddonLifecycle.RegisterListener(AddonEvent.PreRefresh, bags, InventoryPreRefreshHandler); @@ -71,6 +72,14 @@ public class InventoryMonitor : IDisposable System.AddonInventoryWindow.Close(); } + private void OnInventoryPreHide(AddonEvent type, AddonArgs args) + { + if (System.Config.General.OpenWithGameInventory) + { + System.AddonInventoryWindow.Close(); + } + } + private unsafe void OpenInventories(string name) { GeneralSettings config = System.Config.General; @@ -192,14 +201,10 @@ public class InventoryMonitor : IDisposable if (config.OpenWithGameInventory) { - AtkValue* value1 = (AtkValue*)atkValues[1].Address; - int openTitleId = value1->Int; + var addon = RaptureAtkUnitManager.Instance()->GetAddonByName(args.AddonName); + bool isCurrentlyVisible = addon != null && addon->IsVisible; - if (openTitleId == 0) - { - System.AddonInventoryWindow.Toggle(); - } - else + if (!isCurrentlyVisible) { System.AddonInventoryWindow.Open(); } @@ -245,6 +250,6 @@ public class InventoryMonitor : IDisposable public void Dispose() { Services.GameInventory.InventoryChangedRaw -= OnInventoryChangedRaw; - Services.AddonLifecycle.UnregisterListener(OnPostSetup, OnPreFinalize, OnInventoryUpdate, OnSaddleBagUpdate, OnRetainerInventoryUpdate, OnInventoryPreFinalize, InventoryPreRefreshHandler); + Services.AddonLifecycle.UnregisterListener(OnPostSetup, OnPreFinalize, OnInventoryUpdate, OnSaddleBagUpdate, OnRetainerInventoryUpdate, OnInventoryPreFinalize, OnInventoryPreHide, InventoryPreRefreshHandler); } } \ No newline at end of file