Ports the three retail outbound-movement packers verbatim (decomp-derived golden bytes, confirmed via the Ghidra bridge, cross-checked vs holtburger): - D1 — RawMotionState::Pack (0x0051ed10): new AcDream.Core.Physics.RawMotionState data type (11 fields + actions, retail defaults) + RawMotionStatePacker that sets a flag bit only when the field DIFFERS from its default. MoveToState.Build now takes a RawMotionState instead of presence-based nullable params, so the over-sent forwardSpeed=1.0 / currentHoldKey=None / default per-axis holdkeys are no longer emitted. num_actions packs into bits 11-15 (not "bits 11-31"). - D3 — MoveToStatePack::Pack (0x005168f0) trailing byte = (standingLongjump ? 0x02 : 0) | (contact ? 0x01 : 0); explicit contact/ standingLongjump params (standingLongjump=false honestly until the feature lands). - D4 — JumpAction rewritten to retail JumpPack::Pack (0x00516d10): extent, velocity, full Position, four u16 timestamps, align. Removed the spurious objectGuid/spellId u32s; Position is now packed (it was absent). Body 56 bytes. - Position::Pack (0x005a9640) / Frame::Pack (0x00535130) verified already-correct (cellId, origin xyz, quaternion wxyz); locked with a golden test, no change. GameWindow callers adapted minimally: build the RawMotionState from the existing MovementResult values (behavior preserved except the intended D1 omissions) and pass cellId/position/rotation to the Jump send. Pre-existing MotionInterpreter placeholder struct RawMotionState renamed LegacyRawMotionState (D6/Phase-2 scope, pure rename) to free the name for the retail-faithful type. D5 audit: confirmed a real divergence — retail SendMovementEvent (0x006b4680) stamps only last_sent_position_time after an MTS while SendPositionEvent (0x006b4770) stamps all three; acdream's NotePositionSent stamps all three on both paths. Left unchanged (comments added at both call sites), recorded as register TS-33, deferred to a dedicated cadence-port slice. Tests: RawMotionStatePackTests / MoveToStateGoldenTests / JumpActionTests / PositionPackTests + updated MoveToStateTests / AutonomousPositionTests. Full suite green (Core.Net.Tests 372, full solution 3228 passed / 4 pre-existing skips). Register: TS-24/TS-25 refreshed (packer now supports actions/style; runtime emission still deferred), TS-33 added. Roadmap L.2b shipped note added. Spec: docs/superpowers/specs/2026-06-30-movement-wire-parity-design.md (2-6) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
107 lines
4.7 KiB
C#
107 lines
4.7 KiB
C#
using System.Numerics;
|
|
using AcDream.Core.Net.Packets;
|
|
using AcDream.Core.Physics;
|
|
|
|
namespace AcDream.Core.Net.Messages;
|
|
|
|
/// <summary>
|
|
/// Outbound <c>GameAction(MoveToState)</c> message — opcode <c>0xF61C</c>.
|
|
/// Sent whenever the client's motion state changes: starting or stopping
|
|
/// walking, switching direction, changing speed, entering or leaving combat
|
|
/// stance. The server uses this to update the player's authoritative motion
|
|
/// state and to drive interpolated position for other nearby clients.
|
|
///
|
|
/// <para>
|
|
/// Wire layout — ports retail's <c>MoveToStatePack::Pack</c> verbatim
|
|
/// (<c>0x005168f0</c>, decomp lines ~284694-284722). Confirmed against the
|
|
/// Ghidra decompile-by-address bridge during this slice (2026-06-30):
|
|
/// </para>
|
|
/// <list type="bullet">
|
|
/// <item><b>GameAction envelope</b>: u32 0xF7B1, u32 sequence, u32 0xF61C</item>
|
|
/// <item><b>RawMotionState::Pack</b>: see <see cref="RawMotionStatePacker"/>
|
|
/// — default-difference flags dword + conditional fields + actions.</item>
|
|
/// <item><b>Position::Pack</b>: u32 cellId, f32 x, f32 y, f32 z,
|
|
/// f32 qw, f32 qx, f32 qy, f32 qz (32 bytes)</item>
|
|
/// <item><b>Sequences</b>: u16 instance, u16 serverControl,
|
|
/// u16 teleport, u16 forcePosition</item>
|
|
/// <item><b>Trailing byte</b>: <c>(standingLongjump ? 0x02 : 0) |
|
|
/// (contact ? 0x01 : 0)</c> — <c>MoveToStatePack::Pack</c> trailing
|
|
/// byte expression <c>(longjump_mode == 0) - 1U & 2 |
|
|
/// contact != 0</c>.</item>
|
|
/// <item><b>Align to 4 bytes</b></item>
|
|
/// </list>
|
|
/// </summary>
|
|
public static class MoveToState
|
|
{
|
|
public const uint GameActionOpcode = 0xF7B1u;
|
|
public const uint MoveToStateAction = 0xF61Cu;
|
|
|
|
/// <summary>
|
|
/// Build a MoveToState GameAction body.
|
|
/// </summary>
|
|
/// <param name="gameActionSequence">Monotonically increasing counter from
|
|
/// <see cref="WorldSession.NextGameActionSequence"/>.</param>
|
|
/// <param name="rawMotionState">Complete raw-motion snapshot, matching
|
|
/// retail's <c>CPhysicsObj::InqRawMotionState()</c>. Fields equal to
|
|
/// <see cref="RawMotionState.Default"/> are omitted from the wire
|
|
/// (see <see cref="RawMotionStatePacker"/>).</param>
|
|
/// <param name="cellId">Landblock cell ID (u32).</param>
|
|
/// <param name="position">World-space position relative to the landblock.</param>
|
|
/// <param name="rotation">Rotation quaternion. AC wire order is W, X, Y, Z.</param>
|
|
/// <param name="instanceSequence">Instance sequence number from the server.</param>
|
|
/// <param name="serverControlSequence">Server-control sequence number.</param>
|
|
/// <param name="teleportSequence">Teleport sequence number.</param>
|
|
/// <param name="forcePositionSequence">Force-position sequence number.</param>
|
|
/// <param name="contact">True if the character is on the ground.</param>
|
|
/// <param name="standingLongjump">True during a standing (charged,
|
|
/// stationary) longjump wind-up. Not yet implemented in acdream —
|
|
/// callers pass <c>false</c> honestly until that feature lands.</param>
|
|
public static byte[] Build(
|
|
uint gameActionSequence,
|
|
RawMotionState rawMotionState,
|
|
uint cellId,
|
|
Vector3 position,
|
|
Quaternion rotation,
|
|
ushort instanceSequence,
|
|
ushort serverControlSequence,
|
|
ushort teleportSequence,
|
|
ushort forcePositionSequence,
|
|
bool contact = true,
|
|
bool standingLongjump = false)
|
|
{
|
|
var w = new PacketWriter(128);
|
|
|
|
// --- GameAction envelope ---
|
|
w.WriteUInt32(GameActionOpcode);
|
|
w.WriteUInt32(gameActionSequence);
|
|
w.WriteUInt32(MoveToStateAction);
|
|
|
|
// --- RawMotionState::Pack (0x0051ed10) ---
|
|
RawMotionStatePacker.Pack(w, rawMotionState);
|
|
|
|
// --- Position::Pack (0x005a9640): cellId + Frame::Pack (32 bytes) ---
|
|
w.WriteUInt32(cellId);
|
|
w.WriteFloat(position.X);
|
|
w.WriteFloat(position.Y);
|
|
w.WriteFloat(position.Z);
|
|
// Quaternion wire order: W, X, Y, Z
|
|
w.WriteFloat(rotation.W);
|
|
w.WriteFloat(rotation.X);
|
|
w.WriteFloat(rotation.Y);
|
|
w.WriteFloat(rotation.Z);
|
|
|
|
// --- Sequence numbers ---
|
|
w.WriteUInt16(instanceSequence);
|
|
w.WriteUInt16(serverControlSequence);
|
|
w.WriteUInt16(teleportSequence);
|
|
w.WriteUInt16(forcePositionSequence);
|
|
|
|
// --- Trailing byte (MoveToStatePack::Pack, 0x005168f0): ---
|
|
// ((longjump_mode != 0) ? 0x02 : 0) | (contact != 0 ? 0x01 : 0)
|
|
byte trailing = (byte)((standingLongjump ? 0x02 : 0) | (contact ? 0x01 : 0));
|
|
w.WriteByte(trailing);
|
|
w.AlignTo4();
|
|
|
|
return w.ToArray();
|
|
}
|
|
}
|