commit 92ecad46f08d54f8fd179eacb516e0190090a284
parent f691392abdd725b57be00d25256fa1a6f37510ef
Author: anon <anon@example.com>
Date: Thu, 22 Oct 2026 07:25:03 +0000
Translate classic inventory slots at the protocol boundary
Diffstat:
8 files changed, 218 insertions(+), 22 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -25,7 +25,7 @@ no extra player-facing provisioning system is needed just for testing.
character cannot delete it by supplying its identity.
- [x] Handle a full inventory. Check: a grant or pickup fails without losing
the source item or overwriting an occupied slot.
-- [ ] Reconcile the 14.9.1 native inventory slot range. Check: filling the
+- [x] Reconcile the 14.9.1 native inventory slot range. Check: filling the
inventory reaches its final supported slot, with every item visible and
movable before and after reconnect.
diff --git a/docs/corpse-loot.md b/docs/corpse-loot.md
@@ -127,7 +127,8 @@ destination 111, the next-free-slot sentinel. The request contains no corpse
identity. The server validates the session's opened corpse, killer ownership,
visibility, playfield and five-metre use range. It chooses an empty inventory
slot and atomically saves ownership before removing the corpse item. Its
-ContainerAddItem response carries that persisted destination slot. Native
+ContainerAddItem response carries the chosen destination translated into the
+[14.9.1 inventory range](inventory.md). Native
`sub_36042750`, `sub_360614E0` and `sub_3605FB40` transfer the template proxy and
update the corpse window without a replacement contents update.
diff --git a/docs/inventory.md b/docs/inventory.md
@@ -7,9 +7,10 @@ quality and logical inventory slot. The first fixture uses QL 1 Solar-Powered
Pistol, template 121567, identity type 51018. Players do not receive a fixture
item automatically.
-The ordinary inventory has 30 logical slots, 64 through 93. Grants choose an
-empty slot and return failure when all are occupied. Inventory changes use the
-existing atomic file replacement and become visible in memory after the save
+The ordinary inventory has 30 slots. Saved inventories and the shared 11.0
+protocol use 64 through 93; the 14.9.1 wire uses 48 through 77. Grants choose an
+empty saved slot and return failure when all are occupied. Inventory changes
+use the existing atomic file replacement and become visible in memory after the save
succeeds. A persisted last-issued ID preserves the allocation high-water mark,
including after deleting the last item. Startup takes the maximum across owners.
Profile edits and zoning preserve inventory independently of profile fields.
@@ -27,7 +28,7 @@ encoded length is `(items + 1) * 1009`. Each entry has these network-order field
| Field | Size | Initial individual-item value |
| --- | --- | --- |
-| Logical slot | 4 | 64 through 93 |
+| Logical slot | 4 | 48 through 77 on the 14.9.1 wire |
| Entry flags | 2 | 2 |
| Count | 2 | 1 |
| Instance type and ID | 8 | Template type and persistent server ID |
@@ -54,11 +55,21 @@ layout is corroborated by the local AOtomation `ContainerAddItemMessage` and
CellAO `ContainerAddItemMessageHandler` reference sources; it is not the message
used by the native same-window visual rearrangement described below.
-Corpse-transfer tracing also exposed a slot-range mismatch to reconcile: the
-14.9.1 native inventory buffer starts with 80 slots, and next-free placement
-searches from slot 48 (`sub_3605FB40`), while server persistence currently uses
-64..93. The fixed-item loot check uses an explicit persisted destination, 64.
-Verification of the complete native range remains a TODO.
+`kkr.dll` `sub_3605C400` constructs the character's inventory with 78 slots
+through `sub_3602D080`. Ordinary inventory begins at 48 in `sub_3605E1A0` and
+`sub_3605FB40`; next-free searches stop at the container size through
+`sub_3602D1E0` and `sub_3602D210`. The ordinary range is therefore 48..77.
+Runtime inspection with a full inventory confirms 78 total slots and all 30
+item identities in that range. Sending saved slots directly omitted items at
+the upper end and disagreed with the client's next-free placement.
+
+`targetPacket` translates ordinary slots by subtracting 16 in FullCharacter,
+ContainerAddItem and delete acknowledgements. Incoming 14.9.1 inventory
+requests are translated before server validation. Invalid native slots cannot
+alias legal saved slots: 78 and 93 are rejected rather than interpreted as
+saved positions. Equipment slot 6, corpse page 107 positions and next-free
+sentinel 111 retain their native meaning. Saved files, item identities and
+the 11.0 protocol retain their existing slot representation.
The captured 14.9.1 `CharacterAction` (`0x5e477770`) delete payload is exactly
five integers: action 112, page 104, logical slot, low template and high template.
@@ -114,6 +125,16 @@ Deletion was checked after reload, and a second simultaneous WASM visitor showed
only its own pistol while the first visitor's inventory stayed empty. The
browser driver closes its contexts and temporary server in `finally`.
+The full-inventory regression in `server/target_protocol_test.go` checks all
+30 native slots, invalid native boundaries and a last-to-first move through the
+world connection followed by restart. `server/loot_test.go` checks pickup into
+the final free slot. Manual WASM evidence in `local/inventory-range-smoke/`
+confirms all 30 identities in native slots 48..77, full-bag pickup rejection,
+held-menu deletion from slot 77 and corpse pickup into that freed slot. Server
+restart and page reconnect retain the final item; axe equip and unequip also
+preserve the inventory and visible weapon state. The run produced no browser
+errors and closed its browser context and temporary server.
+
The production-initializer storage regression in `client/tests/browser_storage.c`
has initial, resume and second-character passes. Run `storage-test.html`,
`storage-test.html?resume`, `storage-test.html?other`,
@@ -135,9 +156,9 @@ separate milestones; the normal-damage distribution is still provisional.
The native Wear window accepts left-click pickup from inventory and placement
into the right hand. `ContainerAddItem` uses source page 104 and logical slot
-64..93, target owner identity, and destination 6. Unequip requests use page 101,
-slot 6, and destination 111 (next free inventory slot). The server selects the
-first free logical inventory slot, but echoes the original requested placement
+48..77 on the 14.9.1 wire, target owner identity, and destination 6. Unequip
+requests use page 101, slot 6, and destination 111 (next free inventory slot).
+The server selects the first free logical inventory slot, but echoes the original requested placement
111. Replacing that sentinel with the resolved slot leaves the native Wear icon
unchanged. Ordinary visual ordering still uses the browser preferences above.
diff --git a/server/inventory_test.go b/server/inventory_test.go
@@ -58,7 +58,7 @@ func TestInventoryNativeMoveDeleteAndRestart(t *testing.T) {
t.Fatal(err)
}
if binary.BigEndian.Uint32(packet[16:20]) == 0x29304349 {
- if hex.EncodeToString(packet[33:69]) != "000007e200000040000200010000c74a000000010001dadf0001dadf0000000100000000" {
+ if hex.EncodeToString(packet[33:69]) != "000007e200000030000200010000c74a000000010001dadf0001dadf0000000100000000" {
t.Fatalf("native inventory list: %x", packet[33:69])
}
}
@@ -72,7 +72,7 @@ func TestInventoryNativeMoveDeleteAndRestart(t *testing.T) {
}
client, done := connect()
- client.Write(targetPacket(inventoryMovePacket(1, 64, 72)))
+ client.Write(targetPacket(inventoryMovePacket(1, 64, 93)))
move, err := readPacket(client)
if err != nil {
t.Fatal(err)
@@ -82,9 +82,9 @@ func TestInventoryNativeMoveDeleteAndRestart(t *testing.T) {
t.Fatal(err)
}
world = newTestInventoryServer(t)
- expected.Slot = 72
+ expected.Slot = 93
if !reflect.DeepEqual(world.characters[1].inventory.Items, []ownedItem{expected}) ||
- binary.BigEndian.Uint32(move[16:20]) != 0x47537a24 || binary.BigEndian.Uint32(move[45:49]) != 72 {
+ binary.BigEndian.Uint32(move[16:20]) != 0x47537a24 || binary.BigEndian.Uint32(move[45:49]) != 77 {
t.Fatalf("move lost item identity or slot: %+v %x", world.characters[1].inventory, move)
}
// The next connection must initialize using the saved slot.
@@ -101,7 +101,7 @@ func TestInventoryNativeMoveDeleteAndRestart(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if binary.BigEndian.Uint32(packet[16:20]) == 0x29304349 && binary.BigEndian.Uint32(packet[37:41]) != 72 {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x29304349 && binary.BigEndian.Uint32(packet[37:41]) != 77 {
t.Fatal("reconnect did not send the moved slot")
}
if binary.BigEndian.Uint32(packet[16:20]) == 0x5f52412e {
@@ -111,7 +111,7 @@ func TestInventoryNativeMoveDeleteAndRestart(t *testing.T) {
client.Write(targetPacket(n3Packet(0x570c2039, 50000, 1, nil)))
readPacket(client)
// Captured 14.9.1 delete layout, with the test owner and moved slot.
- request, err := hex.DecodeString("dfdf000a0001003100000001000000025e4777700000c35000000001000000007000000068000000480001dadf0001dadf000000")
+ request, err := hex.DecodeString("dfdf000a0001003100000001000000025e4777700000c350000000010000000070000000680000004d0001dadf0001dadf000000")
if err != nil {
t.Fatal(err)
}
diff --git a/server/loot_test.go b/server/loot_test.go
@@ -77,7 +77,7 @@ func TestLootNativeCorpseTakeAndRestart(t *testing.T) {
if !slices.Equal(restarted.characters[1].inventory.Items, expected) || restarted.nextItem != 17 || len(world.characters[1000000].corpse.items) != 0 {
t.Fatalf("loot ownership after restart: %+v", restarted.characters[1].inventory)
}
- if hex.EncodeToString(conn.packets[len(conn.packets)-1][29:49]) != "0000006b000000000000c3500000000100000040" {
+ if hex.EncodeToString(conn.packets[len(conn.packets)-1][29:49]) != "0000006b000000000000c3500000000100000030" {
t.Fatal("pickup acknowledgement lost its corpse source or persisted destination")
}
world.handleLootUse(world.clients[1], lootUseRequest(2))
@@ -111,6 +111,29 @@ func TestLootUseTogglesAndRejectsRepeatedSequences(t *testing.T) {
}
}
+func TestLootFillsTheLastNativeInventorySlot(t *testing.T) {
+ t.Chdir(t.TempDir())
+ world, conn := newLootWorld(t)
+ for slot := uint32(64); slot < 93; slot++ {
+ world.characters[1].inventory.Items = append(world.characters[1].inventory.Items,
+ ownedItem{ID: slot + 100, Type: 51018, Template: 121567, Quality: 1, Slot: slot})
+ }
+ world.characters[1].inventory.LastID = 192
+ world.handleLootUse(world.clients[1], lootUseRequest(1))
+
+ err := world.handleInventory(world.clients[1], lootTakeRequest())
+ restarted := newTestInventoryServer(t)
+
+ if err != nil || len(restarted.characters[1].inventory.Items) != 30 ||
+ binary.BigEndian.Uint32(conn.packets[len(conn.packets)-1][45:49]) != 77 ||
+ len(world.characters[1000000].corpse.items) != 0 {
+ t.Fatalf("last-slot pickup failed: %v", err)
+ }
+ if item := restarted.characters[1].inventory.Items[29]; item.ID != 17 || item.Slot != 93 {
+ t.Fatalf("last-slot ownership changed: %+v", item)
+ }
+}
+
func TestLootRejectsUnavailableItemsWithoutChangingOwnership(t *testing.T) {
for _, scenario := range []string{"closed", "distance", "playfield", "foreign owner", "stale session", "empty slot", "full inventory", "save failure", "repeat pickup"} {
t.Run(scenario, func(t *testing.T) {
diff --git a/server/main.go b/server/main.go
@@ -401,6 +401,9 @@ func (server *server) serveWorldClient(client *worldClient) error {
if len(body) < 16 || character == nil {
return fmt.Errorf("N3 message before character initialization")
}
+ if client.target {
+ decodeInventory1491(body)
+ }
switch binary.BigEndian.Uint32(body[0:4]) {
case 0x52526858:
if err := server.handleLootUse(client, body); err != nil {
diff --git a/server/target_protocol.go b/server/target_protocol.go
@@ -70,7 +70,15 @@ func targetPacket(packet []byte) []byte {
}
case 0x29304349:
// FullCharacter has seven encoded lists before its stats.
- inventoryEnd := 64 + int(binary.BigEndian.Uint32(packet[40:44])/1009-1)*32
+ inventoryCount := int(binary.BigEndian.Uint32(packet[40:44])/1009 - 1)
+ inventoryEnd := 64 + inventoryCount*32
+ for index := 0; index < inventoryCount; index++ {
+ cursor := 44 + index*32
+ slot := binary.BigEndian.Uint32(packet[cursor:])
+ if slot >= 64 && slot < 94 {
+ binary.BigEndian.PutUint32(packet[cursor:], slot-16)
+ }
+ }
tail := append([]byte(nil), packet[inventoryEnd:]...)
packet = binary.BigEndian.AppendUint32(packet[:inventoryEnd], 1009)
packet = append(packet, tail...)
@@ -79,6 +87,19 @@ func targetPacket(packet []byte) []byte {
for _, value := range []uint32{0, 0, 1009, 1009} {
packet = binary.BigEndian.AppendUint32(packet, value)
}
+ case 0x47537a24:
+ // Ordinary inventory uses shared slots 64..93 and native slots 48..77.
+ if binary.BigEndian.Uint32(packet[36:40]) == 104 {
+ binary.BigEndian.PutUint32(packet[40:44], binary.BigEndian.Uint32(packet[40:44])-16)
+ }
+ destination := binary.BigEndian.Uint32(packet[52:56])
+ if destination >= 64 && destination < 94 {
+ binary.BigEndian.PutUint32(packet[52:56], destination-16)
+ }
+ case 0x5e477770:
+ if binary.BigEndian.Uint32(packet[36:40]) == 112 && binary.BigEndian.Uint32(packet[40:44]) == 104 {
+ binary.BigEndian.PutUint32(packet[44:48], binary.BigEndian.Uint32(packet[44:48])-16)
+ }
case 0x54111123:
packet = append(packet[:36:36], encodeMovement1491(packet[36:])...)
case 0x5f52412e:
@@ -100,3 +121,30 @@ func targetPacket(packet []byte) []byte {
binary.BigEndian.PutUint16(packet[6:8], uint16(len(packet)))
return append(packet, make([]byte, (-len(packet))&3)...)
}
+
+func decodeInventory1491(body []byte) {
+ if len(body) != 36 {
+ return
+ }
+ switch binary.BigEndian.Uint32(body) {
+ case 0x47537a24:
+ if binary.BigEndian.Uint32(body[16:20]) == 104 {
+ binary.BigEndian.PutUint32(body[20:24], decodeInventorySlot1491(binary.BigEndian.Uint32(body[20:24])))
+ }
+ destination := binary.BigEndian.Uint32(body[32:36])
+ if destination != 6 && destination != 111 {
+ binary.BigEndian.PutUint32(body[32:36], decodeInventorySlot1491(destination))
+ }
+ case 0x5e477770:
+ if binary.BigEndian.Uint32(body[16:20]) == 112 && binary.BigEndian.Uint32(body[20:24]) == 104 {
+ binary.BigEndian.PutUint32(body[24:28], decodeInventorySlot1491(binary.BigEndian.Uint32(body[24:28])))
+ }
+ }
+}
+
+func decodeInventorySlot1491(slot uint32) uint32 {
+ if slot < 48 || slot >= 78 {
+ return 0
+ }
+ return slot + 16
+}
diff --git a/server/target_protocol_test.go b/server/target_protocol_test.go
@@ -87,6 +87,37 @@ initialized:
}
}
+func TestTargetFullInventoryUsesAllThirtyNativeSlots(t *testing.T) {
+ t.Chdir(t.TempDir())
+ world := newTestServer(t)
+ player := world.newCharacter()
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for range 30 {
+ if granted, err := world.grantItem_locked(player, 121567); err != nil || !granted {
+ t.Fatalf("grant: %v %v", granted, err)
+ }
+ }
+ conn := &combatTestConn{}
+ client := &worldClient{id: 1, conn: conn, target: true}
+
+ err := client.send(fullCharacterPacket(player))
+
+ if err != nil {
+ t.Fatal(err)
+ }
+ for index, slot := range []uint32{48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77} {
+ if got := binary.BigEndian.Uint32(conn.packets[0][37+index*32:]); got != slot {
+ t.Fatalf("item %d uses native slot %d instead of %d", index+1, got, slot)
+ }
+ }
+ if player.inventory.Items[0].Slot != 64 || player.inventory.Items[29].Slot != 93 {
+ t.Fatal("native encoding changed persisted slots")
+ }
+}
+
func TestTargetMovementIsPersistedAndRelayedToReleaseClient(t *testing.T) {
useNPCData(t, testNPCData())
world := newTestServer(t)
@@ -149,6 +180,75 @@ func TestTargetMovementIsPersistedAndRelayedToReleaseClient(t *testing.T) {
}
}
+func TestTargetInventoryBoundsAndLastSlotMovesSurviveRestart(t *testing.T) {
+ t.Chdir(t.TempDir())
+ useNPCData(t, testNPCData())
+ world := newTestServer(t)
+ player := world.newCharacter()
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for range 30 {
+ if granted, err := world.grantItem_locked(player, 121567); err != nil || !granted {
+ t.Fatalf("grant: %v %v", granted, err)
+ }
+ }
+ player.inventory.Items = append(player.inventory.Items[:14], player.inventory.Items[15:]...)
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ client, connection := net.Pipe()
+ defer client.Close()
+ client.SetDeadline(time.Now().Add(5 * time.Second))
+ done := make(chan error, 1)
+ go func() { defer connection.Close(); done <- world.serveWorldConnection(connection) }()
+ cookie, _ := hex.DecodeString("dfdf00010001002000000001000000020000001b000000010000000000000000")
+ client.Write(cookie)
+ for {
+ packet, err := readPacket(client)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x5f52412e {
+ break
+ }
+ }
+ client.Write(targetPacket(n3Packet(0x570c2039, 50000, 1, nil)))
+ readPacket(client)
+
+ // Native slot 93 must not alias a valid persisted slot; 48 is the first slot.
+ invalid := targetPacket(inventoryDeletePacket(1, 64))
+ binary.BigEndian.PutUint32(invalid[37:41], 93)
+ client.Write(invalid)
+ client.Write(targetPacket(inventoryDeletePacket(1, 64)))
+ if _, err := readPacket(client); err != nil {
+ t.Fatal(err)
+ }
+ // Native 78 is outside the inventory, even though persisted slot 78 is empty.
+ invalid = targetPacket(inventoryMovePacket(1, 93, 64))
+ binary.BigEndian.PutUint32(invalid[45:49], 78)
+ client.Write(invalid)
+ client.Write(targetPacket(inventoryMovePacket(1, 93, 64)))
+ move, err := readPacket(client)
+ if err != nil {
+ t.Fatal(err)
+ }
+ client.Close()
+ if err := <-done; err != nil {
+ t.Fatal(err)
+ }
+ restarted := newTestInventoryServer(t)
+
+ if len(restarted.characters[1].inventory.Items) != 28 || restarted.nextItem != 30 ||
+ binary.BigEndian.Uint32(move[33:37]) != 77 || binary.BigEndian.Uint32(move[45:49]) != 48 {
+ t.Fatalf("native inventory bounds or move changed: %x %+v", move, restarted.characters[1].inventory)
+ }
+ last := restarted.characters[1].inventory.Items[27]
+ if last.ID != 30 || last.Slot != 64 {
+ t.Fatalf("last native slot did not persist its move: %+v", last)
+ }
+}
+
func TestTargetTeleportIncludesFullPlayfieldProxy(t *testing.T) {
useNPCData(t, testNPCData())
world := newTestServer(t)