Plugin fixes: duplicate target requests, bounded name read, guarded exports

Selection: a selection change asked for an appraisal and a health query for every
object, and the dashboard asked for health again. The engine selects each
corpse it opens and each item it moves, so one object drew 4-6 identifies.
OnSelectedTargetChange now sends an identify only for a creature with no
cached appraisal (HasAppraisalData, else GetLastIdTime > 0) and a health
query only for creatures. The dashboard no longer queries health itself.
A target cached as Unknown (type not read yet) is undecided like an
uncached one: a corpse name ("Corpse of") rejects, the creature flag 0x10
accepts, a typed non-creature rejects, then ObjectIsAttackable decides, and
with nothing to go on it fails open.

Fellowship name read: FellowshipTracker.ReadPString read to a NUL with no bound. It now reads
at most 64 characters and never past the end of the probed region.

Exports: an exception escaping an UnmanagedCallersOnly export fail-fasts the
client under NativeAOT. The Shutdown exports of RynthAi, RynthNav, RynthNet,
RynthVision, RynthLua, RynthChat, RynthInventory, RynthOracle and
RynthTracker guard each step and log the error; the Name/Version exports of
RynthAi, RynthNav, RynthLua, RynthChat, RynthInventory, RynthNet,
RynthOracle, RynthTracker and RynthVision (a static initializer that throws
surfaces there) are wrapped.

Tests (PluginFixTests) with FakeHost QueryHealth and GetLastIdTime.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-10-12 16:32:05 -07:00
commit cf69899198
16 changed files with 518 additions and 52 deletions

View file

@ -36,15 +36,34 @@ public static unsafe class PluginExports
[UnmanagedCallersOnly(EntryPoint = "RynthPluginShutdown", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void Shutdown()
{
Runtime.Shutdown();
PathInterface.Release();
// An exception escaping an UnmanagedCallersOnly export fail-fasts the client under NativeAOT.
// Guard each step so one failure cannot skip the other.
RynthNavPlugin? plugin = Runtime.Plugin; // Runtime.Shutdown drops it; the log needs its host
try { Runtime.Shutdown(); }
catch (Exception ex) { LogShutdownError(plugin, "Runtime.Shutdown", ex); }
try { PathInterface.Release(); }
catch (Exception ex) { LogShutdownError(plugin, "PathInterface.Release", ex); }
}
private static void LogShutdownError(RynthNavPlugin? plugin, string step, Exception ex)
{
try { plugin?.LogFromExport($"[RynthNav] Shutdown: {step} failed: {ex.GetType().Name}: {ex.Message}"); }
catch { /* never throw out of a native export */ }
}
[UnmanagedCallersOnly(EntryPoint = "RynthPluginName", CallConvs = new[] { typeof(CallConvCdecl) })]
public static IntPtr GetName() => RynthNavPlugin.NamePointer;
public static IntPtr GetName()
{
try { return RynthNavPlugin.NamePointer; } // a static initializer that throws surfaces here (TypeInitializationException)
catch { return IntPtr.Zero; }
}
[UnmanagedCallersOnly(EntryPoint = "RynthPluginVersion", CallConvs = new[] { typeof(CallConvCdecl) })]
public static IntPtr GetVersion() => RynthNavPlugin.VersionPointer;
public static IntPtr GetVersion()
{
try { return RynthNavPlugin.VersionPointer; }
catch { return IntPtr.Zero; }
}
[UnmanagedCallersOnly(EntryPoint = "RynthPluginOnLoginComplete", CallConvs = new[] { typeof(CallConvCdecl) })]
public static void OnLoginComplete() => Runtime.OnLoginComplete();

View file

@ -28,6 +28,9 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
internal const string PluginVersion = "0.6.6";
internal static readonly IntPtr VersionPointer = Marshal.StringToHGlobalAnsi(PluginVersion);
/// <summary>Lets PluginExports log through this plugin's host (the base Log is protected).</summary>
internal void LogFromExport(string message) => Log(message);
// Where the tiles, portals.tsv, locations.json and the player's atlas.txt/recalls.txt live.
// From RYNTHNAV_NAVDATA, else "navDataDir" in %APPDATA%\RynthCore\rynthnav.json, else the
// default (the folder the release zip and the launcher's tile updater fill). See NavDataConfig.