aorecomp

Anarchy Online classic in the browser

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


commit 5f83e3aaec0c1c3464dd422611536abcb6454b23
parent 7263c7a3b630f1876a882d198a8a48e21f345d0f
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 03:41:27 +0000

Expose native inventory grid and drag state in browser snapshots

Diffstat:
MDEVELOPERS.md | 23+++++++++++++++++++++++
MTODO.md | 10++++++++--
Mclient/runtime/browser_testing.c | 49++++++++++++++++++++++++++++++++++++++++++++++---
Mclient/tests/browser_testing.c | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/browser_inventory_grid_test.go | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_inventory_grid.mjs | 103+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 351 insertions(+), 5 deletions(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -598,6 +598,29 @@ do not resume pointer scanning from page JavaScript. The production page does not request snapshots or collect test traces during normal play. Rebuild and publish the matching bundle with `make wasm -j8` after runtime changes. +Snapshots include active native `grids`, with columns, visible rows, `firstRow`, +and `totalCells`. Each active cell records its visual `index`, native `identity`, +canvas-pixel `bounds` and `dummy` flag. Grid `position` is local to its parent +render window; use cell bounds for browser input. Empty cells and icons hidden +during a drag can both be dummy cells. The root `dragged` identity comes from +the native drag manager and is `[0, 0]` when no object is held. + +For ordinary inventory, a cell identity `[104, slot]` refers to the corresponding +native actor inventory slot. It does not give the visual cell index or physical +item ID. Collect successive scroll rows to cover the whole grid before declaring +an icon missing, and account for an item on the mouse cursor. These snapshots +report active native cells; they do not calculate occlusion by other windows. + +`TestBrowserInventoryGrid` checks sparse logical slots, complete cell coverage, +native wheel offsets, mouse-held/dummy state and a fully settled visual swap. +Page reload retains the layout, while cold store loading confirms unchanged +ownership of 28 carried and two banked items. It uses controlled fixtures and +real browser input, without earning progression to reach the condition: + +```sh +AO_GAME_TEST=1 go test ./server -run '^TestBrowserInventoryGrid$' -count=1 -timeout=5m -v +``` + Focused harness checks, without starting the full game: ```sh diff --git a/TODO.md b/TODO.md @@ -3467,16 +3467,22 @@ with payloads and known client/server provenance. The retained history starts after death; the resurrection sequence is no longer in that bounded trace. Keep this evidence gap separate from a missing game transition or native error. Captures: `local/todo-progression-play/runtime-level6/`. -- [ ] [P1] Record visible inventory grid cells and scroll offset in browser +- [x] [P1] Record visible inventory grid cells and scroll offset in browser snapshots. Check: missing-icon audits identify the actual displayed cells and verify coverage of every row rather than infer visual order from logical - slots. Current actor snapshots expose inventory ownership, not GUI placement; + slots. Actor inventory snapshots alone expose ownership, not GUI placement; the original kit-37 post-reload scan omitted its previous top-row cell. Saved native icon maps and explicit wheel-row screenshots now establish the focused case; see [merged-kit audit](docs/starter-progression.md#merged-kit-visual-cell-audit). The later seven-part sale also confirms that initially sparse logical slots can occupy compact GUI cells. Its wire offers identify exact sources despite the visual order; see [earned recovery restock](docs/mission-levels.md#earned-recovery-restock). + Read-only completed-frame snapshots now expose actual cells, bounds, logical + identities, first visible row, dummy state and the mouse-held identity. A + controlled native fixture covers every cell, distinguishes sparse logical + slots from visual positions, completes a visual swap and preserves its layout + through reload with unchanged cold ownership. See + [browser game testing](DEVELOPERS.md#browser-game-testing). - [ ] [P2] Capture effective equipment defenses in the browser harness. Actor stat snapshots contain raw AC 90..97, while worn-item modifiers are separate. Check: repeatable snapshots distinguish base values from all eight diff --git a/client/runtime/browser_testing.c b/client/runtime/browser_testing.c @@ -72,6 +72,44 @@ static void inventory(FILE *output, uint32_t actor) fputc(']', output); } +static void icon_grids(FILE *output, uint32_t head) +{ + fputc('[', output); + unsigned count = 0; + for (uint32_t node = head ? MEM32(head) : 0; node && node != head; node = MEM32(node)) { + uint32_t slider = MEM32(node + 8); + /* ccr.dll!IconGrid_t::IconGrid_t binds even inactive scrollbars through + SliderButton_t::SetCallback. Check its class before reading those fields. */ + if (MEM32(slider) != 0x27034524 || MEM32(slider + 0xb4) != 0x27011540) continue; + uint32_t grid = MEM32(slider + 0xb8); + if (!grid || !MEM8(grid + 0x35)) continue; + if (count++) fputc(',', output); + uint32_t list = MEM32(grid), cells = MEM32(list + 4); + fprintf(output, "{\"position\":[%d,%d],\"cellSize\":[%d,%d],\"columns\":%u,\"rows\":%u," + "\"firstRow\":%d,\"totalCells\":%u,\"dragType\":%u,\"cells\":[", + (int32_t)MEM32(grid + 8), (int32_t)MEM32(grid + 12), + (int32_t)MEM32(grid + 0x18), (int32_t)MEM32(grid + 0x1c), + MEM32(grid + 0x10), MEM32(grid + 0x14), (int32_t)MEM32(grid + 0x2c), + MEM32(list + 8), MEM32(grid + 0x3c)); + + /* IconGrid_t::Reposition walks this list in visual order, independently + of each DragObject_t identity. Dummy cells include pending/empty icons. */ + unsigned index = 0, visible = 0; + for (uint32_t cell = MEM32(cells); cell != cells; cell = MEM32(cell), ++index) { + uint32_t object = MEM32(cell + 8); + if (!MEM8(object + 8)) continue; + if (visible++) fputc(',', output); + fprintf(output, "{\"index\":%u,\"identity\":[%u,%u],\"bounds\":[%d,%d,%d,%d],\"dummy\":%s}", + index, MEM32(object + 0x54), MEM32(object + 0x58), + (int32_t)MEM32(object + 0x2c), (int32_t)MEM32(object + 0x30), + (int32_t)MEM32(object + 0x34), (int32_t)MEM32(object + 0x38), + MEM8(object + 0x70) ? "true" : "false"); + } + fputs("]}", output); + } + fputc(']', output); +} + static void actor(FILE *output, uint32_t object, uint32_t type, uint32_t id, int local) { uint32_t vehicle = MEM32(object + 0x60); @@ -164,10 +202,13 @@ void browser_test_frame(void) uint32_t engine = MEM32(0x2d01752c), local = engine ? MEM32(engine + 0x88) : 0; /* KKR sub_36072000 owns selection in the local actor's command helper. */ uint32_t commands = local ? MEM32(local + 0x168) : 0; - fprintf(output, "{\"frame\":%u,\"screen\":[%u,%u],\"hover\":[%u,%u],\"selected\":[%u,%u],", + /* ccr.dll!DragAndDrop_t::GetDragObject returns the mouse-held object. */ + uint32_t drag = MEM32(0x27048b6c), dragged = drag ? MEM32(drag + 0x20) : 0; + fprintf(output, "{\"frame\":%u,\"screen\":[%u,%u],\"hover\":[%u,%u],\"selected\":[%u,%u],\"dragged\":[%u,%u],", frame, MEM32(0x27048be8), MEM32(0x27048bec), engine ? MEM32(engine + 0xd8) : 0, engine ? MEM32(engine + 0xdc) : 0, - commands ? MEM32(commands + 0x70) : 0, commands ? MEM32(commands + 0x74) : 0); + commands ? MEM32(commands + 0x70) : 0, commands ? MEM32(commands + 0x74) : 0, + dragged ? MEM32(dragged + 0x54) : 0, dragged ? MEM32(dragged + 0x58) : 0); uint32_t scene = MEM32(0x3806ec04), camera = scene ? MEM32(scene + 0x80) : 0; fputs("\"camera\":", output); @@ -200,7 +241,9 @@ void browser_test_frame(void) fprintf(output, "[%d,%d,%d,%d]", (int32_t)MEM32(region + 0x2c), (int32_t)MEM32(region + 0x30), (int32_t)MEM32(region + 0x34), (int32_t)MEM32(region + 0x38)); } - fputs("]}", output); + fputs("],\"grids\":", output); + icon_grids(output, head); + fputc('}', output); if (fclose(output)) abort(); ao_test_publish(json); free(json); diff --git a/client/tests/browser_testing.c b/client/tests/browser_testing.c @@ -184,6 +184,90 @@ static void snapshots_observe_active_local_actions_without_mutation(void) assert(g_eax == 123 && g_esp == 456); } +static void snapshots_record_visible_grid_cells_and_scroll_without_mutation(void) +{ + guest_map("test icon grid", 0x51000000, 0x10000); + MEM32(0x27048b7c) = 0x51000000; + MEM32(0x51000000) = 0x51000100; + MEM8(0x51000004) = 1; + MEM32(0x51000104) = 0x51000200; + memcpy((void *)ADDR(0x51000200), (uint32_t[]){0x51000220, 0x51000240, 0}, 12); + memcpy((void *)ADDR(0x51000220), (uint32_t[]){0x51000230, 0x51000200, 0x51000400}, 12); + memcpy((void *)ADDR(0x51000230), (uint32_t[]){0x51000240, 0x51000220, 0x51000600}, 12); + memcpy((void *)ADDR(0x51000240), (uint32_t[]){0x51000200, 0x51000230, 0x5100ffac}, 12); + + /* The scrollbar itself is inactive, but still identifies the visible grid. */ + MEM32(0x51000400) = MEM32(0x51000600) = 0x27034524; + MEM32(0x510004b4) = 0x27011540; + MEM32(0x510004b8) = 0x51000800; + MEM32(0x510006b4) = 0x12345678; + MEM32(0x5100ffac) = 0x2703429c; + MEM32(0x51000800) = 0x51000a00; + MEM32(0x51000808) = 200; + MEM32(0x5100080c) = 250; + MEM32(0x51000810) = 3; + MEM32(0x51000814) = 2; + MEM32(0x51000818) = MEM32(0x5100081c) = 52; + MEM32(0x5100082c) = 1; + MEM8(0x51000835) = 1; + MEM32(0x5100083c) = 1; + MEM32(0x51000a04) = 0x51000b00; + MEM32(0x51000a08) = 9; + MEM32(0x51000b00) = 0x51000b20; + for (unsigned i = 0; i < 9; ++i) { + uint32_t node = 0x51000b20 + i * 16, object = 0x51001000 + i * 256; + MEM32(node) = i == 8 ? 0x51000b00 : node + 16; + MEM32(node + 8) = object; + MEM8(object + 8) = i >= 3; + MEM8(object + 0x70) = i != 3; + MEM32(object + 0x2c) = 200 + i % 3 * 52; + MEM32(object + 0x30) = 250 + ((int)i / 3 - 1) * 52; + MEM32(object + 0x34) = MEM32(object + 0x2c) + 44; + MEM32(object + 0x38) = MEM32(object + 0x30) + 44; + } + MEM32(0x51001354) = MEM32(0x51001554) = 104; + MEM32(0x51001358) = 77; + MEM32(0x51001558) = 48; + unsigned char before[100]; + memcpy(before, (void *)ADDR(0x51000800), sizeof(before)); + + browser_test_request(); + browser_test_frame(); + + assert(strstr(snapshot, "\"grids\":[{\"position\":[200,250],\"cellSize\":[52,52],\"columns\":3,\"rows\":2,\"firstRow\":1,\"totalCells\":9,\"dragType\":1")); + assert(strstr(snapshot, "\"cells\":[{\"index\":3,\"identity\":[104,77],\"bounds\":[200,250,244,294],\"dummy\":false}")); + assert(strstr(snapshot, "{\"index\":4,\"identity\":[0,0],\"bounds\":[252,250,296,294],\"dummy\":true}")); + assert(strstr(snapshot, "{\"index\":5,\"identity\":[104,48],\"bounds\":[304,250,348,294],\"dummy\":true}")); + assert(strstr(snapshot, "{\"index\":8,\"identity\":[0,0],\"bounds\":[304,302,348,346],\"dummy\":true}")); + assert(!strstr(snapshot, "\"index\":0")); + assert(!memcmp(before, (void *)ADDR(0x51000800), sizeof(before))); + assert(MEM32(0x51001358) == 77 && MEM8(0x51001570) == 1); + assert(g_eax == 123 && g_esp == 456); + + /* Hidden grids are omitted even while their scrollbar stays registered. */ + MEM8(0x51000835) = 0; + browser_test_request(); + browser_test_frame(); + assert(strstr(snapshot, "\"grids\":[]")); +} + +static void snapshots_record_dragged_identity_without_mutation(void) +{ + MEM32(0x27048b6c) = 0x51000c00; + MEM32(0x51000c20) = 0x51001300; + + browser_test_request(); + browser_test_frame(); + + assert(strstr(snapshot, "\"dragged\":[104,77]")); + assert(MEM32(0x51000c20) == 0x51001300 && MEM32(0x51001358) == 77); + assert(g_eax == 123 && g_esp == 456); + MEM32(0x51000c20) = 0; + browser_test_request(); + browser_test_frame(); + assert(strstr(snapshot, "\"dragged\":[0,0]")); +} + int main(void) { snapshot_copies_native_state_without_changing_guest_registers(); @@ -193,6 +277,8 @@ int main(void) snapshots_observe_active_local_actions_without_mutation(); snapshots_include_reclaim_booths_without_mutation(); snapshots_preserve_wrapped_weapon_results(); + snapshots_record_visible_grid_cells_and_scroll_without_mutation(); + snapshots_record_dragged_identity_without_mutation(); free(snapshot); puts("PASS: frame snapshots, native inventory, directory clearing and guest state preservation"); } diff --git a/server/browser_inventory_grid_test.go b/server/browser_inventory_grid_test.go @@ -0,0 +1,85 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "slices" + "testing" + "time" +) + +func TestBrowserInventoryGrid(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the visible inventory grid check") + } + + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/icon-grid", time.Now().Format("20060102-150405")) + world := newTestServer(t) + player := world.newCharacter() + player.playfield, player.position = 705, [3]float32{960, 16.5, 511} + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("inventory-grid"))) + world.characters = map[uint32]*character{player.id: player} + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + for i := 0; i < 30; i++ { + template := uint32(42640) + if i == 0 { + template = 25812 + } else if i == 29 { + template = 121564 + } + if granted, err := world.grantItem_locked(player, template); err != nil || !granted { + t.Fatal(granted, err) + } + } + inventory := player.inventory + inventory.Items = nil + for _, item := range player.inventory.Items { + if item.Slot == 75 || item.Slot == 80 { + item.Slot = uint32(len(inventory.Bank)) + inventory.Bank = append(inventory.Bank, item) + } else { + inventory.Items = append(inventory.Items, item) + } + } + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + mux := http.NewServeMux() + mux.Handle("/", world.httpHandler()) + mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) { + world.mutex.Lock() + defer world.mutex.Unlock() + json.NewEncoder(w).Encode(player.inventory) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 4*time.Minute) + defer cancel() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_inventory_grid.mjs"), host.URL, output) + command.Dir = root + command.Stdout, command.Stderr = os.Stdout, os.Stderr + if err := command.Run(); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + + if !slices.Equal(player.inventory.Items, inventory.Items) || !slices.Equal(cold.characters[1].inventory.Items, inventory.Items) || + !slices.Equal(cold.characters[1].inventory.Bank, inventory.Bank) { + t.Fatal("visual grid actions changed durable item placement") + } + t.Logf("Browser artifacts: %s", output) +} diff --git a/tools/client/test_inventory_grid.mjs b/tools/client/test_inventory_grid.mjs @@ -0,0 +1,103 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +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', headless: false, + args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', + '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); +const evidence = {}; +let game; +try { + const context = await browser.newContext({viewport: {width: 1024, height: 480}}); + await context.addCookies([{name: 'ao_client', value: 'inventory-grid', url}]); + const page = await context.newPage(); + game = await GameTest.attach(page); + await page.goto(url); + await game.ready(); + evidence.before = await (await page.request.get(url + '/test-state')).json(); + await game.key('i'); + console.log('Initial grids:', JSON.stringify(game.state.grids.map(grid => ({...grid, cells: grid.cells.slice(0, 4)})))); + const inventoryGrid = state => state.grids.find(grid => grid.totalCells >= 28 && + grid.cells.some(cell => cell.identity[0] === 104 && cell.identity[1] >= 48 && cell.identity[1] < 78)); + await game.wait('native inventory grid', state => inventoryGrid(state)); + await game.save(output + '/top'); + + // Cover every visual cell while observing the native scroll row. + const seen = new Set(); + const identities = new Set(); + evidence.rows = []; + for (let attempt = 0; attempt < 30; ++attempt) { + const grid = inventoryGrid(game.state); + evidence.rows.push(grid); + for (const cell of grid.cells) { + seen.add(cell.index); + if (cell.identity[0] === 104 && !cell.dummy) identities.add(cell.identity[1]); + } + if (grid.cells.some(cell => cell.index === grid.totalCells - 1)) break; + const [left, top, right, bottom] = grid.cells[0].bounds; + const point = await game.point((left + right) / 2, (top + bottom) / 2); + await page.mouse.move(point.x, point.y); + await page.mouse.wheel(0, 120); + await game.wait('native inventory row advances', state => inventoryGrid(state)?.firstRow > grid.firstRow); + } + let grid = inventoryGrid(game.state); + assert.equal(seen.size, grid.totalCells); + assert.deepEqual([...identities].sort((a, b) => a - b), game.local().inventory.map(item => item.slot).sort((a, b) => a - b)); + assert(grid.firstRow > 0); + const source = grid.cells.find(cell => cell.identity[0] === 104 && cell.identity[1] === 77); + const target = grid.cells.find(cell => !cell.dummy && cell.identity[0] === 104 && cell.identity[1] === 76); + assert(source && target); + assert.notEqual(source.index, 29, 'Sparse logical slots must not be interpreted as visual indices'); + evidence.source = source; + evidence.target = target; + const visible = grid.cells.filter(cell => !cell.dummy).map(cell => cell.identity[1]).sort((a, b) => a - b); + await game.save(output + '/bottom'); + + await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2); + await game.wait('picked icon becomes a dummy', state => state.dragged[0] === 104 && state.dragged[1] === 77 && + inventoryGrid(state).cells.some(cell => cell.identity[0] === 104 && cell.identity[1] === 77 && cell.dummy)); + evidence.picked = game.state.dragged; + await game.click((target.bounds[0] + target.bounds[2]) / 2, (target.bounds[1] + target.bounds[3]) / 2); + await game.wait('occupied cell displaces the other item', state => state.dragged[0] === 104 && state.dragged[1] === 76 && + inventoryGrid(state).cells.some(cell => cell.index === target.index && cell.identity[0] === 104 && cell.identity[1] === 77 && !cell.dummy)); + evidence.displaced = game.state.dragged; + await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2); + await game.wait('visual swap completes with no held item', state => state.dragged[0] === 0 && state.dragged[1] === 0 && + inventoryGrid(state).cells.some(cell => cell.index === source.index && cell.identity[0] === 104 && cell.identity[1] === 76 && !cell.dummy)); + assert.deepEqual(inventoryGrid(game.state).cells.filter(cell => !cell.dummy).map(cell => cell.identity[1]).sort((a, b) => a - b), visible); + assert.deepEqual(await (await page.request.get(url + '/test-state')).json(), evidence.before); + await game.save(output + '/moved'); + + await page.reload(); + await game.ready(); + if (!inventoryGrid(game.state)) await game.key('i'); + await game.wait('inventory after reload', state => inventoryGrid(state)); + for (let attempt = 0; attempt < 30; ++attempt) { + grid = inventoryGrid(game.state); + if (grid.cells.some(cell => cell.index === target.index && cell.identity[0] === 104 && cell.identity[1] === 77) && + grid.cells.some(cell => cell.index === source.index && cell.identity[0] === 104 && cell.identity[1] === 76)) break; + const [left, top, right, bottom] = grid.cells[0].bounds; + const point = await game.point((left + right) / 2, (top + bottom) / 2); + await page.mouse.move(point.x, point.y); + await page.mouse.wheel(0, 120); + await game.wait('reload scroll row advances', state => inventoryGrid(state)?.firstRow > grid.firstRow); + } + assert(inventoryGrid(game.state).cells.some(cell => cell.index === target.index && cell.identity[0] === 104 && cell.identity[1] === 77 && !cell.dummy)); + assert.deepEqual(await (await page.request.get(url + '/test-state')).json(), evidence.before); + assert.equal(game.errors.length, 0); + evidence.after = inventoryGrid(game.state); + assert.deepEqual(game.state.dragged, [0, 0]); + await game.save(output + '/replayed'); + await game.key('i'); + await game.wait('closed inventory has no active grids', state => state.grids.length === 0); + console.log('PASS: visible cells, sparse logical identities, complete wheel coverage, dummy state, visual swap and page retention'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); + if (game) await game.save(output + '/final'); + } finally { await browser.close(); } +}