From d3e875c372edb14b24081608ed744d2af95e5f12 Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Wed, 28 Apr 2021 23:57:46 -0400 Subject: [PATCH] fix: add limit to context menu items --- XivCommon/Functions/ContextMenu.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/XivCommon/Functions/ContextMenu.cs b/XivCommon/Functions/ContextMenu.cs index 88ed3fc..089ed39 100755 --- a/XivCommon/Functions/ContextMenu.cs +++ b/XivCommon/Functions/ContextMenu.cs @@ -23,6 +23,8 @@ namespace XivCommon.Functions { internal const string GetAddonByInternalId = "E8 ?? ?? ?? ?? 8B 6B 20"; } + private const int MaxItems = 32; + /// /// Offset from addon to menu type /// @@ -186,12 +188,19 @@ namespace XivCommon.Functions { try { this.OpenContextMenu?.Invoke(args); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in OpenMenuDetour"); + Logger.LogError(ex, "Exception in OpenMenuDetour"); goto Original; } this.Items.AddRange(args.AdditionalItems); + if (this.NormalSize + this.Items.Count > MaxItems) { + var toKeep = MaxItems - this.NormalSize; + var toRemove = this.Items.Count - toKeep; + this.Items.RemoveRange(toKeep, toRemove); + Logger.LogWarning($"Context menu item limit ({MaxItems}) exceeded. Removing {toRemove} item(s)."); + } + var hasCustomDisabled = this.Items.Any(item => !item.Enabled); var hasAnyDisabled = hasGameDisabled || hasCustomDisabled; @@ -272,7 +281,7 @@ namespace XivCommon.Functions { info.actorWorld )); } catch (Exception ex) { - PluginLog.LogError(ex, "Exception in custom context menu item"); + Logger.LogError(ex, "Exception in custom context menu item"); } }