diff --git a/Dalamud/Game/Gui/ChatGui.cs b/Dalamud/Game/Gui/ChatGui.cs index 6de4e3c3f..72b8ef8d1 100644 --- a/Dalamud/Game/Gui/ChatGui.cs +++ b/Dalamud/Game/Gui/ChatGui.cs @@ -41,7 +41,7 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui private static readonly ModuleLog Log = new("ChatGui"); private readonly Queue chatQueue = new(); - private readonly Dictionary<(string PluginName, Guid CommandId), Action> dalamudLinkHandlers = new(); + private readonly Dictionary<(string PluginName, uint CommandId), Action> dalamudLinkHandlers = new(); private readonly Hook printMessageHook; private readonly Hook inventoryItemCopyHook; @@ -50,7 +50,8 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui [ServiceManager.ServiceDependency] private readonly DalamudConfiguration configuration = Service.Get(); - private ImmutableDictionary<(string PluginName, Guid CommandId), Action>? dalamudLinkHandlersCopy; + private ImmutableDictionary<(string PluginName, uint CommandId), Action>? dalamudLinkHandlersCopy; + private uint dalamudChatHandlerId = 1000; [ServiceManager.ServiceConstructor] private ChatGui() @@ -86,7 +87,7 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui public byte LastLinkedItemFlags { get; private set; } /// - public IReadOnlyDictionary<(string PluginName, Guid CommandId), Action> RegisteredLinkHandlers + public IReadOnlyDictionary<(string PluginName, uint CommandId), Action> RegisteredLinkHandlers { get { @@ -164,19 +165,33 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui #region Chat Links - /// - public DalamudLinkPayload AddChatLinkHandler(Action commandAction) + /// + /// Register a chat link handler. + /// + /// Internal use only. + /// The action to be executed. + /// Returns an SeString payload for the link. + public DalamudLinkPayload AddChatLinkHandler(Action commandAction) { - return this.AddChatLinkHandler("Dalamud", commandAction); + return this.AddChatLinkHandler("Dalamud", this.dalamudChatHandlerId++, commandAction); } /// - public void RemoveChatLinkHandler(Guid commandId) + /// Internal use only. + public DalamudLinkPayload AddChatLinkHandler(uint commandId, Action commandAction) + { + return this.AddChatLinkHandler("Dalamud", commandId, commandAction); + } + + /// + /// Internal use only. + public void RemoveChatLinkHandler(uint commandId) { this.RemoveChatLinkHandler("Dalamud", commandId); } /// + /// Internal use only. public void RemoveChatLinkHandler() { this.RemoveChatLinkHandler("Dalamud"); @@ -240,11 +255,11 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui /// Create a link handler. /// /// The name of the plugin handling the link. + /// The ID of the command to run. /// The command action itself. /// A payload for handling. - internal DalamudLinkPayload AddChatLinkHandler(string pluginName, Action commandAction) + internal DalamudLinkPayload AddChatLinkHandler(string pluginName, uint commandId, Action commandAction) { - var commandId = Guid.CreateVersion7(); var payload = new DalamudLinkPayload { Plugin = pluginName, CommandId = commandId }; lock (this.dalamudLinkHandlers) { @@ -277,7 +292,7 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui /// /// The name of the plugin handling the link. /// The ID of the command to be removed. - internal void RemoveChatLinkHandler(string pluginName, Guid commandId) + internal void RemoveChatLinkHandler(string pluginName, uint commandId) { lock (this.dalamudLinkHandlers) { @@ -534,7 +549,7 @@ internal class ChatGuiPluginScoped : IInternalDisposableService, IChatGui public byte LastLinkedItemFlags => this.chatGuiService.LastLinkedItemFlags; /// - public IReadOnlyDictionary<(string PluginName, Guid CommandId), Action> RegisteredLinkHandlers => this.chatGuiService.RegisteredLinkHandlers; + public IReadOnlyDictionary<(string PluginName, uint CommandId), Action> RegisteredLinkHandlers => this.chatGuiService.RegisteredLinkHandlers; /// void IInternalDisposableService.DisposeService() @@ -551,11 +566,11 @@ internal class ChatGuiPluginScoped : IInternalDisposableService, IChatGui } /// - public DalamudLinkPayload AddChatLinkHandler(Action commandAction) - => this.chatGuiService.AddChatLinkHandler(this.plugin.InternalName, commandAction); + public DalamudLinkPayload AddChatLinkHandler(uint commandId, Action commandAction) + => this.chatGuiService.AddChatLinkHandler(this.plugin.InternalName, commandId, commandAction); /// - public void RemoveChatLinkHandler(Guid commandId) + public void RemoveChatLinkHandler(uint commandId) => this.chatGuiService.RemoveChatLinkHandler(this.plugin.InternalName, commandId); /// diff --git a/Dalamud/Game/Text/SeStringHandling/Payloads/DalamudLinkPayload.cs b/Dalamud/Game/Text/SeStringHandling/Payloads/DalamudLinkPayload.cs index ee06172b4..8b020b111 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payloads/DalamudLinkPayload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payloads/DalamudLinkPayload.cs @@ -16,7 +16,7 @@ public class DalamudLinkPayload : Payload public override PayloadType Type => PayloadType.DalamudLink; /// Gets the plugin command ID to be linked. - public Guid CommandId { get; internal set; } + public uint CommandId { get; internal set; } /// Gets an optional extra integer value 1. public int Extra1 { get; internal set; } @@ -40,7 +40,7 @@ public class DalamudLinkPayload : Payload var ssb = Lumina.Text.SeStringBuilder.SharedPool.Get(); var res = ssb.BeginMacro(MacroCode.Link) .AppendIntExpression((int)EmbeddedInfoType.DalamudLink - 1) - .AppendStringExpression(this.CommandId.ToString()) + .AppendUIntExpression(this.CommandId) .AppendIntExpression(this.Extra1) .AppendIntExpression(this.Extra2) .BeginStringExpression() @@ -72,15 +72,15 @@ public class DalamudLinkPayload : Payload if (!pluginExpression.TryGetString(out var pluginString)) return; - if (!commandIdExpression.TryGetString(out var commandId)) + if (!commandIdExpression.TryGetUInt(out var commandId)) return; this.Plugin = pluginString.ExtractText(); - this.CommandId = Guid.Parse(commandId.ExtractText()); + this.CommandId = commandId; } else { - if (!commandIdExpression.TryGetString(out var commandId)) + if (!commandIdExpression.TryGetUInt(out var commandId)) return; if (!extra1Expression.TryGetInt(out var extra1)) @@ -102,7 +102,7 @@ public class DalamudLinkPayload : Payload return; } - this.CommandId = Guid.Parse(commandId.ExtractText()); + this.CommandId = commandId; this.Extra1 = extra1; this.Extra2 = extra2; this.Plugin = extraData[0]; diff --git a/Dalamud/Plugin/Services/IChatGui.cs b/Dalamud/Plugin/Services/IChatGui.cs index ab595dc3f..c474ca386 100644 --- a/Dalamud/Plugin/Services/IChatGui.cs +++ b/Dalamud/Plugin/Services/IChatGui.cs @@ -83,20 +83,21 @@ public interface IChatGui /// /// Gets the dictionary of Dalamud Link Handlers. /// - public IReadOnlyDictionary<(string PluginName, Guid CommandId), Action> RegisteredLinkHandlers { get; } + public IReadOnlyDictionary<(string PluginName, uint CommandId), Action> RegisteredLinkHandlers { get; } /// /// Register a chat link handler. /// + /// The ID of the command. /// The action to be executed. /// Returns an SeString payload for the link. - public DalamudLinkPayload AddChatLinkHandler(Action commandAction); + public DalamudLinkPayload AddChatLinkHandler(uint commandId, Action commandAction); /// /// Remove a chat link handler. /// /// The ID of the command. - public void RemoveChatLinkHandler(Guid commandId); + public void RemoveChatLinkHandler(uint commandId); /// /// Removes all chat link handlers registered by the plugin.