From 3a5dcae26165f6c22444c4d574e977ee16f5c812 Mon Sep 17 00:00:00 2001 From: Infi Date: Tue, 28 May 2024 14:23:31 +0200 Subject: [PATCH] Fix #63 --- ChatTwo/GameFunctions/Chat.cs | 34 +++++++++++++++++++------- ChatTwo/Resources/Language.Designer.cs | 9 +++++++ ChatTwo/Resources/Language.resx | 3 +++ ChatTwo/Ui/ChatLogWindow.cs | 2 +- ChatTwo/Util/AutoTranslate.cs | 3 +-- ChatTwo/Util/ImGuiUtil.cs | 2 +- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/ChatTwo/GameFunctions/Chat.cs b/ChatTwo/GameFunctions/Chat.cs index bd83da3..4921ff4 100755 --- a/ChatTwo/GameFunctions/Chat.cs +++ b/ChatTwo/GameFunctions/Chat.cs @@ -2,6 +2,7 @@ using System.Numerics; using System.Text; using ChatTwo.Code; using ChatTwo.GameFunctions.Types; +using ChatTwo.Resources; using ChatTwo.Util; using Dalamud.Game.ClientState.Keys; using Dalamud.Game.Config; @@ -10,6 +11,7 @@ using Dalamud.Hooking; using Dalamud.Memory; using Dalamud.Plugin.Services; using Dalamud.Utility.Signatures; +using FFXIVClientStructs.FFXIV.Client.Network; using FFXIVClientStructs.FFXIV.Client.System.Framework; using FFXIVClientStructs.FFXIV.Client.System.String; using FFXIVClientStructs.FFXIV.Client.UI; @@ -46,10 +48,7 @@ internal sealed unsafe class Chat : IDisposable private readonly delegate* unmanaged PrintTellNative = null!; [Signature("E8 ?? ?? ?? ?? 48 8D 4C 24 ?? E8 ?? ?? ?? ?? 48 8D 8C 24 ?? ?? ?? ?? E8 ?? ?? ?? ?? B0 01")] - private readonly delegate* unmanaged SendTellNative = null!; - - [Signature("E8 ?? ?? ?? ?? F6 43 0A 40")] - private readonly delegate* unmanaged GetNetworkModule = null!; + private readonly delegate* unmanaged SendTellNative = null!; // TODO Replace with CS in InfoProxyCrossworldLinkshell [Signature("E8 ?? ?? ?? ?? 48 8B C8 E8 ?? ?? ?? ?? 45 8D 46 FB")] @@ -703,22 +702,39 @@ internal sealed unsafe class Chat : IDisposable return new TellHistoryInfo(name, world, contentId); } - internal void SendTell(TellReason reason, ulong contentId, string name, ushort homeWorld, byte[] message) + internal void SendTell(TellReason reason, ulong contentId, string name, ushort homeWorld, byte[] message, string rawText) { var uName = Utf8String.FromString(name); var uMessage = Utf8String.FromSequence(message); - var networkModule = GetNetworkModule(Framework.Instance()); - var a1 = *(IntPtr*) (networkModule + 8); + var encoded = Utf8String.FromUtf8String(PronounModule.Instance()->ProcessString(uMessage, true)); + var decoded = EncodeMessage(rawText); + AutoTranslate.ReplaceWithPayload(ref decoded); + using var decodedUtf8String = new Utf8String(decoded); + + var networkModule = Framework.Instance()->GetNetworkModuleProxy()->NetworkModule; var logModule = Framework.Instance()->GetUiModule()->GetRaptureLogModule(); - SendTellNative(a1, contentId, homeWorld, uName, uMessage, (byte) reason, homeWorld); - PrintTellNative(logModule, 33, uName, uMessage, contentId, homeWorld, 255, 0, 0); + var ok = SendTellNative(networkModule, contentId, homeWorld, uName, encoded, (byte) reason, homeWorld); + if (ok) + PrintTellNative(logModule, 33, uName, &decodedUtf8String, contentId, homeWorld, 255, 0, 0); + else + Plugin.ChatGui.PrintError(Language.Chat_SendTell_Error); + encoded->Dtor(true); uName->Dtor(true); uMessage->Dtor(true); } + internal byte[] EncodeMessage(string str) { + using var input = new Utf8String(str); + using var ouput = new Utf8String(); + + input.Copy(PronounModule.Instance()->ProcessString(&input, true)); + ouput.Copy(PronounModule.Instance()->ProcessString(&input, false)); + return ouput.AsSpan().ToArray(); + } + internal bool IsCharValid(char c) { var uC = Utf8String.FromString(c.ToString()); diff --git a/ChatTwo/Resources/Language.Designer.cs b/ChatTwo/Resources/Language.Designer.cs index f4ee12a..0b15b18 100755 --- a/ChatTwo/Resources/Language.Designer.cs +++ b/ChatTwo/Resources/Language.Designer.cs @@ -77,6 +77,15 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to An error occured while sending this tell message. + /// + internal static string Chat_SendTell_Error { + get { + return ResourceManager.GetString("Chat_SendTell_Error", resourceCulture); + } + } + /// /// Looks up a localized string similar to Input is disabled for this tab. /// diff --git a/ChatTwo/Resources/Language.resx b/ChatTwo/Resources/Language.resx index 2b39046..13b1884 100644 --- a/ChatTwo/Resources/Language.resx +++ b/ChatTwo/Resources/Language.resx @@ -1198,4 +1198,7 @@ FromTo: + + An error occured while sending this tell message + diff --git a/ChatTwo/Ui/ChatLogWindow.cs b/ChatTwo/Ui/ChatLogWindow.cs index 591f4ca..20a0194 100644 --- a/ChatTwo/Ui/ChatLogWindow.cs +++ b/ChatTwo/Ui/ChatLogWindow.cs @@ -840,7 +840,7 @@ public sealed class ChatLogWindow : Window var tellBytes = Encoding.UTF8.GetBytes(trimmed); AutoTranslate.ReplaceWithPayload(ref tellBytes); - Plugin.Functions.Chat.SendTell(reason, target.ContentId, target.Name, (ushort) world.RowId, tellBytes); + Plugin.Functions.Chat.SendTell(reason, target.ContentId, target.Name, (ushort) world.RowId, tellBytes, trimmed); } if (TempChannel is InputChannel.Tell) diff --git a/ChatTwo/Util/AutoTranslate.cs b/ChatTwo/Util/AutoTranslate.cs index c45f66a..b3379d6 100644 --- a/ChatTwo/Util/AutoTranslate.cs +++ b/ChatTwo/Util/AutoTranslate.cs @@ -4,7 +4,6 @@ using System.Text; using Dalamud; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; -using Dalamud.Plugin.Services; using Dalamud.Utility; using Lumina.Excel; using Lumina.Excel.GeneratedSheets; @@ -293,7 +292,7 @@ internal static class AutoTranslate { var payload = ValidEntries.Contains((group, key)) ? new AutoTranslatePayload(group, key).Encode() - : Array.Empty(); + : []; var oldBytes = bytes.ToArray(); var lengthDiff = payload.Length - (i - start); diff --git a/ChatTwo/Util/ImGuiUtil.cs b/ChatTwo/Util/ImGuiUtil.cs index 7e75060..27e5b95 100755 --- a/ChatTwo/Util/ImGuiUtil.cs +++ b/ChatTwo/Util/ImGuiUtil.cs @@ -301,7 +301,7 @@ internal static class ImGuiUtil public static void DrawArrows(ref int selected, int min, int max, float spacing, int id = 0) { // Prevents changing values from triggering EndDisable - var isMin = selected == 1; + var isMin = selected == min; var isMax = selected == max; ImGui.SameLine(0, spacing);