commit 14367a9330b84a65c8649fe3c0c2124d9e732c14
parent 6a1e4d03b06548294daa57388c81d6f33b741731
Author: anon <anon@example.com>
Date: Mon, 26 Oct 2026 15:22:48 +0000
Simulate native flight exits and restore observer ground modes
Walk/run requests leave flight through shared position-only exit placement,
preserving velocity, gravity, unrelated controls and the worn item. Walking
restores stat197 orientation; running retains mode4. Equipment removal shares
the exit placement while retaining its own authored effect.
Restore late observers' ground modes after authored flight OnWear replay,
including idle and following actors. Use the native mode-only update followed
by a pose anchor so the callback's extra lift does not accumulate.
Validation: all 1321 server roots / 14343 results; 60 focused roots / 148 results;
150 race roots / 431 results; data tests and vet. Four controller regression
roots and the separate observer-replay root fail against their old code.
Paired headed GPU WASM checks verify real remote callbacks from explicit
C2S22/23 inputs, distinct orientation, two reloads per mode, normal equipment
UI and the same persisted item. Read-only guest probes; no page errors. Cleaned
owned fixtures and left one HTTPS preview running with the verified build.
Diffstat:
6 files changed, 347 insertions(+), 20 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -1314,10 +1314,15 @@ disconnect retention and succession policy still need period corroboration.
explicitly standing before release, water exit with both preferred modes,
and ordinary admitted turning/walk/run. See
[physical admission](docs/player-movement.md#physical-movement-admission).
+- [x] Apply walk/run callbacks while flying. Share position-only exit placement
+ with equipment removal, preserving vector velocity, existing gravity and
+ unrelated controls. Walk22 restores stat197 orientation; run23 keeps mode4.
+ Keep the vehicle worn, and restore ground modes for late observers after
+ authored flight OnWear replay, followed by a pose-only anchor. Include idle
+ actors and following actors. See
+ [ground requests during flight](docs/player-movement.md#ground-mode-requests-during-flight).
- [ ] Complete native movement callbacks and posture admission. Check sit28's
- forward/strafe/turn state gate, stand33's Features4 handling, and walk/run
- while flying against the complete builder/callback table. Walk and run have
- different orientation restoration when leaving flight. Complete the frozen
+ forward/strafe/turn state gate and stand33's Features4 handling. Complete the frozen
and sneak state lifecycles before claiming the whole helper state machine.
Trace the complete sneak flow before admitting movement26/32; ordinary
sit/stand86/87 uses helper28/33 instead. Crawl25 is only bound to an exported
diff --git a/docs/player-movement.md b/docs/player-movement.md
@@ -142,10 +142,60 @@ classification remains in TODO and is not claimed as exact trajectory parity.
The predicate retains the source's eight-mode rules. Existing server lifecycle
support remains walking/running, swimming, flying and sitting; copying the
predicate does not implement frozen/sneak transitions. Sit/stand builder gates
-and flight-to-walk/run callbacks remain explicit TODOs. The verified source
+remain explicit TODOs. The verified source
tables remain under `local/player-flight-input/research/helpers/`; this
milestone's tests and paired traces are under `local/player-movement-mode/`.
+## Ground mode requests during flight
+
+Accepted walk22/run23 requests leave flight while keeping the item worn, its
+model and its bonuses. They set the preferred ground mode, enable new falls,
+raise Y by float32(0.1) through position-only placement, and clear vertical
+control. They preserve vector velocity, existing gravity, ordinary controls and
+helper component history. Equipment removal shares that placement and control
+update; it still applies its own authored effect when the item is removed after
+an earlier ground-mode request.
+
+The native callbacks have different orientation rules. Walk restores stat197
+after placement, so an idle pitched body levels on its next ground frame. Run
+keeps orientation mode4, including its three-dimensional facing. Selecting run
+must not invoke the full equipment-removal callback and restore mode0.
+Sources: `client/game/kkr.dll/lifted-0022.c`, `sub_36046270`, `sub_36046080`
+and `sub_360468F0`.
+
+A new observer loads the snapshot's helper before later worn OnWear effects.
+An authored53138 effect then enters flight again, overriding a serialized
+ground mode. The replay checks the worn functions for53138 and restores2/3
+after OnWear through the native mode-only message575F6628. That message preserves
+follow. A following0x94 pose anchor removes the exit callback's extra lift
+without another helper transition. Include idle and following actors; the usual
+active-motion filter alone skips both cases. Repeated same-mode requests reject
+before callbacks, so another ready refresh does not accumulate height.
+
+The source-only initialization ledger under
+`local/player-flight-ground/research/initialization/` binds71 complete bodies
+and34 input hashes. It establishes the concrete SCFU reader, worn-effect order,
+mode-only consumer and correction guards. No lift-free live helper-snapshot
+setter was established. Pose anchoring still runs ordinary collision/contact
+logic; it does not prove that intermediate placement has no physical effects.
+
+All 1,321 server roots (14,343 results), 60 focused roots (148 results), 150 race
+roots (431 results), data tests and go vet pass. Four regression roots fail
+against the previous controller; the observer-ordering root separately fails
+against the previous replay. Native transport tests cover idle and following
+actors for both modes.
+
+Paired GPU WASM captures use explicit C2S22/23 test packets through the
+ordinary JS transport, with read-only guest probes. The real remote client
+lands in walk2/orientation0 or run3/orientation4 and retains that state across
+two reloads per mode, within0.00001m of the server's settled position. The
+synthetic sender's native controller intentionally stays in flight until normal
+UI removal. Its fall from Y60 and the already-grounded remote produce different
+contact histories on human restoration; ordinary movement reconciles their
+positions. Normal UI wear/removal returns the same item to slot64 in SQLite,
+and both clients report no page errors. These are settled-state and effect-order
+checks, not a claim of exact airborne/loading trajectory parity.
+
## Flight transitions and facing
The shared OnWear iterator consumes authored function 53138 in order with shape
diff --git a/server/player_flight.go b/server/player_flight.go
@@ -13,28 +13,34 @@ func (player *character) changeFlight(remove bool) {
return
}
movement.components[5] = movement.components[3]
- movement.components[0] = 7
- lift := float32(.5)
if remove {
- movement.components[0] = 2
- if player.running {
- movement.components[0] = 3
- }
- lift = .1
+ player.leaveFlight()
+ movement.orientation = uint32(player.inventory.equipmentBonus(197) + player.nanoBonus(197))
+ return
}
+ movement.components[0] = 7
// SetRelPos preserves V and q, aligns with the previous orientation mode,
// and stores the requested position as the fall-height history.
// Sources: kkr.dll 36046770/360468F0; qqr.dll 420108F0/42011D00.
position := player.position
- position[1] += lift
+ position[1] += .5
player.placePosition(position)
- if remove {
- movement.vertical = 0
- movement.orientation = uint32(player.inventory.equipmentBonus(197) + player.nanoBonus(197))
- } else {
- movement.orientation = 4
+ movement.orientation = 4
+}
+
+func (player *character) leaveFlight() {
+ // The ground mode admits falling during position-only placement. Preserve
+ // the old orientation until the caller applies its callback's distinct rule.
+ // Source: client/game/kkr.dll/lifted-0022.c, sub_36046080/36046270/360468F0.
+ player.movement.components[0] = 2
+ if player.running {
+ player.movement.components[0] = 3
}
+ position := player.position
+ position[1] += .1
+ player.placePosition(position)
+ player.movement.vertical = 0
}
func (player *character) orientMovement() {
diff --git a/server/player_flight_modes_test.go b/server/player_flight_modes_test.go
@@ -0,0 +1,235 @@
+package main
+
+import (
+ "encoding/binary"
+ "fmt"
+ "math"
+ "net"
+ "testing"
+ "time"
+)
+
+func TestPlayerFlightWalkAndRunPreserveUnrelatedMotionAndEquipment(t *testing.T) {
+ for _, action := range []uint32{22, 23} {
+ for _, running := range []bool{false, true} {
+ t.Run(fmt.Sprintf("action%d/preferredRun%t", action, running), func(t *testing.T) {
+ world := newPlayerFormWorld(t, 117322)
+ player, client := world.characters[1], world.clients[1]
+ player.running = running
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ player.position = [3]float32{961.625, 60, 510.75}
+ player.movement.velocity, player.movement.speed = [3]float32{3, 4, 0}, 5
+ player.movement.forward, player.movement.strafe, player.movement.turn, player.movement.vertical = 1, 2, 1.5, 6
+ player.movement.components = [10]byte{7, 3, 1, 3, 4, 3, 5, 5, 4, 4}
+ body, item := player.body, player.inventory.Items[0]
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: 705, health: 100}
+ world.clients[2] = &worldClient{id: 2, ready: true, target: true, conn: observer}
+
+ if err := world.handleMovement(client, playerMovementRequest(player, action)); err != nil {
+ t.Fatal(err)
+ }
+
+ mode, orientation := byte(2), uint32(0)
+ if action == 23 {
+ mode, orientation = 3, 4
+ }
+ if player.flying() || player.running != (action == 23) || player.movement.components[0] != mode || player.movement.orientation != orientation || binary.BigEndian.Uint32(player.vehicleState()[22:26]) != uint32(mode) {
+ t.Fatal("walk/run did not leave flight with its distinct orientation and preferred mode", player.movement, player.running)
+ }
+ if player.position != [3]float32{961.625, 60.1, 510.75} || player.movement.previousPosition != player.position || player.movement.velocity != [3]float32{3, 4, 0} || player.movement.speed != 5 || !player.movement.falling || player.movement.fallHeight != 60.1 {
+ t.Fatal("walk/run exit lost position-only placement or falling admission", player.position, player.movement)
+ }
+ if player.movement.forward != 1 || player.movement.strafe != 2 || player.movement.turn != 1.5 || player.movement.vertical != 0 || player.movement.components != [10]byte{mode, 3, 1, 3, 4, 3, 5, 5, 4, 4} {
+ t.Fatal("walk/run exit changed unrelated controls or helper state", player.movement)
+ }
+ if player.body != body || player.inventory.Items[0] != item || player.height != 150 {
+ t.Fatal("a movement mode request changed the worn vehicle or its body", player.body, player.inventory)
+ }
+ if len(observer.packets) != 1 || observer.packets[0][29] != byte(action) || binary.BigEndian.Uint16(observer.packets[0][32:34]) != 960 {
+ t.Fatal("observer must receive the original pose and action before its own native lift", observer.packets)
+ }
+ })
+ }
+ }
+}
+
+func TestPlayerFlightWalkAndRunPreserveExistingGravity(t *testing.T) {
+ for _, action := range []uint32{22, 23} {
+ t.Run(fmt.Sprint(action), func(t *testing.T) {
+ world := newPlayerFormWorld(t, 117322)
+ player, client := world.characters[1], world.clients[1]
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ player.position[1] = 60
+ player.movement.falling, player.movement.verticalVelocity, player.movement.fallHeight = true, -12, 1000
+
+ if err := world.handleMovement(client, playerMovementRequest(player, action)); err != nil {
+ t.Fatal(err)
+ }
+ exit, impulse := player.position, player.movement.verticalVelocity
+ world.advancePlayerMovement(player.movement.updatedAt.Add(100 * time.Millisecond))
+
+ if exit != [3]float32{961.625, 60.1, 510.75} || impulse != -12 || player.movement.verticalVelocity != -14 || player.movement.fallHeight != 1000 || !player.movement.falling || math.Abs(float64(player.position[1])-58.7) > .00001 {
+ t.Fatal("leaving flight reset existing gravity or fall history", exit, impulse, player.position, player.movement)
+ }
+ })
+ }
+}
+
+func TestPlayerFlightWalkLevelsFacingButRunRetainsFlightOrientation(t *testing.T) {
+ for _, action := range []uint32{22, 23} {
+ t.Run(fmt.Sprint(action), func(t *testing.T) {
+ world := newPlayerFormWorld(t, 117322)
+ player, client := world.characters[1], world.clients[1]
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ player.position[1] = 60
+ player.rotation = [4]float32{-.38268343, 0, 0, .9238795}
+
+ if err := world.handleMovement(client, playerMovementRequest(player, action)); err != nil {
+ t.Fatal(err)
+ }
+ exit, _ := bodyAxes(player.rotation)
+ world.advancePlayerMovement(player.movement.updatedAt.Add(100 * time.Millisecond))
+
+ forward, _ := bodyAxes(player.rotation)
+ if exit[1] < .7 || !player.movement.falling || player.flying() {
+ t.Fatal("exit must place in the previous orientation before restoring ground physics", exit, player.movement)
+ }
+ if action == 22 && forward != [3]float32{0, 0, 1} || action == 23 && forward[1] < .7 {
+ t.Fatal("walk and run must have distinct orientation restoration", forward, player.rotation, player.movement)
+ }
+ })
+ }
+}
+
+func TestPlayerFlightEquipmentRemovalStillAppliesAfterWalkOrRun(t *testing.T) {
+ for _, action := range []uint32{22, 23} {
+ t.Run(fmt.Sprint(action), func(t *testing.T) {
+ world := newPlayerFormWorld(t, 117322)
+ player, client := world.characters[1], world.clients[1]
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ player.position[1] = 60
+ if err := world.handleMovement(client, playerMovementRequest(player, action)); err != nil {
+ t.Fatal(err)
+ }
+ item := player.inventory.Items[0]
+ if err := world.handleInventory(client, itemMovePacket(1, 1, 111)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("removal was not scheduled", err)
+ }
+ finish := client.equipment.readyAt
+ player.movement.updatedAt = finish
+ before := player.position
+
+ world.advanceEquipment(finish)
+
+ if math.Abs(float64(player.position[1]-before[1])-.1) > .00001 || player.movement.orientation != 0 || player.flying() || player.inventory.Items[0].ID != item.ID || player.inventory.Items[0].Slot != 64 || !player.movement.falling {
+ t.Fatal("equipment removal lost its own exit effect or the original item", player.position, player.movement, player.inventory)
+ }
+ })
+ }
+}
+
+func TestPlayerFlightWalkAndRunPlacementCanEnterSwimming(t *testing.T) {
+ for _, action := range []uint32{22, 23} {
+ t.Run(fmt.Sprint(action), func(t *testing.T) {
+ world := newPlayerFormWorld(t, 117322)
+ player, client := world.characters[1], world.clients[1]
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ player.position = [3]float32{100, 6.5, 25}
+ player.movement.strafe, player.movement.vertical = 2, 6
+ player.movement.components[3], player.movement.components[4] = 3, 4
+
+ if err := world.handleMovement(client, playerMovementRequest(player, action)); err != nil {
+ t.Fatal(err)
+ }
+
+ if player.flying() || player.running != (action == 23) || !player.movement.deepWater || player.movement.components[0] != 4 || player.movement.strafe != 0 || player.movement.vertical != 0 || player.movement.components[3] != 3 || player.position[0] != 100 || player.position[2] != 25 || player.inventory.Items[0].Slot != 1 {
+ t.Fatal("flight exit overwrote water admission or retained its lateral control", player.position, player.movement, player.inventory)
+ }
+ })
+ }
+}
+
+func TestPlayerFlightGroundModeReplayedAfterWearForNewObserver(t *testing.T) {
+ for _, action := range []uint32{22, 23} {
+ for _, following := range []bool{false, true} {
+ t.Run(fmt.Sprintf("action%d/following%t", action, following), func(t *testing.T) {
+ world := newPlayerFormWorld(t, 117322)
+ player, client := world.characters[1], world.clients[1]
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ player.position[1] = 60
+ if err := world.handleMovement(client, playerMovementRequest(player, action)); err != nil {
+ t.Fatal(err)
+ }
+ world.advancePlayerMovement(player.movement.updatedAt.Add(4 * time.Second))
+ if player.flying() || player.movement.active() {
+ t.Fatal("fixture must settle in a ground mode with its flight item still worn", player.position, player.movement)
+ }
+ world.nextCharacter = 1
+ observer := world.newCharacter_locked()
+ observer.playfield = 705
+ if following {
+ player.followTarget = observer.id
+ }
+ connection, host := net.Pipe()
+ t.Cleanup(func() { connection.Close() })
+ connection.SetDeadline(time.Now().Add(5 * time.Second))
+ go func() { defer host.Close(); world.serveWorldConnection(host) }()
+ cookie := systemPacket(0x1b, append(binary.BigEndian.AppendUint32(nil, observer.id), make([]byte, 8)...))
+ binary.BigEndian.PutUint16(cookie, 0xdfdf)
+
+ if _, err := connection.Write(cookie); err != nil {
+ t.Fatal(err)
+ }
+ wear, restore, anchor := -1, -1, -1
+ for index := 0; ; index++ {
+ packet, err := readPacket(connection)
+ if err != nil {
+ t.Fatal(err)
+ }
+ key := binary.BigEndian.Uint32(packet[16:20])
+ if key == 0x5f52412e {
+ break
+ }
+ if key != 0x35505644 && key != 0x575f6628 && key != 0x54111123 {
+ continue
+ }
+ if binary.BigEndian.Uint32(packet[24:28]) != 1 {
+ continue
+ }
+ if key == 0x35505644 && binary.BigEndian.Uint32(packet[45:49]) == 6 {
+ wear = index
+ }
+ if key == 0x575f6628 && binary.BigEndian.Uint32(packet[29:33]) == action {
+ restore = index
+ }
+ if key == 0x54111123 && packet[29] == 0x94 {
+ anchor = index
+ }
+ }
+
+ if wear < 0 || restore <= wear || anchor <= restore {
+ t.Fatal("new observer must restore the ground mode after worn effects, then anchor the native lift", wear, restore, anchor)
+ }
+ })
+ }
+ }
+}
diff --git a/server/player_follow.go b/server/player_follow.go
@@ -96,7 +96,21 @@ func (server *server) playerMovementReplay_locked(observer *worldClient, now tim
var packets [][]byte
for id, client := range server.clients {
player := server.characters[id]
- if id == observer.id || !client.ready || client.loading || !player.movement.active() && !player.flying() || player.playfield != server.characters[observer.id].playfield || player.followTarget != 0 && player.movement.direction >= 0 {
+ if id == observer.id || !client.ready || client.loading || player.playfield != server.characters[observer.id].playfield {
+ continue
+ }
+ // Worn flight effects replay after the snapshot and can replace its ground mode.
+ restoreGround := false
+ if player.movement.components[0] == 2 || player.movement.components[0] == 3 {
+ for _, item := range player.inventory.Items {
+ for function := range item.wearFunctions {
+ if function.ID == 53138 {
+ restoreGround = true
+ }
+ }
+ }
+ }
+ if !restoreGround && (!player.movement.active() && !player.flying() || player.followTarget != 0 && player.movement.direction >= 0) {
continue
}
snapshot := player.predictedMovement(now)
@@ -107,7 +121,17 @@ func (server *server) playerMovementReplay_locked(observer *worldClient, now tim
// necessarily restarts acceleration; see docs/player-movement.md.
packets = append(packets, npcMovementPacket(&snapshot, 4), npcMovementPacket(&snapshot, 3))
}
- packets = append(packets, npcMovementPacket(&snapshot, 20))
+ if restoreGround && (snapshot.movement.components[0] == 2 || snapshot.movement.components[0] == 3) {
+ action := uint32(22)
+ if snapshot.running {
+ action = 23
+ }
+ // Mode-only updates preserve follow. Their native exit adds .1; the
+ // following pose correction anchors it without another transition.
+ packets = append(packets, n3Packet(0x575f6628, 50000, id, binary.BigEndian.AppendUint32(nil, action)), npcMovementPacket(&snapshot, 0x94))
+ } else {
+ packets = append(packets, npcMovementPacket(&snapshot, 20))
+ }
}
return packets
}
diff --git a/server/player_movement.go b/server/player_movement.go
@@ -440,7 +440,14 @@ func (movement *playerMovement) action(player *character, action uint32) bool {
}
case 22, 23:
player.running = action == 23
- movement.prepare(player, movement.updatedAt)
+ if old[0] == 7 {
+ player.leaveFlight()
+ if action == 22 {
+ movement.orientation = uint32(player.inventory.equipmentBonus(197) + player.nanoBonus(197))
+ }
+ } else {
+ movement.prepare(player, movement.updatedAt)
+ }
case 20:
return true
}