diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenu.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenu.cs index 401c2cbce..5c9d1223f 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenu.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenu.cs @@ -12,7 +12,7 @@ using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using FFXIVClientStructs.FFXIV.Component.GUI; using Serilog; -using SignatureHelper = Dalamud.Utility.Signatures.SignatureHelper; + using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; namespace Dalamud.Game.Gui.ContextMenus @@ -48,7 +48,6 @@ namespace Dalamud.Game.Gui.ContextMenus /// /// Initializes a new instance of the class. /// - /// Address resolver for context menu hooks. public ContextMenu() { this.Address = new ContextMenuAddressResolver(); @@ -66,7 +65,6 @@ namespace Dalamud.Game.Gui.ContextMenus } } - #region Delegates private unsafe delegate bool OpenSubContextMenuDelegate(AgentContext* agentContext); diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenuAddressResolver.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenuAddressResolver.cs index 29f3e21b2..6bd0f6f72 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenuAddressResolver.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenuAddressResolver.cs @@ -2,9 +2,11 @@ namespace Dalamud.Game.Gui.ContextMenus { + /// + /// Address resolver for context menu functions. + /// public class ContextMenuAddressResolver : BaseAddressResolver { - private const string SigOpenSubContextMenu = "E8 ?? ?? ?? ?? 44 39 A3 ?? ?? ?? ?? 0F 86"; private const string SigContextMenuOpening = "E8 ?? ?? ?? ?? 0F B7 C0 48 83 C4 60"; private const string SigContextMenuOpened = "48 8B C4 57 41 56 41 57 48 81 EC"; @@ -12,18 +14,37 @@ namespace Dalamud.Game.Gui.ContextMenus private const string SigSubContextMenuOpening = "E8 ?? ?? ?? ?? 44 39 A3 ?? ?? ?? ?? 0F 84"; private const string SigSubContextMenuOpened = "48 8B C4 57 41 55 41 56 48 81 EC"; + /// + /// Gets the OpenSubContextMenu function address. + /// public IntPtr OpenSubContextMenuPtr { get; private set; } + /// + /// Gets the ContextMenuOpening function address. + /// public IntPtr ContextMenuOpeningPtr { get; private set; } + /// + /// Gets the ContextMenuOpened function address. + /// public IntPtr ContextMenuOpenedPtr { get; private set; } + /// + /// Gets the ContextMenuItemSelected function address. + /// public IntPtr ContextMenuItemSelectedPtr { get; private set; } + /// + /// Gets the SubContextMenuOpening function address. + /// public IntPtr SubContextMenuOpeningPtr { get; private set; } + /// + /// Gets the SubContextMenuOpened function address. + /// public IntPtr SubContextMenuOpenedPtr { get; private set; } + /// protected override void Setup64Bit(SigScanner scanner) { this.OpenSubContextMenuPtr = scanner.ScanText(SigOpenSubContextMenu); diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenuItem.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenuItem.cs index f2a24aa53..dcf094e04 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenuItem.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenuItem.cs @@ -1,7 +1,6 @@ using System.Numerics; -using Dalamud.Game.Text; + using Dalamud.Game.Text.SeStringHandling; -using Dalamud.Game.Text.SeStringHandling.Payloads; namespace Dalamud.Game.Gui.ContextMenus { diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenuItemIndicator.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenuItemIndicator.cs index b48c96cb7..cdd2aa694 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenuItemIndicator.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenuItemIndicator.cs @@ -9,13 +9,15 @@ /// The item has no indicator. /// None, + /// /// The item has a previous indicator. /// Previous, + /// /// The item has a next indicator. /// - Next + Next, } } diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenuOpenedArgs.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenuOpenedArgs.cs index aecc7141c..66043c814 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenuOpenedArgs.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenuOpenedArgs.cs @@ -1,8 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; + using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI.Agent; -using FFXIVClientStructs.FFXIV.Component.GUI; namespace Dalamud.Game.Gui.ContextMenus { diff --git a/Dalamud/Game/Gui/ContextMenus/ContextMenuReaderWriter.cs b/Dalamud/Game/Gui/ContextMenus/ContextMenuReaderWriter.cs index 3b03117c4..16f24365d 100644 --- a/Dalamud/Game/Gui/ContextMenus/ContextMenuReaderWriter.cs +++ b/Dalamud/Game/Gui/ContextMenus/ContextMenuReaderWriter.cs @@ -14,6 +14,9 @@ using ValueType = FFXIVClientStructs.FFXIV.Component.GUI.ValueType; namespace Dalamud.Game.Gui.ContextMenus { + /// + /// Class responsible for reading and writing to context menu data. + /// internal unsafe class ContextMenuReaderWriter { private readonly AgentContextInterface* agentContextInterface; @@ -42,12 +45,24 @@ namespace Dalamud.Game.Gui.ContextMenus Alternate, } + /// + /// Gets the number of AtkValues for this context menu. + /// public int AtkValueCount => this.atkValueCount; + /// + /// Gets the AtkValues for this context menu. + /// public AtkValue* AtkValues => this.atkValues; + /// + /// Gets the amount of items in the context menu. + /// public int ContextMenuItemCount => this.atkValues[0].Int; + /// + /// Gets a value indicating whether the context menu has a title. + /// public bool HasTitle { get @@ -61,6 +76,9 @@ namespace Dalamud.Game.Gui.ContextMenus } } + /// + /// Gets the title of the context menu. + /// public SeString? Title { get @@ -75,32 +93,9 @@ namespace Dalamud.Game.Gui.ContextMenus } } - public int HasPreviousIndicatorFlagsIndex - { - get - { - if (this.HasTitle) - { - return 6; - } - - return 2; - } - } - - public int HasNextIndicatorFlagsIndex - { - get - { - if (this.HasTitle) - { - return 5; - } - - return 3; - } - } - + /// + /// Gets the index of the first context menu item. + /// public int FirstContextMenuItemIndex { get @@ -114,7 +109,46 @@ namespace Dalamud.Game.Gui.ContextMenus } } - public int NameIndexOffset + /// + /// Gets the position of the context menu. + /// + public Vector2? Position + { + get + { + if (this.HasTitle) return new Vector2(this.atkValues[2].Int, this.atkValues[3].Int); + + return null; + } + } + + private int HasPreviousIndicatorFlagsIndex + { + get + { + if (this.HasTitle) + { + return 6; + } + + return 2; + } + } + + private int HasNextIndicatorFlagsIndex + { + get + { + if (this.HasTitle) + { + return 5; + } + + return 3; + } + } + + private int NameIndexOffset { get { @@ -127,7 +161,7 @@ namespace Dalamud.Game.Gui.ContextMenus } } - public int IsDisabledIndexOffset + private int IsDisabledIndexOffset { get { @@ -140,6 +174,7 @@ namespace Dalamud.Game.Gui.ContextMenus } } + /* /// /// 0x14000000 | action /// @@ -152,8 +187,9 @@ namespace Dalamud.Game.Gui.ContextMenus return null; } } + */ - public int SequentialAtkValuesPerContextMenuItem + private int SequentialAtkValuesPerContextMenuItem { get { @@ -163,7 +199,7 @@ namespace Dalamud.Game.Gui.ContextMenus } } - public int TotalDesiredAtkValuesPerContextMenuItem + private int TotalDesiredAtkValuesPerContextMenuItem { get { @@ -173,17 +209,7 @@ namespace Dalamud.Game.Gui.ContextMenus } } - public Vector2? Position - { - get - { - if (this.HasTitle) return new Vector2(this.atkValues[2].Int, this.atkValues[3].Int); - - return null; - } - } - - public unsafe bool IsInventoryContext + private bool IsInventoryContext { get { @@ -200,58 +226,48 @@ namespace Dalamud.Game.Gui.ContextMenus { get { - if (HasTitle) + if (this.HasTitle) { if (this.atkValues[7].Int == 8) - { return SubContextMenuStructLayout.Alternate; - } - else if (this.atkValues[7].Int == 1) - { - return SubContextMenuStructLayout.Main; - } + + if (this.atkValues[7].Int == 1) return SubContextMenuStructLayout.Main; } return null; } } - public byte NoopAction + private byte NoopAction { get { - if (IsInventoryContext) - { + if (this.IsInventoryContext) return 0xff; - } - else - { - return 0x67; - } + return 0x67; } } - public byte OpenSubContextMenuAction + private byte OpenSubContextMenuAction { get { - if (IsInventoryContext) + if (this.IsInventoryContext) { // This is actually the action to open the Second Tier context menu and we just hack around it return 0x31; } - else - { - return 0x66; - } + + return 0x66; } } - public byte? FirstUnhandledAction + private byte? FirstUnhandledAction { get { - if (this.StructLayout is SubContextMenuStructLayout.Alternate) return 0x68; + if (this.StructLayout is SubContextMenuStructLayout.Alternate) + return 0x68; return null; } @@ -334,6 +350,11 @@ namespace Dalamud.Game.Gui.ContextMenus return gameContextMenuItems.ToArray(); } + /// + /// Write items to the context menu. + /// + /// The items to write. + /// Whether or not reallocation is allowed. public void Write(IEnumerable contextMenuItems, bool allowReallocate = true) { if (allowReallocate) @@ -353,7 +374,7 @@ namespace Dalamud.Game.Gui.ContextMenus // Zero the memory, then copy the atk values up to the first context menu item atk value Marshal.Copy(new byte[newAtkValuesArraySize], 0, newAtkValuesArray, newAtkValuesArraySize); - Buffer.MemoryCopy(this.atkValues, newAtkValues, newAtkValuesArraySize - arrayCountSize, (long)sizeof(AtkValue) * FirstContextMenuItemIndex); + Buffer.MemoryCopy(this.atkValues, newAtkValues, newAtkValuesArraySize - arrayCountSize, (long)sizeof(AtkValue) * this.FirstContextMenuItemIndex); // Free the old array var oldArray = (IntPtr)this.atkValues - arrayCountSize; @@ -467,12 +488,13 @@ namespace Dalamud.Game.Gui.ContextMenus } } - public void Log() + /* + private void Log() { Log(this.atkValueCount, this.atkValues); } - public static void Log(int atkValueCount, AtkValue* atkValues) + private static void Log(int atkValueCount, AtkValue* atkValues) { PluginLog.Debug($"ContextMenuReader.Log"); @@ -515,5 +537,6 @@ namespace Dalamud.Game.Gui.ContextMenus PluginLog.Debug($"atkValues[{atkValueIndex}]={(IntPtr)atkValue:X} {atkValue->Type}={value}"); } } + */ } } diff --git a/Dalamud/Game/Gui/ContextMenus/CustomContextMenuItem.cs b/Dalamud/Game/Gui/ContextMenus/CustomContextMenuItem.cs index 7b9575a6a..50a5c0a9f 100644 --- a/Dalamud/Game/Gui/ContextMenus/CustomContextMenuItem.cs +++ b/Dalamud/Game/Gui/ContextMenus/CustomContextMenuItem.cs @@ -9,11 +9,6 @@ namespace Dalamud.Game.Gui.ContextMenus /// public class CustomContextMenuItem : ContextMenuItem { - /// - /// The action that will be called when the item is selected. - /// - public CustomContextMenuItemSelectedDelegate ItemSelected { get; } - /// /// Initializes a new instance of the class. /// @@ -22,15 +17,21 @@ namespace Dalamud.Game.Gui.ContextMenus internal CustomContextMenuItem(SeString name, CustomContextMenuItemSelectedDelegate itemSelected) : base(new SeString().Append(new UIForegroundPayload(539)).Append($"{SeIconChar.BoxedLetterD.ToIconString()} ").Append(new UIForegroundPayload(0)).Append(name)) { - ItemSelected = itemSelected; + this.ItemSelected = itemSelected; } + /// + /// Gets the action that will be called when the item is selected. + /// + public CustomContextMenuItemSelectedDelegate ItemSelected { get; } + + /// public override int GetHashCode() { unchecked { - int hash = base.GetHashCode(); - hash = hash * 23 + ItemSelected.GetHashCode(); + var hash = base.GetHashCode(); + hash = (hash * 23) + this.ItemSelected.GetHashCode(); return hash; } } diff --git a/Dalamud/Game/Gui/ContextMenus/CustomContextMenuItemSelectedArgs.cs b/Dalamud/Game/Gui/ContextMenus/CustomContextMenuItemSelectedArgs.cs index dc54c0a5e..a73f0364a 100644 --- a/Dalamud/Game/Gui/ContextMenus/CustomContextMenuItemSelectedArgs.cs +++ b/Dalamud/Game/Gui/ContextMenus/CustomContextMenuItemSelectedArgs.cs @@ -5,16 +5,6 @@ /// public class CustomContextMenuItemSelectedArgs { - /// - /// The currently opened context menu. - /// - public ContextMenuOpenedArgs ContextMenuOpenedArgs { get; init; } - - /// - /// The selected item within the currently opened context menu. - /// - public CustomContextMenuItem SelectedItem { get; init; } - /// /// Initializes a new instance of the class. /// @@ -22,8 +12,18 @@ /// The selected item within the currently opened context menu. public CustomContextMenuItemSelectedArgs(ContextMenuOpenedArgs contextMenuOpenedArgs, CustomContextMenuItem selectedItem) { - ContextMenuOpenedArgs = contextMenuOpenedArgs; - SelectedItem = selectedItem; + this.ContextMenuOpenedArgs = contextMenuOpenedArgs; + this.SelectedItem = selectedItem; } + + /// + /// Gets the currently opened context menu. + /// + public ContextMenuOpenedArgs ContextMenuOpenedArgs { get; init; } + + /// + /// Gets the selected item within the currently opened context menu. + /// + public CustomContextMenuItem SelectedItem { get; init; } } } diff --git a/Dalamud/Game/Gui/ContextMenus/GameContextMenuItem.cs b/Dalamud/Game/Gui/ContextMenus/GameContextMenuItem.cs index bc77db5cc..5c8628701 100644 --- a/Dalamud/Game/Gui/ContextMenus/GameContextMenuItem.cs +++ b/Dalamud/Game/Gui/ContextMenus/GameContextMenuItem.cs @@ -7,11 +7,6 @@ namespace Dalamud.Game.Gui.ContextMenus /// public class GameContextMenuItem : ContextMenuItem { - /// - /// The game action that will be handled when the item is selected. - /// - public byte SelectedAction { get; } - /// /// Initializes a new instance of the class. /// @@ -20,15 +15,21 @@ namespace Dalamud.Game.Gui.ContextMenus public GameContextMenuItem(SeString name, byte selectedAction) : base(name) { - SelectedAction = selectedAction; + this.SelectedAction = selectedAction; } + /// + /// Gets the game action that will be handled when the item is selected. + /// + public byte SelectedAction { get; } + + /// public override int GetHashCode() { unchecked { - int hash = base.GetHashCode(); - hash = hash * 23 + SelectedAction; + var hash = base.GetHashCode(); + hash = (hash * 23) + this.SelectedAction; return hash; } } diff --git a/Dalamud/Game/Gui/ContextMenus/InventoryItemContext.cs b/Dalamud/Game/Gui/ContextMenus/InventoryItemContext.cs index b9f3fb3b6..96d80f18a 100644 --- a/Dalamud/Game/Gui/ContextMenus/InventoryItemContext.cs +++ b/Dalamud/Game/Gui/ContextMenus/InventoryItemContext.cs @@ -5,21 +5,6 @@ /// public class InventoryItemContext { - /// - /// The id of the item. - /// - public uint Id { get; } - - /// - /// The count of the item in the stack. - /// - public uint Count { get; } - - /// - /// Whether the item is high quality. - /// - public bool IsHighQuality { get; } - /// /// Initializes a new instance of the class. /// @@ -28,9 +13,24 @@ /// Whether the item is high quality. public InventoryItemContext(uint id, uint count, bool isHighQuality) { - Id = id; - Count = count; - IsHighQuality = isHighQuality; + this.Id = id; + this.Count = count; + this.IsHighQuality = isHighQuality; } + + /// + /// Gets the id of the item. + /// + public uint Id { get; } + + /// + /// Gets the count of the item in the stack. + /// + public uint Count { get; } + + /// + /// Gets a value indicating whether the item is high quality. + /// + public bool IsHighQuality { get; } } } diff --git a/Dalamud/Game/Gui/ContextMenus/OpenSubContextMenuItem.cs b/Dalamud/Game/Gui/ContextMenus/OpenSubContextMenuItem.cs index 859e9cf73..8e7258b4f 100644 --- a/Dalamud/Game/Gui/ContextMenus/OpenSubContextMenuItem.cs +++ b/Dalamud/Game/Gui/ContextMenus/OpenSubContextMenuItem.cs @@ -7,11 +7,6 @@ namespace Dalamud.Game.Gui.ContextMenus /// public class OpenSubContextMenuItem : ContextMenuItem { - /// - /// The action that will be called when the item is selected. - /// - public ContextMenuOpenedDelegate Opened { get; set; } - /// /// Initializes a new instance of the class. /// @@ -20,16 +15,22 @@ namespace Dalamud.Game.Gui.ContextMenus internal OpenSubContextMenuItem(SeString name, ContextMenuOpenedDelegate opened) : base(name) { - Opened = opened; - Indicator = ContextMenuItemIndicator.Next; + this.Opened = opened; + this.Indicator = ContextMenuItemIndicator.Next; } + /// + /// Gets the action that will be called when the item is selected. + /// + public ContextMenuOpenedDelegate Opened { get; } + + /// public override int GetHashCode() { unchecked { int hash = base.GetHashCode(); - hash = hash * 23 + Opened.GetHashCode(); + hash = (hash * 23) + this.Opened.GetHashCode(); return hash; } } diff --git a/Dalamud/Game/Gui/GameGui.cs b/Dalamud/Game/Gui/GameGui.cs index a4bd7abc1..78a199b20 100644 --- a/Dalamud/Game/Gui/GameGui.cs +++ b/Dalamud/Game/Gui/GameGui.cs @@ -1,6 +1,7 @@ using System; using System.Numerics; using System.Runtime.InteropServices; + using Dalamud.Game.Gui.ContextMenus; using Dalamud.Game.Gui.FlyText; using Dalamud.Game.Gui.PartyFinder; diff --git a/Dalamud/Game/Text/SeIconCharExtensions.cs b/Dalamud/Game/Text/SeIconCharExtensions.cs index cee45e9d5..648b332c2 100644 --- a/Dalamud/Game/Text/SeIconCharExtensions.cs +++ b/Dalamud/Game/Text/SeIconCharExtensions.cs @@ -1,7 +1,7 @@ namespace Dalamud.Game.Text { /// - /// Extension methods for + /// Extension methods for . /// public static class SeIconCharExtensions { diff --git a/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/ContextMenuAgingStep.cs b/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/ContextMenuAgingStep.cs index 9e085fbe2..630df5ecc 100644 --- a/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/ContextMenuAgingStep.cs +++ b/Dalamud/Interface/Internal/Windows/SelfTest/AgingSteps/ContextMenuAgingStep.cs @@ -1,13 +1,11 @@ using System; -using System.Runtime.CompilerServices; + using Dalamud.Data; using Dalamud.Game.Gui.ContextMenus; using Dalamud.Utility; using ImGuiNET; using Lumina.Excel.GeneratedSheets; -using Lumina.Text; using Serilog; -using SeString = Dalamud.Game.Text.SeStringHandling.SeString; namespace Dalamud.Interface.Internal.Windows.SelfTest.AgingSteps {