diff --git a/Deliveroo/Deliveroo.csproj b/Deliveroo/Deliveroo.csproj index 6a063a6..c66aaab 100644 --- a/Deliveroo/Deliveroo.csproj +++ b/Deliveroo/Deliveroo.csproj @@ -1,7 +1,7 @@ net7.0-windows - 2.6 + 2.7 11.0 enable true diff --git a/Deliveroo/DeliverooPlugin.Exchange.cs b/Deliveroo/DeliverooPlugin.Exchange.cs index 5c2faf7..7089876 100644 --- a/Deliveroo/DeliverooPlugin.Exchange.cs +++ b/Deliveroo/DeliverooPlugin.Exchange.cs @@ -2,6 +2,7 @@ using Dalamud.Game.ClientState.Objects.Types; using Deliveroo.GameData; using FFXIVClientStructs.FFXIV.Component.GUI; +using LLib.GameUI; using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; namespace Deliveroo; @@ -47,8 +48,8 @@ partial class DeliverooPlugin return; } - if (TryGetAddonByName("GrandCompanyExchange", out var addonExchange) && - IsAddonReady(addonExchange)) + if (_gameGui.TryGetAddonByName("GrandCompanyExchange", out var addonExchange) && + LAddon.IsAddonReady(addonExchange)) { _pluginLog.Information($"Selecting tier 1, {(int)item.Tier - 1}"); var selectRank = stackalloc AtkValue[] @@ -78,8 +79,8 @@ partial class DeliverooPlugin return; } - if (TryGetAddonByName("GrandCompanyExchange", out var addonExchange) && - IsAddonReady(addonExchange)) + if (_gameGui.TryGetAddonByName("GrandCompanyExchange", out var addonExchange) && + LAddon.IsAddonReady(addonExchange)) { _pluginLog.Information($"Selecting subcategory 2, {(int)item.SubCategory}"); var selectType = stackalloc AtkValue[] @@ -102,8 +103,8 @@ partial class DeliverooPlugin private unsafe void SelectReward() { - if (TryGetAddonByName("GrandCompanyExchange", out var addonExchange) && - IsAddonReady(addonExchange)) + if (_gameGui.TryGetAddonByName("GrandCompanyExchange", out var addonExchange) && + LAddon.IsAddonReady(addonExchange)) { if (SelectRewardItem(addonExchange)) { @@ -167,8 +168,8 @@ partial class DeliverooPlugin private unsafe void CloseGcExchange() { - if (TryGetAddonByName("GrandCompanyExchange", out var addonExchange) && - IsAddonReady(addonExchange)) + if (_gameGui.TryGetAddonByName("GrandCompanyExchange", out var addonExchange) && + LAddon.IsAddonReady(addonExchange)) { addonExchange->FireCallbackInt(-1); CurrentStage = Stage.TargetPersonnelOfficer; diff --git a/Deliveroo/DeliverooPlugin.GameFunctions.cs b/Deliveroo/DeliverooPlugin.GameFunctions.cs index 75858b5..1894eb4 100644 --- a/Deliveroo/DeliverooPlugin.GameFunctions.cs +++ b/Deliveroo/DeliverooPlugin.GameFunctions.cs @@ -165,52 +165,4 @@ partial class DeliverooPlugin .ThenBy(x => x.ItemId) .ToList(); } - - private const int UnitListCount = 18; - private unsafe AtkUnitBase* GetAddonById(uint id) - { - var unitManagers = &AtkStage.GetSingleton()->RaptureAtkUnitManager->AtkUnitManager.DepthLayerOneList; - for (var i = 0; i < UnitListCount; i++) - { - var unitManager = &unitManagers[i]; - foreach (var j in Enumerable.Range(0, Math.Min(unitManager->Count, unitManager->EntriesSpan.Length))) - { - var unitBase = unitManager->EntriesSpan[j].Value; - if (unitBase != null && unitBase->ID == id) - { - return unitBase; - } - } - } - - return null; - } - - private unsafe bool TryGetAddonByName(string addonName, out T* addonPtr) - where T : unmanaged - { - var a = _gameGui.GetAddonByName(addonName); - if (a != IntPtr.Zero) - { - addonPtr = (T*)a; - return true; - } - else - { - addonPtr = null; - return false; - } - } - - private unsafe bool IsAddonReady(AtkUnitBase* addon) - { - return addon->IsVisible && addon->UldManager.LoadedState == AtkLoadState.Loaded; - } - - private unsafe string? ReadAtkString(AtkValue atkValue) - { - if (atkValue.String != null) - return MemoryHelper.ReadSeStringNullTerminated(new nint(atkValue.String)).ToString(); - return null; - } } diff --git a/Deliveroo/DeliverooPlugin.Supply.cs b/Deliveroo/DeliverooPlugin.Supply.cs index b9534b2..5616628 100644 --- a/Deliveroo/DeliverooPlugin.Supply.cs +++ b/Deliveroo/DeliverooPlugin.Supply.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; using Dalamud.Game.ClientState.Objects.Types; -using Dalamud.Memory; using Deliveroo.GameData; using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Component.GUI; +using LLib.GameUI; using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; namespace Deliveroo; @@ -30,8 +30,8 @@ partial class DeliverooPlugin if (addonId == 0) return; - AtkUnitBase* addon = GetAddonById(addonId); - if (addon == null || !IsAddonReady(addon)) + AtkUnitBase* addon = LAddon.GetAddonById(addonId); + if (addon == null || !LAddon.IsAddonReady(addon)) return; // if using haseltweaks, this *can* be the default @@ -73,8 +73,8 @@ partial class DeliverooPlugin if (addonId == 0) return; - AtkUnitBase* addon = GetAddonById(addonId); - if (addon == null || !IsAddonReady(addon)) + AtkUnitBase* addon = LAddon.GetAddonById(addonId); + if (addon == null || !LAddon.IsAddonReady(addon)) return; var addonGc = (AddonGrandCompanySupplyList*)addon; @@ -173,10 +173,10 @@ partial class DeliverooPlugin private unsafe void TurnInSelectedItem() { - if (TryGetAddonByName("GrandCompanySupplyReward", - out var addonSupplyReward) && IsAddonReady(&addonSupplyReward->AtkUnitBase)) + if (_gameGui.TryGetAddonByName("GrandCompanySupplyReward", + out var addonSupplyReward) && LAddon.IsAddonReady(&addonSupplyReward->AtkUnitBase)) { - _pluginLog.Information($"Turning in '{ReadAtkString(addonSupplyReward->AtkUnitBase.AtkValues[4])}'"); + _pluginLog.Information($"Turning in '{addonSupplyReward->AtkUnitBase.AtkValues[4].ReadAtkString()}'"); addonSupplyReward->AtkUnitBase.FireCallbackInt(0); _continueAt = DateTime.Now.AddSeconds(0.58); @@ -186,8 +186,8 @@ partial class DeliverooPlugin private unsafe void FinalizeTurnInItem() { - if (TryGetAddonByName("GrandCompanySupplyList", - out var addonSupplyList) && IsAddonReady(&addonSupplyList->AtkUnitBase)) + if (_gameGui.TryGetAddonByName("GrandCompanySupplyList", + out var addonSupplyList) && LAddon.IsAddonReady(&addonSupplyList->AtkUnitBase)) { var updateFilter = stackalloc AtkValue[] { diff --git a/Deliveroo/DeliverooPlugin.cs b/Deliveroo/DeliverooPlugin.cs index 48b3e9e..d94c5a7 100644 --- a/Deliveroo/DeliverooPlugin.cs +++ b/Deliveroo/DeliverooPlugin.cs @@ -14,6 +14,7 @@ using Deliveroo.GameData; using Deliveroo.Windows; using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Component.GUI; +using LLib.GameUI; using Lumina.Excel.GeneratedSheets; namespace Deliveroo; @@ -207,12 +208,12 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin if (nextItem != null && GetCurrentSealCount() >= _configuration.ReservedSealCount + nextItem.SealCost) CurrentStage = Stage.TargetQuartermaster; - if (TryGetAddonByName("GrandCompanySupplyList", out var gcSupplyList) && - IsAddonReady(&gcSupplyList->AtkUnitBase)) + if (_gameGui.TryGetAddonByName("GrandCompanySupplyList", out var gcSupplyList) && + LAddon.IsAddonReady(&gcSupplyList->AtkUnitBase)) CurrentStage = Stage.SelectExpertDeliveryTab; - if (TryGetAddonByName("GrandCompanyExchange", out var gcExchange) && - IsAddonReady(gcExchange)) + if (_gameGui.TryGetAddonByName("GrandCompanyExchange", out var gcExchange) && + LAddon.IsAddonReady(gcExchange)) CurrentStage = Stage.SelectRewardTier; } diff --git a/LLib b/LLib index e7f5017..abbbec4 160000 --- a/LLib +++ b/LLib @@ -1 +1 @@ -Subproject commit e7f5017cbfb0f52b767640cfd4eb1bc913df248c +Subproject commit abbbec4f26b1a8903b0cd7aa04f00d557602eaf3