feat(engine): install-aware paths, logging levels and item drag bridge

- RynthInstallPaths: logs, AcClient, RynthSuite data and imgui.ini resolve
  from the installer-chosen folders instead of hard-coded C:\Games paths
  (engine, injector, loader, launcher, StatusAgent).
- Logging levels: engine.json "LoggingLevel" plus per-category levels
  (LogSettings), edited live from the launcher's Logging tab; RynthLog
  category methods write through them. Errors are always written.
- RynthCore.DesktopLog: shared rolling log + .NET desktop prerequisite check
  for the launcher and agents.
- Item drag bridge: an AC inventory item dragged onto an ImGui window is
  handed to the window instead of dropping on the ground (DragDropHooks,
  ItemDragBridge, Win32Backend input routing); ImGui gets the mouse over
  Avalonia panels while it wants it.

No plugin API changes.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
BlankenshipG 2026-10-05 16:42:54 -04:00
commit 9709a39e63
32 changed files with 1978 additions and 87 deletions

View file

@ -12,6 +12,7 @@ using System.Runtime.InteropServices;
using System.Threading;
using System.Collections.Generic;
using ImGuiNET;
using RynthCore;
using RynthCore.Engine.Compatibility;
using RynthCore.Engine.D3D9;
using RynthCore.Engine.Plugins;
@ -45,7 +46,21 @@ public static class EntryPoint
private static readonly Queue<string> RecentLogLines = new();
private static long _recentLogSeq;
/// <summary>Set true to enable verbose startup logging (hook ready messages, plugin lifecycle, etc.).</summary>
internal enum EngineLogLevel
{
/// <summary>As a global threshold: nothing but errors. As a category level: never written.</summary>
Off = -1,
Error = 0,
Warning = 1,
Info = 2,
Debug = 3,
Trace = 4
}
/// <summary>Active engine logging threshold loaded from engine settings.</summary>
internal static EngineLogLevel LoggingLevel = EngineLogLevel.Info;
/// <summary>Legacy convenience flag used by existing verbose call sites.</summary>
internal static bool VerboseLogging = false;
/// <summary>Set by EngineFrameController once the game window is confirmed. Read by AvaloniaOverlay.</summary>
@ -154,8 +169,14 @@ public static class EntryPoint
}
catch { }
// engine.json "LoggingLevel" + "LogCategories" (launcher Logging card) set the threshold
// and per-category levels first so every line written below honours them. The watcher
// started later re-reads them whenever the launcher edits the file.
string logSummary = LogSettings.Reload();
// Set up the unified log sink BEFORE anything else so all
// subsequent failures are captured in C:\Games\RynthCore\Logs.
// subsequent failures are captured in <CoreDir>\Logs (installer-chosen;
// resolved here on the init worker, never under the loader lock).
LogPaths.EnsureLogDirectory();
if (_initCount <= 1)
{
@ -170,10 +191,18 @@ public static class EntryPoint
InstallManagedExceptionHandlers();
RynthLog.Info("================================================================");
RynthLog.Info($"RynthCore.Engine init build={BuildStamp} initCount={_initCount} pid={Environment.ProcessId}");
RynthLog.Info($" os={Environment.OSVersion} clr={Environment.Version} cwd={Environment.CurrentDirectory}");
RynthLog.Info("================================================================");
// The banner bypasses the category levels: it must be in every log, whatever engine.json says.
LogTagged("engine", "================================================================", "INF");
LogTagged("engine", $"RynthCore.Engine init build={BuildStamp} initCount={_initCount} pid={Environment.ProcessId}", "INF");
LogTagged("engine", $" os={Environment.OSVersion} clr={Environment.Version} cwd={Environment.CurrentDirectory}", "INF");
LogTagged("engine", $" logging {logSummary}", "INF");
LogTagged("engine", "================================================================", "INF");
string hiddenCategories = LogSettings.HiddenCategoriesWarning();
if (hiddenCategories.Length > 0) RynthLog.Warn(hiddenCategories);
// Live logging config: launcher edits to engine.json apply without a client restart.
// Stopped in EngineLifecycle.Shutdown before the module can be unloaded.
LogSettings.StartWatcher();
CrashLogger.Install();
@ -181,18 +210,10 @@ public static class EntryPoint
// logging AC's main-thread native stack when its EndScene beat stalls.
MainThreadHangWatchdog.Start();
// MultiClientHooks.Initialize installs MinHook detours synchronously
// here, BEFORE InitWorker spawns and runs the main PreloadNativeDll
// pass. If we don't preload minhook.x86.dll first, the P/Invoke
// into minhook fails with DllNotFoundException and the multi-
// client hook silently skips — which means AC's
// Client::IsAlreadyRunning check fires unpatched on the second-
// and-later concurrent acclient.exe processes.
string? earlyEngineDir = GetEngineDirectory();
if (!string.IsNullOrEmpty(earlyEngineDir))
PreloadNativeDll(earlyEngineDir, "minhook.x86.dll");
else
RynthLog.Info("Early-init: could not resolve engine directory — minhook may not be preloaded before MultiClientHooks.");
// MultiClientHooks installs MinHook-based detours immediately. P/Invoke resolves
// minhook.x86.dll before InitWorker runs, so preload it from the engine directory;
// otherwise Client::IsAlreadyRunning fires unpatched on second-and-later clients.
TryPreloadMinHookForEarlyInit();
RunInitStep("early multi-client hooks", MultiClientHooks.Initialize);
// DatFileShareHooks force-shares AC's data files at the CreateFile
@ -300,6 +321,33 @@ public static class EntryPoint
return new string(buffer, 0, (int)length);
}
/// <summary>
/// Loads MinHook on the RynthCoreInit thread so <see cref="MultiClientHooks.Initialize"/> can
/// call <see cref="Hooking.MinHook"/> P/Invokes without relying on the default DLL search path
/// (which often resolves against the AC client directory, not <c>Runtime\</c>).
/// </summary>
private static void TryPreloadMinHookForEarlyInit()
{
try
{
string? engineDir = GetEngineDirectory();
if (string.IsNullOrEmpty(engineDir))
{
RynthLog.Info("Early MinHook preload skipped: could not resolve engine directory.");
return;
}
if (PreloadNativeDll(engineDir, "minhook.x86.dll"))
RynthLog.Verbose($"Early MinHook preload OK (engine dir: {engineDir})");
else
RynthLog.Info($"Early MinHook preload failed: minhook.x86.dll not found beside engine ({engineDir}).");
}
catch (Exception ex)
{
RynthLog.Info($"Early MinHook preload exception: {ex.Message}");
}
}
/// <summary>
/// No-op anchor whose address is taken via `&EngineDirAnchor` to give us a
/// stable pointer inside the engine's own module image — used by
@ -656,6 +704,8 @@ public static class EntryPoint
Step("account hooks", AccountHooks.Initialize);
Step("client combat hooks", () => ClientCombatHooks.Probe());
Step("selected-target hooks", SelectedTargetHooks.Initialize);
// Which item AC is dragging (AC keeps the old selection during a drag).
Step("drag-start hook", DragDropHooks.Initialize);
Step("smartbox hooks", SmartBoxHooks.Initialize);
Step("player vitals hooks", PlayerVitalsHooks.Initialize);
Step("enchantment hooks", () => EnchantmentHooks.Initialize());
@ -1634,10 +1684,34 @@ public static class EntryPoint
internal static void LogVerbose(string message)
{
if (VerboseLogging)
if (ShouldLog(EngineLogLevel.Debug))
Log(message);
}
/// <summary>
/// True when a line at <paramref name="level"/> passes the global threshold. Off-level lines
/// never pass; an Off threshold blocks everything (errors bypass this gate).
/// </summary>
internal static bool ShouldLog(EngineLogLevel level)
=> level != EngineLogLevel.Off && level <= LoggingLevel;
/// <summary>Parses the global level: Off, Error, Warning/Warn, Info, Debug/Verbose, Trace. Unknown → Info.</summary>
internal static EngineLogLevel ParseLoggingLevel(string? configuredLevel)
{
if (string.IsNullOrWhiteSpace(configuredLevel))
return EngineLogLevel.Info;
string normalized = configuredLevel.Trim();
if (string.Equals(normalized, "Verbose", StringComparison.OrdinalIgnoreCase))
return EngineLogLevel.Debug;
if (string.Equals(normalized, "Warn", StringComparison.OrdinalIgnoreCase))
return EngineLogLevel.Warning;
return Enum.TryParse(normalized, ignoreCase: true, out EngineLogLevel parsed) && Enum.IsDefined(parsed)
? parsed
: EngineLogLevel.Info;
}
internal static string[] GetRecentLogLines()
{
lock (LogLock)