Add Generic Helper (#2403)
Some checks failed
Tag Build / Tag Build (push) Successful in 3s
Build Dalamud / Build on Windows (push) Has been cancelled
Build Dalamud / Check API Compatibility (push) Has been cancelled
Build Dalamud / Deploy dalamud-distrib staging (push) Has been cancelled

This commit is contained in:
MidoriKami 2025-09-09 00:53:38 -07:00 committed by GitHub
parent 0047e24031
commit f07b308757
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View file

@ -182,6 +182,10 @@ internal sealed unsafe class GameGui : IInternalDisposableService, IGameGui
return (nint)unitManager->GetAddonByName(name, index);
}
/// <inheritdoc/>
public T* GetAddonByName<T>(string name, int index = 1) where T : unmanaged
=> (T*)this.GetAddonByName(name, index).Address;
/// <inheritdoc/>
public AgentInterfacePtr GetAgentById(int id)
{
@ -328,7 +332,7 @@ internal sealed unsafe class GameGui : IInternalDisposableService, IGameGui
return retVal;
}
private unsafe void SetUiVisibilityDetour(RaptureAtkModule* thisPtr, bool uiVisible)
private void SetUiVisibilityDetour(RaptureAtkModule* thisPtr, bool uiVisible)
{
this.setUiVisibilityHook.Original(thisPtr, uiVisible);
@ -441,6 +445,10 @@ internal class GameGuiPluginScoped : IInternalDisposableService, IGameGui
public AtkUnitBasePtr GetAddonByName(string name, int index = 1)
=> this.gameGuiService.GetAddonByName(name, index);
/// <inheritdoc/>
public unsafe T* GetAddonByName<T>(string name, int index = 1) where T : unmanaged
=> (T*)this.gameGuiService.GetAddonByName(name, index).Address;
/// <inheritdoc/>
public AgentInterfacePtr GetAgentById(int id)
=> this.gameGuiService.GetAgentById(id);

View file

@ -36,7 +36,7 @@ public unsafe interface IGameGui
/// If > 1.000.000, subtract 1.000.000 and treat it as HQ.
/// </summary>
public ulong HoveredItem { get; set; }
/// <summary>
/// Gets the action ID that is current hovered by the player. 0 when no action is hovered.
/// </summary>
@ -89,6 +89,15 @@ public unsafe interface IGameGui
/// <returns>A pointer wrapper to the addon.</returns>
public AtkUnitBasePtr GetAddonByName(string name, int index = 1);
/// <summary>
/// Gets the pointer to the Addon with the given name and index.
/// </summary>
/// <param name="name">Name of addon to find.</param>
/// <param name="index">Index of addon to find (1-indexed).</param>
/// <returns>A pointer wrapper to the addon.</returns>
/// <typeparam name="T">Type of addon pointer AtkUnitBase or any derived struct.</typeparam>
public T* GetAddonByName<T>(string name, int index = 1) where T : unmanaged;
/// <summary>
/// Find the agent associated with an addon, if possible.
/// </summary>