RynthSuite as of 2026-10-04 (internal c94715f): RynthOracle (based on Oracle of Dereth by Advis Eveldan) and RynthInventory, RynthAi patrol doorways and rooms, healing priority, strict monster priority, finish the wounded target, slayer weapons, arcs when clear, blasts like rings, learn unknown spells, looting fixes, release 2026.10.4.6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Tom Bohar 2026-10-04 18:34:29 -04:00
commit 12ca25f911
426 changed files with 108239 additions and 7521 deletions

View file

@ -0,0 +1,369 @@
using System;
using System.IO;
using RynthCore.Plugin.RynthTracker;
namespace RynthCore.TrackerSessionTests;
// Tests for RynthTracker's session persistence across plugin reloads (TrackerSessionStore):
// the save format round-trips and rejects torn or foreign files, a save restores only for
// the same client process and character within 10 minutes, the reload gap is counted once
// (never lost, never doubled), and the files land, swap and clean up as intended.
// Self-contained; fails on zero assertions.
//
// Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
internal static class Program
{
private static int _asserts;
private static int _fails;
private static void Check(bool cond, string msg)
{
_asserts++;
if (!cond) { _fails++; Console.WriteLine($" [FAIL] {msg}"); }
}
private static void Eq<T>(T actual, T expected, string msg)
{
_asserts++;
if (!Equals(actual, expected)) { _fails++; Console.WriteLine($" [FAIL] {msg}: expected {expected}, got {actual}"); }
}
private static int Main()
{
Console.WriteLine("=== RynthTracker session tests ===");
TestRise();
TestRoundTrip();
TestRoundTripNullBaselines();
TestRejectsBadText();
TestRejectsTornWrite();
TestToleratesCrlfAndUnknownKeys();
TestShouldRestore();
TestReloadGapCountedOnce();
TestReloadGapWithSpending();
TestReloadsMatchContinuousPolling();
TestNoBaselineYet();
TestFileNames();
TestFiles();
TestCleanup();
Console.WriteLine($"\n{_asserts} assertions, {_fails} failed.");
if (_asserts == 0) { Console.WriteLine("ABORT: zero assertions ran."); return 1; }
Console.WriteLine(_fails == 0 ? "ALL TRACKER SESSION TESTS PASSED." : $"{_fails} FAILURE(S).");
return _fails == 0 ? 0 : 1;
}
private static readonly DateTime Now = new(2026, 10, 1, 3, 0, 0, DateTimeKind.Utc);
private static TrackerSessionState Sample() => new()
{
ProcessId = 4321,
ProcessStartUtcTicks = Now.AddHours(-5).Ticks,
CharacterId = 0x5000_00A1,
SavedUtcTicks = Now.Ticks,
SessionStartUtcTicks = Now.AddHours(-3).Ticks,
XpTotal = 123_456_789_012,
LumTotal = 987_654,
RadTotal = 4_200,
KillsTotal = 812,
DeathsTotal = 2,
KillXp = 100_000_000_000,
XpKills = 800,
OpenKills = 3,
KillWindowUntilUtcTicks = Now.AddSeconds(2).Ticks,
MaxLevel = true,
XpBase = 191_226_310_247,
LumBase = 1_500_000,
RadBase = 0,
BankedBase = 77,
DrawnBase = -5,
};
private static void SameState(TrackerSessionState a, TrackerSessionState b, string what)
{
Eq(a.ProcessId, b.ProcessId, what + " pid");
Eq(a.ProcessStartUtcTicks, b.ProcessStartUtcTicks, what + " process start");
Eq(a.CharacterId, b.CharacterId, what + " char");
Eq(a.SavedUtcTicks, b.SavedUtcTicks, what + " saved");
Eq(a.SessionStartUtcTicks, b.SessionStartUtcTicks, what + " start");
Eq(a.XpTotal, b.XpTotal, what + " xp");
Eq(a.LumTotal, b.LumTotal, what + " lum");
Eq(a.RadTotal, b.RadTotal, what + " rad");
Eq(a.KillsTotal, b.KillsTotal, what + " kills");
Eq(a.DeathsTotal, b.DeathsTotal, what + " deaths");
Eq(a.KillXp, b.KillXp, what + " killxp");
Eq(a.XpKills, b.XpKills, what + " xpkills");
Eq(a.OpenKills, b.OpenKills, what + " openkills");
Eq(a.KillWindowUntilUtcTicks, b.KillWindowUntilUtcTicks, what + " killuntil");
Eq(a.MaxLevel, b.MaxLevel, what + " maxlevel");
Eq(a.XpBase, b.XpBase, what + " xpbase");
Eq(a.LumBase, b.LumBase, what + " lumbase");
Eq(a.RadBase, b.RadBase, what + " radbase");
Eq(a.BankedBase, b.BankedBase, what + " bankedbase");
Eq(a.DrawnBase, b.DrawnBase, what + " drawnbase");
}
// First read is the baseline; rises count; a drop only moves the baseline.
private static void TestRise()
{
var r = new TrackerRise();
Eq(r.Baseline, (long?)null, "no baseline before the first read");
Eq(r.Take(1000), 0L, "first read is the baseline");
Eq(r.Baseline, (long?)1000, "baseline after the first read");
Eq(r.Take(1250), 250L, "rise counts");
Eq(r.Take(900), 0L, "drop counts nothing");
Eq(r.Take(950), 50L, "rise after a drop counts from the drop");
r.Clear();
Eq(r.Take(5000), 0L, "after Clear the next read is the baseline again");
}
private static void TestRoundTrip()
{
var s = Sample();
string text = TrackerSessionStore.Serialize(s);
Check(text.StartsWith(TrackerSessionStore.Header + "\n", StringComparison.Ordinal), "header first");
Check(TrackerSessionStore.TryParse(text, out var back), "round trip parses");
SameState(back, s, "round trip");
}
private static void TestRoundTripNullBaselines()
{
var s = Sample();
s.XpBase = null; s.LumBase = null; s.RadBase = null; s.BankedBase = null; s.DrawnBase = null;
s.MaxLevel = false;
Check(TrackerSessionStore.TryParse(TrackerSessionStore.Serialize(s), out var back), "null baselines parse");
SameState(back, s, "null baselines");
}
private static void TestRejectsBadText()
{
string good = TrackerSessionStore.Serialize(Sample());
Check(!TrackerSessionStore.TryParse(null, out _), "null rejected");
Check(!TrackerSessionStore.TryParse("", out _), "empty rejected");
Check(!TrackerSessionStore.TryParse(good.Replace("session v1", "session v9"), out _), "other version rejected");
Check(!TrackerSessionStore.TryParse(good.Replace("end=1\n", ""), out _), "no end marker rejected");
Check(!TrackerSessionStore.TryParse(good.Replace("kills=812\n", ""), out _), "missing field rejected");
Check(!TrackerSessionStore.TryParse(good.Replace("kills=812", "kills=lots"), out _), "bad number rejected");
Check(!TrackerSessionStore.TryParse(good.Replace("maxlevel=1", "maxlevel=yes"), out _), "bad flag rejected");
Check(!TrackerSessionStore.TryParse(good.Replace("xpbase=191226310247", "xpbase=?"), out _), "bad baseline rejected");
Check(!TrackerSessionStore.TryParse(good.Replace("char=1342177441", "char=-1"), out _), "negative character rejected");
Check(!TrackerSessionStore.TryParse(good.Replace("deaths=2", "deaths 2"), out _), "line without = rejected");
Check(!TrackerSessionStore.TryParse(good.Replace("saved=" + Now.Ticks, "saved=" + long.MaxValue), out _), "ticks out of DateTime range rejected");
}
// Any cut before the end marker (a half-written file) must not parse.
private static void TestRejectsTornWrite()
{
string good = TrackerSessionStore.Serialize(Sample());
int endAt = good.IndexOf("end=1", StringComparison.Ordinal) + "end=1".Length;
int parsed = 0;
for (int len = 0; len < endAt; len++)
if (TrackerSessionStore.TryParse(good.Substring(0, len), out _)) parsed++;
Eq(parsed, 0, "no cut before the end marker parses");
}
private static void TestToleratesCrlfAndUnknownKeys()
{
string good = TrackerSessionStore.Serialize(Sample());
Check(TrackerSessionStore.TryParse(good.Replace("\n", "\r\n"), out var crlf), "CRLF parses");
SameState(crlf, Sample(), "CRLF");
Check(TrackerSessionStore.TryParse(good.Replace("end=1", "future=thing\nend=1"), out _), "unknown key ignored");
}
private static void TestShouldRestore()
{
var s = Sample();
int pid = s.ProcessId;
uint chr = s.CharacterId;
long ps = s.ProcessStartUtcTicks;
Check(TrackerSessionStore.ShouldRestore(s, pid, ps, chr, Now.AddSeconds(5)), "same client, same character, 5 s later");
Check(TrackerSessionStore.ShouldRestore(s, pid, ps, chr, Now.AddMinutes(9).AddSeconds(59)), "9:59 later");
Check(!TrackerSessionStore.ShouldRestore(s, pid, ps, chr, Now.AddMinutes(10).AddSeconds(1)), "10:01 later is stale");
Check(!TrackerSessionStore.ShouldRestore(s, pid + 1, ps, chr, Now.AddSeconds(5)), "another client process");
Check(!TrackerSessionStore.ShouldRestore(s, pid, ps, chr + 1, Now.AddSeconds(5)), "another character");
Check(!TrackerSessionStore.ShouldRestore(s, pid, ps, 0, Now.AddSeconds(5)), "no character id");
Check(!TrackerSessionStore.ShouldRestore(s, pid, ps + 1, chr, Now.AddSeconds(5)), "same process id, another client (reused id)");
Check(TrackerSessionStore.ShouldRestore(s, pid, ps, chr, Now.AddSeconds(-30)), "clock 30 s behind the save: slack");
Check(!TrackerSessionStore.ShouldRestore(s, pid, ps, chr, Now.AddMinutes(-2)), "save 2 min in the future");
var odd = Sample();
odd.SessionStartUtcTicks = odd.SavedUtcTicks + 1;
Check(!TrackerSessionStore.ShouldRestore(odd, pid, ps, chr, Now.AddSeconds(5)), "session starting after its save");
}
// XP keeps coming in while the plugin is unloaded: the first read after the restore
// counts the whole gap once, so the total equals the real rise since the session began.
private static void TestReloadGapCountedOnce()
{
long total = 0;
var xp = new TrackerRise();
total += xp.Take(1_000); // baseline
total += xp.Take(1_100);
total += xp.Take(1_250);
var saved = Sample();
saved.XpTotal = total;
saved.XpBase = xp.Baseline;
Check(TrackerSessionStore.TryParse(TrackerSessionStore.Serialize(saved), out var back), "gap save parses");
// Unloaded: XP rises to 1,400. New plugin copy restores.
long total2 = back.XpTotal;
var xp2 = new TrackerRise();
xp2.Restore(back.XpBase);
total2 += xp2.Take(1_400);
Eq(total2, 400L, "gap counted once (not lost, not doubled)");
total2 += xp2.Take(1_400);
Eq(total2, 400L, "a second read with no change adds nothing");
total2 += xp2.Take(1_450);
Eq(total2, 450L, "later rises carry on");
}
// Luminance spent during the gap only moves the baseline, as it would while loaded.
private static void TestReloadGapWithSpending()
{
var lum = new TrackerRise();
lum.Take(500);
lum.Take(600); // +100 before the save
long? saved = lum.Baseline;
var lum2 = new TrackerRise();
lum2.Restore(saved);
Eq(lum2.Take(200), 0L, "spent in the gap: nothing counted");
Eq(lum2.Take(260), 60L, "rise after the spend counts from the new low");
}
// A monotonic total (experience) polled with reloads at arbitrary points ends with the
// same session total as polling it straight through.
private static void TestReloadsMatchContinuousPolling()
{
var rng = new Random(20261001);
for (int trial = 0; trial < 200; trial++)
{
int reads = 5 + rng.Next(40);
long[] values = new long[reads];
long v = 1_000_000 + rng.Next(1_000_000);
for (int i = 0; i < reads; i++) { v += rng.Next(3) == 0 ? 0 : rng.Next(50_000); values[i] = v; }
long straight = 0;
var a = new TrackerRise();
foreach (long x in values) straight += a.Take(x);
long reloaded = 0;
var b = new TrackerRise();
int savedThrough = -1;
long savedTotal = 0;
long? savedBase = null;
for (int i = 0; i < reads; i++)
{
// Sometimes a save (after this read), sometimes a reload that skips reads
// (the gap) and restores from the last save.
if (rng.Next(4) == 0) { savedTotal = reloaded; savedBase = b.Baseline; savedThrough = i - 1; }
if (rng.Next(6) == 0 && savedThrough >= 0)
{
var st = Sample();
st.XpTotal = savedTotal;
st.XpBase = savedBase;
TrackerSessionStore.TryParse(TrackerSessionStore.Serialize(st), out var back);
reloaded = back.XpTotal;
b = new TrackerRise();
b.Restore(back.XpBase);
i += rng.Next(3); // reads missed while unloaded
if (i >= reads) i = reads - 1;
}
reloaded += b.Take(values[i]);
}
if (reloaded != straight)
{
Eq(reloaded, straight, $"trial {trial}: reloaded total vs straight-through total");
return;
}
}
Check(true, "200 random reload trials match straight-through polling");
}
// Saved before anything was read: the restored copy treats its first read as the baseline.
private static void TestNoBaselineYet()
{
var r = new TrackerRise();
r.Restore(null);
Eq(r.Baseline, (long?)null, "null restore keeps no baseline");
Eq(r.Take(7_000), 0L, "first read after a null restore is the baseline");
Eq(r.Take(7_100), 100L, "then rises count");
}
private static void TestFileNames()
{
string a = TrackerSessionStore.FileName(100, 0x50000001);
Eq(a, "session-100-50000001.txt", "file name format");
Check(a != TrackerSessionStore.FileName(101, 0x50000001), "process id in the name");
Check(a != TrackerSessionStore.FileName(100, 0x50000002), "character id in the name");
Check(TrackerSessionStore.DefaultDirectory().EndsWith(Path.Combine("RynthCore", "tracker"), StringComparison.OrdinalIgnoreCase),
"default folder is RynthCore\\tracker");
}
private static string TempDir()
{
string dir = Path.Combine(Path.GetTempPath(), "rynthtracker-tests-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
return dir;
}
private static void TestFiles()
{
string dir = Path.Combine(TempDir(), "nested", "tracker"); // Save creates it
try
{
var s = Sample();
TrackerSessionStore.Save(dir, s);
Check(TrackerSessionStore.TryLoad(dir, s.ProcessId, s.CharacterId, out var back), "saved file loads");
SameState(back, s, "file round trip");
Check(!TrackerSessionStore.TryLoad(dir, s.ProcessId, s.CharacterId + 1, out _), "another character finds no file");
Check(!TrackerSessionStore.TryLoad(dir, s.ProcessId + 1, s.CharacterId, out _), "another process finds no file");
s.KillsTotal = 900;
TrackerSessionStore.Save(dir, s);
TrackerSessionStore.TryLoad(dir, s.ProcessId, s.CharacterId, out back);
Eq(back.KillsTotal, 900, "second save replaces the first");
Eq(Directory.GetFiles(dir).Length, 1, "one file, no temp left over");
File.WriteAllText(Path.Combine(dir, TrackerSessionStore.FileName(s.ProcessId, s.CharacterId)), "RynthTracker session v1\npid=4");
Check(!TrackerSessionStore.TryLoad(dir, s.ProcessId, s.CharacterId, out _), "half file doesn't load");
TrackerSessionStore.Delete(dir, s.ProcessId, s.CharacterId);
Check(!TrackerSessionStore.TryLoad(dir, s.ProcessId, s.CharacterId, out _), "deleted (logout) file is gone");
TrackerSessionStore.Delete(dir, s.ProcessId, s.CharacterId);
Check(true, "deleting a missing file is fine");
}
finally { try { Directory.Delete(Path.GetDirectoryName(Path.GetDirectoryName(dir))!, true); } catch { } }
}
private static void TestCleanup()
{
string dir = TempDir();
try
{
Eq(TrackerSessionStore.Cleanup(Path.Combine(dir, "missing"), 1, Now), 0, "missing folder: nothing to do");
void Put(int pid, uint chr, DateTime written)
{
var s = Sample(); s.ProcessId = pid; s.CharacterId = chr;
TrackerSessionStore.Save(dir, s);
File.SetLastWriteTimeUtc(Path.Combine(dir, TrackerSessionStore.FileName(pid, chr)), written);
}
DateTime now = DateTime.UtcNow;
Put(10, 0xA, now); // this client, old character (no logout seen)
Put(10, 0xB, now); // this client, another old character
Put(20, 0xC, now.AddMinutes(-1)); // another live client: keep
Put(30, 0xD, now.AddDays(-2)); // a client closed long ago: purge
File.WriteAllText(Path.Combine(dir, "notes.txt"), "not ours");
int removed = TrackerSessionStore.Cleanup(dir, 10, now);
Eq(removed, 3, "own-process saves and the long-dead client's save removed");
Check(!File.Exists(Path.Combine(dir, TrackerSessionStore.FileName(10, 0xA))), "own save A gone");
Check(!File.Exists(Path.Combine(dir, TrackerSessionStore.FileName(10, 0xB))), "own save B gone");
Check(File.Exists(Path.Combine(dir, TrackerSessionStore.FileName(20, 0xC))), "other live client's save kept");
Check(!File.Exists(Path.Combine(dir, TrackerSessionStore.FileName(30, 0xD))), "2-day-old save purged");
Check(File.Exists(Path.Combine(dir, "notes.txt")), "unrelated files left alone");
}
finally { try { Directory.Delete(dir, true); } catch { } }
}
}

View file

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
Tests for RynthTracker's session persistence (TrackerSessionStore: the line format,
the same-process/same-character/recent restore rule, the file save/load/cleanup and the
reload-gap rule for the Rise baselines). The plugin itself is a NativeAOT x86 library,
so the dependency-free source file is compiled in here directly instead of referencing
the plugin project. File tests use a temp folder, never %LOCALAPPDATA%\RynthCore.
Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
-->
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>RynthCore.TrackerSessionTests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthTracker\TrackerSessionStore.cs" Link="Linked\TrackerSessionStore.cs" />
</ItemGroup>
</Project>