53 lines
1.3 KiB
C#
53 lines
1.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Dalamud.Game.NativeWrapper;
|
|
using Dalamud.Plugin.Services;
|
|
using FFXIVClientStructs.FFXIV.Component.GUI;
|
|
|
|
namespace LLib.GameUI;
|
|
|
|
public static class LAddon
|
|
{
|
|
private const int UnitListCount = 18;
|
|
|
|
public unsafe static AtkUnitBase* GetAddonById(uint id)
|
|
{
|
|
AtkUnitList* ptr = &AtkStage.Instance()->RaptureAtkUnitManager->AtkUnitManager.DepthLayerOneList;
|
|
for (int i = 0; i < 18; i++)
|
|
{
|
|
AtkUnitList* ptr2 = ptr + i;
|
|
foreach (int item in Enumerable.Range(0, Math.Min(ptr2->Count, ptr2->Entries.Length)))
|
|
{
|
|
AtkUnitBase* value = ptr2->Entries[item].Value;
|
|
if (value != null && value->Id == id)
|
|
{
|
|
return value;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public unsafe static bool TryGetAddonByName<T>(this IGameGui gameGui, string addonName, out T* addonPtr) where T : unmanaged
|
|
{
|
|
ArgumentNullException.ThrowIfNull(gameGui, "gameGui");
|
|
ArgumentException.ThrowIfNullOrEmpty(addonName, "addonName");
|
|
AtkUnitBasePtr addonByName = gameGui.GetAddonByName(addonName);
|
|
if (!addonByName.IsNull)
|
|
{
|
|
addonPtr = (T*)addonByName.Address;
|
|
return true;
|
|
}
|
|
addonPtr = null;
|
|
return false;
|
|
}
|
|
|
|
public unsafe static bool IsAddonReady(AtkUnitBase* addon)
|
|
{
|
|
if (addon->IsVisible)
|
|
{
|
|
return addon->UldManager.LoadedState == AtkLoadState.Loaded;
|
|
}
|
|
return false;
|
|
}
|
|
}
|