aorecomp

Anarchy Online classic in the browser

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


docs/research-notes/player-trade-research/native/README.md (15465B)


Original 14.9.1 player trade protocol

Scope: read-only inspection of shipped original binaries and existing matching REA evidence. No server, browser, client, or database mutations were performed. This describes the client contract, not recovered original server source.

Follow-up: remote-template-delivery.md establishes a simpler remote counted template reconstruction using AddTemplate on the remote subject followed by Trade4. It supersedes the unresolved-delivery boundary below for that composed path. Runtime verification and shadow-inventory cleanup are now implemented and verified in local/player-trade-live-smoke/, including32 actual cancel cycles. cash-consent.md subsequently establishes Enter's local-only cash commit and supersedes the blanket two-sided cash-freeze recommendation below. feedback.md establishes the original numeric FeedbackIIR reader and catalog messages; local/trade-feedback-smoke/ verifies both recipient perspectives.

Artifact identity and retained evidence

All addresses are original x86 virtual addresses, not lifted WASM addresses. Ghidra 12.1.2 profile digest: 17fae9135c0f647ce7271e2b74936949ebe245320c1606a223c86bce0b2b7bed.

Artifact SHA-256 Local bundle
kkr.dll a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0 kkr-evidence.json, kkr.snapshot.json
ddr.dll 3c937161de8f690351c3c08e158431417cee9ced77a41b677e7123b61a8c9883 ddr-evidence.json, ddr.snapshot.json
eer.dll 99bc32ca57356aa227e6f78dfe544f8fe16f9ca694a6dee6d3846a36c5a2a6ff eer-evidence.json, eer.snapshot.json

Original artifacts live in anarchy-vanilla-14.9.1/. Pseudocode extracts in this directory retain their address selectors in names; interior selectors may canonicalize to the entry below.

Previously retained local/shop-research/wire/batch1.json through batch8.json have the same KKR hash and were reused, not treated as another game version. reused-evidence.json and reused-*.c.txt retain these observations.

Evidence ID Main coverage
ev_7b9d6df644c4ebba9d00c0111dc0e7583567a4a335ebe3bd0d3704efe782ca1c KKR Add, Remove, Cash producers; TradeIIR constructor
ev_5fe35f4305fb3b2ec2b32dd82476cb8f06a0e6e886698554938a898003b9f24b KKR Start, Accept, Abort producers; TradeIIR reader/writer/handler
ev_e8d99b8728b013c566e5e8d7e4f52959628066199d83239630c958bb67715e60 KKR TradeIIR action dispatcher
ev_3b068fe016d29c9c6d60176e86341dcd106df72df90b32492a9c956186bf61c7 KKR all action handlers, start/accept/abort/complete/add/remove/peer/cash
ev_83bfca3addecffce5689c7919fc1da766ee6040815026f5eb8b07f1766299fca KKR validation, inventory selection, remove and first-free helpers
ev_38cafa740984bd47ca82588bce33953cc0ac8a9fa5711e837bc18829a26a3608 KKR actual row constructor, identity/count/page lookup
ev_c377df0a78b0a09634426321e7c2edd319bad2630359ebf2582069822a6b2017 DDR native trade callbacks and start setup
ev_14ec02170beb079a5d02c4fd0900fa29e4fbf2ad9cc7b1f22a080eb443932971 DDR acceptance indicator and cash UI
ev_54f573e7f808a88dcbfa7bd04148f5d080b9b5e15b33b89b502baa39c4dea19f DDR controls and Accept click handler
ev_e80c5381d39b65a7616e28888f4b02fe7d9dbfaa12bd76ee413104d34a9549a6 DDR constructor wiring and trade state
ev_d0d0fa19d74c314b98b189846115599eb982a78f62a06cd773e166e8cbba81c8 EER UI-to-KKR TradeAccept bridge
ev_32786111da866c2a088451e1f3ee5895b3eb57b7060305b9b7e54cc6b9383397 KKR inventory constructor: ordinary78, TradeInv30
ev_f7fd2a9bd0b71b9f3a4a759510fc2664d531815c60d295dbc67a327c5e8fdd27 Complete row marker sets flags0x20, preserves count
ev_501edf9c1ea8290ea0c8e874ad792f5655da0d405e266c7d8e358dc1cfdd72d4 InventoryUpdate SimpleChar branch only supports overflow110
ev_ca4c61b90349a7bce8a2af5220109b0095dcc42655c12c2189d8ff0b32e26dca FullCharacter applies inventory to named SimpleChar, plus many other effects

TradeIIR wire and topology

Message key 0x36284f6e. Body is six network-order DWORDs: 1, action, A.type, A.id, B.type, B.id. Outer N3 subject is separate. Reader10084b80 rejects action outside0..8. Handler10084c50 resolves subject as SimpleChar, obtains helper10071f90, dispatches through100780b0.

Let A and B below denote players; zero is (0,0).

Action Client request Receiving-client meaning
0 Start subjectA, first=playerB, second=zero Initializes subjectA partnerB, recursively initializes B partnerA; local actor opens UI
1 Accept subjectA, first=zero, second=zero LOCAL subject's TradeAccepted callback turns peer lamp green; notify B with subjectB for A's acceptance
2 Abort subjectA, first=(0,showMessageBool), second=zero Restores subject offers first-free; recursively aborts partner; closes local UI
3 Complete server response, first/second zero Transfers subject's entire TradeInv and offered cash to partner; does not recursively complete partner
4 Add own subjectA, first=playerA, second=(104,nativeRootSlot) Moves entire own row into first-free TradeInv slot
5 Remove own subjectA, first=playerA, second=(108,tradeSlot) Moves selected TradeInv row to first-free ordinary slot
6 Cash subjectA, first=(0,signedCash), second=zero Stores subject offered cash; remote subject emits opponent cash UI callback
7 Add peer dynel server response subjectB, first=playerA, second=actualItemIdentity Resolves A-owned SimpleItem, creates row in A.TradeInv displayed by B
8 Remove peer dynel server response subjectB, first=playerA, second=actualItemIdentity Removes row matching actual identity from A.TradeInv

A single Start subjectA can be sent to both clients; both actors are initialized by recursion10077370. Unlike vending, there is no machine catalog initialization or (111,catalogTag) second identity for this player path.

Own ordinary inventory sources48..77 map to saved server slots64..93. TradeInv slots0..29 are never translated. Local GUI identities are page108; remote GUI identities are page208. Helper10061800 maps208 to the partner's TradeInv.

After successful durable commit, both directions Complete are needed on both clients: subjectA then subjectB (or reverse), once each. Each Complete moves only that subject's offers and subtracts that subject's cash/adds it to its partner. Sending only recipient Complete leaves its received offers on the wrong actor. Absolute final cash correction, if used, belongs after both native predictions.

Offers, quantities, and the unresolved remote stack path

Own Add handler10077aa0 requires subject in trade, first identity=subject owner, valid ownership via100619d0, and common validator10060510. It rejects when either player helper byte+0x10 is true, then moves entire row through100601b0. The move1002d3c0 preserves flags, ushort count, instance identity, QL and templates. Own Remove10077cc0 has the same byte+0x10 rejection and uses10060090.

Peer Add10077e10 requires recipient in trade and first identity=its partner. It verifies ownership on that partner, then10061b40 resolves the actual dynel and calls1002d870. This constructor explicitly makes flags0x22 and count1, copies actual identity, and reads QL701/low702/high703 (high0 falls back to low). It does not read Energy26 or MultipleCount412 to populate the row count. Peer Remove10077ee0 calls10061ba0/1002d740 to remove by actual identity.

Read-only lifted-source cross-check: original1005de70 (lifted3605de70) in client/game/kkr.dll/lifted-0028.c:14613, reached by GetSkill at original1002bd80, returns the row count for stat412. For actual rows only stats26 and8 bypass to the live dynel first. Therefore supplying dynel stat412 does not correct a page208 quantity query; row count must be correct. This cross-check was not a new REA observation and should not be confused with the original-binary Evidence above.

Therefore action7 alone demonstrably does NOT convey a template stack count. Sending a full item dynel plus action7 is sufficient for a count1 actual object, but is not evidence for a correct count25 template stack. Do not silently make stacks count1 or infer that Energy26 equals the row count.

InventoryUpdate handler100b0cd0 was examined as a possible solution. Its target Chest branch replaces contents. Its SimpleChar branch10062ec0 accepts only handle110/overflow; it does not replace TradeInv for handle108 or208. FullCharacter handler1007eea0 overlays rows on the named SimpleChar even for a remote actor, but also reapplies equipment and other state and effects. A seeded remote ordinary row followed by action4 could preserve full rows in principle; this is an untested reconstruction, not recovered original trade delivery.

Complete10077700 preserves whatever count the moved row actually has. Helper1002dd90(slot,1) sets row flag0x20; it DOES NOT set count to1. This matters when distinguishing a correctly seeded/copied template row from action7's new count1 row. The historical remote template-stack transfer path remains unresolved.

First-free restoration and completion

TradeInv has30 slots, constructed at1005c400 with1002d080(30,owner). Ordinary inventory has78 slots total: equipment0..47, carried48..77. New offers allocate first-free TradeInv0..29. Removing a row leaves that trade slot vacant; later offers reuse its first free slot.

Remove10060090 selects first-free ordinary from48 and moves the selected row. Abort100774a0 scans own TradeInv in ascending slot order and restores each row to first-free ordinary from48. There is no original-source-slot bookmark. It clears TradeInv and recursively aborts the other actor after clearing its own trade flag, preventing endless recursion.

Consequently server reservations at original source slots are only staging. Before acknowledging Remove/Abort, atomically save the same first-free final layout. Example: occupied saved64 and70 offered in that order, with65 free; Abort restores them to64 then65, not64 then70. Otherwise client and DB diverge. Cancelling before other inventory actions avoids source reservation collisions but does not remove this first-free requirement.

Complete scans source TradeInv ascending, placing each into partner's first-free ordinary slot. It reparents actual dynels to partner. A portable bag occupies one root slot; transferring its children is a server ownership transaction and must preserve their identities/counts. Client Complete does not reconstruct authoritative bag contents for the server.

DDR10048870 first calls10049090: parse cash withatoi, cap at player cash stat61, store view+a0, send Cash6. Cash6 therefore precedes Accept1 even if unchanged. For player trade it then sets one-shot view+0x89 and sends AFCM9/event0x16c only if that byte was false. EER100034c0 directly calls KKR TradeAccept1.

Incoming Accept10077450 only calls the local owner's callback. DDR10048e70 sets view+0x88, green lamp visible/red hidden, and waiting overlay visible. This is the opponent accepted indication. An A acceptance should reach B as subjectB/action1, not as an own-A echo that wrongly turns A's peer lamp green.

Start DDR100485b0 resets bytes+0x88/+0x89. No Unaccept action or post-mutation reset was recovered. No second confirmation dialog was found in this path. Actions7/8 are peer item add/remove, not final-confirmation states. Generic server question dialogs were not exhaustively excluded; a later2009 forum report is not evidence that a second stage existed in14.9.1.

The shipped help cd_image/text/help/The Trade Window.txt independently says both players press ACCEPT to complete and identifies the red-to-green peer lamp. Its SHA-256 is315fbe0b3b1f7ef4be7cf01e688779f4ddd38c20fd2cb920782730c33445723e.

Implementation recommendation (inference, not recovered server policy): freeze both offers and cash after either accepted; allow unchanged Cash6 echoes but reject actual mutations until cancel/restart. Merely clearing server acceptance after a mutation cannot obtain a second click from this one-shot native UI. The legacy request has no basket revision or nonce; freezing ensures a queued old Accept cannot approve a different basket within one session.

Admission and rejection evidence

Start producer1001f840 requires a different SimpleChar target, stat388=0, three-dimensional distance <=5, and no conflicting target trade. If both players are already in a trade it emits Abort instead. Start handler10077370 requires subject flag8 clear, internal flags+0x11c bit0x4000 clear, and target dynel exists. No side/faction restriction was recovered.

Add producer1001fb50 and common validator10060510 reject equipped sources, foreign ownership, missing/full destinations, NoDrop0x04000000 for player trade, and unsuitable sources. Offering directly from inside a container is explicitly rejected with Can't trade from container (yet)..; move it to ordinary first. Offering an entire ordinary backpack is supported.

At100612cf common validator checks actual Chest sources (except bank page105): 1008bdd0(0x04000000) rejects any NoDrop child, and1008bdd0(0x08000000) rejects any Unique child. Thus Unique-inside-bag rejection exists in14.9.1 itself and is not just the later forum claim. This is independent of recipient owning a duplicate.

The client also contains original server-error text for full recipient inventory, full own inventory, NoDrop basket, and recipient already owning Unique. These strings are registered by10040b00 as errors21,24,46,47 respectively; their only string xrefs lead to the message catalog, not server validation code. They support the existence of these failure outcomes but do not prove exact original server counting rules, bank inclusion, or unique-template matching.

Server must separately enforce current sessions/playfield/range/death/loading, nonnegative bounded credits, actual inventory ownership, NoDrop/Unique checks, destination capacity, and atomic persistence before success. Exact original server distance-on-completion, combat policy, Unique search across bank/reclaim, and credit ceiling were not established from these client paths.

Remaining work / confidence limits

  1. Recover or experimentally verify a remote template-stack row delivery path preserving actual IDs, QL and ushort quantities; plain action7 is insufficient. Sending both Complete directions and then the existing syncStacks ordinary rebuild is a plausible correction for final received quantities. AddTemplate creates proxies with null client IDs, while saved server instance IDs remain intact. This must be manually tested and does not by itself fix the quantity displayed in the peer basket before consent.
  2. Manually verify both clients' inventory, cash, bag contents and reconnect after success/cancel/remove with noncontiguous original slots and filled inventories.
  3. Verify queued/malformed/replayed requests, unchanged Cash6-before-Accept, failed persistence, disconnect, zone/death, Unique children and recipient duplicates.
  4. If adding a final confirmation dialog for modern safety, label it a deliberate server policy until a14.9.1 server-driven dialog contract is proven.

All evidence is static client evidence unless explicitly marked inference. All three owned REA sessions were exported and closed. Final KKR bundle contains 153 records; binary_session subsequently reported open=false.