diff --git a/XivCommon/Functions/ContextMenu/ContextMenu.cs b/XivCommon/Functions/ContextMenu/ContextMenu.cs index bc5c0f5..a628cd8 100755 --- a/XivCommon/Functions/ContextMenu/ContextMenu.cs +++ b/XivCommon/Functions/ContextMenu/ContextMenu.cs @@ -269,6 +269,13 @@ namespace XivCommon.Functions.ContextMenu { // remove any NormalContextMenuItems that may have been added - these will crash the game args.Items.RemoveAll(item => item is NormalContextMenuItem); + // set the agent of any remaining custom items + foreach (var item in args.Items) { + if (item is InventoryContextMenuItem custom) { + custom.Agent = agent; + } + } + this.Items.AddRange(args.Items); } else { var info = GetAgentInfo(agent); @@ -294,6 +301,13 @@ namespace XivCommon.Functions.ContextMenu { // remove any InventoryContextMenuItems that may have been added - these will crash the game args.Items.RemoveAll(item => item is InventoryContextMenuItem); + // set the agent of any remaining custom items + foreach (var item in args.Items) { + if (item is NormalContextMenuItem custom) { + custom.Agent = agent; + } + } + this.Items.AddRange(args.Items); } @@ -371,13 +385,12 @@ namespace XivCommon.Functions.ContextMenu { switch (item) { // a custom item is being clicked case NormalContextMenuItem custom: { - var (_, agent) = this.GetContextMenuAgent(); var addonName = this.GetParentAddonName(addon); - var info = GetAgentInfo(agent); + var info = GetAgentInfo(custom.Agent); var args = new ContextMenuItemSelectedArgs( addon, - agent, + custom.Agent, addonName, info.actorId, info.contentIdLower, @@ -394,13 +407,12 @@ namespace XivCommon.Functions.ContextMenu { break; } case InventoryContextMenuItem custom: { - var (_, agent) = this.GetContextMenuAgent(); var addonName = this.GetParentAddonName(addon); - var info = GetInventoryAgentInfo(agent); + var info = GetInventoryAgentInfo(custom.Agent); var args = new InventoryContextMenuItemSelectedArgs( addon, - agent, + custom.Agent, addonName, info.itemId, info.itemAmount, diff --git a/XivCommon/Functions/ContextMenu/CustomContextMenuItem.cs b/XivCommon/Functions/ContextMenu/CustomContextMenuItem.cs index b5fbf8c..e7a7a7d 100755 --- a/XivCommon/Functions/ContextMenu/CustomContextMenuItem.cs +++ b/XivCommon/Functions/ContextMenu/CustomContextMenuItem.cs @@ -6,6 +6,8 @@ namespace XivCommon.Functions.ContextMenu { /// public abstract class CustomContextMenuItem : BaseContextMenuItem where T : Delegate { + internal IntPtr Agent { get; set; } + /// /// The name of the context item to be shown for English clients. ///