aorecomp

Anarchy Online classic in the browser

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


commit a8ffb139b3026b044c4ee7d3f9022605754aed90
parent cd135503ee91cecdfe075bdeddcbe0c67d6cca5e
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 02:20:35 +0000

Fix carried slots in generic SimpleItem updates

Diffstat:
MTODO.md | 5++++-
Mdocs/mission-keys.md | 38+++++++++++++++++++++++++++++++++-----
Aserver/browser_mission_key_name_test.go | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/simple_item_protocol_test.go | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/target_protocol.go | 5+++++
Atools/client/test_mission_key_name.mjs | 45+++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 225 insertions(+), 6 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -2471,7 +2471,10 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md). twenty credits and immediately copies the held key, with exact page/cold retention. Controlled funds/location isolate this acquisition check from earned progression. Tools placement follows the later wiki; original per-terminal - stock remains unrecovered. Native destination metadata remains unimplemented. + stock remains unrecovered. The original generic SimpleItem custom-name route + now displays two distinct controlled live-key names in native tooltips/info; + its missing carried-slot translation is fixed. Production destination labels + and their bank/trade/reclaim/reconnect behavior remain unimplemented. See [mission keys](docs/mission-keys.md). Cover held, banked, traded, deleted and reclaimed keys; possession of an unrelated template28577 must never admit a player to another mission. diff --git a/docs/mission-keys.md b/docs/mission-keys.md @@ -80,8 +80,36 @@ The two focused public-handler checks protect the nine-template stock boundary, purchase/repeated Accept, immediate copy and cold ownership. Captures are in `local/mission-key-acquisition/`. -Destination-specific native naming remains open. Copies still display the -original base name. The bounded naming -investigation is retained in `local/mission-key-metadata/`; do not invent an -instance identity or name message to conceal that evidence gap. Historical key -retention after completion/abandonment remains separately unresolved. +## Native name route + +The original generic SimpleItemFullUpdateIIR `0x3b11256f` supports a per-instance +name. Its SimpleItem11 reader `0x100b2440` reads a length and raw bytes into +message+0x74. Apply routine `0x100b2830` passes that allocation to `0x10090d90`, +which stores it at item+0x78. The name virtual `0x10090df0` prefers that pointer +over the static template name. Include the terminating NUL in the payload and +its length. Setter evidence is `ev_fbe6657d0c75b2eef160313bf11216372ada2f3c060a7f219466177864c4d2b9` +in `local/mission-key-name/native/kkr-evidence.json`; reader/apply and getter +evidence are retained in `local/ncu-upgrade-research/native/` and +`local/mission-key-metadata/` respectively. These concern original `kkr.dll`, +SHA256 `a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`. + +The protocol adapter now translates this generic update's carried slots64..93 +to native48..77, preserving first-free111 and other pages. Parentless updates +include a transform before placement and must not use the carried offset. +The first/last-slot regression failed before this correction; the world case +protects transform bytes that resemble a page/slot pair. + +`TestBrowserMissionKeyNameRoute` starts with two controlled, unbound key +instances. Generic updates attach the two live identities to their existing +inventory rows, with labels `Mission Key to Destination A` and +`Mission Key to Destination B`. Real Shift-clicks show each distinct name in +its native tooltip and information window. The short check verifies native +slots48/49, no client errors and unchanged cold ownership/allocation. These +test labels are not recovered historical destination wording or mission bindings. +Captures and protocol verification are in `local/mission-key-name/`. + +Production keys and copies still display the base name. Destination publication, +historical label wording and live-item bank/trade/reclaim/reconnect behavior +remain open. The original activation ignores already-existing dynels, so fresh +creation alone cannot prove those lifetime paths. Historical key retention after +completion/abandonment remains separately unresolved. diff --git a/server/browser_mission_key_name_test.go b/server/browser_mission_key_name_test.go @@ -0,0 +1,84 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/binary" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "slices" + "testing" + "time" +) + +func TestBrowserMissionKeyNameRoute(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the native key name experiment") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/mission-key-name", time.Now().Format("20060102-150405")) + world := newTestServer(t) + player := world.newCharacter() + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("mission-key-name"))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + for range 2 { + if granted, err := world.grantItem_locked(player, 28577); err != nil || !granted { + t.Fatal(granted, err) + } + } + mux := http.NewServeMux() + mux.Handle("/", world.httpHandler()) + mux.HandleFunc("POST /test-name", func(w http.ResponseWriter, r *http.Request) { + world.updateMutex.Lock() + defer world.updateMutex.Unlock() + world.mutex.Lock() + defer world.mutex.Unlock() + // Original SimpleItem11 with distinct controlled labels, not mission bindings. + for index, name := range []string{"Mission Key to Destination A", "Mission Key to Destination B"} { + var body []byte + for _, value := range []uint32{11, 50000, 1, player.playfield, 0, 0} { + body = binary.BigEndian.AppendUint32(body, value) + } + body = append(body, 104, byte(64+index)) + for _, value := range []uint32{5 * 1009, 23, 28577, 701, 1, 702, 28577, 703, 28577, uint32(len(name) + 1)} { + body = binary.BigEndian.AppendUint32(body, value) + } + body = append(body, []byte(name)...) + body = append(body, 0) + if err := world.clients[1].send(n3Packet(0x3b11256f, 51053, uint32(index+1), body)); err != nil { + t.Error(err) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) + defer cancel() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_mission_key_name.mjs"), host.URL, output) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + err := command.Run() + + t.Logf("Browser artifacts: %s", output) + if err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + expected := []ownedItem{{ID: 1, Type: 51053, Template: 28577, Quality: 1, Slot: 64, Count: 1}, + {ID: 2, Type: 51053, Template: 28577, Quality: 1, Slot: 65, Count: 1}} + if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) || + world.nextItem != 2 || cold.nextItem != 2 || player.inventory.Credits != 0 || cold.characters[1].inventory.Credits != 0 { + t.Fatal("native name updates changed durable ownership or allocation") + } +} diff --git a/server/simple_item_protocol_test.go b/server/simple_item_protocol_test.go @@ -0,0 +1,54 @@ +package main + +import ( + "bytes" + "encoding/binary" + "testing" +) + +func TestTargetSimpleItemFullUpdatePlacement(t *testing.T) { + for _, row := range []struct { + name string + page, slot, want byte + }{ + {"first carried", 104, 64, 48}, + {"last carried", 104, 93, 77}, + {"first free", 104, 111, 111}, + {"out of range", 104, 94, 94}, + {"bank", 105, 64, 64}, + {"backpack", 107, 64, 64}, + } { + t.Run(row.name, func(t *testing.T) { + var body []byte + for _, value := range []uint32{11, 50000, 1, 950, 0, 0} { + body = binary.BigEndian.AppendUint32(body, value) + } + body = append(body, row.page, row.slot) + for _, value := range []uint32{1009, 4} { + body = binary.BigEndian.AppendUint32(body, value) + } + body = append(body, 'K', 'e', 'y', 0) + + packet := targetPacket(n3Packet(0x3b11256f, 51053, 7, body)) + packet = packet[:binary.BigEndian.Uint16(packet[6:8])] + + if packet[53] != row.page || packet[54] != row.want || !bytes.Equal(packet[55:], body[26:]) || + binary.BigEndian.Uint32(packet[20:24]) != 51053 || binary.BigEndian.Uint32(packet[24:28]) != 7 { + t.Fatalf("generic SimpleItem changed identity, placement or name bytes: %x", packet) + } + }) + } +} + +func TestTargetWorldSimpleItemPreservesTransform(t *testing.T) { + body := simpleItemBody(28577, 950, [3]float32{}, [4]float32{0, 0, 0, 1}, nil) + // These opaque quaternion bytes resemble an ordinary page/slot pair. + binary.BigEndian.PutUint32(body[24:28], 0x68400000) + + packet := targetPacket(n3Packet(0x3b11256f, 51053, 7, body)) + packet = packet[:binary.BigEndian.Uint16(packet[6:8])] + + if !bytes.Equal(packet[29:], body) { + t.Fatalf("parentless SimpleItem transform was treated as inventory placement: %x", packet) + } +} diff --git a/server/target_protocol.go b/server/target_protocol.go @@ -112,6 +112,11 @@ func targetPacket(packet []byte) []byte { if binary.BigEndian.Uint32(packet[44:48]) == 50000 && destination >= 64 && destination < 94 { binary.BigEndian.PutUint32(packet[52:56], destination-16) } + case 0x3b11256f: + // Parentless SimpleItems have a transform before their placement bytes. + if binary.BigEndian.Uint32(packet[40:44]) == 50000 && packet[60] == 104 && packet[61] >= 64 && packet[61] < 94 { + packet[61] -= 16 + } case 0x465a5d73, 0x3b1d2268: // Preserve first-free sentinel 111; translate only ordinary shared slots. if packet[60] == 104 && packet[61] >= 64 && packet[61] < 94 { diff --git a/tools/client/test_mission_key_name.mjs b/tools/client/test_mission_key_name.mjs @@ -0,0 +1,45 @@ +import assert from 'node:assert/strict'; +import {createRequire} from 'node:module'; +import {GameTest} from './game_test.mjs'; + +const {chromium} = createRequire(import.meta.url)('playwright'); +const [url, output] = process.argv.slice(2); +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']}); +let game; +try { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'mission-key-name', url}]); + const page = await context.newPage(); + game = await GameTest.attach(page); + await page.goto(url); + await game.ready(); + await page.waitForFunction(() => touchRegion(500, 400)?.world === true); + await game.snapshot(); + await game.key('KeyI'); + await game.save(output + '/before'); + assert((await page.request.post(url + '/test-name')).ok()); + await game.wait('both named keys attached to real instances', state => + game.events.filter(event => event.direction === 'framereceived' && event.opcode === '3b11256f').length === 2 && + game.local(state).inventory.length === 2 && + game.local(state).inventory.every(item => item.type === 51053 && item.id !== 0)); + const updates = game.events.filter(event => event.direction === 'framereceived' && event.opcode === '3b11256f'); + assert.deepEqual(updates.map(event => Buffer.from(event.hex, 'hex')[54]), [48, 49]); + for (const slot of [48, 49]) { + const cell = game.state.grids.flatMap(grid => grid.cells).find(cell => + cell.identity[0] === 104 && cell.identity[1] === slot && !cell.dummy); + assert(cell, 'named key row remains usable'); + await page.keyboard.down('Shift'); + try { + await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2); + } finally { await page.keyboard.up('Shift'); } + await game.save(output + '/info-' + slot); + await game.key('Escape'); + } + assert.deepEqual(game.errors, []); + console.log('PASS: generic SimpleItem updates attach both named key identities; inspect native info screenshots'); +} finally { + try { if (game) await game.save(output + '/final'); } + finally { await browser.close(); } +}