using System; using System.Runtime.InteropServices; using RynthCore.PluginCore; namespace RynthCore.Plugin.RynthChat; public sealed class RynthChatPlugin : RynthPluginBase { internal static readonly IntPtr NamePointer = Marshal.StringToHGlobalAnsi("RynthChat"); internal static readonly IntPtr VersionPointer = Marshal.StringToHGlobalAnsi("0.4.0"); private readonly ChatBuffer _buffer = new(); public override int Initialize() { Host.Log("[RynthChat] Plugin initialized."); return 0; } public override void OnLoginComplete() { Host.Log("[RynthChat] Login complete."); } public override void OnLogout() { Host.Log("[RynthChat] Logout."); } public override void OnChatWindowText(string? text, int chatType, ref int eat) { // A plugin earlier in the dispatch ate the line (RynthAi's Meta Manager eats the // reply to its own /myquests poll): keep it out of the chat window. if (eat != 0) return; _buffer.Add(text, chatType); } public override void OnChatBarEnter(string? text, ref int eat) { // Phase 5: intercept + own outgoing chat. } internal string BuildScrollbackJson(ulong sinceSeq) => _buffer.BuildJson(sinceSeq); internal int SetScrollbackCapacity(int lines) => _buffer.SetCapacity(lines); internal int SetPlayerScrollbackCapacity(int lines) => _buffer.SetPlayerCapacity(lines); // Called on the game thread from the engine's deferred chat dispatch // (Win32Backend posts WM_RYNTHCORE_CHAT so this runs on a fresh, non-reentrant // message dispatch rather than inline inside the Enter keystroke handler). internal void SendLine(string text) { if (!Host.HasInvokeChatParser || string.IsNullOrWhiteSpace(text)) return; Host.InvokeChatParser(text); } }