commit 42f67a43d24221a617c64d71edaae2672091949c
parent 44c5bbe2acf0595e0b82ad06cd10ad806c078419
Author: anon <anon@example.com>
Date: Mon, 26 Oct 2026 03:07:17 +0000
Admit complete original AggDef self nanos through shared buff rules
Recognize keyed native attack/defense metadata independently of outer order,
positive signed Level/skill weights, preserved zero-default getter lists and
checked HeadText companions. Require self-only effects for flags0x1c000 and
route stat51 through the existing numeric modifier consumer.
This admits exactly Call on Insanity, Soul of Malevolence and Frenzied Soul
From The Pit, with their three original crystals. Preserve complete companions,
strict skill gates, NCU exemption, noncancelability, strain replacement and
atomic persistence without program-specific gameplay branches. Keep the other
17 AggDef contracts rejected whole and record the separate native fist gap.
Validate the exact 470-program/468-crystal catalog, 13,885 full-suite results,
292 focused and 1,586 race results, plus vet and two GPU WASM clients.
Native checks cover 21 states, 61 matching owned hit pairs, all modifiers,
ordinary damage, expiry, cancellation refusal, reconnect and cold SQLite restore.
Remove owned fixtures and keep the sole shared HTTPS8443 preview available.
Diffstat:
7 files changed, 650 insertions(+), 35 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -234,11 +234,17 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md).
different playfields and repeated readiness. Fresh native fights agree at
slider 0 and -100; the active-timer discrepancy above remains open. See
[receiver evidence and checks](docs/remote-combat-stats.md).
-- [ ] Complete the20 original stat51 nano contracts before admitting them.
- Allowing scalar51 alone completes none: pet chants also need53153 and target
- criteria; Call/Soul programs have unsupported metadata/dictionaries; rage tiers
- need276/277, morph criteria and child events; Blessed by the Eagle uses zero
- cost, different flags and a conditional parent producer. Establish the full
+- [x] Admit the complete Call on Insanity, Soul of Malevolence and Frenzied Soul
+ From The Pit contracts through shared buff metadata and effect consumers.
+ Preserve all AggDef, initiative, damage and HeadText companions, self-only
+ recipients, strict upload/cast gates, zero used NCU, noncancelability and
+ same-strain strength. Check owner/observer delivery, cold restore, full NCU,
+ upgrade/refresh/rejection, ordinary hits and atomic failure/retry. See
+ [AggDef nanos](docs/nano-aggdef.md).
+- [ ] Complete the remaining17 original stat51 nano contracts before admitting
+ them. Pet chants also need53153 and target criteria; rage tiers need276/277,
+ morph criteria and child events; Blessed by the Eagle uses zero cost,
+ different flags and a conditional parent producer. Establish the full
producers and recipient effects instead of relaxing validators piecemeal.
Complete records, crystals, references and blockers are in
`local/aggdef-nano-contract-research/`.
@@ -316,6 +322,13 @@ capacity checks are recorded in [belts and NCU](docs/belts-ncu.md).
match documented expected amounts at representative boundaries.
- [ ] Select Martial Arts fist QL from skill. Check: known MA values select the
evidenced template/QL and change damage without equipping a weapon.
+ The level200 AggDef smoke exposes a separate current mismatch: the native
+ client constructs a QL200 fist from the supplied43712/43713 endpoints, with
+ 133cs delays and damage28/115/201, while the server uses QL1 values. Native
+ clocks are308/308cs at raw slider-100 and100/100cs under Call on Insanity.
+ Establish original server selection and use shared template interpolation;
+ do not patch individual programs or infer an MA curve from this client
+ construction. See `local/aggdef-nano-fist-clock-research/findings.md`.
- [x] Replace the approximate melee range check. Check: two actors at known
positions and sizes are accepted or rejected at the recovered range boundary.
- [ ] Reject attacks through one solid obstruction. Check: the same stationary
diff --git a/docs/nano-aggdef.md b/docs/nano-aggdef.md
@@ -0,0 +1,133 @@
+# AggDef nanos
+
+Call on Insanity, Soul of Malevolence and Frenzied Soul From The Pit use the
+shared timed-buff path. Their complete original contracts qualify through
+template metadata and implemented effect consumers; there are no program-ID
+branches in casting, timing, damage, persistence or removal.
+
+| Program | Crystal / QL | Duration | NCU strength | Complete numeric effects |
+| --- | --- | --- | ---: | --- |
+| Call on Insanity 149994 | 150020 / 107 | 18s | 33 | AggDef +200; four initiatives +1000; Melee, Energy and Chemical damage +100 |
+| Soul of Malevolence 152522 | 152531 / 143 | 60s | 44 | AggDef +90; all eight ordinary damage types +93 |
+| Frenzied Soul From The Pit 152525 | 152529 / 143 | 30s | 45 | AggDef +120; four initiatives +450; all eight ordinary damage types +190 |
+
+The initiatives are 118/119/120/149. Call also authors HeadText53057 with
+`Call on Insanity`, color 2; Frenzied authors `Soul Unleashed`, color 2.
+The native client executes this presentation when the whole program is applied.
+It is not replaced with another numeric modifier or a server chat message.
+
+Call requires effective Psychological Modification129 >245. Both Soul programs
+require Matter Creation130, Biological Metamorphosis128 and Time and Space131
+each >525. The original crystals have the same caster predicates. Upload and
+casting share the requirement evaluator; equality fails. Upload consumes the
+actual crystal instance atomically with learning the program.
+
+## Generic metadata and recipients
+
+The original section4/subtype4 attack and defense entries have keys 12 and 13
+in defense-first order. The native loader stores these outer entries by key;
+their unique-key order is immaterial. The attack vector is Level54 with weight
+1000, and the defense vector is NanoResist168 with weight zero. Native weighted
+getters divide each signed term by 100 before summation. Weights do not need to
+sum to 100. Actor Level54 and a program's NCU54 are separate values.
+
+The buff validator recognizes positive signed weights for Level and supported
+skills, and retains the zero Nano Resist defense contract. This does not add
+resistance rolls to friendly buffs or change the separate hostile hit path.
+These three programs contain only self selectors 1/2. Both supplied identity
+words are normalized to the caster before the ordinary live-target checks.
+The new flags0x1c000 class requires a complete self-only effect set; it does not
+admit an arbitrary hostile buff on another player or an NPC.
+
+Section6/subtype27 is an ordered native list, not the keyed weight tree. These
+records preserve `(13,0),(12,0)`. Admission recognizes unique keys 12 and
+optional 13 with zero defaults while leaving the original list untouched.
+The bounded source review establishes accepted ordered storage, but not its
+wider evaluation semantics. No claim that reversing this list is behaviorally
+equivalent is needed to deliver the original definition unchanged.
+
+## NCU, stacking and removal
+
+All three records have BuffNano0x10000 and flag0x8000. Native addition/removal
+skips used-NCU180 accounting for that bit, and the native local cancellation
+sender refuses it. The server's existing shared NCU and removal paths implement
+the same rules. These effects can coexist with a full NCU allocation, and their
+expiry must not subtract the authored 33/44/45 from unrelated used NCU.
+The flag does not by itself establish harmful effects or opposing-side policy.
+
+Authored NCU54 still controls same-strain replacement. Soul and Frenzied share
+strain226, so 45 replaces 44, an equal-strength refresh retains one complete
+contribution, and 44 cannot replace 45. Call's omitted strain uses the original
+program-ID default 149994 and stacks separately. A failed durable replacement
+retains the old complete modifier set and refunds the reserved nano.
+
+Expiry commits removal before action65 reaches owner and observers. A failed
+removal retains every companion until a durable retry succeeds. Local action65
+requests cannot cancel these programs. The current shared death/offline-clock
+policies remain reconstruction policies; these flags do not prove the original
+server's treatment of death, offline time or resource reset.
+
+## Timing and damage
+
+Shared player weapon timing sums the raw slider, worn AggDef and active-nano
+AggDef without clamping the effective sum to the slider's -100..100 range.
+Initiative companions reach the same existing effective-stat getters. Nano
+casting continues to use the raw slider; an initiative149 companion can still
+change its initiative reduction. Trained bases are never overwritten.
+
+At raw slider -100, abilities all 1 and trained PhysicalInitiative zero, the
+server's current QL1 fist fallback runs at 300/300 centiseconds. The complete
+Call contract gives 100/100, Soul gives 210/210, and Frenzied gives 105/100.
+Expiry restores the unmodified clock. The existing damage-type consumer adds
+the matching authored damage bonus to ordinary weapon hits.
+
+The level200 native smoke instead constructs a QL200 fist from the supplied
+43712/43713 endpoints: its 133cs delays yield 308/308cs before and after Call,
+and 100/100cs during Call on both clients. Damage fields 28/115/201 independently
+match that interpolation. The server's fist selection remains an open issue;
+these captures establish native client construction, not the original server's
+MA-to-template/QL selection. The source-bound ledger is retained in
+`local/aggdef-nano-fist-clock-research/`.
+
+## Evidence and scope
+
+The independent audit covers all 87,611 original/YAML identities, 4,366 program
+records and 2,550 upload carriers. Admission changes from 467 programs / 465
+crystals to exactly 470 / 468. All six new original payloads were independently
+reparsed, hash-checked and matched against complete current YAML. Full original
+functions, requirements, metadata, hashes and source boundaries are retained in
+`local/aggdef-nano-admission-research/`, alongside the earlier flag and dictionary
+audits linked by its report.
+
+The other 17 original AggDef programs remain rejected as whole contracts. Pet
+chants need their recipient/53153 companions; rage tiers need offense/defense,
+morph and child-event support; Blessed by the Eagle needs its producer chain.
+None receives a partial effect from adding the shared AggDef consumer.
+
+## Verification
+
+Focused public cast/upload tests cover every strict skill boundary, all numeric
+companions, cold database restore, exact expiry, full-NCU coexistence, actual
+ordinary hits, separate strains, replacement/refresh/downgrade and persistence
+failure/refund/retry. Malformed complete contracts are rejected before reserving
+nano or applying effects. The complete catalog assertion pins the exact admitted
+program and crystal identities, including all previous admissions.
+
+Two GPU WASM clients verify 21 native states and 61 matching owned ordinary
+hit pairs. All three original crystals upload through the inventory UI. Soul
+upgrades to Frenzied without retaining the weaker contribution; a subsequent
+Soul cast is refused. Right-click cancellation of Frenzied is refused locally.
+Every authored modifier appears on owner and observer while trained bases stay
+unchanged, used NCU stays zero and natural expiry removes all companions.
+Call's live clocks agree at 100/100cs on both clients; unbuffed captures before
+and after expiry agree at 308/308cs, subject to the fist-selection gap above.
+Its ordinary hits include the full +100 Melee damage bonus.
+
+An active Soul survives browser reconnect and a full server restart with one
+modifier contribution and decreasing replay durations of 5999, 5617 and 3135cs.
+The stopped database contains the same program/caster with 31.356507555s left.
+No WASM errors occurred. Screenshots, read-only native state/SQLite probes,
+reassembled wire packets and checks are retained in `local/aggdef-nano-smoke/`.
+The verifier excludes empty-grid clicks, an interrupted pre-reload cast and
+idle captures mislabeled as combat. Owned fixtures and browser processes are
+removed after testing; the single shared HTTPS8443 preview remains available.
diff --git a/docs/nano-buffs.md b/docs/nano-buffs.md
@@ -1,30 +1,35 @@
# Temporary nano research for 14.9.1
Ordinary ability, health, skill and passive regeneration buffs share one
-timed-effect path. Complete-contract checks admit 242 original programs and
-241 original crystals; see [skill buffs](nano-skill-buffs.md) for the expansion.
+timed-effect path. Complete-contract checks admit 470 original programs and
+468 original crystals, including the [AggDef self buffs](nano-aggdef.md).
Learning and casting remain separate operations; arbitrary nano functions are
not enabled by this family.
## Complete contract admission
Programs require native header51051, ItemType0, audited Can0/8 and the raw
-Flags0 values `0x80010000`, `0x10000` or `0x10002`. All carry BuffNano0x10000
-and lack the hostile/nonoverwrite flags used by the reviewed cast and
-cancellation paths.
-These are three exact audited values, not a claim that arbitrary other flag bits
-are harmless. Duration, NCU, strain, cost, range, attack and recharge
+Flags0 values `0x80010000`, `0x10000`, `0x10002`, `0x14000` or `0x14002`.
+The additional `0x1c000` class requires self-only effects and uses the existing
+NCU-exemption and local-cancellation rules for bit0x8000. All carry
+BuffNano0x10000. These are exact audited values, not a claim that arbitrary other
+flag bits are harmless. Duration, NCU, strain, cost, range, attack and recharge
must resolve to positive finite values, including original constructor defaults
for omitted fields. Authored zero values remain zero. Each OnUse0 effect is an
-unconditional Modify53045,
-target3, tick1/interval0, with two integer arguments and an implemented consumer.
-Positive MaxHealth1, ability16..21, trained skills100..168, HealDelta343 and
-NanoDelta364 modifiers qualify.
+unconditional numeric Modify53045 or Skill53012 with an implemented consumer,
+or a checked HeadText53057 presentation companion. Effects require consistent
+self or supplied-target selectors and tick1/interval0. A complete program must
+contain a numeric effect. Positive MaxHealth1, ability16..21, trained
+skills100..168, HealDelta343 and NanoDelta364 modifiers qualify alongside the
+separately audited armor and combat consumers. Signed AggDef51 reaches shared
+player weapon timing.
Signed SkillLockModifier382 also has a verified consumer, but no original
nano uses it; its synthetic lifecycle fixtures remain separate from content.
-The checker validates ordinary attack-weight dictionaries4/4 and getter-mode
-maps6/27, plus action3 criteria22/36. Unknown metadata, additional effects,
+The checker validates keyed attack-weight dictionaries4/4 and preserves
+recognized zero-default getter lists6/27, plus action3 criteria22/36. Native
+weights need not sum to100; the AggDef programs use Level54 weighted1000.
+Unknown metadata, unsupported effects,
other events, conditions or repetition reject the whole program. An ordinary
crystal requires header51005, one audited Flags0 value (`0x80400203`,
`0x00400203`, `0x88400203` or `0x08400203`), Can30=`0x29`, Count26=1 and
@@ -135,7 +140,7 @@ not a captured historical server exchange.
CharacterAction `5e477770`, action 177, uses the recipient as envelope actor
and DWORD fields `{177,53019,programID,casterID,durationCs}`. Receiver
`1006fa30 -> 10066010` adds the active record, executes its modifiers and
-increments used NCU 180. It applies to owner and observer representations;
+increments used NCU180 unless flag0x8000 exempts it. It applies to owner and observer representations;
only the local recipient receives the effect icon. Do not also send an
ApplySpells modifier stream for the same effect. Ordinary cast admission
18 and completion 107 remain separate from this active-effect delivery.
diff --git a/server/aggdef_nano_test.go b/server/aggdef_nano_test.go
@@ -0,0 +1,439 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "encoding/binary"
+ "fmt"
+ "slices"
+ "testing"
+ "time"
+)
+
+type aggDefNanoFixture struct {
+ program, crystal, quality, duration, debit uint32
+ modifiers [][2]int32
+ attack, recharge time.Duration
+}
+
+func aggDefNanoFixtures() []aggDefNanoFixture {
+ return []aggDefNanoFixture{
+ {149994, 150020, 107, 1800, 34,
+ [][2]int32{{51, 200}, {149, 1000}, {119, 1000}, {120, 1000}, {118, 1000}, {311, 100}, {280, 100}, {279, 100}},
+ time.Second, time.Second},
+ {152522, 152531, 143, 6000, 119,
+ [][2]int32{{282, 93}, {317, 93}, {281, 93}, {311, 93}, {316, 93}, {280, 93}, {278, 93}, {279, 93}, {51, 90}},
+ 2100 * time.Millisecond, 2100 * time.Millisecond},
+ {152525, 152529, 143, 3000, 119,
+ [][2]int32{{120, 450}, {149, 450}, {119, 450}, {118, 450}, {282, 190}, {317, 190}, {281, 190}, {311, 190},
+ {316, 190}, {280, 190}, {278, 190}, {279, 190}, {51, 120}},
+ 1050 * time.Millisecond, time.Second},
+ }
+}
+
+func TestAggDefNanosUploadCastRestoreAndExpireCompleteEffects(t *testing.T) {
+ for _, fixture := range aggDefNanoFixtures() {
+ t.Run(fmt.Sprint(fixture.program), func(t *testing.T) {
+ world, conn := newCombatNanoWorld(t, combatNanoFixture{})
+ player, client := world.characters[1], world.clients[1]
+ player.aggDef = -100
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ player.stats.Body.MartialArts = 0
+ player.stats.Speed.MeleeInitiative, player.stats.Speed.RangedInitiative = 0, 0
+ player.stats.Speed.PhysicalInitiative, player.stats.Speed.NanoInitiative = 0, 0
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ if granted, err := world.grantItem_locked(player, fixture.crystal); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ trained := player.baseStats()
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: 950, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, ready: true, target: true}
+
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if len(conn.packets) != 3 || binary.BigEndian.Uint32(conn.packets[1][37:41]) != fixture.quality ||
+ !slices.Equal(player.inventory.LearnedNanos, []uint32{fixture.program}) {
+ t.Fatal("complete original crystal did not upload its program once")
+ }
+ conn.packets = nil
+ completed := castTestBuff(t, world, 1, 1000000, fixture.program)
+ cold := newTestInventoryServer(t).characters[1]
+
+ if player.baseStats() != trained || cold.baseStats() != trained || player.aggDef != -100 || cold.aggDef != -100 ||
+ player.nano != 50000-fixture.debit || cold.nano != player.nano || player.nanoReserved != 0 ||
+ len(player.activeNanos) != 1 || len(cold.activeNanos) != 1 || player.usedNCU() != 0 || cold.usedNCU() != 0 ||
+ player.activeNanos[0].expiresAt.Sub(completed) != time.Duration(fixture.duration)*10*time.Millisecond ||
+ len(cold.inventory.Items) != 2 || !slices.Equal(cold.inventory.LearnedNanos, []uint32{fixture.program}) ||
+ len(world.characters[1000000].activeNanos) != 0 || len(world.characters[2].activeNanos) != 0 {
+ t.Fatal("cast or cold restore changed the wrong target, foundation, item, duration or resource")
+ }
+ for _, modifier := range fixture.modifiers {
+ if player.nanoBonus(uint32(modifier[0])) != modifier[1] || cold.nanoBonus(uint32(modifier[0])) != modifier[1] {
+ t.Fatal("cast or cold restore lost an authored companion", modifier)
+ }
+ }
+ attack, recharge := player.attackDelays()
+ if attack != fixture.attack || recharge != fixture.recharge {
+ t.Fatal("complete initiative/AggDef effects did not reach shared weapon timing", attack, recharge)
+ }
+ for _, packets := range [][][]byte{conn.packets, observer.packets} {
+ applications := 0
+ for _, packet := range packets {
+ if binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 && binary.BigEndian.Uint32(packet[29:33]) == 177 {
+ if !slices.Equal(packet[16:], targetPacket(characterActionPacket(1, [5]uint32{177, 53019, fixture.program, 1, fixture.duration}))[16:]) {
+ t.Fatal("native application changed the source, target or original program")
+ }
+ applications++
+ }
+ }
+ if applications != 1 {
+ t.Fatal("owner or observer did not receive exactly one whole-program application", applications)
+ }
+ }
+
+ conn.packets, observer.packets = nil, nil
+ if err := world.handleNanoRemoval(client, characterActionPacket(1, [5]uint32{65, 0, 0, 53019, fixture.program})[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if len(player.activeNanos) != 1 || len(newTestInventoryServer(t).characters[1].activeNanos) != 1 || len(conn.packets) != 0 || len(observer.packets) != 0 {
+ t.Fatal("a locally noncancelable effect accepted cancellation")
+ }
+
+ deadline := player.activeNanos[0].expiresAt
+ world.advanceNanos(deadline.Add(-time.Nanosecond))
+ if len(player.activeNanos) != 1 {
+ t.Fatal("effect expired before its authored deadline")
+ }
+ world.advanceNanos(deadline)
+ world.advanceNanos(deadline.Add(time.Second))
+ cold = newTestInventoryServer(t).characters[1]
+
+ if len(player.activeNanos) != 0 || len(cold.activeNanos) != 0 || player.usedNCU() != 0 || cold.usedNCU() != 0 ||
+ player.baseStats() != trained || player.aggDef != -100 || cold.aggDef != -100 {
+ t.Fatal("authoritative expiry retained an effect or changed its foundations")
+ }
+ for _, modifier := range fixture.modifiers {
+ if player.nanoBonus(uint32(modifier[0])) != 0 || cold.nanoBonus(uint32(modifier[0])) != 0 {
+ t.Fatal("expiry retained an authored companion", modifier)
+ }
+ }
+ attack, recharge = player.attackDelays()
+ if attack != 3*time.Second || recharge != 3*time.Second {
+ t.Fatal("expiry did not restore the unmodified defensive timing", attack, recharge)
+ }
+ for _, packets := range [][][]byte{conn.packets, observer.packets} {
+ if len(packets) != 1 || !slices.Equal(packets[0][16:], targetPacket(characterActionPacket(1, [5]uint32{65, 0, 0, 1, fixture.program}))[16:]) {
+ t.Fatal("expiry did not publish exactly one whole-program removal", packets)
+ }
+ }
+ })
+ }
+}
+
+func TestAggDefNanoCrystalAndCastEnforceEveryStrictSkillGate(t *testing.T) {
+ for _, fixture := range []struct {
+ program, crystal, stat uint32
+ threshold uint16
+ }{
+ {149994, 150020, 129, 245},
+ {152522, 152531, 130, 525}, {152522, 152531, 128, 525}, {152522, 152531, 131, 525},
+ {152525, 152529, 130, 525}, {152525, 152529, 128, 525}, {152525, 152529, 131, 525},
+ } {
+ for _, difference := range []int{-1, 0, 1} {
+ t.Run(fmt.Sprintf("%d/%d/%d", fixture.program, fixture.stat, difference), func(t *testing.T) {
+ world, _ := newCombatNanoWorld(t, combatNanoFixture{})
+ player, client := world.characters[1], world.clients[1]
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ for _, field := range player.stats.trainingStats() {
+ if field.stat == fixture.stat {
+ *field.value = uint16(int(fixture.threshold) + difference)
+ }
+ }
+ if granted, err := world.grantItem_locked(player, fixture.crystal); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 64, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ learned := slices.Contains(player.inventory.LearnedNanos, fixture.program)
+ player.inventory.LearnedNanos = []uint32{fixture.program}
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, fixture.program})[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if difference == 1 {
+ if !learned || client.nanoCast == nil || len(player.inventory.Items) != 2 {
+ t.Fatal("qualified original crystal or cast was rejected")
+ }
+ } else if learned || client.nanoCast != nil || player.nano != 50000 || player.nanoReserved != 0 ||
+ len(player.inventory.Items) != 3 || len(player.activeNanos) != 0 {
+ t.Fatal("failed strict skill gate consumed a crystal, reserved nano or applied an effect")
+ }
+ })
+ }
+ }
+}
+
+func TestAggDefNanosUseNoNCUAtFullCapacity(t *testing.T) {
+ for _, fixture := range aggDefNanoFixtures() {
+ t.Run(fmt.Sprint(fixture.program), func(t *testing.T) {
+ world, conn := newCombatNanoWorld(t, combatNanoFixture{Profession: 12})
+ player, client := world.characters[1], world.clients[1]
+ player.inventory.LearnedNanos = []uint32{29303, 27169, fixture.program}
+ castTestBuff(t, world, 1, 1, 29303)
+ if player.usedNCU() != 52 || player.maximumNCU() != 52 {
+ t.Fatal("fixture did not fill the available NCU")
+ }
+ player.nanoRechargeUntil = time.Time{}
+ before := player.nano
+
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, 27169})[20:]); err != nil {
+ t.Fatal(err)
+ }
+
+ if client.nanoCast != nil || player.nano != before || len(player.activeNanos) != 1 {
+ t.Fatal("full NCU did not reject an ordinary buff without debit")
+ }
+
+ castTestBuff(t, world, 1, 1, fixture.program)
+ cold := newTestInventoryServer(t).characters[1]
+
+ if player.usedNCU() != 52 || cold.usedNCU() != 52 || len(player.activeNanos) != 2 || len(cold.activeNanos) != 2 ||
+ player.nano != before-fixture.debit || player.nanoBonus(51) == 0 {
+ t.Fatal("NCU-exempt effect did not coexist with a full allocation")
+ }
+
+ conn.packets = nil
+ world.advanceNanos(player.activeNanos[1].expiresAt)
+ cold = newTestInventoryServer(t).characters[1]
+
+ if player.usedNCU() != 52 || cold.usedNCU() != 52 || len(player.activeNanos) != 1 || len(cold.activeNanos) != 1 ||
+ player.activeNanos[0].program != 29303 || player.nanoBonus(129) != 140 || player.nanoBonus(51) != 0 || len(conn.packets) != 1 {
+ t.Fatal("expiry subtracted exempt NCU or removed an unrelated effect")
+ }
+ })
+ }
+}
+
+func TestAggDefNanoDamageCompanionsReachOrdinaryHits(t *testing.T) {
+ for _, fixture := range []struct{ program, health uint32 }{{149994, 895}, {152522, 902}, {152525, 805}} {
+ t.Run(fmt.Sprint(fixture.program), func(t *testing.T) {
+ world, _ := newCombatNanoWorld(t, combatNanoFixture{})
+ player, target, client := world.characters[1], world.characters[1000000], world.clients[1]
+ player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1}
+ player.stats.Body.MartialArts = 0
+ player.inventory.LearnedNanos = []uint32{fixture.program}
+ target.health = 1000
+ castTestBuff(t, world, 1, 1, fixture.program)
+
+ if err := world.handleCombat(client, attackPacket(1, target.id)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceCombat(player.nextAttack)
+
+ if target.health != fixture.health {
+ t.Fatal("ordinary hit omitted the matching authored damage companion", target.health, fixture.health)
+ }
+ })
+ }
+}
+
+func TestAggDefNanoStrainUpgradeRefreshAndDowngradePreserveSeparateContributions(t *testing.T) {
+ world, conn := newCombatNanoWorld(t, combatNanoFixture{})
+ player, client := world.characters[1], world.clients[1]
+ player.inventory.LearnedNanos = []uint32{149994, 152522, 152525}
+ castTestBuff(t, world, 1, 1, 149994)
+ player.nanoRechargeUntil = time.Time{}
+ castTestBuff(t, world, 1, 1, 152522)
+ if player.nanoBonus(51) != 290 || player.nanoBonus(279) != 193 || player.usedNCU() != 0 {
+ t.Fatal("distinct strains did not retain separate complete contributions")
+ }
+
+ player.nanoRechargeUntil = time.Time{}
+ castTestBuff(t, world, 1, 1, 152525)
+ player.nanoRechargeUntil = time.Time{}
+ castTestBuff(t, world, 1, 1, 152525)
+ before := len(conn.packets)
+ player.nanoRechargeUntil = time.Time{}
+ err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, 152522})[20:])
+ cold := newTestInventoryServer(t).characters[1]
+
+ if err != nil || client.nanoCast != nil || player.nano != 49609 || cold.nano != 49609 || len(player.activeNanos) != 2 || len(cold.activeNanos) != 2 ||
+ player.nanoBonus(51) != 320 || cold.nanoBonus(51) != 320 || player.nanoBonus(279) != 290 || cold.nanoBonus(279) != 290 ||
+ player.nanoBonus(120) != 1450 || cold.nanoBonus(120) != 1450 || player.usedNCU() != 0 || cold.usedNCU() != 0 || len(conn.packets) != before+1 {
+ t.Fatal("NCU-exempt strain replacement stacked, lost another strain or charged a rejected downgrade", err)
+ }
+ for _, effect := range player.activeNanos {
+ if effect.program == 152522 {
+ t.Fatal("weaker strain survived replacement")
+ }
+ }
+}
+
+func TestAggDefNanoFailedReplacementAndExpiryRetainCompleteEffectsUntilRetry(t *testing.T) {
+ for _, operation := range []string{"replace", "expire"} {
+ t.Run(operation, func(t *testing.T) {
+ world, conn := newCombatNanoWorld(t, combatNanoFixture{})
+ player, client := world.characters[1], world.clients[1]
+ player.inventory.LearnedNanos = []uint32{152522, 152525}
+ castTestBuff(t, world, 1, 1, 152522)
+ player.nanoRechargeUntil = time.Time{}
+ at := player.activeNanos[0].expiresAt
+ statement := "CREATE TRIGGER reject_effect BEFORE DELETE ON active_nanos BEGIN SELECT RAISE(FAIL, 'test expiry'); END"
+ if operation == "replace" {
+ if err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, 152525})[20:]); err != nil || client.nanoCast == nil {
+ t.Fatal("replacement was not admitted", err)
+ }
+ at = client.nanoCast.readyAt.Add(time.Nanosecond)
+ statement = "CREATE TRIGGER reject_effect BEFORE INSERT ON active_nanos WHEN NEW.program_id=152525 BEGIN SELECT RAISE(FAIL, 'test replacement'); END"
+ }
+ if _, err := world.db.Exec(statement); err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ world.advanceNanos(at)
+ cold := newTestInventoryServer(t).characters[1]
+
+ if player.nano != 49881 || cold.nano != 49881 || player.nanoReserved != 0 || len(player.activeNanos) != 1 || len(cold.activeNanos) != 1 ||
+ player.nanoBonus(51) != 90 || cold.nanoBonus(51) != 90 || player.nanoBonus(279) != 93 || cold.nanoBonus(279) != 93 || player.nanoBonus(120) != 0 ||
+ player.usedNCU() != 0 || cold.usedNCU() != 0 || operation == "replace" && len(conn.packets) != 2 || operation == "expire" && len(conn.packets) != 0 {
+ t.Fatal("failed persistence published a partial replacement/removal or lost a refund")
+ }
+ if _, err := world.db.Exec("DROP TRIGGER reject_effect"); err != nil {
+ t.Fatal(err)
+ }
+
+ if operation == "replace" {
+ player.nanoRechargeUntil = time.Time{}
+ castTestBuff(t, world, 1, 1, 152525)
+ } else {
+ world.advanceNanos(at.Add(time.Second))
+ }
+ cold = newTestInventoryServer(t).characters[1]
+
+ if operation == "replace" {
+ if len(player.activeNanos) != 1 || len(cold.activeNanos) != 1 || player.activeNanos[0].program != 152525 ||
+ player.nanoBonus(51) != 120 || cold.nanoBonus(51) != 120 || player.nanoBonus(279) != 190 || player.nano != 49762 || cold.nano != 49762 {
+ t.Fatal("durable retry did not replace the complete strain exactly once")
+ }
+ } else if len(player.activeNanos) != 0 || len(cold.activeNanos) != 0 || player.nanoBonus(51) != 0 || cold.nanoBonus(279) != 0 || len(conn.packets) != 1 {
+ t.Fatal("expiry did not retry the complete durable removal")
+ }
+ })
+ }
+}
+
+func TestAggDefNanoIncompleteContractsRejectWithoutPartialEffects(t *testing.T) {
+ for _, scenario := range []string{"foreign target", "mixed target", "unknown stat", "unknown function", "unknown flags",
+ "duplicate attack key", "missing attack", "empty weights", "unknown attack stat", "zero weight", "negative weight",
+ "duplicate getter", "missing attack getter", "unknown getter", "nonzero getter", "missing getters",
+ "missing text", "missing color", "extra text argument", "text header", "text argument header", "text only",
+ "conditional", "repeated", "interval"} {
+ t.Run(scenario, func(t *testing.T) {
+ original := gamedata.NanoTemplates[149994]
+ definition := *original
+ definition.Stats, definition.Sections = slices.Clone(original.Stats), slices.Clone(original.Sections)
+ entries := slices.Clone(*definition.Sections[0].Entries)
+ definition.Sections[0].Entries = &entries
+ functions := slices.Clone(*definition.Sections[2].Functions)
+ definition.Sections[2].Functions = &functions
+ textIndex := slices.IndexFunc(functions, func(function gamedata.ItemFunction) bool { return function.ID == 53057 })
+ if textIndex < 0 {
+ t.Fatal("original Call on Insanity has no HeadText companion")
+ }
+ text := &functions[textIndex]
+ text.Arguments = slices.Clone(text.Arguments)
+ switch scenario {
+ case "foreign target":
+ for index := range functions {
+ functions[index].Target = 3
+ }
+ case "mixed target":
+ text.Target = 3
+ case "unknown stat":
+ functions[0].Arguments = []gamedata.ItemArgument{{Integer: new(int32(277))}, {Integer: new(int32(200))}}
+ case "unknown function":
+ functions[0].ID = 53153
+ case "unknown flags":
+ for index, stat := range definition.Stats {
+ if stat[0] == 0 {
+ definition.Stats[index][1] = 0x1c002
+ }
+ }
+ case "duplicate attack key":
+ entries[0] = entries[1]
+ case "missing attack":
+ entries = entries[:1]
+ case "empty weights", "unknown attack stat", "zero weight", "negative weight":
+ weights := [][2]uint32{{54, 1000}}
+ if scenario == "empty weights" {
+ weights = nil
+ }
+ if scenario == "unknown attack stat" {
+ weights[0][0] = 999
+ }
+ if scenario == "zero weight" {
+ weights[0][1] = 0
+ }
+ if scenario == "negative weight" {
+ weights[0][1] = 0xffffffff
+ }
+ entries[1].Stats = &weights
+ case "duplicate getter", "missing attack getter", "unknown getter", "nonzero getter", "missing getters":
+ getters := [][2]uint32{{13, 0}, {12, 0}}
+ if scenario == "duplicate getter" {
+ getters[0][0] = 12
+ }
+ if scenario == "missing attack getter" {
+ getters = getters[:1]
+ }
+ if scenario == "unknown getter" {
+ getters[0][0] = 14
+ }
+ if scenario == "nonzero getter" {
+ getters[1][1] = 2
+ }
+ definition.Sections[1].Stats = &getters
+ if scenario == "missing getters" {
+ definition.Sections[1].Stats = nil
+ }
+ case "missing text":
+ text.Arguments[0] = gamedata.ItemArgument{}
+ case "missing color":
+ text.Arguments[1] = gamedata.ItemArgument{}
+ case "extra text argument":
+ text.Arguments = append(text.Arguments, gamedata.ItemArgument{Integer: new(int32(1))})
+ case "text header":
+ text.HeaderWords[0] = 1
+ case "text argument header":
+ text.ArgumentHeader = 8
+ case "text only":
+ functions = []gamedata.ItemFunction{*text}
+ case "conditional":
+ text.Requirements = []gamedata.ItemRequirement{{Stat: 54, Operator: 2, Value: 1}}
+ case "repeated":
+ text.TickCount = 2
+ case "interval":
+ text.TickInterval = 1
+ }
+ gamedata.NanoTemplates[149994] = &definition
+ t.Cleanup(func() { gamedata.NanoTemplates[149994] = original })
+ world, conn := newCombatNanoWorld(t, combatNanoFixture{})
+ player, client := world.characters[1], world.clients[1]
+ player.inventory.LearnedNanos = []uint32{149994}
+
+ err := world.handleNanoCast(client, characterActionPacket(1, [5]uint32{19, 50000, 1, 53019, 149994})[20:])
+
+ if err != nil || client.nanoCast != nil || player.nano != 50000 || player.nanoReserved != 0 || len(player.activeNanos) != 0 ||
+ len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 108 {
+ t.Fatal("unsupported contract started a cast, charged nano or applied partial effects", err)
+ }
+ })
+ }
+}
diff --git a/server/nano_buffs.go b/server/nano_buffs.go
@@ -29,7 +29,8 @@ func statBuffNano(program uint32) bool {
if can := itemStat(definition, 30); can != 0 && can != 8 {
return false
}
- if flags := itemStat(definition, 0); flags != 0x80010000 && flags != 0x10000 && flags != 0x10002 && flags != 0x14000 && flags != 0x14002 {
+ flags := itemStat(definition, 0)
+ if flags != 0x80010000 && flags != 0x10000 && flags != 0x10002 && flags != 0x14000 && flags != 0x14002 && flags != 0x1c000 {
return false
}
// Ordinary timed buffs have finite duration, NCU, strain, range and casting costs.
@@ -44,32 +45,42 @@ func statBuffNano(program uint32) bool {
for _, section := range definition.Sections {
switch section.Type {
case 4:
- // Admit the ordinary attack-weight dictionary carried by these buffs.
+ // Outer attack/defense keys are independent of serialized order.
if section.Subtype != 4 || section.Entries == nil || len(*section.Entries) < 1 || len(*section.Entries) > 2 {
return false
}
+ entry := (*section.Entries)[0]
if len(*section.Entries) == 2 {
defense := (*section.Entries)[1]
+ if entry.Type != nil && *entry.Type == 13 {
+ entry, defense = defense, entry
+ }
if defense.Type == nil || *defense.Type != 13 || defense.Stats == nil || !slices.Equal(*defense.Stats, [][2]uint32{{168, 0}}) {
return false
}
}
- entry := (*section.Entries)[0]
- if entry.Type == nil || *entry.Type != 12 || entry.Stats == nil {
+ if entry.Type == nil || *entry.Type != 12 || entry.Stats == nil || len(*entry.Stats) == 0 {
return false
}
- var total uint32
for _, weight := range *entry.Stats {
- if weight[0] < 100 || weight[0] > 168 || weight[1] == 0 || weight[1] > 100 {
+ // Native ratings divide each term by 100; weights need not sum to 100.
+ if weight[0] != 54 && (weight[0] < 100 || weight[0] > 168) || weight[1] == 0 || weight[1] >= 0x80000000 {
return false
}
- total += weight[1]
}
- if total != 100 {
+ case 6:
+ if section.Subtype != 27 || section.Stats == nil || len(*section.Stats) < 1 || len(*section.Stats) > 2 {
return false
}
- case 6:
- if section.Subtype != 27 || section.Stats == nil || !slices.Equal(*section.Stats, [][2]uint32{{12, 0}}) && !slices.Equal(*section.Stats, [][2]uint32{{12, 0}, {13, 0}}) {
+ // Preserve the original getter list; recognize unique zero-default keys.
+ var seen uint32
+ for _, value := range *section.Stats {
+ if value[0] < 12 || value[0] > 13 || value[1] != 0 || seen&(1<<(value[0]-12)) != 0 {
+ return false
+ }
+ seen |= 1 << (value[0] - 12)
+ }
+ if seen&1 == 0 {
return false
}
case 22:
@@ -105,7 +116,14 @@ func statBuffNano(program uint32) bool {
return false
}
effectTarget = target
- if function.ID == 53012 {
+ if function.ID == 53057 {
+ // HeadText is executed by the client with its authored text and color.
+ if function.HeaderWords != [2]uint32{0, 4} || function.ArgumentHeader != 9 || len(function.Arguments) != 2 ||
+ function.Arguments[0].String == nil || function.Arguments[1].Integer == nil {
+ return false
+ }
+ continue
+ } else if function.ID == 53012 {
// Skill has a third serialized word; only authored zero is admitted.
if len(function.Arguments) != 3 || function.Arguments[2].BytesHex == nil || *function.Arguments[2].BytesHex != "00000000" {
return false
@@ -122,7 +140,7 @@ func statBuffNano(program uint32) bool {
if value <= 0 {
return false
}
- case 318, 381, 382:
+ case 51, 318, 381, 382:
default:
if stat < 100 || stat > 168 || value <= 0 {
return false
@@ -134,7 +152,7 @@ func statBuffNano(program uint32) bool {
return false
}
}
- return hasEffect
+ return hasEffect && (flags != 0x1c000 || effectTarget == 2)
}
func selfOnlyNano(program uint32) bool {
diff --git a/server/self_nano_test.go b/server/self_nano_test.go
@@ -120,6 +120,9 @@ func TestSelfAndCriticalNanosUploadCastRestoreAndCancelCompleteContracts(t *test
func TestSelfOnlyNanosRedirectEverySuppliedTargetToTheCaster(t *testing.T) {
fixtures := selfAndCriticalNanoFixtures(t)
+ for _, fixture := range aggDefNanoFixtures() {
+ fixtures = append(fixtures, selfAndCriticalNanoFixture{Program: fixture.program, NanoCost: fixture.debit, SelfOnly: true})
+ }
for _, fixture := range combatNanoFixtures(t) {
if fixture.Target == 2 {
fixtures = append(fixtures, selfAndCriticalNanoFixture{Program: fixture.Program, Profession: fixture.Profession,
diff --git a/server/stat_buff_catalog_test.go b/server/stat_buff_catalog_test.go
@@ -75,6 +75,10 @@ func TestStatBuffCatalogAdmitsOnlyCompleteOrdinaryContracts(t *testing.T) {
expectedCrystals = append(expectedCrystals, fixture.Crystal)
}
}
+ for _, fixture := range aggDefNanoFixtures() {
+ expectedPrograms = append(expectedPrograms, fixture.program)
+ expectedCrystals = append(expectedCrystals, fixture.crystal)
+ }
slices.Sort(expectedPrograms)
slices.Sort(expectedCrystals)
@@ -92,10 +96,10 @@ func TestStatBuffCatalogAdmitsOnlyCompleteOrdinaryContracts(t *testing.T) {
slices.Sort(crystals)
// Exact IDs come from the independent complete-original-record catalog audit.
- if len(programs) != 467 || !slices.Equal(programs, expectedPrograms) {
+ if len(programs) != 470 || !slices.Equal(programs, expectedPrograms) {
t.Fatal("buff admission differs from the complete effect/metadata audit", programs)
}
- if len(crystals) != 465 || !slices.Equal(crystals, expectedCrystals) {
+ if len(crystals) != 468 || !slices.Equal(crystals, expectedCrystals) {
t.Fatal("crystal admission differs from the complete upload audit", crystals)
}
}
@@ -320,7 +324,7 @@ func TestStatBuffCastRejectsIncompleteOrSpecialContractsWithoutDebit(t *testing.
modes := [][2]uint32{{12, 3}}
definition.Sections[1].Stats = &modes
case "bad weights":
- weights := [][2]uint32{{127, 55}, {128, 55}}
+ weights := [][2]uint32{{999, 100}}
entries := slices.Clone(*definition.Sections[0].Entries)
entries[0].Stats = &weights
definition.Sections[0].Entries = &entries