From ee99fe4499535e7744a9b05623685defb48617b9 Mon Sep 17 00:00:00 2001 From: Raymond Date: Mon, 9 Aug 2021 18:45:55 -0400 Subject: [PATCH] Live addon rework --- .../Gui/Addon => Gui/Addons}/Addon.cs | 41 ++++++------ Dalamud/Game/Internal/Gui/Structs/Addon.cs | 66 ------------------- .../Interface/Internal/Windows/DataWindow.cs | 23 ++++--- 3 files changed, 34 insertions(+), 96 deletions(-) rename Dalamud/Game/{Internal/Gui/Addon => Gui/Addons}/Addon.cs (56%) delete mode 100644 Dalamud/Game/Internal/Gui/Structs/Addon.cs diff --git a/Dalamud/Game/Internal/Gui/Addon/Addon.cs b/Dalamud/Game/Gui/Addons/Addon.cs similarity index 56% rename from Dalamud/Game/Internal/Gui/Addon/Addon.cs rename to Dalamud/Game/Gui/Addons/Addon.cs index 5a0c4ce98..207443b8b 100644 --- a/Dalamud/Game/Internal/Gui/Addon/Addon.cs +++ b/Dalamud/Game/Gui/Addons/Addon.cs @@ -1,66 +1,63 @@ using System; -namespace Dalamud.Game.Internal.Gui.Addon +using Dalamud.Memory; + +namespace Dalamud.Game.Gui.Addons { /// /// This class represents an in-game UI "Addon". /// - public class Addon + public unsafe class Addon { - /// - /// The address of the addon. - /// - public IntPtr Address; - - /// - /// The addon interop data. - /// - protected Structs.Addon addonStruct; - /// /// Initializes a new instance of the class. /// /// The address of the addon. - /// The addon interop data. - public Addon(IntPtr address, Structs.Addon addonStruct) + public Addon(IntPtr address) { this.Address = address; - this.addonStruct = addonStruct; } + /// + /// Gets the address of the addon. + /// + public IntPtr Address { get; } + /// /// Gets the name of the addon. /// - public string Name => this.addonStruct.Name; + public string Name => MemoryHelper.ReadString((IntPtr)this.Struct->Name, 0x20); /// /// Gets the X position of the addon on screen. /// - public short X => this.addonStruct.X; + public short X => this.Struct->X; /// /// Gets the Y position of the addon on screen. /// - public short Y => this.addonStruct.Y; + public short Y => this.Struct->Y; /// /// Gets the scale of the addon. /// - public float Scale => this.addonStruct.Scale; + public float Scale => this.Struct->Scale; /// /// Gets the width of the addon. This may include non-visible parts. /// - public unsafe float Width => this.addonStruct.RootNode->Width * this.Scale; + public unsafe float Width => this.Struct->RootNode->Width * this.Scale; /// /// Gets the height of the addon. This may include non-visible parts. /// - public unsafe float Height => this.addonStruct.RootNode->Height * this.Scale; + public unsafe float Height => this.Struct->RootNode->Height * this.Scale; /// /// Gets a value indicating whether the addon is visible. /// - public bool Visible => (this.addonStruct.Flags & 0x20) == 0x20; + public bool Visible => this.Struct->IsVisible; + + private FFXIVClientStructs.FFXIV.Component.GUI.AtkUnitBase* Struct => (FFXIVClientStructs.FFXIV.Component.GUI.AtkUnitBase*)this.Address; } } diff --git a/Dalamud/Game/Internal/Gui/Structs/Addon.cs b/Dalamud/Game/Internal/Gui/Structs/Addon.cs deleted file mode 100644 index 57595a2c7..000000000 --- a/Dalamud/Game/Internal/Gui/Structs/Addon.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System.Runtime.InteropServices; - -using FFXIVClientStructs.FFXIV.Component.GUI; - -namespace Dalamud.Game.Internal.Gui.Structs -{ - /// - /// Native memory representation of an FFXIV UI addon. - /// - [StructLayout(LayoutKind.Explicit)] - public struct Addon - { - /// - /// The name of the addon. - /// - [FieldOffset(AddonOffsets.Name)] - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] - public string Name; - - /// - /// Various flags that can be set on the addon. - /// - /// - /// This is a bitfield. - /// - [FieldOffset(AddonOffsets.Flags)] - public byte Flags; - - /// - /// The X position of the addon on screen. - /// - [FieldOffset(AddonOffsets.X)] - public short X; - - /// - /// The Y position of the addon on screen. - /// - [FieldOffset(AddonOffsets.Y)] - public short Y; - - /// - /// The scale of the addon. - /// - [FieldOffset(AddonOffsets.Scale)] - public float Scale; - - /// - /// The root node of the addon's node tree. - /// - [FieldOffset(AddonOffsets.RootNode)] - public unsafe AtkResNode* RootNode; - } - - /// - /// Memory offsets for the type. - /// - public static class AddonOffsets - { - public const int Name = 0x8; - public const int RootNode = 0xC8; - public const int Flags = 0x182; - public const int X = 0x1BC; - public const int Y = 0x1BE; - public const int Scale = 0x1AC; - } -} diff --git a/Dalamud/Interface/Internal/Windows/DataWindow.cs b/Dalamud/Interface/Internal/Windows/DataWindow.cs index e4c9ab03f..ac06d5139 100644 --- a/Dalamud/Interface/Internal/Windows/DataWindow.cs +++ b/Dalamud/Interface/Internal/Windows/DataWindow.cs @@ -9,8 +9,8 @@ using Dalamud.Game.ClientState; using Dalamud.Game.ClientState.Actors.Types; using Dalamud.Game.ClientState.Actors.Types.NonPlayer; using Dalamud.Game.ClientState.Structs.JobGauge; +using Dalamud.Game.Gui.Addons; using Dalamud.Game.Gui.Toast; -using Dalamud.Game.Internal.Gui.Addon; using Dalamud.Game.Text; using Dalamud.Interface.Windowing; using Dalamud.Plugin; @@ -104,6 +104,17 @@ namespace Dalamud.Interface.Internal.Windows Gamepad, } + /// + public override void OnOpen() + { + } + + /// + public override void OnClose() + { + this.resultAddon = null; + } + /// /// Set the DataKind dropdown menu. /// @@ -562,9 +573,7 @@ namespace Dalamud.Interface.Internal.Windows if (ImGui.Button("Get Addon")) { - this.resultAddon = - this.dalamud.Framework.Gui.GetAddonByName( - this.inputAddonName, this.inputAddonIndex); + this.resultAddon = this.dalamud.Framework.Gui.GetAddonByName(this.inputAddonName, this.inputAddonIndex); } if (ImGui.Button("Find Agent")) @@ -572,14 +581,12 @@ namespace Dalamud.Interface.Internal.Windows if (this.resultAddon != null) { - 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}"); + 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}"); } if (this.findAgentInterfacePtr != IntPtr.Zero) { - ImGui.TextUnformatted( - $"Agent: 0x{this.findAgentInterfacePtr.ToInt64():x}"); + ImGui.TextUnformatted($"Agent: 0x{this.findAgentInterfacePtr.ToInt64():x}"); ImGui.SameLine(); if (ImGui.Button("C"))