aorecomp

Anarchy Online classic in the browser

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


commit 3a659df90202b6fbc7464b453a70a40fa10b10bc
parent e43454ce11a784276a53275e9057e02fd9303af5
Author: anon <anon@example.com>
Date:   Tue,  3 Nov 2026 14:07:53 +0000

Admit Support Beam qualities with cap-valid native fixtures

Diffstat:
MTODO.md | 13+++++++++++++
Mdocs/katana.md | 10++++++++--
Mdocs/kinetic-axe.md | 9+++++++--
Adocs/support-beam.md | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/browser_katana_test.go | 11++++++++---
Mserver/browser_kinetic_axe_test.go | 11++++++++---
Aserver/browser_support_beam_test.go | 148+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/gamedata/item_families.yaml | 2++
Mserver/gamedata/item_quality_test.go | 1+
Aserver/support_beam_quality_test.go | 312+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtools/client/test_katana.mjs | 6+++---
Mtools/client/test_kinetic_axe.mjs | 6+++---
Atools/client/test_support_beam.mjs | 157+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13 files changed, 756 insertions(+), 16 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -406,6 +406,12 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). sale and cold ownership. Two controlled WASM clients verify QL2/12/13 wear, QL14 refusal, one 13-point hit, the exact sale and page/fresh-server retention. Acquisition remains open; see [Kinetic Axe contracts](docs/kinetic-axe.md). + The reviewed Dull Support Beam pair now admits QL1..20, fixing qualified QL2 + Atrox wear refusal. Complete original contracts, selected values, Duck defense, + strict breed/skill gates, pickup, sale and cold ownership pass focused checks. + Two native clients verify Atrox wear, Solitus refusal, one hit and retained + identities through page/fresh-server recovery; see + [Support Beam contracts](docs/support-beam.md). The reviewed Original Electronicum pair now admits QL1..98 through shared quality and modifier consumers, fixing qualified QL2 rejection. Focused public-handler checks cover Pistol gates, selected damage/timing/value, @@ -415,6 +421,13 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). retention of the five exact identities and their ammunition. Historical acquisition and later tiers remain open; see [Electronicum contracts](docs/electronicum.md). +- [x] [P0] Keep selected-quality weapon browser fixtures within native training + caps. Katana and Kinetic Axe's abilities 20 limited their raw weapon skill to 39, + below the seeded 56/52. All three fixtures now check actual raw fields against + native caps and use abilities 28 while preserving their effective skills. + Three two-client warm/cold runs retain wear/refusal, damage, exact sale and + item ownership, with 34 clean traces. See + [native fixture caps](docs/support-beam.md#native-fixture-caps). - [x] Admit the complete Low-Tech armor set through shared quality and shop data. Eight explicit original pairs cover QL1..200, including alternate body and leg styles and independent sleeves. All three basic armor factions offer the diff --git a/docs/katana.md b/docs/katana.md @@ -55,7 +55,7 @@ accepted/repeated sale. Final fixture wallets are 169/256 credits, including the pre-existing one corpse credit. This does not establish historical drops. `TestBrowserKatanaQualities` uses two controlled WASM clients. The owner has -abilities20, raw 2h Edged56/Brawling33/Dimach12, producing effective 60/37/16. +abilities 28, raw 2h Edged 54/Brawling 31/Dimach 10, producing effective 60/37/16. Its level100 checkpoint supplies survival time for the isolated encounter; it is not earned progression. A nearby original full-health Leet is held in place while equipment and combat run normally. Native input wears/removes @@ -67,7 +67,7 @@ instance on cancellation and credit exactly 168 on acceptance. Page replay and a fresh server/two-client startup must retain the other three exact identities, their qualities/slots and the wallet, with no observer item or cash leak. -The final native run passes in 88.75 seconds (warm 51.59, cold 37.15), or 96.430 +The original native run passes in 88.75 seconds (warm 51.59, cold 37.15), or 96.430 seconds including Go. Its independent verifier checks both original payload hashes, the selected wear phases, the single native attack result, five sale requests and exact page/cold ledgers. All 11 retained traces have empty error @@ -78,6 +78,12 @@ would occupy its usual position while the weapon panel was open. Checking the actual unlimited attack result and closing that panel resolved those fixture assumptions; neither required a server or client change. +The original fixture used abilities 20 and raw 2h Edged 56, above its raw cap 39. +The current fixture enforces raw caps and retains the same effective skills; +see [native fixture caps](support-beam.md#native-fixture-caps) for the corrected +profiles and new native verification. The older captures establish controlled +protocol behavior, without proving that their raw skill profile was trainable. + The related Go selection passes 20 top-level tests and 493 individual results: 126.834s for server and 7.660s for gamedata. Two opt-in browser checks are skipped there; the Katana native run above executes its full check separately. This diff --git a/docs/kinetic-axe.md b/docs/kinetic-axe.md @@ -48,7 +48,7 @@ Shared family tests reject qualities outside 1..24; the existing Fast Attack unsupported-quality case now uses 25 instead of the newly admitted 2. `TestBrowserKineticAxeQualities` uses two controlled WASM clients. Level 100, -abilities 20 and raw 1h Edged 52/Brawling 31/Fast Attack 25 give effective +abilities 28 and raw 1h Edged 50/Brawling 29/Fast Attack 23 give effective 56/35/29. Real input wears/removes QL2/12 and wears QL13, while QL14 is refused. A controlled minimum noncritical roll against an unchanged full-health Leet deals 13 damage, with result ammo -1. Both clients observe 87 HP. A cancelled sale @@ -57,12 +57,17 @@ recovery retain item 2 (QL12/slot65), item 3 (QL13/slot6), item 4 (QL14/slot67) and that wallet. The observer acquires no items or credits. -The native baseline reproduces the actual QL2 request and refusal. The accepted +The native baseline reproduces the actual QL2 request and refusal. The original run passes in 76.46 seconds, including fresh-server recovery; all 11 traces have empty error lists and zero dropped events. The independent verifier checks original hashes, the baseline, observer properties, the one unlimited-ammo hit and exact final ownership. Captures and results are under `local/kinetic-axe/`. +That original fixture used abilities 20 and raw 1h Edged 52, above its raw cap 39. +The current fixture validates raw caps while retaining the same effective skills; +see [native fixture caps](support-beam.md#native-fixture-caps). Earlier captures +prove their controlled item/protocol behavior, not a trainable raw profile. + The focused Go selection passes 30 roots and 313 results across server and game data packages. Race checks pass four roots and 93 results in 107.840 seconds. Existing authored-weight, initiative and weapon-admission checks also pass. diff --git a/docs/support-beam.md b/docs/support-beam.md @@ -0,0 +1,86 @@ +# Dull Support Beam selected qualities + +The reviewed 122905/122906 pair admits QL1..20 through the shared quality table. +Before that row, a qualified Atrox's QL2 wear request was refused. No +weapon-specific gameplay handler is added. + +The complete original resource payloads independently reparse to the maintained +records in `server/gamedata/items/items_039.yaml`. Their SHA256 hashes are: + +- 122905: `e0ccd34fb386b6419d38e2b2bf6e0df5bf012057bccba731d5d5f4a77fc143c5`. +- 122906: `84965678cf6316999fa74f703b2a2d865506151c9ea5319b56b32771b7cea538`. + +All headers, text, sections, weights, function 53076 presentation and requirement +operators agree. Only quality, damage, value and three strict skill thresholds +vary. The complete action 8 predicate requires Breed 4 (Atrox) at both endpoints. +Attack uses 2h Blunt (107) and defense uses Duck (153), independently of Evade +Close (155). + +| QL | Damage | Critical bonus | Minimum 2h Blunt/Brawling/Dimach | Value | +| --- | --- | --- | --- | --- | +| 1 | 6-25 | 15 | 6/6/6 | 3170 | +| 2 | 6-27 | 18 | 11/9/7 | 3186 | +| 10 | 7-47 | 38 | 51/33/15 | 4521 | +| 11 | 8-50 | 40 | 57/36/16 | 4838 | +| 19 | 9-70 | 60 | 97/60/24 | 8575 | +| 20 | 9-72 | 63 | 102/63/25 | 9193 | + +Attack/recharge stay 350/250 cs, equip 450 cs, range 3 m, Melee damage (91), Melee +Initiative (118) and unlimited ammunition. Model 30235 and icon 33143 are unchanged. +Original bytes, the resource index digest, complete reparse and independent +integer arithmetic are retained under `local/support-beam/original/`. + +The local Fandom dump has no exact name/122905 match. An +[indexed 2002 player report](https://arstechnica.com/civis/threads/perpetual-how-i-did-on-rubi-ka-2-last-night-thread-ars-org.822102/?thutp_user_id=7337) +describes a QL4 reward from a Rome mission terminal. Direct fetching returned 403; +this is a membership lead, not a recovered distribution. Production acquisition +selections are unchanged. + +## Verification + +Public-handler regressions check both anchors at QL1/2/10/11/19/20, the Atrox +gate, independent strict skill boundaries, equip deadline, native endpoint +delivery, damage/value, unlimited ammunition and cold ownership. Controlled +opposite Duck/Evade foundations verify selection of the original defense stat +through actual hit/miss outcomes under the existing provisional chance policy. +Generated pickup tracks the same instance through refusal, repeated wear/removal, +cancelled/accepted sale and cold load. The hit/critical-selection policies remain +as documented in [critical hits](critical-hits.md). + +The two-client native fixture uses an Atrox and Solitus with the same effective +2h Blunt 57/Brawling 36/Dimach 16. Solitus QL2 wear is refused before a server move; +Atrox wears/removes QL2/10, wears QL11 and refuses QL12. A controlled minimum +noncritical hit against an unchanged full-health Leet deals 9 Melee damage, with +native result ammunition -1. Cancellation retains the QL2 instance; acceptance +pays 159 credits. Page and fresh-server recovery retain owner items 2/3/4 at +QL10/11/12, slots 65/6/67 and wallet 159, plus the Solitus's separate item 5/QL2/slot64 +and zero wallet. These are controlled fixtures, not earned progression. + +## Native fixture caps + +The selected-quality Katana and Kinetic Axe fixtures previously used abilities 20 +with raw weapon skills 56/52. The native training bound includes an ability-based +limit: `trunc(weighted_ability * 0.01f * 0.25 * 8)`. At 20 it is 39, independently +of the level 100 title cap. New assertions reproduce those fixture errors before +opening browsers. All three fixtures now use abilities 28 and validate their +actual raw fields against `trainingMaximum` before casting or equipping. + +| Fixture | Raw skills | Effective skills | Ability-based raw ceiling | +| --- | --- | --- | --- | +| Katana: 2h Edged/Brawling/Dimach | 54/31/10 | 60/37/16 | 55 | +| Kinetic Axe: 1h Edged/Brawling/Fast Attack | 50/29/23 | 56/35/29 | 55 | +| Support Beam: 2h Blunt/Brawling/Dimach | 51/30/10 | 57/36/16 | 55 | + +The effective wear boundaries, damage and sale checks stay the same. Earlier +captures establish their controlled item/protocol observations; they do not +establish trainability of the over-cap raw fixtures. Corrected native captures +and the focused failure baseline are retained under `local/support-beam/`, +with each family's new native run in its own capture directory. + +The corrected Katana run `local/katana-quality/20261103-055741` passes in 83.71s; +Kinetic Axe `local/kinetic-axe/20261103-055905` in 78.82s; Support Beam +`local/support-beam/20261103-060024` in 108.27s. All 34 traces have empty error lists +and zero dropped events. The independent verifier checks both raw profiles, +baseline failure, original hashes, selected observer properties and all final +ledgers. The focused Go selection passes 33 roots/519 results; race passes four +roots/82 results in 107.075s. Vet and all three Node syntax checks pass. diff --git a/server/browser_katana_test.go b/server/browser_katana_test.go @@ -42,9 +42,14 @@ func TestBrowserKatanaQualities(t *testing.T) { player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint("katana-", index)))) if index == 0 { player.level = 100 - player.stats.Abilities = characterAbilitiesStats{20, 20, 20, 20, 20, 20} - player.stats.Melee.TwoHandEdged = 56 - player.stats.Body.Brawling, player.stats.Body.Dimach = 33, 12 + player.stats.Abilities = characterAbilitiesStats{28, 28, 28, 28, 28, 28} + player.stats.Melee.TwoHandEdged = 54 + player.stats.Body.Brawling, player.stats.Body.Dimach = 31, 10 + for stat, raw := range map[uint32]uint16{105: player.stats.Melee.TwoHandEdged, 142: player.stats.Body.Brawling, 144: player.stats.Body.Dimach} { + if uint32(raw) > player.trainingMaximum(stat) { + t.Fatal("controlled raw skill exceeds its native cap", stat, raw, player.trainingMaximum(stat)) + } + } for stat, expected := range map[uint32]int32{105: 60, 142: 37, 144: 16} { if actual, _ := player.effectiveStat(stat); actual != expected { t.Fatal("controlled effective skill differs", stat, actual) diff --git a/server/browser_kinetic_axe_test.go b/server/browser_kinetic_axe_test.go @@ -42,9 +42,14 @@ func TestBrowserKineticAxeQualities(t *testing.T) { player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint("kinetic-axe-", index)))) if index == 0 { player.level = 100 - player.stats.Abilities = characterAbilitiesStats{20, 20, 20, 20, 20, 20} - player.stats.Melee.OneHandEdged = 52 - player.stats.Body.Brawling, player.stats.Melee.FastAttack = 31, 25 + player.stats.Abilities = characterAbilitiesStats{28, 28, 28, 28, 28, 28} + player.stats.Melee.OneHandEdged = 50 + player.stats.Body.Brawling, player.stats.Melee.FastAttack = 29, 23 + for stat, raw := range map[uint32]uint16{103: player.stats.Melee.OneHandEdged, 142: player.stats.Body.Brawling, 147: player.stats.Melee.FastAttack} { + if uint32(raw) > player.trainingMaximum(stat) { + t.Fatal("controlled raw skill exceeds its native cap", stat, raw, player.trainingMaximum(stat)) + } + } for stat, expected := range map[uint32]int32{103: 56, 142: 35, 147: 29} { if actual, _ := player.effectiveStat(stat); actual != expected { t.Fatal("controlled effective skill differs", stat, actual) diff --git a/server/browser_support_beam_test.go b/server/browser_support_beam_test.go @@ -0,0 +1,148 @@ +package main + +import ( + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "runtime" + "slices" + "testing" + "time" +) + +func TestBrowserSupportBeamQualities(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the focused native SupportBeam check") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/support-beam", 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) + var target *character + for _, actor := range world.characters { + if actor.npc && actor.playfield == 950 && actor.monsterData == 17655 && actor.level == 1 && actor.combatProfile != nil && (target == nil || actor.id < target.id) { + target = actor + } + } + if phase == "warm" { + for index := 0; index < 2; index++ { + player := world.newCharacter() + player.name, player.appearance = fmt.Sprint("SupportBeam", index), 0x515 + player.position = [3]float32{60 - float32(index)*3, 14.75, 53} + player.rotation = [4]float32{0, 1, 0, 0} + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint("support-beam-", index)))) + if index == 0 { + player.appearance = 0x545 + } + player.level = 100 + player.stats.Abilities = characterAbilitiesStats{28, 28, 28, 28, 28, 28} + player.stats.Melee.TwoHandBlunt = 51 + player.stats.Body.Brawling, player.stats.Body.Dimach = 30, 10 + for stat, raw := range map[uint32]uint16{107: player.stats.Melee.TwoHandBlunt, 142: player.stats.Body.Brawling, 144: player.stats.Body.Dimach} { + if uint32(raw) > player.trainingMaximum(stat) { + t.Fatal("controlled raw skill exceeds its cap", stat, raw, player.trainingMaximum(stat)) + } + } + for stat, expected := range map[uint32]int32{107: 57, 142: 36, 144: 16} { + if actual, _ := player.effectiveStat(stat); actual != expected { + t.Fatal("controlled effective skill differs", stat, actual) + } + } + player.health, player.nano = player.maximumHealth(), player.maximumNano() + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + } + // Controlled contracts and a nearby original Leet isolate the weapon check. + for _, item := range []struct{ template, quality uint32 }{ + {122905, 2}, {122906, 10}, {122906, 11}, {122905, 12}, + } { + if granted, err := world.grantItem_locked(world.characters[1], item.template); err != nil || !granted { + t.Fatal(granted, err) + } + world.characters[1].inventory.Items[len(world.characters[1].inventory.Items)-1].Quality = item.quality + } + if err := world.saveInventory_locked(world.characters[1], world.characters[1].inventory); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(world.characters[2], 122905); err != nil || !granted { + t.Fatal(granted, err) + } + world.characters[2].inventory.Items[0].Quality = 2 + if err := world.saveInventory_locked(world.characters[2], world.characters[2].inventory); err != nil { + t.Fatal(err) + } + target.position, target.motion.home = [3]float32{61, 14.75, 51.5}, [3]float32{61, 14.75, 51.5} + world.combatRoll = func(limit uint32) uint32 { + if limit == 100 { + return 99 + } + return 0 + } + } + owner, watcher := world.characters[1], world.characters[2] + 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{"inventory": owner.inventory, "observer": watcher.inventory, + "target": target.id, "health": target.health, "fighting": owner.fighting, "ownerHealth": owner.health}) + }) + host := httptest.NewServer(mux) + t.Cleanup(host.Close) + closeTestBrowserStreams(t, world) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + defer cancel() + stopped := make(chan struct{}) + go func() { + defer close(stopped) + ticker := time.NewTicker(20 * time.Millisecond) + defer ticker.Stop() + for { + select { + case now := <-ticker.C: + world.advanceEquipment(now) + world.advanceCombat(now) + case <-ctx.Done(): + return + } + } + }() + defer func() { cancel(); <-stopped }() + + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_support_beam.mjs"), host.URL, filepath.Join(output, phase)) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + err := command.Run() + cancel() + <-stopped + t.Logf("Browser artifacts: %s", output) + + if err != nil { + t.Fatal(err) + } + expected := []ownedItem{ + {ID: 2, Type: 51018, Template: 122906, Quality: 10, Slot: 65, Count: 1}, + {ID: 3, Type: 51018, Template: 122906, Quality: 11, Slot: 6, Count: 1}, + {ID: 4, Type: 51018, Template: 122905, Quality: 12, Slot: 67, Count: 1}, + } + if !slices.Equal(owner.inventory.Items, expected) || owner.inventory.Credits != 159 || owner.health == 0 || + !slices.Equal(watcher.inventory.Items, []ownedItem{{ID: 5, Type: 51018, Template: 122905, Quality: 2, Slot: 64, Count: 1}}) || + watcher.inventory.Credits != 0 || world.nextItem != 5 { + t.Fatal("native wear, sale or cold recovery lost an instance or cash", owner.inventory) + } + }) + if t.Failed() { + return + } + } +} diff --git a/server/gamedata/item_families.yaml b/server/gamedata/item_families.yaml @@ -26,6 +26,8 @@ - [122691, 122692] # Kinetic Axe: original descriptor audit; docs/kinetic-axe.md. - [209283, 209284] +# Dull Support Beam: original descriptor audit; docs/support-beam.md. +- [122905, 122906] # Katana: original descriptor audits; docs/katana.md. - [121969, 121970] - [121971, 121972] diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go @@ -17,6 +17,7 @@ func TestReviewedItemFamilyQualityRanges(t *testing.T) { {123748, 123749, 38, 119}, {121969, 121970, 1, 20}, {121971, 121972, 21, 40}, {121973, 121974, 41, 60}, {209283, 209284, 1, 24}, + {122905, 122906, 1, 20}, {160288, 160289, 1, 98}, {124256, 124257, 1, 4}, {124258, 124259, 5, 69}, {124260, 124261, 70, 179}, {70558, 85640, 1, 200}, {70559, 85689, 1, 200}, {70560, 85688, 1, 200}, {70561, 85744, 1, 200}, diff --git a/server/support_beam_quality_test.go b/server/support_beam_quality_test.go @@ -0,0 +1,312 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "fmt" + "slices" + "testing" + "time" +) + +func TestSupportBeamQualitiesEnforceWearBoundariesAndRecover(t *testing.T) { + for _, template := range []uint32{122905, 122906} { + for _, row := range []struct { + quality, minimum, maximum, critical, value uint32 + blunt, brawling, dimach uint16 + }{ + {1, 6, 25, 15, 3170, 6, 6, 6}, + {2, 6, 27, 18, 3186, 11, 9, 7}, + {10, 7, 47, 38, 4521, 51, 33, 15}, + {11, 8, 50, 40, 4838, 57, 36, 16}, + {19, 9, 70, 60, 8575, 97, 60, 24}, + {20, 9, 72, 63, 9193, 102, 63, 25}, + } { + for _, failed := range []uint32{0, 4, 107, 142, 144} { + t.Run(fmt.Sprintf("%d/QL%d/below%d", template, row.quality, failed), func(t *testing.T) { + world, output := newEquipmentWorld(t) + player, client := world.characters[1], world.clients[1] + player.appearance = 0x545 + player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Melee.TwoHandBlunt = row.blunt + player.stats.Body.Brawling, player.stats.Body.Dimach = row.brawling, row.dimach + switch failed { + case 4: + player.appearance = 0x515 + case 107: + player.stats.Melee.TwoHandBlunt-- + case 142: + player.stats.Body.Brawling-- + case 144: + player.stats.Body.Dimach-- + } + player.inventory.Items[0].Template, player.inventory.Items[0].Quality = template, row.quality + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + + started := time.Now() + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil { + t.Fatal(err) + } + if client.equipment != nil { + finish := client.equipment.readyAt + if finish.Before(started.Add(4500*time.Millisecond)) || finish.After(time.Now().Add(4500*time.Millisecond)) { + t.Fatal("SupportBeam did not retain its original equip delay") + } + world.advanceEquipment(finish.Add(-time.Nanosecond)) + if player.inventory.Items[0].Slot != 64 { + t.Fatal("weapon moved before its equip deadline") + } + world.advanceEquipment(finish) + } + cold := newTestInventoryServer(t).characters[1] + + expected := ownedItem{ID: 1, Type: 51018, Template: template, Quality: row.quality, Slot: 64, Count: 1} + if failed == 0 { + expected.Slot = 6 + } + if !slices.Equal(player.inventory.Items, []ownedItem{expected}) || !slices.Equal(cold.inventory.Items, []ownedItem{expected}) { + t.Fatal("wear boundary lost the selected instance or placement", player.inventory.Items, cold.inventory.Items) + } + if failed != 0 { + return + } + weapon := cold.attackWeapon() + if weapon == nil || itemStat(weapon, 286) != row.minimum || itemStat(weapon, 285) != row.maximum || itemStat(weapon, 284) != row.critical || + itemStat(weapon, 294) != 350 || itemStat(weapon, 210) != 250 || itemStat(weapon, 211) != 450 || itemStat(weapon, 287) != 3 || + itemStat(weapon, 440) != 118 || expected.usesAmmo() || expected.shopPrice() != row.value { + t.Fatal("selected quality lost damage, timing, ammo, range, damage type or value", weapon) + } + low, high := uint32(122905), uint32(122906) + if row.quality == 1 { + high = low + } else if row.quality == 20 { + low = high + } + var delivered []byte + for _, packet := range output.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x3b1d2268 { + delivered = packet + } + } + if len(delivered) < 91 || binary.BigEndian.Uint32(delivered[71:75]) != row.quality || + binary.BigEndian.Uint32(delivered[79:83]) != low || binary.BigEndian.Uint32(delivered[87:91]) != high { + t.Fatal("native weapon delivery lost the selected endpoints") + } + }) + } + } + } +} + +func TestSupportBeamSelectedDamageAndTimingWithoutAmmunition(t *testing.T) { + for _, row := range []struct{ quality, normal, critical uint32 }{ + {1, 50, 80}, {2, 54, 90}, {10, 94, 170}, {11, 100, 180}, {19, 140, 260}, {20, 144, 270}, + } { + for _, critical := range []bool{false, true} { + t.Run(fmt.Sprintf("QL%d/critical%v", row.quality, critical), func(t *testing.T) { + world, output := newRangedWorld(t) + player, target := world.characters[1], world.characters[1000000] + player.appearance = 0x545 + target.position = [3]float32{1, 0, 0} + player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Melee.TwoHandBlunt = 400 + player.stats.Body.Brawling, player.stats.Body.Dimach = 100, 100 + player.stats.Speed.MeleeInitiative, player.aggDef = 0, 75 + player.inventory.Items[0].Template, player.inventory.Items[0].Quality, player.inventory.Items[0].Ammo = 122905, row.quality, 0 + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + world.combatRoll = func(limit uint32) uint32 { + if limit == 10000 || limit == 100 && critical { + return 0 + } + return limit - 1 + } + + if err := world.handleCombat(world.clients[1], attackPacket(1, target.id)[20:]); err != nil { + t.Fatal(err) + } + hit := player.nextAttack + world.advanceCombat(hit) + cold := newTestInventoryServer(t) + + damage := row.normal + if critical { + damage = row.critical + } + if target.health != 1000-damage || player.rechargeUntil.Sub(hit) != 2500*time.Millisecond || player.nextAttack.Sub(hit) != 6000*time.Millisecond || + player.inventory.Items[0].Ammo != 0 || cold.characters[1].inventory.Items[0].Ammo != 0 || player.inventory.Items[1].Count != 100 { + t.Fatal("selected SupportBeam damage, cadence or ammunition differs", target.health, player.inventory) + } + found := false + for _, packet := range output.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x46002f16 && binary.BigEndian.Uint32(packet[24:28]) == player.id { + found = binary.BigEndian.Uint32(packet[33:37]) == 0xffffffff + } + } + if !found { + t.Fatal("melee result lost its unlimited-ammunition sentinel") + } + }) + } + } +} + +func TestSupportBeamUsesDuckInsteadOfEvadeClose(t *testing.T) { + for _, duck := range []uint16{0, 10000} { + t.Run(fmt.Sprint(duck), func(t *testing.T) { + world, output := newRangedWorld(t) + player, target := world.characters[1], world.characters[1000000] + player.appearance = 0x545 + player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Melee.TwoHandBlunt = 400 + player.stats.Body.Brawling, player.stats.Body.Dimach = 100, 100 + player.inventory.Items[0].Template, player.inventory.Items[0].Quality, player.inventory.Items[0].Ammo = 122905, 2, 0 + target.position, target.stats.Speed.DuckExplosions, target.stats.Speed.EvadeClose = [3]float32{1, 0, 0}, duck, 10000-duck + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + world.combatRoll = func(limit uint32) uint32 { + if limit == 10000 { + return 5000 + } + return limit - 1 + } + + if err := world.handleCombat(world.clients[1], attackPacket(1, target.id)[20:]); err != nil { + t.Fatal(err) + } + world.advanceCombat(player.nextAttack) + + health, opcode := uint32(946), uint32(0x46002f16) + if duck != 0 { + health, opcode = 1000, 0x5c654b28 + } + if target.health != health || !slices.ContainsFunc(output.packets, func(packet []byte) bool { + return binary.BigEndian.Uint32(packet[16:20]) == opcode && binary.BigEndian.Uint32(packet[24:28]) == player.id + }) { + t.Fatal("Support Beam used the wrong defense skill", target.health) + } + }) + } +} + +func TestSupportBeamGeneratedPickupEquipRemoveAndSale(t *testing.T) { + for _, scenario := range []struct { + template, quality uint32 + blunt, brawling, dimach uint16 + credits uint32 + }{ + {122905, 2, 11, 9, 7, 160}, {122906, 2, 11, 9, 7, 160}, + {122905, 11, 57, 36, 16, 242}, {122906, 11, 57, 36, 16, 242}, + } { + t.Run(fmt.Sprintf("%d/QL%d", scenario.template, scenario.quality), func(t *testing.T) { + world, _ := newKillExperienceWorld(t, "unarmed") + // Controlled membership tests delivery, not historical Leet equipment drops. + profile := *world.characters[1000000].combatProfile + profile.Loot = []gamedata.NPCLoot{{Template: scenario.template, Quality: [2]uint32{scenario.quality, scenario.quality}, Chance: 100}} + world.characters[1000000].combatProfile = &profile + world.combatRoll = func(uint32) uint32 { return 0 } + identity := world.nextItem + 1 + + attackForExperience(t, world, "unarmed") + if err := world.handleLootUse(world.clients[1], lootUseRequest(1)); err != nil { + t.Fatal(err) + } + for range 2 { + if err := world.handleInventory(world.clients[1], lootTakeRequest()); err != nil { + t.Fatal(err) + } + } + world = newTestInventoryServer(t) + player := world.characters[1] + player.appearance = 0x545 + client := &worldClient{id: 1, conn: &combatTestConn{}, target: true, ready: true} + world.clients[1] = client + player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Melee.TwoHandBlunt = scenario.blunt - 1 + player.stats.Body.Brawling, player.stats.Body.Dimach = scenario.brawling, scenario.dimach + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment != nil || + len(player.inventory.Items) != 1 || player.inventory.Items[0].ID != identity || player.inventory.Items[0].Slot != 64 { + t.Fatal("rejected wear lost the picked-up instance", err) + } + player.stats.Melee.TwoHandBlunt++ + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + for _, move := range [][2]uint32{{64, 6}, {6, 64}, {64, 6}, {6, 64}} { + request := inventoryMovePacket(1, move[0], move[1]) + if move[0] < 64 { + request = itemMovePacket(1, move[0], move[1]) + } + if err := world.handleInventory(client, request[20:]); err != nil || client.equipment == nil { + t.Fatal("generated selected-quality weapon did not move", err) + } + world.advanceEquipment(client.equipment.readyAt) + cold := newTestInventoryServer(t) + expected := []ownedItem{{ID: identity, Type: 51018, Template: scenario.template, Quality: scenario.quality, Slot: move[1], Count: 1}} + if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) || + len(cold.characters[1000000].corpse.items) != 0 || cold.characters[1].inventory.Credits != 1 || cold.nextItem != identity { + t.Fatal("pickup, repeated wear or cold recovery lost or duplicated the weapon") + } + } + + // Sell that same instance after cancellation and a cold reconnect. + player.appearance = 0x545 + player.position = [3]float32{60, 14.75, 53} + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.savePosition_locked(player); err != nil { + t.Fatal(err) + } + if err := world.handleShopUse(client, shopUseRequest(1)); err != nil { + t.Fatal(err) + } + add := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{50000, 1}, [2]uint32{104, 64})[20:] + if err := world.handleTrade(client, add); err != nil { + t.Fatal(err) + } + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 2, [2]uint32{}, [2]uint32{})[20:]); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + if len(cold.characters[1].inventory.Items) != 1 || cold.characters[1].inventory.Credits != 1 { + t.Fatal("cancelled sale lost the selected-quality weapon") + } + world, player = cold, cold.characters[1] + client = &worldClient{id: 1, conn: &combatTestConn{}, target: true, ready: true} + world.clients[1] = client + if err := world.handleShopUse(client, shopUseRequest(1)); err != nil { + t.Fatal(err) + } + if err := world.handleTrade(client, add); err != nil { + t.Fatal(err) + } + for range 2 { + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]); err != nil { + t.Fatal(err) + } + } + cold = newTestInventoryServer(t) + + for _, current := range []*server{world, cold} { + if len(current.characters[1].inventory.Items) != 0 || current.characters[1].inventory.Credits != scenario.credits || + current.characters[1].experience != 100 || current.nextItem != identity { + t.Fatal("selected-quality sale lost or repeated value, rewards or an instance", current.characters[1].inventory) + } + if _, exists := current.items[identity]; exists { + t.Fatal("sold weapon returned in the shared cache") + } + } + }) + } +} diff --git a/tools/client/test_katana.mjs b/tools/client/test_katana.mjs @@ -29,9 +29,9 @@ try { const state = async () => (await owner.page.request.get(url + '/test-state')).json(); evidence.initial = await state(); if (evidence.initial.inventory.Items.length === 4) { - assert.equal(owner.local().stats[105], 56); - assert.equal(owner.local().stats[142], 33); - assert.equal(owner.local().stats[144], 12); + assert.equal(owner.local().stats[105], 54); + assert.equal(owner.local().stats[142], 31); + assert.equal(owner.local().stats[144], 10); await owner.key('KeyI'); await owner.page.keyboard.press('Control+1'); for (const id of [1, 2, 3]) { diff --git a/tools/client/test_kinetic_axe.mjs b/tools/client/test_kinetic_axe.mjs @@ -29,9 +29,9 @@ try { const state = async () => (await owner.page.request.get(url + '/test-state')).json(); evidence.initial = await state(); if (evidence.initial.inventory.Items.length === 4) { - assert.equal(owner.local().stats[103], 52); - assert.equal(owner.local().stats[142], 31); - assert.equal(owner.local().stats[147], 25); + assert.equal(owner.local().stats[103], 50); + assert.equal(owner.local().stats[142], 29); + assert.equal(owner.local().stats[147], 23); await owner.key('KeyI'); await owner.page.keyboard.press('Control+1'); for (const id of [1, 2, 3]) { diff --git a/tools/client/test_support_beam.mjs b/tools/client/test_support_beam.mjs @@ -0,0 +1,157 @@ +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 games = [], evidence = {}; +async function bagClick(game, id) { + await game.wait('native equipment action finishes', state => + !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); + const cell = game.local().inventory.find(item => item.id === id).slot - 48; + assert(cell >= 0 && cell < 9); + await game.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54, 'right'); +} +try { + for (const index of [0, 1]) { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'support-beam-' + index, url}]); + const page = await context.newPage(), game = await GameTest.attach(page); + games.push(game); + await page.goto(url); + await game.ready(); + } + const [owner, observer] = games; + const state = async () => (await owner.page.request.get(url + '/test-state')).json(); + evidence.initial = await state(); + if (evidence.initial.inventory.Items.length === 4) { + assert.equal(owner.local().stats[4], 4); + assert.equal(observer.local().stats[4], 1); + assert.equal(observer.local().stats[107], 51); + assert.equal(observer.local().stats[142], 30); + assert.equal(observer.local().stats[144], 10); + await observer.key('KeyI'); + const rejectedBreed = observer.sequence; + await bagClick(observer, 5); + await observer.save(output + '/solitus-refusal'); + assert(!observer.events.some(event => event.sequence > rejectedBreed && + event.direction === 'framesent' && event.opcode === '47537a24')); + assert.deepEqual((await state()).observer, evidence.initial.observer); + assert.equal(owner.local().stats[107], 51); + assert.equal(owner.local().stats[142], 30); + assert.equal(owner.local().stats[144], 10); + await owner.key('KeyI'); + await owner.page.keyboard.press('Control+1'); + for (const id of [1, 2, 3]) { + const sequence = observer.sequence; + await bagClick(owner, id); + await owner.wait('selected Support Beam worn', snapshot => owner.local(snapshot).inventory.some(item => item.id === id && item.slot === 6)); + await observer.wait('observer receives selected Support Beam', () => observer.events.some(event => + event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '3b1d2268' && + event.actor[0] === 51018 && event.actor[1] === id)); + const event = observer.events.find(event => event.sequence > sequence && event.direction === 'framereceived' && + event.opcode === '3b1d2268' && event.actor[0] === 51018 && event.actor[1] === id); + const packet = Buffer.from(event.hex, 'hex'), stats = new Map(); + for (let offset = 59; offset < packet.readUInt16BE(6) - 4; offset += 8) + stats.set(packet.readUInt32BE(offset), packet.readUInt32BE(offset + 4)); + const [quality, definition, minimum, maximum, critical, value] = { + 1: [2, 122905, 6, 27, 18, 3186], 2: [10, 122905, 7, 47, 38, 4521], + 3: [11, 122906, 8, 50, 40, 4838], + }[id]; + assert.equal(stats.get(23), definition); + const base = { + 122905: {74: 3170, 284: 15, 285: 25, 286: 6}, + 122906: {74: 9193, 284: 63, 285: 72, 286: 9}, + }[definition]; + for (const [stat, expected] of Object.entries({74: value, 284: critical, 285: maximum, 286: minimum, + 701: quality, 702: 122905, 703: 122906})) + assert.equal(stats.get(Number(stat)) ?? base[stat], expected, 'selected native Support Beam stat ' + stat); + evidence['worn' + id] = {native: owner.local().inventory, server: await state()}; + await owner.save(output + '/worn-' + id); + if (id !== 3) { + await owner.click(867, 206, 'right'); + await owner.wait('same Support Beam removed', snapshot => owner.local(snapshot).inventory.some(item => item.id === id && item.slot >= 48)); + } + } + const rejected = await state(), rejectionSequence = owner.sequence; + await bagClick(owner, 4); + await owner.save(output + '/rejected-12'); + assert(!owner.events.some(event => event.sequence > rejectionSequence && event.direction === 'framesent' && event.opcode === '47537a24')); + assert.deepEqual((await state()).inventory, rejected.inventory); + + // An ordinary Q attack uses the selected QL11 damage and consumes no ammunition. + const deadline = Date.now() + 10000; + while (owner.state.selected[0] !== 50000 || owner.state.selected[1] !== rejected.target) { + assert(Date.now() < deadline, 'Native Tab did not select the controlled Leet'); + const selected = owner.state.selected; + await owner.key('Tab'); + await owner.wait('native target cycle advances', snapshot => snapshot.selected[0] !== selected[0] || snapshot.selected[1] !== selected[1]); + } + const attack = owner.sequence; + await owner.key('KeyQ'); + await owner.wait('ordinary selected-quality hit', () => owner.events.some(event => event.sequence > attack && + event.direction === 'framereceived' && event.opcode === '46002f16' && event.actor[1] === owner.local().id)); + const result = owner.events.find(event => event.sequence > attack && event.direction === 'framereceived' && + event.opcode === '46002f16' && event.actor[1] === owner.local().id); + assert.equal(Buffer.from(result.hex, 'hex').readUInt32BE(33), 0xffffffff); + await owner.key('KeyQ'); + await Promise.all(games.map(game => game.wait('native selected-quality impact', snapshot => + snapshot.actors.some(actor => actor.id === rejected.target && actor.stats[27] === 91)))); + evidence.hit = await state(); + assert.equal(evidence.hit.health, 91); + assert.equal(evidence.hit.fighting, 0); + assert.equal(evidence.hit.inventory.Items[2].Ammo, 0); + await owner.save(output + '/hit'); + + // Cancel, then accept the QL2 instance's sale at the original training machine. + await owner.page.keyboard.press('Control+1'); + await owner.wait('weapon panel closed', snapshot => !snapshot.regions.some(([left, top, right, bottom]) => + left === 832 && top === 0 && right === 1024 && bottom === 360)); + if (!owner.state.camera.firstPerson) await owner.key('F8'); + const offered = await state(); + for (let attempt = 0; attempt < 2; ++attempt) { + await owner.click(...await owner.pick(51035, 3221226422), 'right'); + await owner.wait('training machine open', snapshot => snapshot.regions.some(([left, top, right, bottom]) => + left === 832 && top === 0 && right === 1024 && bottom === 494)); + const cell = owner.local().inventory.find(item => item.id === 1).slot - 48; + await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54); + const sequence = owner.sequence; + await owner.click(864, 416); + await owner.wait('sale offered', () => owner.events.some(event => event.sequence > sequence && + event.direction === 'framesent' && event.opcode === '36284f6e')); + assert.deepEqual((await state()).inventory, offered.inventory); + await owner.save(output + '/sale-offer-' + attempt); + if (attempt === 0) { + await owner.click(945, 475); + await owner.wait('cancelled Support Beam restored', snapshot => owner.local(snapshot).inventory.some(item => item.id === 1 && item.slot === 48)); + assert.deepEqual((await state()).inventory, offered.inventory); + } + } + await owner.click(874, 475); + await owner.wait('exact selected-quality sale', snapshot => owner.local(snapshot).stats[61] === 159); + evidence.sale = await state(); + await owner.page.reload(); + await owner.ready(); + } + assert.deepEqual(owner.local().inventory.map(item => [item.id, item.slot, item.quality, ...item.templates, item.count]).sort((a, b) => a[0] - b[0]), [ + [2, 49, 10, 122905, 122906, 1], [3, 6, 11, 122905, 122906, 1], [4, 51, 12, 122905, 122906, 1], + ]); + assert.equal(owner.local().stats[61], 159); + assert.deepEqual(observer.local().inventory.map(item => [item.id, item.slot, item.quality, ...item.templates, item.count]), + [[5, 48, 2, 122905, 122906, 1]]); + evidence.final = {native: owner.local().inventory, server: await state()}; + assert.equal(evidence.final.server.inventory.Items[1].Ammo, 0); + assert(evidence.final.server.ownerHealth > 0); + assert(games.every(game => game.errors.length === 0)); + console.log('PASS: native Support Beam qualities, wear/removal, strict refusal, ordinary melee, exact sale and page/cold ownership'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2)); + await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); + } finally { await browser.close(); } +}