Snapshot for release 2026.10.6.1 (internal 1cbe514)
This commit is contained in:
parent
913a2a00b6
commit
abf9146a5b
93 changed files with 10168 additions and 597 deletions
|
|
@ -34,6 +34,7 @@ internal static class EngineSettings
|
|||
// "DisabledUiHooks": the UI hooks (Compatibility/UiHookRegistry) switched off by name.
|
||||
private static readonly HashSet<string> _disabledUiHooks = new(StringComparer.OrdinalIgnoreCase);
|
||||
private static bool _serverMessageStream = true;
|
||||
private static bool _flightRecorder = true;
|
||||
private static bool _loaded;
|
||||
|
||||
public static IReadOnlyList<string> PluginPaths
|
||||
|
|
@ -288,6 +289,19 @@ internal static class EngineSettings
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>"FlightRecorder" in engine.json (default true): the always-on flight recorder
|
||||
/// (Net/FlightRecorder.cs, /rc flightdump): a sendto hook plus a ring of the last minutes of
|
||||
/// client/server traffic and engine markers. false = no sendto hook and nothing recorded,
|
||||
/// from the next client start.</summary>
|
||||
public static bool FlightRecorder
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureLoaded();
|
||||
return _flightRecorder;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddPluginPath(string path)
|
||||
{
|
||||
EnsureLoaded();
|
||||
|
|
@ -414,6 +428,10 @@ internal static class EngineSettings
|
|||
(smsEl.ValueKind == JsonValueKind.True || smsEl.ValueKind == JsonValueKind.False))
|
||||
_serverMessageStream = smsEl.GetBoolean();
|
||||
|
||||
if (doc.RootElement.TryGetProperty("FlightRecorder", out var frEl) &&
|
||||
(frEl.ValueKind == JsonValueKind.True || frEl.ValueKind == JsonValueKind.False))
|
||||
_flightRecorder = frEl.GetBoolean();
|
||||
|
||||
if (doc.RootElement.TryGetProperty("PreventIdleLogoff", out var pilEl) &&
|
||||
(pilEl.ValueKind == JsonValueKind.True || pilEl.ValueKind == JsonValueKind.False))
|
||||
{
|
||||
|
|
@ -436,6 +454,19 @@ internal static class EngineSettings
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Every engine.json key EnsureLoaded reads or Save writes. Save rewrites these from
|
||||
/// memory (one written only when not the default is left out, as before) and keeps every
|
||||
/// other key as the file had it. A new engine.json setting goes here too
|
||||
/// (tools/EngineSettingsTests checks this list against this file).</summary>
|
||||
internal static readonly HashSet<string> OwnedKeys = new(StringComparer.Ordinal)
|
||||
{
|
||||
"PluginPaths", "EnableImGuiShell", "EnablePlugins", "EnableDatShareHook",
|
||||
"EnableAvaloniaOverlay", "EnableD3D9Hook", "EnableEngine", "EngineHookCount",
|
||||
"EnableImGuiBackend", "EnableHangMinidump", "PreventIdleLogoff", "DecalBridge",
|
||||
"DecalInGameImGui", "DecalStandDown", "DisabledUiHooks", "ServerMessageStream",
|
||||
"FlightRecorder",
|
||||
};
|
||||
|
||||
private static void Save()
|
||||
{
|
||||
try
|
||||
|
|
@ -476,9 +507,20 @@ internal static class EngineSettings
|
|||
}
|
||||
if (!_serverMessageStream) // default true: leave the file as it was
|
||||
w.WriteBoolean("ServerMessageStream", false);
|
||||
if (!_flightRecorder) // default true: leave the file as it was
|
||||
w.WriteBoolean("FlightRecorder", false);
|
||||
w.WriteEndObject();
|
||||
}
|
||||
File.WriteAllBytes(SettingsPath, ms.ToArray());
|
||||
|
||||
// Keep the keys others write (the launcher's), and swap the file in atomically.
|
||||
string? existing = File.Exists(SettingsPath) ? File.ReadAllText(SettingsPath) : null;
|
||||
byte[]? merged = EngineSettingsFile.Merge(existing, ms.ToArray(), OwnedKeys, out string? readError);
|
||||
if (merged == null)
|
||||
{
|
||||
RynthLog.Warn($"EngineSettings: not saving - {SettingsPath} can't be read ({readError}), and rewriting it would lose what it holds. The change holds until the client closes; fix or delete the file to save again.");
|
||||
return;
|
||||
}
|
||||
EngineSettingsFile.WriteAtomic(SettingsPath, merged);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
119
src/RynthCore.Engine/Plugins/EngineSettingsFile.cs
Normal file
119
src/RynthCore.Engine/Plugins/EngineSettingsFile.cs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
||||
namespace RynthCore.Engine.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// File side of <see cref="EngineSettings"/>'s save: engine.json is shared (the launcher writes its
|
||||
/// own keys there, e.g. EnableDcompOverlay), so a save keeps every top-level key the engine doesn't
|
||||
/// own exactly as it was, and swaps the file in atomically (temp file, then replace) so a crash
|
||||
/// mid-save can't leave a truncated engine.json. No logging and no engine state: the
|
||||
/// EngineSettingsTests tool compiles this file in.
|
||||
/// Idea from Silentkelpie (rynth PR #1, CopyUnownedFields); re-implemented here.
|
||||
/// </summary>
|
||||
internal static class EngineSettingsFile
|
||||
{
|
||||
/// <summary>
|
||||
/// The new engine.json: <paramref name="ownedJson"/> (a JSON object holding the keys the
|
||||
/// engine writes, in its order), then every top-level key of <paramref name="existingJson"/>
|
||||
/// that is neither in <paramref name="ownedKeys"/> nor written by the engine, value untouched.
|
||||
/// A key in <paramref name="ownedKeys"/> that the engine didn't write this time (one it only
|
||||
/// writes when not the default) is left out, as before. A missing or empty existing file has
|
||||
/// nothing to keep. Returns null, with <paramref name="error"/> set, when the existing file
|
||||
/// isn't a readable JSON object: overwriting it would lose whatever it holds.
|
||||
/// </summary>
|
||||
public static byte[]? Merge(string? existingJson, byte[] ownedJson, ICollection<string> ownedKeys, out string? error)
|
||||
{
|
||||
error = null;
|
||||
JsonDocument? existing = null;
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(existingJson))
|
||||
{
|
||||
try
|
||||
{
|
||||
existing = JsonDocument.Parse(existingJson);
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
error = ex.Message;
|
||||
return null;
|
||||
}
|
||||
if (existing.RootElement.ValueKind != JsonValueKind.Object)
|
||||
{
|
||||
error = $"the top level is {existing.RootElement.ValueKind}, not an object";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
using JsonDocument owned = JsonDocument.Parse(ownedJson);
|
||||
var written = new HashSet<string>(StringComparer.Ordinal);
|
||||
using var ms = new MemoryStream();
|
||||
using (var w = new Utf8JsonWriter(ms, new JsonWriterOptions { Indented = true }))
|
||||
{
|
||||
w.WriteStartObject();
|
||||
foreach (JsonProperty p in owned.RootElement.EnumerateObject())
|
||||
{
|
||||
if (!written.Add(p.Name)) continue;
|
||||
p.WriteTo(w);
|
||||
}
|
||||
if (existing != null)
|
||||
{
|
||||
foreach (JsonProperty p in existing.RootElement.EnumerateObject())
|
||||
{
|
||||
if (ownedKeys.Contains(p.Name)) continue;
|
||||
if (!written.Add(p.Name)) continue; // also drops a duplicate key in the old file
|
||||
p.WriteTo(w);
|
||||
}
|
||||
}
|
||||
w.WriteEndObject();
|
||||
}
|
||||
return ms.ToArray();
|
||||
}
|
||||
finally
|
||||
{
|
||||
existing?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes <paramref name="bytes"/> to a temp file next to <paramref name="path"/> (unique per
|
||||
/// process, since every client's engine can save), then swaps it in with File.Replace (or a
|
||||
/// move when there is no file yet). A reader or another client's save holding the file for a
|
||||
/// moment gets a few short retries. The temp file never stays behind. Throws on failure.
|
||||
/// </summary>
|
||||
public static void WriteAtomic(string path, byte[] bytes)
|
||||
{
|
||||
string tmp = $"{path}.{Environment.ProcessId}.{Guid.NewGuid():N}.tmp";
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes(tmp, bytes);
|
||||
for (int attempt = 1; ; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(path))
|
||||
File.Replace(tmp, path, destinationBackupFileName: null);
|
||||
else
|
||||
File.Move(tmp, path, overwrite: true);
|
||||
return;
|
||||
}
|
||||
catch (IOException) when (attempt < 4)
|
||||
{
|
||||
Thread.Sleep(25 * attempt);
|
||||
}
|
||||
catch (UnauthorizedAccessException) when (attempt < 4)
|
||||
{
|
||||
Thread.Sleep(25 * attempt);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { if (File.Exists(tmp)) File.Delete(tmp); } catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1407,6 +1407,7 @@ internal static partial class PluginManager
|
|||
}
|
||||
|
||||
RynthLog.Plugin("PluginManager: Rescanning plugins...");
|
||||
Net.FlightRecorder.Mark(Net.FlightMark.PluginReload, text: "all plugins unloaded and loaded again (rescan)");
|
||||
|
||||
UnloadAllPlugins();
|
||||
PluginLoader.CleanupShadowCopies(_shadowRootDir);
|
||||
|
|
@ -2334,7 +2335,7 @@ internal static partial class PluginManager
|
|||
// bundled Plugins\ folder — that historically caused stray DLLs to
|
||||
// load on next start (or after hot-reload) without the user knowing.
|
||||
var extraPaths = EngineSettings.PluginPaths;
|
||||
var candidates = new List<string>(extraPaths.Count);
|
||||
var present = new List<string>(extraPaths.Count);
|
||||
for (int i = 0; i < extraPaths.Count; i++)
|
||||
{
|
||||
string dllPath = extraPaths[i];
|
||||
|
|
@ -2343,33 +2344,26 @@ internal static partial class PluginManager
|
|||
RynthLog.Plugin($"PluginManager: Extra plugin not found: {dllPath}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip if a plugin with the same filename was already loaded from the default directory.
|
||||
// Both paths share the same session shadow dir — loading the same filename twice would
|
||||
// try to overwrite a locked shadow copy and crash.
|
||||
string extraFileName = Path.GetFileName(dllPath);
|
||||
bool alreadyLoaded = false;
|
||||
for (int j = 0; j < _plugins.Count; j++)
|
||||
{
|
||||
if (string.Equals(Path.GetFileName(_plugins[j].SourceFilePath), extraFileName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
alreadyLoaded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < candidates.Count && !alreadyLoaded; j++)
|
||||
{
|
||||
if (string.Equals(Path.GetFileName(candidates[j]), extraFileName, StringComparison.OrdinalIgnoreCase))
|
||||
alreadyLoaded = true;
|
||||
}
|
||||
if (alreadyLoaded)
|
||||
{
|
||||
RynthLog.Plugin($"PluginManager: Extra plugin {extraFileName} already loaded from default directory — skipping.");
|
||||
continue;
|
||||
}
|
||||
candidates.Add(dllPath);
|
||||
present.Add(dllPath);
|
||||
}
|
||||
|
||||
// One plugin per file name, before any shadow copy: every shadow copy shares the session
|
||||
// folder, so a second DLL of the same name would overwrite a mapped copy. The same file
|
||||
// listed twice loads once; the same name from two folders is a conflict - the first wins
|
||||
// (PluginPathDedupe).
|
||||
var loadedSources = new List<string>(_plugins.Count);
|
||||
for (int j = 0; j < _plugins.Count; j++)
|
||||
loadedSources.Add(_plugins[j].SourceFilePath);
|
||||
PluginPathDedupe.Result deduped = PluginPathDedupe.Dedupe(present, loadedSources);
|
||||
foreach (PluginPathDedupe.Skipped skipped in deduped.Skipped)
|
||||
{
|
||||
if (skipped.SameFile)
|
||||
RynthLog.Plugin($"PluginManager: {skipped.Message}");
|
||||
else
|
||||
RynthLog.Warn($"PluginManager: {skipped.Message}");
|
||||
}
|
||||
List<string> candidates = deduped.Load;
|
||||
|
||||
// Manifests (embedded in the DLLs, read without loading them): refuse a plugin that needs
|
||||
// a newer engine API or a missing plugin, and put required plugins first. Without
|
||||
// manifests the list loads exactly as before.
|
||||
|
|
@ -3056,6 +3050,7 @@ internal static partial class PluginManager
|
|||
|
||||
private static int CancelAttack()
|
||||
{
|
||||
Compatibility.AcActionTrace.Record("CancelAttack");
|
||||
return ToAbiBool(ClientActionHooks.CancelAttack());
|
||||
}
|
||||
|
||||
|
|
@ -3584,6 +3579,7 @@ internal static partial class PluginManager
|
|||
|
||||
private static int UseObjectOn(uint sourceObjectId, uint targetObjectId)
|
||||
{
|
||||
Compatibility.AcActionTrace.Record("UseObjectOn", sourceObjectId, targetObjectId);
|
||||
LogPluginUse("UseObjectOn", sourceObjectId, targetObjectId);
|
||||
return ToAbiBool(ClientHelperHooks.UseObjectOn(sourceObjectId, targetObjectId));
|
||||
}
|
||||
|
|
@ -3633,31 +3629,37 @@ internal static partial class PluginManager
|
|||
|
||||
private static int UseEquippedItem(uint sourceObjectId, uint targetObjectId)
|
||||
{
|
||||
Compatibility.AcActionTrace.Record("UseEquippedItem", sourceObjectId, targetObjectId);
|
||||
return ToAbiBool(ClientHelperHooks.UseEquippedItem(sourceObjectId, targetObjectId));
|
||||
}
|
||||
|
||||
private static int MoveItemExternal(uint objectId, uint targetContainerId, int amount)
|
||||
{
|
||||
Compatibility.AcActionTrace.Record("MoveItemExternal", objectId, targetContainerId);
|
||||
return ToAbiBool(ClientHelperHooks.MoveItemExternal(objectId, targetContainerId, amount));
|
||||
}
|
||||
|
||||
private static int MoveItemInternal(uint objectId, uint targetContainerId, int slot, int amount)
|
||||
{
|
||||
Compatibility.AcActionTrace.Record("MoveItemInternal", objectId, targetContainerId);
|
||||
return ToAbiBool(ClientHelperHooks.MoveItemInternal(objectId, targetContainerId, slot, amount));
|
||||
}
|
||||
|
||||
private static int SplitStackInternal(uint objectId, uint targetContainerId, int slot, int amount)
|
||||
{
|
||||
Compatibility.AcActionTrace.Record("SplitStackInternal", objectId, targetContainerId);
|
||||
return ToAbiBool(ClientHelperHooks.SplitStackInternal(objectId, targetContainerId, slot, amount));
|
||||
}
|
||||
|
||||
private static int MergeStackInternal(uint sourceObjectId, uint targetObjectId)
|
||||
{
|
||||
Compatibility.AcActionTrace.Record("MergeStackInternal", sourceObjectId, targetObjectId);
|
||||
return ToAbiBool(ClientHelperHooks.MergeStackInternal(sourceObjectId, targetObjectId));
|
||||
}
|
||||
|
||||
private static int GiveObjectTo(uint objectId, uint targetId, int amount)
|
||||
{
|
||||
Compatibility.AcActionTrace.Record("GiveObjectTo", objectId, targetId);
|
||||
return ToAbiBool(ClientHelperHooks.GiveObjectTo(objectId, targetId, amount));
|
||||
}
|
||||
|
||||
|
|
@ -4129,6 +4131,7 @@ internal static partial class PluginManager
|
|||
/// <summary>v70: wield into a chosen slot (see PluginContract.WieldItemFn).</summary>
|
||||
private static int WieldItemAction(uint objectId, uint equipMask)
|
||||
{
|
||||
Compatibility.AcActionTrace.Record("WieldItem", objectId, equipMask);
|
||||
return ToAbiBool(ClientHelperHooks.WieldItem(objectId, equipMask));
|
||||
}
|
||||
|
||||
|
|
@ -4140,6 +4143,16 @@ internal static partial class PluginManager
|
|||
if (string.IsNullOrEmpty(name))
|
||||
return 0;
|
||||
|
||||
// The flight recorder answers to a reserved name (no plugin export, no API bump):
|
||||
// an engine without it finds no such plugin and returns 0, so a plugin can call it
|
||||
// on any engine.
|
||||
if (name == Net.FlightRecorder.PluginCommandTarget)
|
||||
{
|
||||
string? action = actionAnsi != IntPtr.Zero ? Marshal.PtrToStringAnsi(actionAnsi) : null;
|
||||
string? value = valueAnsi != IntPtr.Zero ? Marshal.PtrToStringAnsi(valueAnsi) : null;
|
||||
return Net.FlightRecorder.HandlePluginCommand(action, value) ? 1 : 0;
|
||||
}
|
||||
|
||||
IntPtr export = ResolvePluginExport(name, "RynthPluginApplyRemoteCommand");
|
||||
if (export == IntPtr.Zero)
|
||||
return 0;
|
||||
|
|
@ -4245,7 +4258,11 @@ internal static partial class PluginManager
|
|||
catch { return 0; }
|
||||
}
|
||||
|
||||
private static void ForceResetBusyCountAction() => BusyCountHooks.ForceResetBusyCount();
|
||||
private static void ForceResetBusyCountAction()
|
||||
{
|
||||
Net.FlightRecorder.Mark(Net.FlightMark.BusyForceClearAsk, text: "a plugin (host ForceResetBusyCount)");
|
||||
BusyCountHooks.ForceResetBusyCount();
|
||||
}
|
||||
|
||||
private static unsafe int GetObjectSpellIdsAction(uint guid, uint* spellIds, int maxCount)
|
||||
{
|
||||
|
|
|
|||
96
src/RynthCore.Engine/Plugins/PluginPathDedupe.cs
Normal file
96
src/RynthCore.Engine/Plugins/PluginPathDedupe.cs
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace RynthCore.Engine.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// De-duplicates engine.json's PluginPaths before anything is shadow-copied or loaded. Every
|
||||
/// plugin's shadow copy sits in the same session folder under its file name, so two entries with
|
||||
/// one file name can never both load: the second copy would overwrite a mapped file.
|
||||
/// - The same file listed twice (any case, / or \, ".." or "." segments): loaded once; a
|
||||
/// harmless repeat, said once in the log.
|
||||
/// - The same file name in two folders: a real conflict (two builds of one plugin). The one
|
||||
/// listed first (or already loaded) wins; the other is ignored with a warning naming both.
|
||||
/// No logging and no engine state: PluginManager writes the lines, and tools/PluginManifestTests
|
||||
/// compiles this file in.
|
||||
/// Idea from Silentkelpie (rynth PR #1); re-implemented here.
|
||||
/// </summary>
|
||||
internal static class PluginPathDedupe
|
||||
{
|
||||
/// <summary>An entry that won't load: <see cref="Path"/> as listed, and the entry that loads
|
||||
/// instead. <see cref="SameFile"/>: both name one file (a repeat), not two copies.</summary>
|
||||
internal readonly record struct Skipped(string Path, string KeptPath, bool SameFile, bool KeptAlreadyLoaded)
|
||||
{
|
||||
public string Message => SameFile
|
||||
? (KeptAlreadyLoaded
|
||||
? $"{Path} is already loaded - listed twice in engine.json PluginPaths, loaded once."
|
||||
: $"{Path} is listed twice in engine.json PluginPaths - loaded once.")
|
||||
: $"plugin conflict: {System.IO.Path.GetFileName(Path)} is listed from two folders. "
|
||||
+ $"Using {KeptPath} ({(KeptAlreadyLoaded ? "already loaded" : "listed first")}); ignoring {Path}. "
|
||||
+ "Remove the one you don't want from the launcher's plugin list.";
|
||||
}
|
||||
|
||||
internal sealed class Result
|
||||
{
|
||||
public List<string> Load { get; } = new();
|
||||
public List<Skipped> Skipped { get; } = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <paramref name="paths"/> in order, less repeats and file-name conflicts with an earlier
|
||||
/// entry or with <paramref name="alreadyLoaded"/> (plugins loaded before this pass). The paths
|
||||
/// kept are returned as listed, not rewritten.
|
||||
/// </summary>
|
||||
public static Result Dedupe(IReadOnlyList<string> paths, IEnumerable<string>? alreadyLoaded = null)
|
||||
{
|
||||
var result = new Result();
|
||||
// File name -> (normalized full path, path as listed, already loaded?)
|
||||
var byName = new Dictionary<string, (string Full, string Listed, bool Loaded)>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (alreadyLoaded != null)
|
||||
{
|
||||
foreach (string loaded in alreadyLoaded)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(loaded)) continue;
|
||||
string name = FileName(loaded);
|
||||
if (!byName.ContainsKey(name))
|
||||
byName[name] = (Normalize(loaded), loaded, true);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string path in paths)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path)) continue;
|
||||
string name = FileName(path);
|
||||
string full = Normalize(path);
|
||||
if (byName.TryGetValue(name, out var kept))
|
||||
{
|
||||
bool same = string.Equals(kept.Full, full, StringComparison.OrdinalIgnoreCase);
|
||||
result.Skipped.Add(new Skipped(path, kept.Listed, same, kept.Loaded));
|
||||
continue;
|
||||
}
|
||||
byName[name] = (full, path, false);
|
||||
result.Load.Add(path);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string FileName(string path) => Path.GetFileName(path.Trim().TrimEnd('/', '\\'));
|
||||
|
||||
/// <summary>Full path with \ separators and no trailing separator; the raw text if the path
|
||||
/// can't be resolved (it then only matches itself).</summary>
|
||||
internal static string Normalize(string path)
|
||||
{
|
||||
string p = path.Trim();
|
||||
try
|
||||
{
|
||||
p = Path.GetFullPath(p);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Bad characters or the like: compare as written.
|
||||
}
|
||||
return p.Replace('/', '\\').TrimEnd('\\');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue