// ============================================================================ // RynthSuite - Plugins/Shared/RynthServerHubApi.cs // The "RynthServer.Hub" interface: a server plugin's part of RynthAi's Mini // Remote. The Mini Remote stays RynthAi's (its window, tab bar, Remote, Pets and // Crafting tabs) and knows no server's content: the active server's plugin // supplies its tabs and the Pets tab's sub-tabs, its sections drawn inside // RynthAi's surfaces (Remote, Pets, Options, menu), its feature bits, texts and // mirrored settings, its "/ra" verbs and the pet summon-from-empty gate. // // RynthAi asks the plugin that owns RynthCore's active server (plugin API v86, // GetServerStateJson "activePlugin") for this interface, else the owners of the // other servers RynthCore lists (a server plugin may follow its own world check). // A server plugin answers it with the table below; RynthILT also serves the same // table under its own older name (RynthIltHubApi.cs). // // The ids and the layout are the wire format: they kept their values and order // when the interface was split out of RynthIltHubApi.cs (2026-10-21), so every // copy of RynthILT since its first release still fits. // Compiled into RynthAi and the server plugins that serve it (linked source), so // the layout can't drift. // // Rules (as the RynthAi.* interfaces, Shared/RynthAiScriptApi.cs): // - Append-only: new functions go at the end, and Version goes up. // - Strings are UTF-8, NUL-terminated. // - Threads: each function says where it may be called. The render-thread ones // draw into the caller's current ImGui window and context (the engine's cimgui, // shared by both plugins). // - Every function returns safely (no exception crosses the boundary), and returns // 0 / "unknown" once the serving plugin has shut down. // - The table is allocated once per loaded copy of the serving plugin and never // freed: its functions stay callable from the render thread while plugins shut // down (a plugin DLL is never unloaded, see the engine's // PluginManager.PluginsUnloaded). Shutdown sets Version to 0; a caller // re-queries (host GetPluginInterface) when it sees that, after a plugin // reload, or every few seconds. // ============================================================================ using System.Runtime.InteropServices; namespace RynthCore.Plugin.Shared; /// Constants of the "RynthServer.Hub" interface (section, tab, text, feature and setting ids). public static class RynthServerHub { /// Tab flag: the Mini Remote shows this tab now (the plugin's server, or forced, and the tab is usable). public const uint TabShown = 1; /// Tab flag: the server reports the tab's feature on. public const uint TabAvailable = 2; // Sections RynthAi draws through RenderSection, each in one of its own surfaces. A plugin draws // nothing (returns 0) for a section it doesn't have, or off its server. /// Remote tab, above the rebuff line: the server's bank balances. public const string SectionRemoteBank = "remote-bank"; /// Remote tab, under the translate line: a line of the server's own (e.g. a quest NPC's last answer). public const string SectionRemoteGuardian = "remote-guardian"; /// Remote tab, Stats section, under RynthAi's per-hour lines: the server's own session rates. public const string SectionRemoteStats = "remote-stats"; /// /// The Remote tab's Options popup, under RynthAi's own section switches: the switches of the server's /// Remote sections (saved by the plugin, which then draws or skips SectionRemoteBank / SectionRemoteGuardian). /// public const string SectionRemoteOptions = "remote-options"; /// Pets tab, under the roster: the server's pet extras (charms, refills). Draws its own leading separator. public const string SectionPetCharms = "pets-charms"; /// Pets tab, under SectionPetCharms: the server's monster capture (as SectionPetCharms). public const string SectionPetCapture = "pets-capture"; /// Pets tab, last: the server's pet logs. public const string SectionPetLogs = "pets-logs"; /// /// Mini Remote menu, under the plugin's server (TextServerId) in RynthCore's server list: the plugin's /// status (why no feature is on, its override, Refresh). The id keeps its first owner's name. /// public const string SectionServerStatus = "ilt-status"; /// Mini Remote menu without RynthCore's server list (an older RynthCore): the plugin's own menu items. public const string SectionServerMenu = "server-menu"; /// GetSubTabs parent: RynthAi's Pets tab (its first sub-tab, the roster, is RynthAi's own). public const string TabParentPets = "pets"; /// GetText id: the tail RynthAi adds to its one-line session report ("" or ", Coins 1.2k/h, Pyr 4.5m/h"). public const string TextSessionReport = "session-report"; /// GetText id: the RynthCore server id this plugin's tabs and menu entries belong to. public const string TextServerId = "server-id"; /// Feature key RynthAi reads (GetFeature): the server's /myquests (0 = off: no login refresh). public const string FeatureQuests = "quests"; /// /// GetSetting / SetSetting key: the server plugin's Vaulted Dungeons switch (0 off, 1 on), which RynthAi /// mirrors into the engine's Settings > Navigation row; -1 (no row) when the plugin doesn't offer it. /// public const string SettingVaultedDungeons = "vaulted-dungeons"; } /// One tab as GetTabs / GetSubTabs hand it out. Blittable. [StructLayout(LayoutKind.Sequential)] public unsafe struct ServerHubTabV1 { /// The tab id (UTF-8, NUL-terminated): saved as the Mini Remote's tab, "/ra hub open <id>". public fixed byte Id[24]; /// The tab bar label (UTF-8, NUL-terminated). public fixed byte Label[32]; /// The size of the tab body (the child it draws in). public float Width; public float Height; /// RynthServerHub.Tab* bits. public uint Flags; } [StructLayout(LayoutKind.Sequential)] public unsafe struct RynthServerHubApiV1 { public const string InterfaceName = "RynthServer.Hub"; public const uint InterfaceVersion = 1; /// /// The table's size up to and including Command, as the interface's first release filled it. /// Readers check StructSize against this (not sizeof, which grows as functions are appended) and /// check for the appended functions with . /// public static uint BaseStructSize => (uint)(2 * sizeof(uint) + 9 * sizeof(nint)); /// Whether a table is big enough to hold the function at . public static bool Has(RynthServerHubApiV1* t, int offset) => t != null && t->StructSize >= (uint)(offset + sizeof(nint)); /// Byte offset of the n-th function appended after the base table (0 = AllowSummonOnEmpty). private static int Appended(int n) => (int)BaseStructSize + n * sizeof(nint); /// Offset of (for ). public static int AllowSummonOnEmptyOffset => Appended(0); /// Offset of . public static int GetSubTabsOffset => Appended(1); /// Offset of . public static int GetSettingOffset => Appended(2); /// Offset of . public static int SetSettingOffset => Appended(3); /// Offset of . public static int GetTextOffset => Appended(4); public uint Version; // InterfaceVersion of the table the plugin filled; 0 once it has shut down public uint StructSize; // sizeof(RynthServerHubApiV1) as the plugin built it /// IsServerWorld(): 1 when this world is the plugin's server (or forced there). Any thread. public delegate* unmanaged[Cdecl] IsServerWorld; /// GetFeature(key): the server's bit for a feature, -1 unknown, 0 off, 1 on (-1 off its server). Any thread. public delegate* unmanaged[Cdecl] GetFeature; /// /// GetRates(first, second): two session rates of the server's (per hour); 0 (nothing written) off its /// server. Any thread. RynthAi no longer reads it (SectionRemoteStats draws them); kept for the layout. /// public delegate* unmanaged[Cdecl] GetRates; /// GetForceServer(): this character's "treat this world as the plugin's server" override (1 on). Any thread. public delegate* unmanaged[Cdecl] GetForceServer; /// SetForceServer(on): sets that override. Any thread (applied and saved on the plugin's next tick). public delegate* unmanaged[Cdecl] SetForceServer; /// /// GetTabs(tabs, capacity): every tab of the plugin's, in tab-bar order with its flags. Writes up to /// capacity, returns how many there are (tabs null: just the count). Render thread. /// public delegate* unmanaged[Cdecl] GetTabs; /// RenderTab(id): draws that tab's body into the current (child) window; 1 = drawn. Render thread. public delegate* unmanaged[Cdecl] RenderTab; /// RenderSection(id): draws a RynthServerHub.Section* (or a sub-tab's id) into the current window; 1 = drawn. Render thread. public delegate* unmanaged[Cdecl] RenderSection; /// /// Command(text): one of the plugin's "/ra" verbs, as typed after "/ra" ("hub bank", "rates reset"). /// The plugin answers in chat itself. 1 = handled, 0 = not one of its verbs. Pump thread. /// public delegate* unmanaged[Cdecl] Command; // ── Appended 2026-10-20 (check with Has before calling) ───────────────── /// /// AllowSummonOnEmpty(): 1 when a pet may be summoned from an EMPTY essence because the server /// refills it (the player opted in and the server confirmed the feature). RynthAi's PetManager /// hook asks this; 0 off the plugin's server and whenever unsure (an unknown state never spends /// pyreals). Any thread. /// public delegate* unmanaged[Cdecl] AllowSummonOnEmpty; /// /// GetSubTabs(parent, tabs, capacity): the sub-tabs the plugin adds to one of RynthAi's tabs (parent /// RynthServerHub.TabParentPets). Each tab's Id is a section id drawn with RenderSection; Width / /// Height are 0 (the parent's size). Writes up to capacity, returns how many (tabs null: the count); /// 0 off its server or for an unknown parent. Render thread. /// public delegate* unmanaged[Cdecl] GetSubTabs; /// /// GetSetting(key): one of the plugin's settings that another plugin shows (RynthServerHub.Setting*; /// RynthAi mirrors them into the engine's Settings window). The value, or -1 when the plugin has no /// such setting to offer now (unknown key, before login, off its server). Any thread. /// public delegate* unmanaged[Cdecl] GetSetting; /// SetSetting(key, value): changes that setting (saved by the plugin); 1 = taken, 0 = not ours / not now. Any thread. public delegate* unmanaged[Cdecl] SetSetting; /// /// GetText(id, buffer, capacity): a short text RynthAi shows (RynthServerHub.Text*), UTF-8, truncated to /// capacity. Returns its length; 0 for nothing (unknown id, off its server). Any thread. /// public delegate* unmanaged[Cdecl] GetText; }