From 604a2cb4828720ccf4426f01fe8d08908e8ee672 Mon Sep 17 00:00:00 2001 From: Infi Date: Mon, 1 Jul 2024 23:56:24 +0200 Subject: [PATCH] Remove debug info --- ChatTwo/GameFunctions/ChatBox.cs | 74 +++++++------------------------- ChatTwo/PayloadHandler.cs | 1 - ChatTwo/Plugin.cs | 4 +- 3 files changed, 16 insertions(+), 63 deletions(-) diff --git a/ChatTwo/GameFunctions/ChatBox.cs b/ChatTwo/GameFunctions/ChatBox.cs index cc7c5bd..6f68ff8 100644 --- a/ChatTwo/GameFunctions/ChatBox.cs +++ b/ChatTwo/GameFunctions/ChatBox.cs @@ -1,45 +1,29 @@ -using System.Diagnostics.CodeAnalysis; -using System.Runtime.InteropServices; -using System.Text; -using Dalamud.Game; +using System.Text; +using Dalamud.Utility.Signatures; using FFXIVClientStructs.FFXIV.Client.System.String; using FFXIVClientStructs.FFXIV.Client.UI; namespace ChatTwo.GameFunctions; // From: https://git.anna.lgbt/anna/XivCommon/src/branch/main/XivCommon/Functions/Chat.cs -public class ChatCommon +public unsafe class ChatCommon { - private static class Signatures + [Signature("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 45 84 C9")] + private readonly delegate* unmanaged ProcessChatBox = null!; + + internal ChatCommon() { - internal const string SendChat = "48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 45 84 C9"; + Plugin.GameInteropProvider.InitializeFromAttributes(this); } - private delegate void ProcessChatBoxDelegate(IntPtr uiModule, IntPtr message, IntPtr unused, byte a4); - private ProcessChatBoxDelegate? ProcessChatBox { get; } - - internal ChatCommon(ISigScanner scanner) - { - if (scanner.TryScanText(Signatures.SendChat, out var processChatBoxPtr)) - { - ProcessChatBox = Marshal.GetDelegateForFunctionPointer(processChatBoxPtr); - } - } - - public unsafe void SendMessageUnsafe(byte[] message) + public void SendMessageUnsafe(byte[] message) { if (ProcessChatBox == null) throw new InvalidOperationException("Could not find signature for chat sending"); - var uiModule = (IntPtr)UIModule.Instance(); - - using var payload = new ChatPayload(message); - var mem1 = Marshal.AllocHGlobal(400); - Marshal.StructureToPtr(payload, mem1, false); - - ProcessChatBox(uiModule, mem1, IntPtr.Zero, 0); - - Marshal.FreeHGlobal(mem1); + var mes = Utf8String.FromSequence(message); + ProcessChatBox(UIModule.Instance(), mes, IntPtr.Zero, 0); + mes->Dtor(true); } public void SendMessage(string message) @@ -57,42 +41,14 @@ public class ChatCommon SendMessageUnsafe(bytes); } - private static unsafe string SanitiseText(string text) + private static string SanitiseText(string text) { var uText = Utf8String.FromString(text); - uText->SanitizeString( 0x27F, Utf8String.CreateEmpty()); - + uText->SanitizeString( 0x27F, (Utf8String*)nint.Zero); var sanitised = uText->ToString(); - uText->Dtor(); + uText->Dtor(true); return sanitised; } - - [StructLayout(LayoutKind.Explicit)] - [SuppressMessage("ReSharper", "PrivateFieldCanBeConvertedToLocalVariable")] - private readonly struct ChatPayload : IDisposable - { - [FieldOffset(0)] private readonly IntPtr textPtr; - [FieldOffset(16)] private readonly ulong textLen; - [FieldOffset(8)] private readonly ulong unk1; - [FieldOffset(24)] private readonly ulong unk2; - - internal ChatPayload(byte[] stringBytes) - { - textPtr = Marshal.AllocHGlobal(stringBytes.Length + 30); - Marshal.Copy(stringBytes, 0, textPtr, stringBytes.Length); - Marshal.WriteByte(textPtr + stringBytes.Length, 0); - - textLen = (ulong)(stringBytes.Length + 1); - - unk1 = 64; - unk2 = 0; - } - - public void Dispose() - { - Marshal.FreeHGlobal(textPtr); - } - } } \ No newline at end of file diff --git a/ChatTwo/PayloadHandler.cs b/ChatTwo/PayloadHandler.cs index ed7631b..ae951dc 100755 --- a/ChatTwo/PayloadHandler.cs +++ b/ChatTwo/PayloadHandler.cs @@ -602,7 +602,6 @@ public sealed class PayloadHandler { } var isFriend = GameFunctions.GameFunctions.GetFriends().Any(friend => friend.NameString == player.PlayerName && friend.HomeWorld == world.RowId); - Plugin.Log.Information($"Is Friend? {isFriend}"); if (!isFriend && ImGui.Selectable(Language.Context_SendFriendRequest)) LogWindow.Plugin.Functions.SendFriendRequest(player.PlayerName, (ushort) world.RowId); diff --git a/ChatTwo/Plugin.cs b/ChatTwo/Plugin.cs index ff2a1b5..4e8b350 100755 --- a/ChatTwo/Plugin.cs +++ b/ChatTwo/Plugin.cs @@ -6,7 +6,6 @@ using ChatTwo.Ipc; using ChatTwo.Resources; using ChatTwo.Ui; using ChatTwo.Util; -using Dalamud.Game; using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Objects; using Dalamud.Interface.Windowing; @@ -40,7 +39,6 @@ public sealed class Plugin : IDalamudPlugin [PluginService] internal static IGameConfig GameConfig { get; private set; } = null!; [PluginService] internal static INotificationManager Notification { get; private set; } = null!; [PluginService] internal static IAddonLifecycle AddonLifecycle { get; private set; } = null!; - [PluginService] internal static ISigScanner Scanner { get; private set; } = null!; internal static Configuration Config = null!; @@ -82,7 +80,7 @@ public sealed class Plugin : IDalamudPlugin ImGuiUtil.Initialize(this); Commands = new Commands(this); - Common = new ChatCommon(Scanner); + Common = new ChatCommon(); TextureCache = new TextureCache(); Functions = new GameFunctions.GameFunctions(this); Ipc = new IpcManager();