Ports retail's Configure Keyboard screen (gmKeyboardUI, LayoutDesc 0x21000009) — its own separate full-screen window, not a fifth Options- panel tab. Retires OP3's INERT contract for the Gameplay tab's Configure Keyboard button (0x10000204). DAT reader (src/AcDream.Core/Input/RetailActionMap.cs): reads the ActionMap singleton (DID 0x26000000, empirically the only one — not 0x27000000 as GetDBOType's Turbine-internal tag would suggest) and both MasterInputMap defaults (0x14000000 "gmDefaultMap"/0x14000002 "DefaultMap"), union-merged per (InputMapId, ActionId) — proven order- independent since the two maps' one shared context (0x5) has disjoint action-id sets. Empirically resolved three lane-D unknowns against the live DAT: the six ActionClass values (1=Movement, 2=Camera, 3=UI, 4=Combat, 5=Emote, 7=CharacterSettings — 6 is genuinely absent), that the six unnamed InputMaps are 100% non-bindable (render nothing, not an unlabeled group), and that the enum-to-DID pairing for the two master maps is inconsequential to the merge result. Identity table (src/AcDream.UI.Abstractions/Input/RetailActionIdentityTable.cs): maps DAT (InputMapId, ActionId) pairs to acdream's InputAction where a live consumer exists (~140 of 306 user-bindable rows — Movement/Camera/ Combat map almost completely; UI/Quickslot/Chat partially; only 5 of 87 Emotes and none of 48 CharacterSettings hotkeys, since acdream has no general emote player or hotkey-to-option-toggle dispatcher yet). Every entry cross-verified by label match AND a DAT-default-vs- KeyBindings.RetailDefaults() byte comparison (RetailActionIdentityRoundTripTests), which caught a real off-by-one in the Quickslot 13-18 block before it shipped and found three genuine pre-existing RetailDefaults() gaps (walk-mode's Shift-echoed chord, ten CameraAlternateControls arrow-key alternates, and the Quickslot Ctrl+N use-vs-select ambiguity) — none introduced by this slice, all documented rather than silently patched. KeyboardConfigController: six ActionClass list boxes built from the DAT, merged with live KeyBindings for mapped rows (rebind applies immediately through the same InputDispatcher every other input path uses) and a new sibling RetailUnmappedKeyBindings store for rows with no InputAction yet. Left-click a key button opens real InputDispatcher modal capture; right-click erases that slot. N-way conflict detection scans every other row plus the live KeyBindings table for acdream-only actions (Ctrl+M mute, debug F-keys) as the non-user-bindable refusal analogue, using retail's own byte-verified "Could not overwrite " string (table 0x23000004). OK/Cancel/Defaults/Revert reuse the OptionPage/IOptionRow verb model via a new ActionKeyMapOptionRow. Persistence is keybinds.json only (D4 — no .keymap file interchange). Five register rows: AP-202 (.keymap interchange narrowing), AP-203 (store-only rows with no live consumer), AP-204 (silent auto-reassign instead of retail's confirm dialog; OK/Cancel ported as left-click not right-click-release). Small supporting additions: UiButton.OnRightClick (additive, no existing behavior changed), InputDispatcher.Bindings getter (the screen's single live-truth read seam), RetailScanCodeMap (DIK scan code <-> Silk.NET Key, keyboard + the one mouse-device row). 19 new tests (6 ActionMap reader conformance incl. live-DAT row-count/ label pins, 1 DAT-vs-RetailDefaults round-trip, 12 controller behavior tests against the committed keyboard_config_21000009.json fixture) — full solution suite 13,147 passed / 4 skipped / 0 failed (baseline 13,128/4/0, zero regressions). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
165 lines
8.3 KiB
C#
165 lines
8.3 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>Three real, byte-verified disagreements survive after the mechanism fixes</b>
|
|
/// (2026-08-11 investigation — none are bugs in this slice's table; all three are
|
|
/// PRE-EXISTING <see cref="KeyBindings.RetailDefaults"/> gaps/design choices this
|
|
/// slice does not touch, listed in <see cref="KnownRetailDefaultsDisagreements"/>
|
|
/// with citations):
|
|
/// </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>Ten CameraAlternateControls (InputMap 0x6) actions.</b> Retail
|
|
/// ships TWO camera-control schemes with DIFFERENT default keys: InputMap 0x5's
|
|
/// (Numpad: Keypad4/6/8/2 for rotate, KeypadSubtract/Add for zoom, ...) and InputMap
|
|
/// 0x6's (Arrow keys: Left/Right/Up/Down for rotate, ...). Both InputMaps' actions
|
|
/// share the SAME <see cref="RetailActionClass.Camera"/> bucket and this slice
|
|
/// correctly maps BOTH to the same <see cref="InputAction"/> (research doc §5.3: a
|
|
/// user can rebind either scheme's row independently). <c>RetailDefaults()</c> — a
|
|
/// PRE-EXISTING, OP8-independent file — only carries the Numpad (0x5) scheme; it does
|
|
/// not carry the arrow-key (0x6) alternates as SECOND bindings for the same action.
|
|
/// This is a genuine <c>RetailDefaults()</c> completeness gap, reported here rather
|
|
/// than silently patched into a foundational, heavily-tested file outside this
|
|
/// slice's scope (register row filed).</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.CameraMoveToward,
|
|
InputAction.CameraMoveAway,
|
|
InputAction.CameraRotateLeft,
|
|
InputAction.CameraRotateRight,
|
|
InputAction.CameraRotateUp,
|
|
InputAction.CameraRotateDown,
|
|
InputAction.CameraViewDefault,
|
|
InputAction.CameraViewFirstPerson,
|
|
InputAction.CameraViewLookDown,
|
|
InputAction.CameraViewMapMode,
|
|
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));
|
|
}
|
|
}
|