aorecomp

Anarchy Online classic in the browser

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


commit 7f89fbcfbced5c4c6f28a096473d8d7b6d1d293f
parent 533a9647d94ac91da85810b9c25a5cac61472e5d
Author: anon <anon@example.com>
Date:   Wed,  4 Nov 2026 16:01:07 +0000

Capture effective armor in passive WASM snapshots

Diffstat:
MDEVELOPERS.md | 6++++++
MTODO.md | 22+++++++++++++++-------
Mclient/runtime/browser_testing.c | 20++++++++++++++++++++
Mclient/tests/browser_testing.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Adocs/browser-effective-armor.md | 46++++++++++++++++++++++++++++++++++++++++++++++
Aserver/browser_effective_armor_test.go | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_effective_armor.mjs | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 303 insertions(+), 7 deletions(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -499,6 +499,12 @@ C snapshots taken after complete game frames. It does not grant items, edit stats, teleport characters, bypass native commands or inject protocol packets. Use it for remaining gameplay work instead of copying local memory-scanning scripts or adding sleeps after each action. +Actor `stats` entries are raw values. `effectiveArmor` contains the eight +Protection-form defenses in stat90..97 order, including signed worn/nano +modifiers. Use it when checking actual AC changes; zero raw AC does not imply +missing armor. The snapshot reads the native tree without calling guest code. +`TestBrowserEffectiveArmor` checks all eight values through wear, removal, page +replay and fresh-server startup; see [effective armor snapshots](docs/browser-effective-armor.md). Short key/click helpers release on the fresh consumed SDL event, then read the next full snapshot. Reading a large snapshot while holding a skill button can trigger native autorepeat and buy more points than intended. diff --git a/TODO.md b/TODO.md @@ -3951,13 +3951,21 @@ with payloads and known client/server provenance. 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 - effective AC values and agree with the original Protection form through - wear, removal, reconnect and cold startup. The earned QL8 body/pants run - currently verifies effective values by inspecting that form's screenshots; - raw zero AC entries are not evidence of lost armor. +- [x] [P2] Capture effective equipment defenses in the browser harness. + Raw `stats[90..97]` now remain distinct from `effectiveArmor`, read passively + from the native signed modifier tree. A controlled QL2 vest matches all eight + Protection-form values through real wear/removal, re-wear, page replay and + fresh-server startup. WASM contracts cover nonzero raw values, signed and + missing modifiers and unchanged guest state; raw zero AC is not evidence of + lost armor. See [effective armor snapshots](docs/browser-effective-armor.md). +- [ ] [P1] Reconcile native and server selected-quality armor requirement + boundaries. The QL2 vest85481/85690 fixture sends no native wear request at + raw Sense10/Agility10, then wears at11/11, while the public-handler catalog + test admits10/9. Isolate each ability and recover the original interpolation, + integer conversion and strict comparison before changing admission. Check + both reviewed anchors at exact boundaries and adjacent values, with native + requests and matching server acceptance. See the snapshot fixture's retained + first run; this is separate from AC capture. - [x] [P1] Audit native inventory-proxy identities immediately after rewards. Mission 81's new boots have the correct slot, QL, templates and count while their raw proxy still reports type/id 0; page replay populates exact ID 87. diff --git a/client/runtime/browser_testing.c b/client/runtime/browser_testing.c @@ -157,6 +157,26 @@ static void actor(FILE *output, uint32_t object, uint32_t type, uint32_t id, int if (i) fputc(',', output); fprintf(output, "%d", (int32_t)MEM32(stats + i * 4)); } + /* KKR sub_3606DFB0 mode3 / sub_36075CD0: raw AC plus signed modifiers. + Read the modifier tree without calling getters that may insert keys. */ + uint32_t skills = MEM32(object + 0x154); + uint32_t modifiers = skills ? MEM32(skills + 8) : 0; + uint32_t head = modifiers ? MEM32(modifiers + 4) : 0; + fputs("],\"effectiveArmor\":[", output); + for (unsigned stat = 90; stat < 98; ++stat) { + uint32_t value = MEM32(stats + stat * 4); + uint32_t node = head ? MEM32(head + 4) : 0; + while (node && node != head) { + uint32_t key = MEM32(node + 12); + if (stat == key) { + value += MEM32(node + 16); + break; + } + node = MEM32(node + (stat < key ? 0 : 8)); + } + if (stat != 90) fputc(',', output); + fprintf(output, "%d", (int32_t)value); + } fputs("],\"weapons\":[", output); unsigned weapons = 0; if (combat) { diff --git a/client/tests/browser_testing.c b/client/tests/browser_testing.c @@ -300,6 +300,50 @@ static void snapshots_record_uploaded_mission_identities_without_mutation(void) assert(strstr(snapshot, "\"missionWaypoints\":{\"local\":[],\"planet\":null,\"compass\":null}")); } +static void snapshots_distinguish_raw_and_effective_armor_without_mutation(void) +{ + MEM32(0x50001154) = 0x50005100; + MEM32(0x50005108) = 0x50005200; + MEM32(0x50005204) = 0x50005300; + MEM32(0x50005304) = 0x50005300; + for (unsigned i = 0; i < 8; ++i) + MEM32(0x50004000 + (90 + i) * 4) = 10 + i; + + browser_test_request(); + browser_test_frame(); + + assert(strstr(snapshot, "\"effectiveArmor\":[10,11,12,13,14,15,16,17]")); + assert(g_eax == 123 && g_esp == 456); + + const int modifiers[8] = {20, -3, 4, 5, 6, 7, 8, 9}; + const int children[8][2] = {{-1, -1}, {0, 2}, {-1, -1}, {1, 6}, {-1, 5}, {-1, -1}, {4, 7}, {-1, -1}}; + MEM32(0x50005304) = 0x50005460; + for (unsigned i = 0; i < 8; ++i) { + uint32_t node = 0x50005400 + i * 32; + MEM32(node) = children[i][0] < 0 ? 0x50005300 : 0x50005400 + children[i][0] * 32; + MEM32(node + 8) = children[i][1] < 0 ? 0x50005300 : 0x50005400 + children[i][1] * 32; + MEM32(node + 12) = 90 + i; + MEM32(node + 16) = modifiers[i]; + } + unsigned char before[0x600]; + memcpy(before, (void *)ADDR(0x50005000), sizeof(before)); + + browser_test_request(); + browser_test_frame(); + + assert(strstr(snapshot, "\"effectiveArmor\":[30,8,16,18,20,22,24,26]")); + assert(!memcmp(before, (void *)ADDR(0x50005000), sizeof(before))); + assert(MEM32(0x50004000 + 91 * 4) == 11); + assert(g_eax == 123 && g_esp == 456); + + /* Missing keys use zero modifiers rather than a neighboring tree node. */ + MEM32(0x500054c0) = 0x50005300; + browser_test_request(); + browser_test_frame(); + assert(strstr(snapshot, "\"effectiveArmor\":[30,8,16,18,14,15,24,26]")); + MEM32(0x50001154) = 0; +} + int main(void) { snapshot_copies_native_state_without_changing_guest_registers(); @@ -312,6 +356,7 @@ int main(void) snapshots_record_visible_grid_cells_and_scroll_without_mutation(); snapshots_record_dragged_identity_without_mutation(); snapshots_record_uploaded_mission_identities_without_mutation(); + snapshots_distinguish_raw_and_effective_armor_without_mutation(); free(snapshot); puts("PASS: frame snapshots, native inventory, directory clearing and guest state preservation"); } diff --git a/docs/browser-effective-armor.md b/docs/browser-effective-armor.md @@ -0,0 +1,46 @@ +# Effective armor snapshots + +`GameTest.local().stats` preserves the original raw stat dictionary. The +actor's `effectiveArmor` array separately captures stat90..97: projectile, +melee, energy, chemical, radiation, cold, poison/disease and fire AC. Worn-item +and active-nano modifiers belong to the native modifier tree rather than the +raw dictionary. Zero raw AC is not proof that an item lost its effects. + +The snapshot reads the same raw-plus-signed-modifier values exposed by KKR's +mode3 getter, `client/game/kkr.dll/lifted-0033.c::sub_3606DFB0` and +`client/game/kkr.dll/lifted-0034.c::sub_36075CD0`. It walks the existing tree +without invoking getters that can insert absent keys. It does not change guest +registers, item state or modifier nodes, and does not infer AC from server data +or replay catalog wear effects. This field is specific to defenses; it is not +a general replacement for the native skill getters or their ability weights. + +`client/tests/browser_testing.c` exercises all eight nonzero raw values, +positive/negative modifiers, empty trees, missing interior keys and guest-state +preservation. The new contract fails against the prior snapshot, which omitted +the field, and passes in the WASM test module. Existing ten snapshot contracts +continue to pass. + +```sh +make -C client -f Makefile.wasm build/wasm/browser-testing.js +node client/build/wasm/browser-testing.js +AO_GAME_TEST=1 go test ./server -run '^TestBrowserEffectiveArmor$' -count=1 -timeout=5m -v +``` + +The browser check uses a controlled level2 character and one QL2 Leather Vest, +with raw Sense11/Agility11. Actual mouse input wears, removes and re-wears the +same physical instance. All eight native values agree with the server: +`9,10,2,2,9,9,2,6` while worn and all zero after removal. Protection-form +screenshots were independently reviewed and show those same values in the +form's visual order. Page replay and a fresh server/browser load retain the +exact vest and defenses; no earned acquisition or progression is claimed. + +Accepted captures: `local/effective-armor/20261104-075711/`, warm23.56s and +cold9.98s. The first controlled run at raw10/10 was refused locally without a +wear request. Its comparison with the server's10/9 admission remains a separate +TODO for recovering requirement interpolation, not a claimed fix here. +Original getter/resource evidence, source and bundle hashes, complete traces, +validation logs and a packet/state audit are retained in `local/effective-armor/`. +The focused armor checks pass2 roots/76 results in19.120s; maintained-package +vet, JavaScript syntax and whitespace checks pass. Twelve complete native +traces have no client errors or dropped events, and the audit verifies the +published bundle's bytes and complete client-source digest. diff --git a/server/browser_effective_armor_test.go b/server/browser_effective_armor_test.go @@ -0,0 +1,94 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "slices" + "testing" + "time" +) + +func TestBrowserEffectiveArmor(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for effective armor snapshots") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/effective-armor", time.Now().Format("20060102-150405")) + t.Chdir(t.TempDir()) + for _, phase := range []string{"warm", "cold"} { + t.Run(phase, func(t *testing.T) { + world := newServerForTest(t) + if phase == "warm" { + player := world.newCharacter() + player.level = 2 + player.stats.Abilities.Sense, player.stats.Abilities.Agility = 11, 11 + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("effective-armor"))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, 85481); err != nil || !granted { + t.Fatal(granted, err) + } + inventory := player.inventory + inventory.Items = slices.Clone(inventory.Items) + inventory.Items[0].Quality = 2 + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + } + player := world.characters[1] + 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() + var armor [8]int32 + for index := range armor { + armor[index] = player.equipmentBonus(90 + uint32(index)) + } + json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "armor": armor}) + }) + mux.HandleFunc("POST /test-complete", func(w http.ResponseWriter, r *http.Request) { + world.mutex.Lock() + finish := world.clients[1].equipment.readyAt + world.mutex.Unlock() + world.advanceEquipment(finish) + }) + 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_effective_armor.mjs"), host.URL, filepath.Join(output, phase), phase) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + err := command.Run() + t.Logf("Armor snapshot artifacts: %s", output) + + if err != nil { + t.Fatal(err) + } + if !slices.Equal(player.inventory.Items, []ownedItem{{ID: 1, Type: 51022, Template: 85481, Quality: 2, Slot: 21, Count: 1}}) || + world.nextItem != 1 || player.inventory.Credits != 0 { + t.Fatal("armor snapshot scenario changed the retained vest") + } + for index, value := range [8]int32{9, 10, 2, 2, 9, 9, 2, 6} { + if player.equipmentBonus(90+uint32(index)) != value { + t.Fatal("retained vest defenses changed", index) + } + } + }) + if t.Failed() { + return + } + } +} diff --git a/tools/client/test_effective_armor.mjs b/tools/client/test_effective_armor.mjs @@ -0,0 +1,77 @@ +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, phase] = 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; +const evidence = {}; +try { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'effective-armor', url}]); + const page = await context.newPage(); + game = await GameTest.attach(page); + await page.goto(url); + await game.ready(); + const expected = [9, 10, 2, 2, 9, 9, 2, 6]; + const verify = async (label, armor) => { + await game.wait(label + ' effective armor', state => + JSON.stringify(game.local(state).effectiveArmor) === JSON.stringify(armor)); + const state = await (await page.request.get(url + '/test-state')).json(); + assert.deepEqual(state.armor, armor); + assert.deepEqual(game.local().stats.slice(90, 98), [0, 0, 0, 0, 0, 0, 0, 0]); + evidence[label] = {server: state, armor: game.local().effectiveArmor}; + await game.save(output + '/' + label); + }; + const protection = async label => { + await game.key('u'); + await game.click(302, 427); + await game.save(output + '/' + label + '-protection'); + await game.click(544, 622); + }; + const move = async (x, y, slot) => { + await game.wait('previous native equipment action ends', state => + !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); + const sequence = game.sequence; + await game.click(x, y, 'right'); + await game.wait('real vest move request', () => game.events.some(event => event.sequence > sequence && + event.direction === 'framesent' && event.opcode === '47537a24')); + assert((await page.request.post(url + '/test-complete')).ok()); + await game.wait('vest reaches its exact slot', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === slot)); + }; + await game.key('i'); + await page.keyboard.press('Control+1'); + await game.click(953, 53); + if (phase === 'warm') { + await verify('unworn', [0, 0, 0, 0, 0, 0, 0, 0]); + await move(681, 45, 21); + await verify('worn', expected); + await protection('worn'); + await move(927, 148, 48); + await verify('removed', [0, 0, 0, 0, 0, 0, 0, 0]); + await protection('removed'); + await move(681, 45, 21); + await verify('reworn', expected); + await page.reload(); + await game.ready(); + await verify('page-replay', expected); + await protection('page-replay'); + } else { + assert.equal(phase, 'cold'); + await verify('cold', expected); + await protection('cold'); + } + assert.deepEqual(game.errors, []); + assert.equal(game.dropped, 0); + console.log('PASS: ' + phase + ' raw/effective AC snapshots retain all eight vest defenses'); +} 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(); } +}