aorecomp

Anarchy Online classic in the browser

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


docs/corpse-loot.md (27653B)


Corpse and loot protocol

The server creates native corpses for killed NPCs with a recovered death animation. It handles opening, closing and reopening the loot window, validates pickup and persists the new owner before acknowledging the transfer. The fixed WASM test fixture supplies QL 1 Monster Parts after an actual server combat kill. Ordinary level 1 Leets now generate provisional Monster Parts and credits through shared NPC loot profiles. Their historical drop rates and the remaining production loot tables are unresolved.

Corpse creation

CorpseFullUpdateIIR_t (0x4f474e05) uses outer identity type 51050 and version 7. The native reader is kkr.dll sub_360AF9C0; activation is sub_360AFCB0. The original character identity appears inside the body. The corpse is a separate object, and activation hides the original actor. Prerequisite sub_360AFBC0 checks the original actor's death state. The warm transition needs the correct death animation key 6000, as described in the combat protocol. Cold replay without an original actor update is separately verified for the Stalker below.

The decoded body has this order; integers are network-order uint32 unless specified otherwise:

  1. Corpse version 7.
  2. SimpleItem version 11, parent identity, and, for parent type zero, position XYZ and quaternion XYZW as float32 values.
  3. Playfield, auxiliary identity, then two individual page/placement bytes.
  4. Stat-pair list with encoded length (count + 1) * 1009, followed by pairs.
  5. Extra-data byte length and raw bytes. A NUL-terminated name here supplies Remains of Loot Target in the verified fixture.
  6. Lockable version 2, lock field, encoded identity list; Chest version 3.
  7. Encoded creation-event function list, original actor identity, encoded ClothData list.
  8. Additional-texture-list presence integer and optional texture list.
  9. Team, loot mode, looter identity, XP reward count and optional reward entries.

The SimpleItem reader and activation are sub_360B2440 and sub_360B2830. The raw name is applied by sub_36090D90 and returned by sub_36090DF0. An empty name falls back to template lookup and can produce NameMissing. ClothData is clothing data, not a replacement for the corpse's base mesh. The creature's model belongs in stat 42 (CATMesh), with breed, sex and race in stats 4, 59 and 89. The verified Leet fixture uses model 15222, breed 6, sex 1, race 1, static mesh stat 12 equal to zero, scale stat 360 equal to 100, and CanChangeClothes stat 223 equal to zero. Merely copying MonsterData's mesh stat 12 into a SimpleItem does not establish an animated corpse. MultipleCount stat 26 is -1: native generic Use otherwise consumes the remains by setting their TimeExist stat to 1 (sub_3609FC80).

Creation animation

sub_360AF9C0 reads the creation-event function list through sub_360BD000 into event 10. Its length is (count + 1) * 1009. An empty list leaves the animated mesh without an animation: bbr.dll VisualCATMesh_t::RunFunction (0x25096dd0) returns -1 for an empty animation list, and llr.dll n3VisualDynel_t::Run (0x3803d500) substitutes default_mesh.abiff. Native WASM tracing confirmed successful model creation followed by this replacement, independently of the loot-window update.

One animation function prevents that replacement and holds the death pose. After the list length 2018, the verified Leet function has these uint32 words:

Field Value
Function identity type, instance 53003, 0
Function version, requirement count 4, 0
Common arguments 3, 4, 32, 35 1, 0, 0, 0xffffffff
Target type, target instance 51050, corpse ID
Animation resource 18107
Base-animation flag, argument 11 1, 0

Reader sub_360B9530 establishes version 4 and this argument order for type 53003. Dispatch sub_360BE8E0 calls sub_360BD850; its base-animation branch calls sub_36018550, which sets both animation start and stop to the resource's total time and starts it. Resource 18107 is the Leet's cutecreature_die-pain_01_01.ani, obtained from MonsterData 17655's key 6000. The creation function takes a resource ID, whereas the living actor's death action takes the MonsterData animation key. This wire-only fixture kept the correct fallen model visible without changing maintained client code.

tools/data/extract_monsters.py retains each MonsterData definition's key-6000 resources in server/gamedata/monsters.yaml. Corpse creation currently selects the first variant. Matching a living actor's randomly selected death variant is not yet implemented. Definitions without a recovered death resource do not create a corpse.

Correct animation and skeleton creation do not ensure visibility on slopes. The corpse pose audit reproduces the original Aquaan geometry and measures its burial under terrain; original placement policy remains open.

Contents and pickup

Native right-click use emits GenericCmdIIR_t (0x52526858). Its body is eight uint32 words: 0, sequence, 3, 1, 50000, playerID, 51050, corpseID. The request was captured by selecting and right-clicking the rendered Leet. Closing its loot window and then using the corpse again emitted the same layout with successive sequence values 1, 2 and 3. The close/open state and acknowledgement use command state 0 for requests, 1 for success and 2 for failure. The server acknowledges before sending the opening contents update. It retains one opened corpse per session and ignores repeated command sequences. Opening another corpse closes the previous native container first, preventing its identity-free pickup requests from referring to the replacement contents. In scripted WASM input, settle mouse motion before pressing the button so the native world picker uses the intended cursor position.

Closing also requires ActionIIR_t (0x2049527c), with the corpse as its outer identity and body 1, 102, 50000, playerID. The first word is version 1. Reader sub_360AEA40 and activation sub_360AEAA0 dispatch action 102 through sub_3608C6C0, sub_36097C30 and sub_3609ED70 to native Close. That removes the container registration through sub_36053160; an acknowledgement alone leaves the registration present and prevents the window from reopening. This is distinct from the CharacterAction message.

InventoryUpdateIIR_t (0x4e536976) starts directly with the encoded item list, using (count + 1) * 1009. There is no slot-count prefix in this client. Each 32-byte entry is slot, uint16 flags, uint16 count, item identity, low/high templates, quality and auxiliary value. Corpse item entries use flags 3, count 1 and auxiliary zero. Flag bit 0 selects the template-proxy transfer branch in sub_3602D710 and sub_3605FB40; flags 2 render an icon but leave pickup on an object-transfer branch requiring a separately instantiated item. The body ends with corpse identity, container index zero and an open flag. The final one opens the native loot window. The outer identity is the receiving player. Reader sub_360B0C20, activation sub_360B0CD0 and writer sub_360B0C80 establish this layout.

The fixture item is template 42640, QL 1, native type 51005: Monster Parts. Its icon and native details window were verified. This does not establish a historical drop rate or a production loot table.

Left-clicking the displayed item emits ContainerAddItem (0x47537a24): source identity (107, 0), target player identity (50000, playerID), and destination 111, the next-free-slot sentinel. The request contains no corpse identity. The server validates the session's opened corpse, loot entitlement, visibility, playfield and five-metre use range. It chooses an empty inventory slot and atomically saves ownership before removing the corpse item. Its ContainerAddItem response carries the chosen destination translated into the 14.9.1 inventory range. Native sub_36042750, sub_360614E0 and sub_3605FB40 transfer the template proxy and update the corpse window without a replacement contents update.

One left click on a corpse item already places it in inventory. The shipped cd_image/text/help/The Inventory Window.txt describes this automatic placement. Clicking the newly owned inventory item again picks it up onto the native mouse cursor; Escape returns it to its slot. A two-client level-2 Leet check confirmed the same item ID and slot before and after that cancellation, with no ownership change. This cursor state can otherwise look like a missing inventory item.

Failed saves, full inventory, stale sessions and unavailable items retain the previous owner. Repeated and concurrent requests cannot take the same item twice. Corpses, untaken contents and taken inventory survive reconnect and server restart in SQLite. Entitlement follows individual or aggregate team damage contribution as described below and in team loot. Leader/Alpha orders and their selected allocation policies are described in team loot. Public rights release remains separate work. Corpse credits describes known-amount cash collection and persistence. The level-1 Leet's corpse expiry is described below.

If the client still sees free space but the authoritative inventory is full, the refusal must cancel its pending pickup with CharacterAction146, page107 and the source slot, before refreshing the corpse contents. A contents refresh alone hides the icon and prevents the next mouse click from sending a request. The focused TestBrowserCorpsePickupRefusal fixture delays controlled filler additions, then banks one filler item. Real native clicks verify refusal and same-window retry; page replay and cold loading retain the first looter's 31 instances and the original corpse credit. This is controlled failure-path evidence, rather than earned-progression evidence.

Other open loot windows

An InventoryUpdate for an already open corpse does not remove rows absent from its new contents. Two entitled native members reproduced a selectable phantom: after member2 collected the only item, member1 received an empty update but a later click still emitted a pickup request. Neither durable ownership nor cash was duplicated; the stale native source remained usable until corrected.

Successful pickup now sends CharacterAction112/page107/exact source slot to other eligible open windows before refreshing their remaining contents. Both messages follow the ownership commit. A request for an already empty slot gets 146 to cancel its drag, then112 to remove the stale row, then the contents update. Full-inventory and pending-equipment refusals retain their actually owned source.

TestCorpsePeerPickupClearsOnlyTheCommittedSource verifies ignored-write retention, nonzero-slot removal, remaining contents and exact cold item/cash ownership. TestLootStaleSlotCancelsPickupWithoutDuplicatingTransfer checks the stale-request correction. TestBrowserCorpsePeerPickupClearsNativeSource uses two native clients and one controlled corpse: member2 collects during member1's real mouse gesture; release and another click must emit no phantom pickup. The window stays open, page replay retains exact identity/quality/count/location, and Go cold loading accounts for the item, both wallets and the allocator. This is controlled-fixture evidence, not earned progression or historical loot probability. Captures and the baseline are in local/corpse-peer-pickup/. The related Go suite passes121 roots/672 results in168.645 seconds; race checks pass11 roots/19 results in133.787 seconds. The final native check passes in25.63 seconds, compared with the16.06-second failing baseline. All six baseline/final captures have no native errors or dropped events. Vet and driver syntax pass.

A pickup arriving during an admitted equipment move also receives CharacterAction146 and refreshed contents, without changing the equipment deadline or closing the corpse. Ignoring it leaves the native source icon dummy/hidden. TestBrowserLootDuringEquipment reproduces this using explicit axe placement and a real corpse pickup after the local equip animation ends, with server completion held at a controlled checkpoint. After refusal restores the icon, the original move completes and a same-window retry transfers the exact part once. Native page replay and cold store loading retain both instances. This preserves the current busy refusal policy; original-server permission for concurrent looting and equipping remains an evidence gap.

An eligible pickup of an already-taken slot also needs CharacterAction146 and fresh contents, while retaining the usable window. The fixture withholds one looter's refresh during a teammate's real pickup, then checks that the stale click transfers nothing and refreshes only the remaining loot. Both picked parts remain native after corpse removal and match page/cold ownership.

When an open corpse window becomes unusable through expiry, distance, lost visibility or lost rights, pickup cancels its pending page107 move and closes the window with ActionIIR102. Closing the view preserves the previous owner; the normal expiry transaction retires untaken items. The native fixture also expires a second part before the cleanup tick, verifies the late pickup and reopen refusals, then checks removal for both observers and cold retirement of only that untaken instance. The 32 owned instances and credit remain intact.

The two-player pickup check uses a kill by one entitled player. TestLootConcurrentPlayersHaveOnePersistentOwner releases two authenticated players' requests together, including a stale or forged container handle for the competitor. Only the entitled request publishes a transfer; the competitor's stale window closes after rejection. The single item remains owned after loading both inventories from disk. The existing same-session duplicate-request test covers repeated eligible claims.

Two WASM clients also sent native pickup requests for corpse slot 0 in the same logged second. The competitor's request arrived first. A fixture supplied its stale open loot window, while the server retained the killer's rights. The killer alone acquired Monster Parts item 201, Count 1, and the corpse slot became empty. Both native inventories agreed with the server: the killer's item occupied native slot 48, while the competitor's inventory was empty. Both page reconnects and a server restart preserved those inventories; native probes after restart still found exactly one copy. The run had no page exceptions or adapter failures. Refused socket connections occurred during the intentional server restart. This verifies pickup serialization and ownership checks, not historical public or team loot eligibility. Captures and read-only native inventory probes are retained in local/loot-race-smoke/.

Individual loot rights

The shipped cd_image/text/tips/OnSelectRemains.txt assigns loot to the player or team inflicting the majority of damage. The contemporary Vampi guide, whose header says final update 13 September 2001, describes the most-damage player receiving rights, while qualifying its observations. A later official FAQ also defines the killing team by most damage. Neither supplies a controlled three-contender result or an equal-damage tie rule.

The server accumulates each solo player's or team's applied HP damage for one NPC life and grants rights to the greatest contributor. Overkill contributes only remaining HP. Stopping and restarting attacks does not erase damage. Departure, death or a playfield change does not transfer an existing lead to another player; opening and taking still require the entitled player to be alive, connected, ready, nearby and in the same playfield. Respawn creates a new identity with no inherited contributions. The provisional solo XP path now uses this encounter lead, with separate reward eligibility checks. Original XP ownership remains unverified.

Ties retain the first contributor to reach the tied total. Greatest damage without a strict majority, applied-damage accounting, contribution retention and this tie rule are explicit reconstruction policies where period evidence does not establish the exact arithmetic or reset behavior. Contributions currently remain through NPC regeneration. Pets and damage shields are outside the implemented combat scope. Team loot describes the hit-time accounting and current-member All rights.

Entitlement lasts until the corpse's existing deadline; opening, closing and taking do not release rights. The level-1 Leet retains the provisional 180-second death-based lifetime below. A February 2002 Nuggetz guide describes public looting roughly a minute after guards kill that unique NPC. It does not establish an ordinary Leet's public timer or an owner-close rule, so no public unlock duration has been invented.

The native CorpseFullUpdate carries team ID, loot mode and looter identity. 100afcb0 passes them to 1008c740, which stores the looter on the original hidden actor at offsets 0x12c/0x130 when that actor still resolves, and prints entitlement text. An absent original actor skips the store. The corpse's Use predicate 1009fcd0 returns eligible without checking the looter. Closing clears local container state without changing entitlement. Replaying creation does not update an existing corpse, and no public-unlock update path was recovered. Server-side authorization remains necessary for both Use and pickup. These addresses refer to the shipped kkr.dll at base 0x10000000; the retained audit is local/loot-rights-smoke/native-source-audit.json.

TestLootRights* covers competing contributors, changing leads, ties, three-way plurality, extreme overkill, stopped attacks, departure, fresh respawn, concurrent combat ticks, credit collection, item pickup and denial through stale handles before and after expiry. Source copies and remaining research gaps are retained in local/loot-rights-smoke/source-ledger.json.

Two WASM clients contested an actual combat kill: player 2 dealt nine of thirteen HP, stopped attacking, and player 1 dealt the final four. Player 2 received the native entitlement message, opened the corpse, collected 123 fixture credits once across close/reopen, and took Monster Parts item 501, QL 1, Count 1. Player 1 selected the corpse and emitted a real native Use request but received no open handle, credits or item. Read-only native inventory probes found item 501 in player 2's native slot 48 and no items in player 1's inventory. Expiry removed the corpse and closed the open handle; both clients' subsequent Use input recovered nothing. A server restart and both page reloads preserved the same single item and balances, including the native client state. The first run also exercised contributor death and automatic removal at the unchanged 180-second deadline; the interaction run used tougher fixture characters and advanced expiry to its existing deadline. Neither run had page exceptions or adapter failures. Connection refusals were limited to the deliberate server restart. Captures, request logs and native probes are retained in local/loot-rights-smoke/.

Corpse expiry

The shipped 14.9.1 cd_image/text/help/combat.txt states that an unlooted monster corpse decays after a time period. It supplies no duration. A bounded search of the local wiki and online corpse/decay/timer references did not establish this Leet's historical lifetime. Later boss-specific corpse times and emulator defaults are insufficient to establish a universal 14.9.1 rule.

The MonsterData 17655, level-1 profile explicitly sets corpse_seconds: 180. This duration and its death-based clock origin are provisional reconstruction policy. Empty and populated corpses have the same deadline; opening, closing and taking items neither extends nor shortens it. Unprofiled corpses have no automatic expiry yet. This timer is independent of the profile's 100-second respawn delay and is not supplied as a client TimeExist value.

At expiry, the server clears the session's loot handle and sends the native action-102 close before deleting the hidden character (50000) and corpse (51050) through 0x36510078. Only observers that know the corpse receive its deletions, including clients still loading an already queued snapshot. The FIFO output queue retires those objects after their initialization packets. Interest entries, the actor, its inactive roaming entry and its expiry queue entry are removed. A pending respawn retains the source needed to create a fresh life if the corpse's deadline comes first; an existing replacement has a separate identity and remains untouched.

Before sending those packets, one SQLite transaction deletes every unclaimed item's placement and record, including the contents of portable bags, and retires the corpse. If a replacement is still pending, its hidden source and deadline remain stored without corpse state; otherwise the source row is deleted. Taken items are outside this transaction. Failed or ignored writes and failed commits roll back the entire operation, retain the in-memory corpse and open handles, and retry on a subsequent cleanup tick. No native removal is published before a successful commit, and cleanup does not depend on a later periodic checkpoint or respawn.

Use and pickup also check the deadline directly, rejecting expired requests before the cleanup tick. Cleanup and pickup share the normal update/state lock order, so a competing pickup either commits ownership first or finds no available corpse. Taken inventory remains durable; untaken contents are discarded with the corpse. Offline cleanup does not wait for an observer, and reentry cannot recreate an expired actor or recover its contents.

server/corpse_expiry_test.go covers the exact boundary, close/delete ordering for two observers, stale requests before and after cleanup, pickup persistence, concurrent expiry/pickup, both timer orderings, fixed and roaming creatures, offline cleanup, loading clients and reentry. server/corpse_expiry_outcome_test.go additionally reads SQLite at the first native close packet, checks both respawn/expiry orderings, injects failed and ignored placement/item/source writes and failed commits, and verifies retries and cold recovery. Filled-bag failures preserve both the bag and its contents; successful expiry removes them together without reusing their identities.

An ordinary level-2 Tiny Stalker kill also verified cold replay in the GPU-backed WASM client: the server restarted with almost 178 seconds of the normal lifetime remaining, sent the separate corpse without an original living-actor update, and the rendered remains accepted right-click Use. Native pickup transferred Monster Parts item 137, QL3, Count 1 into player 5's inventory. Expiry closed its empty window; reconnect preserved that item and the living replacement. This establishes the outdoor Stalker path. The earlier team fixture's unlocated remains and the general activation prerequisites still need their own checks.

A second ordinary kill left item 138, QL2 Monster Parts, unclaimed while a scoped SQLite trigger blocked only that corpse's retirement for twelve seconds after expiry. All 47 failed cleanup attempts retained the item, corpse and native loot window. Removing the trigger allowed one committed cleanup followed by native close and both deletions. The wire capture contains no removal during the fault. The earlier taken item and all 62 pre-existing item records remained intact. Another cold server restart and native reconnect retained all 21 owned instances, the same 62 total records, 1075 current-level XP, 8309 IP and 40 credits. The expired corpse and its unclaimed item stayed absent; item identity 138 remained reserved. Neither native phase had a page exception or adapter failure; the console contained two generic HTTP 404 errors in each phase. Captures, SQLite snapshots and the fault/retry checks are retained under local/corpse-replay/; neither run required a client or corpse-packet workaround.

The maintained Go suite passed 1,685 root tests / 16,575 results with no test skips. Focused race runs passed 14 roots / 35 results in total, and vet passed. All 22 new regression results fail against the previous committed expiry and respawn implementation through a Go overlay. The source hashes, test reports and native verification are recorded in local/corpse-replay/verification.json.

Two published WASM clients checked the full 180-second lifetime after a real 100-HP Leet kill. Corpse 1000000 held untaken fixture item 101 while the owner already held item 100. Its window remained open across respawn, then closed at expiry with the cursor over the loot item. Both clients lost the fallen model; replacement 1068609 remained alive at 100 HP. The expired actor and loot handle were absent from the server state, and inventory retained item 100 without acquiring item 101. Page reconnect and server restart preserved that ownership and did not restore the expired corpse. The passing run had no page errors; socket failures were confined to the intentional restart. Screenshots, per-step states and machine-checked results are retained in local/corpse-expiry-smoke/.

Expiry during a native pickup

TestBrowserCorpseExpiryDuringNativePickup adds a repeatable two-member case. One native member collects item1 while item2 remains at corpse slot7. The other member holds a consumed mouse-down over that remaining source while the fixture advances the normal expiry visitor to its saved deadline. Both clients receive close, hidden-character destruction and corpse destruction in that order. The windows and both native objects disappear; releasing and clicking again emits no pickup request and neither client crashes or freezes.

Both page reloads retain the collected QL1 item and the1/0 wallets. Cold Go loading retains sole ownership and allocator2, deletes the corpse source, and confirms the untaken QL2 item is absent. The fixture isolates expiry from respawn and does not establish a historical lifetime. This path passes without a product change; broader placement remains open. Captures and verification are in local/corpse-pickup-expiry/. The final expiry/peer checks pass in26.21/26.78 seconds, with all seven saved traces free of native errors or dropped events. The captured close falls between the consumed mouse-down and mouse-up; vet and driver syntax also pass.

The published WASM client was checked with a real combat kill, fallen corpse, open/close/reopen, native Monster Parts details showing QL 1, pickup into the ordinary inventory, empty corpse, page reconnect and server restart. The item remained visible and owned after both reconnects. A second client joining after death loaded the corpse with its animated model. Server tests cover rejected access, failed saves, full inventory, repeated/concurrent pickup, switching containers and interest reentry.

Maintained native source is under client/game/kkr.dll/. The functions above use the rebased image addresses; subtract 0x26000000 for original image addresses. Local REA evidence bundles and WASM captures are retained under the ignored local/loot-smoke/ directory.