commit 19224e2f58703d65d4d98061147cfb00c150f790
parent 4b2a3d1fa42512a99f11b20243e4e4b332c8711d
Author: anon <anon@example.com>
Date: Sun, 1 Nov 2026 22:25:22 +0000
Execute authored text-only world item Use callbacks
Diffstat:
5 files changed, 280 insertions(+), 3 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -2052,6 +2052,14 @@ client rendering fixes and checks are in [nano damage](docs/nano-damage.md).
effects. The original book's right-click emits GenericCmd action3, while its
explicit R/Pick Up emits InventoryMove; preserve that distinction and resolve
actual instances before the existing type51005 terminal handling.
+ Complete immediate HeadText-only contracts now use that original callback,
+ with actual instance/assignment/range/criteria checks and whole-contract
+ rejection. The book's original cyan text is visible after ordinary native
+ Use, and three successive Uses preserve the same floor instance and all
+ player state. Both page reconnects, separate R/Pick Up, exact-book hand-in
+ and cold recovery conserve all 37 final owned items, with 803 credits and
+ unchanged XP/IP/vitals/supplies. Other world-item effects remain unsupported.
+ See [world-item Use](docs/mission-objectives.md#pickup-protocol).
- [x] Populate the fixed mission through shared admitted NPC profiles. Acceptance
commits five concrete level-1 Leets with the assignment and key; reconnect,
reentry and cold load retain those lives without re-reading a spawn recipe.
diff --git a/docs/mission-objectives.md b/docs/mission-objectives.md
@@ -34,9 +34,64 @@ with the book selected:
| Requested destination slot | 111, automatic inventory placement |
Right-clicking this usable book emits GenericCmd action3 instead. Treating that
-Use request as a pickup would conflate distinct native actions. Existing terminal
-handling denies that unsupported world-item Use; descriptor-driven world-item
-Use is still open work.
+Use request as a pickup would conflate distinct native actions. World-item Use
+now resolves the actual floor instance before the ordinary terminal path. It
+admits a complete immediate HeadText contract through the original callback;
+other world-item effect contracts remain unsupported rather than partially
+executing their known functions.
+
+The original Blue Book payload has SHA-256
+`645b946ec12830a3695e1c27659dc37676dbc2b884cb1f19e4fda1692e7066fe`.
+Its sole Use function is HeadText53057(`Heh. Nice...`,2), targeting the user.
+The original successful Use path `kkr.dll`1004d880 ->1004c9f0 resolves a
+world SimpleItem and invokes its action3 callback. Base dispatcher1009e0c0
+then calls virtual+0x58 ->1009fc80 ->100902b0, which executes the authored
+effect. An extra owner TemplateAction would execute that effect again.
+Native quantity handling also runs in this callback; server conservation alone
+does not prove the item's native lifetime.
+
+Admission checks the current session, life/loading state, actual assignment,
+expiry, fixed QL, one physical instance, the original item flags, Use
+permission/criteria and the existing five-metre world interaction range.
+Open trade/shop/bank and pending equipment operations reject Use.
+No item, credit, progress or reward changes are needed
+for this presentation-only contract. Replayed sequences have no second callback.
+The numeric range remains current interaction policy, not a recovered original
+server formula. Static resources and other effects are not admitted by this
+text-only contract.
+
+Thirty related Go test roots and 190 results pass normally and under the race
+detector; vet passes. The new positive regression fails against the old terminal
+routing, then passes with exact acknowledgements, repeated Use, cold floor
+conservation and subsequent pickup. Rejection cases cover invalid placements,
+sessions, expired assignments and incomplete effects. Original payload rereads,
+26 complete retained REA records, selected callback bodies and verification
+logs are under `local/world-item-use/`.
+
+An ordinary earned level-seven Enforcer accepted its first neutral-difficulty
+offer for seven credits and reached book 282 in private world 65566 without
+combat, grants or edited poses. Three actual right-click Uses received matching
+success replies; the original cyan text is visible above the player in
+`native-20261101-140759/world-use-clear-effect-view/0/screen.png` under that
+evidence directory. The same native book remained present, rendered and pickable.
+Inventory, XP, IP, vitals, mission state and cash stayed unchanged across all
+three Uses. Both page reconnects retained it. Explicit R/Pick Up then transferred
+that exact book to inventory slot 78, retaining its QL1 template pair and count 1.
+The known initial zero type/id on its simple inventory proxy is checked
+separately from the exact world request/reply and physical ledger.
+
+Returning it to the real issuing booth consumed only book 282/key 281, delivered
+the promised QL7 sleeve 283 and paid 20 credits. The final wallet is 803, with
+30 owner items and seven observer items. No kills, XP, skill, health or supply
+changes occurred. Independent SQL checks conserve all 110 prior item/location
+records plus the reward, all old mission/encounter rows and unrelated wallets.
+The five new level-seven encounters remain alive. Fresh server/client startup
+and both page reconnects retain all 37 owned instances with permanent native
+identities, trained stats, wallets and six completed contracts. Integrity and
+foreign-key checks pass; owned test clients and temporary servers closed.
+See `hot-use-verified.json`, `pickup-verified.json`, `handin-verified.json` and
+`cold-verified.json` in `local/world-item-use/`. Other world-item effects and
+original-server publication/range policy remain separate work.
Pickup checks the current session, life/loading state, private assignment,
expiry, original Carry permission, five-metre three-dimensional distance,
diff --git a/server/insurance.go b/server/insurance.go
@@ -31,6 +31,10 @@ func (server *server) handleTerminalUse(client *worldClient, body []byte) error
return nil
}
client.useSequence = sequence
+ if placement, exists := server.worldItems[binary.BigEndian.Uint32(body[44:48])]; exists && binary.BigEndian.Uint32(body[40:44]) == 51005 {
+ defer server.mutex.Unlock()
+ return server.useWorldItem_locked(client, body, placement)
+ }
// Shipped statel 51005:0xc00202c1 uses Omni-Med template 117665.
position := predictedPosition_locked(player, time.Now())
diff --git a/server/world_item_use_test.go b/server/world_item_use_test.go
@@ -0,0 +1,157 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "encoding/binary"
+ "reflect"
+ "slices"
+ "testing"
+ "time"
+)
+
+func worldItemUseRequest(sequence uint32) []byte {
+ request := missionBoothUseRequest(3, sequence)
+ binary.BigEndian.PutUint32(request[40:44], 51005)
+ return request
+}
+
+func TestWorldItemUsePreservesObjectiveAndAllowsPickup(t *testing.T) {
+ world, client, output := enteredObjectiveWorld(t)
+ before := world.characters[1].userData()
+ record, placement := world.items[3], world.worldItems[3]
+ request := worldItemUseRequest(1)
+
+ if err := world.handleTerminalUse(client, request); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleTerminalUse(client, request); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleTerminalUse(client, worldItemUseRequest(2)); err != nil {
+ t.Fatal(err)
+ }
+ cold := reloadMissionEntranceWorld(t)
+ inventory := world.characters[1].inventory
+ inventory.LastID = 3
+
+ if len(output.packets) != 2 || !reflect.DeepEqual(before, world.characters[1].userData()) ||
+ !reflect.DeepEqual(world.items[3], record) || world.worldItems[3] != placement || !reflect.DeepEqual(cold.items[3], record) || cold.worldItems[3] != placement ||
+ !reflect.DeepEqual(cold.characters[1].inventory, inventory) || world.nextItem != 3 || cold.nextItem != 3 ||
+ cold.characters[1].missions[0].completed || cold.characters[1].missions[0].objective != 3 {
+ t.Fatal("world Use moved, consumed, rewarded or duplicated the objective", output.packets)
+ }
+ for index, packet := range output.packets {
+ if binary.BigEndian.Uint32(packet[16:20]) != 0x52526858 || binary.BigEndian.Uint32(packet[29:33]) != 1 ||
+ binary.BigEndian.Uint32(packet[33:37]) != uint32(index+1) || binary.BigEndian.Uint32(packet[53:57]) != 51005 ||
+ binary.BigEndian.Uint32(packet[57:61]) != 3 {
+ t.Fatal("world Use did not acknowledge the exact sequence and world identity", packet)
+ }
+ }
+
+ if err := world.handleInventory(client, worldPickupRequest(1, 3)); err != nil {
+ t.Fatal(err)
+ }
+ cold = reloadMissionEntranceWorld(t)
+
+ if len(world.worldItems) != 0 || len(cold.worldItems) != 0 || world.nextItem != 3 || cold.nextItem != 3 ||
+ !slices.Contains(cold.characters[1].inventory.Items, ownedItem{ID: 3, Type: 51005, Template: 40822, Quality: 1, Slot: 66, Count: 1}) {
+ t.Fatal("ordinary pickup after Use lost the original objective")
+ }
+}
+
+func TestWorldItemUseRejectsInvalidPlacementAndIncompleteEffects(t *testing.T) {
+ for _, scenario := range []string{"range", "vertical range", "wrong world", "expired", "resource", "quality", "quantity", "type", "quantity flags",
+ "trading", "equipping", "shopping", "banking", "unsupported effect", "conditional effect", "delayed effect", "wrong target",
+ "extra section", "Use requirement", "forged sender", "replay", "stale session", "loading", "dead"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, client, output := enteredObjectiveWorld(t)
+ player := world.characters[1]
+ request, silent := worldItemUseRequest(1), false
+ original := gamedata.ItemTemplates[40822]
+ definition := *original
+ definition.Stats = slices.Clone(original.Stats)
+ definition.Sections = slices.Clone(original.Sections)
+ functions := slices.Clone(*original.Sections[0].Functions)
+ definition.Sections[0].Functions = &functions
+ gamedata.ItemTemplates[40822] = &definition
+ t.Cleanup(func() { gamedata.ItemTemplates[40822] = original })
+ switch scenario {
+ case "range":
+ player.position[0] += 5.01
+ case "vertical range":
+ player.position[1] += 5.01
+ case "wrong world":
+ player.playfield++
+ case "expired":
+ world.missionWorld_locked(player.playfield).expiresAt = time.Now().Add(-time.Second)
+ case "resource":
+ placement := world.worldItems[3]
+ placement.resource = 1
+ world.worldItems[3] = placement
+ case "quality", "quantity", "type":
+ record := world.items[3]
+ if scenario == "quality" {
+ record.Quality = 2
+ } else if scenario == "quantity" {
+ record.Count = 2
+ } else {
+ record.Type = 51022
+ }
+ world.items[3] = record
+ case "trading":
+ client.trade = &playerTrade{}
+ case "quantity flags":
+ for index := range definition.Stats {
+ if definition.Stats[index][0] == 0 {
+ definition.Stats[index][1] |= 0x400000
+ }
+ }
+ case "equipping":
+ client.equipment = &equipmentMove{}
+ case "shopping":
+ client.shop = &shopTrade{}
+ case "banking":
+ client.bank = &bankSession{}
+ case "unsupported effect":
+ functions[0].ID = 53002
+ case "conditional effect":
+ functions[0].Requirements = []gamedata.ItemRequirement{{Stat: 54, Operator: 2, Value: 1}}
+ case "delayed effect":
+ functions[0].TickInterval = 1
+ case "wrong target":
+ functions[0].Target = 3
+ case "extra section":
+ definition.Sections = append(definition.Sections, gamedata.ItemSection{Type: 99})
+ case "Use requirement":
+ actions := []gamedata.ItemAction{{Type: 3, Requirements: []gamedata.ItemRequirement{{Stat: 54, Operator: 2, Value: 1}}}}
+ definition.Sections = append(definition.Sections, gamedata.ItemSection{Type: 22, Subtype: 36, Actions: &actions})
+ case "forged sender":
+ binary.BigEndian.PutUint32(request[8:12], 2)
+ silent = true
+ case "replay":
+ client.useSequence, silent = 1, true
+ case "stale session":
+ world.clients[1], silent = &worldClient{}, true
+ case "loading":
+ client.loading, silent = true, true
+ case "dead":
+ player.health, silent = 0, true
+ }
+ before := player.userData()
+ record, placement := world.items[3], world.worldItems[3]
+
+ err := world.handleTerminalUse(client, request)
+
+ if err != nil || !reflect.DeepEqual(before, player.userData()) || !reflect.DeepEqual(world.items[3], record) || world.worldItems[3] != placement {
+ t.Fatal("rejected world Use changed the player or item", err)
+ }
+ if silent {
+ if len(output.packets) != 0 {
+ t.Fatal("invalid session or replay received a success callback")
+ }
+ } else if len(output.packets) != 1 || binary.BigEndian.Uint32(output.packets[0][29:33]) != 2 {
+ t.Fatal("unsupported world Use did not reject the whole contract", output.packets)
+ }
+ })
+ }
+}
diff --git a/server/world_items.go b/server/world_items.go
@@ -15,6 +15,59 @@ type worldItem struct {
position [3]float32
}
+func supportedWorldItemUse(definition *gamedata.Item) bool {
+ if definition == nil || definition.Undecoded != nil || definition.HeaderWords[0] != 51005 ||
+ itemStat(definition, 0) != 0x80000003 || itemStat(definition, 30) != 9 {
+ return false
+ }
+ var effects bool
+ for _, section := range definition.Sections {
+ if section.Type == 22 && section.Subtype == 36 && section.Actions != nil {
+ for _, action := range *section.Actions {
+ if action.Type != 3 {
+ return false
+ }
+ }
+ continue
+ }
+ if section.Type != 2 || section.Subtype != 0 || section.Functions == nil {
+ return false
+ }
+ for _, function := range *section.Functions {
+ // HeadText executes through the original successful world Use callback.
+ if function.ID != 53057 || function.HeaderWords != [2]uint32{0, 4} || function.ArgumentHeader != 9 || function.Target != 2 ||
+ len(function.Requirements) != 0 || function.TickCount != 1 || function.TickInterval != 0 || len(function.Arguments) != 2 ||
+ function.Arguments[0].String == nil || function.Arguments[1].Integer == nil {
+ return false
+ }
+ effects = true
+ }
+ }
+ return effects
+}
+
+func (server *server) useWorldItem_locked(client *worldClient, body []byte, placement worldItem) error {
+ player := server.characters[client.id]
+ mission := server.missionWorld_locked(player.playfield)
+ record := server.items[binary.BigEndian.Uint32(body[44:48])]
+ definition := gamedata.ItemTemplates[record.Template]
+ accepted := client.target && client.equipment == nil && client.trade == nil && client.shop == nil && client.bank == nil &&
+ placement.resource == 0 && mission != nil && placement.mission == mission.id && time.Now().Before(mission.expiresAt) &&
+ record.Type == 51005 && record.Count == 1 && record.Ammo == 0 && supportedWorldItemUse(definition) &&
+ definition.Quality != nil && record.Quality == *definition.Quality && player.templateUseRequirementsMet(definition)
+ position := predictedPosition_locked(player, time.Now())
+ x, y, z := position[0]-placement.position[0], position[1]-placement.position[1], position[2]-placement.position[2]
+ accepted = accepted && x*x+y*y+z*z <= 25
+
+ // Use executes presentation without moving or rewarding the physical item.
+ reply := slices.Clone(body[16:])
+ binary.BigEndian.PutUint32(reply, 2)
+ if accepted {
+ binary.BigEndian.PutUint32(reply, 1)
+ }
+ return client.send(n3Packet(0x52526858, 50000, client.id, reply))
+}
+
func (server *server) worldScenePackets_locked(player *character) ([][]byte, error) {
packets, err := server.missionDoorPackets_locked(player)
if err != nil {