Rewrite chat

This commit is contained in:
Asriel Camora
2025-03-28 20:52:54 -07:00
parent 72d4b20bb2
commit 9f99f617a4
4 changed files with 28 additions and 22 deletions
-2
View File
@@ -31,7 +31,6 @@ public sealed class Plugin : IDalamudPlugin
public Configuration Configuration { get; } public Configuration Configuration { get; }
public IconManager IconManager { get; } public IconManager IconManager { get; }
public Hooks Hooks { get; } public Hooks Hooks { get; }
public Chat Chat { get; }
public CommunityMacros CommunityMacros { get; } public CommunityMacros CommunityMacros { get; }
public Ipc Ipc { get; } public Ipc Ipc { get; }
public AttributeCommandManager AttributeCommandManager { get; } public AttributeCommandManager AttributeCommandManager { get; }
@@ -44,7 +43,6 @@ public sealed class Plugin : IDalamudPlugin
Configuration = Configuration.Load(); Configuration = Configuration.Load();
IconManager = new(); IconManager = new();
Hooks = new(); Hooks = new();
Chat = new();
CommunityMacros = new(); CommunityMacros = new();
Ipc = new(); Ipc = new();
AttributeCommandManager = new(); AttributeCommandManager = new();
-1
View File
@@ -32,7 +32,6 @@ public sealed class Service
public static Configuration Configuration => Plugin.Configuration; public static Configuration Configuration => Plugin.Configuration;
public static IconManager IconManager => Plugin.IconManager; public static IconManager IconManager => Plugin.IconManager;
public static WindowSystem WindowSystem => Plugin.WindowSystem; public static WindowSystem WindowSystem => Plugin.WindowSystem;
public static Chat Chat => Plugin.Chat;
public static CommunityMacros CommunityMacros => Plugin.CommunityMacros; public static CommunityMacros CommunityMacros => Plugin.CommunityMacros;
public static Ipc Ipc => Plugin.Ipc; public static Ipc Ipc => Plugin.Ipc;
#pragma warning restore CS8618 #pragma warning restore CS8618
+25 -16
View File
@@ -1,5 +1,3 @@
using Craftimizer.Plugin;
using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.System.String; using FFXIVClientStructs.FFXIV.Client.System.String;
using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI;
using System; using System;
@@ -7,25 +5,36 @@ using System;
namespace Craftimizer.Utils; namespace Craftimizer.Utils;
// https://github.com/Caraxi/SimpleTweaksPlugin/blob/0973b93931cdf8a1b01153984d62f76d998747ff/Utility/ChatHelper.cs#L17 // https://github.com/Caraxi/SimpleTweaksPlugin/blob/0973b93931cdf8a1b01153984d62f76d998747ff/Utility/ChatHelper.cs#L17
public sealed unsafe class Chat public static unsafe class Chat
{ {
private delegate void SendChatDelegate(UIModule* @this, Utf8String* message, Utf8String* historyMessage, bool pushToHistory); public static void SendMessage(string message)
[Signature("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 48 8B F2 48 8B F9 45 84 C9")]
private readonly SendChatDelegate sendChat = null!;
public Chat()
{
Service.GameInteropProvider.InitializeFromAttributes(this);
}
public void SendMessage(string message)
{ {
ArgumentException.ThrowIfNullOrWhiteSpace(message); ArgumentException.ThrowIfNullOrWhiteSpace(message);
var str = Utf8String.FromString(message); var str = Utf8String.FromString(message);
str->SanitizeString(0x27F, null); try
sendChat(UIModule.Instance(), str, null, false); {
ArgumentOutOfRangeException.ThrowIfZero(str->Length, nameof(message));
ArgumentOutOfRangeException.ThrowIfGreaterThan(str->Length, 500, nameof(message));
var unsanitizedLength = str->Length;
str->SanitizeString(
AllowedEntities.Unknown9 | // 200
AllowedEntities.Payloads | // 40
AllowedEntities.OtherCharacters | // 20
AllowedEntities.CharacterList | // 10
AllowedEntities.SpecialCharacters | // 8
AllowedEntities.Numbers | // 4
AllowedEntities.LowercaseLetters | // 2
AllowedEntities.UppercaseLetters, // 1
null);
ArgumentOutOfRangeException.ThrowIfNotEqual(unsanitizedLength, str->Length, nameof(message));
UIModule.Instance()->ProcessChatBoxEntry(str);
}
finally
{
str->Dtor(true); str->Dtor(true);
} }
} }
}
+2 -2
View File
@@ -476,7 +476,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable
var action = NextAction; var action = NextAction;
if (canExecute && action != null) if (canExecute && action != null)
{ {
Service.Chat.SendMessage($"/ac \"{action.Value.GetName(RecipeData!.ClassJob)}\""); Chat.SendMessage($"/ac \"{action.Value.GetName(RecipeData!.ClassJob)}\"");
return true; return true;
} }
return false; return false;
@@ -542,7 +542,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable
{ {
foreach (var status in statusManager->Status) foreach (var status in statusManager->Status)
if (status.StatusId == id) if (status.StatusId == id)
return status.StackCount; return (byte)status.Param;
return 0; return 0;
} }
bool HasEffect(ushort id) bool HasEffect(ushort id)