commit df8255c8281ca81ea7360eef02381b86ecd591ca
parent 71ed19bf3a2ddf013099ce021e35797f36c3c774
Author: anon <anon@example.com>
Date: Wed, 4 Nov 2026 21:01:08 +0000
Reject partial wear of resource-hit weapons
Diffstat:
6 files changed, 304 insertions(+), 6 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -655,8 +655,9 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
The independent original weapon census covers7,380 main-hand candidates.
Strict OnWear admission refuses83 conditional-modifier contracts, five stat315
contracts and two unresolved53162 contracts. Together with the invalid damage
- interval this leaves7,289 admissions; the broader companion-event audit remains
- open. See [weapon wear admission](docs/weapon-wear-admission.md).
+ interval the OnWear gate leaves7,289 candidates. The resource-hit refusals
+ below reduce current admission to7,285; the broader companion-event audit
+ remains open. See [weapon wear admission](docs/weapon-wear-admission.md).
Review actual consumers before extending that list:315 has a NanoAC weapon
damage branch, but no original main-hand weapon uses NanoAC and its five
modifier records deal Energy damage. Their practical effect remains unknown;
@@ -673,6 +674,14 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
leave signed modifier offsets until owner reconstruction. Establish generic
applied-effect and owner/observer synchronization semantics before enabling
conditional weapons; see `local/weapon-contract-research/conditional-native-lifecycle.md`.
+- [x] [P2] Refuse weapon wear with unimplemented automatic resource-hit effects.
+ A short native checkpoint equipped Neleb's Notum Battlerod and added 50 maximum
+ nano while omitting its authored event5 nano hits. All four resource-hit
+ weapons now refuse before applying partial wear. Public-handler and short
+ WASM checks cover usable source restoration, repeated input, supported starter
+ wear and exact page/cold ownership. Their hit implementation and separate
+ CastChance procs remain in the full-contract audit above. See
+ [resource-hit admission](docs/weapon-wear-admission.md#automatic-resource-hit-admission).
- [x] Apply worn AggDef51 through shared player weapon/fist timing. Preserve
the signed effective sum beyond slider bounds, base slider persistence and
replication, frozen phase deadlines and base-only nano queue timing. Check
diff --git a/docs/weapon-wear-admission.md b/docs/weapon-wear-admission.md
@@ -44,8 +44,52 @@ broader whole-item audit remain open. Solar starters retain their event10
descriptors. Stat315 has a NanoAC weapon-damage branch, but these five modifier
records deal Energy damage; their practical effect is unresolved.
The shared [defense consumer admission](stat-equipment.md#worn-defense-modifiers)
-now admits Jupiter208069..208071, whose complete wear effects add277. Current
-main-hand admission is7,289; other events and the historical hit curve remain open.
+now admits Jupiter208069..208071, whose complete wear effects add277. The
+wear gate admits 7,289 contracts. The resource-hit boundary below reduces
+current main-hand admission to 7,285; other events and the historical hit curve
+remain open.
+
+## Automatic resource-hit admission
+
+Four original main-hand weapons have automatic event 5 Hit53002 effects:
+Neleb's Notum Battlerod 152026, Deimos' Bio-Enhanced Feedback Rifle 153981,
+Parasitic Hecataleech 206047 and Augmented Deimos' Bio-Enhanced Feedback
+Rifle 206048. The rod authors two nano hits; the other three author owner health
+hits. These effects have no server combat-outcome consumer. Accepting their
+wear applies a partial contract even when their ordinary damage is supported.
+
+`isWieldableWeapon` now refuses these contracts before any wear bonus applies.
+The existing delayed-equipment validator uses the same predicate. Ownership,
+templates, selected quality, count and ammunition remain stored; refusal uses
+the existing native source-icon correction. This is the reconstruction's
+unsupported-contract policy, not a claim that the original game refused these
+weapons. Implementing their hit effects remains part of the full-contract audit.
+
+An original-resource census covers all 7,380 main-hand candidates and 437 event 5
+contracts. Comparing the actual predicate before and after finds exactly these
+four new refusals and no new admissions. The eight starters, four native
+HeadText weapons and existing CastChance53089 admissions remain unchanged.
+The separate proc gaps, including Briefcase of Holding, remain open; this
+boundary does not claim their complete implementation. Complete resource-hit
+sections, original payload hashes and the exact census are retained in
+`local/weapon-hit-admission/` and `local/weapon-contract-research/`.
+
+`TestWeaponHitEffectsRejectWearWithoutPartialBonuses` uses the public inventory
+handler for every resource-hit weapon with qualified skills, repeated wear,
+byte-identical refusal storage and exact cold ownership. The short
+`TestBrowserWeaponHitAdmission` baseline wore the rod and changed server maximum
+nano 297 -> 347. The final controlled WASM check takes 21.36 seconds: two real
+pickup/place refusals retain its usable carried icon, a supported bat completes
+wear/remove/rewear, and page replay plus cold Go loading retain both exact IDs.
+The refused screenshot was manually inspected. This is fixture evidence, not
+earned progression or a recovered original-server rejection policy.
+
+Related Go checks pass 186 roots and 4,748 results including subtests in
+276 seconds. Three focused race roots pass seven results in 96.5 seconds;
+maintained-package vet, driver syntax, gofmt and whitespace checks pass.
+`local/weapon-hit-admission/verification.json` binds the exact four-contract
+census change, real native requests/corrections, final item tuples, four
+error-free traces without dropped events and the terminal Go results.
## Focused verification
diff --git a/server/browser_weapon_hit_admission_test.go b/server/browser_weapon_hit_admission_test.go
@@ -0,0 +1,89 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestBrowserWeaponHitAdmission(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for automatic-hit weapon admission")
+ }
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/weapon-hit-admission", time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ player := world.newCharacter()
+ player.level, player.profession, player.appearance = 50, 9, 0x515
+ player.stats.Abilities = characterAbilitiesStats{100, 100, 100, 100, 100, 100}
+ player.stats.Melee.TwoHandBlunt, player.stats.Melee.FastAttack = 250, 125
+ player.health, player.nano = player.maximumHealth(), player.maximumNano()
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("weapon-hit-admission")))
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for _, template := range []uint32{152026, 121564} {
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatal(granted, 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{"inventory": player.inventory, "nanoMaximum": player.maximumNano()})
+ })
+ host := httptest.NewServer(mux)
+ t.Cleanup(host.Close)
+ closeTestBrowserStreams(t, world)
+ ctx, cancel := context.WithTimeout(context.Background(), 2*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)
+ case <-ctx.Done():
+ return
+ }
+ }
+ }()
+ defer func() { cancel(); <-stopped }()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_weapon_hit_admission.mjs"), host.URL, output)
+ 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)
+ }
+ cold := newTestInventoryServer(t)
+ expected := []ownedItem{
+ {ID: 1, Type: 51018, Template: 152026, Quality: 53, Slot: 64, Count: 1},
+ {ID: 2, Type: 51018, Template: 121564, Quality: 1, Slot: 6, Count: 1},
+ }
+ if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) ||
+ player.inventory.equipmentBonus(221) != 0 || cold.characters[1].inventory.equipmentBonus(221) != 0 ||
+ player.inventory.Credits != 0 || cold.characters[1].inventory.Credits != 0 || world.nextItem != 2 || cold.nextItem != 2 {
+ t.Fatal("refused hit weapon or supported bat lost ownership, applied a partial bonus or changed cash")
+ }
+}
diff --git a/server/weapon_hit_admission_test.go b/server/weapon_hit_admission_test.go
@@ -0,0 +1,66 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "fmt"
+ "slices"
+ "testing"
+)
+
+func TestWeaponHitEffectsRejectWearWithoutPartialBonuses(t *testing.T) {
+ for _, template := range []uint32{152026, 153981, 206047, 206048} {
+ t.Run(fmt.Sprint(template), func(t *testing.T) {
+ world, output := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ player.level = 200
+ player.profession = 5
+ player.stats.Abilities = characterAbilitiesStats{200, 200, 200, 200, 200, 200}
+ for _, field := range player.stats.trainingStats() {
+ *field.value = 2000
+ }
+ item := &player.inventory.Items[0]
+ item.Template = template
+ item.Quality = *gamedata.ItemTemplates[template].Quality
+ if !item.requirementsMet(8, player.meetsStatRequirement) {
+ t.Fatal("fixture does not meet the original weapon requirements")
+ }
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.saveInventory_locked(player, player.inventory); err != nil {
+ t.Fatal(err)
+ }
+ expected := slices.Clone(player.inventory.Items)
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ output.packets = nil
+
+ for range 2 {
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if client.equipment != nil {
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+ }
+ after, err := readTestItemStore(world)
+ cold := newTestInventoryServer(t).characters[1]
+
+ if err != nil || !bytes.Equal(before, after) || client.equipment != nil ||
+ !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.inventory.Items, expected) ||
+ player.attackWeapon() != nil || cold.attackWeapon() != nil ||
+ player.inventory.equipmentBonus(221) != 0 || cold.inventory.equipmentBonus(221) != 0 ||
+ len(output.packets) != 4 {
+ t.Fatal("unimplemented automatic hit contract applied partial wear or changed ownership", err)
+ }
+ for index, packet := range output.packets {
+ if !bytes.Equal(packet, targetPacket(equipmentCorrectionPackets(1, 64)[index%2])) {
+ t.Fatal("unsupported hit weapon did not restore its ordinary source")
+ }
+ }
+ })
+ }
+}
diff --git a/server/weapon_stats.go b/server/weapon_stats.go
@@ -13,9 +13,19 @@ func (item ownedItem) isWieldableWeapon() bool {
return false
}
- // A weapon's complete wear event must be supported before any bonus applies.
+ // Resource hits and wear events must be supported before any bonus applies.
for _, section := range definition.Sections {
- if section.Type != 2 || section.Subtype != 14 {
+ if section.Type != 2 {
+ continue
+ }
+ if section.Subtype == 5 {
+ for _, function := range *section.Functions {
+ if function.ID == 53002 {
+ return false
+ }
+ }
+ }
+ if section.Subtype != 14 {
continue
}
for _, function := range *section.Functions {
diff --git a/tools/client/test_weapon_hit_admission.mjs b/tools/client/test_weapon_hit_admission.mjs
@@ -0,0 +1,80 @@
+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 evidence = {attempts: []};
+let game;
+try {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: 'weapon-hit-admission', url}]);
+ const page = await context.newPage();
+ game = await GameTest.attach(page);
+ await page.goto(url);
+ await game.ready();
+ const server = async () => (await page.request.get(url + '/test-state')).json();
+ evidence.initial = await server();
+ await game.key('KeyI');
+ await page.keyboard.press('Control+1');
+
+ // Exercise real pickup/place twice, including reuse of the refused source.
+ for (let attempt = 0; attempt < 2; ++attempt) {
+ await game.wait('native equipment action finishes', state =>
+ !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
+ const sequence = game.sequence;
+ await game.click(681, 45);
+ await game.wait('rod picked from carried inventory', state => state.dragged[0] === 104 && state.dragged[1] === 48);
+ await game.click(867, 206);
+ await game.wait('weapon move receives a native reply', () => game.events.some(event =>
+ event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24') &&
+ (game.events.filter(event => event.sequence > sequence && event.direction === 'framereceived' &&
+ event.opcode === '47537a24').length === 2 || game.events.some(event =>
+ event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '3b1d2268')));
+ evidence.attempts.push(await server());
+ await game.save(output + '/refused-' + attempt);
+ assert.deepEqual(evidence.attempts[attempt], evidence.initial);
+ const moves = game.events.filter(event => event.sequence > sequence &&
+ event.direction === 'framereceived' && event.opcode === '47537a24').map(event => {
+ const bytes = Buffer.from(event.hex, 'hex');
+ return [bytes.readUInt32BE(29), bytes.readUInt32BE(33), bytes.readUInt32BE(45)];
+ });
+ assert.deepEqual(moves, [[104, 48, 49], [104, 49, 48]]);
+ await game.wait('refused rod source remains usable', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy)));
+ assert.deepEqual(game.state.dragged, [0, 0]);
+ assert.equal(game.local().inventory.find(item => item.id === 1).slot, 48);
+ }
+
+ // A supported weapon still completes wear, removal and a second wear.
+ for (const remove of [true, false]) {
+ await game.click(735, 45, 'right');
+ await game.wait('supported bat wears', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 6));
+ if (remove) {
+ await game.wait('bat equip action finishes', state =>
+ !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
+ await game.click(867, 206, 'right');
+ await game.wait('supported bat removes', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 49));
+ }
+ }
+ evidence.after = await server();
+ await game.save(output + '/supported');
+ await page.reload();
+ await game.ready();
+ assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality]).sort((a, b) => a[0] - b[0]),
+ [[1, 48, 53], [2, 6, 1]]);
+ assert.deepEqual(await server(), evidence.after);
+ assert.equal(evidence.after.nanoMaximum, evidence.initial.nanoMaximum);
+ assert.deepEqual(game.errors, []);
+ console.log('PASS: two automatic-hit weapon refusals retain a usable source; supported bat wear/removal, page replay and cold ownership agree');
+} 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(); }
+}