RynthSuite as of 2026-09-05 (internal a5ff5c2)

A snapshot of the working tree for aelrynth.com/git/: the code, build files
and public docs. Internal review notes and agent instructions are left out.
MIT licensed; see LICENSE.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tom Bohar 2026-09-25 21:23:05 -04:00
commit 0a4b611a90
166 changed files with 186537 additions and 0 deletions

View file

@ -0,0 +1,115 @@
using System;
using System.Text;
using System.Threading;
namespace RynthCore.Plugin.RynthChat;
internal sealed class ChatBuffer
{
private const int Capacity = 500;
private readonly ChatLine[] _ring = new ChatLine[Capacity];
private readonly object _lock = new();
private int _head; // next write index (mod Capacity)
private int _count; // total items stored (≤ Capacity)
private ulong _nextSeq = 1;
internal void Add(string? text, int chatType)
{
if (string.IsNullOrEmpty(text)) return;
string channel = ChatClassifier.IsRynthOutput(text)
? ChatClassifier.Rynth
: ChatClassifier.ChannelFor(chatType);
string? sender = ChatClassifier.SenderFor(text, chatType);
string ts = DateTime.Now.ToString("HH:mm:ss");
var line = new ChatLine
{
Seq = Interlocked.Increment(ref _nextSeq) - 1,
Timestamp = ts,
Channel = channel,
Sender = sender,
Text = text,
};
lock (_lock)
{
_ring[_head % Capacity] = line;
_head = (_head + 1) % Capacity;
if (_count < Capacity) _count++;
}
}
// Returns JSON array of lines with Seq > sinceSeq, oldest-first.
internal string BuildJson(ulong sinceSeq)
{
ChatLine[] snapshot;
int count;
int head;
lock (_lock)
{
snapshot = (ChatLine[])_ring.Clone();
count = _count;
head = _head;
}
var sb = new StringBuilder(256);
sb.Append('[');
bool first = true;
// Iterate oldest→newest. Oldest entry is at (head - count + Capacity) % Capacity.
int start = (head - count + Capacity) % Capacity;
for (int i = 0; i < count; i++)
{
var line = snapshot[(start + i) % Capacity];
if (line == null || line.Seq <= sinceSeq) continue;
if (!first) sb.Append(',');
first = false;
sb.Append("{\"seq\":");
sb.Append(line.Seq);
sb.Append(",\"ts\":\"");
sb.Append(line.Timestamp);
sb.Append("\",\"chan\":\"");
AppendEscaped(sb, line.Channel);
sb.Append("\",\"sender\":");
if (line.Sender != null)
{
sb.Append('"');
AppendEscaped(sb, line.Sender);
sb.Append('"');
}
else
{
sb.Append("null");
}
sb.Append(",\"text\":\"");
AppendEscaped(sb, line.Text);
sb.Append("\"}");
}
sb.Append(']');
return sb.ToString();
}
private static void AppendEscaped(StringBuilder sb, string s)
{
foreach (char c in s)
{
switch (c)
{
case '"': sb.Append("\\\""); break;
case '\\': sb.Append("\\\\"); break;
case '\n': sb.Append("\\n"); break;
case '\r': sb.Append("\\r"); break;
case '\t': sb.Append("\\t"); break;
default:
if (c < 0x20)
sb.Append($"\\u{(int)c:X4}");
else
sb.Append(c);
break;
}
}
}
}

View file

@ -0,0 +1,84 @@
using System;
using System.Text.RegularExpressions;
namespace RynthCore.Plugin.RynthChat;
// ChatMessageType values from ACE.Entity.Enum.ChatMessageType (ACE binary is
// byte-identical to retail, so these are authoritative for retail acclient.exe too).
internal static class ChatClassifier
{
internal const string Chat = "Chat"; // Local/Tell/Allegiance/Fellow — all player-to-player
internal const string Channels = "Channels"; // General/Trade/LFG/Roleplay/Society/Admin — all 0x08/0x09
internal const string System = "System";
internal const string Combat = "Combat";
internal const string Rynth = "Rynth"; // Any RynthCore/RynthAi/RynthChat plugin output ("[Rynth…]")
internal const string Other = "Other";
internal static readonly string[] AllChannels =
{ Chat, Channels, System, Combat, Rynth, Other };
/// <summary>
/// True for output emitted by the Rynth stack itself — every Rynth plugin tags
/// its chat lines with a "[Rynth…]" prefix (e.g. "[RynthAi]", "[RynthChat]",
/// "[RynthAi Craft]"). These are routed to the dedicated Rynth tab regardless of
/// the chatType the plugin happened to write them with, so nothing gets scattered
/// across System/Other/Chat and lost.
/// </summary>
internal static bool IsRynthOutput(string text) =>
text.StartsWith("[Rynth", StringComparison.OrdinalIgnoreCase);
// ── Channel classification ─────────────────────────────────────────────
internal static string ChannelFor(int chatType) => (uint)chatType switch
{
0x02 or 0x03 or 0x04 or 0x0A or 0x0B
or 0x0C or 0x12 or 0x13 => Chat,
0x08 or 0x09 => Channels,
0x00 or 0x05 or 0x0D or 0x14 or 0x17 or 0x18
or 0x19 or 0x1F => System,
0x06 or 0x07 or 0x11 or 0x15 or 0x16 => Combat,
_ => Other,
};
internal static uint ColorFor(string channel) => channel switch
{
Chat => 0xFFE0E0E0,
Channels => 0xFF7AB8F5,
System => 0xFF8CA6BF,
Combat => 0xFFD93333,
_ => 0xFFAAAAAA,
};
// ── Sender extraction ──────────────────────────────────────────────────
private static readonly Regex _sayRe = new(@"^(.+?) says, """, RegexOptions.Compiled);
private static readonly Regex _tellInRe = new(@"^(.+?) tells you, """, RegexOptions.Compiled);
private static readonly Regex _tellOutRe = new(@"^You tell (.+?), """, RegexOptions.Compiled);
private static readonly Regex _allegianceRe = new(@"^(.+?) says on the Allegiance channel, """, RegexOptions.Compiled);
private static readonly Regex _fellowRe = new(@"^(.+?) says on the Fellowship channel, """, RegexOptions.Compiled);
private static readonly Regex _chanSenderRe = new(@"^(.+?) says on the .+? channel, """, RegexOptions.Compiled);
internal static string? SenderFor(string text, int chatType) => (uint)chatType switch
{
0x02 => Match(_sayRe, text),
0x03 => Match(_tellInRe, text),
0x04 => TellOutSender(text),
0x12 => Match(_allegianceRe, text) ?? Match(_sayRe, text),
0x13 => Match(_fellowRe, text) ?? Match(_sayRe, text),
0x0A => Match(_sayRe, text),
0x08 => Match(_chanSenderRe, text),
_ => null,
};
private static string? Match(Regex re, string text)
{
var m = re.Match(text);
return m.Success ? m.Groups[1].Value : null;
}
private static string? TellOutSender(string text)
{
var m = _tellOutRe.Match(text);
return m.Success ? $"→{m.Groups[1].Value}" : null;
}
}

View file

@ -0,0 +1,10 @@
namespace RynthCore.Plugin.RynthChat;
internal sealed class ChatLine
{
internal ulong Seq { get; init; }
internal string Timestamp { get; init; } = "";
internal string Channel { get; init; } = "";
internal string? Sender { get; init; }
internal string Text { get; init; } = "";
}

View file

@ -0,0 +1,82 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using RynthCore.PluginCore;
using RynthCore.PluginSdk;
namespace RynthCore.Plugin.RynthChat;
public static unsafe class PluginExports
{
private static readonly RynthPluginRuntime<RynthChatPlugin> Runtime = new();
[UnmanagedCallersOnly(EntryPoint = "RynthPluginInit", CallConvs = new[] { typeof(CallConvCdecl) })]
private static int Init(RynthCoreApiNative* api) => Runtime.Init(api);
[UnmanagedCallersOnly(EntryPoint = "RynthPluginShutdown", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void Shutdown() => Runtime.Shutdown();
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnLoginComplete", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void OnLoginComplete() => Runtime.OnLoginComplete();
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnLogout", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void OnLogout() => Runtime.OnLogout();
[UnmanagedCallersOnly(EntryPoint = "RynthPluginName", CallConvs = new[] { typeof(CallConvCdecl) })]
public static IntPtr GetName() => RynthChatPlugin.NamePointer;
[UnmanagedCallersOnly(EntryPoint = "RynthPluginVersion", CallConvs = new[] { typeof(CallConvCdecl) })]
public static IntPtr GetVersion() => RynthChatPlugin.VersionPointer;
[UnmanagedCallersOnly(EntryPoint = "RynthPluginTick", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void Tick() => Runtime.OnTick();
[UnmanagedCallersOnly(EntryPoint = "RynthPluginRender", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void Render() => Runtime.OnRender();
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnChatWindowText", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void OnChatWindowText(IntPtr textUtf16, int chatType, IntPtr eatFlag) => Runtime.OnChatWindowText(textUtf16, chatType, eatFlag);
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnChatBarEnter", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void OnChatBarEnter(IntPtr textUtf16, IntPtr eatFlag) => Runtime.OnChatBarEnter(textUtf16, eatFlag);
// ── Chat scrollback bridge for the engine-side RynthChatPanel ──────────
// Panel polls RynthChatGetScrollbackJson (~10 Hz) to receive new lines.
// Panel calls RynthChatSendLine to submit a message via InvokeChatParser.
// Buffer swap pattern from RynthAi: alloc-new → swap → free-old keeps the
// polling thread safe without a lock.
private static IntPtr _scrollbackPtr = IntPtr.Zero;
[UnmanagedCallersOnly(EntryPoint = "RynthChatGetScrollbackJson", CallConvs = new[] { typeof(CallConvCdecl) })]
public static IntPtr GetScrollbackJson(ulong sinceSeq)
{
try
{
string json = Runtime.Plugin?.BuildScrollbackJson(sinceSeq) ?? "[]";
IntPtr newPtr = Marshal.StringToHGlobalAnsi(json);
IntPtr oldPtr = Interlocked.Exchange(ref _scrollbackPtr, newPtr);
if (oldPtr != IntPtr.Zero)
Marshal.FreeHGlobal(oldPtr);
return newPtr;
}
catch
{
return IntPtr.Zero;
}
}
[UnmanagedCallersOnly(EntryPoint = "RynthChatSendLine", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void SendLine(IntPtr ansiText)
{
try
{
if (ansiText == IntPtr.Zero) return;
string? text = Marshal.PtrToStringAnsi(ansiText);
if (string.IsNullOrEmpty(text)) return;
Runtime.Plugin?.SendLine(text);
}
catch { }
}
}

View file

@ -0,0 +1,50 @@
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.1.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)
{
_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);
// 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);
}
}

View file

@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0-windows</TargetFramework>
<PlatformTarget>x86</PlatformTarget>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<OutputType>Library</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<PublishAot>true</PublishAot>
<NativeLib>Shared</NativeLib>
<InvariantGlobalization>true</InvariantGlobalization>
<IlcOptimizationPreference>Size</IlcOptimizationPreference>
<StripSymbols>false</StripSymbols>
<RootNamespace>RynthCore.Plugin.RynthChat</RootNamespace>
<AssemblyName>RynthCore.Plugin.RynthChat</AssemblyName>
<Platforms>x86</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ImGui.NET" Version="1.91.6.1" />
</ItemGroup>
<ItemGroup>
<TrimmerRootAssembly Include="ImGui.NET" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\RynthCore\src\RynthCore.PluginCore\RynthCore.PluginCore.csproj" />
<ProjectReference Include="..\..\..\RynthCore\src\RynthCore.PluginSdk\RynthCore.PluginSdk.csproj" />
</ItemGroup>
<Target Name="RemoveBundledImGuiNativeFromBuild" AfterTargets="Build">
<Delete Files="$(OutputPath)cimgui.dll" Condition="Exists('$(OutputPath)cimgui.dll')" />
</Target>
<Target Name="RemoveBundledImGuiNativeFromPublish" AfterTargets="Publish" Condition="'$(PublishDir)' != ''">
<Delete Files="$(PublishDir)cimgui.dll" Condition="Exists('$(PublishDir)cimgui.dll')" />
</Target>
</Project>