From f07b308757ec12490bb65ad25eff2592bc8afd27 Mon Sep 17 00:00:00 2001
From: MidoriKami <9083275+MidoriKami@users.noreply.github.com>
Date: Tue, 9 Sep 2025 00:53:38 -0700
Subject: [PATCH] Add Generic Helper (#2403)
---
Dalamud/Game/Gui/GameGui.cs | 10 +++++++++-
Dalamud/Plugin/Services/IGameGui.cs | 11 ++++++++++-
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/Dalamud/Game/Gui/GameGui.cs b/Dalamud/Game/Gui/GameGui.cs
index 415dd44c6..4da7b6857 100644
--- a/Dalamud/Game/Gui/GameGui.cs
+++ b/Dalamud/Game/Gui/GameGui.cs
@@ -182,6 +182,10 @@ internal sealed unsafe class GameGui : IInternalDisposableService, IGameGui
return (nint)unitManager->GetAddonByName(name, index);
}
+ ///
+ public T* GetAddonByName(string name, int index = 1) where T : unmanaged
+ => (T*)this.GetAddonByName(name, index).Address;
+
///
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);
+ ///
+ public unsafe T* GetAddonByName(string name, int index = 1) where T : unmanaged
+ => (T*)this.gameGuiService.GetAddonByName(name, index).Address;
+
///
public AgentInterfacePtr GetAgentById(int id)
=> this.gameGuiService.GetAgentById(id);
diff --git a/Dalamud/Plugin/Services/IGameGui.cs b/Dalamud/Plugin/Services/IGameGui.cs
index 773ba61b4..e2326328a 100644
--- a/Dalamud/Plugin/Services/IGameGui.cs
+++ b/Dalamud/Plugin/Services/IGameGui.cs
@@ -36,7 +36,7 @@ public unsafe interface IGameGui
/// If > 1.000.000, subtract 1.000.000 and treat it as HQ.
///
public ulong HoveredItem { get; set; }
-
+
///
/// Gets the action ID that is current hovered by the player. 0 when no action is hovered.
///
@@ -89,6 +89,15 @@ public unsafe interface IGameGui
/// A pointer wrapper to the addon.
public AtkUnitBasePtr GetAddonByName(string name, int index = 1);
+ ///
+ /// Gets the pointer to the Addon with the given name and index.
+ ///
+ /// Name of addon to find.
+ /// Index of addon to find (1-indexed).
+ /// A pointer wrapper to the addon.
+ /// Type of addon pointer AtkUnitBase or any derived struct.
+ public T* GetAddonByName(string name, int index = 1) where T : unmanaged;
+
///
/// Find the agent associated with an addon, if possible.
///