commit fd8f20869e98ef18939a60f4096fd4b107bc994c
parent 529239813f0f470e5c9fd822f85903f007b5783a
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 11:40:05 +0000
Handle native corpse range-close notifications
Diffstat:
7 files changed, 235 insertions(+), 27 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -3999,8 +3999,8 @@ and server restarts. Turn every reproduced bug into a focused regression test.
native section boundary and returns to pick/collect the exact remaining slot 1.
Native remains and server interest survive; cash is awarded once and cold
ownership retains both instances. This supplies partial-loot section coverage,
- separately from the earlier earned untaken-item case. Open-window transitions,
- slope placement and broader streaming still need checks. See
+ separately from the earlier earned untaken-item case. Native range-close
+ handling is fixed below; slope placement and broader streaming remain open. See
[focused partial reentry](docs/corpse-scene-audit.md#focused-partial-slot-reentry).
The ordinary Omni boss run instantiated nine native corpses using mesh 25717
and death resource 25721. Some showed only two small mesh portions above a
@@ -4020,6 +4020,14 @@ and server restarts. Turn every reproduced bug into a focused regression test.
untaken gloves expired before pickup committed. Evidence:
[earned creature upgrades](docs/earned-creature-upgrade.md) and
`local/earned-creature-upgrade/`.
+- [x] [P0] Synchronize native corpse-window closure after leaving Use range.
+ A short controlled WASM round trip reproduced ignored action 142: the native
+ window closed, but its server handle made the first returning Use close again.
+ Accept the authenticated notification only for the current corpse. Verify
+ one-Use reopening, nonzero-slot pickup, unchanged cash, exact cold ownership,
+ forged/stale refusal and no database writes for close/reopen. Original client
+ range/packet evidence and the focused checks are in
+ [native range close](docs/corpse-scene-audit.md#native-range-close-notification).
- [x] [P0] Restore a corpse source after pickup during a pending equipment move.
Reproduced with explicit native axe placement followed by corpse pickup: the
server ignores the pickup and its icon becomes dummy/hidden. Check explicit
diff --git a/docs/corpse-scene-audit.md b/docs/corpse-scene-audit.md
@@ -39,8 +39,8 @@ second item, places the checkpoint and extends its observation window. These
conditions isolate reentry and are not earned progression, a drop-table
measurement or evidence for the historical corpse lifetime.
-Real WASM input opens the remains and collects slot 0 and its one credit.
-The client closes the window, walks across the nearby section boundary and
+The earlier closed-window check opens the remains and collects slot 0 and its one
+credit. The client closes the window, walks across the nearby section boundary and
returns. Outbound and return `CharZoneMoveIIR` messages establish both crossings;
the server retains NPC interest and the native directory retains the corpse.
Native camera input frames the same remains above chat. Picking and reopening
@@ -52,8 +52,42 @@ The maintained driver is `tools/client/test_corpse_reentry.mjs`. The short
checkpoint completes in about 17 seconds. Captures, exact ledgers, source hashes,
fixture failures and limits are retained in
`local/corpse-scene-reentry/focused-partial-verification.json` and
-`local/corpse-scene-reentry/focused-partial-reentry.md`. The loot window is closed
-during travel; open-window transitions and generic slope placement remain open.
+`local/corpse-scene-reentry/focused-partial-reentry.md`. The maintained scenario
+now also covers the native range-close notification below. Generic slope
+placement and broader streaming remain open.
+
+## Native range-close notification
+
+Leaving the partially looted window open reproduced a stale server handle.
+Beyond five metres the native client closed its window and sent CharacterAction
+142 with the corpse identity. The server ignored that action. The first Use on
+return therefore toggled the retained handle closed instead of reopening loot.
+The remaining item and zeroed cash were intact; a second Use was required.
+
+Original `kkr.dll` (SHA256
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`)
+function `100567b0` checks remote Chest distance against five metres, constructs
+action 142, sends it and removes the local window. CharacterAction constructor
+`1007d4b0` stores the action and its two identity pairs. The captured notification
+has a zero first pair and `51050:1000000` in the second. This is range closure;
+the section boundary itself does not establish its cause. REA evidence IDs are
+`ev_30c7bc5667112b3467e020212ecf1bd76ce4b44cf15d0fecdee96aa40035934f`
+and `ev_ccb0d09b5b7918d1ef372b685115cf46e678aba05b9464b09fb2f6ce7c9160aa`.
+Full dossiers and their static-analysis limitations are retained in
+`local/corpse-open-window/native-evidence.json`.
+
+The server now retires only the authenticated session's matching corpse handle.
+It accepts the close outside Use range without awarding cash, moving items,
+writing the database or sending another close. A stale notification for an old
+corpse cannot close a replacement window. The next normal Use can reopen the
+returned corpse once. Focused handler tests cover malformed/forged requests,
+replaced/loading sessions, duplicate closes, late target identities, one-Use
+reopening and exact cold conservation. The WASM scenario leaves loot open during
+departure, observes native closure and collects the remaining nonzero slot after
+one returning Use. Evidence and fixture limits are retained under
+`local/corpse-open-window/verification.json`. Related Go checks pass 67 roots/203
+results, focused race checks pass 8/20, and vet is clean. The native run completes
+in 16.67 seconds; all five saved traces have no errors or dropped events.
## Ordinary earned controls
diff --git a/server/browser_corpse_reentry_test.go b/server/browser_corpse_reentry_test.go
@@ -71,7 +71,8 @@ func TestBrowserPartiallyLootedCorpseSceneReentry(t *testing.T) {
world.mutex.Lock()
defer world.mutex.Unlock()
json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "items": corpse.items,
- "credits": corpse.credits, "interest": world.clients[1].npcs[1000000], "position": player.position})
+ "credits": corpse.credits, "interest": world.clients[1].npcs[1000000], "position": player.position,
+ "lootCorpse": world.clients[1].lootCorpse})
})
host := httptest.NewServer(mux)
t.Cleanup(host.Close)
diff --git a/server/loot.go b/server/loot.go
@@ -190,6 +190,25 @@ func (server *server) handleLootUse(client *worldClient, body []byte) error {
return client.send(lootClosePacket(client.id, corpse.id))
}
+func (server *server) handleLootClose(client *worldClient, body []byte) error {
+ if len(body) != 36 {
+ return nil
+ }
+ server.updateMutex.Lock()
+ defer server.updateMutex.Unlock()
+ server.mutex.Lock()
+ defer server.mutex.Unlock()
+ if !client.target || server.clients[client.id] != client || !client.ready || client.loading ||
+ binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id ||
+ binary.BigEndian.Uint32(body[16:20]) != 142 || binary.BigEndian.Uint64(body[20:28]) != 0 ||
+ binary.BigEndian.Uint32(body[28:32]) != 51050 || binary.BigEndian.Uint32(body[32:36]) != client.lootCorpse {
+ return nil
+ }
+ // The native client already closed this window after leaving Use range.
+ client.lootCorpse = 0
+ return nil
+}
+
func (server *server) takeLoot_locked(client *worldClient, body []byte) error {
corpse := server.characters[client.lootCorpse]
if client.lootCorpse == 0 || binary.BigEndian.Uint32(body[24:28]) != 50000 ||
diff --git a/server/loot_close_test.go b/server/loot_close_test.go
@@ -0,0 +1,128 @@
+package main
+
+import (
+ "encoding/binary"
+ "slices"
+ "testing"
+)
+
+func TestLootCloseOutOfRangeAllowsOneUseReopen(t *testing.T) {
+ world, conn := newLootWorld(t)
+ player, client, corpse := world.characters[1], world.clients[1], world.characters[1000000]
+ corpse.corpse.credits = 7
+ corpse.corpse.items = append(corpse.corpse.items, ownedItem{ID: 18, Type: 51005, Template: 42640, Quality: 1, Slot: 1, Count: 1})
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleLootUse(client, lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleInventory(client, lootTakeRequest()); err != nil {
+ t.Fatal(err)
+ }
+ auditCheckpointWrites(t, world)
+ conn.packets = nil
+ request := characterActionPacket(1, [5]uint32{142, 0, 0, 51050, 1000000})[20:]
+
+ player.position[0] = 7
+ for range 2 {
+ if err := world.handleLootClose(client, request); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if client.lootCorpse != 0 || len(conn.packets) != 0 || client.useSequence != 1 {
+ t.Fatal("native range close retained its handle or changed the Use sequence")
+ }
+ player.position[0] = 0
+ if err := world.handleLootUse(client, lootUseRequest(2)); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+
+ if client.lootCorpse != 1000000 || len(conn.packets) != 2 ||
+ binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x4e536976 {
+ t.Fatal("one Use after returning did not reopen the corpse")
+ }
+ if writes := checkpointWrites(t, world); len(writes) != 0 {
+ t.Fatal("close/reopen rewrote durable state", writes)
+ }
+ if cold.characters[1].inventory.Credits != 7 || cold.characters[1000000].corpse.credits != 0 ||
+ !slices.Equal(cold.characters[1].inventory.Items, []ownedItem{{ID: 17, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}}) ||
+ !slices.Equal(cold.characters[1000000].corpse.items, []ownedItem{{ID: 18, Type: 51005, Template: 42640, Quality: 1, Slot: 1, Count: 1}}) {
+ t.Fatal("range close/reopen changed item ownership or repeated cash")
+ }
+}
+
+func TestLootCloseRejectsForgedAndStaleRequests(t *testing.T) {
+ for _, scenario := range []string{"short", "long", "owner type", "foreign owner", "wrong action", "first pair", "target type", "other corpse", "loading", "unready", "replaced", "unsupported client"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, conn := newLootWorld(t)
+ client := world.clients[1]
+ if err := world.handleLootUse(client, lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ request := characterActionPacket(1, [5]uint32{142, 0, 0, 51050, 1000000})[20:]
+ switch scenario {
+ case "short":
+ request = request[:35]
+ case "long":
+ request = append(request, 0)
+ case "owner type":
+ binary.BigEndian.PutUint32(request[4:8], 51050)
+ case "foreign owner":
+ binary.BigEndian.PutUint32(request[8:12], 2)
+ case "wrong action":
+ binary.BigEndian.PutUint32(request[16:20], 106)
+ case "first pair":
+ binary.BigEndian.PutUint32(request[24:28], 1)
+ case "target type":
+ binary.BigEndian.PutUint32(request[28:32], 51017)
+ case "other corpse":
+ binary.BigEndian.PutUint32(request[32:36], 1000001)
+ case "loading":
+ client.loading = true
+ case "unready":
+ client.ready = false
+ case "replaced":
+ world.clients[1] = &worldClient{id: 1}
+ case "unsupported client":
+ client.target = false
+ }
+ conn.packets = nil
+ auditCheckpointWrites(t, world)
+
+ err := world.handleLootClose(client, request)
+
+ if err != nil || client.lootCorpse != 1000000 || client.useSequence != 1 || len(conn.packets) != 0 {
+ t.Fatal("invalid close changed the current session", err)
+ }
+ if writes := checkpointWrites(t, world); len(writes) != 0 {
+ t.Fatal("invalid close changed durable state", writes)
+ }
+ })
+ }
+}
+
+func TestLootCloseForPreviousCorpseKeepsTheCurrentWindow(t *testing.T) {
+ world, conn := newLootWorld(t)
+ client := world.clients[1]
+ other := *world.characters[1000000]
+ other.id = 1000001
+ world.characters[other.id] = &other
+ client.npcs[other.id] = true
+ if err := world.handleLootUse(client, lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ request := lootUseRequest(2)
+ binary.BigEndian.PutUint32(request[44:48], other.id)
+ if err := world.handleLootUse(client, request); err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ err := world.handleLootClose(client, characterActionPacket(1, [5]uint32{142, 0, 0, 51050, 1000000})[20:])
+
+ if err != nil || client.lootCorpse != 1000001 || len(conn.packets) != 0 {
+ t.Fatal("a late close retired the replacement window", err)
+ }
+}
diff --git a/server/main.go b/server/main.go
@@ -596,6 +596,10 @@ func (server *server) serveWorldClient(client *worldClient) error {
if err := server.handleBankClose(client, body); err != nil {
return err
}
+ case 142:
+ if err := server.handleLootClose(client, body); err != nil {
+ return err
+ }
case 105:
if err := server.handleCharacterInfo(client, body); err != nil {
return err
diff --git a/tools/client/test_corpse_reentry.mjs b/tools/client/test_corpse_reentry.mjs
@@ -19,28 +19,33 @@ try {
await game.ready();
if (!game.state.camera.firstPerson) await game.key('F8');
const server = async () => (await page.request.get(url + '/test-state')).json();
+ const windowOpen = () => game.state.regions.some(region =>
+ region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128);
const open = async () => {
// Frame the remains above the transparent chat region with native camera input.
- const point = await game.point(512, 300);
- let mouseY = point.y, sequence = game.sequence;
- await page.mouse.move(point.x, mouseY);
- await page.mouse.down({button: 'right'});
- try {
- await game.waitInput(sequence, 1025);
- const deadline = Date.now() + 10000;
- for (;;) {
- await game.snapshot();
- const y = game.state.actors.find(actor => actor.type === 51050 && actor.id === 1000000).screenPosition[1];
- if (y >= 350 && y <= 540) break;
- assert(Date.now() < deadline, 'Camera did not frame the corpse above chat');
- mouseY += y > 540 ? 20 : -20;
- await page.mouse.move(point.x, mouseY, {steps: 2});
+ let y = game.state.actors.find(actor => actor.type === 51050 && actor.id === 1000000).screenPosition[1];
+ if (y < 350 || y > 540) {
+ const point = await game.point(512, 300);
+ let mouseY = point.y, sequence = game.sequence;
+ await page.mouse.move(point.x, mouseY);
+ await page.mouse.down({button: 'right'});
+ try {
+ await game.waitInput(sequence, 1025);
+ const deadline = Date.now() + 10000;
+ for (;;) {
+ await game.snapshot();
+ y = game.state.actors.find(actor => actor.type === 51050 && actor.id === 1000000).screenPosition[1];
+ if (y >= 350 && y <= 540) break;
+ assert(Date.now() < deadline, 'Camera did not frame the corpse above chat');
+ mouseY += y > 540 ? 20 : -20;
+ await page.mouse.move(point.x, mouseY, {steps: 2});
+ }
+ } finally {
+ sequence = game.sequence;
+ await page.mouse.up({button: 'right'});
}
- } finally {
- sequence = game.sequence;
- await page.mouse.up({button: 'right'});
+ await game.waitInput(sequence, 1026);
}
- await game.waitInput(sequence, 1026);
await game.click(...await game.pick(51050, 1000000), 'right');
await game.wait('corpse loot window', state => state.regions.some(region =>
region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128));
@@ -61,27 +66,36 @@ try {
assert.equal(evidence.partial.items.length, 1);
assert.equal(evidence.partial.inventory.Credits, 1);
await game.save(output + '/partial');
- await game.click(170, 8);
// Walk the previously observed scene boundary without zoning or teleporting.
const sequence = game.sequence;
await game.walk(157, 67.125);
evidence.away = await server();
evidence.awayNative = game.state.actors.some(actor => actor.type === 51050 && actor.id === 1000000);
+ evidence.awayWindow = windowOpen();
evidence.transitions = game.events.filter(event => event.sequence > sequence &&
event.direction === 'framesent' && event.opcode === '2d2b2169').length;
assert(evidence.transitions > 0, 'The route must cross an actual native scene section');
assert.equal(evidence.away.interest, true, 'Scene retirement must be distinguished from server interest removal');
+ assert.equal(evidence.awayWindow, false, 'The native window closes outside five metres');
+ assert.equal(evidence.away.lootCorpse, 0, 'The native close notification must retire the server handle');
assert.deepEqual(evidence.away.items, evidence.partial.items);
await game.save(output + '/away');
await game.walk(161, 67.125);
await game.walk(161, 66.625);
evidence.returned = await server();
+ evidence.returnWindow = windowOpen();
evidence.returnTransitions = game.events.filter(event => event.sequence > sequence &&
event.direction === 'framesent' && event.opcode === '2d2b2169').length;
assert(evidence.returnTransitions > evidence.transitions, 'The return must cross the native section boundary again');
+ assert.equal(evidence.returnWindow, false);
+ assert.equal(evidence.returned.lootCorpse, 0);
await game.save(output + '/returned');
+ const reopenSequence = game.sequence;
await open();
+ evidence.reopenRequests = game.events.filter(event => event.sequence > reopenSequence &&
+ event.direction === 'framesent' && event.opcode === '52526858').length;
+ assert.equal(evidence.reopenRequests, 1, 'A single native Use must reopen the returned corpse');
await take(1);
await game.wait('second exact item collected', state => game.local(state).inventory.length === 2);
evidence.after = await server();
@@ -90,7 +104,7 @@ try {
assert.deepEqual(evidence.after.inventory.Items.map(item => item.ID), evidence.before.items.map(item => item.ID));
await game.save(output + '/collected');
assert.deepEqual(game.errors, []);
- console.log('PASS: partial corpse loot survives a real scene-section round trip with exact items and one cash award');
+ console.log('PASS: open partial corpse window survives a real scene-section round trip with exact items and one cash award');
} finally {
try {
await fs.mkdir(output, {recursive: true});