diff --git a/Dalamud/Game/Internal/Gui/GameGui.cs b/Dalamud/Game/Internal/Gui/GameGui.cs index 16e2ed3e3..521ea8179 100644 --- a/Dalamud/Game/Internal/Gui/GameGui.cs +++ b/Dalamud/Game/Internal/Gui/GameGui.cs @@ -48,6 +48,14 @@ namespace Dalamud.Game.Internal.Gui { private delegate IntPtr ToggleUiHideDelegate(IntPtr thisPtr, byte unknownByte); private readonly Hook toggleUiHideHook; + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + private delegate IntPtr GetBaseUIObjectDelegate(); + private readonly GetBaseUIObjectDelegate getBaseUIObject; + + [UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Ansi)] + private delegate IntPtr GetUIObjectByNameDelegate(IntPtr thisPtr, string uiName, int index); + private readonly GetUIObjectByNameDelegate getUIObjectByName; + public bool GameUiHidden { get; private set; } /// @@ -103,6 +111,9 @@ namespace Dalamud.Game.Internal.Gui { Marshal.GetDelegateForFunctionPointer(Address.ScreenToWorld); this.toggleUiHideHook = new Hook(Address.ToggleUiHide, new ToggleUiHideDelegate(ToggleUiHideDetour), this); + + this.getBaseUIObject = Marshal.GetDelegateForFunctionPointer(Address.GetBaseUIObject); + this.getUIObjectByName = Marshal.GetDelegateForFunctionPointer(Address.GetUIObjectByName); } private IntPtr HandleSetGlobalBgmDetour(UInt16 bgmKey, byte a2, UInt32 a3, UInt32 a4, UInt32 a5, byte a6) { @@ -306,6 +317,20 @@ namespace Dalamud.Game.Internal.Gui { return this.toggleUiHideHook.Original(thisPtr, unknownByte); } + /// + /// Gets the pointer to the UI Object with the given name and index. + /// + /// Name of UI to find + /// Index of UI to find (1-indexed) + /// IntPtr.Zero if unable to find UI, otherwise IntPtr pointing to the start of the UI Object + public IntPtr GetUiObjectByName(string name, int index) { + var baseUi = this.getBaseUIObject(); + if (baseUi == IntPtr.Zero) return IntPtr.Zero; + var baseUiProperties = Marshal.ReadIntPtr(baseUi, 0x20); + if (baseUiProperties == IntPtr.Zero) return IntPtr.Zero; + return this.getUIObjectByName(baseUiProperties, name, index); + } + public void SetBgm(ushort bgmKey) => this.setGlobalBgmHook.Original(bgmKey, 0, 0, 0, 0, 0); public void Enable() { diff --git a/Dalamud/Game/Internal/Gui/GameGuiAddressResolver.cs b/Dalamud/Game/Internal/Gui/GameGuiAddressResolver.cs index 3da0ecc8a..47e758da7 100644 --- a/Dalamud/Game/Internal/Gui/GameGuiAddressResolver.cs +++ b/Dalamud/Game/Internal/Gui/GameGuiAddressResolver.cs @@ -15,6 +15,8 @@ namespace Dalamud.Game.Internal.Gui { public IntPtr GetMatrixSingleton { get; private set; } public IntPtr ScreenToWorld { get; private set; } public IntPtr ToggleUiHide { get; set; } + public IntPtr GetBaseUIObject { get; private set; } + public IntPtr GetUIObjectByName { get; private set; } public GameGuiAddressResolver(IntPtr baseAddress) { BaseAddress = baseAddress; @@ -37,6 +39,8 @@ namespace Dalamud.Game.Internal.Gui { GetMatrixSingleton = sig.ScanText("E8 ?? ?? ?? ?? 48 8D 4C 24 ?? 48 89 4c 24 ?? 4C 8D 4D ?? 4C 8D 44 24 ??"); ScreenToWorld = sig.ScanText("48 83 EC 48 48 8B 05 ?? ?? ?? ?? 4D 8B D1"); ToggleUiHide = sig.ScanText("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 0F B6 B9 ?? ?? ?? ?? B8 ?? ?? ?? ??"); + GetBaseUIObject = sig.ScanText("E8 ?? ?? ?? ?? 41 B8 01 00 00 00 48 8D 15 ?? ?? ?? ?? 48 8B 48 20 E8 ?? ?? ?? ?? 48 8B CF"); + GetUIObjectByName = sig.ScanText("E8 ?? ?? ?? ?? 48 8B CF 48 89 87 ?? ?? 00 00 E8 ?? ?? ?? ?? 41 B8 01 00 00 00"); } } }