commit b11c1c03501436a10b6a33c9bc64ac08f3bdf725
parent 07fe521166a42885605f0e2568c0f735bdae0fe7
Author: anon <anon@example.com>
Date: Thu, 22 Oct 2026 09:50:48 +0000
Restore defeated players through native resurrection
Diffstat:
8 files changed, 338 insertions(+), 5 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -131,7 +131,7 @@ recorded in [inventory behavior](docs/inventory.md).
- [x] Respawn one creature. Check: after the profile's respawn interval, exactly
one living replacement appears with fresh resources and no old fight state.
-- [ ] Resurrect a player through the native flow. Check: death leads to a valid
+- [x] Resurrect a player through the native flow. Check: death leads to a valid
resurrection location and usable character without reloading the browser.
- [ ] Save a resurrection location. Check: using one save terminal persists the
location and a later death returns the character there.
@@ -142,6 +142,8 @@ recorded in [inventory behavior](docs/inventory.md).
The Leet's replacement lifecycle and explicitly provisional delay are recorded
in [creature respawn](docs/npc-respawn.md).
+Native player return and provisional location/resources are recorded in
+[player resurrection](docs/player-resurrection.md).
## Loot and credits
diff --git a/docs/combat-client-protocol.md b/docs/combat-client-protocol.md
@@ -136,7 +136,7 @@ which can differ from object-field order.
| SpecialAttackWeapon / `0x1d3c0f1c` | encoded weapon list, five i32 values `+24..+34` | Reader `0x10083f00`. Activation `0x10083fb0` rebuilds available weapon state and applies stats 118,119,120,149,51 (initiatives and Agg/Def). List layout described below. |
| Skill / `0x3e205660` | i32 count, then count pairs `(i32 stat, i32 value)` | `0x10083d30` -> `0x10008c90`; activation `0x10083d80` assigns each stat. This is not evidence that a plain stat assignment starts a skill-lock countdown. |
| Action / `0x2049527c` | i32 version **1**, i32 action `+20`, identity argument `+24` | Reader `0x100aea40`; activation `0x100aeaa0` dispatches to the actor/item action handler. Receiver rejects another version. Individual action contracts remain partial. |
-| Resurrect / `0x445f2a0b` | two i32 values `+20,+24` | Reader `0x100b08d0`; activation `0x10080e20` assigns these to stats 27 and 214, then calls `0x10053230`. Full reclaim and resurrection behavior remain unresolved. |
+| Resurrect / `0x445f2a0b` | two i32 values `+20,+24` | Reader `0x100b08d0`; activation `0x10080e20` assigns these to stats 27 and 214, then calls `0x10053230`. The server now handles the native action-152 return; insurance, reclaim and historical resource amounts remain unresolved. See [player resurrection](player-resurrection.md). |
`SpecialAttackWeapon` uses `0x100767d0`: an encoded count of
`1009 * (count + 1)`, then four i32 values per entry. The reader stores these
diff --git a/docs/combat-client-reconstruction.md b/docs/combat-client-reconstruction.md
@@ -72,7 +72,7 @@ unknowns for each area:
| Rule or behavior | Evidence status | Current server |
| --- | --- | --- |
| Attack, stop and basic hit layouts | Native reader/writer/activation plus runtime | Implemented and covered by native-wire tests |
-| Health/death presentation and ordering | Native handlers plus browser encounters | Implemented for basic PvE; reload revival remains local |
+| Health/death presentation and ordering | Native handlers plus browser encounters | Implemented for basic PvE; native player resurrection uses a provisional starter return |
| Weapon initiative/AggDef formulas | Exact native arithmetic and integer conversion | QL 1 fists, editable Physical Initiative and ability trickle; 250 ms resolution tick |
| AggDef request and stat update | Native request/serializer plus real slider request | Implemented; scheduled swing keeps its deadline |
| QL 1 fist damage endpoints | Shipped item record | Normal uniform 3-5 roll; distribution and always-hit policy are local |
@@ -86,7 +86,8 @@ unknowns for each area:
| Resource regeneration | Native prediction formulas and injured-client probes | Authoritative player recovery; absolute quiet corrections reconcile prediction |
| Corpse loot | Native handlers and real combat/loot encounters | Fixed-item transfer persists; level-1 Leet corpses expire after a provisional 180 seconds; production drop tables remain unimplemented |
| Creature respawn | Explicit provisional level-1 Leet delay; historical district units unresolved | One fresh replacement after 100 seconds; see [respawn](npc-respawn.md) |
-| XP, reclaim and player resurrection | Separate rules and state required | Not implemented |
+| Player resurrection | Native action 152 and Resurrect handler | Automatic native return with provisional location/resources; see [player resurrection](player-resurrection.md) |
+| XP, reclaim and insurance | Separate rules and state required | Not implemented |
## Implementation order and acceptance checks
diff --git a/docs/player-resurrection.md b/docs/player-resurrection.md
@@ -0,0 +1,101 @@
+# Player resurrection
+
+Player death now follows the native 14.9.1 resurrection request and zone
+transition without reloading the browser. The return point is provisionally
+playfield 705, XYZ `[960, 16.5, 510]`, in the existing Omni starter area.
+Returned health and nano are provisionally 1 each. These are reconstruction
+choices, not verified historical server values.
+
+## Shipped evidence
+
+The original `anarchy-vanilla-14.9.1/kkr.dll` has SHA-256
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+Original addresses below use base `0x10000000`; generated C uses `0x36000000`.
+
+- The death-state update at `0x10086120` accumulates frame time after its
+ transition becomes active. After comparison against the float 3.0 at
+ `0x1017158c`, the local actor constructs CharacterAction 152 using
+ `0x1007d4b0` and sends it through the character's message interface.
+ See `client/game/kkr.dll/lifted-0039.c`, `sub_36086120`. This does not
+ establish the complete time from killing blow to request: animation and
+ presentation precede the active transition.
+- ResurrectIIR_t, wire key `0x445f2a0b`, carries two signed 32-bit integers.
+ Reader `0x100b08d0` and activation `0x10080e20` are described in the
+ [protocol report](combat-client-protocol.md). The activation assigns health
+ stat 27 and nano stat 214, then invokes character recovery helper
+ `0x10053230`. See `lifted-0038.c`, `sub_36080E20`.
+- The recovery helper clears the death presentation and enables visibility.
+ For local actors it also invokes level-dependent reclaim/shock feedback:
+ level 10 and higher takes the reclaim branch, and level 15 and higher takes
+ the resurrection-shock branch. These client branches do not establish the
+ original server's item transfer or stat penalty rules.
+
+The fresh REA recovery-helper decompilation is evidence
+`ev_c2a370e32e75f900b6adc42b43d81fd62a5402a7380724acda44b335bc925c2d`;
+the 3.0 float read is
+`ev_98d1aba4fb13a294634813a2fbb85252284e675cae05c9d9e3b813486dbe2550`.
+The export is `local/reports/resurrection-1491-evidence.json`. Current Ghidra
+auto-analysis did not define the resurrection activation/death update as
+functions, so those branches were checked against the maintained generated
+assembly rather than represented as fresh decompilation results. Retained
+death-constructor evidence is in `local/resurrection-smoke/retained-evidence.json`.
+The REA session was closed before runtime testing.
+
+Shipped help `cd_image/text/help/Death and insurance.txt` says a new body appears
+near the last saved insurance terminal, items become available at reclaim, and
+temporary weakness follows death. `cd_image/text/tips/OnResurrected.txt`
+describes reclaim and healing after return. Neither supplies the exact returned
+resource amounts or this prototype's default checkpoint.
+
+## Server transition and limits
+
+Only a ready, fully loaded, current session whose player is dead can request
+resurrection. The envelope must identify that session's own player. Repeated,
+stale, spoofed, alive and loading requests do nothing.
+
+The candidate return position is written atomically before changing live state
+or sending packets. A save failure leaves the dead character and session
+unchanged. On success the server clears posture, combat/recharge state and any
+old door return, restores the provisional resources, and sends Resurrect to
+nearby observers and the player. It then uses the existing teleport and world
+redirect sequence. The departing session is removed before another request can
+take effect. The replacement world session initializes the same character,
+equipment and inventory at the saved return point.
+
+Health and nano remain runtime state. Ordinary reconnect behavior still revives
+a defeated player with full health, and server restart initializes resources
+from the saved character profile. This milestone does not implement insurance
+terminals, saved resurrection points, item reclaim, XP loss or resurrection
+shock stat penalties. Inventory remains owned across death. Those features
+retain separate TODO entries.
+
+## Verification
+
+`server/resurrection_test.go` covers the native request/response order, durable
+arrival before reconnect, retained inventory after restart, movement after the
+new world handshake, concurrent repeated requests, both observers, stale and
+invalid sessions/identities, combat cleanup and save failure.
+
+Two published WASM clients exercised a full-health 37 HP player's defeat by the
+profiled 100 HP Leet. The native client sent action 152 automatically and
+returned with 1 HP/1 nano at `[960, 16.5, 510]`, without a page reload. The
+observer saw the living player return without a second body. Walking changed
+the server position to `[958.625, 16.375, 508.625]`; the equipped QL 1 Kinetic
+Axe and owned Monster Parts remained visible. A second native attack damaged
+the same surviving Leet and led to another death/automatic return. That second
+encounter used a low-health fixture adjustment. Neither death required a
+client adapter change.
+
+Restarting the isolated server and reloading afterward retained the arrival
+position and both item identities. As expected for the existing runtime
+resource policy, restart initialized 37 HP/0 nano rather than retaining 1/1.
+There were zero page errors and 15 expected connection-refused console messages
+during intentional restart. Evidence is under `local/resurrection-smoke/`:
+`verification.json`, `encounter-packets.log`, `arrival-position.yaml`, and
+the per-step state JSON and PNGs. `tmp_verify.py` checks both native requests,
+resources, combat cleanup, movement and durable inventory/arrival. Test-owned
+browser contexts and the fixture server were closed before the full Go checks.
+
+The full maintained suite, `go test ./server/...`, passed after these changes.
+Focused race checks also passed for `TestResurrection`,
+`TestTeleportReconnects`, `TestShopDoorReturns` and `TestCombatReconnect`.
diff --git a/server/control.go b/server/control.go
@@ -260,7 +260,11 @@ func (server *server) updateUser_locked(destination userData) error {
delete(server.clients, character.id)
server.mutex.Unlock()
server.sendCombatUpdates(updates)
+ return server.teleportUser_locked(client, destination, previousPlayfield)
+}
+func (server *server) teleportUser_locked(client *worldClient, destination userData, previousPlayfield uint32) error {
+ // Hold updateMutex; the departing session is already removed from clients.
// Original n3Teleport uses XYZ, a zone flag, two identities, and a stream.
var body []byte
for _, value := range destination.Position {
diff --git a/server/main.go b/server/main.go
@@ -425,13 +425,17 @@ func (server *server) serveWorldClient(client *worldClient) error {
if len(body) < 36 {
return fmt.Errorf("short character action message")
}
- // Acknowledge sitting and standing so the client updates its posture.
switch binary.BigEndian.Uint32(body[16:20]) {
+ case 152:
+ if err := server.handleResurrection(client, body); err != nil {
+ return err
+ }
case 112:
if err := server.handleInventory(client, body); err != nil {
return err
}
case 86, 87:
+ // Acknowledge sitting and standing so the client updates its posture.
if binary.BigEndian.Uint32(body[16:20]) == 87 {
loggingOut = false
if err := conn.SetReadDeadline(time.Time{}); err != nil {
diff --git a/server/resurrection.go b/server/resurrection.go
@@ -0,0 +1,49 @@
+package main
+
+import (
+ "encoding/binary"
+ "time"
+)
+
+func (server *server) handleResurrection(client *worldClient, body []byte) error {
+ server.updateMutex.Lock()
+ defer server.updateMutex.Unlock()
+ server.mutex.Lock()
+ player := server.characters[client.id]
+ if server.clients[client.id] != client || !client.ready || client.loading || player.health != 0 ||
+ binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id {
+ server.mutex.Unlock()
+ return nil
+ }
+
+ // Until insurance terminals exist, return to the known playable starter area.
+ updated := *player
+ updated.playfield = 705
+ updated.position = [3]float32{960, 16.5, 510}
+ updated.rotation = [4]float32{0, 0.9238795, 0, -0.3826834}
+ updated.returnDoor = nil
+ updated.sitting = false
+ // Starting health and nano are provisional until historical amounts are known.
+ updated.health, updated.nano = 1, 1
+ updated.fighting = 0
+ updated.nextAttack = time.Time{}
+ updated.rechargeUntil = time.Time{}
+ if err := server.savePosition_locked(&updated); err != nil {
+ server.mutex.Unlock()
+ return err
+ }
+
+ // Reset the native death presentation before starting its zone transition.
+ updates := make(map[*worldClient][][]byte)
+ server.cancelCombat_locked(player.id, updates)
+ resources := binary.BigEndian.AppendUint32(nil, updated.health)
+ resources = binary.BigEndian.AppendUint32(resources, updated.nano)
+ server.queueCombat_locked(updates, player, player, n3Packet(0x445f2a0b, 50000, player.id, resources))
+ previousPlayfield := player.playfield
+ *player = updated
+ client.ready = false
+ delete(server.clients, player.id)
+ server.mutex.Unlock()
+ server.sendCombatUpdates(updates)
+ return server.teleportUser_locked(client, updated.userData(), previousPlayfield)
+}
diff --git a/server/resurrection_test.go b/server/resurrection_test.go
@@ -0,0 +1,172 @@
+package main
+
+import (
+ "encoding/binary"
+ "os"
+ "slices"
+ "sync"
+ "testing"
+ "time"
+)
+
+func resurrectionRequest(owner uint32) []byte {
+ body := binary.BigEndian.AppendUint32(nil, 152)
+ body = append(body, make([]byte, 16)...)
+ return n3Packet(0x5e477770, 50000, owner, body)
+}
+
+func TestResurrectionNativeRequestRedirectsAndPersistsBeforeReconnect(t *testing.T) {
+ useNPCData(t, testNPCData())
+ world := newTestServer(t)
+ player := world.newCharacter()
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ item := ownedItem{ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 64}
+ if err := world.saveInventory_locked(player, playerInventory{LastID: 17, Items: []ownedItem{item}}); err != nil {
+ t.Fatal(err)
+ }
+ connection := connectZoningClient(t, world, true)
+ world.mutex.Lock()
+ player.health = 0
+ player.nano = 0
+ player.returnDoor = &doorOrigin{705, 1}
+ world.mutex.Unlock()
+
+ if _, err := connection.Write(targetPacket(resurrectionRequest(1))); err != nil {
+ t.Fatal(err)
+ }
+ for _, key := range []uint32{0x445f2a0b, 0x43197d22, 0x3c} {
+ packet, err := readPacket(connection)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if binary.BigEndian.Uint32(packet[16:20]) != key {
+ t.Fatalf("wrong resurrection sequence: %x", packet)
+ }
+ if key == 0x445f2a0b && (len(packet) != 37 || binary.BigEndian.Uint32(packet[29:33]) != 1 || binary.BigEndian.Uint32(packet[33:37]) != 1) {
+ t.Fatalf("wrong native resurrection resources: %x", packet)
+ }
+ }
+ restarted := newServer()
+ connection.Close()
+ connection = connectZoningClient(t, world, true)
+ world.mutex.Lock()
+ movement := *player
+ world.mutex.Unlock()
+ movement.position[0] = 961
+ connection.Write(targetPacket(npcMovementPacket(&movement, 2)))
+ ping := systemPacket(1, nil)
+ binary.BigEndian.PutUint16(ping[2:4], 11)
+ connection.Write(ping)
+ if _, err := readPacket(connection); err != nil {
+ t.Fatal(err)
+ }
+
+ arrived := restarted.characters[1]
+ if arrived.playfield != 705 || arrived.position != [3]float32{960, 16.5, 510} || arrived.returnDoor != nil || !slices.Equal(arrived.inventory.Items, []ownedItem{item}) {
+ t.Fatalf("resurrection arrival or belongings did not persist: %+v", arrived)
+ }
+ world.mutex.Lock()
+ defer world.mutex.Unlock()
+ if player.health != 1 || player.nano != 1 || player.position != [3]float32{961, 16.5, 510} || !world.clients[1].ready || world.clients[1].loading {
+ t.Fatalf("resurrected character cannot play: %+v", player)
+ }
+}
+
+func TestResurrectionOnlyOnceAndClearsCombatForBothObservers(t *testing.T) {
+ world, conn := newCombatWorld()
+ t.Chdir(t.TempDir())
+ player := world.characters[1]
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: 950, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true}
+ world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:])
+ world.advanceCombat(player.nextAttack)
+ player.health = 0
+ player.rechargeUntil = time.Now().Add(time.Hour)
+ client := world.clients[1]
+ conn.packets, observer.packets = nil, nil
+
+ var requests sync.WaitGroup
+ for range 8 {
+ requests.Go(func() {
+ if err := world.handleResurrection(client, resurrectionRequest(1)[20:]); err != nil {
+ t.Error(err)
+ }
+ })
+ }
+ requests.Wait()
+
+ if player.health != 1 || player.nano != 1 || player.fighting != 0 || !player.nextAttack.IsZero() || !player.rechargeUntil.IsZero() ||
+ world.characters[1000000].fighting != 0 || len(world.fighting) != 0 || world.clients[1] != nil || client.ready {
+ t.Fatal("resurrection retained combat or a departing session")
+ }
+ for _, packets := range [][][]byte{conn.packets, observer.packets} {
+ count := 0
+ for _, packet := range packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x445f2a0b {
+ count++
+ }
+ }
+ if count != 1 {
+ t.Fatalf("observer received %d resurrection packets: %x", count, packets)
+ }
+ }
+ if binary.BigEndian.Uint32(observer.packets[len(observer.packets)-1][16:20]) != 0x36510078 ||
+ binary.BigEndian.Uint32(conn.packets[len(conn.packets)-2][16:20]) != 0x43197d22 {
+ t.Fatal("observers did not remove the departing character after resurrection")
+ }
+}
+
+func TestResurrectionRejectsInvalidRequests(t *testing.T) {
+ for _, scenario := range []string{"alive", "loading", "unready", "replaced", "wrong owner", "wrong type"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, conn := newCombatWorld()
+ client := world.clients[1]
+ world.characters[1].health = 0
+ body := resurrectionRequest(1)[20:]
+ switch scenario {
+ case "alive":
+ world.characters[1].health = 50
+ case "loading":
+ client.loading = true
+ case "unready":
+ client.ready = false
+ case "replaced":
+ world.clients[1] = &worldClient{id: 1}
+ case "wrong owner":
+ binary.BigEndian.PutUint32(body[8:12], 2)
+ case "wrong type":
+ binary.BigEndian.PutUint32(body[4:8], 51050)
+ }
+
+ if err := world.handleResurrection(client, body); err != nil {
+ t.Fatal(err)
+ }
+
+ if len(conn.packets) != 0 || world.characters[1].playfield != 950 || client != world.clients[1] && scenario != "replaced" {
+ t.Fatal("invalid request changed the character or session")
+ }
+ })
+ }
+}
+
+func TestResurrectionSaveFailureLeavesDeadCharacterAndSessionUnchanged(t *testing.T) {
+ world, conn := newCombatWorld()
+ t.Chdir(t.TempDir())
+ if err := os.WriteFile("data", nil, 0600); err != nil {
+ t.Fatal(err)
+ }
+ world.characters[1].health = 0
+ client := world.clients[1]
+
+ err := world.handleResurrection(client, resurrectionRequest(1)[20:])
+
+ if err == nil || len(conn.packets) != 0 || world.characters[1].health != 0 || world.characters[1].playfield != 950 || world.clients[1] != client || !client.ready {
+ t.Fatal("failed save partially resurrected the player")
+ }
+}