Snapshot for release 2026.10.13.2 (internal 6cd69e2)
This commit is contained in:
parent
319740ff5d
commit
56b9f6c813
94 changed files with 5793 additions and 1637 deletions
329
Plugins/Shared/DataWriteGuard.cs
Normal file
329
Plugins/Shared/DataWriteGuard.cs
Normal file
|
|
@ -0,0 +1,329 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace RynthCore.Plugin.Shared;
|
||||
|
||||
/// <summary>Why a write in a plugin's data folders failed (see <see cref="DataWriteGuard.Classify"/>).</summary>
|
||||
internal enum WriteFailureKind
|
||||
{
|
||||
/// <summary>Windows refused: the folder or file isn't writable for this account, or Controlled folder access blocked acclient.exe.</summary>
|
||||
AccessDenied,
|
||||
/// <summary>The file carries the ReadOnly attribute and it couldn't be cleared.</summary>
|
||||
ReadOnlyFile,
|
||||
/// <summary>Another program holds the file open (editor, sync client, antivirus).</summary>
|
||||
InUse,
|
||||
DiskFull,
|
||||
/// <summary>A OneDrive (cloud files) placeholder whose sync provider isn't running.</summary>
|
||||
CloudProvider,
|
||||
/// <summary>The folder doesn't exist and couldn't be created.</summary>
|
||||
PathMissing,
|
||||
Other,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves of metas, navs, loot profiles and settings profiles (2026-10-13; RynthAi, and RynthILT for
|
||||
/// its own files and the copies it migrates from RynthAi; linked into each, so each plugin keeps
|
||||
/// its own state and says its own name: <see cref="PluginName"/>). Players reported
|
||||
/// that metas and navs "don't save" and that "the plugin folders are read only": every one of
|
||||
/// those saves swallowed its exception, so a folder the client can't write looked like a save
|
||||
/// that silently did nothing. Now:
|
||||
/// - <see cref="PrepareOverwrite"/> clears the ReadOnly attribute on our own file before it
|
||||
/// is overwritten (works whenever the folder itself is writable);
|
||||
/// - <see cref="Report"/> says in chat, once per folder per session, what couldn't be saved,
|
||||
/// where and why (access denied / read-only file / file in use / ...), with the fix (the
|
||||
/// launcher's Recovery Actions > Fix folder permissions). Every failure is logged
|
||||
/// (throttled per folder so a failing autosave can't flood the log);
|
||||
/// - <see cref="CheckFolders"/> is the startup self-check: it tries to create a file in
|
||||
/// each data folder.
|
||||
/// Chat lines are queued here and posted by the plugin tick once the character is in game
|
||||
/// (<see cref="DrainChat"/>), so a failure on any thread, or before login, still shows.
|
||||
/// </summary>
|
||||
internal static class DataWriteGuard
|
||||
{
|
||||
public const string FixHint =
|
||||
"Fix: in the RynthCore launcher, Recovery Actions > Fix folder permissions (one administrator prompt).";
|
||||
|
||||
/// <summary>A failing folder logs at most once per this many ms (plus a count of the skipped ones).</summary>
|
||||
public const long LogThrottleMs = 60_000;
|
||||
|
||||
private static readonly object Gate = new();
|
||||
private static readonly HashSet<string> ReportedFolders = new(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly Dictionary<string, (long At, int Skipped)> LastLog = new(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly Queue<string> PendingChat = new();
|
||||
|
||||
/// <summary>The plugin's name in chat and log lines ("[RynthAi] ..."); Initialize sets it.</summary>
|
||||
public static string PluginName = "RynthAi";
|
||||
|
||||
/// <summary>What the startup self-check says won't be kept when a folder can't be written.</summary>
|
||||
public static string DataDescription = "Metas, navs, loot and settings";
|
||||
|
||||
/// <summary>The plugin's log (Initialize sets it). Null: nothing is logged.</summary>
|
||||
public static Action<string>? LogSink;
|
||||
|
||||
/// <summary>Milliseconds clock; tests replace it.</summary>
|
||||
internal static Func<long> Clock = () => Environment.TickCount64;
|
||||
|
||||
/// <summary>Forgets what was reported (a new session; tests).</summary>
|
||||
public static void Reset()
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
ReportedFolders.Clear();
|
||||
LastLog.Clear();
|
||||
PendingChat.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Chat lines waiting to be posted.</summary>
|
||||
public static int PendingCount { get { lock (Gate) return PendingChat.Count; } }
|
||||
|
||||
/// <summary>Posts the queued chat lines (plugin tick, in game).</summary>
|
||||
public static void DrainChat(Action<string> chat)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
string line;
|
||||
lock (Gate)
|
||||
{
|
||||
if (PendingChat.Count == 0) return;
|
||||
line = PendingChat.Dequeue();
|
||||
}
|
||||
try { chat(line); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the ReadOnly attribute of an existing file we are about to overwrite. Returns
|
||||
/// true when it was set and is now cleared. Never throws: when the folder isn't writable
|
||||
/// either, the write that follows fails and is reported.
|
||||
/// </summary>
|
||||
public static bool PrepareOverwrite(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || !File.Exists(path)) return false;
|
||||
FileAttributes a = File.GetAttributes(path);
|
||||
if ((a & FileAttributes.ReadOnly) == 0) return false;
|
||||
File.SetAttributes(path, a & ~FileAttributes.ReadOnly);
|
||||
Log($"[{PluginName}] {path} was marked read-only; cleared that so it can be saved.");
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs <paramref name="write"/> for <paramref name="path"/> (ReadOnly cleared first).
|
||||
/// False when it threw; the failure is then reported (<see cref="Report"/>).
|
||||
/// </summary>
|
||||
public static bool TrySave(string what, string path, Action write) => TrySave(what, path, write, out _);
|
||||
|
||||
/// <inheritdoc cref="TrySave(string, string, Action)"/>
|
||||
/// <param name="reason">When it failed, the reason and the fix in plain words ("access denied (...). Fix: ..."), else empty.</param>
|
||||
/// <param name="callerShows">The caller puts the failure in chat itself (an explicit save the
|
||||
/// player asked for): nothing is queued, the folder still counts as reported.</param>
|
||||
public static bool TrySave(string what, string path, Action write, out string reason, bool callerShows = false)
|
||||
{
|
||||
reason = string.Empty;
|
||||
try
|
||||
{
|
||||
PrepareOverwrite(path);
|
||||
write();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
reason = Report(what, path, ex, callerShows);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ERROR_* as HRESULTs (0x8007xxxx).
|
||||
private const int HrAccessDenied = unchecked((int)0x80070005);
|
||||
private const int HrWriteProtect = unchecked((int)0x80070013);
|
||||
private const int HrSharingViolation = unchecked((int)0x80070020);
|
||||
private const int HrLockViolation = unchecked((int)0x80070021);
|
||||
private const int HrHandleDiskFull = unchecked((int)0x80070027);
|
||||
private const int HrDiskFull = unchecked((int)0x80070070);
|
||||
private const int HrCloudProviderNotRunning = unchecked((int)0x8007016A);
|
||||
private const int HrCloudNotInSync = unchecked((int)0x80070185);
|
||||
private const int HrUserMappedFile = unchecked((int)0x800704C8);
|
||||
|
||||
/// <summary>What kind of failure <paramref name="ex"/> is, for a write of <paramref name="path"/>.</summary>
|
||||
public static WriteFailureKind Classify(Exception ex, string? path)
|
||||
{
|
||||
switch (ex)
|
||||
{
|
||||
case UnauthorizedAccessException:
|
||||
return IsReadOnlyFile(path) ? WriteFailureKind.ReadOnlyFile : WriteFailureKind.AccessDenied;
|
||||
case DirectoryNotFoundException:
|
||||
return WriteFailureKind.PathMissing;
|
||||
case IOException io:
|
||||
switch (io.HResult)
|
||||
{
|
||||
case HrSharingViolation:
|
||||
case HrLockViolation:
|
||||
case HrUserMappedFile:
|
||||
return WriteFailureKind.InUse;
|
||||
case HrDiskFull:
|
||||
case HrHandleDiskFull:
|
||||
return WriteFailureKind.DiskFull;
|
||||
case HrCloudProviderNotRunning:
|
||||
case HrCloudNotInSync:
|
||||
return WriteFailureKind.CloudProvider;
|
||||
case HrAccessDenied:
|
||||
case HrWriteProtect:
|
||||
return IsReadOnlyFile(path) ? WriteFailureKind.ReadOnlyFile : WriteFailureKind.AccessDenied;
|
||||
}
|
||||
return WriteFailureKind.Other;
|
||||
default:
|
||||
return WriteFailureKind.Other;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsReadOnlyFile(string? path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return !string.IsNullOrEmpty(path) && File.Exists(path)
|
||||
&& (File.GetAttributes(path) & FileAttributes.ReadOnly) != 0;
|
||||
}
|
||||
catch { return false; }
|
||||
}
|
||||
|
||||
/// <summary>The reason in plain words.</summary>
|
||||
public static string Describe(WriteFailureKind kind, Exception? ex) => kind switch
|
||||
{
|
||||
WriteFailureKind.AccessDenied =>
|
||||
"access denied (Windows doesn't let this game client write there: the folder's permissions, " +
|
||||
"or Windows Security's Controlled folder access blocking acclient.exe)",
|
||||
WriteFailureKind.ReadOnlyFile => $"the file is marked read-only and {PluginName} couldn't clear that",
|
||||
WriteFailureKind.InUse => "the file is open in another program (an editor, OneDrive or backup sync, antivirus)",
|
||||
WriteFailureKind.DiskFull => "the disk is full",
|
||||
WriteFailureKind.CloudProvider => "the folder is synced by OneDrive (or another cloud app) that isn't running",
|
||||
WriteFailureKind.PathMissing => "the folder doesn't exist and couldn't be created",
|
||||
_ => ex?.Message ?? "unknown error",
|
||||
};
|
||||
|
||||
/// <summary>What the player can do about it.</summary>
|
||||
public static string Hint(WriteFailureKind kind) => kind switch
|
||||
{
|
||||
WriteFailureKind.AccessDenied or WriteFailureKind.ReadOnlyFile or WriteFailureKind.PathMissing => FixHint,
|
||||
WriteFailureKind.InUse => "Close the program that has it open and save again.",
|
||||
WriteFailureKind.DiskFull => "Free some disk space and save again.",
|
||||
WriteFailureKind.CloudProvider => "Start OneDrive, or install RynthSuite outside the synced folder.",
|
||||
_ => FixHint,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A failed save of <paramref name="what"/> ("the meta", "the nav", ...) to
|
||||
/// <paramref name="path"/>: logged (throttled per folder) and, the first time for that
|
||||
/// folder this session, queued for chat. Returns the reason and the fix in plain words.
|
||||
/// </summary>
|
||||
public static string Report(string what, string path, Exception ex, bool callerShows = false)
|
||||
{
|
||||
WriteFailureKind kind = Classify(ex, path);
|
||||
string reason = Describe(kind, ex);
|
||||
string folder = FolderOf(path);
|
||||
bool chat;
|
||||
string? logLine = null;
|
||||
lock (Gate)
|
||||
{
|
||||
chat = !AlreadyReported(folder);
|
||||
ReportedFolders.Add(folder);
|
||||
long now = Clock();
|
||||
if (!LastLog.TryGetValue(folder, out var last) || now - last.At >= LogThrottleMs || chat)
|
||||
{
|
||||
string skipped = last.Skipped > 0 ? $" ({last.Skipped} more failure(s) in this folder since the last line)" : "";
|
||||
logLine = $"[{PluginName}] Save failed: {what} -> {path}: {reason} [{ex.GetType().Name}: {ex.Message}]{skipped}";
|
||||
LastLog[folder] = (now, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LastLog[folder] = (last.At, last.Skipped + 1);
|
||||
}
|
||||
if (chat && !callerShows)
|
||||
PendingChat.Enqueue($"[{PluginName}] Couldn't save {what} to {path}: {reason}. {Hint(kind)} " +
|
||||
"(Shown once per folder; later failures there go to the log.)");
|
||||
}
|
||||
if (logLine != null) Log(logLine);
|
||||
return $"{reason}. {Hint(kind)}";
|
||||
}
|
||||
|
||||
/// <summary>One data folder the self-check couldn't write.</summary>
|
||||
internal readonly record struct FolderProblem(string Folder, WriteFailureKind Kind, string Reason);
|
||||
|
||||
/// <summary>
|
||||
/// The startup self-check: creates (if missing) and writes a throw-away file in each of
|
||||
/// <paramref name="folders"/>. Returns the folders that failed; for those, one line goes
|
||||
/// to the log and one summary line is queued for chat.
|
||||
/// </summary>
|
||||
public static List<FolderProblem> CheckFolders(IEnumerable<string> folders)
|
||||
{
|
||||
var problems = new List<FolderProblem>();
|
||||
foreach (string folder in folders)
|
||||
{
|
||||
if (string.IsNullOrEmpty(folder)) continue;
|
||||
string probe = Path.Combine(folder, $".{PluginName.ToLowerInvariant()}-write-check-{Environment.ProcessId}-{Guid.NewGuid():N}.tmp");
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
using (var fs = new FileStream(probe, FileMode.CreateNew, FileAccess.Write, FileShare.None, 1, FileOptions.DeleteOnClose))
|
||||
fs.WriteByte(0);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteFailureKind kind = Classify(ex, null);
|
||||
problems.Add(new FolderProblem(folder, kind, Describe(kind, ex)));
|
||||
Log($"[{PluginName}] Data folder not writable: {folder}: {Describe(kind, ex)} [{ex.GetType().Name}: {ex.Message}]");
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { if (File.Exists(probe)) File.Delete(probe); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
if (problems.Count > 0)
|
||||
{
|
||||
lock (Gate)
|
||||
{
|
||||
foreach (var p in problems) ReportedFolders.Add(p.Folder); // the save itself needn't repeat it
|
||||
string list = problems.Count == 1
|
||||
? problems[0].Folder
|
||||
: $"{problems.Count} folders ({string.Join(", ", problems.ConvertAll(p => Path.GetFileName(p.Folder)))})";
|
||||
PendingChat.Enqueue($"[{PluginName}] Can't write to {list}: {problems[0].Reason}. {DataDescription} " +
|
||||
$"saved there will NOT be kept. {Hint(problems[0].Kind)}");
|
||||
}
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
|
||||
/// <summary>This folder, or one it is inside (e.g. SettingsProfiles for a character's folder), was reported. Under Gate.</summary>
|
||||
private static bool AlreadyReported(string folder)
|
||||
{
|
||||
foreach (string f in ReportedFolders)
|
||||
if (folder.Equals(f, StringComparison.OrdinalIgnoreCase)
|
||||
|| folder.StartsWith(f + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>The folder a failure is counted against.</summary>
|
||||
internal static string FolderOf(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
string? dir = Path.GetDirectoryName(path);
|
||||
return string.IsNullOrEmpty(dir) ? path : dir.TrimEnd('\\', '/');
|
||||
}
|
||||
catch { return path; }
|
||||
}
|
||||
|
||||
private static void Log(string line)
|
||||
{
|
||||
try { LogSink?.Invoke(line); } catch { }
|
||||
}
|
||||
}
|
||||
80
Plugins/Shared/ImGuiNativeBinding.cs
Normal file
80
Plugins/Shared/ImGuiNativeBinding.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
// ImGuiNativeBinding.cs - Binds ImGui.NET's "cimgui" P/Invokes to the cimgui module the
|
||||
// engine already loaded. Linked into every plugin that draws with ImGui.NET (RynthAi, RynthILT).
|
||||
//
|
||||
// The engine ships its own build as RynthCore.cimgui.dll. Without this resolver, Windows
|
||||
// resolves "cimgui" to a separate cimgui.dll: a second ImGui instance whose windows (the Mini
|
||||
// Remote, its tabs, the Item HUD) are built but never reach the engine's draw data. Both
|
||||
// plugins bound to the one module share its current context, so one can draw inside a window
|
||||
// the other has begun (RynthILT's tabs inside RynthAi's Mini Remote).
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using ImGuiNET;
|
||||
|
||||
namespace RynthCore.Plugin.Shared;
|
||||
|
||||
internal static class ImGuiNativeBinding
|
||||
{
|
||||
private const string EngineModule = "RynthCore.cimgui.dll";
|
||||
private const string LegacyModule = "cimgui.dll";
|
||||
|
||||
private static int _configured; // 1 once the resolver is registered (survives DLL-copy reuse)
|
||||
private static int _resolvedLogged;
|
||||
private static Action<string>? _log;
|
||||
|
||||
/// <summary>
|
||||
/// Registers the resolver. Call before the first ImGui call (Initialize). The resolver can be
|
||||
/// set only once per assembly, so later calls (a reused plugin DLL copy) are no-ops.
|
||||
/// <paramref name="log"/> gets one line when the resolver is registered and one when it binds.
|
||||
/// </summary>
|
||||
public static void Ensure(Action<string>? log = null)
|
||||
{
|
||||
if (log != null) _log = log;
|
||||
if (Interlocked.Exchange(ref _configured, 1) != 0) return;
|
||||
try
|
||||
{
|
||||
NativeLibrary.SetDllImportResolver(typeof(ImGui).Assembly, Resolve);
|
||||
Log("[ImGui] native resolver registered (prefers the engine's " + EngineModule + ").");
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// Already registered by an earlier instance in this process.
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log($"[ImGui] ImGuiNativeBinding.Ensure failed: {ex.GetType().Name}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void Log(string message)
|
||||
{
|
||||
try { _log?.Invoke(message); }
|
||||
catch { }
|
||||
}
|
||||
|
||||
/// <summary>Runs on the first cimgui P/Invoke: the engine's module, else whatever cimgui.dll is loaded.</summary>
|
||||
private static IntPtr Resolve(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
|
||||
{
|
||||
if (!string.Equals(libraryName, "cimgui", StringComparison.OrdinalIgnoreCase) &&
|
||||
!string.Equals(libraryName, LegacyModule, StringComparison.OrdinalIgnoreCase))
|
||||
return IntPtr.Zero;
|
||||
|
||||
string bound = EngineModule;
|
||||
IntPtr module = GetModuleHandleA(EngineModule);
|
||||
if (module == IntPtr.Zero)
|
||||
{
|
||||
bound = LegacyModule;
|
||||
module = GetModuleHandleA(LegacyModule);
|
||||
}
|
||||
|
||||
if (Interlocked.Exchange(ref _resolvedLogged, 1) == 0)
|
||||
Log(module != IntPtr.Zero
|
||||
? $"[ImGui] cimgui bound to loaded {bound} (0x{module.ToInt64():X})."
|
||||
: "[ImGui] no loaded cimgui module found; falling back to the default DLL search.");
|
||||
return module; // IntPtr.Zero = default resolution
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
|
||||
private static extern IntPtr GetModuleHandleA(string lpModuleName);
|
||||
}
|
||||
128
Plugins/Shared/RynthAiHubApi.cs
Normal file
128
Plugins/Shared/RynthAiHubApi.cs
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
// ============================================================================
|
||||
// RynthSuite - Plugins/Shared/RynthAiHubApi.cs
|
||||
// The "RynthAi.Hub" interface: what RynthILT (the Infinite Leaftide features)
|
||||
// borrows from RynthAi. The Mini Remote that hosts the ILT tabs, the /myquests
|
||||
// tracker (the Temple attribute tracker reads its flags), spell names (the dispel
|
||||
// keeper), VTank loot-profile matching (equipment suits) and the VTank .usd
|
||||
// importer (which edits RynthAi's own rules; drawn in RynthILT's Gear tab), and the
|
||||
// Mini Remote's session stats (the Character tab's rates count the same session).
|
||||
// Compiled into both plugins (linked source), so the layout can't drift.
|
||||
//
|
||||
// Rules: as RynthILT.Hub (Shared/RynthIltHubApi.cs): append-only, UTF-8 strings,
|
||||
// each function says its thread, no exception crosses, the table lives as long as
|
||||
// the RynthAi copy (never freed; Version 0 after Shutdown), callers re-query.
|
||||
// RynthILT works without RynthAi: every feature that needs it says so.
|
||||
// ============================================================================
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RynthCore.Plugin.Shared;
|
||||
|
||||
/// <summary>Constants of the "RynthAi.Hub" interface.</summary>
|
||||
public static class RynthAiHub
|
||||
{
|
||||
/// <summary>The providing plugin's display name.</summary>
|
||||
public const string PluginName = "RynthAi";
|
||||
|
||||
/// <summary>RenderSection: the VTank .usd settings importer (RynthAi's monster / weapon / consumable rules).</summary>
|
||||
public const string SectionVTankImport = "vtank-import";
|
||||
}
|
||||
|
||||
/// <summary>One /myquests flag as RynthAi's quest tracker has it. Blittable.</summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct QuestFlagV1
|
||||
{
|
||||
public int Solves;
|
||||
/// <summary>-1 unlimited (as the server prints it).</summary>
|
||||
public int MaxSolves;
|
||||
/// <summary>Last completion, UTC ticks (DateTime.Ticks); 0 = never / unknown.</summary>
|
||||
public long CompletedOnUtcTicks;
|
||||
/// <summary>Repeat time in seconds (0 = none).</summary>
|
||||
public long RepeatSeconds;
|
||||
}
|
||||
|
||||
/// <summary>The quest tracker's state. Blittable.</summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct QuestStatusV1
|
||||
{
|
||||
/// <summary>1 when the server said /myquests is disabled.</summary>
|
||||
public int Disabled;
|
||||
/// <summary>Flags cached.</summary>
|
||||
public int Count;
|
||||
/// <summary>Bumped each time a refresh ends (0 = none yet this session).</summary>
|
||||
public int Generation;
|
||||
/// <summary>1 while a refresh is running.</summary>
|
||||
public int Refreshing;
|
||||
}
|
||||
|
||||
/// <summary>The Mini Remote's session stats (RynthTracker's SessionStats code). Blittable.</summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct SessionStatsV1
|
||||
{
|
||||
/// <summary>Session start, UTC ticks (DateTime.Ticks); 0 = no session yet.</summary>
|
||||
public long StartUtcTicks;
|
||||
public double SessionSeconds;
|
||||
public long Xp;
|
||||
public double XpPerHour;
|
||||
public long Lum;
|
||||
public double LumPerHour;
|
||||
public long LumLast5Min;
|
||||
/// <summary>1 when the pass-up figures below are tracked.</summary>
|
||||
public int PassUpTracked;
|
||||
public long LumPassUp;
|
||||
public double PassUpPerHour;
|
||||
public long Kills;
|
||||
public double KillsPerHour;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct RynthAiHubApiV1
|
||||
{
|
||||
public const string InterfaceName = "RynthAi.Hub";
|
||||
public const uint InterfaceVersion = 1;
|
||||
|
||||
public uint Version; // InterfaceVersion of the table RynthAi filled; 0 once it has shut down
|
||||
public uint StructSize; // sizeof(RynthAiHubApiV1) as RynthAi built it
|
||||
|
||||
/// <summary>
|
||||
/// MiniRemoteTab(tabId, mode, reply, replyCapacity): puts the Mini Remote on a tab (tabId "" =
|
||||
/// its Remote tab; mode "show" / "hide" / "toggle", or "select" to switch tabs without showing
|
||||
/// it). Writes the chat-ready reply (UTF-8, truncated to capacity). 1 = done, 0 = no Mini Remote
|
||||
/// yet (before login). Any thread.
|
||||
/// </summary>
|
||||
public delegate* unmanaged[Cdecl]<byte*, byte*, byte*, int, int> MiniRemoteTab;
|
||||
|
||||
/// <summary>MiniRemoteVisible(): 1 while the Mini Remote is on screen. Any thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<int> MiniRemoteVisible;
|
||||
|
||||
/// <summary>QuestFlag(key, flag): 1 and the flag filled when /myquests has it (case-insensitive key). Pump thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<byte*, QuestFlagV1*, int> QuestFlag;
|
||||
|
||||
/// <summary>QuestStatus(status): fills the tracker state; 0 when there is no tracker (before login). Pump thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<QuestStatusV1*, int> QuestStatus;
|
||||
|
||||
/// <summary>
|
||||
/// QuestRefresh(reply, replyCapacity): a quiet /myquests refresh, with the Quests tab's one-a-minute
|
||||
/// cooldown. Writes what happened ("Refreshing quests...", "Wait 40s ..."). 1 = sent. Pump thread.
|
||||
/// </summary>
|
||||
public delegate* unmanaged[Cdecl]<byte*, int, int> QuestRefresh;
|
||||
|
||||
/// <summary>SpellName(spellId, buffer, capacity): the spell's name from RynthAi's spell table; its length, 0 unknown. Any thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<uint, byte*, int, int> SpellName;
|
||||
|
||||
/// <summary>
|
||||
/// LootKeeps(utlPath, ids, count, keep, error, errorCapacity): evaluates the VTank loot profile at
|
||||
/// utlPath (.utl) against each object id; keep[i] = 1 when that item's first matching rule is Keep.
|
||||
/// 1 = evaluated; 0 = the profile couldn't be read (error says why). Pump thread.
|
||||
/// </summary>
|
||||
public delegate* unmanaged[Cdecl]<byte*, uint*, int, byte*, byte*, int, int> LootKeeps;
|
||||
|
||||
/// <summary>RenderSection(id): draws a RynthAiHub.Section* into the current window; 1 = drawn. Render thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<byte*, int> RenderSection;
|
||||
|
||||
/// <summary>SessionStats(stats): the Mini Remote's session (XP, luminance, kills); 0 before login. Any thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<SessionStatsV1*, int> SessionStats;
|
||||
|
||||
/// <summary>SessionReset(): starts the Mini Remote's session over (as its Reset XP button). Any thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<void> SessionReset;
|
||||
}
|
||||
118
Plugins/Shared/RynthIltHubApi.cs
Normal file
118
Plugins/Shared/RynthIltHubApi.cs
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
// ============================================================================
|
||||
// RynthSuite - Plugins/Shared/RynthIltHubApi.cs
|
||||
// The "RynthILT.Hub" interface: RynthILT's Infinite Leaftide features as RynthAi's
|
||||
// Mini Remote shows them. The Mini Remote stays RynthAi's (its window, tab bar,
|
||||
// Remote tab, Quests and Pets tabs); RynthILT supplies the ILT tabs (Character,
|
||||
// Banking, Gear, Charms, Games), a few ILT sections drawn inside RynthAi's
|
||||
// surfaces, the server's ILT feature bits and the "/ra hub ..." ILT verbs.
|
||||
// Compiled into both plugins (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 RynthILT has shut down.
|
||||
// - The table is allocated once per loaded copy of RynthILT 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;
|
||||
|
||||
/// <summary>Constants of the "RynthILT.Hub" interface.</summary>
|
||||
public static class RynthIltHub
|
||||
{
|
||||
/// <summary>The providing plugin's display name.</summary>
|
||||
public const string PluginName = "RynthILT";
|
||||
|
||||
/// <summary>Tab flag: the Mini Remote shows this tab now (an ILT world, or forced, and the tab is usable).</summary>
|
||||
public const uint TabShown = 1;
|
||||
/// <summary>Tab flag: the server reports the tab's feature on (Character is always available).</summary>
|
||||
public const uint TabAvailable = 2;
|
||||
|
||||
// Sections RynthAi draws through RenderSection (each draws nothing off ILT).
|
||||
/// <summary>Remote tab, Bank section: the ILT bank balances.</summary>
|
||||
public const string SectionRemoteBank = "remote-bank";
|
||||
/// <summary>Remote tab, Guardian line: the Temple guardian's last answer.</summary>
|
||||
public const string SectionRemoteGuardian = "remote-guardian";
|
||||
/// <summary>Quests tab: the "Quest bonus (/qb)" list.</summary>
|
||||
public const string SectionQuestBonus = "quests-qb";
|
||||
/// <summary>Pets tab: the /pets and /shinies logs.</summary>
|
||||
public const string SectionPetLogs = "pets-logs";
|
||||
/// <summary>Mini Remote menu, under Infinite Leaftide: why no ILT feature is on, the Force-ILT override, Refresh.</summary>
|
||||
public const string SectionIltStatus = "ilt-status";
|
||||
/// <summary>Mini Remote menu without RynthCore's server list: RynthILT's own Infinite Leaftide items.</summary>
|
||||
public const string SectionServerMenu = "server-menu";
|
||||
|
||||
/// <summary>Feature keys RynthAi reads (GetFeature).</summary>
|
||||
public const string FeatureQuests = "quests";
|
||||
public const string FeaturePetRefill = "pet_refill";
|
||||
public const string FeatureUniversalMastery = "universal_mastery";
|
||||
public const string FeatureRequireComps = "require_spell_comps";
|
||||
}
|
||||
|
||||
/// <summary>One ILT tab as GetTabs hands it out. Blittable.</summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct IltTabV1
|
||||
{
|
||||
/// <summary>The tab id (UTF-8, NUL-terminated): saved as the Mini Remote's tab, "/ra hub open <id>".</summary>
|
||||
public fixed byte Id[24];
|
||||
/// <summary>The tab bar label (UTF-8, NUL-terminated).</summary>
|
||||
public fixed byte Label[32];
|
||||
/// <summary>The size of the tab body (the child it draws in).</summary>
|
||||
public float Width;
|
||||
public float Height;
|
||||
/// <summary>RynthIltHub.Tab* bits.</summary>
|
||||
public uint Flags;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct RynthIltHubApiV1
|
||||
{
|
||||
public const string InterfaceName = "RynthILT.Hub";
|
||||
public const uint InterfaceVersion = 1;
|
||||
|
||||
public uint Version; // InterfaceVersion of the table RynthILT filled; 0 once it has shut down
|
||||
public uint StructSize; // sizeof(RynthIltHubApiV1) as RynthILT built it
|
||||
|
||||
/// <summary>IsIltWorld(): 1 when this world is Infinite Leaftide / ACECustom (or forced). Any thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<int> IsIltWorld;
|
||||
|
||||
/// <summary>GetFeature(key): the server's bit for a feature, -1 unknown, 0 off, 1 on (-1 off ILT). Any thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<byte*, int> GetFeature;
|
||||
|
||||
/// <summary>GetRates(coinsPerHour, pyrealsPerHour): ILT session rates; 0 (nothing written) off ILT. Any thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<double*, double*, int> GetRates;
|
||||
|
||||
/// <summary>GetForceIlt(): this character's "Treat this world as ILT" override (1 on). Any thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<int> GetForceIlt;
|
||||
|
||||
/// <summary>SetForceIlt(on): sets that override. Any thread (applied and saved on RynthILT's next tick).</summary>
|
||||
public delegate* unmanaged[Cdecl]<int, void> SetForceIlt;
|
||||
|
||||
/// <summary>
|
||||
/// GetTabs(tabs, capacity): every ILT tab in tab-bar order with its flags. Writes up to
|
||||
/// capacity, returns how many there are (tabs null: just the count). Render thread.
|
||||
/// </summary>
|
||||
public delegate* unmanaged[Cdecl]<IltTabV1*, int, int> GetTabs;
|
||||
|
||||
/// <summary>RenderTab(id): draws that tab's body into the current (child) window; 1 = drawn. Render thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<byte*, int> RenderTab;
|
||||
|
||||
/// <summary>RenderSection(id): draws a RynthIltHub.Section* into the current window; 1 = drawn. Render thread.</summary>
|
||||
public delegate* unmanaged[Cdecl]<byte*, int> RenderSection;
|
||||
|
||||
/// <summary>
|
||||
/// Command(text): one of the ILT "/ra" verbs, as typed after "/ra" ("hub bank", "hub attr run",
|
||||
/// "guardian handin", "bounty show", "rates reset"). RynthILT answers in chat itself.
|
||||
/// 1 = handled, 0 = not an ILT verb. Pump thread.
|
||||
/// </summary>
|
||||
public delegate* unmanaged[Cdecl]<byte*, int> Command;
|
||||
}
|
||||
Loading…
Reference in a new issue