diff --git a/ChatTwo/GameFunctions/Chat.cs b/ChatTwo/GameFunctions/Chat.cs index f160487..6064efe 100755 --- a/ChatTwo/GameFunctions/Chat.cs +++ b/ChatTwo/GameFunctions/Chat.cs @@ -58,6 +58,9 @@ internal sealed unsafe class Chat : IDisposable { [Signature("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 8B F2 48 8D B9")] private readonly delegate* unmanaged _getColourInfo = null!; + [Signature("E8 ?? ?? ?? ?? EB 0A 48 8D 4C 24 ?? E8 ?? ?? ?? ?? 48 8D 8D")] + private readonly delegate* unmanaged _sanitiseString = null!; + // Hooks private delegate byte ChatLogRefreshDelegate(IntPtr log, ushort eventId, AtkValue* value); @@ -646,4 +649,16 @@ internal sealed unsafe class Chat : IDisposable { uMessage->Dtor(); IMemorySpace.Free(uMessage); } + + internal bool IsCharValid(char c) { + var uC = Utf8String.FromString(c.ToString()); + + this._sanitiseString(uC, 0x27F, IntPtr.Zero); + var wasValid = uC->ToString().Length > 0; + + uC->Dtor(); + IMemorySpace.Free(uC); + + return wasValid; + } } diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index 3ba7a5f..84d32f2 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Numerics; +using System.Text; using ChatTwo.Code; using ChatTwo.GameFunctions.Types; using ChatTwo.Resources; @@ -490,6 +491,7 @@ internal sealed class ChatLog : IUiComponent { ImGui.SetNextItemWidth(inputWidth); const ImGuiInputTextFlags inputFlags = ImGuiInputTextFlags.EnterReturnsTrue | ImGuiInputTextFlags.CallbackAlways + | ImGuiInputTextFlags.CallbackCharFilter | ImGuiInputTextFlags.CallbackHistory; if (ImGui.InputText("##chat2-input", ref this.Chat, 500, inputFlags, this.Callback)) { if (!string.IsNullOrWhiteSpace(this.Chat)) { @@ -525,7 +527,7 @@ internal sealed class ChatLog : IUiComponent { } } - this.Ui.Plugin.Common.Functions.Chat.SendMessage(trimmed); + this.Ui.Plugin.Common.Functions.Chat.SendMessageUnsafe(Encoding.UTF8.GetBytes(trimmed)); } Skip: @@ -850,6 +852,13 @@ internal sealed class ChatLog : IUiComponent { private unsafe int Callback(ImGuiInputTextCallbackData* data) { var ptr = new ImGuiInputTextCallbackDataPtr(data); + if (data->EventFlag == ImGuiInputTextFlags.CallbackCharFilter) { + var valid = this.Ui.Plugin.Functions.Chat.IsCharValid((char) ptr.EventChar); + if (!valid) { + return 1; + } + } + if (this.Activate) { this.Activate = false; data->CursorPos = this.Chat.Length;