LLib/GameUI/LAddon.cs

55 lines
1.5 KiB
C#
Raw Normal View History

2023-10-11 01:21:19 +00:00
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;
2024-03-20 18:10:35 +00:00
2023-10-11 01:21:19 +00:00
public static unsafe AtkUnitBase* GetAddonById(uint id)
{
2024-07-02 15:35:40 +00:00
var unitManagers = &AtkStage.Instance()->RaptureAtkUnitManager->AtkUnitManager.DepthLayerOneList;
2023-10-11 01:21:19 +00:00
for (var i = 0; i < UnitListCount; i++)
{
var unitManager = &unitManagers[i];
2024-07-02 15:35:40 +00:00
foreach (var j in Enumerable.Range(0, Math.Min(unitManager->Count, unitManager->Entries.Length)))
2023-10-11 01:21:19 +00:00
{
2024-07-02 15:35:40 +00:00
var unitBase = unitManager->Entries[j].Value;
if (unitBase != null && unitBase->Id == id)
2023-10-11 01:21:19 +00:00
{
return unitBase;
}
}
}
return null;
}
public static unsafe bool TryGetAddonByName<T>(this IGameGui gameGui, string addonName, out T* addonPtr)
where T : unmanaged
{
2024-03-20 18:10:35 +00:00
ArgumentNullException.ThrowIfNull(gameGui);
ArgumentException.ThrowIfNullOrEmpty(addonName);
2023-10-11 01:21:19 +00:00
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;
}
}