Fixes the three MUST-FIX findings from the 2026-08-11 combined dual-lens
review of commit b4edee97 (docs/research/2026-08-11-op8-review.md).
M1 — SetForAction destroyed ActivationType/InputScope on every write,
collapsing walk-mode's Hold, the three combat-scoped bindings, and
CameraInstantMouseLook's mouse chord the instant a row (including
Defaults, which touches all ~140 mapped rows at once) wrote back.
Widened the Bindings seam to carry the full Binding (chord + activation
+ scope), not a bare chord: KeyboardConfigController captures each
row's live Activation/Scope ONCE at build time (every multi-chord
action in KeyBindings.RetailDefaults() shares one pair across all its
bindings) and reapplies it on every write — rebind, Cancel/Revert, and
Defaults (which restores DAT-sourced KEYS only, never touches the
pair). New tests pin this across both Defaults and Cancel for a
Hold+MeleeCombat-scoped action.
M2 — InputMap 0x5 (CameraControls) and 0x6 (CameraAlternateControls)
aliased one InputAction each: both rows read/wrote the same live target,
so they showed identical stale chords, a rebind of one silently wiped
the other, and a row could conflict with its own twin. Building real
per-scheme dual-binding storage (or new InputAction members plus the
camera-dispatch code to consume them) is a feature, not a one-line fix.
Chose the third option: only ctx 0x5 — the scheme RetailDefaults()
actually has live support for — maps to InputAction; ctx 0x6 falls
through to the existing unmapped/store-only path (AP-203), fully
rendered, bindable, and persisted, honestly carrying no live effect.
This also retired 10 stale allowlist entries in the DAT-vs-
RetailDefaults() round-trip test: with the alias gone, ctx 0x5 alone
matches RetailDefaults() exactly for all twelve Camera actions.
M3 — the auto-reassign-on-conflict path was wired silent in production
(NotifyReassigned: _ => "") though the contract asked for a prompt and
retail confirms before overwriting (OpenOverwriteBindingDialog). Wired
a real confirm dialog through RetailDialogFactory.MakeConfirmation —
the same seam GameplayConfirmationController already uses — read
lazily since DialogFactory mounts after MountKeyboardConfig in
Initialize()'s order. Only reassigns on accept; decline leaves every
row untouched. AP-204 (which recorded the narrowing) is RETIRED; the
still-true OK/Cancel left-click-vs-right-click-release note moves to a
code comment (zero observable difference, doesn't warrant a register
row). Reverted the gate script's step 9 from documenting the silent
shape back to the real confirm-prompt behavior.
SHOULD-FIX addressed as one-liners in files already touched:
- S1: non-user-bindable conflicts are now checked BEFORE any row
conflict (retail's own order), and ALL conflicting rows are collected
(N-way), not just the first match.
- S3: Save wraps the file-write pair in the same try/catch
RuntimeKeyBindingTarget.Apply already uses for keybinds.json.
- S4: assigning "Mapping 3" on a row with no existing bindings now
lands on display index 2, not index 0 — ReplaceSlotValue trims only
TRAILING empty slots instead of stripping every default(KeyChord).
Right-click on an already-empty slot is now a no-op instead of
shifting later bindings.
- S6: UiButton.OnRightClick returns false (unhandled, bubbles to
parent) when no handler is set, disabled or not — matching the
pre-existing behavior the class doc already claimed.
Left for a future pass (not one-liners): S2 (ActionMap.ConflictingMaps
is still unread — the conflict scan treats all 306 rows as one flat
universe instead of respecting the DAT's own legitimately-shared-key
table) and S5 (the ~330 DAT layout imports still run eagerly at mount
instead of lazily on first open).
19 KeyboardConfigControllerTests (was 12): +2 activation/scope
preservation (Defaults, Cancel), +1 camera de-alias, +2 confirm-dialog
accept/decline, +1 non-bindable-takes-priority-over-row-conflict, +1
sparse-row third-slot placement. Full solution suite 13,154 passed / 4
skipped / 0 failed (this round's baseline 13,147/4/0, zero regressions).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
150 lines
7.5 KiB
C#
150 lines
7.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using AcDream.Content;
|
|
using AcDream.Core.Input;
|
|
using AcDream.UI.Abstractions.Input;
|
|
using DatReaderWriter;
|
|
using Xunit;
|
|
|
|
namespace AcDream.Core.Tests.Input;
|
|
|
|
/// <summary>
|
|
/// Campaign OP slice OP8: pins <see cref="RetailActionIdentityTable"/>'s agreement
|
|
/// with <see cref="KeyBindings.RetailDefaults"/> — for every <see cref="InputAction"/>
|
|
/// this slice's table resolves, the UNION of DAT default bindings across every DAT
|
|
/// row mapped to that action must equal <c>KeyBindings.RetailDefaults()</c>'s chord
|
|
/// set for it. Per the slice contract: "investigate + report any disagreement rather
|
|
/// than silently preferring one." Skips cleanly when the installed dats are
|
|
/// unavailable (CI), matching every other live-DAT conformance test in this project.
|
|
///
|
|
/// <para>
|
|
/// <b>Two real, byte-verified disagreements survive after the mechanism fixes</b>
|
|
/// (2026-08-11 investigation, updated at the M2 rework — none are bugs in this
|
|
/// slice's table; both are PRE-EXISTING <see cref="KeyBindings.RetailDefaults"/>
|
|
/// gaps/design choices this slice does not touch, listed in
|
|
/// <see cref="KnownRetailDefaultsDisagreements"/> with citations). A THIRD
|
|
/// disagreement — ten CameraAlternateControls (InputMap 0x6) actions — was RETIRED
|
|
/// at the M2 rework: <see cref="RetailActionIdentityTable"/> no longer maps InputMap
|
|
/// 0x6 to any <see cref="InputAction"/> at all (the aliasing that produced two
|
|
/// independent rows fighting over one live target — M2, 2026-08-11 review), so this
|
|
/// test never sees a ctx-0x6 row and the ctx-0x5-only union now matches
|
|
/// <c>RetailDefaults()</c> exactly for all twelve Camera actions with no allowlist
|
|
/// entry needed:
|
|
/// </para>
|
|
/// <list type="number">
|
|
/// <item><description><b>MovementWalkMode.</b> The DAT's raw <c>QualifiedControl.Modifier</c>
|
|
/// for the Shift-key binding is 0 (the key itself IS Shift — there is no separate
|
|
/// "modifier" to report when the primary key and the modifier are the same physical
|
|
/// key). <c>RetailDefaults()</c> deliberately encodes <c>Modifiers=Shift</c> anyway —
|
|
/// its own comment (K-fix1, 2026-04-26) explains the OS echoes
|
|
/// <c>CurrentModifiers=Shift</c> alongside a Shift key-DOWN event, so the chord must
|
|
/// carry the flag to match at dispatch time. Not a disagreement to fix; a raw-DAT
|
|
/// artifact this slice's reader faithfully reproduces.</description></item>
|
|
/// <item><description><b>Quickslot 1-9's Ctrl+N chord (and its SelectQuickSlot_1-9
|
|
/// counterpart).</b> The DAT's own default
|
|
/// master map binds Ctrl+1..9 to the SAME action id as bare 1..9 ("Quickslot N" —
|
|
/// <c>UseQuickSlot_N</c>), NOT to the separate "Select Quickslot N" action id
|
|
/// (<c>SelectQuickSlot_N</c>, DAT action ids <c>0x1000004E-56</c>) — those carry NO
|
|
/// default binding at all in the shipped DAT. <c>RetailDefaults()</c>'s own comment
|
|
/// (citing <c>gmToolbarUI::ListenToGlobalMessage @0x004BE4E0</c>) asserts retail's
|
|
/// CLIENT reinterprets Ctrl+N contextually as Select — a runtime behavior this raw
|
|
/// keymap-default probe cannot see (it reads bound ACTIONS, not the dispatch
|
|
/// function's own modifier branching). Both readings are independently retail-
|
|
/// sourced; reconciling them needs the decompiled dispatch function, out of scope
|
|
/// here. Reported, not silently resolved either way.</description></item>
|
|
/// </list>
|
|
/// </summary>
|
|
public sealed class RetailActionIdentityRoundTripTests
|
|
{
|
|
/// <summary>Actions with a citation-backed, pre-existing reason their DAT-union
|
|
/// default set legitimately differs from <see cref="KeyBindings.RetailDefaults"/>
|
|
/// — see class doc. Every other mapped action must match exactly.</summary>
|
|
private static readonly HashSet<InputAction> KnownRetailDefaultsDisagreements = new()
|
|
{
|
|
InputAction.MovementWalkMode,
|
|
InputAction.UseQuickSlot_1,
|
|
InputAction.UseQuickSlot_2,
|
|
InputAction.UseQuickSlot_3,
|
|
InputAction.UseQuickSlot_4,
|
|
InputAction.UseQuickSlot_5,
|
|
InputAction.UseQuickSlot_6,
|
|
InputAction.UseQuickSlot_7,
|
|
InputAction.UseQuickSlot_8,
|
|
InputAction.UseQuickSlot_9,
|
|
// Same Use-vs-Select ambiguity as the bare-numeral block above: the DAT's
|
|
// own "Select Quickslot N" action ids carry NO default binding at all —
|
|
// RetailDefaults()'s Ctrl+N->Select mapping rests on the decompiled
|
|
// dispatch function's runtime modifier check, not the raw keymap default.
|
|
InputAction.SelectQuickSlot_1,
|
|
InputAction.SelectQuickSlot_2,
|
|
InputAction.SelectQuickSlot_3,
|
|
InputAction.SelectQuickSlot_4,
|
|
InputAction.SelectQuickSlot_5,
|
|
InputAction.SelectQuickSlot_6,
|
|
InputAction.SelectQuickSlot_7,
|
|
InputAction.SelectQuickSlot_8,
|
|
InputAction.SelectQuickSlot_9,
|
|
};
|
|
|
|
[Fact]
|
|
public void MappedActions_DatUnionDefaultBindings_MatchRetailDefaults()
|
|
{
|
|
string? datDir = Conformance.ConformanceDats.ResolveDatDir();
|
|
if (datDir is null) return;
|
|
|
|
using var dats = new DatCollection(datDir);
|
|
var source = new DatCollectionAdapter(dats);
|
|
RetailActionMapSnapshot? snapshot = RetailActionMapReader.Read(source);
|
|
Assert.NotNull(snapshot);
|
|
|
|
KeyBindings retailDefaults = KeyBindings.RetailDefaults();
|
|
|
|
// Aggregate DAT default chords by resolved InputAction — a single action can
|
|
// be reached by more than one DAT row (e.g. the Camera/CameraAlternate pair).
|
|
var datChordsByAction = new Dictionary<InputAction, HashSet<KeyChord>>();
|
|
var unresolvedScanCodes = new List<string>();
|
|
foreach (RetailActionMapRow row in snapshot!.Rows)
|
|
{
|
|
if (!RetailActionIdentityTable.TryResolve(row.InputMapId, row.ActionId, out InputAction action))
|
|
continue;
|
|
if (!datChordsByAction.TryGetValue(action, out HashSet<KeyChord>? set))
|
|
datChordsByAction[action] = set = new HashSet<KeyChord>();
|
|
|
|
foreach (RetailKeyChord raw in row.DefaultBindings)
|
|
{
|
|
Silk.NET.Input.Key? key = RetailScanCodeMap.ToSilkKey(raw.Scan, raw.Device);
|
|
if (key is null)
|
|
{
|
|
unresolvedScanCodes.Add(
|
|
$"{action}: DAT default scan=0x{raw.Scan:X2} dev={raw.Device} has no "
|
|
+ "RetailScanCodeMap entry");
|
|
continue;
|
|
}
|
|
set.Add(new KeyChord(key.Value, RetailScanCodeMap.ToModifierMask(raw.Modifier), (byte)raw.Device));
|
|
}
|
|
}
|
|
|
|
Assert.True(datChordsByAction.Count > 100,
|
|
$"expected >100 mapped actions, got {datChordsByAction.Count}");
|
|
Assert.Empty(unresolvedScanCodes);
|
|
|
|
var mismatches = new List<string>();
|
|
foreach ((InputAction action, HashSet<KeyChord> datChords) in datChordsByAction)
|
|
{
|
|
if (KnownRetailDefaultsDisagreements.Contains(action)) continue;
|
|
|
|
var acdreamChords = retailDefaults.ForAction(action).Select(b => b.Chord).ToHashSet();
|
|
if (!datChords.SetEquals(acdreamChords))
|
|
{
|
|
mismatches.Add(
|
|
$"{action}: DAT union=[{string.Join(",", datChords)}] vs "
|
|
+ $"RetailDefaults()=[{string.Join(",", acdreamChords)}]");
|
|
}
|
|
}
|
|
|
|
Assert.True(mismatches.Count == 0,
|
|
$"{mismatches.Count} unexpected DAT-vs-RetailDefaults() disagreements "
|
|
+ "(not in the documented KnownRetailDefaultsDisagreements allowlist):\n"
|
|
+ string.Join("\n", mismatches));
|
|
}
|
|
}
|