aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 705480837e3c71e3ebd423faef372d7fd0ea9108
parent fae765d6078c648409fcbd189d689ad9b7b33ecb
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 07:50:21 +0000

Correct stale installed implant removal and native effects

Diffstat:
MTODO.md | 11+++++++++++
Mdocs/implants.md | 31+++++++++++++++++++++++++++++++
Mdocs/inventory.md | 2+-
Mserver/browser_stale_inventory_move_test.go | 14++++++++++++++
Mserver/equipment.go | 8++++----
Mserver/inventory.go | 13+++++++------
Mserver/main.go | 6+++---
Mserver/stale_armor_move_test.go | 6+++---
Aserver/stale_implant_move_test.go | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/state.go | 2+-
Mtools/client/test_stale_inventory_move.mjs | 12+++++++-----
11 files changed, 232 insertions(+), 23 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -4114,6 +4114,17 @@ and server restarts. Turn every reproduced bug into a focused regression test. both directions during wear/removal without writes or deadline changes. No product defect reproduced on this path; see [backpack joins](docs/backpacks.md#stack-join-during-pending-equipment). +- [x] [P0] Clear stale installed-implant sources and their native effects. + Reproduction: install chest implant101173, retain its native page103:37 view + while a controlled earlier bank transfer empties that source, then remove it + through the native client. The baseline handler sent no reply. It now cancels + and clears that exact source, undoing its published MeleeAC+8 once. The short + native check verifies8 ->0 ->8 through same-page withdrawal/reinstallation; + page reconnect and cold loading conserve both physical IDs. Go checks cover + all13 implant positions, duplicate/forged requests and pending equipment. + This is controlled stale-view evidence, not earned progression; the broader + disappearance audit remains open. See + [stale installed implants](docs/implants.md#stale-installed-sources). - [x] [P0] Clear stale worn-armor sources and their native effects. A controlled earlier bank transfer leaves the helmet visible at102:18; native removal previously received no reply. Cancellation/row clearing alone hid the icon diff --git a/docs/implants.md b/docs/implants.md @@ -296,6 +296,37 @@ FullCharacter already applies installed implant effects during initialization; another owner wear message would double the bonus. Observers receive one wear action after their SimpleChar snapshot, as with armor. +## Stale installed sources + +A controlled earlier bank transfer can leave an installed implant visible after +its authoritative row is empty. The focused chest101173/QL1 fixture retains its +native page103:37 view and MeleeAC+8. A real right-click removal sends +ContainerAddItem103:37 ->111 but previously received no reply. Go returns zero +packets; the native baseline times out awaiting cancellation. Retained baselines +are `local/stale-implant-move/baseline.log` and +`local/stale-inventory-move/20261103-234513/37/`. + +The connection's existing exact unwear cache now also covers installed implants. +The empty-source correction sends cancellation146, the exact published action7 +once, then row clearing112. It consumes that cached contract without changing +ownership or guessing the template from bank contents. Normal installation and +removal still require surgery access. Original action6/7 routing is established +above and shares the [armor receiver](inventory.md#stale-worn-armor-sources). + +`TestStaleImplantMove` checks all13 empty anatomical slots, first/last/automatic +ordinary destinations, repeated requests, exact template metadata, zero database +writes, cold ownership, forged requests and pending equipment. The short native +`TestBrowserStaleImplantMove` withdraws and reinstalls the same banked implant on +the same page, then reconnects. Its cold Go read conserves implant1 at37 and +part2 at65, zero cash and allocator2. The16.81-second capture is retained in +`local/stale-inventory-move/20261103-234700/37/`; manual inspection of its Stats +windows verifies MeleeAC8 ->0 ->8 and the cleared/restored chest implant icon. +All trace error/drop counters are zero. This is controlled stale-view evidence, +not earned progression or a resolution of the broader disappearance audit. +Focused related checks pass53 roots/397 results, and the race run passes50 +results. Vet and driver syntax checks pass. Packet ordering, source hashes and +capture hashes are retained in `local/stale-implant-move/validation.json`. + ## Evidence Original `kkr.dll` SHA-256: diff --git a/docs/inventory.md b/docs/inventory.md @@ -273,7 +273,7 @@ The maintained translations are `client/game/kkr.dll/lifted-0039.c::sub_360849C0` and `client/game/kkr.dll/lifted-0028.c::sub_3605E980`. -Each connection now retains the exact armor-removal packet prepared from its +Each connection now retains the exact armor/implant-removal packet prepared from its published FullCharacter, updating it only after normal equipment commits. An authenticated empty page102 source receives cancellation, that last-published OnUnWear once when present, then clearing of its own row. The packet is consumed diff --git a/server/browser_stale_inventory_move_test.go b/server/browser_stale_inventory_move_test.go @@ -29,6 +29,10 @@ func TestBrowserStaleArmorMove(t *testing.T) { testBrowserStaleInventoryMove(t, 18) } +func TestBrowserStaleImplantMove(t *testing.T) { + testBrowserStaleInventoryMove(t, 37) +} + func testBrowserStaleInventoryMove(t *testing.T, sourceSlot uint32) { t.Helper() if os.Getenv("AO_GAME_TEST") != "1" { @@ -42,6 +46,10 @@ func testBrowserStaleInventoryMove(t *testing.T, sourceSlot uint32) { player.playfield, player.position = 1183, [3]float32{193.79826, 5.01, 136.83983} player.rotation = [4]float32{0, .70710677, 0, .70710677} player.stats = testCharacterStats() + if sourceSlot == 37 { + player.stats.NanoAiding.Treatment = 20 + player.implantChangesUntil = time.Now().Add(time.Minute) + } player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("stale-inventory-move"))) if err := world.saveUser_locked(player); err != nil { t.Fatal(err) @@ -52,6 +60,9 @@ func testBrowserStaleInventoryMove(t *testing.T, sourceSlot uint32) { if sourceSlot == 18 { inventory.Items[0].Type, inventory.Items[0].Template = 51022, 85557 } + if sourceSlot == 37 { + inventory.Items[0].Type, inventory.Items[0].Template = 51022, 101173 + } if err := world.saveInventory_locked(player, inventory); err != nil { t.Fatal(err) } @@ -120,6 +131,9 @@ func testBrowserStaleInventoryMove(t *testing.T, sourceSlot uint32) { if sourceSlot == 18 { expected[0].Type, expected[0].Template, expected[0].Slot = 51022, 85557, 18 } + if sourceSlot == 37 { + expected[0].Type, expected[0].Template, expected[0].Slot = 51022, 101173, 37 + } for _, actual := range []playerInventory{player.inventory, cold.characters[1].inventory} { items := slices.Clone(actual.Items) slices.SortFunc(items, func(a, b ownedItem) int { return cmp.Compare(a.ID, b.ID) }) diff --git a/server/equipment.go b/server/equipment.go @@ -288,8 +288,8 @@ func (server *server) advanceEquipment(now time.Time) { // Commit the old-speed prediction and ordered wear effects together. *character = motion for _, removed := range removedItems { - if removed.Slot >= 16 && removed.Slot < 32 { - client.armorRemoval[removed.Slot-16] = nil + if removed.Slot >= 16 && removed.Slot <= 45 { + client.wornRemoval[removed.Slot-16] = nil } if !removed.isWieldableWeapon() { server.queueCombat_locked(updates, character, character, equipmentActionPacket(character.id, removed, 7)) @@ -311,8 +311,8 @@ func (server *server) advanceEquipment(now time.Time) { updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.requestedSlot)) if move.destination < 64 && !item.isWieldableWeapon() { server.queueCombat_locked(updates, character, character, equipmentActionPacket(character.id, character.inventory.Items[index], 6)) - if move.destination >= 16 && move.destination < 32 { - client.armorRemoval[move.destination-16] = equipmentActionPacket(character.id, character.inventory.Items[index], 7) + if move.destination >= 16 && move.destination <= 45 { + client.wornRemoval[move.destination-16] = equipmentActionPacket(character.id, character.inventory.Items[index], 7) } } if move.source == 6 || move.destination == 6 { diff --git a/server/inventory.go b/server/inventory.go @@ -381,20 +381,21 @@ func (server *server) handleInventory(client *worldClient, body []byte) error { } return nil } - if index < 0 && client.equipment == nil && key == 0x47537a24 && sourceType == 102 && sourceSlot >= 16 && sourceSlot < 32 && + if index < 0 && client.equipment == nil && key == 0x47537a24 && + (sourceType == 102 && sourceSlot >= 16 && sourceSlot < 32 || sourceType == 103 && sourceSlot >= 33 && sourceSlot <= 45) && binary.BigEndian.Uint32(body[24:28]) == 50000 && binary.BigEndian.Uint32(body[28:32]) == client.id && (destination == 111 || destination >= 64 && destination < 94) { - // Clear the stale armor row without deleting its detached physical instance. - if err := client.send(characterActionPacket(client.id, [5]uint32{146, 102, sourceSlot})); err != nil { + // Clear the stale worn row without deleting its detached physical instance. + if err := client.send(characterActionPacket(client.id, [5]uint32{146, sourceType, sourceSlot})); err != nil { return err } - if packet := client.armorRemoval[sourceSlot-16]; packet != nil { + if packet := client.wornRemoval[sourceSlot-16]; packet != nil { if err := client.send(packet); err != nil { return err } - client.armorRemoval[sourceSlot-16] = nil + client.wornRemoval[sourceSlot-16] = nil } - return client.send(characterActionPacket(client.id, [5]uint32{112, 102, sourceSlot})) + return client.send(characterActionPacket(client.id, [5]uint32{112, sourceType, sourceSlot})) } if index < 0 || (sourceSlot >= 64 && sourceType != 104) || (sourceSlot > 0 && sourceSlot < 16 && sourceType != 101) || diff --git a/server/main.go b/server/main.go @@ -409,10 +409,10 @@ func (server *server) serveWorldClient(client *worldClient) error { } updates = append(updates, fullCharacterPacket(character)) // Retain the exact native unwear contract while its source row is published. - client.armorRemoval = [16][]byte{} + client.wornRemoval = [30][]byte{} for _, item := range character.inventory.Items { - if item.Slot >= 16 && item.Slot < 32 { - client.armorRemoval[item.Slot-16] = equipmentActionPacket(character.id, item, 7) + if item.Slot >= 16 && item.Slot <= 45 { + client.wornRemoval[item.Slot-16] = equipmentActionPacket(character.id, item, 7) } } petUpdates := petOwnerPackets(character) diff --git a/server/stale_armor_move_test.go b/server/stale_armor_move_test.go @@ -82,7 +82,7 @@ func TestStaleArmorMoveUnwearsOnlyItsPublishedTemplateOnce(t *testing.T) { if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) || - world.nextItem != 2 || cold.nextItem != 2 || len(output.packets) != 5 || client.armorRemoval[2] != nil { + world.nextItem != 2 || cold.nextItem != 2 || len(output.packets) != 5 || client.wornRemoval[2] != nil { t.Fatal("stale armor correction changed ownership, allocation or repeated its unwear", err, len(output.packets)) } for index, action := range map[int]uint32{0: 146, 2: 112, 3: 146, 4: 112} { @@ -132,7 +132,7 @@ func TestStaleArmorMovePreservesInvalidAndPendingRequests(t *testing.T) { } } pending := client.equipment - removal := slices.Clone(client.armorRemoval[2]) + removal := slices.Clone(client.wornRemoval[2]) before, err := readTestItemStore(world) if err != nil { t.Fatal(err) @@ -144,7 +144,7 @@ func TestStaleArmorMovePreservesInvalidAndPendingRequests(t *testing.T) { after, readErr := readTestItemStore(world) if err != nil || readErr != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || - len(output.packets) != 0 || !bytes.Equal(removal, client.armorRemoval[2]) || client.equipment != pending { + len(output.packets) != 0 || !bytes.Equal(removal, client.wornRemoval[2]) || client.equipment != pending { t.Fatal("invalid stale armor request changed ownership, pending wear or published metadata", err, readErr) } }) diff --git a/server/stale_implant_move_test.go b/server/stale_implant_move_test.go @@ -0,0 +1,150 @@ +package main + +import ( + "bytes" + "encoding/binary" + "fmt" + "reflect" + "slices" + "testing" + "time" +) + +func newStaleImplantMoveWorld(t *testing.T) (*server, *combatTestConn) { + t.Helper() + world, output := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + player.stats.NanoAiding.Treatment = 20 + player.implantChangesUntil = time.Now().Add(time.Minute) + if granted, err := world.grantItem_locked(player, 101173); err != nil || !granted { + t.Fatal(granted, err) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 65, 37)[20:]); err != nil || client.equipment == nil { + t.Fatal("fixture implant did not start installation", err) + } + world.advanceEquipment(client.equipment.readyAt) + inventory := player.inventory + inventory.Items = slices.Clone(inventory.Items) + implant := inventory.Items[1] + implant.Slot = 0 + inventory.Bank = []ownedItem{implant} + inventory.Items = inventory.Items[:1] + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + output.packets = nil + return world, output +} + +func TestStaleImplantMoveUnwearsItsPublishedTemplateOnce(t *testing.T) { + world, output := newStaleImplantMoveWorld(t) + player, client := world.characters[1], world.clients[1] + inventory := player.inventory + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + output.packets = nil + auditCheckpointWrites(t, world) + + for range 2 { + if err := world.handleInventory(client, itemMovePacket(1, 37, 111)[20:]); err != nil { + t.Fatal(err) + } + } + after, err := readTestItemStore(world) + cold := newTestInventoryServer(t) + + if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || + !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) || + world.nextItem != 2 || cold.nextItem != 2 || len(output.packets) != 5 || client.wornRemoval[21] != nil { + t.Fatal("stale implant did not correct exactly once without changing ownership", err, len(output.packets)) + } + for index, action := range map[int]uint32{0: 146, 2: 112, 3: 146, 4: 112} { + packet := output.packets[index] + if binary.BigEndian.Uint32(packet[16:20]) != 0x5e477770 || binary.BigEndian.Uint32(packet[29:33]) != action || + binary.BigEndian.Uint32(packet[33:37]) != 103 || binary.BigEndian.Uint32(packet[37:41]) != 37 { + t.Fatalf("stale implant correction addressed another row: %x", packet) + } + } + unwear := output.packets[1] + words := []uint32{} + for offset := 29; offset < 65; offset += 4 { + words = append(words, binary.BigEndian.Uint32(unwear[offset:])) + } + if binary.BigEndian.Uint32(unwear[16:20]) != 0x35505644 || + !slices.Equal(words, []uint32{101173, 101173, 1, 1, 7, 103, 37, 0, 0}) { + t.Fatal("stale implant did not reverse its exact published effect", words) + } +} + +func TestStaleImplantMoveClearsOnlyTheRequestedEmptyRow(t *testing.T) { + world, output := newEquipmentWorld(t) + auditCheckpointWrites(t, world) + for source := uint32(33); source <= 45; source++ { + for _, destination := range []uint32{64, 93, 111} { + t.Run(fmt.Sprintf("%d/%d", source, destination), func(t *testing.T) { + output.packets = nil + + err := world.handleInventory(world.clients[1], itemMovePacket(1, source, destination)[20:]) + + if err != nil || len(output.packets) != 2 || len(checkpointWrites(t, world)) != 0 { + t.Fatal("empty implant source did not receive cancellation and clearing", err, len(output.packets)) + } + for index, action := range []uint32{146, 112} { + packet := output.packets[index] + if binary.BigEndian.Uint32(packet[29:33]) != action || binary.BigEndian.Uint32(packet[33:37]) != 103 || + binary.BigEndian.Uint32(packet[37:41]) != source { + t.Fatalf("implant correction addressed another source: %x", packet) + } + } + }) + } + } +} + +func TestStaleImplantMovePreservesInvalidAndPendingRequests(t *testing.T) { + for _, scenario := range []string{"foreign actor", "foreign target", "target type", "wrong page", "source before", "source after", "invalid destination", "pending equipment"} { + t.Run(scenario, func(t *testing.T) { + world, output := newStaleImplantMoveWorld(t) + client := world.clients[1] + request := itemMovePacket(1, 37, 111)[20:] + switch scenario { + case "foreign actor": + binary.BigEndian.PutUint32(request[8:], 2) + case "foreign target": + binary.BigEndian.PutUint32(request[28:], 2) + case "target type": + binary.BigEndian.PutUint32(request[24:], 51017) + case "wrong page": + binary.BigEndian.PutUint32(request[16:], 102) + case "source before": + binary.BigEndian.PutUint32(request[20:], 32) + case "source after": + binary.BigEndian.PutUint32(request[20:], 46) + case "invalid destination": + binary.BigEndian.PutUint32(request[32:], 94) + case "pending equipment": + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil { + t.Fatal("fixture weapon did not start wear", err) + } + } + pending := client.equipment + removal := slices.Clone(client.wornRemoval[21]) + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + auditCheckpointWrites(t, world) + output.packets = nil + + err = world.handleInventory(client, request) + after, readErr := readTestItemStore(world) + + if err != nil || readErr != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 || + len(output.packets) != 0 || !bytes.Equal(removal, client.wornRemoval[21]) || client.equipment != pending { + t.Fatal("invalid implant removal changed ownership, pending wear or its published effect", err, readErr) + } + }) + } +} diff --git a/server/state.go b/server/state.go @@ -87,7 +87,7 @@ type worldClient struct { npcs map[uint32]bool dialogue *npcDialogue equipment *equipmentMove - armorRemoval [16][]byte + wornRemoval [30][]byte nanoCast *nanoCast reloadUntil time.Time lootCorpse uint32 diff --git a/tools/client/test_stale_inventory_move.mjs b/tools/client/test_stale_inventory_move.mjs @@ -5,9 +5,9 @@ import {GameTest} from './game_test.mjs'; const {chromium} = createRequire(import.meta.url)('playwright'); const [url, output, sourceSlot] = process.argv.slice(2); -const sourcePage = sourceSlot === '6' ? 101 : sourceSlot === '18' ? 102 : 104; +const sourcePage = sourceSlot === '6' ? 101 : sourceSlot === '18' ? 102 : sourceSlot === '37' ? 103 : 104; const nativeSlot = sourcePage === 104 ? 48 : Number(sourceSlot); -const wornSlot = sourcePage === 102 ? 18 : 6; +const wornSlot = sourcePage === 102 ? 18 : sourcePage === 103 ? 37 : 6; const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [ '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); @@ -44,11 +44,12 @@ try { if (sourcePage !== 104) { await page.keyboard.press('Control+1'); if (sourcePage === 102) await game.click(953, 53); + if (sourcePage === 103) await game.click(993, 53); await game.snapshot(); } assert(sourcePresent() && cell(104, 49)); evidence.initial = await server(); - if (sourcePage === 102) await saveArmor('initial-armor'); + if (sourcePage === 102 || sourcePage === 103) await saveArmor('initial-armor'); assert((await page.request.post(url + '/test-stale-view')).ok()); evidence.transferred = await server(); assert.deepEqual(evidence.transferred.Items.map(item => [item.ID, item.Slot]), [[2, 65]]); @@ -56,6 +57,7 @@ try { await game.save(output + '/stale'); const sequence = game.sequence; if (sourcePage === 102) await game.click(927, 94, 'right'); + else if (sourcePage === 103) await game.click(927, 148, 'right'); else if (sourcePage === 101) await game.click(867, 206, 'right'); else await click(cell(104, 48), 'right'); await game.wait('actual stale inventory move', () => game.events.some(event => event.sequence > sequence && @@ -66,7 +68,7 @@ try { event.direction === 'framereceived' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 146)); await game.wait('empty authoritative source cleared', () => !sourcePresent() && cell(104, 49) && game.state.dragged[0] === 0); assert.deepEqual(await server(), evidence.transferred); - if (sourcePage === 102) await saveArmor('refused'); + if (sourcePage === 102 || sourcePage === 103) await saveArmor('refused'); else await game.save(output + '/refused'); // The correction must leave the actual banked instance available on this page. @@ -85,7 +87,7 @@ try { assert.deepEqual(evidence.after.Items.map(item => [item.ID, item.Slot]).sort((a, b) => a[0] - b[0]), [[1, wornSlot], [2, 65]]); assert.equal(evidence.after.Bank.length, 0); assert.deepEqual(evidence.after.Armor, evidence.initial.Armor); - if (sourcePage === 102) await saveArmor('moved'); + if (sourcePage === 102 || sourcePage === 103) await saveArmor('moved'); else await game.save(output + '/moved'); await page.reload(); await game.ready();