From 5c4ed3f715829d92098b5173b4720b7159f4694c Mon Sep 17 00:00:00 2001 From: Raymond Date: Thu, 15 Jul 2021 22:09:31 -0400 Subject: [PATCH] XivChatEntry should use SeString --- Dalamud/Game/ChatHandlers.cs | 6 +++--- Dalamud/Game/Internal/Gui/ChatGui.cs | 12 ++++++------ Dalamud/Game/Text/SeStringHandling/Payload.cs | 2 +- .../Text/SeStringHandling/Payloads/NewLinePayload.cs | 4 ++-- Dalamud/Game/Text/SeStringHandling/SeString.cs | 9 +++++++++ Dalamud/Game/Text/XivChatEntry.cs | 8 +++++--- Dalamud/Plugin/Internal/PluginManager.cs | 2 +- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Dalamud/Game/ChatHandlers.cs b/Dalamud/Game/ChatHandlers.cs index 9fa2411df..e85d80db4 100644 --- a/Dalamud/Game/ChatHandlers.cs +++ b/Dalamud/Game/ChatHandlers.cs @@ -257,7 +257,7 @@ namespace Dalamud.Game { this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry { - MessageBytes = Encoding.UTF8.GetBytes(Loc.Localize("DalamudUpdated", "The In-Game addon has been updated or was reinstalled successfully! Please check the discord for a full changelog.")), + Message = Loc.Localize("DalamudUpdated", "The In-Game addon has been updated or was reinstalled successfully! Please check the discord for a full changelog."), Type = XivChatType.Notice, }); @@ -289,7 +289,7 @@ namespace Dalamud.Game { this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry { - MessageBytes = new SeString(new List() + Message = new SeString(new List() { new TextPayload(Loc.Localize("DalamudPluginUpdateRequired", "One or more of your plugins needs to be updated. Please use the /xlplugins command in-game to update them!")), new TextPayload(" ["), @@ -299,7 +299,7 @@ namespace Dalamud.Game RawPayload.LinkTerminator, new UIForegroundPayload(this.dalamud.Data, 0), new TextPayload("]"), - }).Encode(), + }), Type = XivChatType.Urgent, }); } diff --git a/Dalamud/Game/Internal/Gui/ChatGui.cs b/Dalamud/Game/Internal/Gui/ChatGui.cs index cd4220e0d..09aa234eb 100644 --- a/Dalamud/Game/Internal/Gui/ChatGui.cs +++ b/Dalamud/Game/Internal/Gui/ChatGui.cs @@ -184,7 +184,7 @@ namespace Dalamud.Game.Internal.Gui Log.Verbose("[CHATGUI PRINT REGULAR]{0}", message); this.PrintChat(new XivChatEntry { - MessageBytes = Encoding.UTF8.GetBytes(message), + Message = message, Type = this.dalamud.Configuration.GeneralChatType, }); } @@ -199,7 +199,7 @@ namespace Dalamud.Game.Internal.Gui Log.Verbose("[CHATGUI PRINT SESTRING]{0}", message.TextValue); this.PrintChat(new XivChatEntry { - MessageBytes = message.Encode(), + Message = message, Type = this.dalamud.Configuration.GeneralChatType, }); } @@ -214,7 +214,7 @@ namespace Dalamud.Game.Internal.Gui Log.Verbose("[CHATGUI PRINT REGULAR ERROR]{0}", message); this.PrintChat(new XivChatEntry { - MessageBytes = Encoding.UTF8.GetBytes(message), + Message = message, Type = XivChatType.Urgent, }); } @@ -229,7 +229,7 @@ namespace Dalamud.Game.Internal.Gui Log.Verbose("[CHATGUI PRINT SESTRING ERROR]{0}", message.TextValue); this.PrintChat(new XivChatEntry { - MessageBytes = message.Encode(), + Message = message, Type = XivChatType.Urgent, }); } @@ -249,10 +249,10 @@ namespace Dalamud.Game.Internal.Gui continue; } - var senderRaw = Encoding.UTF8.GetBytes(chat.Name ?? string.Empty); + var senderRaw = (chat.Name ?? string.Empty).Encode(); using var senderOwned = framework.Libc.NewString(senderRaw); - var messageRaw = chat.MessageBytes ?? Array.Empty(); + var messageRaw = (chat.Message ?? string.Empty).Encode(); using var messageOwned = framework.Libc.NewString(messageRaw); this.HandlePrintMessageDetour(this.baseAddress, chat.Type, senderOwned.Address, messageOwned.Address, chat.SenderId, chat.Parameters); diff --git a/Dalamud/Game/Text/SeStringHandling/Payload.cs b/Dalamud/Game/Text/SeStringHandling/Payload.cs index 36c0e213c..ebf689646 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payload.cs @@ -300,7 +300,7 @@ namespace Dalamud.Game.Text.SeStringHandling EmphasisItalic = 0x1A, /// - /// See the + /// See the . /// NewLine = 0x10, diff --git a/Dalamud/Game/Text/SeStringHandling/Payloads/NewLinePayload.cs b/Dalamud/Game/Text/SeStringHandling/Payloads/NewLinePayload.cs index 48e2c8215..13aba8077 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payloads/NewLinePayload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payloads/NewLinePayload.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace Dalamud.Game.Text.SeStringHandling.Payloads @@ -16,7 +16,7 @@ namespace Dalamud.Game.Text.SeStringHandling.Payloads public static NewLinePayload Payload => new(); /// - /// Gets the text of this payload, evaluates to Environment.NewLine + /// Gets the text of this payload, evaluates to Environment.NewLine. /// public string Text => Environment.NewLine; diff --git a/Dalamud/Game/Text/SeStringHandling/SeString.cs b/Dalamud/Game/Text/SeStringHandling/SeString.cs index 43ae7600e..77ec5fed6 100644 --- a/Dalamud/Game/Text/SeStringHandling/SeString.cs +++ b/Dalamud/Game/Text/SeStringHandling/SeString.cs @@ -13,6 +13,15 @@ namespace Dalamud.Game.Text.SeStringHandling /// public class SeString { + /// + /// Initializes a new instance of the class. + /// Creates a new SeString from an ordered list of payloads. + /// + public SeString() + { + this.Payloads = new List(); + } + /// /// Initializes a new instance of the class. /// Creates a new SeString from an ordered list of payloads. diff --git a/Dalamud/Game/Text/XivChatEntry.cs b/Dalamud/Game/Text/XivChatEntry.cs index dc8005f6b..a5a11766e 100644 --- a/Dalamud/Game/Text/XivChatEntry.cs +++ b/Dalamud/Game/Text/XivChatEntry.cs @@ -1,5 +1,7 @@ using System; +using Dalamud.Game.Text.SeStringHandling; + namespace Dalamud.Game.Text { /// @@ -20,12 +22,12 @@ namespace Dalamud.Game.Text /// /// Gets or sets the sender name. /// - public string Name { get; set; } = string.Empty; + public SeString Name { get; set; } = string.Empty; /// - /// Gets or sets the message bytes. + /// Gets or sets the message. /// - public byte[] MessageBytes { get; set; } + public SeString Message { get; set; } = string.Empty; /// /// Gets or sets the message parameters. diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 6cda9827a..c705c4cf6 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -727,7 +727,7 @@ namespace Dalamud.Plugin.Internal { this.dalamud.Framework.Gui.Chat.PrintChat(new XivChatEntry { - MessageBytes = Encoding.UTF8.GetBytes(Locs.DalamudPluginUpdateFailed(metadata.Name, metadata.Version)), + Message = Locs.DalamudPluginUpdateFailed(metadata.Name, metadata.Version), Type = XivChatType.Urgent, }); }