RynthCore as of 2026-11-15 (internal 59d7e08): release 2026.11.15.2

This commit is contained in:
Tom Bohar 2026-11-15 19:47:05 -05:00
commit 8b09539bb6
9 changed files with 376 additions and 52 deletions

View file

@ -497,8 +497,9 @@ internal static class EngineSettings
}
/// <summary>"RememberAcWindowPosition" in engine.json (default false, opt-in): save the Asheron's
/// Call window's position and size per character and put it back at the next login.
/// Set in game in Settings > Game Client.</summary>
/// Call window's position per character and put it back at the next login (UI/AcWindowChrome).
/// Set in game in Settings > Game Client. Since 2026-11-15 (R-20261115-160655-1201) never its
/// size; while it is on, the launcher leaves the window's position alone (it reads this key).</summary>
public static bool RememberAcWindowPosition
{
get

View file

@ -107,6 +107,8 @@
<Compile Include="..\RynthCore.App\CharacterCacheStore.cs" Link="Shared\CharacterCacheStore.cs" />
<Compile Include="..\RynthCore.App\SessionStateStore.cs" Link="Shared\SessionStateStore.cs" />
<Compile Include="..\RynthCore.App\BuildVersion.cs" Link="Shared\BuildVersion.cs" />
<!-- The AC window's position rule, shared with the launcher (UI/AcWindowChrome.cs, 2026-11-15: position only, saved once it held 30 s). -->
<Compile Include="..\RynthCore.App\AcWindowPlacementRule.cs" Link="Shared\AcWindowPlacementRule.cs" />
<!-- DXT1/3/5 for AC icons in script windows (UI/ScriptWindows/AcIconDecoder.cs); the StatusAgent's decoder (RynthCore's own, MIT). -->
<Compile Include="..\RynthCore.StatusAgent\Dat\DxtUtil.cs" Link="Shared\DxtUtil.cs" />
<!-- The byte-ring protocol shared with the Decal bridge plugin (docs/DECAL_BRIDGE_PLAN.md). -->

View file

@ -7,7 +7,10 @@
// window's style from before, which outlives an in-process engine hot reload
// and dies with the process. No marker and the setting off = hands off.
// - Remember placement (opt-in): persist the outer window rect per client
// (ac_window.<server-character>.txt) and put it back once after login.
// (ac_window.<server-character>.txt) and put its POSITION back once after login.
// Since 2026-11-15 (report R-20261115-160655-1201) never its size, and a rect is
// saved only in the world once it held for 30 s: see AcWindowChromePolicy.
// While this is on, the launcher leaves the window's position to the engine.
// Original: SilentKelpie (RynthCore PR 6). Decisions live in AcWindowChromePolicy.
//
// Threading. Tick runs inside EndScene (the render callback) and only READS there
@ -24,6 +27,7 @@ using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using RynthCore.App;
using RynthCore.Engine.Compatibility;
using RynthCore.Engine.Plugins;
using static RynthCore.Engine.UI.AcWindowChromePolicy;
@ -45,18 +49,29 @@ internal static class AcWindowChrome
private const string PlacementDoneProp = "RynthCore.AcWindowChrome.PlacementRestored";
private const long TickIntervalMs = 2000;
private const long SaveIntervalMs = 10000;
private const long NoKeyFallbackMs = 90000; // no character this long: use the shared file
private const long PostStuckMs = 10000; // a posted job that never ran may be posted again
private const long StyleRetryMs = 10000; // a style change that does not stick is not retried every tick
private static readonly object Sync = new();
private static readonly Action PostedWork = RunOnGameThread;
private static long _nextTickMs, _nextSaveMs, _firstTickMs, _workPostedAtMs, _nextStyleActionMs;
private static long _nextTickMs, _firstTickMs, _workPostedAtMs, _nextStyleActionMs;
private static int _workPosted;
private static Rect? _lastWritten;
private static bool _loggedNoExecutor;
// Placement (under Sync). The saved rect, read once per key; the restore's clocks; what a new
// rect is compared with (the saved rect, else the first one seen in the world) and the rect
// waiting out AcWindowPlacementRule.StableFor. A hot reload resets them, which is fine: the
// PlacementDoneProp on the HWND keeps the restore from running twice.
private static string? _savedKey;
private static bool _savedLoaded;
private static Rect? _saved;
private static long _restoreWatchStartMs, _sizeSinceMs;
private static int _sizeW, _sizeH;
private static Rect? _reference;
private static bool _referenceSet;
private static AcWindowPlacementRule.Pending? _pending;
// ── Frame loop (EndScene): reads + posts only ────────────────────────
/// <summary>Call from the frame loop; throttled. Never changes the window itself.</summary>
@ -86,7 +101,8 @@ internal static class AcWindowChrome
&& DecideBorderless(EngineSettings.BorderlessWindowed, ReadMarker(hwnd), style,
LooksExclusiveFullscreen(hwnd, style)).Action != ChromeAction.None;
if (EngineSettings.RememberAcWindowPosition && !PlacementDone(hwnd) && KeyReady(now, out _))
// Posted every tick until the restore is decided: it waits for AC's size to settle.
if (EngineSettings.RememberAcWindowPosition && !PlacementDone(hwnd) && InWorld() && KeyReady(now, out _))
work = true;
if (work) PostWork(now);
@ -182,38 +198,69 @@ internal static class AcWindowChrome
private static void TryRestorePlacement(IntPtr hwnd)
{
if (!KeyReady(Environment.TickCount64, out string? key)) return; // still at the login screen
// One attempt per window, even a skipped one; the HWND carries it across a hot reload.
long now = Environment.TickCount64;
if (!InWorld() || !KeyReady(now, out string? key)) return; // login screen / character select
if (_restoreWatchStartMs == 0) _restoreWatchStartMs = now;
if (!GetWindowRect(hwnd, out RECT wr)) return;
var cur = new Rect(wr.Left, wr.Top, wr.Right, wr.Bottom);
if (cur.Width != _sizeW || cur.Height != _sizeH)
{
_sizeW = cur.Width;
_sizeH = cur.Height;
_sizeSinceMs = now;
}
Rect? saved = LoadSaved(key);
var d = DecideRestore(saved, IsIconic(hwnd) || IsZoomed(hwnd),
LooksExclusiveFullscreen(hwnd, GetWindowLong(hwnd, GwlStyle)), cur,
TimeSpan.FromMilliseconds(now - _sizeSinceMs), TimeSpan.FromMilliseconds(now - _restoreWatchStartMs),
WorkAreas());
if (d.Action == AcWindowPlacementRule.RestoreAction.Wait) return; // asked again next tick
// One decision per window, even a skipped one; the HWND carries it across a hot reload.
SetProp(hwnd, PlacementDoneProp, new IntPtr(1));
SetReference(saved);
if (d.Action == AcWindowPlacementRule.RestoreAction.Move && saved is Rect from)
{
// SWP_NOSIZE: AC sizes its own window from its resolution; a smaller window crops the
// picture and leaves the HUD out of reach (R-20261115-160655-1201).
SetWindowPos(hwnd, IntPtr.Zero, d.X, d.Y, 0, 0, SwpNosize | SwpNozorder | SwpNoactivate);
RynthLog.UI(d.Clamped
? FormattableString.Invariant($"AcWindowChrome: restored AC window position to ({d.X},{d.Y}), pulled onto the screen from ({from.Left},{from.Top}); size left to AC ({cur.Width}x{cur.Height}).")
: FormattableString.Invariant($"AcWindowChrome: restored AC window position to ({d.X},{d.Y}); size left to AC ({cur.Width}x{cur.Height})."));
}
else if (saved is Rect sv)
{
RynthLog.UI(FormattableString.Invariant(
$"AcWindowChrome: saved position ({sv.Left},{sv.Top}) not restored ({d.Why}); leaving AC where it is."));
}
}
if (IsIconic(hwnd) || IsZoomed(hwnd)) return;
/// <summary>The saved rect for this client, read once per key (null: none, or unreadable).</summary>
private static Rect? LoadSaved(string? key)
{
if (_savedLoaded && string.Equals(_savedKey, key, StringComparison.Ordinal)) return _saved;
_savedLoaded = true;
_savedKey = key;
_saved = null;
string path = PlacementPath(key);
if (!File.Exists(path)) return;
Rect saved;
try
{
if (!TryParsePlacement(File.ReadAllLines(path), out saved)) return;
if (File.Exists(path) && TryParsePlacement(File.ReadAllLines(path), out Rect r))
_saved = r;
}
catch (Exception ex)
{
try { RynthLog.UI($"AcWindowChrome: read placement failed - {ex.Message}"); } catch { }
return;
}
return _saved;
}
PlacementVerdict v = EvaluatePlacement(true, LooksExclusiveFullscreen(hwnd, GetWindowLong(hwnd, GwlStyle)),
saved, Monitors());
if (v != PlacementVerdict.Ok)
{
RynthLog.UI($"AcWindowChrome: saved placement not restored ({v}); leaving AC where it is.");
return;
}
SetWindowPos(hwnd, IntPtr.Zero, saved.Left, saved.Top, saved.Width, saved.Height,
SwpNozorder | SwpNoactivate);
_lastWritten = saved;
RynthLog.UI(FormattableString.Invariant(
$"AcWindowChrome: restored AC window to ({saved.Left},{saved.Top}) {saved.Width}x{saved.Height}."));
private static void SetReference(Rect? r)
{
_reference = r;
_referenceSet = true;
_pending = null;
}
// ── Saving the rect (read on the render thread, written in the background) ──
@ -221,23 +268,47 @@ internal static class AcWindowChrome
private static void MaybeSavePlacement(IntPtr hwnd, long now, int style)
{
if (!EngineSettings.RememberAcWindowPosition) return;
if (now < _nextSaveMs) return;
// Not before the restore attempt: it would overwrite the saved rect with the launch position.
// Not before the restore is decided: it would overwrite the saved rect with the launch position.
if (!PlacementDone(hwnd)) return;
_nextSaveMs = now + SaveIntervalMs;
TrySavePlacement(hwnd, style, now, force: false);
}
private static void TrySavePlacement(IntPtr hwnd, int style, long now, bool force)
{
if (!KeyReady(now, out string? key)) return;
if (IsIconic(hwnd) || IsZoomed(hwnd)) return;
if (!GetWindowRect(hwnd, out RECT wr)) return;
var cur = new Rect(wr.Left, wr.Top, wr.Right, wr.Bottom);
PlacementVerdict v = EvaluatePlacement(true, LooksExclusiveFullscreen(hwnd, style), cur, Monitors());
if (!force && !ShouldWritePlacement(v, cur, _lastWritten)) return;
if (v != PlacementVerdict.Ok) return;
_lastWritten = cur;
bool saveable = !IsIconic(hwnd) && !IsZoomed(hwnd) && !LooksExclusiveFullscreen(hwnd, style);
bool inWorld = InWorld();
bool baselineOk = inWorld && saveable && AcWindowPlacementRule.IsCapturable(ToPlacement(cur));
lock (Sync)
{
// After a hot reload the restore was decided by the old engine: start from the saved rect.
if (!_referenceSet) SetReference(LoadSaved(key));
if (_reference is null && !force)
{
// Nothing saved: the first rect in the world is AC's own placement, never saved
// until the player moves the window away from it (as in the launcher).
if (baselineOk) _reference = cur;
return;
}
var d = DecideSave(inWorld, saveable, force, cur, _reference, ref _pending, DateTime.UtcNow);
if (d.Action == AcWindowPlacementRule.SaveAction.LoginShrink)
{
if (d.FirstSeen && _reference is Rect rf)
RynthLog.UI(FormattableString.Invariant(
$"AcWindowChrome: not saving {cur.Width}x{cur.Height}, under half the in-game {rf.Width}x{rf.Height} (the login / character-select window)."));
return;
}
if (d.Action != AcWindowPlacementRule.SaveAction.Save) return;
// Off-screen (a monitor that is gone) or absurd: not worth saving.
if (EvaluatePlacement(true, false, cur, Monitors()) != PlacementVerdict.Ok) return;
_reference = cur;
}
string path = PlacementPath(key);
UiBackgroundWriter.Enqueue("ac window placement", () => WritePlacement(path, cur));
}
@ -301,6 +372,16 @@ internal static class AcWindowChrome
// ── Helpers ──────────────────────────────────────────────────────────
/// <summary>
/// In the world after a login: not the login screen, not character select (where AC's window
/// is its small 800x600 one), not AC closing. A mode not seen yet counts as the world, as
/// elsewhere in the engine; the 30 s rule and the login-shrink guard cover that gap.
/// </summary>
private static bool InWorld()
=> LoginLifecycleHooks.HasObservedLoginComplete
&& UiFlowHooks.InWorldOrUnknown
&& !UiFlowHooks.ClientCleanupStarted;
private static bool KeyReady(long now, out string? key)
=> TryResolveKey(SessionStateRegistry.LastServerName, SessionStateRegistry.LastCharacterName,
_firstTickMs == 0 ? 0 : now - _firstTickMs, NoKeyFallbackMs, out key);
@ -344,14 +425,22 @@ internal static class AcWindowChrome
&& Math.Abs(wr.Top - mi.rcMonitor.Top) <= 4;
}
private static List<Rect> Monitors()
private static List<Rect> Monitors() => EnumMonitors(work: false);
/// <summary>Each monitor's work area (the screen minus the taskbar): where a restored window is pulled onto.</summary>
private static List<Rect> WorkAreas() => EnumMonitors(work: true);
private static List<Rect> EnumMonitors(bool work)
{
var list = new List<Rect>(4);
EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, (IntPtr mon, IntPtr dc, ref RECT rc, IntPtr data) =>
{
var mi = new MONITORINFO { cbSize = Marshal.SizeOf<MONITORINFO>() };
if (GetMonitorInfo(mon, ref mi))
list.Add(new Rect(mi.rcMonitor.Left, mi.rcMonitor.Top, mi.rcMonitor.Right, mi.rcMonitor.Bottom));
{
RECT m = work ? mi.rcWork : mi.rcMonitor;
list.Add(new Rect(m.Left, m.Top, m.Right, m.Bottom));
}
return true;
}, IntPtr.Zero);
return list;

View file

@ -5,7 +5,9 @@
// - Borderless windowed: what to do given the setting, the "we stripped it" marker
// and the window's current style bits.
// - Window position: whether a saved or current rect is worth restoring / saving,
// and which file a client's rect lives in.
// and which file a client's rect lives in. Since 2026-11-15 the restore and the
// save follow the launcher's AcWindowPlacementRule (src\RynthCore.App, compiled in):
// position only, and a rect is saved only once it held for 30 s.
// AcWindowChrome does the Win32 work and asks these first.
// Idea and first version: SilentKelpie (RynthCore PR 6).
// ============================================================================
@ -14,6 +16,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using RynthCore.App;
namespace RynthCore.Engine.UI;
@ -96,7 +99,8 @@ internal static class AcWindowChromePolicy
internal enum PlacementVerdict { Ok, OptedOut, ExclusiveFullscreen, TooSmall, TooLarge, OffScreen }
/// <summary>
/// Whether <paramref name="r"/> is a rect worth saving or restoring. Off-screen rects (a monitor
/// Whether <paramref name="r"/> is a rect worth saving (since 2026-11-15 a restore pulls a saved
/// position onto the screen instead: DecideRestore). Off-screen rects (a monitor
/// that is gone) are refused: the window's centre and the middle of its top edge must both be on
/// a monitor, so neither the window nor its title bar ends up unreachable.
/// </summary>
@ -120,9 +124,84 @@ internal static class AcWindowChromePolicy
return false;
}
/// <summary>Write only when the rect is saveable and differs from what was last written.</summary>
public static bool ShouldWritePlacement(PlacementVerdict verdict, Rect current, Rect? lastWritten)
=> verdict == PlacementVerdict.Ok && (lastWritten is null || lastWritten.Value != current);
// ── Restore and save (2026-11-15) ────────────────────────────────────
//
// Report R-20261115-160655-1201: right after the 2026.11.15.1 update one player's main came
// up in a small window, cropped, with the HUD out of reach, for three launches in a row. The
// log: "AcWindowChrome: restored AC window to (296,51) 806x635" in a 2560x1600 game. This
// option saved whatever rect differed from the last one every 10 s, character select
// included (the character name is kept after a logout), so AC's 800x600 logout window
// became "the" rect, and the restore put its SIZE back with SetWindowPos. AC draws at its own
// resolution whatever the window size, so the game was cropped: the launcher's bug fixed in
// 2026.11.15.1 (AcWindowPlacementRule), here in the engine. It had not shown before because
// the launcher's put-back of a shrunk window (AcWindowRestoreRule, removed in that release)
// resized the window again right after. So, as in the launcher:
// - only the position is put back (SWP_NOSIZE), and only when the window is about the size
// the position was saved at; it waits for AC's size to settle and gives up after 60 s;
// - the position is pulled onto a monitor's work area at the window's real size;
// - a rect is saved only in the world (never at character select), only after it held for
// 30 s, and never when it is the login-size shrink of the in-game window;
// - a profile already holding the small rect heals itself: its position is skipped (the
// sizes differ) and the real rect is saved 30 s later.
internal static AcWindowPlacementRule.Placement ToPlacement(Rect r) => new(r.Left, r.Top, r.Width, r.Height);
/// <summary>
/// What to do with the saved rect now: wait, move (position only), or leave the window where
/// AC put it. <paramref name="sinceInWorld"/> runs from the first look after the login.
/// </summary>
public static AcWindowPlacementRule.RestoreDecision DecideRestore(Rect? saved, bool minimisedOrMaximised,
bool looksExclusiveFullscreen, Rect current, TimeSpan sizeHeldFor, TimeSpan sinceInWorld,
IReadOnlyList<Rect> workAreas)
{
if (saved is not Rect sv)
return new(AcWindowPlacementRule.RestoreAction.Skip, 0, 0, false, "nothing saved");
if (minimisedOrMaximised)
return new(AcWindowPlacementRule.RestoreAction.Skip, 0, 0, false, "window minimised or maximised");
if (looksExclusiveFullscreen)
return new(AcWindowPlacementRule.RestoreAction.Skip, 0, 0, false, "window looks like exclusive fullscreen");
if (!AcWindowPlacementRule.IsCapturable(ToPlacement(current)))
{
// Parked off-screen or still tiny: AC has not shown its game window yet.
return sinceInWorld <= AcWindowPlacementRule.RestoreWatch
? new(AcWindowPlacementRule.RestoreAction.Wait, 0, 0, false, "window not shown yet")
: new(AcWindowPlacementRule.RestoreAction.Skip, 0, 0, false, "window never showed");
}
var areas = new List<AcWindowPlacementRule.WorkArea>(workAreas.Count);
foreach (Rect a in workAreas) areas.Add(new AcWindowPlacementRule.WorkArea(a.Left, a.Top, a.Right, a.Bottom));
return AcWindowPlacementRule.DecideRestore(ToPlacement(sv), current.Width, current.Height,
sizeHeldFor, sinceInWorld, areas);
}
/// <summary>
/// One look at the window for the save. <paramref name="inWorld"/> false (character select,
/// the login screen, AC closing) never saves and forgets a pending rect, so time spent at
/// character select never counts toward the 30 s. <paramref name="saveable"/> false (minimised,
/// maximised, exclusive fullscreen) likewise. <paramref name="force"/> is Save Layout Now: no
/// 30 s wait, but still never the login-size shrink. <paramref name="reference"/> is the saved
/// rect, else the first rect seen after the login (so AC's own placement is never saved until
/// the player moves the window).
/// </summary>
public static AcWindowPlacementRule.SaveDecision DecideSave(bool inWorld, bool saveable, bool force,
Rect current, Rect? reference, ref AcWindowPlacementRule.Pending? pending, DateTime nowUtc)
{
if (!inWorld || !saveable)
{
pending = null;
return new(AcWindowPlacementRule.SaveAction.None, false);
}
AcWindowPlacementRule.Placement cur = ToPlacement(current);
AcWindowPlacementRule.Placement? rf = reference is Rect r ? ToPlacement(r) : null;
if (!force)
return AcWindowPlacementRule.DecideSave(cur, rf, ref pending, nowUtc);
if (!AcWindowPlacementRule.IsCapturable(cur))
return new(AcWindowPlacementRule.SaveAction.None, false);
if (rf is AcWindowPlacementRule.Placement f && AcWindowPlacementRule.IsLoginShrink(cur.Width, cur.Height, f.Width, f.Height))
return new(AcWindowPlacementRule.SaveAction.LoginShrink, true);
pending = null;
return new(AcWindowPlacementRule.SaveAction.Save, true);
}
// ── Per-client file ──────────────────────────────────────────────────

View file

@ -1079,7 +1079,7 @@ internal static class SettingsSchema
Plugins.EngineSettings.RememberAcWindowPosition = v;
AcWindowChrome.RequestApply();
},
"On: save the Asheron's Call window's position and size for each character and put it back after you log in.\nOff (default): the game window is never moved. A saved spot that is off-screen (a monitor that is gone) is ignored."),
"On: save where the Asheron's Call window sits for each character and move it back there after you log in. The game sets the window's size from its resolution; this never changes it. While this is on, the launcher's own memory of the window's spot (per account) stands aside.\nOff (default): the engine never moves the game window. A spot off every screen (a monitor that is gone) is pulled back onto one."),
Spacer(),
Section("Performance"),
Bool("Enable FPS Limit", s => s.EnableFPSLimit, (s, v) => s.EnableFPSLimit = v, gates: true),