From 8ed6c909cbc86461daaf0d1f98c1efc16adf83e8 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Wed, 10 Apr 2024 03:10:01 +1000 Subject: [PATCH] fix: avoid double-up player names in screenshot mode, censor tell target In party chat, players from other servers seem to have extra (empty) text chunks with the same PlayerPayload link. The screenshot mode code would replace all chunks with the hashed player name. Changes the screenshot mode code to skip changing the chunk content for PlayerPayload chunks unless the content contans the player name. Also censors the tell target above the chat input. --- ChatTwo/Ui/ChatLogWindow.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/ChatTwo/Ui/ChatLogWindow.cs b/ChatTwo/Ui/ChatLogWindow.cs index 193985b..17e1318 100644 --- a/ChatTwo/Ui/ChatLogWindow.cs +++ b/ChatTwo/Ui/ChatLogWindow.cs @@ -453,6 +453,10 @@ public sealed class ChatLogWindow : Window, IUiComponent { ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero); try { if (_tellTarget != null) { + var playerName = _tellTarget.Name; + if (ScreenshotMode) + playerName = HashPlayer(_tellTarget.Name, _tellTarget.World); + var world = Plugin.DataManager.GetExcelSheet() ?.GetRow(_tellTarget.World) ?.Name @@ -460,7 +464,7 @@ public sealed class ChatLogWindow : Window, IUiComponent { DrawChunks(new Chunk[] { new TextChunk(ChunkSource.None, null, "Tell "), - new TextChunk(ChunkSource.None, null, _tellTarget.Name), + new TextChunk(ChunkSource.None, null, playerName), new IconChunk(ChunkSource.None, null, BitmapFontIcon.CrossWorld), new TextChunk(ChunkSource.None, null, world), }); @@ -1367,12 +1371,13 @@ public sealed class ChatLogWindow : Window, IUiComponent { var content = text.Content; if (ScreenshotMode) { - if (chunk.Link is PlayerPayload playerPayload) { - var hashCode = $"{Salt}{playerPayload.PlayerName}{playerPayload.World.RowId}".GetHashCode(); - content = $"Player {hashCode:X8}"; + // Check for contains here as sometimes there are multiple + // TextChunks with the same PlayerPayload but only one has the name. + // E.g. party chat with cross world players adds extra chunks. + if (chunk.Link is PlayerPayload playerPayload && content.Contains(playerPayload.PlayerName)) { + content = content.Replace(playerPayload.PlayerName, HashPlayer(playerPayload.PlayerName, playerPayload.World.RowId)); } else if (Plugin.ClientState.LocalPlayer is { } player && content.Contains(player.Name.TextValue)) { - var hashCode = $"{Salt}{player.Name.TextValue}{player.HomeWorld.Id}".GetHashCode(); - content = content.Replace(player.Name.TextValue, $"Player {hashCode:X8}"); + content = content.Replace(player.Name.TextValue, HashPlayer(player.Name.TextValue, player.HomeWorld.Id)); } } @@ -1391,4 +1396,9 @@ public sealed class ChatLogWindow : Window, IUiComponent { ImGui.PopStyleColor(); } } + + private string HashPlayer(string playerName, uint worldId) { + var hashCode = $"{Salt}{playerName}{worldId}".GetHashCode(); + return $"Player {hashCode:X8}"; + } }