Bar icon dropdown: barMenu on plugin windows (API v95) #13

Open
AwfulWaffle wants to merge 26 commits from AwfulWaffle/RynthCore:bar-menu into main
11 changed files with 437 additions and 3 deletions
Showing only changes of commit 28d480c90a - Show all commits

Plugin API v93: web panel table fields and SDK wrappers (number provisional)

Four appended table slots (WebPanelOpen/Navigate/Close/GetState), native structs and code enums in engine and SDK, a WebPanelApi stub answering Unavailable (CoreCLR flavour only; AOT leaves the slots zero), SDK OpenWebPanel/NavigateWebPanel/CloseWebPanel/GetWebPanelState with HasWebPanel gated on Version >= 93, parity tests in PluginManifestTests. Also adds the missing System usings to the Task 1 WebPanel files, which did not compile in the engine project (no ImplicitUsings).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Daniel Wallace 2026-11-07 14:31:48 -08:00

View file

@ -1069,6 +1069,74 @@ internal struct RynthCoreAPI
/// reading, 0 without (never read; *ratio = -1, *ageMs = 0xFFFFFFFF). Either pointer may be null.
/// Read-only, any thread, no game calls. Requires API v93+.</summary>
public IntPtr GetMonsterHealthFn;
//── v93: a WebView2 web panel over the game window (WebPanel\WebPanelApi.cs) ──
// No call blocks its caller (AC's main thread, the plugin pump and ImGui draws all call these).
/// <summary>v93: <c>int WebPanelOpen(WebPanelOpenNative* open)</c>: opens (or replaces) the web panel.
/// Returns a handle &gt; 0, or BadArgs / UrlNotAllowed / NoGameWindow / Unavailable / ShuttingDown
/// (WebPanelCode). Requires API v93+ (provisional number).</summary>
public IntPtr WebPanelOpenFn;
/// <summary>v93: <c>int WebPanelNavigate(int handle, byte* url)</c>: 1 queued; -2 off the allowlist
/// (opened in the system browser when it is browser-safe); -6 stale handle.</summary>
public IntPtr WebPanelNavigateFn;
/// <summary>v93: <c>int WebPanelClose(int handle)</c>: 1 queued, 0 already closed, -6 stale handle.</summary>
public IntPtr WebPanelCloseFn;
/// <summary>v93: <c>int WebPanelGetState(int handle, WebPanelStateNative* state)</c>: the WebPanelStatusCode
/// (a handle that is not the live one reads 6 Superseded), -1 bad args.</summary>
public IntPtr WebPanelGetStateFn;
}
/// <summary>v93 WebPanelOpen argument (Pack 4; 48 bytes on x86). Mirrors RynthCore.PluginSdk/WebPanelTypes.cs.</summary>
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal unsafe struct WebPanelOpenNative
{
/// <summary>sizeof the caller's struct; the engine accepts Size &gt;= OffsetOf(Reserved) (32 on x86).</summary>
public uint Size;
/// <summary>WebPanelFlags; unknown bits ignored.</summary>
public uint Flags;
/// <summary>UTF-8 NUL-terminated, at most 4096 bytes, must pass the URL policy's IsAllowed.</summary>
public byte* Url;
/// <summary>UTF-8, '\n'-separated allowlist (WebPanelUrlPolicy.TryParseAllowlist).</summary>
public byte* Allowlist;
/// <summary>UTF-8, may be null; at most 256 bytes.</summary>
public byte* ProfileKey;
/// <summary>UTF-8, may be null; at most 128 bytes.</summary>
public byte* Title;
/// <summary>0 = 88, else 30..100 (only when no remembered layout).</summary>
public int WidthPercent;
public int HeightPercent;
public fixed uint Reserved[4];
}
/// <summary>v93 WebPanelGetState result (Pack 4; 48 bytes). Mirrors RynthCore.PluginSdk/WebPanelTypes.cs.</summary>
[StructLayout(LayoutKind.Sequential, Pack = 4)]
internal unsafe struct WebPanelStateNative
{
public uint Size;
public int Handle;
/// <summary>WebPanelStatusCode.</summary>
public int Status;
/// <summary>1 Visible, 2 Focused, 4 OpenedInBrowser.</summary>
public uint Flags;
/// <summary>0 or a negative WebPanelCode (RuntimeMissing / CreateFailed / ProcessFailed).</summary>
public int Error;
public int LastHttpStatus;
public uint NavigationCount;
public fixed uint Reserved[5];
}
/// <summary>v93 return codes of the web panel calls. Append only.</summary>
internal enum WebPanelCode
{
Queued = 1, AlreadyClosed = 0, BadArgs = -1, UrlNotAllowed = -2, NoGameWindow = -3,
Unavailable = -4, ShuttingDown = -5, StaleHandle = -6, RuntimeMissing = -7, CreateFailed = -8, ProcessFailed = -9,
}
/// <summary>v93 WebPanelStateNative.Status values. Append only.</summary>
internal enum WebPanelStatusCode
{
None = 0, Starting = 1, Loading = 2, Ready = 3, Closed = 4, Failed = 5, Superseded = 6,
}
/// <summary>v89 GetUiColor tokens. Append only: plugins compiled against these numbers keep them.</summary>
@ -1930,6 +1998,18 @@ internal unsafe delegate int GetAmbientLightCallbackDelegate(uint* client, uint*
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int GetMonsterHealthCallbackDelegate(uint id, float* ratio, uint* ageMs);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int WebPanelOpenCallbackDelegate(WebPanelOpenNative* open);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int WebPanelNavigateCallbackDelegate(int handle, byte* url);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int WebPanelCloseCallbackDelegate(int handle);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate int WebPanelGetStateCallbackDelegate(int handle, WebPanelStateNative* state);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate uint VendorBuyCallbackDelegate(uint vendorId, VendorTradeEntryNative* entries, int count);

View file

@ -47,5 +47,8 @@ internal static class PluginContractVersion
// any thread (feature/hud-health-for-plugins, 2026-11-07). Note: feature/reload-state,
// feature/engine-events and the branches built on them (unmerged) also use 93 and 94; whichever
// merges second renumbers.
// v93: WebPanelOpen, WebPanelNavigate, WebPanelClose and WebPanelGetState: a WebView2 web panel over the
// game window (WebPanel\WebPanelApi.cs; DreamWeave's in-game market and tools). The number is
// PROVISIONAL: upstream may take 93 first, in which case this renumbers on merge.
public const uint Current = 93;
}

View file

@ -304,6 +304,12 @@ internal static partial class PluginManager
private static SetAmbientLightFloorCallbackDelegate? _setAmbientLightFloorCallback; // v91
private static GetAmbientLightCallbackDelegate? _getAmbientLightCallback; // v91
private static GetMonsterHealthCallbackDelegate? _getMonsterHealthCallback; // v93
#if ENGINE_CORECLR
private static WebPanelOpenCallbackDelegate? _webPanelOpenCallback; // v93
private static WebPanelNavigateCallbackDelegate? _webPanelNavigateCallback; // v93
private static WebPanelCloseCallbackDelegate? _webPanelCloseCallback; // v93
private static WebPanelGetStateCallbackDelegate? _webPanelGetStateCallback; // v93
#endif
private static ForceResetBusyCountCallbackDelegate? _forceResetBusyCountCallback;
private static GetObjectSpellIdsCallbackDelegate? _getObjectSpellIdsCallback;
private static GetObjectSkillLevelCallbackDelegate? _getObjectSkillBuffedCallback;
@ -3254,6 +3260,13 @@ internal static partial class PluginManager
_setAmbientLightFloorCallback ??= AmbientLight.SetFloor; // v91
unsafe { _getAmbientLightCallback ??= AmbientLight.Get; }
unsafe { _getMonsterHealthCallback ??= GetMonsterHealthAction; } // v93
#if ENGINE_CORECLR
// v93: the AOT engine leaves these slots zero, so HasWebPanel is false there.
unsafe { _webPanelOpenCallback ??= WebPanel.WebPanelApi.Open; }
unsafe { _webPanelNavigateCallback ??= WebPanel.WebPanelApi.Navigate; }
_webPanelCloseCallback ??= WebPanel.WebPanelApi.Close;
unsafe { _webPanelGetStateCallback ??= WebPanel.WebPanelApi.GetState; }
#endif
_api.Version = PluginContractVersion.Current;
_api.LogFn = Marshal.GetFunctionPointerForDelegate(_logCallback);
@ -3427,6 +3440,12 @@ internal static partial class PluginManager
_api.SetAmbientLightFloorFn = Marshal.GetFunctionPointerForDelegate(_setAmbientLightFloorCallback);
_api.GetAmbientLightFn = Marshal.GetFunctionPointerForDelegate(_getAmbientLightCallback);
_api.GetMonsterHealthFn = Marshal.GetFunctionPointerForDelegate(_getMonsterHealthCallback);
#if ENGINE_CORECLR
_api.WebPanelOpenFn = Marshal.GetFunctionPointerForDelegate(_webPanelOpenCallback!);
_api.WebPanelNavigateFn = Marshal.GetFunctionPointerForDelegate(_webPanelNavigateCallback!);
_api.WebPanelCloseFn = Marshal.GetFunctionPointerForDelegate(_webPanelCloseCallback!);
_api.WebPanelGetStateFn = Marshal.GetFunctionPointerForDelegate(_webPanelGetStateCallback!);
#endif
RouteApiThroughLoader();
}

View file

@ -0,0 +1,19 @@
using RynthCore.Engine.Plugins;
namespace RynthCore.Engine.WebPanel;
/// <summary>
/// The engine side of the v93 web panel calls (PluginContract.cs WebPanelOpenFn..WebPanelGetStateFn).
/// Task 2 stub: every call answers Unavailable; the WebView2 host arrives in a later task.
/// No call here may block its caller (AC's main thread, the plugin pump and ImGui draws all call these).
/// </summary>
internal static class WebPanelApi
{
public static unsafe int Open(WebPanelOpenNative* open) => (int)WebPanelCode.Unavailable;
public static unsafe int Navigate(int handle, byte* url) => (int)WebPanelCode.Unavailable;
public static int Close(int handle) => (int)WebPanelCode.Unavailable;
public static unsafe int GetState(int handle, WebPanelStateNative* state) => (int)WebPanelCode.Unavailable;
}

View file

@ -1,3 +1,5 @@
using System.IO;
using System;
using System.Security.Cryptography;
using System.Text;

View file

@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace RynthCore.Engine.WebPanel;

View file

@ -1,3 +1,4 @@
using System;
namespace RynthCore.Engine.WebPanel;
internal readonly record struct PanelRect(int Left, int Top, int Right, int Bottom)

View file

@ -204,6 +204,11 @@ public struct RynthCoreApiNative
public IntPtr GetAmbientLightFn; // int GetAmbientLight(uint* client, uint* applied) -> 1 hook live, 0 not
// v93: the monster plates' last server health reading per object
public IntPtr GetMonsterHealthFn; // int GetMonsterHealth(uint id, float* ratio, uint* ageMs) -> 1 reading, 0 none
// v93: a WebView2 web panel over the game window (APPEND-AT-END (ABI); number provisional)
public IntPtr WebPanelOpenFn; // int WebPanelOpen(WebPanelOpenNative*) -> handle > 0, or BadArgs/UrlNotAllowed/NoGameWindow/Unavailable/ShuttingDown
public IntPtr WebPanelNavigateFn; // int WebPanelNavigate(int handle, byte* url) -> 1 queued; -2 off-list; -6 stale
public IntPtr WebPanelCloseFn; // int WebPanelClose(int handle) -> 1 queued, 0 already closed, -6 stale
public IntPtr WebPanelGetStateFn; // int WebPanelGetState(int handle, WebPanelStateNative*) -> Status (non-live handle -> 6 Superseded), -1 bad args
}
/// <summary>

View file

@ -1877,6 +1877,119 @@ public readonly unsafe struct RynthCoreHost
return true;
}
// ── v93: a web panel over the game window (number provisional) ───────────
/// <summary>
/// v93: <see cref="OpenWebPanel"/>, <see cref="NavigateWebPanel"/>, <see cref="CloseWebPanel"/> and
/// <see cref="GetWebPanelState"/>. True only on an engine at API 93 or newer that fills all four.
/// </summary>
public bool HasWebPanel => _api.Version >= 93 && _api.WebPanelOpenFn != IntPtr.Zero && _api.WebPanelNavigateFn != IntPtr.Zero
&& _api.WebPanelCloseFn != IntPtr.Zero && _api.WebPanelGetStateFn != IntPtr.Zero;
/// <summary>
/// v93: opens the web panel over the game window (a second call replaces the first). Returns a handle
/// &gt; 0, or a <see cref="WebPanelResult"/> (BadArgs for an empty URL or allowlist, more than 16
/// entries or a newline inside one; Unavailable on an older engine). Never blocks; the panel loads
/// after this returns - poll <see cref="GetWebPanelState"/>. Any thread.
/// </summary>
public int OpenWebPanel(WebPanelOptions options)
{
if (options == null || string.IsNullOrEmpty(options.Url) || options.Allowlist == null
|| options.Allowlist.Count < 1 || options.Allowlist.Count > 16)
return (int)WebPanelResult.BadArgs;
foreach (string entry in options.Allowlist)
if (string.IsNullOrEmpty(entry) || entry.Contains('\n')) return (int)WebPanelResult.BadArgs;
if (!HasWebPanel) return (int)WebPanelResult.Unavailable;
string allowlist = string.Join("\n", options.Allowlist);
string profile = options.ProfileKey ?? "";
string title = options.Title ?? "";
var enc = System.Text.Encoding.UTF8;
int nUrl = enc.GetByteCount(options.Url), nAllow = enc.GetByteCount(allowlist);
int nProfile = enc.GetByteCount(profile), nTitle = enc.GetByteCount(title);
int total = nUrl + nAllow + nProfile + nTitle + 4;
byte[]? rented = null;
Span<byte> buf = total <= 1024 ? stackalloc byte[total] : (rented = System.Buffers.ArrayPool<byte>.Shared.Rent(total)).AsSpan(0, total);
try
{
int o = 0;
int oUrl = o; o += enc.GetBytes(options.Url, buf[o..]); buf[o++] = 0;
int oAllow = o; o += enc.GetBytes(allowlist, buf[o..]); buf[o++] = 0;
int oProfile = o; o += enc.GetBytes(profile, buf[o..]); buf[o++] = 0;
int oTitle = o; o += enc.GetBytes(title, buf[o..]); buf[o++] = 0;
fixed (byte* b = buf)
{
var open = new WebPanelOpenNative
{
Size = (uint)sizeof(WebPanelOpenNative),
Flags = (uint)options.Flags,
Url = b + oUrl,
Allowlist = b + oAllow,
ProfileKey = nProfile == 0 ? null : b + oProfile,
Title = nTitle == 0 ? null : b + oTitle,
WidthPercent = options.WidthPercent,
HeightPercent = options.HeightPercent,
};
return ((delegate* unmanaged[Cdecl]<WebPanelOpenNative*, int>)_api.WebPanelOpenFn)(&open);
}
}
finally
{
if (rented != null) System.Buffers.ArrayPool<byte>.Shared.Return(rented);
}
}
/// <summary>
/// v93: points the panel <paramref name="handle"/> at <paramref name="url"/>. 1 queued; -2
/// (UrlNotAllowed) when it is off the allowlist (the engine opens it in the system browser when that is
/// safe); -6 (StaleHandle) when the handle is not the live panel. Never blocks. Any thread.
/// </summary>
public int NavigateWebPanel(int handle, string url)
{
if (string.IsNullOrEmpty(url)) return (int)WebPanelResult.BadArgs;
if (!HasWebPanel) return (int)WebPanelResult.Unavailable;
int n = System.Text.Encoding.UTF8.GetByteCount(url);
byte[]? rented = null;
Span<byte> buf = n + 1 <= 1024 ? stackalloc byte[n + 1] : (rented = System.Buffers.ArrayPool<byte>.Shared.Rent(n + 1)).AsSpan(0, n + 1);
try
{
System.Text.Encoding.UTF8.GetBytes(url, buf);
buf[n] = 0;
fixed (byte* p = buf)
return ((delegate* unmanaged[Cdecl]<int, byte*, int>)_api.WebPanelNavigateFn)(handle, p);
}
finally
{
if (rented != null) System.Buffers.ArrayPool<byte>.Shared.Return(rented);
}
}
/// <summary>v93: closes the panel <paramref name="handle"/>. 1 queued, 0 already closed, -6 stale handle. Never blocks. Any thread.</summary>
public int CloseWebPanel(int handle)
{
if (!HasWebPanel) return (int)WebPanelResult.Unavailable;
return ((delegate* unmanaged[Cdecl]<int, int>)_api.WebPanelCloseFn)(handle);
}
/// <summary>
/// v93: where the panel <paramref name="handle"/> is. A handle that is not the live panel reads
/// Superseded. None (and a default <paramref name="state"/>) on an older engine or bad arguments.
/// Any thread.
/// </summary>
public WebPanelStatus GetWebPanelState(int handle, out WebPanelState state)
{
state = default;
if (!HasWebPanel) return WebPanelStatus.None;
WebPanelStateNative native = default;
native.Size = (uint)sizeof(WebPanelStateNative);
int r = ((delegate* unmanaged[Cdecl]<int, WebPanelStateNative*, int>)_api.WebPanelGetStateFn)(handle, &native);
if (r < 0) return WebPanelStatus.None;
var status = (WebPanelStatus)native.Status;
state = new WebPanelState(native.Handle, status, (WebPanelStateFlags)native.Flags, (WebPanelResult)native.Error, native.LastHttpStatus, native.NavigationCount);
return status;
}
private int CallSetActionKey(string action, string key, int op, out string message)
{
message = string.Empty;

View file

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace RynthCore.PluginSdk;
// v93: a WebView2 web panel over the game window. The native structs mirror
// RynthCore.Engine/Plugins/PluginContract.cs field for field (tools\PluginManifestTests checks sizes and
// offsets). The API number is provisional.
/// <summary>v93 WebPanelOpen argument (Pack 4; 48 bytes on x86). Mirrors the engine's WebPanelOpenNative.</summary>
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public unsafe struct WebPanelOpenNative
{
/// <summary>sizeof this struct; the engine accepts Size &gt;= OffsetOf(Reserved) (32 on x86).</summary>
public uint Size;
/// <summary><see cref="WebPanelFlags"/>; unknown bits ignored.</summary>
public uint Flags;
/// <summary>UTF-8 NUL-terminated, at most 4096 bytes.</summary>
public byte* Url;
/// <summary>UTF-8, '\n'-separated allowlist.</summary>
public byte* Allowlist;
/// <summary>UTF-8, may be null; at most 256 bytes.</summary>
public byte* ProfileKey;
/// <summary>UTF-8, may be null; at most 128 bytes.</summary>
public byte* Title;
/// <summary>0 = 88, else 30..100 (only when no remembered layout).</summary>
public int WidthPercent;
public int HeightPercent;
public fixed uint Reserved[4];
}
/// <summary>v93 WebPanelGetState result (Pack 4; 48 bytes). Mirrors the engine's WebPanelStateNative.</summary>
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public unsafe struct WebPanelStateNative
{
public uint Size;
public int Handle;
/// <summary><see cref="WebPanelStatus"/>.</summary>
public int Status;
/// <summary><see cref="WebPanelStateFlags"/>.</summary>
public uint Flags;
/// <summary>0 or a negative <see cref="WebPanelResult"/> (RuntimeMissing / CreateFailed / ProcessFailed).</summary>
public int Error;
public int LastHttpStatus;
public uint NavigationCount;
public fixed uint Reserved[5];
}
/// <summary>Options for <see cref="RynthCoreHost.OpenWebPanel"/>.</summary>
[Flags]
public enum WebPanelFlags : uint
{
None = 0,
/// <summary>When the panel cannot open (no WebView2 runtime, creation failed), open the URL in the system browser.</summary>
FallbackToBrowser = 1,
/// <summary>Escape goes to the page instead of closing the panel.</summary>
PageKeepsEscape = 2,
// 4 is reserved: phase 2 EnableMessages.
}
/// <summary>Results of the web panel calls; an open that succeeds returns a handle &gt; 0 instead.</summary>
public enum WebPanelResult : int
{
Queued = 1, AlreadyClosed = 0, BadArgs = -1, UrlNotAllowed = -2, NoGameWindow = -3,
Unavailable = -4, ShuttingDown = -5, StaleHandle = -6, RuntimeMissing = -7, CreateFailed = -8, ProcessFailed = -9,
}
/// <summary>Where the web panel is in its life.</summary>
public enum WebPanelStatus : int
{
None = 0, Starting = 1, Loading = 2, Ready = 3, Closed = 4, Failed = 5, Superseded = 6,
}
[Flags]
public enum WebPanelStateFlags : uint
{
None = 0, Visible = 1, Focused = 2, OpenedInBrowser = 4,
}
/// <summary>A snapshot of the web panel from <see cref="RynthCoreHost.GetWebPanelState"/>.</summary>
public readonly record struct WebPanelState(int Handle, WebPanelStatus Status, WebPanelStateFlags Flags, WebPanelResult Error, int LastHttpStatus, uint NavigationCount);
public sealed class WebPanelOptions
{
public required string Url { get; init; }
/// <summary>1..16 entries, no '\n' inside an entry.</summary>
public required IReadOnlyList<string> Allowlist { get; init; }
/// <summary>Opaque; the engine lower-cases, hashes and adds the world.</summary>
public string ProfileKey { get; init; } = "";
public string Title { get; init; } = "";
public int WidthPercent { get; init; } = 0;
public int HeightPercent { get; init; } = 0;
public WebPanelFlags Flags { get; init; } = WebPanelFlags.FallbackToBrowser;
}

View file

@ -59,6 +59,10 @@ internal static class Program
Run(nameof(SdkApiVersionCannotDrift), SdkApiVersionCannotDrift);
Run(nameof(TrainingStructsMirror), TrainingStructsMirror);
Run(nameof(ContainerOrderSlots), ContainerOrderSlots);
Run(nameof(WebPanelFieldsAppended), WebPanelFieldsAppended);
Run(nameof(WebPanelStructsMatch), WebPanelStructsMatch);
Run(nameof(WebPanelCodesMatch), WebPanelCodesMatch);
Run(nameof(HasWebPanel_FalseOnOldOrPartialTable), HasWebPanel_FalseOnOldOrPartialTable);
Run(nameof(ManifestAttributeDrivesRuntimeMinimum), ManifestAttributeDrivesRuntimeMinimum);
Run(nameof(DedupeSamePathTwice), DedupeSamePathTwice);
Run(nameof(DedupeCaseAndSlashes), DedupeCaseAndSlashes);
@ -589,6 +593,91 @@ internal static class Program
"targets: the manifest and the runtime attribute both use the derived minimum");
}
// v93: the web panel's four slots are appended right after GetMonsterHealthFn, in order, on both sides.
private static void WebPanelFieldsAppended()
{
string[] slots = { "WebPanelOpenFn", "WebPanelNavigateFn", "WebPanelCloseFn", "WebPanelGetStateFn" };
string prev = "GetMonsterHealthFn";
foreach (string slot in slots)
{
Eq((int)Marshal.OffsetOf<RynthCore.Engine.Plugins.RynthCoreAPI>(slot),
(int)Marshal.OffsetOf<RynthCore.Engine.Plugins.RynthCoreAPI>(prev) + IntPtr.Size, "engine " + slot + " right after " + prev);
Eq((int)Marshal.OffsetOf<RynthCore.PluginSdk.RynthCoreApiNative>(slot),
(int)Marshal.OffsetOf<RynthCore.PluginSdk.RynthCoreApiNative>(prev) + IntPtr.Size, "SDK " + slot + " right after " + prev);
prev = slot;
}
Eq(typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).SkipLast(4).Last(), "GetMonsterHealthFn", "engine table: GetMonsterHealthFn precedes the four");
Eq(typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).SkipLast(4).Last(), "GetMonsterHealthFn", "SDK table: GetMonsterHealthFn precedes the four");
}
private static void StructMirror(Type engine, Type sdk, int size)
{
Eq(Marshal.SizeOf(engine), size, "engine " + engine.Name + " size");
Eq(Marshal.SizeOf(sdk), size, "SDK " + sdk.Name + " size");
var ef = engine.GetFields().Select(f => f.Name).ToArray();
var sf = sdk.GetFields().Select(f => f.Name).ToArray();
Check(ef.SequenceEqual(sf), engine.Name + " field names/order match: " + string.Join(",", ef) + " vs " + string.Join(",", sf));
foreach (string f in ef)
Eq((int)Marshal.OffsetOf(sdk, f), (int)Marshal.OffsetOf(engine, f), engine.Name + "." + f + " offset");
}
// v93: the SDK's WebPanelOpenNative/WebPanelStateNative are the engine's, byte for byte.
private static void WebPanelStructsMatch()
{
int p = IntPtr.Size;
StructMirror(typeof(RynthCore.Engine.Plugins.WebPanelOpenNative), typeof(RynthCore.PluginSdk.WebPanelOpenNative), 8 + 4 * p + 8 + 16);
StructMirror(typeof(RynthCore.Engine.Plugins.WebPanelStateNative), typeof(RynthCore.PluginSdk.WebPanelStateNative), 48);
Eq((int)Marshal.OffsetOf<RynthCore.Engine.Plugins.WebPanelOpenNative>("Reserved"), 8 + 4 * p + 8, "engine WebPanelOpenNative.Reserved offset (32 on x86)");
}
// v93: every code value agrees between the engine's enums and the SDK's.
private static void WebPanelCodesMatch()
{
Dictionary<string, long> Vals(Type t) => Enum.GetNames(t).ToDictionary(n => n, n => Convert.ToInt64(Enum.Parse(t, n)));
var engine = Vals(typeof(RynthCore.Engine.Plugins.WebPanelCode));
var sdk = Vals(typeof(RynthCore.PluginSdk.WebPanelResult));
Eq(sdk.Count, engine.Count, "WebPanelCode vs WebPanelResult member count");
foreach (var kv in engine)
Check(sdk.TryGetValue(kv.Key, out long v) && v == kv.Value, "WebPanelResult." + kv.Key + " = " + kv.Value);
var es = Vals(typeof(RynthCore.Engine.Plugins.WebPanelStatusCode));
var ss = Vals(typeof(RynthCore.PluginSdk.WebPanelStatus));
Eq(ss.Count, es.Count, "WebPanelStatusCode vs WebPanelStatus member count");
foreach (var kv in es)
Check(ss.TryGetValue(kv.Key, out long v) && v == kv.Value, "WebPanelStatus." + kv.Key + " = " + kv.Value);
Eq((uint)RynthCore.PluginSdk.WebPanelStateFlags.Visible, 1u, "state flag Visible");
Eq((uint)RynthCore.PluginSdk.WebPanelStateFlags.Focused, 2u, "state flag Focused");
Eq((uint)RynthCore.PluginSdk.WebPanelStateFlags.OpenedInBrowser, 4u, "state flag OpenedInBrowser");
Eq((uint)RynthCore.PluginSdk.WebPanelFlags.FallbackToBrowser, 1u, "open flag FallbackToBrowser");
Eq((uint)RynthCore.PluginSdk.WebPanelFlags.PageKeepsEscape, 2u, "open flag PageKeepsEscape");
}
// v93: HasWebPanel needs Version >= 93 AND all four slots (an old engine's table is shorter and the
// runtime copies the full new-size struct, so slots past its end are garbage, not zero).
private static void HasWebPanel_FalseOnOldOrPartialTable()
{
IntPtr x = (IntPtr)0xDEAD;
RynthCoreHost Host(uint version, IntPtr a, IntPtr b, IntPtr c, IntPtr d)
=> new RynthCoreHost(new RynthCoreApiNative { Version = version, WebPanelOpenFn = a, WebPanelNavigateFn = b, WebPanelCloseFn = c, WebPanelGetStateFn = d });
Check(!Host(92, x, x, x, x).HasWebPanel, "Version 92 with garbage slots: false");
Check(!Host(93, IntPtr.Zero, x, x, x).HasWebPanel, "Open zero: false");
Check(!Host(93, x, IntPtr.Zero, x, x).HasWebPanel, "Navigate zero: false");
Check(!Host(93, x, x, IntPtr.Zero, x).HasWebPanel, "Close zero: false");
Check(!Host(93, x, x, x, IntPtr.Zero).HasWebPanel, "GetState zero: false");
Check(Host(93, x, x, x, x).HasWebPanel, "Version 93, all four: true");
var old = Host(92, x, x, x, x);
Eq(old.OpenWebPanel(new WebPanelOptions { Url = "https://a.example/", Allowlist = new[] { "a.example" } }), (int)WebPanelResult.Unavailable, "Open without the API: Unavailable");
Eq(old.NavigateWebPanel(1, "https://a.example/"), (int)WebPanelResult.Unavailable, "Navigate without the API: Unavailable");
Eq(old.CloseWebPanel(1), (int)WebPanelResult.Unavailable, "Close without the API: Unavailable");
Eq(old.GetWebPanelState(1, out var st), WebPanelStatus.None, "GetState without the API: None");
Eq(st.Handle, 0, "GetState without the API: default state");
// Bad arguments are refused before the engine is called (the slots hold garbage, so a call would crash).
var live = Host(93, x, x, x, x);
Eq(live.OpenWebPanel(new WebPanelOptions { Url = "", Allowlist = new[] { "a" } }), (int)WebPanelResult.BadArgs, "empty URL: BadArgs");
Eq(live.OpenWebPanel(new WebPanelOptions { Url = "https://a/", Allowlist = Array.Empty<string>() }), (int)WebPanelResult.BadArgs, "empty allowlist: BadArgs");
Eq(live.OpenWebPanel(new WebPanelOptions { Url = "https://a/", Allowlist = new[] { "a\nb" } }), (int)WebPanelResult.BadArgs, "newline in an entry: BadArgs");
Eq(live.NavigateWebPanel(1, ""), (int)WebPanelResult.BadArgs, "navigate empty URL: BadArgs");
}
// v79: the SDK's copies of the training structs must be the engine's, byte for byte.
private static void TrainingStructsMirror()
{
@ -603,11 +692,11 @@ internal static class Program
Eq(RynthCore.PluginSdk.TrainingInfoFlags.Busy, RynthCore.Engine.Plugins.TrainingInfoFlags.Busy, "info flag bits");
Eq(RynthCore.PluginSdk.TrainingEntryFlags.Trainable, RynthCore.Engine.Plugins.TrainingEntryFlags.Trainable, "entry flag bits");
// The three v79 slots follow v78's, then v80's two and v81's GetMergeStackResultFn (v82-v91 follow:
// eleven slots to v89, then v90's thirteen, v91's two and v93's one).
var names = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).SkipLast(27).TakeLast(6).ToArray();
// eleven slots to v89, then v90's thirteen, v91's two, v93's one and the web panel's four).
var names = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).SkipLast(31).TakeLast(6).ToArray();
Check(names.SequenceEqual(new[] { "GetTrainingInfoFn", "RaiseFn", "TrainSkillFn", "GetContainerOrderFn", "PutItemInContainerFn", "GetMergeStackResultFn" }),
"v79, v80 then v81 slots last: " + string.Join(",", names));
var sdkNames = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).SkipLast(27).TakeLast(6).ToArray();
var sdkNames = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).SkipLast(31).TakeLast(6).ToArray();
Check(sdkNames.SequenceEqual(names), "SDK v79, v80 and v81 slots in the same order");
}
@ -618,6 +707,12 @@ internal static class Program
{
var all = typeof(RynthCore.Engine.Plugins.RynthCoreAPI).GetFields().Select(f => f.Name).ToArray();
var sdkAll = typeof(RynthCore.PluginSdk.RynthCoreApiNative).GetFields().Select(f => f.Name).ToArray();
// v93: the web panel's four slots end the table; the checks after these are on the table before them.
string[] v93 = { "WebPanelOpenFn", "WebPanelNavigateFn", "WebPanelCloseFn", "WebPanelGetStateFn" };
Check(all.TakeLast(v93.Length).SequenceEqual(v93), "v93 slots last: " + string.Join(",", all.TakeLast(v93.Length)));
Check(sdkAll.TakeLast(v93.Length).SequenceEqual(v93), "SDK v93 slots last: " + string.Join(",", sdkAll.TakeLast(v93.Length)));
all = all.SkipLast(v93.Length).ToArray();
sdkAll = sdkAll.SkipLast(v93.Length).ToArray();
// v93: the monster plates' health readings end the table (2026-11-07), right after v91's two.
Check(all.Last() == "GetMonsterHealthFn", "v93 slot last: " + all.Last());
Check(sdkAll.Last() == "GetMonsterHealthFn", "SDK v93 slot last: " + sdkAll.Last());