Dalamud/Dalamud/Game/Text/SeStringHandling/Payloads/DalamudLinkPayload.cs
goat 448b0d16ea
Add "loading dialog" for service init, unify blocking logic (#1779)
* wip

* hacky fix for overlapping event text in profiler

* move IsResumeGameAfterPluginLoad logic to PluginManager

* fix some warnings

* handle exceptions properly

* remove ability to cancel, rename button to "hide" instead

* undo Dalamud.Service refactor for now

* warnings

* add explainer, show which plugins are still loading

* add some text if loading takes more than 3 minutes

* undo wrong CS merge
2024-04-21 17:28:37 +02:00

57 lines
1.7 KiB
C#

using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Dalamud.Game.Text.SeStringHandling.Payloads;
/// <summary>
/// This class represents a custom Dalamud clickable chat link.
/// </summary>
public class DalamudLinkPayload : Payload
{
/// <inheritdoc/>
public override PayloadType Type => PayloadType.DalamudLink;
/// <summary>
/// Gets the plugin command ID to be linked.
/// </summary>
public uint CommandId { get; internal set; } = 0;
/// <summary>
/// Gets the plugin name to be linked.
/// </summary>
public string Plugin { get; internal set; } = string.Empty;
/// <inheritdoc/>
public override string ToString()
{
return $"{this.Type} - Plugin: {this.Plugin}, Command: {this.CommandId}";
}
/// <inheritdoc/>
protected override byte[] EncodeImpl()
{
var pluginBytes = Encoding.UTF8.GetBytes(this.Plugin);
var commandBytes = MakeInteger(this.CommandId);
var chunkLen = 3 + pluginBytes.Length + commandBytes.Length;
if (chunkLen > 255)
{
throw new Exception("Chunk is too long. Plugin name exceeds limits for DalamudLinkPayload");
}
var bytes = new List<byte> { START_BYTE, (byte)SeStringChunkType.Interactable, (byte)chunkLen, (byte)EmbeddedInfoType.DalamudLink };
bytes.Add((byte)pluginBytes.Length);
bytes.AddRange(pluginBytes);
bytes.AddRange(commandBytes);
bytes.Add(END_BYTE);
return bytes.ToArray();
}
/// <inheritdoc/>
protected override void DecodeImpl(BinaryReader reader, long endOfStream)
{
this.Plugin = Encoding.UTF8.GetString(reader.ReadBytes(reader.ReadByte()));
this.CommandId = GetInteger(reader);
}
}