Remove Dalamud Addon class, devs should use AtkUnitBase instead

This commit is contained in:
Raymond 2021-08-16 08:58:50 -04:00
parent e02505985f
commit 7fa5e7adbe
2 changed files with 18 additions and 81 deletions

View file

@ -1,63 +0,0 @@
using System;
using Dalamud.Memory;
namespace Dalamud.Game.Gui.Addons
{
/// <summary>
/// This class represents an in-game UI "Addon".
/// </summary>
public unsafe class Addon
{
/// <summary>
/// Initializes a new instance of the <see cref="Addon"/> class.
/// </summary>
/// <param name="address">The address of the addon.</param>
public Addon(IntPtr address)
{
this.Address = address;
}
/// <summary>
/// Gets the address of the addon.
/// </summary>
public IntPtr Address { get; }
/// <summary>
/// Gets the name of the addon.
/// </summary>
public string Name => MemoryHelper.ReadString((IntPtr)this.Struct->Name, 0x20);
/// <summary>
/// Gets the X position of the addon on screen.
/// </summary>
public short X => this.Struct->X;
/// <summary>
/// Gets the Y position of the addon on screen.
/// </summary>
public short Y => this.Struct->Y;
/// <summary>
/// Gets the scale of the addon.
/// </summary>
public float Scale => this.Struct->Scale;
/// <summary>
/// Gets the width of the addon. This may include non-visible parts.
/// </summary>
public unsafe float Width => this.Struct->RootNode->Width * this.Scale;
/// <summary>
/// Gets the height of the addon. This may include non-visible parts.
/// </summary>
public unsafe float Height => this.Struct->RootNode->Height * this.Scale;
/// <summary>
/// Gets a value indicating whether the addon is visible.
/// </summary>
public bool Visible => this.Struct->IsVisible;
private FFXIVClientStructs.FFXIV.Component.GUI.AtkUnitBase* Struct => (FFXIVClientStructs.FFXIV.Component.GUI.AtkUnitBase*)this.Address;
}
}

View file

@ -11,11 +11,11 @@ using Dalamud.Game.ClientState.JobGauge.Enums;
using Dalamud.Game.ClientState.JobGauge.Types;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Game.Gui.Addons;
using Dalamud.Game.Gui.FlyText;
using Dalamud.Game.Gui.Toast;
using Dalamud.Game.Text;
using Dalamud.Interface.Windowing;
using Dalamud.Memory;
using Dalamud.Plugin;
using Dalamud.Utility;
using ImGuiNET;
@ -45,7 +45,6 @@ namespace Dalamud.Interface.Internal.Windows
private string inputAddonName = string.Empty;
private int inputAddonIndex;
private Addon resultAddon;
private IntPtr findAgentInterfacePtr;
@ -130,7 +129,6 @@ namespace Dalamud.Interface.Internal.Windows
/// <inheritdoc/>
public override void OnClose()
{
this.resultAddon = null;
}
/// <summary>
@ -843,22 +841,31 @@ namespace Dalamud.Interface.Internal.Windows
ImGui.Text($"{command.Key}\n -> {command.Value.HelpMessage}\n -> In help: {command.Value.ShowInHelp}\n\n");
}
private void DrawAddon()
private unsafe void DrawAddon()
{
var gameGui = this.dalamud.Framework.Gui;
ImGui.InputText("Addon name", ref this.inputAddonName, 256);
ImGui.InputInt("Addon Index", ref this.inputAddonIndex);
if (ImGui.Button("Get Addon"))
if (this.inputAddonName.IsNullOrEmpty())
return;
var address = gameGui.GetAddonByName(this.inputAddonName, this.inputAddonIndex);
if (address == IntPtr.Zero)
{
this.resultAddon = this.dalamud.Framework.Gui.GetAddonByName(this.inputAddonName, this.inputAddonIndex);
ImGui.Text("Null");
return;
}
if (ImGui.Button("Find Agent"))
this.findAgentInterfacePtr = this.dalamud.Framework.Gui.FindAgentInterface(this.inputAddonName);
var addon = (FFXIVClientStructs.FFXIV.Component.GUI.AtkUnitBase*)address;
var name = MemoryHelper.ReadStringNullTerminated((IntPtr)addon->Name);
ImGui.TextUnformatted($"{name} - 0x{address.ToInt64():x}\n v:{addon->IsVisible} x:{addon->X} y:{addon->Y} s:{addon->Scale}, w:{addon->RootNode->Width}, h:{addon->RootNode->Height}");
if (this.resultAddon != null)
if (ImGui.Button("Find Agent"))
{
ImGui.TextUnformatted($"{this.resultAddon.Name} - 0x{this.resultAddon.Address.ToInt64():x}\n v:{this.resultAddon.Visible} x:{this.resultAddon.X} y:{this.resultAddon.Y} s:{this.resultAddon.Scale}, w:{this.resultAddon.Width}, h:{this.resultAddon.Height}");
this.findAgentInterfacePtr = gameGui.FindAgentInterface(address);
}
if (this.findAgentInterfacePtr != IntPtr.Zero)
@ -869,13 +876,6 @@ namespace Dalamud.Interface.Internal.Windows
if (ImGui.Button("C"))
ImGui.SetClipboardText(this.findAgentInterfacePtr.ToInt64().ToString("x"));
}
if (ImGui.Button("Get Base UI object"))
{
var addr = this.dalamud.Framework.Gui.GetBaseUIObject().ToInt64().ToString("x");
Log.Information("{0}", addr);
ImGui.SetClipboardText(addr);
}
}
private void DrawAddonInspector()
@ -977,7 +977,7 @@ namespace Dalamud.Interface.Internal.Windows
if (ImGui.BeginCombo("Kind", this.flyKind.ToString()))
{
var names = Enum.GetNames(typeof(FlyTextKind));
for (int i = 0; i < names.Length; i++)
for (var i = 0; i < names.Length; i++)
{
if (ImGui.Selectable($"{names[i]} ({i})"))
this.flyKind = (FlyTextKind)i;