RynthSuite/Plugins/RynthCore.Plugin.RynthILT/ServerInterface.cs
BlankenshipG 23efcfee87 feat(suite): ILT Server restore, progress lum/Enl, Oracle Benediction, Handler ring evade
RynthILT: restore RynthILT.Server for Oracle/Mini Remote; aug/enl planners use character AvailableLuminance.
RynthOracle: Asheron Lesser Benediction via lesserbenedictionaug; Skills tabs.
RynthAi: Empyrean Handler lethal-ring back-jump evade (face Handler then xs); pet CD already on sk.
Inventory/Sort: GInv/RSort off bar; inventory links and autostack polish.
2026-10-18 15:59:53 -04:00

81 lines
3.6 KiB
C#

// ServerInterface.cs - RynthILT's side of the "RynthILT.Server" interface (Plugins/Shared/RynthIltServerApi.cs):
// the profile JSON other plugins read (RynthOracle's Fellowship / Quests qb list / feature list):
// the Leaftide feature list with the server's state for each, and the server's fellowship rules.
//
// Restored 2026-10-16: this export was dropped when "RynthServer.Profile" (salvage / identity) was
// added, so Oracle still detected ILT via RynthCore but never received feature / qb / fellowship
// data from RynthILT. Hub + Data stay separate; this table is the feature-profile channel.
//
// The table is allocated once per loaded copy of RynthILT and never freed (a plugin DLL is never
// unloaded); after Release() it reports Version 0 and GetProfileJson answers 0. Before login there
// is no controller, so the profile is the not-ILT default (every feature unknown, retail fellowships).
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using RynthCore.Plugin.RynthILT.Hub;
using RynthCore.Plugin.Shared;
namespace RynthCore.Plugin.RynthILT;
internal static unsafe class ServerInterface
{
private static RynthIltServerApiV1* _table;
private static volatile bool _released;
/// <summary>The profile before any login: not an ILT world, nothing known (built once).</summary>
private static readonly string NotLoggedInJson =
IltFeatureCatalog.BuildProfileJson(false, string.Empty, false, string.Empty, DateTime.MinValue, _ => IltTri.Unknown);
/// <summary>The table for (<paramref name="iface"/>, <paramref name="version"/>), or 0 when it isn't ours.</summary>
public static IntPtr Query(string iface, uint version)
{
if (iface != RynthIltServerApiV1.InterfaceName || version < 1 || version > RynthIltServerApiV1.InterfaceVersion || _released)
return IntPtr.Zero;
if (_table == null)
{
var t = (RynthIltServerApiV1*)NativeMemory.AllocZeroed((nuint)sizeof(RynthIltServerApiV1));
t->StructSize = (uint)sizeof(RynthIltServerApiV1);
t->GetProfileJson = &GetProfileJson;
t->Version = RynthIltServerApiV1.InterfaceVersion;
_table = t;
}
return (IntPtr)_table;
}
/// <summary>Plugin shutdown: readers see Version 0 and re-query; GetProfileJson answers 0.</summary>
public static void Release()
{
_released = true;
if (_table != null) _table->Version = 0;
}
/// <summary>The JSON to hand out now: the live controller's snapshot, or the not-logged-in default.</summary>
internal static string CurrentJson()
=> (_released ? null : PluginExports.Runtime.Plugin?.Hub?.ProfileJson) ?? NotLoggedInJson;
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
private static int GetProfileJson(byte* buffer, int capacity)
{
try
{
if (_released) return 0;
return Write(CurrentJson(), buffer, capacity);
}
catch { return 0; }
}
/// <summary>
/// Copies <paramref name="json"/> as NUL-terminated UTF-8 into the caller's buffer when it fits,
/// and returns its byte length either way (length >= capacity: too small, nothing written).
/// </summary>
internal static int Write(string json, byte* buffer, int capacity)
{
int length = Encoding.UTF8.GetByteCount(json);
if (buffer == null || capacity <= length) return length;
fixed (char* src = json)
Encoding.UTF8.GetBytes(src, json.Length, buffer, capacity);
buffer[length] = 0;
return length;
}
}