fix: add limit to context menu items

This commit is contained in:
Anna 2021-04-28 23:57:46 -04:00
parent 4b14302bf7
commit d3e875c372
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0

View File

@ -23,6 +23,8 @@ namespace XivCommon.Functions {
internal const string GetAddonByInternalId = "E8 ?? ?? ?? ?? 8B 6B 20"; internal const string GetAddonByInternalId = "E8 ?? ?? ?? ?? 8B 6B 20";
} }
private const int MaxItems = 32;
/// <summary> /// <summary>
/// Offset from addon to menu type /// Offset from addon to menu type
/// </summary> /// </summary>
@ -186,12 +188,19 @@ namespace XivCommon.Functions {
try { try {
this.OpenContextMenu?.Invoke(args); this.OpenContextMenu?.Invoke(args);
} catch (Exception ex) { } catch (Exception ex) {
PluginLog.LogError(ex, "Exception in OpenMenuDetour"); Logger.LogError(ex, "Exception in OpenMenuDetour");
goto Original; goto Original;
} }
this.Items.AddRange(args.AdditionalItems); 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 hasCustomDisabled = this.Items.Any(item => !item.Enabled);
var hasAnyDisabled = hasGameDisabled || hasCustomDisabled; var hasAnyDisabled = hasGameDisabled || hasCustomDisabled;
@ -272,7 +281,7 @@ namespace XivCommon.Functions {
info.actorWorld info.actorWorld
)); ));
} catch (Exception ex) { } catch (Exception ex) {
PluginLog.LogError(ex, "Exception in custom context menu item"); Logger.LogError(ex, "Exception in custom context menu item");
} }
} }