aorecomp

Anarchy Online classic in the browser

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


commit b259aaf9677d37a042839a8424b85c866cb7edd7
parent 25e6773e662bda8aeed9c5fd82f29a4fa585245a
Author: anon <anon@example.com>
Date:   Sat, 24 Oct 2026 09:04:45 +0000

Support Doctor startup crystal uploads

Diffstat:
MTODO.md | 6++++++
Mdocs/first-aid.md | 10++++++++++
Adocs/nano-healing.md | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/nano-learning.md | 5+++++
Mserver/backpacks.go | 18+++++++++++-------
Aserver/nano_healing_test.go | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/nano_learning.go | 5+++++
Mtools/data/extract_nano_learning.py | 4++--
8 files changed, 230 insertions(+), 9 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -426,8 +426,14 @@ checks are recorded in [treatment kits](docs/treatment-kit.md). - [x] Learn one nano program. Check: consuming its crystal adds a persistent native program entry and cannot learn or consume it twice accidentally. + The Doctor startup crystal now uploads Improved Healing with its exact + skill/profession gates; healing execution remains separate and unfinished. + See [Doctor healing](docs/nano-healing.md). - [ ] Cast one self-heal. Check: cast time, nano cost, health gain and recharge agree with the chosen program and appear correctly in the native client. + The common-message scheduling lead is now ruled out: AttackInfo and + HealthDamage activate immediately, without an impact clock or weapon fence. + Resolve combat health delivery rather than limiting healing to idle use. - [ ] Cancel an in-progress cast. Check: the applicable cancellation/refund rule is followed and no delayed heal or duplicate result occurs. - [x] Cast one direct-damage program on a creature. Check: target validation, diff --git a/docs/first-aid.md b/docs/first-aid.md @@ -159,6 +159,16 @@ corrected candidate analysis are in `local/weapon-impact-research/`. The test browsers, temporary server and two owned characters were cleaned up, and the ordinary preview was restored on the default ports. +A further pass traced common message scheduling in the original `llr.dll`. +AttackInfo and HealthDamage both use an immediately ready base PollStatus; +their activations run in FIFO order before the frame's root update. The common +remote-info base carries no execution clock or weapon-impact barrier. The +Anarchy input throttle handles bulk snapshots, without waiting for weapon +results. Batching messages cannot supply the missing ordering against future +animation callbacks. Exact targets, procedures, evidence and limitations are +in `local/weapon-impact-research/common-dispatch.md`; both owned sessions were +closed. This excludes that specific lead, not every possible healing route. + Public implementation comparisons also leave delivery unresolved. [CellAO's 2016 Hit implementation](https://github.com/CellAO/CellAO-NightPredator/blob/ca77f375a7dabe3be769da94e6c2a3d093344c2c/CellAO/Server/ZoneEngine/Core/Functions/GameFunctions/hit.cs#L112-L153) changes the base health stat and relies on an absolute dirty-stat flush; the diff --git a/docs/nano-healing.md b/docs/nano-healing.md @@ -0,0 +1,71 @@ +# Doctor startup healing research + +The QL 1 Doctor startup crystal 28778 uploads Improved Healing 28665. Upload +uses the same atomic learned-program/consumption path as the other supported +crystals. Both crystal and program require effective Biological +Metamorphosis 128 above 8, Matter Metamorphosis 127 above 6 and Visual +Profession 368 equal to 10. Skill weights are 80% Intelligence / 20% Psychic. +With abilities of 10, trained BM 7 / MM 5 gives effective 9 / 7. A duplicate upload +retains its crystal and the single existing program entry. + +The original 14.9.1 resource gives program 28665 a selected-target Hit 53002 +with arguments `[27,16,30,0]`: 16 through 30 health. Authored cost 407 is 14, +execution 294 is 250 centiseconds, recharge 210 is 250 centiseconds and range +287 is 20 metres. These are definitions, not proof of the original server's heal +roll or debit policy. `tools/data/extract_nano_learning.py` retains both exact +records and their payload hashes in the local nano-learning report. + +Only learning is implemented. Healing casts remain disabled until health +updates work during incoming weapon combat. The unresolved delivery issue +and rejected approaches are in [First Aid](first-aid.md); the self-heal TODO +remains open. A crystal's upload effects do not apply its learned heal. + +## Common message scheduling + +A native follow-up checked whether common message scheduling could defer an +absolute health update until previously announced weapon damage had landed. +In the original shared dependency `llr.dll`, remote-info construction and +serialization carry class key, destination identity, pass-on flag and subclass +bytes. They supply no common execution timestamp or impact fence. + +AttackInfo and HealthDamage both use the base PollStatus, which immediately +returns ready. The engine activates eligible messages in FIFO order before +its root update. Batching these packets together therefore does not place +health assignment after a later animation callback. The Anarchy engine's +input throttle handles bulk character/playfield snapshots; it does not wait +for weapon impacts. This closes that specific lead and leaves the original +server's damage-resolution and healing exchange unresolved. + +Original target hashes, procedure addresses, exact evidence IDs, failed +lookups and complete exports are retained in +`local/weapon-impact-research/common-dispatch.md` and the adjacent KKR/LLR +bundles. Both owned native analysis sessions were closed. This is static +analysis, not an original-server capture. + +A public [server-traffic dataset paper](https://web-backend.simula.no/sites/default/files/publications/Simula.simula.1162.pdf) +was also checked. Section 3 explicitly states that only network headers were +captured; it contains no gameplay payload to resolve this question. The +visible [AOCapture source tree](https://github.com/philippelatulippe/AOCapture) +provides a packet parser and preservation plan, without a correlated heal +capture. These bounded findings do not establish that no suitable recording +exists elsewhere. + +## Verification + +Go tests cover exact BM/MM boundaries, profession and quality rejection, +duplicate use, failed writes, failed COMMIT, concurrent uploads, private +delivery and reload before any checkpoint. The shared crystal, medical-item +and backpack tests also cover the owned-item dispatch change. The full Go +suite, focused race checks and vet passed. + +Two hardware Chromium WASM clients verified native rejection at BM 8, +upload at BM 9/MM 7, one consumed crystal, one private program entry and +preservation of the spare on a duplicate request. The native success/rejection +acknowledgements were 1 and 2. Owner reconnect and an actual server restart +restored the learned entry and spare crystal. The observer kept its empty +learned list. Both runs had no client errors. + +Screenshots, native probes, wire verification, SQL snapshots and cleanup +checks are retained under `local/healing-upload-smoke/`. Only owned test +characters and items were removed; unrelated rows were unchanged. The +published WASM bundle was unchanged. diff --git a/docs/nano-learning.md b/docs/nano-learning.md @@ -8,6 +8,11 @@ Winter's Bite uses the same upload route for Bureaucrat crystal 29625 and program 29618. Its requirements and supported damage cast are documented in [nano damage](nano-damage.md). +The QL 1 Doctor startup crystal 28778 uploads Improved Healing 28665 through +the same atomic path. It requires effective Biological Metamorphosis above 8, +Matter Metamorphosis above 6 and Doctor profession 10. Healing casts are still +unfinished; catalog and delivery limits are in [Doctor healing](nano-healing.md). + QL 7 Nano Crystal (Strength Boost) 27305 uploads QL 3 program 27169. It requires effective Biological Metamorphosis 128 greater than 34 and Matter Metamorphosis 127 greater than 40, with no profession requirement. Both diff --git a/server/backpacks.go b/server/backpacks.go @@ -80,19 +80,23 @@ func (server *server) handleOwnedItemUse(client *worldClient, body []byte) error client.useSequence = sequence if binary.BigEndian.Uint32(body[40:44]) == 104 { index := slices.IndexFunc(player.inventory.Items, func(item ownedItem) bool { - return item.Slot == binary.BigEndian.Uint32(body[44:48]) && (item.Template == 43552 || item.Template == 85366 || item.Template == 25812 || item.Template == 43330 || item.Template == 29625 || abilityNanoCrystalProgram(item.Template) != 0) + return item.Slot == binary.BigEndian.Uint32(body[44:48]) }) if index >= 0 { - if player.inventory.Items[index].Template == 43330 || player.inventory.Items[index].Template == 29625 || abilityNanoCrystalProgram(player.inventory.Items[index].Template) != 0 { + switch player.inventory.Items[index].Template { + case 43330, 29625, 28778: return server.learnNano_locked(client, index, body) - } - if player.inventory.Items[index].Template == 85366 { + case 85366: return server.useNanoKit_locked(client, index, body) - } - if player.inventory.Items[index].Template == 25812 { + case 25812: return server.useTreatmentKit_locked(client, index, body) + case 43552: + return server.useClinic_locked(client, index, body) + default: + if abilityNanoCrystalProgram(player.inventory.Items[index].Template) != 0 { + return server.learnNano_locked(client, index, body) + } } - return server.useClinic_locked(client, index, body) } } slot := binary.BigEndian.Uint32(body[44:48]) diff --git a/server/nano_healing_test.go b/server/nano_healing_test.go @@ -0,0 +1,120 @@ +package main + +import ( + "encoding/binary" + "slices" + "sync" + "testing" +) + +func newHealingCrystalWorld(t *testing.T) (*server, *combatTestConn) { + t.Helper() + world, conn := newNanoLearningWorld(t) + player := world.characters[1] + player.profession = 10 + player.stats.NanoAiding.BiologicalMetamorphosis = 7 + player.stats.NanoAiding.MatterMetamorphosis = 5 + player.inventory.Items = nil + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if ok, err := world.grantItem_locked(player, 28778); err != nil || !ok { + t.Fatal(ok, err) + } + return world, conn +} + +func TestHealingCrystalUploadCommitsProgramAndConsumption(t *testing.T) { + world, conn := newHealingCrystalWorld(t) + observer := &combatTestConn{} + world.characters[2] = &character{id: 2, playfield: 950, health: 100} + world.clients[2] = &worldClient{id: 2, conn: observer, ready: true, target: true} + + err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 64, 1)[20:]) + restored := newTestInventoryServer(t).characters[1] + + if err != nil || restored.profession != 10 || !slices.Equal(restored.inventory.LearnedNanos, []uint32{28665}) || len(restored.inventory.Items) != 0 || + len(conn.packets) != 3 || len(observer.packets) != 0 { + t.Fatalf("heal upload: err=%v profession=%d learned=%v items=%+v packets=%d observer=%d", err, restored.profession, restored.inventory.LearnedNanos, restored.inventory.Items, len(conn.packets), len(observer.packets)) + } + if binary.BigEndian.Uint32(conn.packets[0][29:33]) != 1 || binary.BigEndian.Uint32(conn.packets[1][29:33]) != 28778 || + binary.BigEndian.Uint32(conn.packets[1][37:41]) != 1 || binary.BigEndian.Uint32(conn.packets[2][41:45]) != 28778 { + t.Fatal("heal crystal upload used the wrong native template, quality or consumption reply") + } +} + +func TestHealingCrystalUploadRejectsInvalidRequirements(t *testing.T) { + for _, scenario := range []string{"BM 8", "MM 6", "profession", "quality", "already known", "failed save", "commit"} { + t.Run(scenario, func(t *testing.T) { + world, conn := newHealingCrystalWorld(t) + player := world.characters[1] + switch scenario { + case "BM 8": + player.stats.NanoAiding.BiologicalMetamorphosis = 6 + case "MM 6": + player.stats.NanoAiding.MatterMetamorphosis = 4 + case "profession": + player.profession = 1 + case "quality": + player.inventory.Items[0].Quality = 2 + case "already known": + player.inventory.LearnedNanos = []uint32{28665} + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + case "failed save": + failDatabaseWrites(t, world) + case "commit": + if _, err := world.db.Exec("CREATE TABLE pending_upload (player_id INTEGER REFERENCES players(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER reject_upload AFTER INSERT ON learned_nanos BEGIN INSERT INTO pending_upload VALUES (999999); END"); err != nil { + t.Fatal(err) + } + } + before := len(player.inventory.LearnedNanos) + + err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 64, 1)[20:]) + restored := newTestInventoryServer(t).characters[1] + + if len(player.inventory.Items) != 1 || len(restored.inventory.Items) != 1 || len(player.inventory.LearnedNanos) != before || len(restored.inventory.LearnedNanos) != before { + t.Fatal("rejected upload consumed the crystal or learned the program") + } + if scenario == "failed save" || scenario == "commit" { + if err == nil || len(conn.packets) != 0 { + t.Fatal("failed upload published success", err) + } + } else if err != nil || len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][29:33]) != 2 { + t.Fatal("invalid upload did not reject natively", err) + } + }) + } +} + +func TestHealingCrystalConcurrentUsesConsumeOnlyOne(t *testing.T) { + world, conn := newHealingCrystalWorld(t) + if ok, err := world.grantItem_locked(world.characters[1], 28778); err != nil || !ok { + t.Fatal(ok, err) + } + var uses sync.WaitGroup + + for _, slot := range []uint32{64, 65} { + uses.Go(func() { + if err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, slot, slot)[20:]); err != nil { + t.Error(err) + } + }) + } + uses.Wait() + restored := newTestInventoryServer(t).characters[1] + + if !slices.Equal(restored.inventory.LearnedNanos, []uint32{28665}) || len(restored.inventory.Items) != 1 { + t.Fatal("concurrent uploads lost the spare crystal or duplicated the program") + } + uploads := 0 + for _, packet := range conn.packets { + if binary.BigEndian.Uint32(packet[16:20]) == 0x35505644 { + uploads++ + } + } + if uploads != 1 { + t.Fatal("concurrent uses published duplicate upload effects") + } +} diff --git a/server/nano_learning.go b/server/nano_learning.go @@ -30,6 +30,11 @@ func (server *server) learnNano_locked(client *worldClient, index int, body []by var program uint32 accepted := item.Type == 51005 && item.Slot >= 64 && item.Slot < 94 switch item.Template { + case 28778: + program = 28665 + accepted = accepted && item.Quality == 1 && player.profession == 10 && + player.effectiveSkill(128, stats.NanoAiding.BiologicalMetamorphosis, [6]uint32{0, 0, 0, 80, 0, 20}) > 8 && + player.effectiveSkill(127, stats.NanoAiding.MatterMetamorphosis, [6]uint32{0, 0, 0, 80, 0, 20}) > 6 case 29625: program = 29618 accepted = accepted && item.Quality == 1 && player.profession == 8 && diff --git a/tools/data/extract_nano_learning.py b/tools/data/extract_nano_learning.py @@ -18,11 +18,11 @@ def main(): (1000020, 27305), (1040005, 27169), (1000020, 26469), (1040005, 26342), (1000020, 26487), (1040005, 26360), (1000020, 27217), (1040005, 27086), (1000020, 27270), (1040005, 27134), (1000020, 27290), (1040005, 27154), - (1000020, 27304), (1040005, 27168)): + (1000020, 27304), (1040005, 27168), (1000020, 28778), (1040005, 28665)): raw = database.read(kind, identity) item = extract_items.parse_item(raw, kind, identity) records.append(dict(record=item, payload_sha256=hashlib.sha256(raw).hexdigest())) - assert [record['record']['quality'] for record in records] == [1, 1, 1, 1, 7, 3, 7, 3, 4, 2, 7, 3, 7, 3, 7, 3, 7, 3] + assert [record['record']['quality'] for record in records] == [1, 1, 1, 1, 7, 3, 7, 3, 4, 2, 7, 3, 7, 3, 7, 3, 7, 3, 1, 1] assert records[0]['record']['header_words'][0] == 51005 assert records[1]['record']['header_words'][0] == 51051