feat(ui): Campaign OP slice OP8 — Configure Keyboard
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>
This commit is contained in:
parent
ff5776415b
commit
b4edee970f
23 changed files with 35760 additions and 12 deletions
|
|
@ -285,6 +285,14 @@ public sealed class InputDispatcher : IDisposable
|
|||
_bindings = bindings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The current live bindings table (Campaign OP slice OP8: the Configure
|
||||
/// Keyboard screen's single source of truth for "what is currently bound" —
|
||||
/// reads through this rather than a caller-held snapshot, which would go
|
||||
/// stale the moment ANY OTHER rebind path calls <see cref="SetBindings"/>).
|
||||
/// </summary>
|
||||
public KeyBindings Bindings => _bindings;
|
||||
|
||||
/// <summary>
|
||||
/// Per-frame "is this action's chord currently held" query. Walks every
|
||||
/// binding for the given action; returns true if any of them has its
|
||||
|
|
|
|||
241
src/AcDream.UI.Abstractions/Input/RetailActionIdentityTable.cs
Normal file
241
src/AcDream.UI.Abstractions/Input/RetailActionIdentityTable.cs
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace AcDream.UI.Abstractions.Input;
|
||||
|
||||
/// <summary>
|
||||
/// Campaign OP slice OP8: maps a retail DAT ActionMap row — the
|
||||
/// <c>(InputMap id, Action id)</c> pair <c>AcDream.Core.Input.RetailActionMapRow</c>
|
||||
/// carries — to acdream's own <see cref="InputAction"/>, when one exists.
|
||||
///
|
||||
/// <para>
|
||||
/// <b>Why this table exists.</b> The DAT ActionMap singleton (empirically dumped
|
||||
/// 2026-08-11, see <c>AcDream.Core.Input.RetailActionMap</c>'s class doc) carries 306
|
||||
/// user-bindable rows. <see cref="InputAction"/> — the enum every OTHER acdream input
|
||||
/// path (live dispatch, <c>KeyBindings</c>, <c>InputDispatcher</c>) already keys on —
|
||||
/// has roughly half that many members, because it was authored around "what acdream
|
||||
/// currently implements" (K.1a/K.1c), not "every action the 2013 client's keymap
|
||||
/// screen can show." Two categories are the biggest gaps: 82 of the DAT's 87 Emote
|
||||
/// rows have no acdream animation dispatch yet (only 5 are wired: Cry/Laugh/Cheer/
|
||||
/// Wave/PointState — exactly the 5 that happen to carry retail default keys), and all
|
||||
/// 48 CharacterSettings rows are hotkeys for the SAME <c>PlayerOption</c>/
|
||||
/// <c>CharacterOptions</c> preference bits OP1's <c>CharacterOptionTable</c> and OP4's
|
||||
/// Character-tab checkboxes already model — wiring "press this key, flip that same
|
||||
/// server-synced bit" is a real feature (a hotkey-to-option-toggle dispatcher) that
|
||||
/// does not exist yet anywhere in acdream and is out of scope for this slice (see the
|
||||
/// OP8 register row).
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// <b>Every mapping below was verified two ways</b> before being added: (1) the DAT's
|
||||
/// resolved English label/tooltip unambiguously names the SAME action as the
|
||||
/// <see cref="InputAction"/> member's own XML doc, AND (2) where the retail default
|
||||
/// key(s) for that DAT row are non-empty, they match
|
||||
/// <see cref="KeyBindings.RetailDefaults"/>'s existing chord(s) for the candidate
|
||||
/// <see cref="InputAction"/> (byte-verified 2026-08-11 against the installed dats —
|
||||
/// see <c>RetailActionMapReaderTests.LiveDatTests</c> and this slice's
|
||||
/// <c>RetailActionIdentityRoundTripTests</c>). A DAT row that could not be verified
|
||||
/// BOTH ways is left OUT of this table on purpose — it renders on the Configure
|
||||
/// Keyboard screen as a real, bindable, persisted row (see
|
||||
/// <c>KeyboardConfigController</c>), it just does not yet reach any live acdream
|
||||
/// consumer. Silently guessing a wrong mapping would misroute a user's rebind to the
|
||||
/// WRONG gameplay action, which is worse than an honest "not wired yet."
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// <b>Known gaps deliberately left unmapped</b> (register row, OP8):
|
||||
/// Spell Slot 10/11/12 (ctx <c>0x10000005</c>, DAT actions <c>0x6E/0x6F/0x70</c> —
|
||||
/// <see cref="InputAction"/> only defines <c>UseSpellSlot_1..9</c>); Quickslot
|
||||
/// 10/11/12/13 (ctx <c>0x1000000C</c>, DAT actions <c>0x1000004B/4C/4D/10000132</c> —
|
||||
/// <see cref="InputAction"/>'s <c>UseQuickSlot_*</c> family jumps from 9 straight to
|
||||
/// 14, a pre-existing enum gap this slice did not introduce and does not fix); every
|
||||
/// CharacterSettings row (ctx <c>0x10000008</c>, all 48); 82 of 87 Emote rows (ctx
|
||||
/// <c>0x10000006</c>); and roughly half of the UI-class rows (ctx
|
||||
/// <c>0x10000007</c>/<c>0x10000009</c> — panels acdream has no toggle for, e.g. Vitae,
|
||||
/// Link Status, House, Map, Character Info, the positive/negative Magic panels).
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class RetailActionIdentityTable
|
||||
{
|
||||
/// <summary>(InputMap id, Action id) → the acdream <see cref="InputAction"/> that
|
||||
/// owns live dispatch for it. A DAT row whose key is absent has no acdream
|
||||
/// consumer yet.</summary>
|
||||
public static readonly IReadOnlyDictionary<(uint InputMapId, uint ActionId), InputAction> Map =
|
||||
BuildTable();
|
||||
|
||||
public static bool TryResolve(uint inputMapId, uint actionId, out InputAction action) =>
|
||||
Map.TryGetValue((inputMapId, actionId), out action);
|
||||
|
||||
private static Dictionary<(uint, uint), InputAction> BuildTable()
|
||||
{
|
||||
var t = new Dictionary<(uint, uint), InputAction>();
|
||||
void M(uint inputMapId, uint actionId, InputAction action) => t[(inputMapId, actionId)] = action;
|
||||
|
||||
// ── MovementCommands (ctx 0x4) — 14/14, complete. ──────────────
|
||||
M(0x4, 0x29, InputAction.MovementForward);
|
||||
M(0x4, 0x2A, InputAction.MovementBackup);
|
||||
M(0x4, 0x2B, InputAction.MovementStop);
|
||||
M(0x4, 0x2C, InputAction.MovementStrafeRight);
|
||||
M(0x4, 0x2D, InputAction.MovementStrafeLeft);
|
||||
M(0x4, 0x2E, InputAction.MovementTurnRight);
|
||||
M(0x4, 0x2F, InputAction.MovementTurnLeft);
|
||||
M(0x4, 0x30, InputAction.MovementRunLock);
|
||||
M(0x4, 0x31, InputAction.MovementJump);
|
||||
M(0x4, 0x32, InputAction.MovementWalkMode);
|
||||
M(0x4, 0x10000094, InputAction.Ready);
|
||||
M(0x4, 0x10000095, InputAction.Crouch);
|
||||
M(0x4, 0x10000096, InputAction.Sitting);
|
||||
M(0x4, 0x10000097, InputAction.Sleeping);
|
||||
|
||||
// ── CameraControls (ctx 0x5) + CameraAlternateControls (ctx 0x6) —
|
||||
// 12 distinct actions, both contexts map to the SAME InputAction
|
||||
// (alternate/numpad chords for the same camera verb). 22/22. ──
|
||||
foreach (uint ctx in new uint[] { 0x5, 0x6 })
|
||||
{
|
||||
M(ctx, 0x33, InputAction.CameraMoveToward);
|
||||
M(ctx, 0x34, InputAction.CameraMoveAway);
|
||||
M(ctx, 0x35, InputAction.CameraRotateLeft);
|
||||
M(ctx, 0x36, InputAction.CameraRotateRight);
|
||||
M(ctx, 0x37, InputAction.CameraRotateUp);
|
||||
M(ctx, 0x38, InputAction.CameraRotateDown);
|
||||
M(ctx, 0x39, InputAction.CameraViewDefault);
|
||||
M(ctx, 0x3A, InputAction.CameraViewFirstPerson);
|
||||
M(ctx, 0x3B, InputAction.CameraViewLookDown);
|
||||
M(ctx, 0x3C, InputAction.CameraViewMapMode);
|
||||
}
|
||||
// 0x3D/0x3E ("Toggle Mouselook"/"Toggle Alternate Camera Mode") only
|
||||
// author defaults under ctx 0x5 (dev=1 mouse chord + F2/Numpad-Divide).
|
||||
M(0x5, 0x3D, InputAction.CameraInstantMouseLook);
|
||||
M(0x5, 0x3E, InputAction.CameraActivateAlternateMode);
|
||||
|
||||
// ── Combat (ctx 0x10000002) — 1/1. ─────────────────────────────
|
||||
M(0x10000002, 0x1000005A, InputAction.CombatToggleCombat);
|
||||
|
||||
// ── MeleeCombat (ctx 0x10000003) — 5/5. ────────────────────────
|
||||
M(0x10000003, 0x1000005B, InputAction.CombatDecreaseAttackPower);
|
||||
M(0x10000003, 0x1000005C, InputAction.CombatIncreaseAttackPower);
|
||||
M(0x10000003, 0x1000005D, InputAction.CombatLowAttack);
|
||||
M(0x10000003, 0x1000005E, InputAction.CombatMediumAttack);
|
||||
M(0x10000003, 0x1000005F, InputAction.CombatHighAttack);
|
||||
|
||||
// ── MissileCombat (ctx 0x10000004) — 5/5. ──────────────────────
|
||||
M(0x10000004, 0x100000EF, InputAction.CombatDecreaseMissileAccuracy);
|
||||
M(0x10000004, 0x100000F0, InputAction.CombatIncreaseMissileAccuracy);
|
||||
M(0x10000004, 0x100000F1, InputAction.CombatAimLow);
|
||||
M(0x10000004, 0x100000F2, InputAction.CombatAimMedium);
|
||||
M(0x10000004, 0x100000F3, InputAction.CombatAimHigh);
|
||||
|
||||
// ── MagicCombat (ctx 0x10000005) — 18/21 (Spell Slot 10/11/12 have
|
||||
// no InputAction — register row). ────────────────────────────
|
||||
M(0x10000005, 0x10000060, InputAction.CombatCastCurrentSpell);
|
||||
M(0x10000005, 0x10000061, InputAction.CombatPrevSpell);
|
||||
M(0x10000005, 0x10000062, InputAction.CombatNextSpell);
|
||||
M(0x10000005, 0x10000063, InputAction.CombatPrevSpellTab);
|
||||
M(0x10000005, 0x10000064, InputAction.CombatNextSpellTab);
|
||||
M(0x10000005, 0x10000065, InputAction.UseSpellSlot_1);
|
||||
M(0x10000005, 0x10000066, InputAction.UseSpellSlot_2);
|
||||
M(0x10000005, 0x10000067, InputAction.UseSpellSlot_3);
|
||||
M(0x10000005, 0x10000068, InputAction.UseSpellSlot_4);
|
||||
M(0x10000005, 0x10000069, InputAction.UseSpellSlot_5);
|
||||
M(0x10000005, 0x1000006A, InputAction.UseSpellSlot_6);
|
||||
M(0x10000005, 0x1000006B, InputAction.UseSpellSlot_7);
|
||||
M(0x10000005, 0x1000006C, InputAction.UseSpellSlot_8);
|
||||
M(0x10000005, 0x1000006D, InputAction.UseSpellSlot_9);
|
||||
// 0x6E/0x6F/0x70 (Spell Slot 10/11/12) — no InputAction. Unmapped.
|
||||
M(0x10000005, 0x10000102, InputAction.CombatFirstSpell);
|
||||
M(0x10000005, 0x10000103, InputAction.CombatLastSpell);
|
||||
M(0x10000005, 0x10000104, InputAction.CombatFirstSpellTab);
|
||||
M(0x10000005, 0x10000105, InputAction.CombatLastSpellTab);
|
||||
|
||||
// ── Emotes (ctx 0x10000006) — 5/87 (the only 5 acdream dispatches
|
||||
// an animation for; also the only 5 with retail default keys). ──
|
||||
M(0x10000006, 0x100000A2, InputAction.Cheer);
|
||||
M(0x10000006, 0x100000A7, InputAction.Cry);
|
||||
M(0x10000006, 0x100000B2, InputAction.Laugh);
|
||||
M(0x10000006, 0x100000BE, InputAction.PointState);
|
||||
M(0x10000006, 0x100000E5, InputAction.Wave);
|
||||
|
||||
// ── ItemSelectionCommands (ctx 0x10000007) — 17/26. ────────────
|
||||
M(0x10000007, 0x1000002D, InputAction.SelectionSplitStack);
|
||||
M(0x10000007, 0x1000002E, InputAction.SelectionPreviousSelection);
|
||||
M(0x10000007, 0x1000002F, InputAction.SelectionClosestCompassItem);
|
||||
M(0x10000007, 0x10000030, InputAction.SelectionPreviousCompassItem);
|
||||
M(0x10000007, 0x10000031, InputAction.SelectionNextCompassItem);
|
||||
M(0x10000007, 0x10000032, InputAction.SelectionClosestItem);
|
||||
M(0x10000007, 0x10000033, InputAction.SelectionPreviousItem);
|
||||
M(0x10000007, 0x10000034, InputAction.SelectionNextItem);
|
||||
M(0x10000007, 0x10000035, InputAction.SelectionClosestMonster);
|
||||
M(0x10000007, 0x10000036, InputAction.SelectionPreviousMonster);
|
||||
M(0x10000007, 0x10000037, InputAction.SelectionNextMonster);
|
||||
M(0x10000007, 0x10000038, InputAction.SelectionLastAttacker);
|
||||
M(0x10000007, 0x10000039, InputAction.SelectionClosestPlayer);
|
||||
M(0x10000007, 0x1000003A, InputAction.SelectionPreviousPlayer);
|
||||
M(0x10000007, 0x1000003B, InputAction.SelectionNextPlayer);
|
||||
M(0x10000007, 0x1000003C, InputAction.SelectionPreviousFellow);
|
||||
M(0x10000007, 0x1000003D, InputAction.SelectionNextFellow);
|
||||
|
||||
// ── UICommands (ctx 0x10000009) — 22/42. ───────────────────────
|
||||
M(0x10000009, 0x55, InputAction.CaptureScreenshot);
|
||||
M(0x10000009, 0x7B, InputAction.ToggleHelp);
|
||||
M(0x10000009, 0x7C, InputAction.TogglePluginManager);
|
||||
M(0x10000009, 0x1000000E, InputAction.ToggleAllegiancePanel);
|
||||
M(0x10000009, 0x1000000F, InputAction.ToggleFellowshipPanel);
|
||||
M(0x10000009, 0x10000011, InputAction.ToggleSpellbookPanel);
|
||||
M(0x10000009, 0x10000012, InputAction.ToggleSpellComponentsPanel);
|
||||
M(0x10000009, 0x10000014, InputAction.ToggleAttributesPanel);
|
||||
M(0x10000009, 0x10000015, InputAction.ToggleSkillsPanel);
|
||||
M(0x10000009, 0x10000016, InputAction.ToggleWorldPanel);
|
||||
M(0x10000009, 0x1000001A, InputAction.ToggleOptionsPanel);
|
||||
M(0x10000009, 0x10000019, InputAction.ToggleInventoryPanel);
|
||||
M(0x10000009, 0x10000114, InputAction.ToggleFloatingChatWindow1);
|
||||
M(0x10000009, 0x10000115, InputAction.ToggleFloatingChatWindow2);
|
||||
M(0x10000009, 0x10000116, InputAction.ToggleFloatingChatWindow3);
|
||||
M(0x10000009, 0x10000117, InputAction.ToggleFloatingChatWindow4);
|
||||
M(0x10000009, 0x10000025, InputAction.UseSelected);
|
||||
M(0x10000009, 0x10000026, InputAction.LOGOUT);
|
||||
M(0x10000009, 0x1000002B, InputAction.SelectionExamine);
|
||||
// 0x1000001F ("Show/Hide Keyboard Configuration") deliberately left
|
||||
// unmapped: it is the retail action that opens THIS screen
|
||||
// (research doc §4.3/lane A §7 — wired directly by
|
||||
// KeyboardConfigController's mount, not through InputAction).
|
||||
|
||||
// ── ChatCommands (ctx 0x1000000A) — 1/6. ───────────────────────
|
||||
M(0x1000000A, 0x10000023, InputAction.EnterChatMode);
|
||||
|
||||
// ── ToggleChatEntry (ctx 0x1000000D) — 1/1. ────────────────────
|
||||
M(0x1000000D, 0x10000024, InputAction.ToggleChatEntry);
|
||||
|
||||
// ── QuickslotCommands (ctx 0x1000000C) — 24/28 (Quickslot
|
||||
// 10/11/12/13 have no InputAction — pre-existing enum gap). ──
|
||||
M(0x1000000C, 0x10000042, InputAction.UseQuickSlot_1);
|
||||
M(0x1000000C, 0x10000043, InputAction.UseQuickSlot_2);
|
||||
M(0x1000000C, 0x10000044, InputAction.UseQuickSlot_3);
|
||||
M(0x1000000C, 0x10000045, InputAction.UseQuickSlot_4);
|
||||
M(0x1000000C, 0x10000046, InputAction.UseQuickSlot_5);
|
||||
M(0x1000000C, 0x10000047, InputAction.UseQuickSlot_6);
|
||||
M(0x1000000C, 0x10000048, InputAction.UseQuickSlot_7);
|
||||
M(0x1000000C, 0x10000049, InputAction.UseQuickSlot_8);
|
||||
M(0x1000000C, 0x1000004A, InputAction.UseQuickSlot_9);
|
||||
M(0x1000000C, 0x1000004E, InputAction.SelectQuickSlot_1);
|
||||
M(0x1000000C, 0x1000004F, InputAction.SelectQuickSlot_2);
|
||||
M(0x1000000C, 0x10000050, InputAction.SelectQuickSlot_3);
|
||||
M(0x1000000C, 0x10000051, InputAction.SelectQuickSlot_4);
|
||||
M(0x1000000C, 0x10000052, InputAction.SelectQuickSlot_5);
|
||||
M(0x1000000C, 0x10000053, InputAction.SelectQuickSlot_6);
|
||||
M(0x1000000C, 0x10000054, InputAction.SelectQuickSlot_7);
|
||||
M(0x1000000C, 0x10000055, InputAction.SelectQuickSlot_8);
|
||||
M(0x1000000C, 0x10000056, InputAction.SelectQuickSlot_9);
|
||||
M(0x1000000C, 0x1000010D, InputAction.CreateShortcut);
|
||||
// 0x10000132 ("Quickslot 13") has no InputAction — same pre-existing
|
||||
// UseQuickSlot_10..13 enum gap as the bare-numeral block above. Unmapped.
|
||||
M(0x1000000C, 0x10000133, InputAction.UseQuickSlot_14);
|
||||
M(0x1000000C, 0x10000134, InputAction.UseQuickSlot_15);
|
||||
M(0x1000000C, 0x10000135, InputAction.UseQuickSlot_16);
|
||||
M(0x1000000C, 0x10000136, InputAction.UseQuickSlot_17);
|
||||
M(0x1000000C, 0x10000137, InputAction.UseQuickSlot_18);
|
||||
|
||||
// CharacterSettings (ctx 0x10000008) is intentionally EMPTY here —
|
||||
// see class doc "Known gaps deliberately left unmapped".
|
||||
|
||||
return t;
|
||||
}
|
||||
}
|
||||
167
src/AcDream.UI.Abstractions/Input/RetailScanCodeMap.cs
Normal file
167
src/AcDream.UI.Abstractions/Input/RetailScanCodeMap.cs
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
using Silk.NET.Input;
|
||||
|
||||
namespace AcDream.UI.Abstractions.Input;
|
||||
|
||||
/// <summary>
|
||||
/// Campaign OP slice OP8: converts retail's DAT-resident key encoding — DirectInput
|
||||
/// scan codes (<c>DIK_*</c>) + device index (0=keyboard, 1=mouse) + a modifier
|
||||
/// bitmask — to/from acdream's own <see cref="KeyChord"/>/<see cref="ModifierMask"/>.
|
||||
/// Needed because <c>AcDream.Core.Input.RetailActionMapReader</c> reads the DAT's
|
||||
/// raw scan-code encoding (it has no Silk.NET dependency — Core stays GL/backend-free
|
||||
/// per Code Structure Rule 2), while every acdream input consumer
|
||||
/// (<see cref="KeyBindings"/>, <see cref="InputDispatcher"/>) keys on Silk.NET's
|
||||
/// <see cref="Key"/> enum.
|
||||
///
|
||||
/// <para>
|
||||
/// The scan-code table covers exactly the 84 distinct DIK codes that appear across
|
||||
/// the DAT's 306 user-bindable ActionMap rows' default bindings (2026-08-11 probe —
|
||||
/// see <c>RetailActionMap.cs</c>'s class doc), cross-checked against
|
||||
/// <c>tools/dump-keymap/Program.cs</c>'s own <c>Dik(uint)</c> transcription (itself
|
||||
/// verified against <c>acclient_2013_pseudo_c.txt</c>'s
|
||||
/// <c>ControlNameMapper::AddKeySemantic</c> calls) and against
|
||||
/// <see cref="KeyBindings.RetailDefaults"/>'s existing chords, which already encode
|
||||
/// the same standard US-layout DirectInput scan codes by construction (both were
|
||||
/// authored from the same <c>retail-default.keymap.txt</c>). Codes outside this set
|
||||
/// (rare/debug/joystick bindings never seen with a non-empty default in the shipped
|
||||
/// DAT) intentionally return null rather than guess.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class RetailScanCodeMap
|
||||
{
|
||||
/// <summary>Retail modifier bitmask (the same encoding
|
||||
/// <c>CInputMap</c>/<c>QualifiedControl.Modifier</c> stores) → <see cref="ModifierMask"/>.
|
||||
/// Bit values from <c>tools/dump-keymap/Program.cs</c>'s <c>ModifierString</c>.</summary>
|
||||
public static ModifierMask ToModifierMask(uint retailModifier)
|
||||
{
|
||||
var mask = ModifierMask.None;
|
||||
if ((retailModifier & 0x80000000u) != 0) mask |= ModifierMask.Shift;
|
||||
if ((retailModifier & 0x40000000u) != 0) mask |= ModifierMask.Ctrl;
|
||||
if ((retailModifier & 0x20000000u) != 0) mask |= ModifierMask.Alt;
|
||||
return mask;
|
||||
}
|
||||
|
||||
/// <summary>DIK scan code + device → Silk.NET <see cref="Key"/>. Device 0 is
|
||||
/// the keyboard table below (see class doc). Device 1 is a mouse chord: the
|
||||
/// DAT's <c>QualifiedControl.Key.Key</c> scan half packs the raw DirectInput
|
||||
/// <c>DIMOUSESTATE.rgbButtons</c> BYTE OFFSET (0x0C=left/0x0D=right/0x0E=middle/
|
||||
/// 0x0F=button4 — byte-verified against <see cref="InputAction.CameraInstantMouseLook"/>'s
|
||||
/// only DAT-default mouse row, InputMap 0x5 action 0x3D, scan 0x0E: it resolves
|
||||
/// to Middle here, matching <see cref="KeyBindings.RetailDefaults"/>'s existing
|
||||
/// MMB-hold binding for the same action exactly), translated through the SAME
|
||||
/// <see cref="InputDispatcher.MouseButtonToKey"/> convention every other mouse
|
||||
/// chord in this codebase uses.</summary>
|
||||
public static Key? ToSilkKey(uint scan, uint device)
|
||||
{
|
||||
if (device == 1)
|
||||
{
|
||||
return scan switch
|
||||
{
|
||||
0x0C => InputDispatcher.MouseButtonToKey(MouseButton.Left),
|
||||
0x0D => InputDispatcher.MouseButtonToKey(MouseButton.Right),
|
||||
0x0E => InputDispatcher.MouseButtonToKey(MouseButton.Middle),
|
||||
0x0F => InputDispatcher.MouseButtonToKey(MouseButton.Button4),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
if (device != 0) return null;
|
||||
return scan switch
|
||||
{
|
||||
0x01 => Key.Escape,
|
||||
0x02 => Key.Number1,
|
||||
0x03 => Key.Number2,
|
||||
0x04 => Key.Number3,
|
||||
0x05 => Key.Number4,
|
||||
0x06 => Key.Number5,
|
||||
0x07 => Key.Number6,
|
||||
0x08 => Key.Number7,
|
||||
0x09 => Key.Number8,
|
||||
0x0A => Key.Number9,
|
||||
0x0B => Key.Number0,
|
||||
0x0C => Key.Minus,
|
||||
0x0D => Key.Equal,
|
||||
0x0E => Key.Backspace,
|
||||
0x0F => Key.Tab,
|
||||
0x10 => Key.Q,
|
||||
0x11 => Key.W,
|
||||
0x12 => Key.E,
|
||||
0x13 => Key.R,
|
||||
0x14 => Key.T,
|
||||
0x15 => Key.Y,
|
||||
0x16 => Key.U,
|
||||
0x17 => Key.I,
|
||||
0x18 => Key.O,
|
||||
0x19 => Key.P,
|
||||
0x1A => Key.LeftBracket,
|
||||
0x1B => Key.RightBracket,
|
||||
0x1C => Key.Enter,
|
||||
0x1E => Key.A,
|
||||
0x1F => Key.S,
|
||||
0x20 => Key.D,
|
||||
0x21 => Key.F,
|
||||
0x22 => Key.G,
|
||||
0x23 => Key.H,
|
||||
0x24 => Key.J,
|
||||
0x25 => Key.K,
|
||||
0x26 => Key.L,
|
||||
0x27 => Key.Semicolon,
|
||||
0x28 => Key.Apostrophe,
|
||||
0x29 => Key.GraveAccent,
|
||||
0x2A => Key.ShiftLeft,
|
||||
0x2B => Key.BackSlash,
|
||||
0x2C => Key.Z,
|
||||
0x2D => Key.X,
|
||||
0x2E => Key.C,
|
||||
0x2F => Key.V,
|
||||
0x30 => Key.B,
|
||||
0x31 => Key.N,
|
||||
0x32 => Key.M,
|
||||
0x33 => Key.Comma,
|
||||
0x34 => Key.Period,
|
||||
0x35 => Key.Slash,
|
||||
0x36 => Key.ShiftRight,
|
||||
0x37 => Key.KeypadMultiply,
|
||||
0x39 => Key.Space,
|
||||
0x3B => Key.F1,
|
||||
0x3C => Key.F2,
|
||||
0x3D => Key.F3,
|
||||
0x3E => Key.F4,
|
||||
0x3F => Key.F5,
|
||||
0x40 => Key.F6,
|
||||
0x41 => Key.F7,
|
||||
0x42 => Key.F8,
|
||||
0x43 => Key.F9,
|
||||
0x44 => Key.F10,
|
||||
0x45 => Key.NumLock,
|
||||
0x46 => Key.ScrollLock,
|
||||
0x47 => Key.Keypad7,
|
||||
0x48 => Key.Keypad8,
|
||||
0x49 => Key.Keypad9,
|
||||
0x4A => Key.KeypadSubtract,
|
||||
0x4B => Key.Keypad4,
|
||||
0x4C => Key.Keypad5,
|
||||
0x4D => Key.Keypad6,
|
||||
0x4E => Key.KeypadAdd,
|
||||
0x4F => Key.Keypad1,
|
||||
0x50 => Key.Keypad2,
|
||||
0x51 => Key.Keypad3,
|
||||
0x52 => Key.Keypad0,
|
||||
0x53 => Key.KeypadDecimal,
|
||||
0x57 => Key.F11,
|
||||
0x58 => Key.F12,
|
||||
0x9C => Key.KeypadEnter,
|
||||
0x9D => Key.ControlRight,
|
||||
0xB5 => Key.KeypadDivide,
|
||||
0xC7 => Key.Home,
|
||||
0xC8 => Key.Up,
|
||||
0xC9 => Key.PageUp,
|
||||
0xCB => Key.Left,
|
||||
0xCD => Key.Right,
|
||||
0xCF => Key.End,
|
||||
0xD0 => Key.Down,
|
||||
0xD1 => Key.PageDown,
|
||||
0xD2 => Key.Insert,
|
||||
0xD3 => Key.Delete,
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
}
|
||||
117
src/AcDream.UI.Abstractions/Input/RetailUnmappedKeyBindings.cs
Normal file
117
src/AcDream.UI.Abstractions/Input/RetailUnmappedKeyBindings.cs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AcDream.UI.Abstractions.Input;
|
||||
|
||||
/// <summary>
|
||||
/// Campaign OP slice OP8: persisted bindings for DAT ActionMap rows that
|
||||
/// <c>RetailActionIdentityTable</c> has no <see cref="InputAction"/> for —
|
||||
/// mostly Emotes and CharacterSettings hotkeys (see that table's class doc for
|
||||
/// the full accounting). These rows still render, bind, conflict-check, and
|
||||
/// persist on the Configure Keyboard screen exactly like a mapped row; they
|
||||
/// just have no live gameplay consumer to dispatch through yet, so they live in
|
||||
/// their own small store rather than <see cref="KeyBindings"/>'s
|
||||
/// <see cref="InputAction"/>-keyed schema. Sibling file next to
|
||||
/// <c>keybinds.json</c> (D4 — no <c>.keymap</c> file interchange).
|
||||
/// </summary>
|
||||
public sealed class RetailUnmappedKeyBindings
|
||||
{
|
||||
private readonly Dictionary<(uint InputMapId, uint ActionId), List<KeyChord>> _bindings = new();
|
||||
|
||||
public IReadOnlyList<KeyChord> Get(uint inputMapId, uint actionId) =>
|
||||
_bindings.TryGetValue((inputMapId, actionId), out List<KeyChord>? list)
|
||||
? list
|
||||
: Array.Empty<KeyChord>();
|
||||
|
||||
public void Set(uint inputMapId, uint actionId, IReadOnlyList<KeyChord> chords)
|
||||
{
|
||||
if (chords.Count == 0)
|
||||
_bindings.Remove((inputMapId, actionId));
|
||||
else
|
||||
_bindings[(inputMapId, actionId)] = new List<KeyChord>(chords);
|
||||
}
|
||||
|
||||
public static RetailUnmappedKeyBindings LoadOrEmpty(string path)
|
||||
{
|
||||
var result = new RetailUnmappedKeyBindings();
|
||||
if (!File.Exists(path)) return result;
|
||||
try
|
||||
{
|
||||
using FileStream stream = File.OpenRead(path);
|
||||
JsonDocument doc = JsonDocument.Parse(stream);
|
||||
if (!doc.RootElement.TryGetProperty("rows", out JsonElement rows)
|
||||
|| rows.ValueKind != JsonValueKind.Array)
|
||||
return result;
|
||||
|
||||
foreach (JsonElement row in rows.EnumerateArray())
|
||||
{
|
||||
if (!row.TryGetProperty("inputMap", out JsonElement mapEl)
|
||||
|| !row.TryGetProperty("action", out JsonElement actionEl)
|
||||
|| !row.TryGetProperty("chords", out JsonElement chordsEl)
|
||||
|| chordsEl.ValueKind != JsonValueKind.Array)
|
||||
continue;
|
||||
|
||||
uint inputMapId = Convert.ToUInt32(mapEl.GetString(), 16);
|
||||
uint actionId = Convert.ToUInt32(actionEl.GetString(), 16);
|
||||
var chords = new List<KeyChord>();
|
||||
foreach (JsonElement c in chordsEl.EnumerateArray())
|
||||
{
|
||||
if (!c.TryGetProperty("key", out JsonElement keyEl)) continue;
|
||||
string? keyName = keyEl.GetString();
|
||||
if (keyName is null || !Enum.TryParse(keyName, out Silk.NET.Input.Key key)) continue;
|
||||
var mods = ModifierMask.None;
|
||||
if (c.TryGetProperty("mod", out JsonElement modEl)
|
||||
&& modEl.ValueKind == JsonValueKind.String
|
||||
&& modEl.GetString() is { } modStr)
|
||||
{
|
||||
foreach (string part in modStr.Split('|', StringSplitOptions.RemoveEmptyEntries))
|
||||
if (Enum.TryParse(part, out ModifierMask m)) mods |= m;
|
||||
}
|
||||
byte device = 0;
|
||||
if (c.TryGetProperty("device", out JsonElement devEl) && devEl.ValueKind == JsonValueKind.Number)
|
||||
device = (byte)devEl.GetInt32();
|
||||
chords.Add(new KeyChord(key, mods, device));
|
||||
}
|
||||
result._bindings[(inputMapId, actionId)] = chords;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"unmapped keybinds: failed to load {path}: {ex.Message}");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SaveToFile(string path)
|
||||
{
|
||||
string? dir = Path.GetDirectoryName(path);
|
||||
if (!string.IsNullOrEmpty(dir)) Directory.CreateDirectory(dir);
|
||||
|
||||
var rows = new List<object>();
|
||||
foreach (((uint inputMapId, uint actionId), List<KeyChord> chords) in _bindings)
|
||||
{
|
||||
var chordList = new List<object>();
|
||||
foreach (KeyChord chord in chords)
|
||||
{
|
||||
var entry = new SortedDictionary<string, object>(StringComparer.Ordinal)
|
||||
{
|
||||
["key"] = chord.Key.ToString(),
|
||||
};
|
||||
if (chord.Modifiers != ModifierMask.None) entry["mod"] = chord.Modifiers.ToString();
|
||||
if (chord.Device != 0) entry["device"] = (int)chord.Device;
|
||||
chordList.Add(entry);
|
||||
}
|
||||
rows.Add(new SortedDictionary<string, object>(StringComparer.Ordinal)
|
||||
{
|
||||
["inputMap"] = $"0x{inputMapId:X}",
|
||||
["action"] = $"0x{actionId:X}",
|
||||
["chords"] = chordList,
|
||||
});
|
||||
}
|
||||
|
||||
var root = new Dictionary<string, object> { ["version"] = 1, ["rows"] = rows };
|
||||
File.WriteAllText(path, JsonSerializer.Serialize(root, new JsonSerializerOptions { WriteIndented = true }));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue