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

@ -3905,6 +3905,7 @@ internal partial class MainWindow : Window
}) + (headlessCount > 0 ? $" ({headlessCount} headless)" : string.Empty);
_sessionItems.Clear();
bool? engineRemembersWindow = null; // engine.json, read once per refresh and only with a window to place
foreach (Process process in targets.OrderBy(p => p.Id))
{
// Headless: no window, no D3D device. Listed, but none of the window steps apply.
@ -3922,7 +3923,8 @@ internal partial class MainWindow : Window
if (_settings.OverrideWindowTitle)
ApplyDesiredWindowTitle(process, activeContexts, activeSessions);
ApplyOrPersistWindowPlacement(process, graphicsReady, activeContexts, activeSessions);
engineRemembersWindow ??= EngineJsonStore.GetBool("RememberAcWindowPosition") == true;
ApplyOrPersistWindowPlacement(process, graphicsReady, activeContexts, activeSessions, engineRemembersWindow.Value);
}
if (_sessionItems.Count == 0)
@ -4986,8 +4988,24 @@ internal partial class MainWindow : Window
Process process,
bool graphicsReady,
IReadOnlyDictionary<int, LaunchContextRecord> activeContexts,
IReadOnlyDictionary<int, SessionStateRecord> activeSessions)
IReadOnlyDictionary<int, SessionStateRecord> activeSessions,
bool engineRemembersWindow)
{
// 2026-11-15, report R-20261115-160655-1201: the engine's opt-in "Remember Game Window
// Position" (engine.json RememberAcWindowPosition, AcWindowChrome) keeps its own rect per
// character, the launcher one per account. Both moving the window after a login means two
// saved spots fighting over it, each saving the other's move 30 s later. The player who
// turned the engine's option on chose it, so while it is on the launcher stays out: no
// restore and no save. The client counts as placed, so turning the option off later in
// the session only starts the saves again and never moves the window late.
if (engineRemembersWindow)
{
_windowSavePending.Remove(process.Id);
if (_windowPositionAppliedPids.Add(process.Id))
LauncherDiag.Info($"WindowPos PID {process.Id}: left to the engine (its Remember Game Window Position is on).");
return;
}
string? accountName = null;
string? serverName = null;
if (activeSessions.TryGetValue(process.Id, out SessionStateRecord? s))

View file

@ -27,6 +27,10 @@ namespace RynthCore.App;
/// - A new rect is saved only after it held for <see cref="StableFor"/>: the shrink right before
/// the client closes, and AC's own moves at startup and portal-in, never reach the profile.
/// The saved width and height are still written: they are what the size checks compare against.
///
/// 2026-11-15, report R-20261115-160655-1201: the engine's opt-in Remember Game Window Position
/// (UI/AcWindowChrome) had the same bug and now uses this rule too (compiled into the engine, so keep
/// it free of launcher types). While that option is on, the launcher leaves the window to the engine.
/// </summary>
internal static class AcWindowPlacementRule
{

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),

View file

@ -33,6 +33,8 @@
<Compile Include="..\..\src\RynthCore.Engine\Compatibility\AelrynthWire.cs" Link="Engine\AelrynthWire.cs" />
<!-- Settings > Display for the AC window: the borderless / window-position decisions (pure functions). -->
<Compile Include="..\..\src\RynthCore.Engine\UI\AcWindowChromePolicy.cs" Link="Engine\AcWindowChromePolicy.cs" />
<!-- ...and the launcher's AcWindowPlacementRule it builds on (compiled into the engine too, 2026-11-15). -->
<Compile Include="..\..\src\RynthCore.App\AcWindowPlacementRule.cs" Link="Engine\AcWindowPlacementRule.cs" />
</ItemGroup>
</Project>

View file

@ -2,6 +2,7 @@ using System.Diagnostics;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using RynthCore.App;
using RynthCore.Engine.Plugins;
using static RynthCore.Engine.UI.AcWindowChromePolicy;
@ -65,6 +66,9 @@ namespace EngineSettingsTests
Run(nameof(PanelLayoutPerCharacterDefaultOnAndSaved), PanelLayoutPerCharacterDefaultOnAndSaved);
Run(nameof(BorderlessDecisions), BorderlessDecisions);
Run(nameof(PlacementDecisions), PlacementDecisions);
Run(nameof(PlacementRestoreIsPositionOnly), PlacementRestoreIsPositionOnly);
Run(nameof(PlacementSaveNeedsAStableInWorldRect), PlacementSaveNeedsAStableInWorldRect);
Run(nameof(AcWindowChromeNeverResizes), AcWindowChromeNeverResizes);
Run(nameof(PlacementFilesArePerClient), PlacementFilesArePerClient);
Run(nameof(PlacementFileRoundTrips), PlacementFileRoundTrips);
}
@ -809,13 +813,138 @@ namespace EngineSettingsTests
Eq(EvaluatePlacement(true, false, new Rect(0, 0, 800, MinHeight - 1), one), PlacementVerdict.TooSmall, "shorter than the minimum");
Eq(EvaluatePlacement(true, false, new Rect(0, 0, MinWidth, MinHeight), one), PlacementVerdict.Ok, "exactly the minimum is fine");
Eq(EvaluatePlacement(true, false, new Rect(0, 0, MaxExtent + 1, 600), one), PlacementVerdict.TooLarge, "absurdly wide");
}
// Writes only when changed.
var r = new Rect(10, 20, 810, 620);
Check(ShouldWritePlacement(PlacementVerdict.Ok, r, null), "first rect is written");
Check(!ShouldWritePlacement(PlacementVerdict.Ok, r, r), "unchanged rect: no write");
Check(ShouldWritePlacement(PlacementVerdict.Ok, r with { Right = 900 }, r), "changed rect: written");
Check(!ShouldWritePlacement(PlacementVerdict.OffScreen, r, null), "a refused rect is never written");
// ── AcWindowChromePolicy: restore and save (2026-11-15, R-20261115-160655-1201) ──
// The report: "restored AC window to (296,51) 806x635" in a 2560x1600 game; the saved rect was
// AC's logout / character-select window, and the restore put its size back.
private static readonly Rect[] Screen2560 = { new Rect(0, 0, 2560, 1560) }; // work area: 2560x1600 minus a 40 px taskbar
private static readonly Rect LogoutRect = new(296, 51, 296 + 806, 51 + 635); // the report's saved rect (800x600 client)
private static readonly Rect InGame = new(10, 10, 10 + 1936, 10 + 1119); // a 1920x1080 game window
private static TimeSpan S(double s) => TimeSpan.FromSeconds(s);
private static void PlacementRestoreIsPositionOnly()
{
// The report's profile: a position saved for the small window never lands on the full-size one,
// and no decision carries a size at all (the window is moved with SWP_NOSIZE).
for (int t = 0; t <= 120; t += 2)
{
var d = DecideRestore(LogoutRect, false, false, InGame, S(t), S(t), Screen2560);
Check(d.Action != AcWindowPlacementRule.RestoreAction.Move, $"report profile at {t} s: never moved");
if (t <= 60) Eq(d.Action, AcWindowPlacementRule.RestoreAction.Wait, $"report profile at {t} s: waits for AC to reach the saved size");
else Eq(d.Action, AcWindowPlacementRule.RestoreAction.Skip, $"report profile at {t} s: gives up, window left where AC put it");
}
var skip = DecideRestore(LogoutRect, false, false, InGame, S(61), S(61), Screen2560);
Check(skip.Why.Contains("806x635"), "the skip says which size the position was saved for: " + skip.Why);
// A position saved for this size: moved there once AC's size held for the settle time.
var home = new Rect(100, 80, 100 + 1936, 80 + 1119);
Eq(DecideRestore(home, false, false, InGame, S(2), S(2), Screen2560).Action, AcWindowPlacementRule.RestoreAction.Wait, "size held 2 s: still settling");
var move = DecideRestore(home, false, false, InGame, S(4), S(4), Screen2560);
Eq(move.Action, AcWindowPlacementRule.RestoreAction.Move, "size held 4 s at the saved size: moved");
Eq((move.X, move.Y, move.Clamped), (100, 80, false), "to the saved spot");
// Borders toggled since the save (a few px either way): still the same window.
var framed = new Rect(10, 10, 10 + 1920, 10 + 1080);
Eq(DecideRestore(home, false, false, framed, S(4), S(4), Screen2560).Action, AcWindowPlacementRule.RestoreAction.Move, "borderless on/off since the save: still moved");
// A saved spot half off the screen is pulled onto it at the window's real size.
var off = new Rect(2000, 900, 2000 + 1936, 900 + 1119);
var pulled = DecideRestore(off, false, false, InGame, S(4), S(4), Screen2560);
Eq(pulled.Action, AcWindowPlacementRule.RestoreAction.Move, "half off the screen: moved");
Eq((pulled.X, pulled.Y, pulled.Clamped), (2560 - 1936 + AcWindowPlacementRule.EdgeSlack, 1560 - 1119 + AcWindowPlacementRule.EdgeSlack, true), "pulled onto the work area");
// A monitor that is gone: onto the one that is left.
var gone = new Rect(-2000, 100, -2000 + 1936, 100 + 1119);
var back = DecideRestore(gone, false, false, InGame, S(4), S(4), Screen2560);
Eq((back.Action, back.X), (AcWindowPlacementRule.RestoreAction.Move, -AcWindowPlacementRule.EdgeSlack), "saved on a monitor that is gone: onto this one");
// Never touched: nothing saved, minimised / maximised, exclusive fullscreen.
Eq(DecideRestore(null, false, false, InGame, S(10), S(10), Screen2560).Action, AcWindowPlacementRule.RestoreAction.Skip, "nothing saved: nothing done");
Eq(DecideRestore(home, true, false, InGame, S(10), S(10), Screen2560).Action, AcWindowPlacementRule.RestoreAction.Skip, "minimised or maximised: left alone");
Eq(DecideRestore(home, false, true, InGame, S(10), S(10), Screen2560).Action, AcWindowPlacementRule.RestoreAction.Skip, "exclusive fullscreen: left alone");
// AC's startup parking spot: wait for the real window, then give up.
var parked = new Rect(-32000, -32000, -32000 + 160, -32000 + 28);
Eq(DecideRestore(home, false, false, parked, S(10), S(10), Screen2560).Action, AcWindowPlacementRule.RestoreAction.Wait, "parked off-screen: waits");
Eq(DecideRestore(home, false, false, parked, S(70), S(70), Screen2560).Action, AcWindowPlacementRule.RestoreAction.Skip, "never shown in 60 s: gives up");
}
/// <summary>Feeds one rect for <paramref name="seconds"/> at 2 s ticks; true if any tick saved.</summary>
private static bool Hold(bool inWorld, Rect rect, Rect? reference, ref AcWindowPlacementRule.Pending? pending,
ref DateTime now, int seconds, out AcWindowPlacementRule.SaveAction last)
{
bool saved = false;
last = AcWindowPlacementRule.SaveAction.None;
for (int t = 0; t < seconds; t += 2, now = now.AddSeconds(2))
{
last = DecideSave(inWorld, true, false, rect, reference, ref pending, now).Action;
if (last == AcWindowPlacementRule.SaveAction.Save) { saved = true; break; }
}
return saved;
}
private static void PlacementSaveNeedsAStableInWorldRect()
{
var t0 = new DateTime(2026, 11, 15, 10, 3, 18, DateTimeKind.Utc);
AcWindowPlacementRule.Pending? pending = null;
// Self-heal: the report's profile holds the logout rect; the real window is saved 30 s later.
DateTime now = t0;
Eq(DecideSave(true, true, false, InGame, LogoutRect, ref pending, now).Action, AcWindowPlacementRule.SaveAction.Waiting, "report profile, first look: waiting");
Eq(DecideSave(true, true, false, InGame, LogoutRect, ref pending, now.AddSeconds(29)).Action, AcWindowPlacementRule.SaveAction.Waiting, "29 s: still waiting");
Eq(DecideSave(true, true, false, InGame, LogoutRect, ref pending, now.AddSeconds(30)).Action, AcWindowPlacementRule.SaveAction.Save, "30 s: the real window replaces the logout rect");
Check(pending == null, "nothing pending after a save");
// The report's cause: a logout to character select used to save AC's 800x600 window. Out of the
// world it never is, for any time, and nothing is left pending.
now = t0;
Check(!Hold(false, LogoutRect, InGame, ref pending, ref now, 300, out _), "character select for 5 min: never saved");
Check(pending == null, "character select: nothing pending");
// ...and while the mode is not known yet (counted as the world), the login-shrink guard holds.
Check(!Hold(true, LogoutRect, InGame, ref pending, ref now, 300, out var shrink), "the logout window in an unknown mode: never saved");
Eq(shrink, AcWindowPlacementRule.SaveAction.LoginShrink, "...refused as the login shrink");
// Time at character select never counts toward the 30 s: a rect pending at logout starts over.
pending = null;
now = t0;
var moved = new Rect(400, 200, 400 + 1936, 400 + 1119);
Check(!Hold(true, moved, InGame, ref pending, ref now, 20, out _), "moved, 20 s in the world: not yet");
Check(!Hold(false, moved, InGame, ref pending, ref now, 60, out _), "then a minute at character select: not saved");
Check(!Hold(true, moved, InGame, ref pending, ref now, 28, out _), "back in the world at the same rect: the 30 s start again");
Eq(DecideSave(true, true, false, moved, InGame, ref pending, now.AddSeconds(2)).Action, AcWindowPlacementRule.SaveAction.Save, "...and it is saved after 30 s in the world");
// A shrink just before the client closes (the launcher's report: 1008x786, 6 s before the exit,
// just over half the area so the guard lets it through) never lasts the 30 s.
pending = null;
now = t0;
var closing = new Rect(296, 76, 296 + 1008, 76 + 786);
var game1608 = new Rect(0, 0, 1608, 936);
Check(!Hold(true, closing, game1608, ref pending, ref now, 6, out var closingLast), "a rect that lasts 6 s: never saved");
Eq(closingLast, AcWindowPlacementRule.SaveAction.Waiting, "...it was only waiting (not the login shrink)");
// Minimised, maximised or fullscreen: nothing saved, nothing pending.
pending = null;
Eq(DecideSave(true, false, false, moved, InGame, ref pending, t0).Action, AcWindowPlacementRule.SaveAction.None, "not saveable: nothing");
Check(pending == null, "not saveable: nothing pending");
// Back where it was: nothing to save.
Eq(DecideSave(true, true, false, InGame, InGame, ref pending, t0).Action, AcWindowPlacementRule.SaveAction.None, "the saved rect itself: nothing");
// Save Layout Now: no 30 s wait, but never at character select and never the login shrink.
pending = null;
Eq(DecideSave(true, true, true, moved, InGame, ref pending, t0).Action, AcWindowPlacementRule.SaveAction.Save, "Save Layout Now in the world: saved at once");
Eq(DecideSave(true, true, true, moved, null, ref pending, t0).Action, AcWindowPlacementRule.SaveAction.Save, "Save Layout Now with nothing saved yet: saved");
Eq(DecideSave(false, true, true, LogoutRect, InGame, ref pending, t0).Action, AcWindowPlacementRule.SaveAction.None, "Save Layout Now at character select: nothing");
Eq(DecideSave(true, true, true, LogoutRect, InGame, ref pending, t0).Action, AcWindowPlacementRule.SaveAction.LoginShrink, "Save Layout Now on the login-size window: refused");
}
// Source guard: every SetWindowPos on the AC window keeps AC's size (R-20261115-160655-1201).
private static void AcWindowChromeNeverResizes()
{
string source = File.ReadAllText(FindUp(Path.Combine("src", "RynthCore.Engine", "UI", "AcWindowChrome.cs")));
var calls = Regex.Matches(source, @"^\s*(?:=>\s*)?SetWindowPos\(hwnd,[^;]*;", RegexOptions.Multiline | RegexOptions.Singleline);
Check(calls.Count >= 2, $"found the SetWindowPos calls ({calls.Count})");
foreach (Match m in calls)
Check(m.Value.Contains("SwpNosize"), "SetWindowPos keeps AC's size: " + Regex.Replace(m.Value.Trim(), @"\s+", " "));
}
private static void PlacementFilesArePerClient()