Rewrite chat
This commit is contained in:
@@ -31,7 +31,6 @@ public sealed class Plugin : IDalamudPlugin
|
||||
public Configuration Configuration { get; }
|
||||
public IconManager IconManager { get; }
|
||||
public Hooks Hooks { get; }
|
||||
public Chat Chat { get; }
|
||||
public CommunityMacros CommunityMacros { get; }
|
||||
public Ipc Ipc { get; }
|
||||
public AttributeCommandManager AttributeCommandManager { get; }
|
||||
@@ -44,7 +43,6 @@ public sealed class Plugin : IDalamudPlugin
|
||||
Configuration = Configuration.Load();
|
||||
IconManager = new();
|
||||
Hooks = new();
|
||||
Chat = new();
|
||||
CommunityMacros = new();
|
||||
Ipc = new();
|
||||
AttributeCommandManager = new();
|
||||
|
||||
@@ -32,7 +32,6 @@ public sealed class Service
|
||||
public static Configuration Configuration => Plugin.Configuration;
|
||||
public static IconManager IconManager => Plugin.IconManager;
|
||||
public static WindowSystem WindowSystem => Plugin.WindowSystem;
|
||||
public static Chat Chat => Plugin.Chat;
|
||||
public static CommunityMacros CommunityMacros => Plugin.CommunityMacros;
|
||||
public static Ipc Ipc => Plugin.Ipc;
|
||||
#pragma warning restore CS8618
|
||||
|
||||
+25
-16
@@ -1,5 +1,3 @@
|
||||
using Craftimizer.Plugin;
|
||||
using Dalamud.Utility.Signatures;
|
||||
using FFXIVClientStructs.FFXIV.Client.System.String;
|
||||
using FFXIVClientStructs.FFXIV.Client.UI;
|
||||
using System;
|
||||
@@ -7,25 +5,36 @@ using System;
|
||||
namespace Craftimizer.Utils;
|
||||
|
||||
// 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);
|
||||
|
||||
[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)
|
||||
public static void SendMessage(string message)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(message);
|
||||
|
||||
var str = Utf8String.FromString(message);
|
||||
str->SanitizeString(0x27F, null);
|
||||
sendChat(UIModule.Instance(), str, null, false);
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,7 +476,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable
|
||||
var action = NextAction;
|
||||
if (canExecute && action != null)
|
||||
{
|
||||
Service.Chat.SendMessage($"/ac \"{action.Value.GetName(RecipeData!.ClassJob)}\"");
|
||||
Chat.SendMessage($"/ac \"{action.Value.GetName(RecipeData!.ClassJob)}\"");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -542,7 +542,7 @@ public sealed unsafe class SynthHelper : Window, IDisposable
|
||||
{
|
||||
foreach (var status in statusManager->Status)
|
||||
if (status.StatusId == id)
|
||||
return status.StackCount;
|
||||
return (byte)status.Param;
|
||||
return 0;
|
||||
}
|
||||
bool HasEffect(ushort id)
|
||||
|
||||
Reference in New Issue
Block a user