From 0483840197e72b0991abb4d2265bcc76252829fb Mon Sep 17 00:00:00 2001 From: goaaats Date: Fri, 15 Apr 2022 21:32:13 +0200 Subject: [PATCH] fix: correct FindAgentInterface --- Dalamud/Game/Gui/GameGui.cs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Dalamud/Game/Gui/GameGui.cs b/Dalamud/Game/Gui/GameGui.cs index de5dc411c..70501b2fc 100644 --- a/Dalamud/Game/Gui/GameGui.cs +++ b/Dalamud/Game/Gui/GameGui.cs @@ -15,6 +15,8 @@ using Dalamud.IoC; using Dalamud.IoC.Internal; using Dalamud.Utility; using FFXIVClientStructs.FFXIV.Client.System.String; +using FFXIVClientStructs.FFXIV.Client.UI; +using FFXIVClientStructs.FFXIV.Component.GUI; using ImGuiNET; using Serilog; @@ -386,12 +388,12 @@ namespace Dalamud.Game.Gui /// /// The addon address. /// A pointer to the agent interface. - public unsafe IntPtr FindAgentInterface(IntPtr addon) + public unsafe IntPtr FindAgentInterface(IntPtr addonPtr) { - if (addon == IntPtr.Zero) + if (addonPtr == IntPtr.Zero) return IntPtr.Zero; - var uiModule = (FFXIVClientStructs.FFXIV.Client.UI.UIModule*)this.GetUIModule(); + var uiModule = (UIModule*)this.GetUIModule(); if (uiModule == null) return IntPtr.Zero; @@ -399,21 +401,20 @@ namespace Dalamud.Game.Gui if (agentModule == null) return IntPtr.Zero; - var unitBase = (FFXIVClientStructs.FFXIV.Component.GUI.AtkUnitBase*)addon; - var id = unitBase->ParentID; - if (id == 0) - { - id = unitBase->ID; - if (id == 0) - return IntPtr.Zero; - } + var addon = (AtkUnitBase*)addonPtr; + var addonId = addon->ParentID == 0 ? addon->ID : addon->ParentID; - // Patch 6.1, 398 agents - for (var i = 0; i < 398; i++) - { - var agent = &agentModule->AgentArray[i]; + if (addonId == 0) + return IntPtr.Zero; - if (agent->AddonId == id) + var index = 0; + while (true) + { + var agent = agentModule->GetAgentByInternalID((uint)index++); + if (agent == uiModule || agent == null) + break; + + if (agent->AddonId == addonId) return new IntPtr(agent); }