From abbbec4f26b1a8903b0cd7aa04f00d557602eaf3 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Wed, 11 Oct 2023 03:21:19 +0200 Subject: [PATCH] Add GameUI Helpers --- GameUI/LAddon.cs | 50 +++++++++++++++++++++++++++++++++++++++++++++ GameUI/LAtkValue.cs | 14 +++++++++++++ LLib.csproj | 4 ---- 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 GameUI/LAddon.cs create mode 100644 GameUI/LAtkValue.cs diff --git a/GameUI/LAddon.cs b/GameUI/LAddon.cs new file mode 100644 index 0000000..ee9e078 --- /dev/null +++ b/GameUI/LAddon.cs @@ -0,0 +1,50 @@ +using System; +using System.Linq; +using Dalamud.Plugin.Services; +using FFXIVClientStructs.FFXIV.Component.GUI; + +namespace LLib.GameUI; + +public static class LAddon +{ + private const int UnitListCount = 18; + public static 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; + } + + public static unsafe bool TryGetAddonByName(this IGameGui gameGui, 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; + } + } + + public static unsafe bool IsAddonReady(AtkUnitBase* addon) + { + return addon->IsVisible && addon->UldManager.LoadedState == AtkLoadState.Loaded; + } +} diff --git a/GameUI/LAtkValue.cs b/GameUI/LAtkValue.cs new file mode 100644 index 0000000..427e7f6 --- /dev/null +++ b/GameUI/LAtkValue.cs @@ -0,0 +1,14 @@ +using Dalamud.Memory; +using FFXIVClientStructs.FFXIV.Component.GUI; + +namespace LLib.GameUI; + +public static class LAtkValue +{ + public static unsafe string? ReadAtkString(this AtkValue atkValue) + { + if (atkValue.String != null) + return MemoryHelper.ReadSeStringNullTerminated(new nint(atkValue.String)).ToString(); + return null; + } +} diff --git a/LLib.csproj b/LLib.csproj index 698c0b8..ce1667e 100644 --- a/LLib.csproj +++ b/LLib.csproj @@ -46,8 +46,4 @@ false - - - -