Restore commandId parameter (#2349)

This commit is contained in:
Haselnussbomber 2025-08-07 04:17:34 +02:00 committed by GitHub
parent 0ca890ebca
commit 27f924f3b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 additions and 23 deletions

View file

@ -41,7 +41,7 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui
private static readonly ModuleLog Log = new("ChatGui"); private static readonly ModuleLog Log = new("ChatGui");
private readonly Queue<XivChatEntry> chatQueue = new(); private readonly Queue<XivChatEntry> chatQueue = new();
private readonly Dictionary<(string PluginName, Guid CommandId), Action<Guid, SeString>> dalamudLinkHandlers = new(); private readonly Dictionary<(string PluginName, uint CommandId), Action<uint, SeString>> dalamudLinkHandlers = new();
private readonly Hook<PrintMessageDelegate> printMessageHook; private readonly Hook<PrintMessageDelegate> printMessageHook;
private readonly Hook<InventoryItem.Delegates.Copy> inventoryItemCopyHook; private readonly Hook<InventoryItem.Delegates.Copy> inventoryItemCopyHook;
@ -50,7 +50,8 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui
[ServiceManager.ServiceDependency] [ServiceManager.ServiceDependency]
private readonly DalamudConfiguration configuration = Service<DalamudConfiguration>.Get(); private readonly DalamudConfiguration configuration = Service<DalamudConfiguration>.Get();
private ImmutableDictionary<(string PluginName, Guid CommandId), Action<Guid, SeString>>? dalamudLinkHandlersCopy; private ImmutableDictionary<(string PluginName, uint CommandId), Action<uint, SeString>>? dalamudLinkHandlersCopy;
private uint dalamudChatHandlerId = 1000;
[ServiceManager.ServiceConstructor] [ServiceManager.ServiceConstructor]
private ChatGui() private ChatGui()
@ -86,7 +87,7 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui
public byte LastLinkedItemFlags { get; private set; } public byte LastLinkedItemFlags { get; private set; }
/// <inheritdoc/> /// <inheritdoc/>
public IReadOnlyDictionary<(string PluginName, Guid CommandId), Action<Guid, SeString>> RegisteredLinkHandlers public IReadOnlyDictionary<(string PluginName, uint CommandId), Action<uint, SeString>> RegisteredLinkHandlers
{ {
get get
{ {
@ -164,19 +165,33 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui
#region Chat Links #region Chat Links
/// <inheritdoc/> /// <summary>
public DalamudLinkPayload AddChatLinkHandler(Action<Guid, SeString> commandAction) /// Register a chat link handler.
/// </summary>
/// <remarks>Internal use only.</remarks>
/// <param name="commandAction">The action to be executed.</param>
/// <returns>Returns an SeString payload for the link.</returns>
public DalamudLinkPayload AddChatLinkHandler(Action<uint, SeString> commandAction)
{ {
return this.AddChatLinkHandler("Dalamud", commandAction); return this.AddChatLinkHandler("Dalamud", this.dalamudChatHandlerId++, commandAction);
} }
/// <inheritdoc/> /// <inheritdoc/>
public void RemoveChatLinkHandler(Guid commandId) /// <remarks>Internal use only.</remarks>
public DalamudLinkPayload AddChatLinkHandler(uint commandId, Action<uint, SeString> commandAction)
{
return this.AddChatLinkHandler("Dalamud", commandId, commandAction);
}
/// <inheritdoc/>
/// <remarks>Internal use only.</remarks>
public void RemoveChatLinkHandler(uint commandId)
{ {
this.RemoveChatLinkHandler("Dalamud", commandId); this.RemoveChatLinkHandler("Dalamud", commandId);
} }
/// <inheritdoc/> /// <inheritdoc/>
/// <remarks>Internal use only.</remarks>
public void RemoveChatLinkHandler() public void RemoveChatLinkHandler()
{ {
this.RemoveChatLinkHandler("Dalamud"); this.RemoveChatLinkHandler("Dalamud");
@ -240,11 +255,11 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui
/// Create a link handler. /// Create a link handler.
/// </summary> /// </summary>
/// <param name="pluginName">The name of the plugin handling the link.</param> /// <param name="pluginName">The name of the plugin handling the link.</param>
/// <param name="commandId">The ID of the command to run.</param>
/// <param name="commandAction">The command action itself.</param> /// <param name="commandAction">The command action itself.</param>
/// <returns>A payload for handling.</returns> /// <returns>A payload for handling.</returns>
internal DalamudLinkPayload AddChatLinkHandler(string pluginName, Action<Guid, SeString> commandAction) internal DalamudLinkPayload AddChatLinkHandler(string pluginName, uint commandId, Action<uint, SeString> commandAction)
{ {
var commandId = Guid.CreateVersion7();
var payload = new DalamudLinkPayload { Plugin = pluginName, CommandId = commandId }; var payload = new DalamudLinkPayload { Plugin = pluginName, CommandId = commandId };
lock (this.dalamudLinkHandlers) lock (this.dalamudLinkHandlers)
{ {
@ -277,7 +292,7 @@ internal sealed unsafe class ChatGui : IInternalDisposableService, IChatGui
/// </summary> /// </summary>
/// <param name="pluginName">The name of the plugin handling the link.</param> /// <param name="pluginName">The name of the plugin handling the link.</param>
/// <param name="commandId">The ID of the command to be removed.</param> /// <param name="commandId">The ID of the command to be removed.</param>
internal void RemoveChatLinkHandler(string pluginName, Guid commandId) internal void RemoveChatLinkHandler(string pluginName, uint commandId)
{ {
lock (this.dalamudLinkHandlers) lock (this.dalamudLinkHandlers)
{ {
@ -534,7 +549,7 @@ internal class ChatGuiPluginScoped : IInternalDisposableService, IChatGui
public byte LastLinkedItemFlags => this.chatGuiService.LastLinkedItemFlags; public byte LastLinkedItemFlags => this.chatGuiService.LastLinkedItemFlags;
/// <inheritdoc/> /// <inheritdoc/>
public IReadOnlyDictionary<(string PluginName, Guid CommandId), Action<Guid, SeString>> RegisteredLinkHandlers => this.chatGuiService.RegisteredLinkHandlers; public IReadOnlyDictionary<(string PluginName, uint CommandId), Action<uint, SeString>> RegisteredLinkHandlers => this.chatGuiService.RegisteredLinkHandlers;
/// <inheritdoc/> /// <inheritdoc/>
void IInternalDisposableService.DisposeService() void IInternalDisposableService.DisposeService()
@ -551,11 +566,11 @@ internal class ChatGuiPluginScoped : IInternalDisposableService, IChatGui
} }
/// <inheritdoc/> /// <inheritdoc/>
public DalamudLinkPayload AddChatLinkHandler(Action<Guid, SeString> commandAction) public DalamudLinkPayload AddChatLinkHandler(uint commandId, Action<uint, SeString> commandAction)
=> this.chatGuiService.AddChatLinkHandler(this.plugin.InternalName, commandAction); => this.chatGuiService.AddChatLinkHandler(this.plugin.InternalName, commandId, commandAction);
/// <inheritdoc/> /// <inheritdoc/>
public void RemoveChatLinkHandler(Guid commandId) public void RemoveChatLinkHandler(uint commandId)
=> this.chatGuiService.RemoveChatLinkHandler(this.plugin.InternalName, commandId); => this.chatGuiService.RemoveChatLinkHandler(this.plugin.InternalName, commandId);
/// <inheritdoc/> /// <inheritdoc/>

View file

@ -16,7 +16,7 @@ public class DalamudLinkPayload : Payload
public override PayloadType Type => PayloadType.DalamudLink; public override PayloadType Type => PayloadType.DalamudLink;
/// <summary>Gets the plugin command ID to be linked.</summary> /// <summary>Gets the plugin command ID to be linked.</summary>
public Guid CommandId { get; internal set; } public uint CommandId { get; internal set; }
/// <summary>Gets an optional extra integer value 1.</summary> /// <summary>Gets an optional extra integer value 1.</summary>
public int Extra1 { get; internal set; } public int Extra1 { get; internal set; }
@ -40,7 +40,7 @@ public class DalamudLinkPayload : Payload
var ssb = Lumina.Text.SeStringBuilder.SharedPool.Get(); var ssb = Lumina.Text.SeStringBuilder.SharedPool.Get();
var res = ssb.BeginMacro(MacroCode.Link) var res = ssb.BeginMacro(MacroCode.Link)
.AppendIntExpression((int)EmbeddedInfoType.DalamudLink - 1) .AppendIntExpression((int)EmbeddedInfoType.DalamudLink - 1)
.AppendStringExpression(this.CommandId.ToString()) .AppendUIntExpression(this.CommandId)
.AppendIntExpression(this.Extra1) .AppendIntExpression(this.Extra1)
.AppendIntExpression(this.Extra2) .AppendIntExpression(this.Extra2)
.BeginStringExpression() .BeginStringExpression()
@ -72,15 +72,15 @@ public class DalamudLinkPayload : Payload
if (!pluginExpression.TryGetString(out var pluginString)) if (!pluginExpression.TryGetString(out var pluginString))
return; return;
if (!commandIdExpression.TryGetString(out var commandId)) if (!commandIdExpression.TryGetUInt(out var commandId))
return; return;
this.Plugin = pluginString.ExtractText(); this.Plugin = pluginString.ExtractText();
this.CommandId = Guid.Parse(commandId.ExtractText()); this.CommandId = commandId;
} }
else else
{ {
if (!commandIdExpression.TryGetString(out var commandId)) if (!commandIdExpression.TryGetUInt(out var commandId))
return; return;
if (!extra1Expression.TryGetInt(out var extra1)) if (!extra1Expression.TryGetInt(out var extra1))
@ -102,7 +102,7 @@ public class DalamudLinkPayload : Payload
return; return;
} }
this.CommandId = Guid.Parse(commandId.ExtractText()); this.CommandId = commandId;
this.Extra1 = extra1; this.Extra1 = extra1;
this.Extra2 = extra2; this.Extra2 = extra2;
this.Plugin = extraData[0]; this.Plugin = extraData[0];

View file

@ -83,20 +83,21 @@ public interface IChatGui
/// <summary> /// <summary>
/// Gets the dictionary of Dalamud Link Handlers. /// Gets the dictionary of Dalamud Link Handlers.
/// </summary> /// </summary>
public IReadOnlyDictionary<(string PluginName, Guid CommandId), Action<Guid, SeString>> RegisteredLinkHandlers { get; } public IReadOnlyDictionary<(string PluginName, uint CommandId), Action<uint, SeString>> RegisteredLinkHandlers { get; }
/// <summary> /// <summary>
/// Register a chat link handler. /// Register a chat link handler.
/// </summary> /// </summary>
/// <param name="commandId">The ID of the command.</param>
/// <param name="commandAction">The action to be executed.</param> /// <param name="commandAction">The action to be executed.</param>
/// <returns>Returns an SeString payload for the link.</returns> /// <returns>Returns an SeString payload for the link.</returns>
public DalamudLinkPayload AddChatLinkHandler(Action<Guid, SeString> commandAction); public DalamudLinkPayload AddChatLinkHandler(uint commandId, Action<uint, SeString> commandAction);
/// <summary> /// <summary>
/// Remove a chat link handler. /// Remove a chat link handler.
/// </summary> /// </summary>
/// <param name="commandId">The ID of the command.</param> /// <param name="commandId">The ID of the command.</param>
public void RemoveChatLinkHandler(Guid commandId); public void RemoveChatLinkHandler(uint commandId);
/// <summary> /// <summary>
/// Removes all chat link handlers registered by the plugin. /// Removes all chat link handlers registered by the plugin.