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

@ -49,6 +49,8 @@
<ItemGroup>
<!-- 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>
</Project>

View file

@ -90,6 +90,7 @@ public sealed partial class RynthLuaPlugin : RynthPluginBase
public override int Initialize()
{
_ = Reply;
_ai = new RynthAiBridge(Host);
// Every use logged (Plugins/Shared/UseAudit.cs). Scripts are the player's: no guard.
RynthCore.Plugin.Shared.UseAudit.Reset("RynthLua", null);
@ -133,8 +134,9 @@ public sealed partial class RynthLuaPlugin : RynthPluginBase
while (_chatCommands.TryDequeue(out string? line))
{
try { HandleLuaChatCommand(line); }
catch (Exception ex) { ChatLine("error: " + ex.Message); }
catch (Exception ex) { ChatFail("error: " + ex.Message); }
}
Reply.Flush();
// Script windows are kept apart from the scripts: a fault in the window steps is logged
// (at most every 10 s) and can't stop every script's threads from running.
try { PollHudEvents(); } // script windows: input first, so this tick's passes see it
@ -291,10 +293,16 @@ public sealed partial class RynthLuaPlugin : RynthPluginBase
_chatCommands.Enqueue("/lua " + value);
}
internal void ChatLine(string text)
{
if (Host.HasWriteToChat) Host.WriteToChat("[RynthLua] " + text, 1);
}
// Chat lines wait in the shared reply queue (Plugins/Shared/CommandReply.cs): the host drops a line
// within 100 ms of another plugin's, so /lua's two-line usage used to lose its second line.
private RynthCore.Plugin.Shared.CommandReply? _reply;
private RynthCore.Plugin.Shared.CommandReply Reply => _reply ??= new RynthCore.Plugin.Shared.CommandReply("[RynthLua]",
(t, c) => Host.HasWriteToChat && Host.WriteToChat(t, c), t => Log(t));
internal void ChatLine(string text) => Reply.Ok(text);
/// <summary>A /lua command that didn't work: why, and the usage (the failure colour).</summary>
internal void ChatFail(string text) => Reply.Fail(text);
// ── Panel ───────────────────────────────────────────────────────────────

View file

@ -285,13 +285,15 @@ public sealed partial class RynthLuaPlugin
case "start":
{
string? err = StartScript(rest);
ChatLine(err ?? $"Running {FindScript(rest)?.Name ?? rest}.");
if (err != null) ChatFail(err);
else ChatLine($"Running {FindScript(rest)?.Name ?? rest}.");
break;
}
case "restart":
{
string? err = StartScript(rest);
ChatLine(err ?? $"Restarted {FindScript(rest)?.Name ?? rest}.");
if (err != null) ChatFail(err);
else ChatLine($"Restarted {FindScript(rest)?.Name ?? rest}.");
break;
}
case "stop":
@ -301,18 +303,25 @@ public sealed partial class RynthLuaPlugin
StopAll("stopped");
ChatLine(n == 0 ? "No script is running." : $"Stopped {n} script(s).");
}
else ChatLine(StopScript(FindScript(rest)?.Name ?? rest) ? $"Stopped {rest}." : $"{rest} isn't running.");
else if (StopScript(FindScript(rest)?.Name ?? rest)) ChatLine($"Stopped {rest}.");
else ChatFail($"{rest} isn't running.");
break;
case "exec":
if (rest.Length == 0) { ChatLine("Usage: /lua exec <code>"); break; }
RunCode("exec", rest);
{
if (rest.Length == 0) { ChatFail("Usage: /lua exec <code>"); break; }
ScriptContext ran = RunCode("exec", rest);
// Its output and errors go to the script console (the Lua window); chat says whether it started.
if (ran.Host.Loaded) ChatLine("exec: started (its output is in the Lua window's console).");
else ChatFail("exec: the code didn't run" + LastConsoleError(ran));
break;
}
case "execin":
{
string[] p = rest.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
if (p.Length < 2) { ChatLine("Usage: /lua execin <script> <code>"); break; }
if (!_scripts.TryGetValue(p[0], out var ctx) || !ctx.Host.Loaded) { ChatLine($"{p[0]} isn't running."); break; }
ctx.Host.Exec(p[1]);
if (p.Length < 2) { ChatFail("Usage: /lua execin <script> <code>"); break; }
if (!_scripts.TryGetValue(p[0], out var ctx) || !ctx.Host.Loaded) { ChatFail($"{p[0]} isn't running."); break; }
if (ctx.Host.Exec(p[1])) ChatLine($"execin {ctx.Name}: started (its output is in {ctx.Name}'s console).");
else ChatFail($"execin {ctx.Name}: the code didn't run" + LastConsoleError(ctx));
break;
}
case "autostart":
@ -321,7 +330,7 @@ public sealed partial class RynthLuaPlugin
string mode = p.Length > 1 ? p[1].ToLowerInvariant() : "";
var e = p.Length > 0 ? FindScript(p[0]) : null;
if (e == null || mode is not ("none" or "global" or "character"))
{ ChatLine("Usage: /lua autostart <script> none|global|character"); break; }
{ ChatFail("Usage: /lua autostart <script> none|global|character"); break; }
SetAutostart(e.Name, mode);
ChatLine($"{e.Name}: autostart {mode}.");
break;
@ -340,12 +349,26 @@ public sealed partial class RynthLuaPlugin
HandleHudCommand(rest);
break;
default:
ChatLine("/lua list | start <script> | stop <script>|all | restart <script> | exec <code> | execin <script> <code> | autostart <script> none|global|character | hud list|show|hide|toggle <script>/<hud>|bench <n>|bench off");
{
// Bare /lua and /lua help: the usage. A word that is neither a verb nor a script's command: why, then the usage.
const string usage = "/lua list | start <script> | stop <script>|all | restart <script> | exec <code> | execin <script> <code> | autostart <script> none|global|character | hud list|show|hide|toggle <script>/<hud>|bench <n>|bench off";
if (sub is "" or "help" or "?") ChatLine(usage);
else ChatFail($"Unknown '/lua {sub}'. {usage}");
ChatLine("/lua <command> [args] runs a script command (game.RegisterCommand) - " + ScriptCommandsSummary());
break;
}
}
}
/// <summary>": " and the last error line in the script's console (why its code didn't run), or ".".</summary>
private static string LastConsoleError(ScriptContext ctx)
{
string[] lines = ctx.Host.ConsoleText().Split('\n');
for (int i = lines.Length - 1; i >= 0; i--)
if (lines[i].StartsWith("error", StringComparison.OrdinalIgnoreCase)) return ": " + lines[i].Trim();
return ".";
}
/// <summary>The registered script commands for the /lua usage text.</summary>
private string ScriptCommandsSummary()
{

View file

@ -793,16 +793,17 @@ public sealed partial class RynthLuaPlugin
string arg = p.Length > 1 ? p[1].Trim() : "";
if (arg.Equals("off", StringComparison.OrdinalIgnoreCase) || arg.Equals("stop", StringComparison.OrdinalIgnoreCase))
{
ChatLine(StopScript(BenchScript) ? "Bench stopped." : "The bench isn't running.");
if (StopScript(BenchScript)) ChatLine("Bench stopped.");
else ChatFail("The bench isn't running.");
break;
}
if (!int.TryParse(arg, NumberStyles.Integer, CultureInfo.InvariantCulture, out int n) || n < 1)
{
ChatLine("Usage: /lua hud bench <widgets 1-1500> | /lua hud bench off");
ChatFail("Usage: /lua hud bench <widgets 1-1500> | /lua hud bench off");
break;
}
n = Math.Min(n, 1500);
if (!UiAvailable) { ChatLine("Script windows need RynthCore API v71 with ImGui on."); break; }
if (!UiAvailable) { ChatFail("Script windows need RynthCore API v71 with ImGui on."); break; }
RunCode(BenchScript, BenchCode(n));
ChatLine($"Bench: a hud with {n} widgets. Measurements go to the log every ~10 s ('hud passes:' and 'ScriptWindows replay:'). /lua hud bench off to stop.");
break;
@ -818,7 +819,7 @@ public sealed partial class RynthLuaPlugin
ScriptHud? hud = FindHud(name, out string? problem);
if (hud == null)
{
ChatLine((problem ?? $"No hud named '{name}'.") + " " + HudListLine());
ChatFail((problem ?? $"No hud named '{name}'.") + " " + HudListLine());
break;
}
bool show = sub == "show" || sub == "toggle" && !hud.Visible;
@ -828,7 +829,8 @@ public sealed partial class RynthLuaPlugin
break;
}
default:
ChatLine("/lua hud list | show|hide|toggle <script>/<hud> | bench <widgets 1-1500> | bench off");
if (sub is "" or "help") ChatLine("/lua hud list | show|hide|toggle <script>/<hud> | bench <widgets 1-1500> | bench off");
else ChatFail($"Unknown '/lua hud {sub}'. /lua hud list | show|hide|toggle <script>/<hud> | bench <widgets 1-1500> | bench off");
break;
}
}