aorecomp

Anarchy Online classic in the browser

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


commit aec9781256d7628f548f71a81bf394974c02bdc9
parent 7e79f26f28e30b63b8902fa6859def51c87e0f77
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 04:46:42 +0000

Reconcile queued weapon damage before remote character inspection

Diffstat:
MTODO.md | 16++++++++++++----
Mclient/Makefile.linux | 2+-
Mclient/game/kkr.dll/lifted-0037.c | 4++++
Mclient/tests/critical_result.c | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/character-info.md | 43++++++++++++++++++++++++++++++++++++-------
Aserver/browser_inspection_health_test.go | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/client/test_inspection_health.mjs | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 306 insertions(+), 12 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -1526,6 +1526,13 @@ replay/failure tests and WASM checks are recorded in [IP training](docs/ip-train packet confirms 106 after 2040 ms; no item charge changed. This separate prediction-phase case is retained in `local/earned-seven/post-kill-hp-phase-verified.json`; the broader audit stays open. +- [x] [P0] Prevent inspection from debiting an already committed queued hit twice. + Two native clients reproduce server/owner HP192 versus observer184 after T + inspection and one eight-damage impact. Check remote inspection, unchanged + result/feedback/timers, both clients' post-impact HP, repeated snapshots, + self-inspection and a later real hit now pass in native/WASM C and the real + two-client T-key regression. Keep independent recovery phases separate; see + [combat inspection](docs/character-info.md#resource-interaction-and-limits). - [x] Use one nano-restoring item. Check: nano recovery, consumption and its lock match that item rather than inheriting the health item's behavior. - [x] Use one sitting treatment kit. Check: it works in the permitted posture @@ -3763,10 +3770,11 @@ and server restarts. Turn every reproduced bug into a focused regression test. - [ ] [P1] Audit combat scheduling and outcomes. Cover range boundaries, moving or unavailable targets, repeated starts/stops, timing changes, equipment changes, two attackers, lethal and nonlethal hits, queued native results and HP agreement. - Include player and NPC inspection while a weapon hit is queued: original InfoPacket - applies absolute remote HP without an animation guard, so it shares the - unresolved healing/hit ordering problem. Verify the server, owner and observer - through impact and subsequent regeneration; see [inspection](docs/character-info.md). + Player inspection now reconciles already received weapon outcomes before + applying remote HP, with real self/remote T requests and both clients checked + through impact. Continue NPC runtime comparisons and subsequent regeneration + without treating the focused fix as full recovery-phase agreement; see + [inspection](docs/character-info.md). The special-animation smoke's Fast target HP54/51 difference is traced to independent native recovery phases by the simultaneous comparison above. Include special animations, each client's recovery phase and target/controller diff --git a/client/Makefile.linux b/client/Makefile.linux @@ -691,7 +691,7 @@ build/linux/fling-result: tests/fling_result.c game/kkr.dll/lifted-0053.c runtim test: build/linux/fling-result -build/linux/critical-result: tests/critical_result.c game/kkr.dll/weapon_health.c game/kkr.dll/weapon_health.h game/kkr.dll/lifted-0034.c game/kkr.dll/lifted-0035.c game/kkr.dll/lifted-0050.c game/kkr.dll/lifted-0051.c game/kkr.dll/lifted-0052.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h +build/linux/critical-result: tests/critical_result.c game/kkr.dll/weapon_health.c game/kkr.dll/weapon_health.h game/kkr.dll/lifted-0034.c game/kkr.dll/lifted-0035.c game/kkr.dll/lifted-0037.c game/kkr.dll/lifted-0050.c game/kkr.dll/lifted-0051.c game/kkr.dll/lifted-0052.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h @mkdir -p $(@D) $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@ diff --git a/client/game/kkr.dll/lifted-0037.c b/client/game/kkr.dll/lifted-0037.c @@ -1,5 +1,6 @@ #define RECOMP_GENERATED_CODE #include "recomp_types.h" +#include "kkr.dll/weapon_health.h" #include <math.h> #include <stdio.h> #include <stdlib.h> @@ -5906,6 +5907,9 @@ L_3607FAA0: esp = esp + 0x18u; /* 0x3607FAC5: add esp, 0x18 */ _flag_k = FK_ADD; edi = eax; /* 0x3607FAC8: mov edi, eax */ + /* Only remote InfoPacket application assigns absolute HP. */ + if (!MEM8(edi + 0x128)) + weapon_health_snapshot(MEM32(esi + 4), MEM32(esi + 8)); PUSH32(esp, edi); /* 0x3607FACA: push edi */ RECOMP_ICALL(0x3605B1A0u); /* 0x3607FACB: call 0x3605b1a0 */ /* not lifted */ RECOMP_FLAGS_IN(); diff --git a/client/tests/critical_result.c b/client/tests/critical_result.c @@ -13,11 +13,37 @@ void sub_360AB5A0(void); void sub_36075DB0(void); void sub_3607BE50(void); void sub_360B0A50(void); +void sub_3607FAA0(void); static unsigned reads, writes, feedbacks, generic_feedbacks, deaths, ammo_updates; static unsigned missing_attacker, missing_target, target_local; static uint32_t expected_result, death_reason; static int32_t ammunition; +static unsigned info_available; + +static void info_apply(void) +{ + assert(g_ecx == 0x50009500 && MEM32(g_esp + 4) == 0x50002000); + if (!MEM8(0x50002128)) { + MEM32(0x50002300) = MEM32(g_ecx + 0x14); + writes++; + } + g_esp += 8; +} + +static void character_control(void) +{ + assert(g_ecx == 0x50002000); + g_eax = 0x50009600; + g_esp += 4; +} + +static void info_publish(void) +{ + assert(g_ecx == 0x50009600 && MEM32(g_esp + 4) == 0x50009500); + info_available++; + g_esp += 8; +} static void actor_lookup(void) { @@ -156,6 +182,9 @@ recomp_func_t recomp_lookup(uint32_t address) case 0x360ab7b0: return damage_type; case 0x36075db0: return sub_36075DB0; case 0x3607be50: return sub_3607BE50; + case 0x3605b1a0: return info_apply; + case 0x36072000: return character_control; + case 0x360564a0: return info_publish; case 0x36072310: return target_state; case 0x3601c590: return feedback_interface; case 0x3601d0b0: return feedback; @@ -432,6 +461,77 @@ static void absolute_health_keeps_real_weapon_results(void) } } +static void inspection_keeps_real_weapon_results(void) +{ + const struct { unsigned index, local, snapshots; } cases[] = { + {0, 0, 1}, {49, 0, 2}, {0, 1, 1} + }; + for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); ++i) { + expected_result = 4; + death_reason = 0; + ammunition = 3; + target_local = cases[i].local; + missing_attacker = missing_target = info_available = 0; + setup(); + MEM32(0x3806c110) = 0x50009200; + MEM32(0x50009204) = MEM32(0x50009208) = 0x50009220; + MEM32(0x50009224) = 0x50009240; + MEM32(0x50009240) = MEM32(0x50009248) = 0x50009220; + MEM32(0x5000924c) = 50000; + MEM32(0x50009250) = 1; + MEM32(0x50009254) = 0x50001000; + MEM32(0x50002300) = 200; + MEM8(0x50002128) = cases[i].local; + MEM32(0x50000024) = 7; + MEM32(0x50003050) = 2; + MEM32(0x50003058) = 50000; + MEM32(0x5000305c) = 2; + MEM32(0x50005014) = MEM32(0x50005018) = cases[i].index; + sub_360AECB0(); + MEM32(0x3616ff70) = 0x3606da90; + MEM32(0x50009004) = 50000; + MEM32(0x50009008) = 2; + MEM32(0x50009020) = 0x50009500; + MEM32(0x50009514) = 193; + uint8_t weapon[0x40], results[400]; + memcpy(weapon, (void *)ADDR(0x50005000), sizeof(weapon)); + memcpy(results, (void *)ADDR(0x50008100), sizeof(results)); + + for (unsigned snapshot = 0; snapshot < cases[i].snapshots; ++snapshot) { + g_esp = 0x5000ff00; + g_ecx = 0x50009000; + g_esi = 123; + g_edi = 456; + sub_3607FAA0(); + assert(g_esp == 0x5000ff04 && g_esi == 123 && g_edi == 456); + assert(MEM32(0x50002300) == (cases[i].local ? 200 : 193)); + assert(!memcmp(weapon, (void *)ADDR(0x50005000), sizeof(weapon))); + assert(!memcmp(results, (void *)ADDR(0x50008100), sizeof(results))); + } + g_esp = 0x5000ff00; + MEM32(g_esp + 4) = 0; + MEM32(g_esp + 8) = 6; + g_ecx = 0x50003000; + sub_3607A2E0(); + + assert(MEM32(0x50002300) == 193 && deaths == 0); + assert(info_available == cases[i].snapshots && feedbacks == 1 && ammo_updates == 1); + assert(MEM32(0x50005014) == (cases[i].index + 1) % 50); + assert(MEM32(0x50005018) == MEM32(0x50005014)); + + // An outcome received after inspection still applies its real damage. + g_esp = 0x5000ff00; + g_ecx = 0x50000000; + sub_360AECB0(); + g_esp = 0x5000ff00; + MEM32(g_esp + 4) = 0; + MEM32(g_esp + 8) = 6; + g_ecx = 0x50003000; + sub_3607A2E0(); + assert(MEM32(0x50002300) == 186 && feedbacks == 2 && ammo_updates == 2); + } +} + int main(void) { assert(guest_map("critical result fixture", 0x50000000, 0x10000)); @@ -442,5 +542,6 @@ int main(void) backlog_results(); zero_result_backlog(); absolute_health_keeps_real_weapon_results(); + inspection_keeps_real_weapon_results(); puts("native weapon results: impact, backlog drain, absolute HP reconciliation, feedback, death and ammo passed"); } diff --git a/docs/character-info.md b/docs/character-info.md @@ -77,13 +77,24 @@ bonus. Later equipment/skill corrections use the same observer accounting as [team resources](team-resources.md). Local actors retain their owner stats. Inspection does not persist anything or broadcast the reply to other players. -The original apply function has no guard for pending weapon animations. -Inspection during a queued hit therefore shares the outstanding absolute-HP -ordering problem documented in [nano healing](nano-healing.md). Authoritative -HP in this response does not resolve that timing problem. Combat-time -inspection needs further verification and reconstruction of the common hit -timeline; this feature does not introduce a fabricated stop or alternate -packet to hide it. +The original apply function has no guard for pending weapon animations. The +maintained InfoPacket receiver therefore records pending outcomes through the +same [absolute-HP reconciliation](first-aid.md#maintained-client-reconciliation) +used by HealthDamage before applying a remote snapshot. Those outcomes still +produce their original animation, feedback and ammunition updates, while their +already included damage does not debit HP again. Outcomes received later apply +normally. Self-inspection skips this bookkeeping because the original apply +function skips owner HP at actor byte+0x128; its queued damage must still apply. + +The receive hook is in `client/game/kkr.dll/lifted-0037.c::sub_3607FAA0`, before +`client/game/kkr.dll/lifted-0028.c::sub_3605B1A0`. The retained +original apply evidence is +`ev_fff80e90dc407ce066139525b840386467dac11754261f0b1a99c4c1ad974179`, +with execute evidence +`ev_13f8d0ea148b7b93dae51450a703f4501f5e38126b623ccedb656595bd735ced`. +The local shipped KKR hash still matches the original above. This reconciliation +does not establish original-server publication timing or align independent +client regeneration phases. ## Knowledge storage @@ -127,6 +138,24 @@ matching snapshots and the save/loader evidence ledger are retained in ## Verification +`TestBrowserInspectionQueuedHit` advances one real incoming Leet hit in a +controlled two-player fixture. The server commits eight damage,200->192, while +the clients retain its queued animation. Before the fix, actual T inspection +sets remote HP192 and the later impact debits it again to184. With the matched +bundle, self-inspection leaves owner HP200 until impact, remote inspection +applies192 while retaining the original result, and both clients end at192. +Server health and attack deadlines stay unchanged; each client receives only +one real weapon result. The initial selection's earlier200-HP InfoPacket also +leaves the later hit eligible. This is focused fixture evidence, not earned +progression or complete NPC/regeneration-phase coverage. + +The native InfoPacket execute and weapon-result regression passes on Linux and +under production WASM optimization. It covers repeated remote snapshots, +ring wrap, the owner bypass, stack/saved-register preservation, untouched guest +weapon/result bytes, original feedback/ammunition callbacks and a later hit's +normal debit. The InfoPacket apply/cache boundary is a controlled sink in that +C fixture; the two-client test exercises the real application and UI path. + Go regressions cover exact native bytes, real world-socket dispatch, self and repeated requests, profile fields and combat regeneration intervals, unchanged SQLite state, recipient isolation, invalid identities/arguments, unavailable diff --git a/server/browser_inspection_health_test.go b/server/browser_inspection_health_test.go @@ -0,0 +1,82 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "testing" + "time" +) + +func TestBrowserInspectionQueuedHit(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for inspection during a queued hit") + } + + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/inspection-health", time.Now().Format("20060102-150405")) + world := newTestServer(t) + var npc *character + for _, actor := range world.characters { + if actor.npc && actor.playfield == 950 && actor.monsterData == 17655 && actor.level == 1 && actor.combatProfile != nil && (npc == nil || actor.id < npc.id) { + npc = actor + } + } + if npc == nil { + t.Fatal("no level-one Leet for inspection reproduction") + } + for index := 0; index < 2; index++ { + player := world.newCharacter() + player.level, player.profession, player.appearance = 10, 9, 0x315 + player.position, player.rotation = npc.position, [4]float32{0, 0, 0, 1} + player.position[2] -= float32(2 + index*3) + player.stats.Body.BodyDevelopment = 55 + player.health = 200 + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint("inspection-", index)))) + if err := world.saveUser_locked(player); 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(map[string]any{"health": world.characters[1].health, "npc": npc.id, + "nextAttack": npc.nextAttack, "rechargeUntil": npc.rechargeUntil, "fighting": npc.fighting}) + }) + // Advance one real swing; no later hits or regeneration obscure inspection. + mux.HandleFunc("POST /test-attack", func(w http.ResponseWriter, r *http.Request) { + world.updateMutex.Lock() + world.mutex.Lock() + updates := make(map[*worldClient][][]byte) + world.startAttack_locked(npc, world.characters[1], time.Now(), updates) + deadline := npc.nextAttack + world.mutex.Unlock() + world.sendCombatUpdates(updates) + world.updateMutex.Unlock() + world.advanceCombat(deadline) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + defer cancel() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_inspection_health.mjs"), host.URL, output) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + err := command.Run() + + if err != nil { + t.Fatal(err) + } + t.Logf("Browser artifacts: %s", output) +} diff --git a/tools/client/test_inspection_health.mjs b/tools/client/test_inspection_health.mjs @@ -0,0 +1,70 @@ +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', + args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', + '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); +const games = [], evidence = {}; +const actor = (game, id) => game.state.actors.find(actor => actor.type === 50000 && actor.id === id); +const pending = (game, id) => actor(game, id)?.weapons.some(weapon => weapon.pending.length); +try { + for (let index = 0; index < 2; index++) { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'inspection-' + index, url}]); + const page = await context.newPage(); + const game = await GameTest.attach(page); + games.push(game); + await page.goto(url); + await game.ready(); + } + const [owner, observer] = games; + const server = async () => (await owner.page.request.get(url + '/test-state')).json(); + const initial = await server(); + await Promise.all(games.map(game => game.wait('both players and Leet', () => + actor(game, 1) && actor(game, 2) && actor(game, initial.npc)))); + const [x, y] = await observer.pick(50000, 1); + await observer.click(x, y); + await observer.wait('owner selected for inspection', state => state.selected[0] === 50000 && state.selected[1] === 1); + + assert((await owner.page.request.post(url + '/test-attack')).ok()); + await Promise.all(games.map(game => game.wait('real result pending before inspection', () => pending(game, initial.npc)))); + evidence.pending = {server: await server(), clients: games.map(game => ({health: actor(game, 1).stats[27], npc: actor(game, initial.npc)}))}; + assert(evidence.pending.server.health > 0 && evidence.pending.server.health < 200); + assert(evidence.pending.clients.every(client => client.health === 200)); + const selfSequence = owner.sequence; + await owner.key('F1'); + await owner.key('t'); + await owner.wait('self inspection leaves the original hit pending', () => + pending(owner, initial.npc) && owner.events.some(event => event.sequence > selfSequence && + event.direction === 'framereceived' && event.opcode === '4d38242e' && event.actor?.[1] === 1)); + evidence.selfInspected = {health: actor(owner, 1).stats[27], npc: actor(owner, initial.npc)}; + assert.equal(evidence.selfInspected.health, 200); + assert.deepEqual(evidence.selfInspected.npc.weapons, evidence.pending.clients[0].npc.weapons); + const sequence = observer.sequence; + await observer.key('t'); + await observer.wait('native InfoPacket while hit remains queued', () => + actor(observer, 1).stats[27] === evidence.pending.server.health && pending(observer, initial.npc) && + observer.events.some(event => event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '4d38242e')); + evidence.inspected = {server: await server(), health: actor(observer, 1).stats[27], npc: actor(observer, initial.npc)}; + assert.deepEqual(evidence.inspected.server, evidence.pending.server); + assert.deepEqual(evidence.inspected.npc.weapons, evidence.pending.clients[1].npc.weapons); + await observer.save(output + '/inspected'); + + await Promise.all(games.map(game => game.wait('original result consumed', () => !pending(game, initial.npc)))); + evidence.after = {server: await server(), clients: games.map(game => ({health: actor(game, 1).stats[27], npc: actor(game, initial.npc)}))}; + assert.deepEqual(evidence.after.server, evidence.pending.server); + assert.equal(evidence.after.clients[0].health, evidence.after.server.health); + assert.equal(evidence.after.clients[1].health, evidence.after.server.health, 'Inspection made the observer debit an already committed hit twice'); + assert(games.every(game => game.errors.length === 0)); + console.log('PASS: real T inspection preserves the queued hit and both clients agree with authoritative HP after impact'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); + await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); + } finally { await browser.close(); } +}