diff --git a/Changelog/2026-10-04-ilt-hub-button-imgui-on-top-live-logging.md b/Changelog/2026-10-04-ilt-hub-button-imgui-on-top-live-logging.md new file mode 100644 index 0000000..6229a91 --- /dev/null +++ b/Changelog/2026-10-04-ilt-hub-button-imgui-on-top-live-logging.md @@ -0,0 +1,60 @@ +# 2026-10-04 — ILT Hub panel button, ImGui windows on top, live logging levels + +Launcher 0.1.5. Needs RynthAi 0.6.18 for the RynthAi logging rows. + +## ILT Hub button (Avalonia RynthAi panel) + +* New **ILT Hub** launcher button (third row of the RynthAi panel launcher grid). + Sends `hub show` through the plugin's `RynthPluginApplyRemoteCommand` export — + the same path as typing `/ra hub show`. +* New `SendRemoteCmd(action, value)` helper marshals both strings, calls the + export and frees them (the plugin copies them and applies on its pump thread). + +## Plugin ImGui windows draw on top of the Avalonia layer + +* `EngineFrameController.RunImGuiFrame` still builds the ImGui frame at the same + point, but no longer submits the draw data. `EndSceneHook` now calls the new + `EngineFrameController.RenderDeferredImGui()` **after** + `OverlayTextureRenderer.Render`, so the plugin overlay windows (ILT Hub, Item + Info, ...) are drawn over the Avalonia panels. +* Input follows the new stacking: when ImGui is hovered or has an active widget, + mouse messages go to ImGui instead of the Avalonia panel underneath + (`Win32Backend.ImGuiOwnsMouseOverAvalonia`). An Avalonia drag/resize already + in progress keeps its capture so the release is never lost. +* Nothing is submitted twice: the pending draw is cleared at the start of each + ImGui frame and after submission. + +## Live, per-category logging (engine + launcher) + +### Engine + +* New `LogSettings` reads engine.json: + * `"LoggingLevel"`: global threshold, now including **Off** + (Off, Error, Warning, Info, Debug, Trace; `Verbose`/`Warn` accepted). + * `"LogCategories"`: per-category emit level (Off, Trace, Debug, Info) for + General, D3D9, Compat, Render, Plugin, UI, Verbose. A category's lines are + written at its level, so a Trace/Debug category set to **Info** shows in the + normal log, and **Off** silences it. +* A background thread polls engine.json once a second and reloads on change + (logs `LogSettings: engine.json changed - logging reloaded (...)`). Stopped in + `EngineLifecycle.Shutdown` before unload. +* `RynthLog` category methods route through the category levels (the hard-coded + `*Enabled` booleans are gone; defaults are unchanged: Render Off, Verbose Debug, + everything else Info). +* Lines are tagged with their real level: `[DBG]` and `[TRC]` instead of `[INF]`. +* `Warn` is now hidden at level Error/Off; `Error` is always written. + `LastIssue` is still recorded for filtered warnings. +* `EngineSettings.Save()` now copies through engine.json fields it doesn't own + (e.g. `LogCategories`, `EnableDcompOverlay`) instead of dropping them. + +### Launcher (Runtime tab) + +* **Logging level** box gains **Off**, and applies immediately (writes + engine.json on change; no Save needed). Unknown saved values fall back to Info. +* New **Logging** card, every change saved immediately and applied live: + * Engine categories: Off / Trace / Debug / Info per category. + * RynthAi categories: Off / Trace / Info per category (diagnostics.json). + * RynthAi key events: Off / Trace / Info per event (diagnostics.json). + * Reload button re-reads both files. +* New `LoggingSettingsStore` does the read-modify-write of both files + (atomic temp-file swap for diagnostics.json, every other field preserved). diff --git a/src/RynthCore.App.Avalonia/LoggingSettingsStore.cs b/src/RynthCore.App.Avalonia/LoggingSettingsStore.cs new file mode 100644 index 0000000..eb3b801 --- /dev/null +++ b/src/RynthCore.App.Avalonia/LoggingSettingsStore.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using System.Text.Json.Nodes; +using RynthCore.Install; + +namespace RynthCore.App.Avalonia; + +/// +/// Launcher-side access to every live logging switch: +/// +/// Engine: engine.json "LoggingLevel" (global threshold) and "LogCategories" (per-category emit +/// level). The engine polls engine.json once a second, so edits apply to running clients. +/// RynthAi: Logs\Diagnostics\diagnostics.json "Categories" and "Events" (Off / Trace / Info). +/// RynthAi polls it every couple of seconds and rewrites it with the full catalog on load. +/// +/// +internal static class LoggingSettingsStore +{ + /// One engine log category as shown in the launcher. + internal readonly record struct EngineCategory(string Name, string DefaultLevel, string Description); + + /// One RynthAi category / event row read from diagnostics.json. + internal sealed record DiagnosticsRow(string Key, string Level, string Description); + + /// Global level choices (engine.json "LoggingLevel"), most to least quiet. + internal static readonly string[] GlobalLevels = { "Off", "Error", "Warning", "Info", "Debug", "Trace" }; + + /// Engine category emit levels. Info = normal log; Debug/Trace show only at that global level. + internal static readonly string[] EngineCategoryLevels = { "Off", "Trace", "Debug", "Info" }; + + /// RynthAi category / event levels: Off, Trace (trace file only), Info (also the normal log). + internal static readonly string[] RynthAiLevels = { "Off", "Trace", "Info" }; + + /// Must match RynthCore.Engine.LogCategory names and LogSettings defaults. + internal static readonly EngineCategory[] EngineCategories = + { + new("General", "Info", "Uncategorised engine lines."), + new("D3D9", "Info", "D3D9 hook, EndScene, bootstrapper, matrix capture, nav markers."), + new("Compat", "Info", "Client hooks: objects, combat, movement, vitals, chat."), + new("Render", "Off", "ImGui rendering and Win32 input (very chatty)."), + new("Plugin", "Info", "Plugin loader/manager and every plugin host Log line."), + new("UI", "Info", "Avalonia overlay and panels."), + new("Verbose", "Debug", "Detail lines across all subsystems (Info = always in the normal log)."), + }; + + private const string EngineCategoriesProperty = "LogCategories"; + + /// RynthAi's diagnostics.json (created by RynthAi on its first load). + internal static string DiagnosticsPath => + Path.Combine(RynthInstallPaths.RynthAiDir, "Logs", "Diagnostics", "diagnostics.json"); + + // ── Engine ────────────────────────────────────────────────────────── + + /// Current engine category levels; categories missing from engine.json get their defaults. + internal static Dictionary ReadEngineCategoryLevels() + { + var result = new Dictionary(StringComparer.OrdinalIgnoreCase); + foreach (EngineCategory c in EngineCategories) result[c.Name] = c.DefaultLevel; + + Dictionary fields = EngineJsonStore.Read(); + if (fields.TryGetValue(EngineCategoriesProperty, out JsonElement cats) && cats.ValueKind == JsonValueKind.Object) + { + foreach (JsonProperty p in cats.EnumerateObject()) + { + if (p.Value.ValueKind == JsonValueKind.String && result.ContainsKey(p.Name)) + result[p.Name] = p.Value.GetString() ?? result[p.Name]; + } + } + return result; + } + + /// Sets one engine category level in engine.json, preserving every other field. + internal static void SetEngineCategoryLevel(string category, string level) + { + Dictionary levels = ReadEngineCategoryLevels(); + levels[category] = level; + + using var ms = new MemoryStream(); + using (var w = new Utf8JsonWriter(ms)) + { + w.WriteStartObject(); + foreach (EngineCategory c in EngineCategories) + w.WriteString(c.Name, levels[c.Name]); + w.WriteEndObject(); + } + + Dictionary fields = EngineJsonStore.Read(); + using var doc = JsonDocument.Parse(ms.ToArray()); + fields[EngineCategoriesProperty] = doc.RootElement.Clone(); + EngineJsonStore.Write(fields); + } + + // ── RynthAi ───────────────────────────────────────────────────────── + + /// + /// Reads RynthAi's category and event rows. Returns false (with empty lists) when diagnostics.json + /// does not exist yet or cannot be parsed (e.g. RynthAi is mid-write; retry later). + /// + internal static bool TryReadRynthAi(out List categories, out List events, out string? error) + { + categories = new List(); + events = new List(); + error = null; + try + { + if (!File.Exists(DiagnosticsPath)) + { + error = "diagnostics.json not found - start RynthAi once to create it."; + return false; + } + if (JsonNode.Parse(File.ReadAllText(DiagnosticsPath)) is not JsonObject root) + { + error = "diagnostics.json is not a JSON object."; + return false; + } + ReadRows(root["Categories"] as JsonArray, "Name", categories); + ReadRows(root["Events"] as JsonArray, "Key", events); + if (categories.Count == 0) + error = "diagnostics.json has no category list - update RynthAi to 0.6.18 or later."; + return true; + } + catch (Exception ex) + { + error = $"diagnostics.json unreadable ({ex.GetType().Name}: {ex.Message})."; + return false; + } + } + + /// Sets a RynthAi category level ("Off", "Trace", "Info") and keeps "Traces" in sync. + internal static void SetRynthAiCategoryLevel(string category, string level) + => UpdateDiagnostics("Categories", "Name", category, level); + + /// Sets a RynthAi key-event level ("Off", "Trace", "Info"). + internal static void SetRynthAiEventLevel(string eventKey, string level) + => UpdateDiagnostics("Events", "Key", eventKey, level); + + private static void ReadRows(JsonArray? array, string keyField, List into) + { + if (array == null) return; + foreach (JsonNode? node in array) + { + if (node is not JsonObject o) continue; + string key = o[keyField]?.GetValue() ?? string.Empty; + if (key.Length == 0) continue; + into.Add(new DiagnosticsRow( + key, + o["Level"]?.GetValue() ?? "Off", + o["Description"]?.GetValue() ?? string.Empty)); + } + } + + /// Read-modify-write of one row's Level; every other field in the file is preserved. + private static void UpdateDiagnostics(string section, string keyField, string key, string level) + { + string path = DiagnosticsPath; + if (JsonNode.Parse(File.ReadAllText(path)) is not JsonObject root) + throw new InvalidDataException("diagnostics.json is not a JSON object."); + if (root[section] is not JsonArray rows) + throw new InvalidDataException($"diagnostics.json has no \"{section}\" list."); + + bool found = false; + foreach (JsonNode? node in rows) + { + if (node is JsonObject o && string.Equals(o[keyField]?.GetValue(), key, StringComparison.OrdinalIgnoreCase)) + { + o["Level"] = level; + found = true; + } + } + if (!found) + throw new KeyNotFoundException($"\"{key}\" is not in diagnostics.json {section}."); + + // RynthAi reads Categories when present, but older readers (and /ra trace status) use Traces. + if (section == "Categories") + { + var traces = new JsonArray(); + foreach (JsonNode? node in rows) + { + if (node is JsonObject o && !string.Equals(o["Level"]?.GetValue(), "Off", StringComparison.OrdinalIgnoreCase)) + traces.Add(o["Name"]?.GetValue()); + } + root["Traces"] = traces; + } + + // Atomic swap so RynthAi's poll never reads a half-written file. + string tmp = path + ".tmp"; + File.WriteAllText(tmp, root.ToJsonString(new JsonSerializerOptions { WriteIndented = false })); + File.Move(tmp, path, overwrite: true); + } +} diff --git a/src/RynthCore.App.Avalonia/MainWindow.Logging.cs b/src/RynthCore.App.Avalonia/MainWindow.Logging.cs new file mode 100644 index 0000000..90abc2c --- /dev/null +++ b/src/RynthCore.App.Avalonia/MainWindow.Logging.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using Avalonia.Controls; +using Avalonia.Layout; +using Avalonia.Media; + +namespace RynthCore.App.Avalonia; + +/// +/// Runtime tab → Logging card and the live global Logging level box. Every change is written +/// straight to engine.json / diagnostics.json (see ); running +/// clients poll those files, so nothing needs a restart or the Save button. +/// +internal partial class MainWindow +{ + private static readonly IBrush LogNameBrush = new SolidColorBrush(Color.Parse("#EAF0F4")); + private static readonly IBrush LogMutedBrush = new SolidColorBrush(Color.Parse("#9AA8B3")); + + // Set while the rows are being (re)built so programmatic selections don't write files. + private bool _suppressLoggingEvents; + + /// Wires the Logging card and the live global level box. Called once after LoadRuntimeControls. + private void InitLoggingControls() + { + LoggingLevelComboBox.SelectionChanged += (_, _) => OnGlobalLoggingLevelChanged(); + ReloadLoggingButton.Click += (_, _) => BuildLoggingRows(); + BuildLoggingRows(); + } + + /// Global level changed: persist to the launcher settings and push to engine.json now. + private void OnGlobalLoggingLevelChanged() + { + if (_suppressLoggingEvents) return; + string level = GetSelectedLoggingLevel(); + if (string.Equals(level, _settings.LoggingLevel, StringComparison.OrdinalIgnoreCase)) return; + try + { + _settings.LoggingLevel = level; + SaveSettings(); + EngineJsonStore.SetString("LoggingLevel", level); + AppendActivity($"Logging level set to {level} (applied live to running clients)."); + } + catch (Exception ex) + { + AppendActivity($"Failed to save logging level: {ex.Message}"); + } + } + + /// (Re)builds the engine category, RynthAi category and RynthAi event rows from disk. + private void BuildLoggingRows() + { + _suppressLoggingEvents = true; + try + { + EngineLogCategoriesPanel.Children.Clear(); + Dictionary engineLevels = LoggingSettingsStore.ReadEngineCategoryLevels(); + foreach (LoggingSettingsStore.EngineCategory cat in LoggingSettingsStore.EngineCategories) + { + string name = cat.Name; + EngineLogCategoriesPanel.Children.Add(BuildLoggingRow( + name, cat.Description, LoggingSettingsStore.EngineCategoryLevels, engineLevels[name], + level => + { + LoggingSettingsStore.SetEngineCategoryLevel(name, level); + AppendActivity($"Engine log category {name} set to {level} (applied live)."); + })); + } + + RynthAiLogCategoriesPanel.Children.Clear(); + RynthAiLogEventsPanel.Children.Clear(); + bool ok = LoggingSettingsStore.TryReadRynthAi( + out List categories, + out List events, + out string? error); + + foreach (LoggingSettingsStore.DiagnosticsRow row in categories) + { + string key = row.Key; + RynthAiLogCategoriesPanel.Children.Add(BuildLoggingRow( + key, row.Description, LoggingSettingsStore.RynthAiLevels, row.Level, + level => + { + LoggingSettingsStore.SetRynthAiCategoryLevel(key, level); + AppendActivity($"RynthAi log category {key} set to {level} (applied live)."); + })); + } + foreach (LoggingSettingsStore.DiagnosticsRow row in events) + { + string key = row.Key; + RynthAiLogEventsPanel.Children.Add(BuildLoggingRow( + key, row.Description, LoggingSettingsStore.RynthAiLevels, row.Level, + level => + { + LoggingSettingsStore.SetRynthAiEventLevel(key, level); + AppendActivity($"RynthAi log event {key} set to {level} (applied live)."); + })); + } + + LoggingStatusText.Text = ok && error == null + ? $"engine.json: {EngineJsonStore.Path}\ndiagnostics.json: {LoggingSettingsStore.DiagnosticsPath}" + : $"RynthAi: {error}"; + } + catch (Exception ex) + { + LoggingStatusText.Text = $"Failed to load logging settings: {ex.Message}"; + } + finally + { + _suppressLoggingEvents = false; + } + } + + /// One "Name | level box | description" row. runs on user changes only. + private Control BuildLoggingRow(string name, string description, string[] levels, string current, Action apply) + { + var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("170,110,*") }; + + grid.Children.Add(new TextBlock + { + Text = name, + Foreground = LogNameBrush, + VerticalAlignment = VerticalAlignment.Center, + }); + + var combo = new ComboBox { ItemsSource = levels, MinWidth = 100, Margin = new global::Avalonia.Thickness(0, 0, 8, 0) }; + int index = Array.FindIndex(levels, l => string.Equals(l, current, StringComparison.OrdinalIgnoreCase)); + combo.SelectedIndex = index >= 0 ? index : 0; + combo.SelectionChanged += (_, _) => + { + if (_suppressLoggingEvents || combo.SelectedItem is not string level) return; + try { apply(level); } + catch (Exception ex) + { + AppendActivity($"Failed to set {name} to {level}: {ex.Message}"); + // Show what is actually on disk; posted so the combo raising this event isn't torn down mid-handler. + global::Avalonia.Threading.Dispatcher.UIThread.Post(BuildLoggingRows); + } + }; + Grid.SetColumn(combo, 1); + grid.Children.Add(combo); + + var desc = new TextBlock + { + Text = description, + Foreground = LogMutedBrush, + TextWrapping = TextWrapping.Wrap, + VerticalAlignment = VerticalAlignment.Center, + }; + Grid.SetColumn(desc, 2); + grid.Children.Add(desc); + return grid; + } +} diff --git a/src/RynthCore.App.Avalonia/MainWindow.axaml b/src/RynthCore.App.Avalonia/MainWindow.axaml index 034b8d9..fc51aee 100644 --- a/src/RynthCore.App.Avalonia/MainWindow.axaml +++ b/src/RynthCore.App.Avalonia/MainWindow.axaml @@ -316,8 +316,10 @@ Content="Rewrite AC window titles per account" ToolTip.Tip="Replaces "Asheron's Call" with "Account / Character @ Server" on tracked clients so multi-box taskbars are readable. Untracked external clients are left alone." /> - - + + + @@ -363,6 +365,42 @@ + + + + + +