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:
parent
913a2a00b6
commit
9709a39e63
32 changed files with 1978 additions and 87 deletions
110
src/RynthCore.Engine/Compatibility/DragDropHooks.cs
Normal file
110
src/RynthCore.Engine/Compatibility/DragDropHooks.cs
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - Compatibility/DragDropHooks.cs
|
||||
// Hooks UIElementManager::StartDragandDrop so the engine knows which item AC
|
||||
// is actually dragging. AC does not change the selected object when a drag
|
||||
// starts, so the selection is the previously clicked item, not the dragged one.
|
||||
//
|
||||
// The dragged UI element is resolved to an object id with AC's own
|
||||
// UIElement_ItemList::InqDropIconInfo (the same call AC makes when the drop
|
||||
// lands), then handed to ItemDragBridge, which republishes it to ImGui.
|
||||
//
|
||||
// Threads: AC's main thread (AC's input / UI processing).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using RynthCore.Engine.Hooking;
|
||||
using RynthCore.Engine.ImGuiBackend;
|
||||
|
||||
namespace RynthCore.Engine.Compatibility;
|
||||
|
||||
internal static unsafe class DragDropHooks
|
||||
{
|
||||
// bool __thiscall UIElementManager::StartDragandDrop(UIElementManager*, UIElement* elem, int clickX, int clickY)
|
||||
private const int StartDragandDropVa = 0x0045E120;
|
||||
// void __cdecl UIElement_ItemList::InqDropIconInfo(const UIElement* icon, uint& itemId, uint& spellId, DropItemFlags& flags)
|
||||
private const int InqDropIconInfoVa = 0x004E3380;
|
||||
|
||||
// Both verified unique in the shipped client (sub esp,34h / mov edi,[esp+48h] / mov esi,ecx prologue;
|
||||
// InqDropIconInfo zeroes its out-params up front).
|
||||
private static readonly byte?[] StartDragandDropPattern =
|
||||
[
|
||||
0x83, 0xEC, 0x34, 0x53, 0x55, 0x56, 0x57, 0x8B, 0x7C, 0x24, 0x48, 0x85, 0xFF, 0x8B, 0xF1, 0x0F, 0x84,
|
||||
null, null, null, null, 0xA1, null, null, null, null, 0x85, 0xC0
|
||||
];
|
||||
private static readonly byte?[] InqDropIconInfoPattern =
|
||||
[
|
||||
0x8B, 0x44, 0x24, 0x10, 0x83, 0xEC, 0x3C, 0x53, 0x55, 0x8B, 0x6C, 0x24, 0x50, 0x56, 0x8B, 0x74, 0x24, 0x4C,
|
||||
0x33, 0xDB, 0x3B, 0xF3, 0x57, 0x8B, 0x7C, 0x24, 0x54, 0x89, 0x1F
|
||||
];
|
||||
|
||||
private static IntPtr _originalStartDrag;
|
||||
private static delegate* unmanaged[Cdecl]<IntPtr, uint*, uint*, uint*, void> _inqDropIconInfo;
|
||||
private static int _logCount;
|
||||
|
||||
/// <summary>The drag-start hook is live, so ItemDragBridge gets the real dragged item.</summary>
|
||||
public static bool IsInstalled { get; private set; }
|
||||
public static string StatusMessage { get; private set; } = "Not probed yet.";
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (IsInstalled) return;
|
||||
if (!AcClientModule.TryReadTextSection(out AcClientTextSection text))
|
||||
{
|
||||
StatusMessage = "acclient.exe not available.";
|
||||
return;
|
||||
}
|
||||
|
||||
var inq = HookResolver.Resolve(text, "DragDrop.InqDropIconInfo", InqDropIconInfoPattern, InqDropIconInfoVa);
|
||||
var start = HookResolver.Resolve(text, "DragDrop.StartDragandDrop", StartDragandDropPattern, StartDragandDropVa);
|
||||
// A guessed address for either would mean calling or patching the wrong code: pattern hits only.
|
||||
if (inq.Source != HookResolver.ResolveSource.PatternScan || start.Source != HookResolver.ResolveSource.PatternScan)
|
||||
{
|
||||
StatusMessage = $"drag-start hook skipped (InqDropIconInfo {inq.Detail}, StartDragandDrop {start.Detail}).";
|
||||
RynthLog.Compat($"Compat: {StatusMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_inqDropIconInfo = (delegate* unmanaged[Cdecl]<IntPtr, uint*, uint*, uint*, void>)inq.Address;
|
||||
delegate* unmanaged[Thiscall]<IntPtr, IntPtr, int, int, byte> detour = &StartDragandDropDetour;
|
||||
MinHook.Hook(start.Address, (IntPtr)detour, out _originalStartDrag);
|
||||
IsInstalled = true;
|
||||
StatusMessage = $"Hooked UIElementManager::StartDragandDrop @ 0x{start.Address.ToInt32():X8}.";
|
||||
RynthLog.Info($"Compat: drag-start hook ready - StartDragandDrop=0x{start.Address.ToInt32():X8}, InqDropIconInfo=0x{inq.Address.ToInt32():X8}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StatusMessage = ex.Message;
|
||||
RynthLog.Compat($"Compat: drag-start hook failed - {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvThiscall)])]
|
||||
private static byte StartDragandDropDetour(IntPtr manager, IntPtr element, int clickX, int clickY)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (element != IntPtr.Zero && _inqDropIconInfo != null)
|
||||
{
|
||||
uint itemId = 0, spellId = 0, flags = 0;
|
||||
_inqDropIconInfo(element, &itemId, &spellId, &flags);
|
||||
// Spell-bar drags carry a spell id and no item.
|
||||
if (itemId != 0)
|
||||
{
|
||||
if (_logCount < 20) { _logCount++; RynthLog.UI($"DragDropHooks: AC drag start item=0x{itemId:X8} flags=0x{flags:X}"); }
|
||||
ItemDragBridge.OnNativeDragStart(itemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { RynthLog.Compat($"Compat: drag-start detour error - {ex.GetType().Name}: {ex.Message}"); } catch { }
|
||||
}
|
||||
|
||||
var original = (delegate* unmanaged[Thiscall]<IntPtr, IntPtr, int, int, byte>)_originalStartDrag;
|
||||
return original(manager, element, clickX, clickY);
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
251
src/RynthCore.Engine/ImGui/ItemDragBridge.cs
Normal file
251
src/RynthCore.Engine/ImGui/ItemDragBridge.cs
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - ImGui/ItemDragBridge.cs
|
||||
// Carries an item drag into the MAIN ImGui context when it didn't start there,
|
||||
// so drop targets in the client (RynthAi's Mini Remote slots) can take it:
|
||||
//
|
||||
// • A popped-out Inventory: the pop-out has its own ImGui context and holds
|
||||
// mouse capture for the whole drag, so the main context never sees it.
|
||||
// The pop-out face reports the dragged item (NotePopOutDrag); the main
|
||||
// frame republishes it as an extern payload. The main context sees no
|
||||
// button press, so the payload uses PayloadAutoExpire: it is delivered to
|
||||
// the hovered target on the first frame it is no longer submitted.
|
||||
// • AC's own inventory: a press that began on the game belongs to the game,
|
||||
// and ImGui ignores hovering for it. DragDropHooks reports the item AC
|
||||
// starts dragging (OnNativeDragStart); a carried one is republished the
|
||||
// same way, under PayloadType, and delivered when ImGui sees the button go
|
||||
// up. AC does not select the dragged item, so without that hook the bridge
|
||||
// can only guess from the selection: the guess goes out under
|
||||
// NativePayloadType, which targets treat as unreliable.
|
||||
//
|
||||
// A native drag released over an ImGui window would otherwise complete in AC
|
||||
// as a drop on the 3D view (the item lands on the ground). TryRedirectNativeDrop
|
||||
// moves that button-up back to where the drag began, which AC treats as
|
||||
// putting the item back.
|
||||
//
|
||||
// Threads: AC's main thread only (game WndProc, EndScene, pop-out frames).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using ImGuiNET;
|
||||
using RynthCore.Engine.Compatibility;
|
||||
|
||||
namespace RynthCore.Engine.ImGuiBackend;
|
||||
|
||||
internal static unsafe class ItemDragBridge
|
||||
{
|
||||
/// <summary>Payload type for one item (uint object id). Must match RynthAi's MiniRemoteHud.ItemPayloadType.</summary>
|
||||
public const string PayloadType = "RYNTH_INV_ITEM";
|
||||
|
||||
/// <summary>
|
||||
/// Payload type for a game drag whose item was guessed from the selection (DragDropHooks not
|
||||
/// installed). Any game left-drag with a carried item selected looks like this (moving an AC
|
||||
/// panel too), so targets should take it only where a wrong item does no harm (RynthAi: empty
|
||||
/// slots). Must match MiniRemoteHud.GameItemPayloadType.
|
||||
/// </summary>
|
||||
public const string NativePayloadType = "RYNTH_GAME_ITEM";
|
||||
|
||||
private const uint WM_MOUSEMOVE = 0x0200, WM_LBUTTONDOWN = 0x0201, WM_LBUTTONUP = 0x0202;
|
||||
private const int MK_LBUTTON = 0x0001, MK_OTHER = 0x0002 | 0x0010 | 0x0020 | 0x0040;
|
||||
/// <summary>Movement (px, squared) before a game press counts as a drag.</summary>
|
||||
private const int DragThresholdSq = 5 * 5;
|
||||
/// <summary>AC may select the pressed item a few messages after the press: keep re-reading it this long.</summary>
|
||||
private static readonly long SelectionSettleTicks = Stopwatch.Frequency / 2;
|
||||
/// <summary>A pop-out drag with no report for this long is over (the pop-out closed mid-drag).</summary>
|
||||
private static readonly long PopOutStaleTicks = Stopwatch.Frequency;
|
||||
|
||||
// Popped-out Inventory drag.
|
||||
private static uint _popOutItem;
|
||||
private static long _popOutSeenAt;
|
||||
|
||||
// Native (AC inventory) drag.
|
||||
private static bool _pressPending;
|
||||
private static IntPtr _pressLParam;
|
||||
private static int _pressX, _pressY;
|
||||
private static long _pressAt;
|
||||
private static uint _nativeItem;
|
||||
/// <summary>_nativeItem came from AC's drag start (DragDropHooks), not from the selection.</summary>
|
||||
private static bool _nativeFromHook;
|
||||
/// <summary>The left button is down on a press that belongs to the game.</summary>
|
||||
private static bool _gamePressHeld;
|
||||
private static bool _nativeReleased;
|
||||
/// <summary>The cursor was over an ImGui window in the last main frame (only tracked during a native drag).</summary>
|
||||
private static bool _overImGui;
|
||||
|
||||
// ── Popped-out Inventory ────────────────────────────────────────────────
|
||||
|
||||
/// <summary>A popped-out Inventory is dragging <paramref name="itemId"/> (call every pop-out frame of the drag).</summary>
|
||||
public static void NotePopOutDrag(uint itemId)
|
||||
{
|
||||
if (itemId == 0) return;
|
||||
if (_popOutItem != itemId)
|
||||
RynthLog.UI($"ItemDragBridge: pop-out drag 0x{itemId:X8} published to the client.");
|
||||
_popOutItem = itemId;
|
||||
_popOutSeenAt = Stopwatch.GetTimestamp();
|
||||
}
|
||||
|
||||
/// <summary>The popped-out Inventory's drag ended (dropped or cancelled).</summary>
|
||||
public static void EndPopOutDrag() => _popOutItem = 0;
|
||||
|
||||
// ── Native drag (game WndProc) ──────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Every game-window mouse message, after the backend decided who owns the held buttons.
|
||||
/// <paramref name="gameOwned"/>: the current press began on the game, not on ImGui.
|
||||
/// </summary>
|
||||
public static void OnGameMouse(uint msg, IntPtr wParam, IntPtr lParam, bool gameOwned)
|
||||
{
|
||||
int keys = (int)((long)wParam & 0xFFFF);
|
||||
switch (msg)
|
||||
{
|
||||
case WM_LBUTTONDOWN:
|
||||
// Only a plain left press that belongs to the game can be an inventory drag.
|
||||
_pressPending = gameOwned && (keys & MK_OTHER) == 0;
|
||||
_pressLParam = lParam;
|
||||
_pressX = LoWord(lParam);
|
||||
_pressY = HiWord(lParam);
|
||||
_pressAt = Stopwatch.GetTimestamp();
|
||||
_gamePressHeld = _pressPending;
|
||||
if (_pressPending) { _nativeItem = 0; _nativeFromHook = false; _nativeReleased = false; }
|
||||
break;
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
if ((keys & MK_LBUTTON) == 0)
|
||||
{
|
||||
// A release we never saw (outside the window): finish the drag.
|
||||
_pressPending = false;
|
||||
_gamePressHeld = false;
|
||||
if (_nativeItem != 0) _nativeReleased = true;
|
||||
break;
|
||||
}
|
||||
if (_pressPending)
|
||||
{
|
||||
int dx = LoWord(lParam) - _pressX, dy = HiWord(lParam) - _pressY;
|
||||
if (dx * dx + dy * dy >= DragThresholdSq)
|
||||
{
|
||||
_pressPending = false;
|
||||
// With the drag-start hook the real item arrives through OnNativeDragStart.
|
||||
if (_nativeItem == 0 && !DragDropHooks.IsInstalled)
|
||||
{
|
||||
_nativeItem = CarriedSelection();
|
||||
if (_nativeItem != 0)
|
||||
RynthLog.UI($"ItemDragBridge: native inventory drag 0x{_nativeItem:X8} (from the selection) published to ImGui.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (_nativeItem != 0 && !_nativeFromHook && !_nativeReleased && Stopwatch.GetTimestamp() - _pressAt < SelectionSettleTicks)
|
||||
{
|
||||
// The selection can trail the press by a few messages: follow it while it settles.
|
||||
uint sel = CarriedSelection();
|
||||
if (sel != 0) _nativeItem = sel;
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
_pressPending = false;
|
||||
_gamePressHeld = false;
|
||||
if (_nativeItem != 0) _nativeReleased = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AC started dragging <paramref name="itemId"/> (DragDropHooks, AC's main thread). Taken while
|
||||
/// a game-owned left press is held and only for items the player carries.
|
||||
/// </summary>
|
||||
public static void OnNativeDragStart(uint itemId)
|
||||
{
|
||||
if (!_gamePressHeld || itemId == 0 || !IsCarried(itemId)) return;
|
||||
_pressPending = false;
|
||||
_nativeItem = itemId;
|
||||
_nativeFromHook = true;
|
||||
_nativeReleased = false;
|
||||
RynthLog.UI($"ItemDragBridge: native inventory drag 0x{itemId:X8} published to ImGui.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A native item drag is being released over an ImGui window: returns the press position
|
||||
/// to send AC instead, so AC puts the item back rather than dropping it on the ground.
|
||||
/// </summary>
|
||||
public static bool TryRedirectNativeDrop(uint msg, out IntPtr pressLParam)
|
||||
{
|
||||
pressLParam = _pressLParam;
|
||||
if (msg != WM_LBUTTONUP || _nativeItem == 0 || !_overImGui) return false;
|
||||
RynthLog.UI($"ItemDragBridge: native drag 0x{_nativeItem:X8} released over an ImGui window; AC gets the drop back at its start ({_pressX},{_pressY}).");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ── Main frame (after ImGui.NewFrame, before any window) ────────────────
|
||||
|
||||
/// <summary>Republishes a pop-out or native drag in the main context for this frame.</summary>
|
||||
public static void SubmitMainFrame(ImGuiIOPtr io)
|
||||
{
|
||||
uint id = 0;
|
||||
string type = PayloadType;
|
||||
if (_popOutItem != 0)
|
||||
{
|
||||
if (Stopwatch.GetTimestamp() - _popOutSeenAt > PopOutStaleTicks) _popOutItem = 0;
|
||||
else id = _popOutItem;
|
||||
}
|
||||
|
||||
if (id == 0 && _nativeItem != 0)
|
||||
{
|
||||
type = _nativeFromHook ? PayloadType : NativePayloadType;
|
||||
// After the button-up, stop once ImGui itself sees the button up: that frame
|
||||
// delivers the drop (the payload outlives its last submission by one frame).
|
||||
if (_nativeReleased && !io.MouseDown[0])
|
||||
{
|
||||
_nativeItem = 0;
|
||||
_nativeFromHook = false;
|
||||
_nativeReleased = false;
|
||||
_overImGui = false;
|
||||
return;
|
||||
}
|
||||
id = _nativeItem;
|
||||
_overImGui = ImGuiNET.ImGui.IsWindowHovered(ImGuiHoveredFlags.AnyWindow | ImGuiHoveredFlags.AllowWhenBlockedByActiveItem);
|
||||
}
|
||||
|
||||
if (id == 0) return;
|
||||
const ImGuiDragDropFlags flags = ImGuiDragDropFlags.SourceExtern | ImGuiDragDropFlags.SourceNoPreviewTooltip
|
||||
| ImGuiDragDropFlags.PayloadAutoExpire;
|
||||
if (ImGuiNET.ImGui.BeginDragDropSource(flags))
|
||||
{
|
||||
ImGuiNET.ImGui.SetDragDropPayload(type, (IntPtr)(&id), sizeof(uint));
|
||||
ImGuiNET.ImGui.EndDragDropSource();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Forget every drag (focus lost, logout, engine shutdown).</summary>
|
||||
public static void Reset()
|
||||
{
|
||||
_popOutItem = 0;
|
||||
_pressPending = false;
|
||||
_gamePressHeld = false;
|
||||
_nativeItem = 0;
|
||||
_nativeFromHook = false;
|
||||
_nativeReleased = false;
|
||||
_overImGui = false;
|
||||
}
|
||||
|
||||
/// <summary>The game's selected object when the player carries it, else 0.</summary>
|
||||
private static uint CarriedSelection()
|
||||
{
|
||||
uint id = ClientHelperHooks.GetSelectedItemId();
|
||||
return IsCarried(id) ? id : 0;
|
||||
}
|
||||
|
||||
/// <summary><paramref name="id"/> is in the player's pack, a side pack, or worn.</summary>
|
||||
private static bool IsCarried(uint id)
|
||||
{
|
||||
if (id == 0 || !ClientHelperHooks.HasGetPlayerId) return false;
|
||||
uint player = ClientHelperHooks.GetPlayerId();
|
||||
if (player == 0 || id == player) return false;
|
||||
if (!ClientObjectHooks.TryGetObjectOwnershipInfo(id, out uint container, out uint wielder, out _)) return false;
|
||||
if (wielder == player || container == player) return true;
|
||||
// Side pack in the main pack.
|
||||
return container != 0 && ClientObjectHooks.TryGetObjectOwnershipInfo(container, out uint outer, out _, out _) && outer == player;
|
||||
}
|
||||
|
||||
private static int LoWord(IntPtr l) => unchecked((short)((long)l & 0xFFFF));
|
||||
private static int HiWord(IntPtr l) => unchecked((short)(((long)l >> 16) & 0xFFFF));
|
||||
}
|
||||
|
|
@ -1025,11 +1025,15 @@ internal static unsafe class Win32Backend
|
|||
// HUD drag (keeps our SetCapture from fighting NewFrame's). No-op
|
||||
// unless the HUD is drawn.
|
||||
if (IsMouseMessage(msg))
|
||||
{
|
||||
TrackMouseButtons(msg, wParam);
|
||||
ItemDragBridge.OnGameMouse(msg, wParam, lParam, _heldButtonsBelongToGame);
|
||||
}
|
||||
else if (msg == WM_KILLFOCUS)
|
||||
{
|
||||
_heldMouseButtons = 0;
|
||||
_heldButtonsBelongToGame = false;
|
||||
ItemDragBridge.Reset();
|
||||
}
|
||||
|
||||
// ── Avalonia panel hit-test & input forwarding ────────────────
|
||||
|
|
@ -1040,7 +1044,7 @@ internal static unsafe class Win32Backend
|
|||
{
|
||||
// fall through: AC gets the message
|
||||
}
|
||||
else if (IsMouseMessage(msg))
|
||||
else if (IsMouseMessage(msg) && !ImGuiOwnsMouseOverAvalonia())
|
||||
{
|
||||
bool handled = TryForwardToAvalonia(msg, wParam, lParam);
|
||||
if (handled)
|
||||
|
|
@ -1129,6 +1133,14 @@ internal static unsafe class Win32Backend
|
|||
}
|
||||
}
|
||||
|
||||
// An AC inventory item dragged onto an ImGui window: AC must not drop it on the
|
||||
// ground behind the window. It gets the release where the drag began instead.
|
||||
if (ItemDragBridge.TryRedirectNativeDrop(msg, out IntPtr pressLParam))
|
||||
{
|
||||
CallWindowProcA(_originalWndProc, hWnd, WM_MOUSEMOVE, (IntPtr)MK_LBUTTON, pressLParam);
|
||||
return CallWindowProcA(_originalWndProc, hWnd, msg, wParam, pressLParam);
|
||||
}
|
||||
|
||||
// Pass through to original WndProc
|
||||
return CallWindowProcA(_originalWndProc, hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
|
@ -1139,6 +1151,17 @@ internal static unsafe class Win32Backend
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ImGui windows are drawn on top of the Avalonia layer, so when the cursor is over
|
||||
/// an ImGui window (or an ImGui widget is active) mouse input must go to ImGui
|
||||
/// instead of the Avalonia panel underneath. An Avalonia drag/resize that is already
|
||||
/// in progress keeps its capture so the release is never lost.
|
||||
/// </summary>
|
||||
private static bool ImGuiOwnsMouseOverAvalonia()
|
||||
{
|
||||
return _wantCaptureMouse && !AvaloniaOverlay.HasPointerCapture;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If the cursor is over the Avalonia shell panel, PostMessage the mouse event to
|
||||
/// the off-screen Avalonia HWND and return true (caller should suppress game delivery).
|
||||
|
|
|
|||
|
|
@ -21,13 +21,15 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using RynthCore.Install;
|
||||
|
||||
namespace RynthCore.Engine;
|
||||
|
||||
internal static class LogPaths
|
||||
{
|
||||
/// <summary>Unified log directory for all RynthCore components.</summary>
|
||||
internal const string LogDirectory = @"C:\Games\RynthCore\Logs";
|
||||
// Installer-chosen RynthCore folder (registry Software\Rynth\CoreDir; falls back to C:\Games\RynthCore).
|
||||
internal static readonly string LogDirectory = RynthInstallPaths.CoreLogsDir;
|
||||
|
||||
/// <summary>Shared launch/orchestration log (injector + launcher + per-engine session pointer).</summary>
|
||||
internal const string SharedLogFileName = "RynthCore.log";
|
||||
|
|
|
|||
245
src/RynthCore.Engine/LogSettings.cs
Normal file
245
src/RynthCore.Engine/LogSettings.cs
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using RynthCore.Engine.Plugins;
|
||||
|
||||
namespace RynthCore.Engine;
|
||||
|
||||
/// <summary>
|
||||
/// Engine log categories. Each one has a configurable emit level (see <see cref="LogSettings"/>).
|
||||
/// Names are the keys of engine.json "LogCategories" and must stay stable.
|
||||
/// </summary>
|
||||
internal enum LogCategory
|
||||
{
|
||||
/// <summary>Uncategorised RynthLog.Info lines.</summary>
|
||||
General = 0,
|
||||
/// <summary>D3D9: vtable, EndScene, bootstrapper, matrix capture, nav3D.</summary>
|
||||
D3D9,
|
||||
/// <summary>Compatibility hooks: client objects, combat, movement, vitals, chat, ...</summary>
|
||||
Compat,
|
||||
/// <summary>ImGui rendering: context, DX9 backend, Win32 input, shell.</summary>
|
||||
Render,
|
||||
/// <summary>Plugin system, including every line plugins write through the host Log API.</summary>
|
||||
Plugin,
|
||||
/// <summary>UI / Avalonia overlay.</summary>
|
||||
UI,
|
||||
/// <summary>Verbose detail lines (RynthLog.Verbose / RynthLog.Debug).</summary>
|
||||
Verbose,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Live engine logging configuration, read from %APPDATA%\RynthCore\engine.json:
|
||||
/// <list type="bullet">
|
||||
/// <item><c>"LoggingLevel"</c> — global threshold: Off, Error, Warning, Info, Debug, Trace.</item>
|
||||
/// <item><c>"LogCategories"</c> — per-category emit level: <c>{ "Compat": "Info", "Verbose": "Debug", ... }</c>.
|
||||
/// The emit level is the level a category's lines are written AT, so a line shows when
|
||||
/// its emit level is within the global threshold. Setting a Trace/Debug category to
|
||||
/// Info puts it in the normal (Info) log; Off silences the category entirely.</item>
|
||||
/// </list>
|
||||
/// A background thread polls the file's timestamp once a second, so launcher edits apply to a
|
||||
/// running client without a restart. Errors are always written, even when the level is Off.
|
||||
/// </summary>
|
||||
internal static class LogSettings
|
||||
{
|
||||
/// <summary>engine.json property holding the per-category levels.</summary>
|
||||
internal const string CategoriesProperty = "LogCategories";
|
||||
|
||||
private const int PollIntervalMs = 1000;
|
||||
|
||||
// Default emit level per LogCategory (index = enum value): categories at Info,
|
||||
// Render off, verbose lines at Debug.
|
||||
private static readonly EntryPoint.EngineLogLevel[] Defaults =
|
||||
{
|
||||
EntryPoint.EngineLogLevel.Info, // General
|
||||
EntryPoint.EngineLogLevel.Info, // D3D9
|
||||
EntryPoint.EngineLogLevel.Info, // Compat
|
||||
EntryPoint.EngineLogLevel.Off, // Render
|
||||
EntryPoint.EngineLogLevel.Info, // Plugin
|
||||
EntryPoint.EngineLogLevel.Info, // UI
|
||||
EntryPoint.EngineLogLevel.Debug, // Verbose
|
||||
};
|
||||
|
||||
// Replaced wholesale on reload (never mutated after publish) so hot-path readers on any
|
||||
// thread can index it without a lock.
|
||||
private static EntryPoint.EngineLogLevel[] _levels = (EntryPoint.EngineLogLevel[])Defaults.Clone();
|
||||
|
||||
private static readonly object WatcherLock = new();
|
||||
private static Thread? _watcherThread;
|
||||
private static ManualResetEventSlim? _stopSignal;
|
||||
private static DateTime _stampUtc = DateTime.MinValue;
|
||||
|
||||
private static string SettingsPath => Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RynthCore", "engine.json");
|
||||
|
||||
/// <summary>Current emit level for a category (cheap; safe on hot paths).</summary>
|
||||
internal static EntryPoint.EngineLogLevel LevelFor(LogCategory category)
|
||||
{
|
||||
EntryPoint.EngineLogLevel[] levels = Volatile.Read(ref _levels);
|
||||
int i = (int)category;
|
||||
return (uint)i < (uint)levels.Length ? levels[i] : EntryPoint.EngineLogLevel.Info;
|
||||
}
|
||||
|
||||
/// <summary>True when a line in this category would be written right now.</summary>
|
||||
internal static bool IsEnabled(LogCategory category) => EntryPoint.ShouldLog(LevelFor(category));
|
||||
|
||||
/// <summary>3-char severity tag written into each log line.</summary>
|
||||
internal static string Tag(EntryPoint.EngineLogLevel level) => level switch
|
||||
{
|
||||
EntryPoint.EngineLogLevel.Error => "ERR",
|
||||
EntryPoint.EngineLogLevel.Warning => "WRN",
|
||||
EntryPoint.EngineLogLevel.Debug => "DBG",
|
||||
EntryPoint.EngineLogLevel.Trace => "TRC",
|
||||
_ => "INF",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Reads the global level and category levels from engine.json and publishes them.
|
||||
/// Called once at init (before the first log line) and again by the watcher on change.
|
||||
/// Missing or unreadable values fall back to their defaults. Returns a one-line summary.
|
||||
/// </summary>
|
||||
internal static string Reload()
|
||||
{
|
||||
string? globalText = null;
|
||||
var levels = (EntryPoint.EngineLogLevel[])Defaults.Clone();
|
||||
|
||||
try
|
||||
{
|
||||
string path = SettingsPath;
|
||||
if (File.Exists(path))
|
||||
{
|
||||
_stampUtc = File.GetLastWriteTimeUtc(path);
|
||||
// ReadAllText strips a UTF-8/UTF-16 BOM that JsonDocument would choke on.
|
||||
using var doc = JsonDocument.Parse(File.ReadAllText(path));
|
||||
JsonElement root = doc.RootElement;
|
||||
|
||||
if (root.TryGetProperty("LoggingLevel", out JsonElement levelEl) && levelEl.ValueKind == JsonValueKind.String)
|
||||
globalText = levelEl.GetString();
|
||||
|
||||
if (root.TryGetProperty(CategoriesProperty, out JsonElement catsEl) && catsEl.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
foreach (JsonProperty p in catsEl.EnumerateObject())
|
||||
{
|
||||
if (p.Value.ValueKind != JsonValueKind.String) continue;
|
||||
if (!Enum.TryParse(p.Name, ignoreCase: true, out LogCategory cat) || !Enum.IsDefined(cat)) continue;
|
||||
if (TryParseCategoryLevel(p.Value.GetString(), out EntryPoint.EngineLogLevel lvl))
|
||||
levels[(int)cat] = lvl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Half-written / corrupt file: keep defaults for this pass; the next timestamp change retries.
|
||||
globalText ??= EngineSettings.LoggingLevel;
|
||||
}
|
||||
|
||||
EntryPoint.LoggingLevel = EntryPoint.ParseLoggingLevel(globalText);
|
||||
Volatile.Write(ref _levels, levels);
|
||||
EntryPoint.VerboseLogging = IsEnabled(LogCategory.Verbose);
|
||||
return Describe();
|
||||
}
|
||||
|
||||
/// <summary>Human-readable "level=Info D3D9=Info Compat=Info ..." summary for the log.</summary>
|
||||
internal static string Describe()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("level=").Append(EntryPoint.LoggingLevel);
|
||||
EntryPoint.EngineLogLevel[] levels = Volatile.Read(ref _levels);
|
||||
for (int i = 0; i < levels.Length; i++)
|
||||
sb.Append(' ').Append((LogCategory)i).Append('=').Append(levels[i]);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Categories whose emit level is more verbose than the global level, so none of their lines
|
||||
/// are written (e.g. every category at Trace with LoggingLevel Info: an almost empty log).
|
||||
/// Empty when nothing is hidden.
|
||||
/// </summary>
|
||||
internal static string HiddenCategoriesWarning()
|
||||
{
|
||||
EntryPoint.EngineLogLevel global = EntryPoint.LoggingLevel;
|
||||
EntryPoint.EngineLogLevel[] levels = Volatile.Read(ref _levels);
|
||||
var hidden = new StringBuilder();
|
||||
for (int i = 0; i < levels.Length; i++)
|
||||
{
|
||||
if (levels[i] == EntryPoint.EngineLogLevel.Off || levels[i] <= global) continue;
|
||||
if (hidden.Length > 0) hidden.Append(", ");
|
||||
hidden.Append((LogCategory)i).Append('=').Append(levels[i]);
|
||||
}
|
||||
return hidden.Length == 0 ? ""
|
||||
: $"LogSettings: {hidden} write above the global LoggingLevel ({global}), so those lines are NOT logged. " +
|
||||
"Raise LoggingLevel to the most verbose category level, or set the categories to Info.";
|
||||
}
|
||||
|
||||
/// <summary>Starts the once-a-second engine.json poll. Idempotent.</summary>
|
||||
internal static void StartWatcher()
|
||||
{
|
||||
lock (WatcherLock)
|
||||
{
|
||||
if (_watcherThread != null) return;
|
||||
_stopSignal = new ManualResetEventSlim(false);
|
||||
ManualResetEventSlim stop = _stopSignal;
|
||||
_watcherThread = new Thread(() => WatchLoop(stop))
|
||||
{
|
||||
IsBackground = true,
|
||||
Name = "RynthCore.LogSettingsWatcher",
|
||||
};
|
||||
_watcherThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops and joins the poll thread. Called from EngineLifecycle.Shutdown so the thread never
|
||||
/// runs inside an old engine generation after a hot reload.
|
||||
/// </summary>
|
||||
internal static void StopWatcher()
|
||||
{
|
||||
Thread? thread;
|
||||
lock (WatcherLock)
|
||||
{
|
||||
thread = _watcherThread;
|
||||
_stopSignal?.Set();
|
||||
_watcherThread = null;
|
||||
}
|
||||
thread?.Join(2000);
|
||||
}
|
||||
|
||||
private static void WatchLoop(ManualResetEventSlim stop)
|
||||
{
|
||||
while (!stop.Wait(PollIntervalMs))
|
||||
{
|
||||
try
|
||||
{
|
||||
string path = SettingsPath;
|
||||
if (!File.Exists(path) || File.GetLastWriteTimeUtc(path) == _stampUtc)
|
||||
continue;
|
||||
|
||||
string summary = Reload();
|
||||
// Bypasses the category levels so a change is visible whenever Info is in range.
|
||||
if (EntryPoint.ShouldLog(EntryPoint.EngineLogLevel.Info))
|
||||
EntryPoint.LogTagged("engine", $"LogSettings: engine.json changed - logging reloaded ({summary}).", "INF");
|
||||
string hidden = HiddenCategoriesWarning();
|
||||
if (hidden.Length > 0) RynthLog.Warn(hidden);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Logging configuration must never take the client down; retry next poll.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a category emit level: Off, Trace, Debug (or Verbose), Info, Warning (or Warn), Error.
|
||||
/// </summary>
|
||||
private static bool TryParseCategoryLevel(string? text, out EntryPoint.EngineLogLevel level)
|
||||
{
|
||||
level = EntryPoint.EngineLogLevel.Info;
|
||||
if (string.IsNullOrWhiteSpace(text)) return false;
|
||||
string t = text.Trim();
|
||||
if (t.Equals("Verbose", StringComparison.OrdinalIgnoreCase)) { level = EntryPoint.EngineLogLevel.Debug; return true; }
|
||||
if (t.Equals("Warn", StringComparison.OrdinalIgnoreCase)) { level = EntryPoint.EngineLogLevel.Warning; return true; }
|
||||
return Enum.TryParse(t, ignoreCase: true, out level) && Enum.IsDefined(level);
|
||||
}
|
||||
}
|
||||
|
|
@ -26,8 +26,10 @@ internal static class EngineSettings
|
|||
private static bool _enableEngine = true;
|
||||
private static int _engineHookCount = int.MaxValue;
|
||||
private static bool _enableImGuiBackend = true;
|
||||
private static bool _enablePluginOverlayWindows = true;
|
||||
private static bool _enableHangMinidump = true;
|
||||
private static bool _preventIdleLogoff = true;
|
||||
private static string _loggingLevel = "Info";
|
||||
private static DecalBridgeMode _decalBridgeMode = DecalBridgeMode.Auto;
|
||||
private static bool _decalInGameImGui = true;
|
||||
private static bool _decalStandDown = true;
|
||||
|
|
@ -178,6 +180,19 @@ internal static class EngineSettings
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>When true (default) and the ImGui shell is off, plugins that export
|
||||
/// RynthPluginRenderOverlay draw their extra ImGui windows (RynthAi: ILT Hub, Item Info)
|
||||
/// beside the Avalonia UI. engine.json "EnablePluginOverlayWindows": false hides them.
|
||||
/// Needs <see cref="EnableImGuiBackend"/>.</summary>
|
||||
public static bool EnablePluginOverlayWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureLoaded();
|
||||
return _enablePluginOverlayWindows;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>When true, MainThreadHangWatchdog writes a minidump to
|
||||
/// Logs\dumps\ the first time AC's main thread is confirmed permanently
|
||||
/// wedged — a targeted post-mortem to replace always-on procdump (which
|
||||
|
|
@ -205,6 +220,18 @@ internal static class EngineSettings
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Engine log threshold from engine.json "LoggingLevel", written by the launcher's
|
||||
/// Logging level box: Error, Warning, Info (default), Debug/Verbose or Trace. Parsed by
|
||||
/// EntryPoint.ParseLoggingLevel at init; unknown values fall back to Info.</summary>
|
||||
public static string LoggingLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
EnsureLoaded();
|
||||
return _loggingLevel;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>"DecalBridge" in engine.json: Auto (default), On or Off. Only matters when
|
||||
/// Decal is loaded in the same client (docs/DECAL_BRIDGE_PLAN.md):
|
||||
/// Auto - bridge mode when the RynthCore Decal bridge is registered and says hello
|
||||
|
|
@ -386,6 +413,12 @@ internal static class EngineSettings
|
|||
_enableImGuiBackend = ibEl.GetBoolean();
|
||||
}
|
||||
|
||||
if (doc.RootElement.TryGetProperty("EnablePluginOverlayWindows", out var powEl) &&
|
||||
(powEl.ValueKind == JsonValueKind.True || powEl.ValueKind == JsonValueKind.False))
|
||||
{
|
||||
_enablePluginOverlayWindows = powEl.GetBoolean();
|
||||
}
|
||||
|
||||
if (doc.RootElement.TryGetProperty("EnableHangMinidump", out var hmEl) &&
|
||||
(hmEl.ValueKind == JsonValueKind.True || hmEl.ValueKind == JsonValueKind.False))
|
||||
{
|
||||
|
|
@ -429,6 +462,14 @@ internal static class EngineSettings
|
|||
_disabledUiHooks.Add(hookName.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
if (doc.RootElement.TryGetProperty("LoggingLevel", out var logLevelEl) &&
|
||||
logLevelEl.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
string? configuredLevel = logLevelEl.GetString();
|
||||
if (!string.IsNullOrWhiteSpace(configuredLevel))
|
||||
_loggingLevel = configuredLevel;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -459,8 +500,12 @@ internal static class EngineSettings
|
|||
w.WriteBoolean("EnableEngine", _enableEngine);
|
||||
w.WriteNumber("EngineHookCount", _engineHookCount);
|
||||
w.WriteBoolean("EnableImGuiBackend", _enableImGuiBackend);
|
||||
w.WriteBoolean("EnablePluginOverlayWindows", _enablePluginOverlayWindows);
|
||||
w.WriteBoolean("EnableHangMinidump", _enableHangMinidump);
|
||||
w.WriteBoolean("PreventIdleLogoff", _preventIdleLogoff);
|
||||
// Preserve the launcher-chosen level; dropping it here would reset logging to Info.
|
||||
w.WriteString("LoggingLevel", _loggingLevel);
|
||||
CopyUnownedFields(w);
|
||||
if (_decalBridgeMode != DecalBridgeMode.Auto) // default: leave the file as it was
|
||||
w.WriteString("DecalBridge", _decalBridgeMode.ToString());
|
||||
if (!_decalInGameImGui) // default true: leave the file as it was
|
||||
|
|
@ -485,6 +530,37 @@ internal static class EngineSettings
|
|||
RynthLog.Plugin($"EngineSettings: Failed to save: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// Fields Save() writes itself; everything else in engine.json belongs to the launcher
|
||||
// (LogCategories, EnableDcompOverlay, ...) and is copied through untouched.
|
||||
private static readonly string[] OwnedFields =
|
||||
{
|
||||
"PluginPaths", "EnableImGuiShell", "EnablePlugins", "EnableDatShareHook", "EnableAvaloniaOverlay",
|
||||
"EnableD3D9Hook", "EnableEngine", "EngineHookCount", "EnableImGuiBackend", "EnablePluginOverlayWindows",
|
||||
"EnableHangMinidump", "DrawCustomVitalBars", "PreventIdleLogoff", "LoggingLevel",
|
||||
// Save() writes these only when non-default, so copying them through would duplicate keys.
|
||||
"DecalBridge", "DecalInGameImGui", "DecalStandDown",
|
||||
};
|
||||
|
||||
/// <summary>Writes every top-level engine.json field not in <see cref="OwnedFields"/> as-is.</summary>
|
||||
private static void CopyUnownedFields(Utf8JsonWriter w)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(SettingsPath)) return;
|
||||
using var doc = JsonDocument.Parse(File.ReadAllText(SettingsPath));
|
||||
if (doc.RootElement.ValueKind != JsonValueKind.Object) return;
|
||||
foreach (JsonProperty p in doc.RootElement.EnumerateObject())
|
||||
{
|
||||
if (Array.IndexOf(OwnedFields, p.Name) >= 0) continue;
|
||||
p.WriteTo(w);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Unreadable file: write only the owned fields (previous behaviour).
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>engine.json "DecalBridge" (see <see cref="EngineSettings.DecalBridgeMode"/>).</summary>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@
|
|||
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
|
||||
<OutputType>Library</OutputType>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<!-- Unreachable code (CS0162) is always a bug here: a misplaced statement after a return
|
||||
once left the plugin render snapshot unpublished and silently disabled every overlay window. -->
|
||||
<WarningsAsErrors>$(WarningsAsErrors);CS0162</WarningsAsErrors>
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<NativeLib>Shared</NativeLib>
|
||||
|
|
@ -66,6 +69,8 @@
|
|||
<PackageReference Include="Avalonia.Desktop" Version="11.2.3" />
|
||||
<PackageReference Include="Avalonia.Skia" Version="11.2.3" />
|
||||
<PackageReference Include="Avalonia.Themes.Simple" Version="11.2.3" />
|
||||
<!-- Overrides Avalonia.FreeDesktop transitive Tmds.DBus.Protocol (NU1903 / GHSA-xrw6-gwf8-vvr9). -->
|
||||
<PackageReference Include="Tmds.DBus.Protocol" Version="0.21.3" />
|
||||
<PackageReference Include="Avalonia.AvaloniaEdit" Version="11.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
@ -159,4 +164,9 @@
|
|||
SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Install-location resolver (installer-chosen RynthCore / RynthSuite folders). -->
|
||||
<Compile Include="..\RynthCore.App\RynthInstallPaths.cs" Link="Shared\RynthInstallPaths.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -4,73 +4,58 @@ namespace RynthCore.Engine;
|
|||
|
||||
/// <summary>
|
||||
/// Centralised logging — every log call in the Engine routes through here.
|
||||
/// Toggle categories on/off at runtime to suppress entire subsystems.
|
||||
/// Messages keep their existing prefix text (e.g. "D3D9VTable: scanning…").
|
||||
/// Each category method writes at that category's emit level (engine.json "LogCategories",
|
||||
/// editable live from the launcher; see <see cref="LogSettings"/>), gated by the global
|
||||
/// "LoggingLevel". Messages keep their existing prefix text (e.g. "D3D9VTable: scanning…").
|
||||
/// </summary>
|
||||
internal static class RynthLog
|
||||
{
|
||||
// ── Category toggles (flip to false to silence a subsystem) ──────────
|
||||
|
||||
internal static bool D3D9Enabled = true;
|
||||
internal static bool CompatEnabled = true;
|
||||
internal static bool RenderEnabled = false; // ImGui, DX9Backend, Win32Backend
|
||||
internal static bool PluginEnabled = true;
|
||||
internal static bool UIEnabled = true;
|
||||
|
||||
// ── Category methods ─────────────────────────────────────────────────
|
||||
|
||||
/// <summary>D3D9 subsystem: vtable, EndScene, bootstrapper, matrix capture, nav3D.</summary>
|
||||
internal static void D3D9(string msg)
|
||||
{
|
||||
if (D3D9Enabled) Write(msg);
|
||||
}
|
||||
internal static void D3D9(string msg) => WriteCategory(LogCategory.D3D9, msg);
|
||||
|
||||
/// <summary>Compatibility hooks: SmartBox, client objects, combat, movement, vitals, chat, etc.</summary>
|
||||
internal static void Compat(string msg)
|
||||
{
|
||||
if (CompatEnabled) Write(msg);
|
||||
}
|
||||
internal static void Compat(string msg) => WriteCategory(LogCategory.Compat, msg);
|
||||
|
||||
/// <summary>ImGui rendering: context, DX9 backend, Win32 input, shell.</summary>
|
||||
internal static void Render(string msg)
|
||||
{
|
||||
if (RenderEnabled) Write(msg);
|
||||
}
|
||||
internal static void Render(string msg) => WriteCategory(LogCategory.Render, msg);
|
||||
|
||||
/// <summary>Plugin system: loader, manager, lifecycle callbacks.</summary>
|
||||
internal static void Plugin(string msg)
|
||||
{
|
||||
if (PluginEnabled) Write(msg);
|
||||
}
|
||||
/// <summary>Plugin system: loader, manager, lifecycle callbacks, plugin host Log lines.</summary>
|
||||
internal static void Plugin(string msg) => WriteCategory(LogCategory.Plugin, msg);
|
||||
|
||||
/// <summary>UI / Avalonia overlay subsystem.</summary>
|
||||
internal static void UI(string msg)
|
||||
{
|
||||
if (UIEnabled) Write(msg);
|
||||
}
|
||||
internal static void UI(string msg) => WriteCategory(LogCategory.UI, msg);
|
||||
|
||||
/// <summary>Verbose-only log (any category). Only written when VerboseLogging is on.</summary>
|
||||
internal static void Verbose(string msg)
|
||||
{
|
||||
if (EntryPoint.VerboseLogging) Write(msg);
|
||||
}
|
||||
/// <summary>Verbose detail (any subsystem). Debug by default; set the Verbose category to Info to see it in the normal log.</summary>
|
||||
internal static void Verbose(string msg) => WriteCategory(LogCategory.Verbose, msg);
|
||||
|
||||
/// <summary>Always-on log for critical / uncategorised messages (INFO).</summary>
|
||||
internal static void Info(string msg) => Write(msg);
|
||||
/// <summary>Same as <see cref="Verbose"/>.</summary>
|
||||
internal static void Debug(string msg) => WriteCategory(LogCategory.Verbose, msg);
|
||||
|
||||
/// <summary>Trace-level line: written only when the global level is Trace.</summary>
|
||||
internal static void Trace(string msg) => WriteAt(EntryPoint.EngineLogLevel.Trace, msg);
|
||||
|
||||
/// <summary>Uncategorised line (General category, Info by default).</summary>
|
||||
internal static void Info(string msg) => WriteCategory(LogCategory.General, msg);
|
||||
|
||||
/// <summary>Same as <see cref="Warn"/>.</summary>
|
||||
internal static void Warning(string msg) => Warn(msg);
|
||||
|
||||
// Most recent WRN/ERR text + when, surfaced via the GetEngineStatusJson host bridge so a stuck box
|
||||
// can be diagnosed remotely without reading the PC log.
|
||||
// can be diagnosed remotely without reading the PC log. Recorded even when the line is filtered.
|
||||
internal static volatile string? LastIssue;
|
||||
internal static DateTime LastIssueUtc;
|
||||
|
||||
/// <summary>Always-on WARN line — a recoverable problem worth grepping for.</summary>
|
||||
/// <summary>WARN line — a recoverable problem worth grepping for. Hidden only at level Error/Off.</summary>
|
||||
internal static void Warn(string msg)
|
||||
{
|
||||
LastIssue = msg; LastIssueUtc = DateTime.UtcNow;
|
||||
EntryPoint.LogTagged("engine", msg, "WRN");
|
||||
if (EntryPoint.ShouldLog(EntryPoint.EngineLogLevel.Warning))
|
||||
EntryPoint.LogTagged("engine", msg, "WRN");
|
||||
}
|
||||
|
||||
/// <summary>Always-on ERROR line — a fault/crash/disable. Triage with grep "[ERR]".</summary>
|
||||
/// <summary>Always-on ERROR line — a fault/crash/disable, written even at level Off. Triage with grep "[ERR]".</summary>
|
||||
internal static void Error(string msg)
|
||||
{
|
||||
LastIssue = msg; LastIssueUtc = DateTime.UtcNow;
|
||||
|
|
@ -154,7 +139,24 @@ internal static class RynthLog
|
|||
: $"thread {Environment.CurrentManagedThreadId}";
|
||||
}
|
||||
|
||||
/// <summary>True when a line in <paramref name="category"/> would be written (guard expensive messages).</summary>
|
||||
internal static bool IsEnabled(LogCategory category) => LogSettings.IsEnabled(category);
|
||||
|
||||
// ── Sink ─────────────────────────────────────────────────────────────
|
||||
|
||||
private static void Write(string message) => EntryPoint.Log(message);
|
||||
/// <summary>Uncategorised line (General category); used by the Move/UseDone traces.</summary>
|
||||
private static void Write(string? message)
|
||||
{
|
||||
if (message != null)
|
||||
WriteCategory(LogCategory.General, message);
|
||||
}
|
||||
|
||||
private static void WriteCategory(LogCategory category, string message)
|
||||
=> WriteAt(LogSettings.LevelFor(category), message);
|
||||
|
||||
private static void WriteAt(EntryPoint.EngineLogLevel level, string message)
|
||||
{
|
||||
if (EntryPoint.ShouldLog(level))
|
||||
EntryPoint.LogTagged("engine", message, LogSettings.Tag(level));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,7 +231,8 @@ internal static unsafe class MetaCommands
|
|||
/// <summary>Names, hints and .af keywords shared by the Meta faces (mirror RynthSuite's MetaSchema).</summary>
|
||||
internal static class MetaVocabulary
|
||||
{
|
||||
public const string MetaFolder = @"C:\Games\RynthSuite\RynthAi\MetaFiles";
|
||||
/// <summary>RynthAi's meta folder under the installed RynthSuite folder (installer-chosen).</summary>
|
||||
public static string MetaFolder => System.IO.Path.Combine(RynthCore.Install.RynthInstallPaths.RynthAiDir, "MetaFiles");
|
||||
|
||||
public static readonly string[] ConditionNames =
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue