128 lines
5.4 KiB
C#
128 lines
5.4 KiB
C#
using AcDream.UI.Abstractions.Input;
|
|
|
|
namespace AcDream.App.Input;
|
|
|
|
internal interface IMovementInputSource
|
|
: IRuntimeMovementInputSource
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Samples held graphical input and maps press edges onto the Runtime-owned
|
|
/// retail autorun latch. The dispatcher remains the only physical
|
|
/// keyboard/mouse-button state source.
|
|
/// </summary>
|
|
internal sealed class DispatcherMovementInputSource : IMovementInputSource
|
|
{
|
|
private readonly RuntimeLocalPlayerMovementState _movement;
|
|
private readonly IInputCaptureSource? _capture;
|
|
private InputDispatcher? _dispatcher;
|
|
|
|
public DispatcherMovementInputSource(
|
|
RuntimeLocalPlayerMovementState movement,
|
|
IInputCaptureSource? capture = null)
|
|
{
|
|
_movement = movement ?? throw new ArgumentNullException(nameof(movement));
|
|
_capture = capture;
|
|
}
|
|
|
|
public bool AutoRunActive => _movement.AutoRunActive;
|
|
public bool IsAvailable => _dispatcher is not null;
|
|
|
|
public void Bind(InputDispatcher dispatcher)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(dispatcher);
|
|
if (_dispatcher is not null && !ReferenceEquals(_dispatcher, dispatcher))
|
|
throw new InvalidOperationException(
|
|
"The movement input source is already bound to another dispatcher.");
|
|
_dispatcher = dispatcher;
|
|
}
|
|
|
|
public void Unbind(InputDispatcher dispatcher)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(dispatcher);
|
|
if (ReferenceEquals(_dispatcher, dispatcher))
|
|
_dispatcher = null;
|
|
}
|
|
|
|
public MovementInput Capture()
|
|
{
|
|
// Logout round (2026-08-17): retail disables the command interpreter
|
|
// the moment the logoff request goes on the wire
|
|
// (CPlayerSystem::RequestLogOff @ 0x00562E6D ->
|
|
// CommandInterpreter::HandleLogOff @ 0x006B3330 -> Disable) — held
|
|
// keys stop producing movement while the server-broadcast LogOut
|
|
// motion plays.
|
|
if (_movement.CommandInterpreterDisabled)
|
|
return default;
|
|
|
|
// Devtools owns the whole gameplay keyboard while active, including
|
|
// a latched autorun. Retained chat owns physical key state only;
|
|
// retail's autorun latch continues until an explicit cancel action.
|
|
if (_capture?.DevToolsWantCaptureKeyboard == true)
|
|
return default;
|
|
|
|
if (_movement.HasCommandInput)
|
|
return _movement.CommandInput with { IsPersistentCommand = true };
|
|
|
|
if (_dispatcher is not { } dispatcher)
|
|
return default;
|
|
|
|
bool walking = dispatcher.IsActionHeld(InputAction.MovementWalkMode);
|
|
bool forward = dispatcher.IsActionHeld(InputAction.MovementForward);
|
|
return new MovementInput(
|
|
Forward: forward || AutoRunActive,
|
|
Backward: dispatcher.IsActionHeld(InputAction.MovementBackup),
|
|
StrafeLeft: dispatcher.IsActionHeld(InputAction.MovementStrafeLeft),
|
|
StrafeRight: dispatcher.IsActionHeld(InputAction.MovementStrafeRight),
|
|
TurnLeft: dispatcher.IsActionHeld(InputAction.MovementTurnLeft),
|
|
TurnRight: dispatcher.IsActionHeld(InputAction.MovementTurnRight),
|
|
// Movement parity audit (2026-07-30): retail's autorun hard-forces
|
|
// Run for its whole duration (ACCmdInterp autorun dispatch always
|
|
// sends RunForward-class state); the live walk/run toggle only
|
|
// applies to ordinary held-key movement. Recomputing `!walking`
|
|
// unconditionally let a walk-mode toggle demote an active autorun
|
|
// to walking — impossible in retail.
|
|
//
|
|
// Campaign OP slice OP4 (2026-08-11): `!walking` was a hardcoded
|
|
// "run by default" assumption. Retail PlayerOption id 0xA
|
|
// (acclient.h's ToggleRun_PlayerOption — ACE calls the same bit
|
|
// RunAsDefaultMovement; N7, OP4 review-fix round 2026-08-11)
|
|
// (retail default ON, matching the prior hardcoded behavior
|
|
// exactly) now supplies the default; the walk-mode modifier
|
|
// still temporarily INVERTS whichever default is active, same
|
|
// as before.
|
|
Run: (_movement.RunAsDefaultMovement != walking) || AutoRunActive,
|
|
Jump: dispatcher.IsActionHeld(InputAction.MovementJump));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Applies the press-only autorun policy at the same point in the semantic
|
|
/// action pipeline as the former GameWindow body.
|
|
/// </summary>
|
|
/// <returns>True when the action is fully consumed.</returns>
|
|
public bool HandlePressedAction(InputAction action)
|
|
{
|
|
if (action == InputAction.MovementRunLock)
|
|
return _movement.Execute(
|
|
AcDream.Runtime.RuntimeMovementCommand.ToggleRunLock);
|
|
|
|
if (AutoRunActive && action is (
|
|
// Movement parity audit (2026-07-30): retail's
|
|
// ACCmdInterp::HandleNewForwardMovement drops autorun on EVERY
|
|
// fresh forward press edge, not only on backward/stop/strafe —
|
|
// a new W press while autorunning hands control back to the key.
|
|
InputAction.MovementForward
|
|
or InputAction.MovementBackup
|
|
or InputAction.MovementStop
|
|
or InputAction.MovementStrafeLeft
|
|
or InputAction.MovementStrafeRight))
|
|
{
|
|
_movement.CancelAutoRun();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void ResetSession() => _movement.ResetInputIntent();
|
|
}
|