Snapshot for release 2026.10.28.3 (internal db7f094)

This commit is contained in:
Tom Bohar 2026-10-28 23:23:42 -04:00
commit e6642d0e10
102 changed files with 4821 additions and 782 deletions

View file

@ -60,6 +60,22 @@ public static unsafe class PluginExports
try { return Runtime.Plugin?.AutoState ?? -1; } catch { return -1; }
}
// The same state for RynthAi's own dashboard (2026-10-23): a plugin reads another's exports only
// through the engine's RynthPluginGet*Json broker (GetPluginExportJson). {"auto":-1|0|1}, a
// literal (nothing to free).
[UnmanagedCallersOnly(EntryPoint = "RynthPluginGetAutoSortJson", CallConvs = new[] { typeof(CallConvCdecl) })]
public static IntPtr AutoSortJson()
{
int state;
try { state = Runtime.Plugin?.AutoState ?? -1; } catch { state = -1; }
return state switch
{
1 => LiteralPointer("{\"auto\":1}"u8),
0 => LiteralPointer("{\"auto\":0}"u8),
_ => LiteralPointer("{\"auto\":-1}"u8),
};
}
[UnmanagedCallersOnly(EntryPoint = "RynthSortCommand", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void Command(IntPtr utf8)
{

View file

@ -40,6 +40,8 @@
<Compile Include="..\Shared\RynthAiStatusApi.cs" Link="Shared\RynthAiStatusApi.cs" />
<!-- Install-folder resolver (env, HKCU, HKLM, default C:\Games). Read only; same file as RynthCore src\Shared. -->
<Compile Include="..\Shared\RynthInstallPaths.cs" Link="Shared\RynthInstallPaths.cs" />
<!-- How a chat command answers (2026-10-28): the shared reply queue and colours. -->
<Compile Include="..\Shared\CommandReply.cs" Link="Shared\CommandReply.cs" />
</ItemGroup>
<ItemGroup>

View file

@ -6,6 +6,7 @@ using System.Text.Json;
using RynthCore.Plugin.RynthSort.Sorting;
using RynthCore.Plugin.RynthSort.Ui;
using RynthCore.Plugin.RynthSort.Views;
using RynthCore.Plugin.Shared;
using RynthCore.PluginCore;
namespace RynthCore.Plugin.RynthSort;
@ -52,7 +53,6 @@ public sealed class RynthSortPlugin : RynthPluginBase
private string _character = string.Empty;
private long _saveDueMs;
private bool _vendorOpen;
private bool _noUiLogged;
private bool _backupOnSave;
private readonly List<string> _warnings = new();
private volatile int _autoState = -1;
@ -75,6 +75,7 @@ public sealed class RynthSortPlugin : RynthPluginBase
public override int Initialize()
{
_reply = new CommandReply("[RynthSort]", (t, c) => Host.WriteToChat(t, c), t => Host.Log(t));
_ui.Log = msg => Host.Log(msg);
_world = new HostSortWorld(Host, _reader, _loot, () => _vendorOpen);
_sort.SettingsChanged = RequestSave;
@ -144,49 +145,50 @@ public sealed class RynthSortPlugin : RynthPluginBase
private void RunCommand(string arg)
{
string[] words = arg.Split(' ', StringSplitOptions.RemoveEmptyEntries);
string word = words.Length > 0 ? words[0].ToLowerInvariant() : string.Empty;
if (word.Length > 0 && !_identityKnown && word is not ("help" or "?"))
// Every /rsort answers in chat (2026-10-28, SortCommand.cs; Plugins/Shared/CommandReply.cs). RynthSort
// can't tell a typed /rsort from a meta's or RynthAi's /ub packsort, so each one does; only the
// dashboard's "on quiet" / "off quiet" (it shows the state itself) is logged instead.
SortCommand c = SortCommand.Parse(arg);
if (c.NeedsLogin && !_identityKnown)
{
Print("Log in first.");
PrintFail("Log in first.");
return;
}
switch (word)
switch (c.Verb)
{
case "":
if (_window != null) { _window.Visible = !_window.Visible; _window.NeedsPass = true; }
if (_window != null && _window.Visible && !Host.HasUi && !_noUiLogged)
case SortVerb.Window:
if (_window != null)
{
_noUiLogged = true;
Print("This RynthCore engine can't show plugin windows (it needs script windows, API v71, with ImGui on). Sorting still runs: /rsort on|off|now|tidy|clean|unpack.");
_window.Visible = !_window.Visible; _window.NeedsPass = true;
if (Host.HasUi) Print(SortCommand.Window(_window.Visible));
else PrintFail(SortCommand.NoWindows);
}
break;
case "on":
case "off":
_sort.SetAuto(word == "on");
// "quiet": the dashboard's toggle, which shows the state itself.
if (!(words.Length > 1 && words[1].Equals("quiet", StringComparison.OrdinalIgnoreCase)))
Print("Auto-sort " + word);
case SortVerb.On:
case SortVerb.Off:
_sort.SetAuto(c.Verb == SortVerb.On);
_reply.Ok("Auto-sort " + (c.Verb == SortVerb.On ? "on" : "off"), quiet: c.Quiet);
break;
case "now":
case "tidy":
case SortVerb.Now:
_sort.StartJob(SortScope.All);
Print(SortCommand.Started(c.Verb));
break;
case "clean":
case SortVerb.Clean:
_sort.StartJob(SortScope.Clean);
Print(SortCommand.Started(c.Verb));
break;
case "unpack":
{
int? n = words.Length > 1 && int.TryParse(words[1], out int p) && p > 0 ? p : null;
_sort.StartUnpack(n);
Print((n != null ? $"Emptying pack {n}" : "Emptying your side packs") + " into the main pack; auto-sort is off (/rsort on when done).");
case SortVerb.Unpack:
_sort.StartUnpack(c.Pack);
Print(SortCommand.Unpacking(c.Pack));
break;
}
case "status":
case SortVerb.Status:
PrintStatus();
break;
case SortVerb.Help:
Print(SortCommand.Usage);
break;
default:
Print("/rsort [on | off | now | tidy | clean | unpack [pack] | status]");
PrintFail(SortCommand.Unknown(c.Word));
break;
}
if (_window != null) _window.NeedsPass = true;
@ -199,11 +201,13 @@ public sealed class RynthSortPlugin : RynthPluginBase
+ $"{v.Packs.Count} side packs, main pack {v.MainUsed}/{v.MainCapacity}; moved {_sort.Moved}, failed {_sort.Failed} this session.");
}
private void Print(string text)
{
if (!Host.WriteToChat("[RynthSort] " + text, 1))
Host.Log("[RynthSort] " + text);
}
// Chat lines wait in the shared reply queue (the host drops a line within 100 ms of another
// plugin's); the tick writes them.
private CommandReply _reply = null!;
private void Print(string text) => _reply.Ok(text);
private void PrintFail(string text) => _reply.Fail(text);
// ── Tick ────────────────────────────────────────────────────────────────
@ -211,6 +215,7 @@ public sealed class RynthSortPlugin : RynthPluginBase
{
long now = Environment.TickCount64;
while (_commands.TryDequeue(out string? cmd)) RunCommand(cmd);
_reply.Flush();
_ui.Poll(Host);
if (_inWorld)

View file

@ -0,0 +1,54 @@
using System;
using RynthCore.Plugin.Shared;
namespace RynthCore.Plugin.RynthSort;
internal enum SortVerb { Window, On, Off, Now, Clean, Unpack, Status, Help, Unknown }
/// <summary>
/// A parsed "/rsort ..." and the lines it answers with (2026-10-28: every command answers,
/// Plugins/Shared/CommandReply.cs). <see cref="Quiet"/>: "on quiet" / "off quiet", the engine
/// dashboard's toggle, which shows the state itself (its success is logged only). Pure, so
/// RynthSort.Tests checks every word.
/// </summary>
internal readonly record struct SortCommand(SortVerb Verb, int? Pack = null, bool Quiet = false, string Word = "")
{
public static SortCommand Parse(string? arg)
{
string[] words = (arg ?? string.Empty).Split(' ', StringSplitOptions.RemoveEmptyEntries);
string word = words.Length > 0 ? words[0].ToLowerInvariant() : string.Empty;
bool quiet = words.Length > 1 && words[1].Equals("quiet", StringComparison.OrdinalIgnoreCase);
return word switch
{
"" => new(SortVerb.Window),
"on" => new(SortVerb.On, Quiet: quiet),
"off" => new(SortVerb.Off, Quiet: quiet),
"now" or "tidy" => new(SortVerb.Now),
"clean" => new(SortVerb.Clean),
"unpack" => new(SortVerb.Unpack, words.Length > 1 && int.TryParse(words[1], out int p) && p > 0 ? p : null),
"status" => new(SortVerb.Status),
"help" or "?" => new(SortVerb.Help),
_ => new(SortVerb.Unknown, Word: word),
};
}
/// <summary>The window and help work before the character is known; everything else waits for it.</summary>
public bool NeedsLogin => Verb is not (SortVerb.Window or SortVerb.Help);
public const string Usage = "/rsort [on | off | now | tidy | clean | unpack [pack] | status]";
public const string NoWindows =
"This RynthCore engine can't show plugin windows (it needs script windows, API v71, with ImGui on). Sorting still runs: /rsort on|off|now|tidy|clean|unpack.";
public static string Window(bool shown) => CommandReply.Shown("RynthSort window", shown);
/// <summary>"/rsort now|tidy|clean": the job that starts (it runs as soon as the way is clear).</summary>
public static string Started(SortVerb verb) => verb == SortVerb.Clean
? "Cleaning: every pack sorted, items no rule wants back to the main pack."
: "Sorting every pack now.";
public static string Unpacking(int? pack) =>
(pack != null ? $"Emptying pack {pack}" : "Emptying your side packs") + " into the main pack; auto-sort is off (/rsort on when done).";
public static string Unknown(string word) => $"Unknown '/rsort {word}'. Usage: {Usage}";
}