Snapshot for release 2026.10.13.3 (internal 8440a2e)
This commit is contained in:
parent
56b9f6c813
commit
e25cb7c9ae
23 changed files with 2666 additions and 289 deletions
|
|
@ -226,6 +226,21 @@ internal static unsafe class FakeHost
|
|||
public static int ForceResets;
|
||||
public static int BusyStateValue;
|
||||
|
||||
/// <summary>Opt-in (set before Create): GetObjectProperties (API v84), answering the record
|
||||
/// <see cref="PropertyRecord"/> returns for an id (null = the engine knows nothing: 0).</summary>
|
||||
public static bool ObjectPropertiesCalls;
|
||||
public static Func<uint, byte[]?>? PropertyRecord;
|
||||
/// <summary>GetObjectProperties calls, in order (the buffer-size retries included).</summary>
|
||||
public static readonly List<uint> PropertyQueries = new();
|
||||
|
||||
/// <summary>Object id -> CPhysicsObj m_state (GetObjectState; 0x4 ETHEREAL = a door that is open).
|
||||
/// When it has entries at Create() time the host also gets GetObjectState (opt-in, as Bitfields).</summary>
|
||||
public static readonly Dictionary<uint, uint> ObjectStates = new();
|
||||
/// <summary>Runs inside UseObject, after the use is recorded (the test plays the server here).</summary>
|
||||
public static Action<uint>? OnUseObject;
|
||||
/// <summary>Runs inside UseObjectOn, after it is recorded.</summary>
|
||||
public static Action<uint, uint>? OnUseObjectOn;
|
||||
|
||||
// ANSI strings handed back to tested code stay alive for the whole run.
|
||||
private static readonly Dictionary<string, IntPtr> _ansi = new();
|
||||
|
||||
|
|
@ -268,6 +283,8 @@ internal static unsafe class FakeHost
|
|||
PluginCommandCalls = false; PluginCommandDelivered = true; PluginCommands.Clear();
|
||||
CombatModeCalls = false; CombatModeRequests.Clear(); CombatModeRefuse = false; CombatModeRefusals = 0;
|
||||
BusyCalls = false; ForceResets = 0; BusyStateValue = 0;
|
||||
ObjectPropertiesCalls = false; PropertyRecord = null; PropertyQueries.Clear();
|
||||
ObjectStates.Clear(); OnUseObject = null; OnUseObjectOn = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -306,6 +323,8 @@ internal static unsafe class FakeHost
|
|||
api.GetContainerContentsFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, uint*, int, int>)&GetContainerContents;
|
||||
if (Bitfields.Count > 0)
|
||||
api.GetObjectBitfieldFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, uint>)&GetObjectBitfield;
|
||||
if (ObjectStates.Count > 0)
|
||||
api.GetObjectStateFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, uint*, int>)&GetObjectState;
|
||||
if (InstanceIds.Count > 0)
|
||||
api.GetObjectInstanceIdPropertyFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, uint, uint*, int>)&GetObjectInstanceIdProperty;
|
||||
api.SetAutoRunFn = (IntPtr)(delegate* unmanaged[Cdecl]<int, int>)&SetAutoRun;
|
||||
|
|
@ -424,6 +443,11 @@ internal static unsafe class FakeHost
|
|||
api.Version = Math.Max(api.Version, 64u);
|
||||
api.SendPluginCommandFn = (IntPtr)(delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, int>)&SendPluginCommand;
|
||||
}
|
||||
if (ObjectPropertiesCalls)
|
||||
{
|
||||
api.Version = Math.Max(api.Version, 84u);
|
||||
api.GetObjectPropertiesFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, byte*, int, int>)&GetObjectProperties;
|
||||
}
|
||||
LastApi = api;
|
||||
return new RynthCoreHost(api);
|
||||
}
|
||||
|
|
@ -646,6 +670,16 @@ internal static unsafe class FakeHost
|
|||
return ids.Length;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int GetObjectProperties(uint id, byte* buf, int size)
|
||||
{
|
||||
PropertyQueries.Add(id);
|
||||
byte[]? rec = PropertyRecord?.Invoke(id);
|
||||
if (rec == null) return 0;
|
||||
if (rec.Length <= size) rec.AsSpan().CopyTo(new Span<byte>(buf, size));
|
||||
return rec.Length;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int GetObjectPalettes(uint id, uint* subIds, uint* offsets, int max)
|
||||
{
|
||||
|
|
@ -750,10 +784,17 @@ internal static unsafe class FakeHost
|
|||
private static int ChangeCombatMode(int mode) { if (CombatModeRefuse) { CombatModeRefusals++; return 0; } CombatModeRequests.Add(mode); return 1; }
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int UseObject(uint id) { Uses.Add(id); return 1; }
|
||||
private static int UseObject(uint id) { Uses.Add(id); OnUseObject?.Invoke(id); return 1; }
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int GetObjectState(uint id, uint* state)
|
||||
{
|
||||
if (!ObjectStates.TryGetValue(id, out uint s)) return 0;
|
||||
*state = s;
|
||||
return 1;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int UseObjectOn(uint source, uint target) { UsesOn.Add((source, target)); return 1; }
|
||||
private static int UseObjectOn(uint source, uint target) { UsesOn.Add((source, target)); OnUseObjectOn?.Invoke(source, target); return 1; }
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int WieldItem(uint id, uint mask) { Wields.Add((id, mask)); return 1; }
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ internal static class Program
|
|||
var runner = new Runner();
|
||||
NativeLootTests.Register(runner);
|
||||
VTankLootTests.Register(runner);
|
||||
PropertyDumpTests.Register(runner);
|
||||
T11LootTests.Register(runner);
|
||||
MagItemDescriberTests.Register(runner);
|
||||
ExpressionTests.Register(runner);
|
||||
|
|
@ -125,6 +126,8 @@ internal static class Program
|
|||
CorpseCloseTests.Register(runner);
|
||||
VTankHotkeyTests.Register(runner);
|
||||
SaveFailureTests.Register(runner);
|
||||
DoorTests.Register(runner);
|
||||
BlankLoadTests.Register(runner);
|
||||
return runner.Run("RynthAi host tests", args.Length > 0 ? args[0] : null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,10 @@
|
|||
<Compile Include="..\..\..\RynthCore\src\RynthCore.Engine\UI\Data\MetaLocation.cs" Link="Engine\MetaLocation.cs" />
|
||||
<!-- The Inventory panel's attribute filter rules and matching (pure; engine 2026-10-11). -->
|
||||
<Compile Include="..\..\..\RynthCore\src\RynthCore.Engine\Compatibility\InventoryAttributeFilter.cs" Link="Engine\InventoryAttributeFilter.cs" />
|
||||
<!-- The engine's v84 GetObjectProperties record writer (pure), so the propertydump tests feed
|
||||
RynthAi exactly what the engine sends (engine 2026-10-13). -->
|
||||
<Compile Include="..\..\..\RynthCore\src\RynthCore.Engine\Compatibility\PropertyWire.cs" Link="Engine\PropertyWire.cs" />
|
||||
<Compile Include="..\..\..\RynthCore\src\RynthCore.Engine\Compatibility\ObjectPropertyRecord.cs" Link="Engine\ObjectPropertyRecord.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
319
Tools/RynthCore.RynthAiHostTests/Tests/BlankLoadTests.cs
Normal file
319
Tools/RynthCore.RynthAiHostTests/Tests/BlankLoadTests.cs
Normal file
|
|
@ -0,0 +1,319 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.Plugin.RynthAi.Meta;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.PluginCore;
|
||||
using RynthCore.PluginSdk;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// 2026-10-13: "load makes a new one", as in VTank. /ra nav load <name> and /vt nav load create an
|
||||
// empty Circular route when NavProfiles has no <name>.nav, and load it (so a route can be recorded
|
||||
// into it); /ra meta load <name> and /vt meta load create a blank <name>.af (one state "Default", no
|
||||
// rules) when MetaFiles has neither <name>.af nor <name>.met, and load it: the old rules are
|
||||
// cleared and the meta is in Default. Existing files are loaded as before, never rewritten. Names
|
||||
// that aren't plain file names are refused. Only scratch folders are used (the dashboard's
|
||||
// NavProfiles / MetaFiles fields are pointed at them).
|
||||
internal static class BlankLoadTests
|
||||
{
|
||||
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("blank load: /ra nav load <new name> creates an empty Circular nav and loads it", NavCreates);
|
||||
r.Add("blank load: /ra nav load of an existing nav loads it, file unchanged", NavExisting);
|
||||
r.Add("blank load: a blank nav round-trips through the nav parser (VTank header, 0 points)", NavRoundTrip);
|
||||
r.Add("blank load: /ra meta load <new name> creates a blank .af and loads it (rules cleared, state Default)", MetaCreates);
|
||||
r.Add("blank load: /ra meta load of an existing .af / .met loads it, files unchanged", MetaExisting);
|
||||
r.Add("blank load: /ra meta new creates only; an existing meta is left alone", MetaNew);
|
||||
r.Add("blank load: a blank .af round-trips through AfFileParser; a file with no state is still refused", MetaRoundTrip);
|
||||
r.Add("blank load: unsafe names are refused and nothing is written", UnsafeNames);
|
||||
r.Add("blank load: names are tidied (quotes, .nav/.af/.met)", Tidy);
|
||||
r.Add("blank load: /ra meta load|new|list reach the dashboard", MetaCommand);
|
||||
}
|
||||
|
||||
private sealed class Rig
|
||||
{
|
||||
public readonly LegacyUiSettings S = new();
|
||||
public readonly LegacyDashboardRenderer Dash;
|
||||
public readonly string Root, Navs, Metas;
|
||||
|
||||
public Rig(string name)
|
||||
{
|
||||
Root = Path.Combine(Program.TempRoot, "blank-load", name);
|
||||
if (Directory.Exists(Root)) Directory.Delete(Root, recursive: true);
|
||||
Navs = Path.Combine(Root, "NavProfiles");
|
||||
Metas = Path.Combine(Root, "MetaFiles");
|
||||
Directory.CreateDirectory(Navs);
|
||||
Directory.CreateDirectory(Metas);
|
||||
|
||||
Dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer));
|
||||
var navFiles = new List<string>();
|
||||
Set("_settings", S);
|
||||
Set("_host", FakeHost.Create());
|
||||
Set("_navFolder", Navs);
|
||||
Set("_metaFolder", Metas);
|
||||
Set("_navFiles", navFiles);
|
||||
Set("_metaFiles", new List<string>());
|
||||
Set("_profileListsLock", new object());
|
||||
Set("_metaUi", new LegacyMetaUi(S, navFiles));
|
||||
// _settingsFilePath stays null: SaveSettings writes nothing.
|
||||
}
|
||||
|
||||
private void Set(string f, object v) => typeof(LegacyDashboardRenderer).GetField(f, Any)!.SetValue(Dash, v);
|
||||
|
||||
public string[] Files() => Directory.GetFiles(Root, "*", SearchOption.AllDirectories);
|
||||
}
|
||||
|
||||
private static List<MetaRule> HuntRules() => new()
|
||||
{
|
||||
new MetaRule { State = "Hunt", Condition = MetaConditionType.Always, Action = MetaActionType.ChatCommand, ActionData = "/ra start" },
|
||||
new MetaRule { State = "Hunt", Condition = MetaConditionType.Always, Action = MetaActionType.SetMetaState, ActionData = "Default" },
|
||||
};
|
||||
|
||||
private static void NavCreates()
|
||||
{
|
||||
DataWriteGuard.Reset();
|
||||
var rig = new Rig("nav-create");
|
||||
rig.S.CurrentRoute.Points.Add(new NavPoint { NS = 1, EW = 2 }); // a route was loaded before
|
||||
rig.S.CurrentRoute.RouteType = NavRouteType.Linear;
|
||||
|
||||
string msg = rig.Dash.LoadNavByName("Fresh Route");
|
||||
string path = Path.Combine(rig.Navs, "Fresh Route.nav");
|
||||
Check.Eq(msg, "[RynthAi] Created new nav 'Fresh Route' (empty, Circular) and loaded it.", "message");
|
||||
Check.True(File.Exists(path), "Fresh Route.nav written");
|
||||
Check.Eq(string.Join("|", File.ReadAllLines(path)), "uTank2 NAV 1.2|1|0", "VTank nav: header, Circular, 0 points");
|
||||
Check.Eq(rig.S.CurrentNavPath, path, "it is the loaded nav");
|
||||
Check.Eq(rig.S.CurrentRoute.Points.Count, 0, "the old route's points are gone");
|
||||
Check.Eq(rig.S.CurrentRoute.RouteType, NavRouteType.Circular, "Circular");
|
||||
Check.Eq(rig.S.ActiveNavIndex, 0, "at the start");
|
||||
Check.True(rig.Dash.NavFileNames().Contains("Fresh Route"), "listed by /ra nav list");
|
||||
|
||||
// Loading it again finds it (no second create).
|
||||
msg = rig.Dash.LoadNavByName("fresh route");
|
||||
Check.Eq(msg, "[RynthAi] Loaded fresh route (0 waypoints).", "second load is a plain load: " + msg);
|
||||
Check.Eq(DataWriteGuard.PendingCount, 0, "nothing reported");
|
||||
}
|
||||
|
||||
private static void NavExisting()
|
||||
{
|
||||
var rig = new Rig("nav-existing");
|
||||
string path = Path.Combine(rig.Navs, "Hive Loop.nav");
|
||||
var route = new NavRouteParser { RouteType = NavRouteType.Linear };
|
||||
route.Points.Add(new NavPoint { NS = 10.5, EW = -3.25 });
|
||||
route.Points.Add(new NavPoint { NS = 11.5, EW = -4.25 });
|
||||
route.Save(path);
|
||||
byte[] before = File.ReadAllBytes(path);
|
||||
DateTime stamp = File.GetLastWriteTimeUtc(path);
|
||||
|
||||
string msg = rig.Dash.LoadNavByName("\"Hive Loop.nav\"");
|
||||
Check.Eq(msg, "[RynthAi] Loaded Hive Loop (2 waypoints).", "loaded: " + msg);
|
||||
Check.Eq(rig.S.CurrentNavPath, path, "the existing file");
|
||||
Check.Eq(rig.S.CurrentRoute.RouteType, NavRouteType.Linear, "its own route type");
|
||||
Check.True(((ReadOnlySpan<byte>)File.ReadAllBytes(path)).SequenceEqual(before), "file bytes unchanged");
|
||||
Check.Eq(File.GetLastWriteTimeUtc(path), stamp, "file not rewritten");
|
||||
Check.Eq(Directory.GetFiles(rig.Navs).Length, 1, "no other file");
|
||||
}
|
||||
|
||||
private static void NavRoundTrip()
|
||||
{
|
||||
NavRouteParser blank = NewProfileFiles.BlankNav();
|
||||
List<string> lines = blank.ToLines();
|
||||
Check.Eq(string.Join("|", lines), "uTank2 NAV 1.2|1|0", "lines");
|
||||
NavRouteParser back = NavRouteParser.LoadFromLines(lines);
|
||||
Check.Eq(back.RouteType, NavRouteType.Circular, "route type");
|
||||
Check.Eq(back.Points.Count, 0, "no points");
|
||||
Check.Null(back.LoadWarning, "no warning");
|
||||
|
||||
string path = Path.Combine(Program.TempRoot, "blank-load", "roundtrip.nav");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
blank.Save(path);
|
||||
NavRouteParser fromFile = NavRouteParser.Load(path);
|
||||
Check.Eq(fromFile.RouteType, NavRouteType.Circular, "file: route type");
|
||||
Check.Eq(fromFile.Points.Count, 0, "file: no points");
|
||||
Check.Null(fromFile.LoadWarning, "file: no warning");
|
||||
Check.Eq(string.Join("|", fromFile.ToLines()), "uTank2 NAV 1.2|1|0", "saves back the same");
|
||||
}
|
||||
|
||||
private static void MetaCreates()
|
||||
{
|
||||
DataWriteGuard.Reset();
|
||||
var rig = new Rig("meta-create");
|
||||
rig.S.MetaRules = HuntRules();
|
||||
rig.S.EmbeddedNavs["old nav"] = new List<string> { "uTank2 NAV 1.2", "1", "0" };
|
||||
rig.S.CurrentState = "Hunt";
|
||||
rig.S.CurrentMetaPath = Path.Combine(rig.Metas, "old.af");
|
||||
|
||||
string msg = rig.Dash.LoadMetaByName("'Blank Farm.af'");
|
||||
string path = Path.Combine(rig.Metas, "Blank Farm.af");
|
||||
Check.Eq(msg, "[RynthAi] Created new meta 'Blank Farm' (one state 'Default', no rules) and loaded it.", "message");
|
||||
Check.True(File.Exists(path), "Blank Farm.af written");
|
||||
Check.Eq(File.ReadAllText(path), AfFileWriter.BlankMetaText(), "the blank meta text");
|
||||
Check.Eq(rig.S.MetaRules.Count, 0, "old rules cleared");
|
||||
Check.Eq(rig.S.EmbeddedNavs.Count, 0, "old embedded navs cleared");
|
||||
Check.Eq(rig.S.CurrentState, "Default", "state Default");
|
||||
Check.True(rig.S.ForceStateReset, "state reset forced");
|
||||
Check.True(rig.S.MetaCallStackReset, "call stack reset");
|
||||
Check.Eq(rig.S.CurrentMetaPath, path, "it is the loaded meta");
|
||||
Check.True(rig.Dash.MetaFileNames().Contains("Blank Farm.af"), "listed by /ra meta list");
|
||||
Check.Eq(DataWriteGuard.PendingCount, 0, "nothing reported");
|
||||
|
||||
// Without an extension, the same name is now found.
|
||||
msg = rig.Dash.LoadMetaByName("blank farm");
|
||||
Check.True(msg.StartsWith("[RynthAi] Loaded meta 'blank farm': 0 rules"), "second load is a plain load: " + msg);
|
||||
Check.Eq(Directory.GetFiles(rig.Metas).Length, 1, "one file");
|
||||
}
|
||||
|
||||
private static void MetaExisting()
|
||||
{
|
||||
var rig = new Rig("meta-existing");
|
||||
string af = Path.Combine(rig.Metas, "Farm.af");
|
||||
AfFileWriter.Save(af, HuntRules(), new Dictionary<string, List<string>>());
|
||||
byte[] afBefore = File.ReadAllBytes(af);
|
||||
DateTime afStamp = File.GetLastWriteTimeUtc(af);
|
||||
|
||||
string msg = rig.Dash.LoadMetaByName("Farm");
|
||||
Check.Eq(msg, "[RynthAi] Loaded meta 'Farm': 2 rules, 0 navs", "loaded: " + msg);
|
||||
Check.Eq(rig.S.MetaRules.Count, 2, "its rules");
|
||||
Check.Eq(rig.S.CurrentState, "Hunt", "its start state");
|
||||
Check.Eq(rig.S.CurrentMetaPath, af, "the .af");
|
||||
Check.True(((ReadOnlySpan<byte>)File.ReadAllBytes(af)).SequenceEqual(afBefore), ".af bytes unchanged");
|
||||
Check.Eq(File.GetLastWriteTimeUtc(af), afStamp, ".af not rewritten");
|
||||
|
||||
// Only a .met by that name: loaded, no .af created beside it. (A .met that parses to no
|
||||
// rules is refused as before: "not loaded", and still no .af.)
|
||||
string met = Path.Combine(rig.Metas, "Old.met");
|
||||
File.WriteAllText(met, "garbage");
|
||||
byte[] metBefore = File.ReadAllBytes(met);
|
||||
msg = rig.Dash.LoadMetaByName("Old.met");
|
||||
Check.True(msg.StartsWith("[RynthAi] Meta 'Old' not loaded:"), "a .met with no rules is refused: " + msg);
|
||||
Check.False(File.Exists(Path.Combine(rig.Metas, "Old.af")), "no blank .af made for an existing .met");
|
||||
Check.True(((ReadOnlySpan<byte>)File.ReadAllBytes(met)).SequenceEqual(metBefore), ".met unchanged");
|
||||
Check.Eq(rig.S.MetaRules.Count, 2, "the loaded meta stays when a load is refused");
|
||||
}
|
||||
|
||||
private static void MetaNew()
|
||||
{
|
||||
var rig = new Rig("meta-new");
|
||||
string af = Path.Combine(rig.Metas, "Farm.af");
|
||||
AfFileWriter.Save(af, HuntRules(), new Dictionary<string, List<string>>());
|
||||
byte[] before = File.ReadAllBytes(af);
|
||||
|
||||
string msg = rig.Dash.LoadMetaByName("Farm", createOnly: true);
|
||||
Check.Eq(msg, "[RynthAi] Meta 'Farm.af' already exists. /ra meta load Farm loads it.", "refused: " + msg);
|
||||
Check.True(((ReadOnlySpan<byte>)File.ReadAllBytes(af)).SequenceEqual(before), "unchanged");
|
||||
Check.Eq(rig.S.MetaRules.Count, 0, "nothing loaded");
|
||||
|
||||
msg = rig.Dash.LoadMetaByName("Next", createOnly: true);
|
||||
Check.Eq(msg, "[RynthAi] Created new meta 'Next' (one state 'Default', no rules) and loaded it.", "created: " + msg);
|
||||
Check.True(File.Exists(Path.Combine(rig.Metas, "Next.af")), "Next.af written");
|
||||
}
|
||||
|
||||
private static void MetaRoundTrip()
|
||||
{
|
||||
string text = AfFileWriter.BlankMetaText();
|
||||
LoadedMeta m = AfFileParser.LoadFromText(text);
|
||||
Check.Eq(m.Rules.Count, 0, "no rules");
|
||||
Check.Eq(string.Join(",", m.DeclaredStates), "Default", "one state, Default");
|
||||
Check.Eq(m.Warnings.Count, 0, "no warnings");
|
||||
Check.True(m.IsBlank, "a blank meta");
|
||||
Check.Eq(m.StartState, "Default", "starts in Default");
|
||||
Check.Eq(AfFileWriter.SaveToString(m.Rules, m.EmbeddedNavs), text, "writes back the same (a meta whose last rule was deleted)");
|
||||
|
||||
// A file with no state at all (a profile, an empty file) is still not a meta.
|
||||
LoadedMeta empty = AfFileParser.LoadFromText("");
|
||||
Check.False(empty.IsBlank, "an empty file isn't a blank meta");
|
||||
string dir = Path.Combine(Program.TempRoot, "blank-load", "roundtrip");
|
||||
Directory.CreateDirectory(dir);
|
||||
string path = Path.Combine(dir, "empty.af");
|
||||
File.WriteAllText(path, "");
|
||||
var settings = new LegacyUiSettings { MetaRules = HuntRules() };
|
||||
var ui = new LegacyMetaUi(settings, new List<string>());
|
||||
Check.False(ui.LoadMacroFile(path), "an empty .af is refused");
|
||||
Check.Eq(settings.MetaRules.Count, 2, "rules kept");
|
||||
File.WriteAllText(path, text);
|
||||
Check.True(ui.LoadMacroFile(path), "the blank .af loads: " + ui.LastLoadStatus);
|
||||
Check.Eq(settings.MetaRules.Count, 0, "rules cleared");
|
||||
Check.Eq(settings.CurrentState, "Default", "Default");
|
||||
}
|
||||
|
||||
private static void UnsafeNames()
|
||||
{
|
||||
var rig = new Rig("unsafe");
|
||||
string parent = Path.GetDirectoryName(rig.Root)!;
|
||||
int parentFiles = Directory.GetFiles(parent).Length;
|
||||
string[] bad =
|
||||
{
|
||||
"", " ", "\"\"", @"..\evil", "../evil", "..", "sub/route", @"sub\route", "a:b", "what?", "star*",
|
||||
"pipe|x", "<x>", "CON", "nul", "com1.txt", "LPT9", "trailing.", "dots..inside", new string('x', 121),
|
||||
};
|
||||
foreach (string name in bad)
|
||||
{
|
||||
string nav = rig.Dash.LoadNavByName(name);
|
||||
Check.True(nav.StartsWith("[RynthAi] Can't use '") && nav.Contains("as a nav name"), $"nav '{name}' refused: {nav}");
|
||||
string meta = rig.Dash.LoadMetaByName(name);
|
||||
Check.True(meta.StartsWith("[RynthAi] Can't use '") && meta.Contains("as a meta name"), $"meta '{name}' refused: {meta}");
|
||||
string mnew = rig.Dash.LoadMetaByName(name, createOnly: true);
|
||||
Check.True(mnew.StartsWith("[RynthAi] Can't use '"), $"meta new '{name}' refused: {mnew}");
|
||||
}
|
||||
Check.Eq(rig.Files().Length, 0, "nothing written in the data folders");
|
||||
Check.Eq(Directory.GetFiles(parent).Length, parentFiles, "nothing written beside them");
|
||||
Check.False(File.Exists(Path.Combine(parent, "evil.nav")) || File.Exists(Path.Combine(parent, "evil.af")), "no escape from the folder");
|
||||
|
||||
// Ordinary names with dots, spaces and dashes are fine.
|
||||
Check.Null(NewProfileFiles.Validate("Farm v2.1 - Hive"), "a normal name");
|
||||
Check.Null(NewProfileFiles.Validate("console"), "CON is reserved, console isn't");
|
||||
}
|
||||
|
||||
private static void Tidy()
|
||||
{
|
||||
Check.Eq(NewProfileFiles.Tidy(" \"Hive Loop.nav\" ", NewProfileFiles.NavExtensions, out string e1), "Hive Loop", "quotes + .nav");
|
||||
Check.Eq(e1, ".nav", "extension seen");
|
||||
Check.Eq(NewProfileFiles.Tidy("'farm.MET'", NewProfileFiles.MetaExtensions, out string e2), "farm", "single quotes + .MET");
|
||||
Check.Eq(e2, ".met", "lower-cased");
|
||||
Check.Eq(NewProfileFiles.Tidy("farm.af", NewProfileFiles.MetaExtensions, out _), "farm", ".af");
|
||||
Check.Eq(NewProfileFiles.Tidy("route.nav", NewProfileFiles.MetaExtensions, out string e3), "route.nav", ".nav isn't a meta extension");
|
||||
Check.Eq(e3, "", "none");
|
||||
Check.Eq(NewProfileFiles.Tidy(".nav", NewProfileFiles.NavExtensions, out _), ".nav", "an extension alone isn't stripped to nothing");
|
||||
}
|
||||
|
||||
private static void MetaCommand()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
var rig = new Rig("meta-command");
|
||||
var plugin = new RynthAiPlugin();
|
||||
typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(plugin, new object[] { FakeHost.LastApi });
|
||||
typeof(RynthAiPlugin).GetField("_dashboard", Any)!.SetValue(plugin, rig.Dash);
|
||||
MethodInfo dispatch = typeof(RynthAiPlugin).GetMethod("DispatchRaCommand", Any)!;
|
||||
void Ra(string line)
|
||||
{
|
||||
string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
dispatch.Invoke(plugin, new object[] { parts[1].ToLowerInvariant(), parts, 0 });
|
||||
}
|
||||
|
||||
Ra("/ra meta load Night Farm");
|
||||
Check.True(FakeHost.Chat.Exists(l => l.Contains("Created new meta 'Night Farm' (one state 'Default', no rules) and loaded it.")),
|
||||
"/ra meta load creates: " + string.Join(" / ", FakeHost.Chat));
|
||||
Check.True(File.Exists(Path.Combine(rig.Metas, "Night Farm.af")), "file written");
|
||||
FakeHost.Chat.Clear();
|
||||
Ra("/ra meta new Night Farm");
|
||||
Check.True(FakeHost.Chat.Exists(l => l.Contains("already exists")), "/ra meta new refuses an existing one");
|
||||
FakeHost.Chat.Clear();
|
||||
Ra("/ra meta list");
|
||||
Check.True(FakeHost.Chat.Exists(l => l.Contains("Metas (1): Night Farm.af")), "/ra meta list: " + string.Join(" / ", FakeHost.Chat));
|
||||
FakeHost.Chat.Clear();
|
||||
Ra("/ra meta load");
|
||||
Check.True(FakeHost.Chat.Exists(l => l.Contains("Usage: /ra meta load <name>")), "usage");
|
||||
FakeHost.Chat.Clear();
|
||||
Ra("/ra nav load New Route");
|
||||
Check.True(FakeHost.Chat.Exists(l => l.Contains("Created new nav 'New Route' (empty, Circular) and loaded it.")),
|
||||
"/ra nav load creates: " + string.Join(" / ", FakeHost.Chat));
|
||||
}
|
||||
}
|
||||
320
Tools/RynthCore.RynthAiHostTests/Tests/DoorTests.cs
Normal file
320
Tools/RynthCore.RynthAiHostTests/Tests/DoorTests.cs
Normal file
|
|
@ -0,0 +1,320 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.PluginCore;
|
||||
using RynthCore.PluginSdk;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// Doors (2026-10-13, a mage on DreamWeave, "doors aren't opening"): the use went out while the
|
||||
// client was busy (portal space), a second use followed 3 s later with the first unanswered (the
|
||||
// server's walk to the door took up to 3.7 s), and a door still closed after a use was called
|
||||
// locked and sent to the lockpick cooldown although the server never said so. See the header of
|
||||
// DoorInteractionController.cs for the rules these check.
|
||||
internal static class DoorTests
|
||||
{
|
||||
private const uint Player = 0x50000D01;
|
||||
private const uint Door = 0x701C9139;
|
||||
private const uint Pick = 0x80000D11;
|
||||
private const uint Kit = 0x80000D12;
|
||||
private const uint Closed = 0x00010018, Ethereal = 0x4;
|
||||
private const uint BfDoor = 0x1000;
|
||||
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public;
|
||||
private static (uint Cell, float X, float Y, float Z) Me0 => (0x01C90231u, 60f, 10f, 0f);
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("door: no use while the client is busy or another use is unanswered; it goes when they clear", WaitsForBusyAndAnswer);
|
||||
r.Add("door: a slow server walk (3.7 s to the answer) is waited out - one use, no retry, opened", SlowWalkOneUse);
|
||||
r.Add("door: no second use while the first is unanswered; a lost use is re-sent only after the answer limit", NoDoubleUse);
|
||||
r.Add("door: still closed after an answered use, no 'locked' from the server: used again, never picked", NotLockedWithoutServer);
|
||||
r.Add("door: the server says locked: a lockpick goes on it, then the door is opened again", LockedUsesLockpick);
|
||||
r.Add("door: locked and no lockpick: cooldown, and the door is skipped a while", LockedNoPick);
|
||||
r.Add("door: nothing in portal space, nor just after it", NothingInPortalSpace);
|
||||
r.Add("door: a door that opens is released at once (no fixed waits)", OpensFast);
|
||||
r.Add("door: 'locked' from chat counts only as the server's line, not a player's", LockedChatLine);
|
||||
}
|
||||
|
||||
// ── Rig ─────────────────────────────────────────────────────────────────
|
||||
|
||||
private sealed class Bot
|
||||
{
|
||||
public readonly RynthAiPlugin P = new();
|
||||
public readonly LegacyUiSettings S = new() { IsMacroRunning = true, OpenDoors = true, OpenDoorRange = 5f, AutoUnlockDoors = true };
|
||||
public readonly WorldObjectCache Cache;
|
||||
public long Now = 50_000_000;
|
||||
public readonly RynthCoreHost Host;
|
||||
|
||||
public Bot(bool lockpick = true)
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.WeaponCalls = true; // UseObject
|
||||
FakeHost.UseOnCalls = true; // UseObjectOn (the lockpick)
|
||||
FakeHost.ServerGates = true; // GetUseDoneSeq, GetCastBusyState
|
||||
FakeHost.LastUseDoneCalls = true;
|
||||
FakeHost.StopCalls = true;
|
||||
FakeHost.Names[Player] = "Mage";
|
||||
FakeHost.Positions[Player] = Me0;
|
||||
FakeHost.PlayerPose = Me0;
|
||||
FakeHost.Names[Door] = "Door";
|
||||
FakeHost.Positions[Door] = (Me0.Cell, Me0.X + 2f, Me0.Y, Me0.Z);
|
||||
FakeHost.Bitfields[Door] = BfDoor;
|
||||
FakeHost.ObjectStates[Door] = Closed;
|
||||
FakeHost.Names[Pick] = "Plain Lockpick";
|
||||
FakeHost.Names[Kit] = "Treated Healing Kit";
|
||||
Host = FakeHost.Create(Player);
|
||||
|
||||
ActionPacer.Reset();
|
||||
ActionPacer.Enabled = true;
|
||||
ActionPacer.NowMs = () => Now;
|
||||
UseAudit.Reset("RynthAi", () => true);
|
||||
UseAudit.NowMs = () => Now;
|
||||
UseAudit.TrackWorldUses = true;
|
||||
MoveAudit.Reset();
|
||||
MoveAudit.NowMs = () => Now;
|
||||
var rec = typeof(RynthAiPlugin).GetMethod("RecordUseForPacing", Any)!;
|
||||
UseAudit.AfterSend = (h, u) => rec.Invoke(null, new object[] { h, u });
|
||||
RynthAiPlugin.DoorClock = () => Now;
|
||||
|
||||
typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(P, new object[] { FakeHost.LastApi });
|
||||
var dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer));
|
||||
typeof(LegacyDashboardRenderer).GetField("_settings", Any)!.SetValue(dash, S);
|
||||
Set("_dashboard", dash);
|
||||
Cache = new WorldObjectCache(Host);
|
||||
Cache.SetPlayerId(Player);
|
||||
Set("_objectCache", Cache);
|
||||
Set("_playerId", Player);
|
||||
Cache.OnCreateObject(Player);
|
||||
Cache.OnCreateObject(Door);
|
||||
_ = Cache[unchecked((int)Pick)];
|
||||
_ = Cache[unchecked((int)Kit)];
|
||||
Cache.Tick();
|
||||
if (lockpick)
|
||||
S.ConsumableRules.Add(new ConsumableRule { Id = unchecked((int)Pick), Name = "Plain Lockpick", Type = "Lockpick" });
|
||||
}
|
||||
|
||||
public void Set(string f, object? v) => typeof(RynthAiPlugin).GetField(f, Any)!.SetValue(P, v);
|
||||
public T Get<T>(string f) => (T)typeof(RynthAiPlugin).GetField(f, Any)!.GetValue(P)!;
|
||||
public int Busy { set => Set("_busyCount", value); }
|
||||
public string State => Get<object>("_doorState").ToString()!;
|
||||
|
||||
/// <summary>One door tick at the current time; true while the door holds nav.</summary>
|
||||
public bool Tick() => (bool)typeof(RynthAiPlugin).GetMethod("TickDoorInteraction", Any)!.Invoke(P, null)!;
|
||||
|
||||
/// <summary>Ticks every <paramref name="stepMs"/> for <paramref name="ms"/>.</summary>
|
||||
public void Run(long ms, long stepMs = 50)
|
||||
{
|
||||
for (long t = 0; t < ms; t += stepMs) { Now += stepMs; Tick(); }
|
||||
}
|
||||
|
||||
public void Answer(bool open)
|
||||
{
|
||||
if (open) FakeHost.ObjectStates[Door] = Closed | Ethereal;
|
||||
FakeHost.UseDone(0);
|
||||
}
|
||||
|
||||
public void Say(string line) => P.NoteDoorServerText(line);
|
||||
}
|
||||
|
||||
private static int DoorUses() => FakeHost.Uses.Count(u => u == Door);
|
||||
private static int Picks() => FakeHost.UsesOn.Count(u => u.Source == Pick && u.Target == Door);
|
||||
|
||||
private static void Cleanup()
|
||||
{
|
||||
ActionPacer.Enabled = false;
|
||||
ActionPacer.Reset();
|
||||
ActionPacer.NowMs = () => Environment.TickCount64;
|
||||
UseAudit.Reset("?", null);
|
||||
UseAudit.NowMs = () => Environment.TickCount64;
|
||||
UseAudit.TrackWorldUses = false;
|
||||
MoveAudit.Reset();
|
||||
MoveAudit.NowMs = () => Environment.TickCount64;
|
||||
RynthAiPlugin.DoorClock = static () => Environment.TickCount64;
|
||||
}
|
||||
|
||||
private static void With(Action body)
|
||||
{
|
||||
try { body(); }
|
||||
finally { Cleanup(); }
|
||||
}
|
||||
|
||||
// ── Tests ───────────────────────────────────────────────────────────────
|
||||
|
||||
private static void WaitsForBusyAndAnswer() => With(() =>
|
||||
{
|
||||
var b = new Bot();
|
||||
// A kit the server hasn't answered yet, and the client's busy count up.
|
||||
ActionPacer.Begin(b.Host, PacedKind.ItemUse, Kit, "'Treated Healing Kit'", "RynthAi/Buff", FakeHost.UseDoneSeq);
|
||||
b.Busy = 1;
|
||||
Check.True(b.Tick(), "targeting the door holds nav");
|
||||
b.Run(1000);
|
||||
Check.Eq(DoorUses(), 0, "no door use while the kit is unanswered (and the client busy)");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("Door: 0x701C9139 waits:")), "the wait is logged");
|
||||
|
||||
FakeHost.UseDone(0); // the kit's answer
|
||||
b.Run(500);
|
||||
Check.Eq(DoorUses(), 0, "the kit answered, but the client still reads busy");
|
||||
b.Busy = 0;
|
||||
b.Run(100);
|
||||
Check.Eq(DoorUses(), 1, "busy 0 and nothing unanswered: the use goes");
|
||||
Check.Eq(b.State, "Opening", "...and waits for the server");
|
||||
});
|
||||
|
||||
private static void SlowWalkOneUse() => With(() =>
|
||||
{
|
||||
var b = new Bot();
|
||||
b.Tick();
|
||||
Check.Eq(FakeHost.Stops, 1, "the character is stopped first");
|
||||
Check.Eq(DoorUses(), 0, "...and the use waits for the stop to settle");
|
||||
b.Run(300); // the stop settles
|
||||
Check.Eq(DoorUses(), 1, "the use went out once the stop settled");
|
||||
b.Run(3700, 100); // the server walks the character to the door: 3.7 s in the 10-13 log
|
||||
Check.Eq(DoorUses(), 1, "no second use during the walk (the old 3 s timeout re-sent it)");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("is locked")), "nothing called locked");
|
||||
b.Answer(open: true);
|
||||
b.Now += 50;
|
||||
Check.False(b.Tick(), "opened: nav released");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("opened OK")), "opened OK logged");
|
||||
Check.Eq(b.State, "None", "back to idle");
|
||||
b.Run(2000);
|
||||
Check.Eq(DoorUses(), 1, "an opened door is not used again");
|
||||
});
|
||||
|
||||
private static void NoDoubleUse() => With(() =>
|
||||
{
|
||||
var b = new Bot();
|
||||
b.Tick();
|
||||
b.Run(300);
|
||||
Check.Eq(DoorUses(), 1, "first use");
|
||||
b.Run(5500, 100); // no answer at all
|
||||
Check.Eq(DoorUses(), 1, "no second use while the first is unanswered (5.8 s)");
|
||||
b.Run(1000, 100); // past the 6 s answer limit
|
||||
Check.Eq(DoorUses(), 2, "a use never answered is sent again after the limit");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("no answer from the server")), "the lost use is logged");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("went out while")), "the pacer never saw a use go out over an unanswered one");
|
||||
});
|
||||
|
||||
private static void NotLockedWithoutServer() => With(() =>
|
||||
{
|
||||
var b = new Bot(lockpick: true);
|
||||
b.Tick();
|
||||
b.Run(300);
|
||||
Check.Eq(DoorUses(), 1, "first use");
|
||||
b.Run(2000, 100);
|
||||
b.Answer(open: false); // answered (UseDone 0), the door stays shut, no locked text
|
||||
b.Run(1000, 100);
|
||||
Check.Eq(DoorUses(), 1, "the door gets a moment to swing after the answer");
|
||||
b.Run(500, 100);
|
||||
Check.Eq(DoorUses(), 2, "still closed: used again");
|
||||
Check.Eq(Picks(), 0, "no lockpick: the server never said locked");
|
||||
b.Answer(open: false);
|
||||
b.Run(1500, 100);
|
||||
b.Answer(open: false);
|
||||
b.Run(1500, 100);
|
||||
Check.Eq(DoorUses(), 3, "three uses in all");
|
||||
Check.Eq(b.State, "Cooldown", "then a cooldown");
|
||||
Check.Eq(Picks(), 0, "still no lockpick");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("is locked")), "never logged as locked");
|
||||
});
|
||||
|
||||
private static void LockedUsesLockpick() => With(() =>
|
||||
{
|
||||
var b = new Bot(lockpick: true);
|
||||
b.Tick();
|
||||
b.Run(300);
|
||||
Check.Eq(DoorUses(), 1, "first use");
|
||||
b.Run(1500, 100);
|
||||
b.Say("The door is locked!"); // ACE Door.ActOnUse's transient string
|
||||
b.Answer(open: false);
|
||||
b.Run(300);
|
||||
Check.Eq(Picks(), 1, "the lockpick goes on the door");
|
||||
Check.Eq(DoorUses(), 1, "...and no open over it");
|
||||
b.Run(1000);
|
||||
Check.Eq(DoorUses(), 1, "nothing while the lockpick is unanswered");
|
||||
FakeHost.UseDone(0); // "You have successfully picked the lock!"
|
||||
b.Run(300);
|
||||
Check.Eq(DoorUses(), 2, "opened again after the lockpick's answer");
|
||||
b.Run(800);
|
||||
b.Answer(open: true);
|
||||
b.Now += 50;
|
||||
Check.False(b.Tick(), "opened: nav released");
|
||||
Check.Eq(b.State, "None", "done");
|
||||
});
|
||||
|
||||
private static void LockedNoPick() => With(() =>
|
||||
{
|
||||
var b = new Bot(lockpick: false);
|
||||
b.Tick();
|
||||
b.Run(300);
|
||||
b.Run(1000, 100);
|
||||
b.Say("The door is locked!");
|
||||
b.Answer(open: false);
|
||||
b.Run(100);
|
||||
Check.Eq(b.State, "Cooldown", "locked, no lockpick: cooldown");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("is locked but there's no lockpick")), "says why");
|
||||
b.Run(6000, 100);
|
||||
Check.Eq(b.State, "None", "cooldown over");
|
||||
b.Run(2000, 100);
|
||||
Check.Eq(DoorUses(), 1, "the locked door is skipped a while (not targeted again)");
|
||||
});
|
||||
|
||||
private static void NothingInPortalSpace() => With(() =>
|
||||
{
|
||||
var b = new Bot();
|
||||
FakeHost.Portaling = true;
|
||||
b.Run(2000);
|
||||
Check.Eq(b.State, "None", "no door targeted in portal space");
|
||||
Check.Eq(DoorUses(), 0, "no use");
|
||||
FakeHost.Portaling = false;
|
||||
b.Run(1000);
|
||||
Check.Eq(b.State, "None", "nor in the first moment after it");
|
||||
b.Run(1000);
|
||||
Check.Eq(DoorUses(), 1, "then the door is opened as usual");
|
||||
|
||||
// Portal space in the middle of a use: forgotten, not judged.
|
||||
FakeHost.Portaling = true;
|
||||
b.Run(200);
|
||||
Check.Eq(b.State, "None", "a use under way is dropped in portal space");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("is locked") || l.Contains(", cooldown")), "never called locked");
|
||||
});
|
||||
|
||||
private static void OpensFast() => With(() =>
|
||||
{
|
||||
var b = new Bot();
|
||||
b.Tick();
|
||||
b.Run(200);
|
||||
Check.Eq(DoorUses(), 1, "use out within 0.2 s of targeting");
|
||||
b.Run(300);
|
||||
FakeHost.ObjectStates[Door] = Closed | Ethereal; // swings open before the UseDone arrives
|
||||
b.Now += 50;
|
||||
Check.False(b.Tick(), "released the tick it reads open");
|
||||
Check.Eq(b.State, "None", "done without waiting for anything else");
|
||||
});
|
||||
|
||||
private static void LockedChatLine() => With(() =>
|
||||
{
|
||||
var b = new Bot(lockpick: true);
|
||||
b.Tick();
|
||||
b.Run(300);
|
||||
b.Run(1000, 100);
|
||||
var chat = typeof(RynthAiPlugin).GetMethod("OnChatWindowText", Any)!;
|
||||
object?[] args = { "Bob says, \"The door is locked!\"", 2, 0 };
|
||||
try { chat.Invoke(b.P, args); } catch { } // the rest of the chat pipeline isn't set up here
|
||||
b.Answer(open: false);
|
||||
b.Run(200);
|
||||
Check.Eq(Picks(), 0, "a player's line isn't the server's");
|
||||
b.Run(1500, 100);
|
||||
args = new object?[] { "The door is locked!", 0, 0 };
|
||||
try { chat.Invoke(b.P, args); } catch { }
|
||||
b.Run(100);
|
||||
b.Answer(open: false);
|
||||
b.Run(300);
|
||||
Check.Eq(Picks(), 1, "the server's line from chat sends the lockpick");
|
||||
});
|
||||
}
|
||||
|
|
@ -48,6 +48,10 @@ internal static class MetaTests
|
|||
r.Add("meta action: SetMetaState, CallMetaState and ReturnFromCall", CallReturn);
|
||||
r.Add("meta action: All runs every child in order", AllAction);
|
||||
r.Add("meta action: embedded nav route", EmbeddedNav);
|
||||
r.Add("meta .af: EmbedNav and NAV names lose stray brackets ('None]' was loaded as a route named 'None]')", EmbedNavStrayBrackets);
|
||||
r.Add("meta action: EmbedNav [None] with no route behind it is an empty route (no 'None.nav', no 'Route missing')", EmbedNavNoneKeepsRoute);
|
||||
r.Add("meta action: a [None] route with points loads, as in VTank (an old 'None]' key too)", EmbedNavNoneWithPointsLoads);
|
||||
r.Add("meta .met: VTank's [None] embedded nav - with points it is a route, empty it is no nav", MetEmbedNavNone);
|
||||
r.Add("meta action: watchdog", Watchdog);
|
||||
r.Add("meta action: RA options, chat expression, expression, views", MiscActions);
|
||||
r.Add("meta: an exception in a tick is caught and forces a reset", ExceptionInTick);
|
||||
|
|
@ -883,6 +887,8 @@ internal static class MetaTests
|
|||
Check.True(rig.Ra.Contains("/ra stop"), "/vt stop");
|
||||
RunAction(rig, A.ChatCommand, "/vt nav load Hive Loop");
|
||||
Check.True(rig.Ra.Contains("/ra nav load Hive Loop"), "/vt nav load keeps spaces");
|
||||
RunAction(rig, A.ChatCommand, "/vt meta load Night Farm");
|
||||
Check.True(rig.Ra.Contains("/ra meta load Night Farm"), "/vt meta load is /ra meta load (one implementation; a new name makes a blank meta)");
|
||||
RunAction(rig, A.ChatCommand, "/vt setattackbar 0.75");
|
||||
Check.True(rig.Ra.Contains("/ra power 75"), "/vt setattackbar 0.75 -> 75%");
|
||||
RunAction(rig, A.ChatCommand, "/vt setattackbar 3");
|
||||
|
|
@ -1020,6 +1026,135 @@ internal static class MetaTests
|
|||
Check.Eq(rig.S.CurrentNavPath, "<embedded:Patrol>", "...and loaded");
|
||||
}
|
||||
|
||||
// The CQ meta family on DreamWeave (C:\Games\metaf\CQHunt~0.af, decompiled by metaf): VTank's
|
||||
// "[None]" routes become tags like nav9___None_ - a one-point hunt spot, and an empty one.
|
||||
// "None]" is the broken spelling from the 10-13 player log ("EmbedNav: loaded 'None]' (1 pts)").
|
||||
private const string CqNoneSnippet =
|
||||
"STATE: {Hunt} ~~ {\n" +
|
||||
"\tIF:\tAlways\n" +
|
||||
"\t\tDO:\tDoAll\n" +
|
||||
"\t\t\t\tChat {/vt opt set enablenav true}\n" +
|
||||
"\t\t\t\tEmbedNav nav9___None_ {[none]}\n" +
|
||||
"\t\t\t\tEmbedNav None] {[None]}\n" +
|
||||
"\t\t\t\tEmbedNav [None] {[None]}\n" +
|
||||
"\t\t\t\tEmbedNav nav42___None_ {[none]}\n" +
|
||||
"~~ }\n" +
|
||||
"NAV: nav9___None_ circular ~~ {\n" +
|
||||
"\tpnt 12.7402540842692 64.8717851956685 1.15794169108073\n" +
|
||||
"~~ }\n" +
|
||||
"NAV: None] circular ~~ {\n" +
|
||||
"\tpnt 12.7402540842692 64.8717851956685 1.15794169108073\n" +
|
||||
"~~ }\n" +
|
||||
"NAV: nav42___None_ circular ~~ {\n" +
|
||||
"~~ }\n";
|
||||
|
||||
private static void EmbedNavStrayBrackets()
|
||||
{
|
||||
var m = AfFileParser.LoadFromText(CqNoneSnippet);
|
||||
var all = m.Rules.Single();
|
||||
var data = all.ActionChildren.Select(c => c.ActionData).ToList();
|
||||
Check.Eq(string.Join("|", data), "/vt opt set enablenav true|nav9___None_|None|None|", "action names: the tag, 'None]' and '[None]' cleaned to None, the empty route's ref cleared");
|
||||
Check.True(m.EmbeddedNavs.ContainsKey("None"), "the NAV block 'None]' is filed as 'None'");
|
||||
Check.False(m.EmbeddedNavs.Keys.Any(k => k.Contains('[') || k.Contains(']')), "no key keeps a stray bracket");
|
||||
Check.True(m.EmbeddedNavs.ContainsKey("nav9___None_"), "metaf's tag is kept as it is");
|
||||
Check.False(m.EmbeddedNavs.ContainsKey("nav42___None_"), "the empty [None] route is dropped");
|
||||
|
||||
// Saved and read back: the same names (the Meta panel saves through AfFileWriter).
|
||||
var back = AfFileParser.LoadFromText(AfFileWriter.SaveToString(m.Rules, m.EmbeddedNavs));
|
||||
Check.Eq(string.Join("|", back.Rules.Single().ActionChildren.Select(c => c.ActionData)),
|
||||
"/vt opt set enablenav true|nav9___None_|None|None|", "round trip keeps the names");
|
||||
Check.True(back.EmbeddedNavs.ContainsKey("None") && back.EmbeddedNavs.ContainsKey("nav9___None_"), "round trip keeps the routes");
|
||||
|
||||
// The clean-up itself.
|
||||
Check.Eq(EmbedNavName.Clean(" [None] "), "None", "wrapping brackets");
|
||||
Check.Eq(EmbedNavName.Clean("None]"), "None", "a stray closing bracket");
|
||||
Check.Eq(EmbedNavName.Clean("[None"), "None", "a stray opening bracket");
|
||||
Check.Eq(EmbedNavName.Clean("Hive [East]"), "Hive [East]", "brackets inside a name are kept");
|
||||
Check.Eq(EmbedNavName.Clean("[a] [b]"), "[a] [b]", "two bracketed parts are not unwrapped");
|
||||
Check.True(EmbedNavName.IsNone("[none]") && EmbedNavName.IsNone("None]") && !EmbedNavName.IsNone("nav9___None_"), "IsNone");
|
||||
}
|
||||
|
||||
private static void EmbedNavNoneKeepsRoute()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.PlayerPose = (0xA9B4001Cu, 96f, 96f, 0f);
|
||||
var host = FakeHost.Create();
|
||||
var rig = new Rig(host, Player);
|
||||
rig.S.EmbeddedNavs["Hive Route"] = NavLines(1, (0, 30, 40, NoTrailer), (0, 33.65, 42.45, NoTrailer), (0, 36, 44, NoTrailer));
|
||||
RunAction(rig, A.EmbeddedNavRoute, "Hive Route");
|
||||
Check.Eq(rig.S.CurrentRoute.Points.Count, 3, "a route is running");
|
||||
foreach (string none in new[] { "[None]", "None]", "None", "[none]" })
|
||||
{
|
||||
FakeHost.Chat.Clear();
|
||||
RunAction(rig, A.EmbeddedNavRoute, "Hive Route");
|
||||
RunAction(rig, A.EmbeddedNavRoute, none);
|
||||
Check.Eq(rig.S.CurrentRoute.Points.Count, 0, $"'{none}': an empty route");
|
||||
Check.Eq(rig.S.CurrentNavPath, "", $"'{none}': no nav file");
|
||||
Check.False(FakeHost.Chat.Exists(c => c.Contains("Route missing")), $"'{none}': no 'Route missing'");
|
||||
}
|
||||
// An empty [None] route is no route either.
|
||||
rig.S.EmbeddedNavs["None"] = NavLines(1);
|
||||
RunAction(rig, A.EmbeddedNavRoute, "Hive Route");
|
||||
RunAction(rig, A.EmbeddedNavRoute, "[None]");
|
||||
Check.Eq(rig.S.CurrentRoute.Points.Count, 0, "an empty [None] route: an empty route");
|
||||
}
|
||||
|
||||
private static void EmbedNavNoneWithPointsLoads()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.PlayerPose = (0xA9B4001Cu, 96f, 96f, 0f);
|
||||
var host = FakeHost.Create();
|
||||
var rig = new Rig(host, Player);
|
||||
// A key from a settings file or meta saved before names were cleaned.
|
||||
rig.S.EmbeddedNavs["None]"] = NavLines(1, (0, 33.65, 42.45, NoTrailer));
|
||||
RunAction(rig, A.EmbeddedNavRoute, "[None]");
|
||||
Check.Eq(rig.S.CurrentRoute.Points.Count, 1, "the one-point [None] route (a hunt spot) loads");
|
||||
Check.True(rig.S.EnableNavigation, "...and navigation runs");
|
||||
RunAction(rig, A.EmbeddedNavRoute, "None]");
|
||||
Check.Eq(rig.S.CurrentNavPath, "<embedded:None]>", "the old key is found from any spelling");
|
||||
}
|
||||
|
||||
/// <summary>A VTank .met with two rules (Always / Never) whose action is an embedded nav named
|
||||
/// "[None]": one with a one-point route, one with an empty route. The layout is VTank's (the
|
||||
/// CQ metas, S_Tusks.met): name line, point count, then the .nav lines, byte-counted.</summary>
|
||||
private static string MetWithNoneNavs()
|
||||
{
|
||||
static string Block(params string[] lines) => string.Join("\r\n", lines) + "\r\n";
|
||||
string onePoint = Block("[None]", "1", "uTank2 NAV 1.2", "1", "1", "0", "33.65", "42.45", "0", "0");
|
||||
string empty = Block("[None]", "0", "uTank2 NAV 1.2", "1", "0");
|
||||
var met = new List<string> { "1", "CondAct", "5", "CType", "AType", "CData", "AData", "State", "n", "n", "n", "n", "n", "2" };
|
||||
met.AddRange(new[] { "i", "1", "i", "4", "i", "0", "ba", System.Text.Encoding.UTF8.GetByteCount(onePoint).ToString() });
|
||||
string head = string.Join("\r\n", met) + "\r\n" + onePoint;
|
||||
var mid = new List<string> { "s", "Default", "i", "0", "i", "4", "i", "0", "ba", System.Text.Encoding.UTF8.GetByteCount(empty).ToString() };
|
||||
return head + string.Join("\r\n", mid) + "\r\n" + empty + "s\r\nDefault\r\n";
|
||||
}
|
||||
|
||||
private static void MetEmbedNavNone()
|
||||
{
|
||||
string path = System.IO.Path.Combine(Program.TempRoot, "embednav-none-test.met");
|
||||
System.IO.File.WriteAllText(path, MetWithNoneNavs());
|
||||
var m = MetFileParser.Load(path);
|
||||
Check.Eq(m.Warnings.Count, 0, "parses cleanly");
|
||||
Check.Eq(m.Rules.Count, 2, "two rules");
|
||||
string first = m.Rules[0].ActionData;
|
||||
Check.True(first.Length > 0 && m.EmbeddedNavs.ContainsKey(first), $"the one-point [None] route is a route ('{first}')");
|
||||
Check.False(first.Contains('[') || first.Contains(']'), "its name has no bracket");
|
||||
Check.Eq(NavRouteParser.LoadFromLines(m.EmbeddedNavs[first]).Points.Count, 1, "...with its point");
|
||||
Check.Eq(m.Rules[1].ActionData, "", "the empty [None] route: no nav");
|
||||
|
||||
// Through the meta: the empty one keeps the running route, the one-point one replaces it.
|
||||
FakeHost.Reset();
|
||||
FakeHost.PlayerPose = (0xA9B4001Cu, 96f, 96f, 0f);
|
||||
var rig = new Rig(FakeHost.Create(), Player);
|
||||
foreach (var kv in m.EmbeddedNavs) rig.S.EmbeddedNavs[kv.Key] = kv.Value;
|
||||
rig.S.EmbeddedNavs["Hive Route"] = NavLines(1, (0, 30, 40, NoTrailer), (0, 36, 44, NoTrailer));
|
||||
RunAction(rig, A.EmbeddedNavRoute, "Hive Route");
|
||||
RunAction(rig, A.EmbeddedNavRoute, m.Rules[1].ActionData);
|
||||
Check.Eq(rig.S.CurrentRoute.Points.Count, 2, "empty [None]: the running route is kept");
|
||||
RunAction(rig, A.EmbeddedNavRoute, first);
|
||||
Check.Eq(rig.S.CurrentRoute.Points.Count, 1, "one-point [None]: loaded");
|
||||
}
|
||||
|
||||
private static void Watchdog()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
|
|
|
|||
312
Tools/RynthCore.RynthAiHostTests/Tests/PropertyDumpTests.cs
Normal file
312
Tools/RynthCore.RynthAiHostTests/Tests/PropertyDumpTests.cs
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using RynthCore.Engine.Compatibility;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.Diagnostics;
|
||||
using RynthCore.PluginCore;
|
||||
using RynthCore.PluginSdk;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
using EngineFlags = RynthCore.Engine.Compatibility.ObjectPropertyFlags;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// /ub propertydump (2026-10-13): a tester found it "isn't exposing all item properties" next to
|
||||
// UtilityBelt's. It probed fixed key ranges one key at a time; now it lists every key the engine
|
||||
// holds (plugin API v84 GetObjectProperties), identifies the object first, chats in chunks and
|
||||
// writes the whole dump to RynthAi\Logs. On an older engine it probes every named key.
|
||||
internal static class PropertyDumpTests
|
||||
{
|
||||
private const uint Player = 0x50000A01, Coat = 0x80001234, Pack = 0x80001200;
|
||||
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("propertydump: every key the engine holds, by type, named, ids in hex, spells by name", ListsEverything);
|
||||
r.Add("propertydump: layout like UtilityBelt's (header, sections sorted by name, unknown keys as numbers)", Layout);
|
||||
r.Add("propertydump: an unidentified item is identified first and dumped when the answer arrives", WaitsForId);
|
||||
r.Add("propertydump: no identify answer in time - dumps what the client has, and says so", IdTimeout);
|
||||
r.Add("propertydump: waits a moment for the engine's main-thread qualities read", QualitiesPending);
|
||||
r.Add("propertydump: long dumps reach chat in chunks; the full dump goes to RynthAi\\Logs", ChunksAndFile);
|
||||
r.Add("propertydump: an engine before v84 probes every named key, past the old ranges", OlderEngineFallback);
|
||||
r.Add("propertydump: /ub, /vt and /ra all route to it; nothing selected = the character", Routes);
|
||||
}
|
||||
|
||||
private sealed class Bot
|
||||
{
|
||||
public readonly RynthAiPlugin P = new();
|
||||
public long Now = 1_000_000;
|
||||
|
||||
public Bot()
|
||||
{
|
||||
typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(P, new object[] { FakeHost.LastApi });
|
||||
Set("_playerId", Player);
|
||||
Set("_loginComplete", true);
|
||||
Set("_initialized", true); // OnChatBarEnter routes /ub, /vt and /ra only once initialized
|
||||
P.PropertyDumpClock = () => Now;
|
||||
// /vt propertydump goes through MetaManager.TryHandleVtCommand back to /ra.
|
||||
var meta = new RynthCore.Plugin.RynthAi.Meta.MetaManager(new RynthCore.Plugin.RynthAi.LegacyUi.LegacyUiSettings(),
|
||||
new RynthCoreHost(FakeHost.LastApi), new PlayerVitalsCache());
|
||||
var ra = typeof(RynthAiPlugin).GetMethod("HandleRaCommand", Any)!;
|
||||
meta.SetRaCommandHandler(cmd => ra.Invoke(P, new object[] { cmd }));
|
||||
Set("_metaManager", meta);
|
||||
}
|
||||
|
||||
public void Set(string f, object? v) => typeof(RynthAiPlugin).GetField(f, Any)!.SetValue(P, v);
|
||||
public void Call(string m, params object[] a) => typeof(RynthAiPlugin).GetMethod(m, Any)!.Invoke(P, a);
|
||||
public void Tick() => Call("TickPropertyDump", false);
|
||||
public void Ra(string line)
|
||||
{
|
||||
string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||
typeof(RynthAiPlugin).GetMethod("DispatchRaCommand", Any)!.Invoke(P, new object[] { parts[1].ToLowerInvariant(), parts, 0 });
|
||||
}
|
||||
public void DrainAll() { for (int i = 0; i < 200; i++) Tick(); }
|
||||
public string AllChat => string.Join("\n", FakeHost.Chat);
|
||||
}
|
||||
|
||||
private static string DumpFolder()
|
||||
{
|
||||
string dir = Path.Combine(Program.TempRoot, "propdump-" + Guid.NewGuid().ToString("N")[..8]);
|
||||
PropertyDump.FolderOverride = dir;
|
||||
return dir;
|
||||
}
|
||||
|
||||
private static PropertyBag CoatBag()
|
||||
{
|
||||
var b = new PropertyBag();
|
||||
b.Ints[1] = 2; // ItemType Armor
|
||||
b.Ints[19] = 15000; // Value
|
||||
b.Ints[28] = 210; // ArmorLevel
|
||||
b.Ints[9015] = 3; // InventoryOrder: no fixed range reached it
|
||||
b.Ints[4242] = 7; // a key with no name
|
||||
b.Int64s[4] = 123456789012L; // ItemTotalXp: int64s had no names
|
||||
b.Bools[22] = true; // Inscribable
|
||||
b.Floats[13] = 1.3; // ArmorModVsSlash: floats had no names
|
||||
b.Floats[167] = 2.5; // CooldownDuration
|
||||
b.Strings[1] = "Olthoi Amuli Coat";
|
||||
b.Strings[16] = "A heavy coat.";
|
||||
b.DataIds[8] = 0x06001F88; // Icon
|
||||
b.DataIds[8044] = 0x1234; // PCAPPhysicsDIDDataTemplatedFrom: past the old 0-80 range
|
||||
b.InstanceIds[2] = Pack; // Container
|
||||
b.InstanceIds[38] = Player; // AllowedWielder
|
||||
return b;
|
||||
}
|
||||
|
||||
private static void Setup(Func<uint, byte[]?> records, bool appraised = true)
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.Names[Player] = "Tester";
|
||||
FakeHost.Names[Coat] = "Olthoi Amuli Coat";
|
||||
FakeHost.Names[Pack] = "Pack";
|
||||
FakeHost.Wcids[Coat] = 37191;
|
||||
FakeHost.WeaponCalls = true; // RequestId + HasAppraisalData
|
||||
FakeHost.ObjectPropertiesCalls = true;
|
||||
FakeHost.PropertyRecord = records;
|
||||
if (appraised) FakeHost.Appraised.Add(Coat);
|
||||
FakeHost.Create(Player);
|
||||
}
|
||||
|
||||
private static byte[] CoatRecord(EngineFlags flags = EngineFlags.HasIdData | EngineFlags.QualitiesRead) =>
|
||||
ObjectPropertyRecord.Encode(CoatBag(), new uint[] { 2783, 4400, 99999 }, flags, 1_760_000_000L);
|
||||
|
||||
private static void ListsEverything()
|
||||
{
|
||||
DumpFolder();
|
||||
Setup(id => id == Coat ? CoatRecord() : null);
|
||||
var bot = new Bot();
|
||||
bot.Set("_currentTargetId", Coat);
|
||||
bot.Ra("/ra dumpprops");
|
||||
bot.DrainAll();
|
||||
string chat = bot.AllChat;
|
||||
Check.True(chat.Contains("Property Dump for Olthoi Amuli Coat"), "header");
|
||||
Check.True(chat.Contains(" InventoryOrder (9015) = 3"), "an int past the old 0-400 range");
|
||||
Check.True(chat.Contains(" 4242 = 7"), "an unknown key as its number");
|
||||
Check.True(chat.Contains(" ItemTotalXp (4) = 123456789012"), "int64 named");
|
||||
Check.True(chat.Contains(" ArmorModVsSlash (13) = 1.3"), "float named");
|
||||
Check.True(chat.Contains(" Inscribable (22) = True"), "bool as True/False");
|
||||
Check.True(chat.Contains(" Icon (8) = 0x06001F88"), "data id in hex");
|
||||
Check.True(chat.Contains(" PCAPPhysicsDIDDataTemplatedFrom (8044) = 0x00001234"), "data id past the old 0-80 range");
|
||||
Check.True(chat.Contains(" Container (2) = 0x80001200 (Pack)"), "instance id in hex with the object's name");
|
||||
Check.True(chat.Contains(" AllowedWielder (38) = 0x50000A01 (Tester)"), "instance id 38");
|
||||
Check.True(chat.Contains("Spells (3):"), "spell book");
|
||||
Check.True(chat.Contains("(2783)") && chat.Contains("(4400)") && chat.Contains("(99999)"), "every spell by id");
|
||||
Check.True(chat.Contains("Total: 15 properties"), "total (" + chat.Split('\n').LastOrDefault(l => l.Contains("Total")) + ")");
|
||||
Check.False(chat.Contains("Older RynthCore engine"), "no older-engine note on v84");
|
||||
Check.Eq(FakeHost.IdRequests.Count, 0, "already identified: no new ID request");
|
||||
}
|
||||
|
||||
private static void Layout()
|
||||
{
|
||||
var d = new PropertyDumpData { Id = Coat, Name = "Coat", Wcid = 37191, ObjectClass = "Armor", ObjectClassValue = 2, HasIdData = true, Complete = true };
|
||||
d.Ints[19] = 5; d.Ints[1] = 2; d.Ints[5000] = 1; d.Ints[4999] = 1;
|
||||
d.Strings[1] = "Coat";
|
||||
d.InstanceIds[2] = Pack;
|
||||
d.Spells.Add(2783);
|
||||
List<string> lines = PropertyDump.Format(d, s => "Spell" + s, id => id == Pack ? "Pack" : null);
|
||||
Check.Eq(lines[0], "Property Dump for Coat", "first line");
|
||||
Check.Eq(lines[1], $"Id = {Coat} (0x{Coat:X8})", "id line");
|
||||
Check.True(lines.Contains("Type (wcid) = 37191") && lines.Contains("ObjectClass = Armor (2)"), "wcid, object class");
|
||||
Check.True(lines.Contains("Container = 0x80001200 (Pack)") && lines.Contains("HasIdData = True"), "container, id data");
|
||||
int strings = lines.IndexOf("String Values:"), ints = lines.IndexOf("Int Values:"), iids = lines.IndexOf("InstanceId Values:"), spells = lines.IndexOf("Spells (1):");
|
||||
Check.True(strings > 0 && strings < ints && ints < iids && iids < spells, "sections in UB's order, spells last");
|
||||
Check.False(lines.Contains("Bool Values:"), "an empty section is left out");
|
||||
Check.Eq(lines[ints + 1], " ItemType (1) = 2", "ints sorted by name: ItemType");
|
||||
Check.Eq(lines[ints + 2], " Value (19) = 5", "then Value");
|
||||
Check.Eq(lines[ints + 3], " 4999 = 1", "unknown keys after the named ones, by number");
|
||||
Check.Eq(lines[spells + 1], " Spell2783 (2783)", "spell line");
|
||||
Check.Eq(PropertyDump.FileName("Olthoi Amuli Coat", new DateTime(2026, 10, 13, 9, 5, 7)), "propertydump-Olthoi_Amuli_Coat-20261013-090507.txt", "file name");
|
||||
Check.Eq(PropertyDump.FileName("<>:|?*", DateTime.MinValue), "propertydump-object-00010101-000000.txt", "unsafe name");
|
||||
}
|
||||
|
||||
private static void WaitsForId()
|
||||
{
|
||||
DumpFolder();
|
||||
bool idArrived = false;
|
||||
Setup(id => id != Coat ? null
|
||||
: idArrived ? CoatRecord()
|
||||
: ObjectPropertyRecord.Encode(new PropertyBag(), null, EngineFlags.HasCreateData, 0), appraised: false);
|
||||
var bot = new Bot();
|
||||
bot.Set("_currentTargetId", Coat);
|
||||
bot.Call("HandleRynthChatSubmit", "/ub propertydump");
|
||||
Check.True(FakeHost.IdRequests.Contains(Coat), "asked the server for an ID");
|
||||
Check.True(bot.AllChat.Contains("isn't identified yet"), "said so");
|
||||
Check.False(bot.AllChat.Contains("Property Dump for"), "no dump before the answer");
|
||||
bot.Now += 300; bot.Tick();
|
||||
Check.False(bot.AllChat.Contains("Property Dump for"), "still waiting");
|
||||
FakeHost.Appraised.Add(Coat); idArrived = true;
|
||||
bot.Now += 150; bot.DrainAll();
|
||||
Check.True(bot.AllChat.Contains("Property Dump for Olthoi Amuli Coat") && bot.AllChat.Contains("InventoryOrder (9015) = 3"), "the dump after the answer, in full");
|
||||
Check.Eq(FakeHost.IdRequests.Count(i => i == Coat), 1, "one ID request");
|
||||
}
|
||||
|
||||
private static void IdTimeout()
|
||||
{
|
||||
DumpFolder();
|
||||
var bag = new PropertyBag(); bag.Ints[19] = 100; bag.Strings[1] = "Olthoi Amuli Coat";
|
||||
Setup(id => id == Coat ? ObjectPropertyRecord.Encode(bag, null, EngineFlags.HasCreateData, 0) : null, appraised: false);
|
||||
var bot = new Bot();
|
||||
bot.Ra($"/ra dumpprops 0x{Coat:X8}");
|
||||
bot.Now += 1000; bot.Tick();
|
||||
Check.False(bot.AllChat.Contains("Property Dump for"), "waiting inside the 4 s");
|
||||
bot.Now += 3500; bot.DrainAll();
|
||||
Check.True(bot.AllChat.Contains("No identify answer"), "the timeout is said");
|
||||
Check.True(bot.AllChat.Contains(" Value (19) = 100"), "what the client has is dumped");
|
||||
Check.True(bot.AllChat.Contains("Not identified"), "the not-identified note");
|
||||
}
|
||||
|
||||
private static void QualitiesPending()
|
||||
{
|
||||
DumpFolder();
|
||||
int calls = 0;
|
||||
Setup(id =>
|
||||
{
|
||||
if (id != Coat) return null;
|
||||
calls++;
|
||||
return calls <= 2 ? CoatRecord(EngineFlags.HasIdData | EngineFlags.QualitiesPending) : CoatRecord();
|
||||
});
|
||||
var bot = new Bot();
|
||||
bot.Set("_currentTargetId", Coat);
|
||||
bot.Ra("/ra dumpprops");
|
||||
Check.False(bot.AllChat.Contains("Property Dump for"), "pending: not yet");
|
||||
bot.Now += 50; bot.Tick();
|
||||
Check.False(bot.AllChat.Contains("Property Dump for"), "inside the poll interval nothing is asked");
|
||||
bot.Now += 100; bot.Tick(); // second query: still pending
|
||||
bot.Now += 100; bot.DrainAll();
|
||||
Check.True(bot.AllChat.Contains("Property Dump for"), "dumped once the read is in");
|
||||
|
||||
// An engine that never finishes the read: dumped anyway after the wait.
|
||||
Setup(id => id == Coat ? CoatRecord(EngineFlags.HasIdData | EngineFlags.QualitiesPending) : null);
|
||||
bot = new Bot();
|
||||
bot.Set("_currentTargetId", Coat);
|
||||
bot.Ra("/ra dumpprops");
|
||||
bot.Now += 2000; bot.DrainAll();
|
||||
Check.True(bot.AllChat.Contains("Property Dump for"), "never finished: dumped after the wait");
|
||||
}
|
||||
|
||||
private static void ChunksAndFile()
|
||||
{
|
||||
string dir = DumpFolder();
|
||||
var big = CoatBag();
|
||||
for (uint k = 5000; k < 5200; k++) big.Ints[k] = (int)k;
|
||||
Setup(id => id == Coat ? ObjectPropertyRecord.Encode(big, null, EngineFlags.HasIdData, 0) : null);
|
||||
var bot = new Bot();
|
||||
bot.Set("_currentTargetId", Coat);
|
||||
int before = FakeHost.Chat.Count;
|
||||
bot.Ra("/ra dumpprops");
|
||||
int first = FakeHost.Chat.Count - before;
|
||||
Check.True(first <= PropertyDump.ChatLinesPerTick, $"first chunk {first} lines");
|
||||
bot.Tick();
|
||||
Check.True(FakeHost.Chat.Count - before <= 2 * PropertyDump.ChatLinesPerTick, "one more chunk per tick");
|
||||
bot.DrainAll();
|
||||
Check.True(bot.AllChat.Contains(" 5199 = 5199"), "the last line reaches chat");
|
||||
string[] files = Directory.Exists(dir) ? Directory.GetFiles(dir, "propertydump-Olthoi_Amuli_Coat-*.txt") : Array.Empty<string>();
|
||||
Check.Eq(files.Length, 1, "one file in RynthAi\\Logs");
|
||||
if (files.Length == 1)
|
||||
{
|
||||
string[] text = File.ReadAllLines(files[0]);
|
||||
Check.True(text[0] == "Property Dump for Olthoi Amuli Coat" && text.Contains(" 5199 = 5199"), "the full dump, without chat prefixes");
|
||||
Check.True(bot.AllChat.Contains("written to " + files[0]), "chat says where");
|
||||
}
|
||||
}
|
||||
|
||||
private static void OlderEngineFallback()
|
||||
{
|
||||
DumpFolder();
|
||||
FakeHost.Reset();
|
||||
FakeHost.Names[Player] = "Tester";
|
||||
FakeHost.Names[Coat] = "Olthoi Amuli Coat";
|
||||
FakeHost.Ints[(Coat, 19)] = 15000;
|
||||
FakeHost.Ints[(Coat, 9015)] = 3; // named, past the old range: now probed
|
||||
FakeHost.Ints[(Coat, 4242)] = 7; // unnamed, past the range: an older engine can't know it
|
||||
FakeHost.Doubles[(Coat, 167)] = 2.5; // CooldownDuration
|
||||
FakeHost.Strings[(Coat, 1)] = "Olthoi Amuli Coat";
|
||||
FakeHost.DataIds[(Coat, 8)] = 0x06001F88;
|
||||
FakeHost.SpellIds[Coat] = new uint[] { 2783 };
|
||||
FakeHost.Create(Player); // no ObjectPropertiesCalls: GetObjectProperties absent
|
||||
var bot = new Bot();
|
||||
PropertyDumpData? d = bot.P.CollectPropertyDump(Coat, out bool pending);
|
||||
Check.True(d != null && !pending && !d.Complete, "collected without v84");
|
||||
Check.True(d!.Ints.TryGetValue(9015, out int io) && io == 3 && d.Ints[19] == 15000, "named keys past the old ranges");
|
||||
Check.False(d.Ints.ContainsKey(4242), "an unnamed key beyond the ranges stays unknown (older engine)");
|
||||
Check.True(d.Floats.TryGetValue(167, out double cd) && cd == 2.5 && d.DataIds[8] == 0x06001F88, "float and data id probed");
|
||||
Check.True(d.Spells.SequenceEqual(new uint[] { 2783 }), "spells from GetObjectSpellIds");
|
||||
bot.Set("_currentTargetId", Coat);
|
||||
bot.Ra("/ra dumpprops");
|
||||
bot.DrainAll();
|
||||
Check.True(bot.AllChat.Contains("Older RynthCore engine"), "the older-engine note");
|
||||
Check.True(bot.AllChat.Contains(" CooldownDuration (167) = 2.5"), "names on the fallback too");
|
||||
}
|
||||
|
||||
private static void Routes()
|
||||
{
|
||||
DumpFolder();
|
||||
var selfBag = new PropertyBag(); selfBag.Ints[25] = 275; selfBag.Strings[1] = "Tester";
|
||||
Setup(id => id == Player ? ObjectPropertyRecord.Encode(selfBag, null, EngineFlags.IsPlayer, 0)
|
||||
: id == Coat ? CoatRecord() : null);
|
||||
var bot = new Bot();
|
||||
bot.Ra("/ra dumpprops");
|
||||
bot.DrainAll();
|
||||
Check.True(bot.AllChat.Contains("Nothing selected") && bot.AllChat.Contains(" Level (25) = 275"), "nothing selected: the character");
|
||||
Check.Eq(FakeHost.IdRequests.Count, 0, "the character isn't identified first");
|
||||
|
||||
FakeHost.Chat.Clear();
|
||||
bot.Set("_currentTargetId", Coat);
|
||||
bot.Ra("/ra propertydump");
|
||||
bot.DrainAll();
|
||||
Check.True(bot.AllChat.Contains("Property Dump for Olthoi Amuli Coat"), "/ra propertydump (the hotkey's command)");
|
||||
|
||||
FakeHost.Chat.Clear();
|
||||
bot.Call("HandleRynthChatSubmit", "/vt propertydump");
|
||||
bot.DrainAll();
|
||||
bool vt = bot.AllChat.Contains("Property Dump for Olthoi Amuli Coat");
|
||||
FakeHost.Chat.Clear();
|
||||
bot.Call("HandleRynthChatSubmit", "/ub propertydump");
|
||||
bot.DrainAll();
|
||||
bool ub = bot.AllChat.Contains("Property Dump for Olthoi Amuli Coat");
|
||||
Check.True(ub, "/ub propertydump");
|
||||
Check.True(vt, "/vt propertydump");
|
||||
}
|
||||
}
|
||||
|
|
@ -282,20 +282,31 @@ internal static class UseAtLoginTests
|
|||
bot.S.IsMacroRunning = true;
|
||||
bot.S.OpenDoors = false; // only the requested door
|
||||
bot.Set("_doorRequestedId", unchecked((int)Door));
|
||||
long now = 70_000_000;
|
||||
RynthAiPlugin.DoorClock = () => now;
|
||||
|
||||
// The targeting tick stops the character; the use goes on the next one (2026-10-13:
|
||||
// it waits for its turn - ActionPacer, the client's busy count).
|
||||
bot.Call("TickDoorInteraction");
|
||||
bot.Call("TickDoorInteraction");
|
||||
Check.Eq(FakeHost.Uses.Count(u => u == Door), 1, "the requested door is used once");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("[Use] RynthAi/Door") && l.Contains("nav detour")), "logged with the reason");
|
||||
|
||||
// The fake never reports the door open. Right after the use: still waiting.
|
||||
for (int i = 0; i < 5; i++) bot.Call("TickDoorInteraction");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("not open after use")), "not judged 'not open' within ms of the use");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("not open")), "not judged 'not open' within ms of the use");
|
||||
Check.Eq(FakeHost.Uses.Count(u => u == Door), 1, "and not used again (a second use would close it)");
|
||||
|
||||
Thread.Sleep(1300);
|
||||
// No UseDone count on this fake engine: the use counts as answered after 600 ms, then
|
||||
// the door gets its time to swing.
|
||||
now += 700;
|
||||
bot.Call("TickDoorInteraction");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("not open after use")), "judged once the door had time to swing");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("not open")), "not judged right at the answer");
|
||||
now += 1300;
|
||||
bot.Call("TickDoorInteraction");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("not open")), "judged once the door had time to swing");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("is locked")), "and not called locked (the server never said so)");
|
||||
}
|
||||
finally { Done(); }
|
||||
finally { RynthAiPlugin.DoorClock = static () => Environment.TickCount64; Done(); }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue