commit 9e60cb158fc2dbc3a2f24dd3d85bd672264043a5
parent b5e2b554c2b2a81185d783bb83fb52aa63030156
Author: anon <anon@example.com>
Date: Sun, 25 Oct 2026 02:20:36 +0000
Enforce Unique item ownership during corpse pickup
Diffstat:
5 files changed, 250 insertions(+), 6 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -1039,11 +1039,15 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah
native text explains the rejection, without the action-46 contract error.
Repeated attempts preserve IDs/counts/placements and the bank opening anchor.
Protocol tests preserve pending equipment work when bank requests overlap it.
-- [ ] Complete Unique acquisition checks beyond bank/backpack transfers.
- Audit corpse loot, shop purchases and future player trading using the same
- source-backed low-template scope, including Unique crystals inside carried
- bags, duplicate races, rejection without debit/loss and cold recovery. Keep
- deliberate GM fixture creation distinct from ordinary acquisition.
+- [x] Enforce Unique corpse pickup against carried ownership. Check loose,
+ equipped and carried-backpack duplicates, separate bank scope, concurrent
+ pickups, durable instance conservation and native rejection/retry. See
+ [Unique items](docs/unique-items.md).
+- [ ] Complete remaining Unique acquisition checks. Audit shop purchases,
+ future player trading and acquiring filled containers with Unique contents
+ using their original contracts. Cover duplicate races, rejection without
+ debit/loss and cold recovery. Keep deliberate GM fixture creation distinct
+ from ordinary acquisition.
- [x] Exercise bank Unique/NoDrop transfers, native Delete cancellation and
confirmation, Ctrl-split, ordinary-inventory merge/redeposit and bank layout
persistence through browser reload. Check IDs, counts and placements against
diff --git a/docs/nano-healing.md b/docs/nano-healing.md
@@ -50,6 +50,26 @@ provides a packet parser and preservation plan, without a correlated heal
capture. These bounded findings do not establish that no suitable recording
exists elsewhere.
+## Direct and periodic Hit execution
+
+A separate original-client trace rules out applying the authored heal through
+CharacterAction 177. Both immediate and queued effects reach `100be8e0`, whose
+gate `100bfb40` rejects Hit53002 before timing, tick count or recipient context
+is inspected. The otherwise unreachable Hit switch entry calls `1010def0`,
+a `ret 4` stub. Changing tick metadata cannot supply an additive HP operation.
+
+Action 177 enters `10066010`, which requires positive duration and the program's
+BuffNano flag before applying effects through the same common executor. Original
+Improved Healing has neither duration nor BuffNano; original Insurance Hack
+85232 has a duration and 40 Hit ticks, but those still reach the same
+gate. An active icon does not establish that current HP was restored.
+
+Nine complete matching native evidence records, original instruction windows,
+and both fully reparsed original program records are retained in
+`local/combat-heal-hit-research/`. This closes the specific direct/periodic
+execution lead; the historical server's HP and weapon-impact exchange remains
+unresolved. No client behavior was changed and no analysis session was opened.
+
## Verification
Go tests cover exact BM/MM boundaries, profession and quality rejection,
diff --git a/docs/unique-items.md b/docs/unique-items.md
@@ -0,0 +1,83 @@
+# Unique item acquisition
+
+Unique is Flags0 bit `0x08000000`, separate from NoDrop `0x04000000`.
+Acquiring an individual Unique item checks its low template ID against loose
+inventory, worn equipment and the contents of carried backpacks. Banked items
+and banked backpack contents are outside that carried scope. Learning a crystal
+consumes the item; its learned program entry is not carried item ownership.
+
+Bank withdrawal and corpse pickup share `playerInventory.carriesUnique`.
+The check runs while the inventory update lock is held and before changing
+locations or committing a transfer. Two concurrent pickups of duplicate Unique
+items can therefore acquire only one instance. Rejection changes no item IDs,
+counts, locations or player credits. Deliberate control-panel fixture creation
+remains unrestricted.
+
+## Original client evidence
+
+Original `kkr.dll!10060510` validates moves from an external Chest. Its Unique
+branch calls `10062a20` when the Chest's parent is not the local character.
+`10062a20` checks the low template against the carried inventories, including
+loaded carried Chest contents. The related bank contract and quality-endpoint
+checks are documented in [bank storage](bank-storage.md).
+
+Three complete retained records are in
+`local/unique-loot-research/native-evidence.json`, selected from the matching
+bank and source-refresh investigations. The original DLL was rehashed as
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+Validator evidence is
+`ev_5a372a2ca28d7119684aacd9981bc963dd958fe827b527bdc110b4817cf4db89`;
+lookup evidence is
+`ev_8fc2e6829eababebc05fba0e2766580f1f6c8ec53240e7d0ae5ca11c4bcb6db9`.
+These are original static client branches, not a historical server capture.
+Source refresh `10062960` is retained as
+`ev_23447888b082b5e191bb5ea8a9564d3271ae3dd17a04935cf66fbab8a2bc8636`.
+
+A client may not yet know the contents of an unopened carried bag. The server
+must check its complete owned inventory rather than relying on the client's
+local validation. On corpse rejection, action 146 refreshes the picked source
+before the authoritative loot list and the original Unique explanation are
+sent. A list refresh alone preserved ownership but left the optimistic source
+icon hidden in the real WASM client.
+
+## Verification
+
+The full maintained Go suite passed in 591.187s, with gamedata passing in
+10.345s. The focused run passed in 64.835s, the same loot/bank/container selection
+passed under the race detector in 566.389s, and build/vet passed. Logs are in
+`local/unique-loot-research/`. New regressions first reproduced duplicate
+acquisition from loose inventory, equipment and carried bags, and both duplicate
+pickups succeeding concurrently. They now cover those rejections, successful
+first acquisition, a different Unique template, bank/banked-bag exclusion,
+exact rejection packets, unchanged item-store snapshots and cold recovery.
+The concurrent case retains one instance in inventory and the other on the
+corpse. Existing bank tests cover low-template equality across quality endpoints.
+
+A real GPU Chromium WASM client exercised the unopened-bag case twice.
+Both server rejections retained all four fixture instances and restored the
+picked source icon. Opening the bag made the native client reject another
+attempt locally without a pickup request. The player then moved the existing
+Body Boost crystal out of the bag and uploaded it, consuming only instance 57.
+Native pickup transferred corpse instance 58 into ordinary inventory; another
+duplicate attempt retained instance 59 on the corpse. Browser reconnect and an
+actual server restart retained the learned program and exact item locations.
+
+`local/unique-loot-smoke/tmp_verify.py` checks native inventory entries, SQL
+snapshots, all pickup requests and acknowledgements, source-refresh slots,
+local rejection without a request, renderer identity and zero client errors.
+The fixture used one GM-created player, a Medium Backpack, three original
+startup crystals and a cloned dead Leet containing the two spare crystals.
+It establishes transfer behavior, not authored Leet loot content. BM/MC were
+raised through the control editor; learning and transfers used native UI.
+
+The owned browser closed. Cleanup removed only the owned character, corpse and
+three remaining item instances. Every unrelated row retained its hash, and
+SQLite foreign key and integrity checks passed. The sole normal HTTPS preview
+remains available on port 8443.
+
+## Remaining scope
+
+Shop purchases and player trading are unfinished. Acquiring a filled container
+with Unique children needs its own complete original contract; this individual
+item check does not claim to validate that operation. Dynamic temporary item
+lifetimes and other acquisition restrictions remain separate work.
diff --git a/server/loot.go b/server/loot.go
@@ -197,6 +197,20 @@ func (server *server) takeLoot_locked(client *worldClient, body []byte) error {
return nil
}
player := server.characters[client.id]
+ item := corpse.corpse.items[index]
+ if itemStat(item.templateDefinition(), 0)&0x08000000 != 0 && player.inventory.carriesUnique(item) {
+ if err := client.send(characterActionPacket(client.id, [5]uint32{146, 107, item.Slot})); err != nil {
+ return err
+ }
+ if err := client.send(lootInventoryPacket(client.id, corpse, false)); err != nil {
+ return err
+ }
+ text := "You already have this unique item..."
+ reply := binary.BigEndian.AppendUint32(nil, uint32(len(text)))
+ reply = append(reply, text...)
+ reply = append(reply, 0, 0)
+ return client.send(n3Packet(0x5f4b442a, 50000, client.id, reply))
+ }
var slot uint32
for slot = 64; slot < 94; slot++ {
if !slices.ContainsFunc(player.inventory.Items, func(item ownedItem) bool { return item.Slot == slot }) {
@@ -208,7 +222,6 @@ func (server *server) takeLoot_locked(client *worldClient, body []byte) error {
}
// Persist the new owner before removing the corpse item or publishing its move.
- item := corpse.corpse.items[index]
item.Slot = slot
inventory := player.inventory
inventory.LastID = max(player.inventory.LastID, server.nextItem, item.ID)
diff --git a/server/unique_loot_test.go b/server/unique_loot_test.go
@@ -0,0 +1,124 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "slices"
+ "sync"
+ "testing"
+)
+
+func TestLootUniqueUsesCarriedOwnershipAndExcludesBank(t *testing.T) {
+ for _, placement := range []string{"absent", "inventory", "equipped", "carried bag", "bank", "banked bag", "different unique"} {
+ t.Run(placement, func(t *testing.T) {
+ world, conn := newLootWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ item := ownedItem{ID: 17, Type: 51005, Template: 29092, Quality: 1, Count: 1}
+ if placement == "equipped" {
+ item.Type, item.Template = 51017, 152039
+ }
+ world.characters[1000000].corpse.items = []ownedItem{item}
+ other := item
+ other.ID, other.Slot = 18, 64
+ switch placement {
+ case "inventory", "different unique":
+ if placement == "different unique" {
+ other.Template = 28778
+ }
+ player.inventory.Items = []ownedItem{other}
+ case "equipped":
+ other.Slot = 19
+ player.inventory.Items = []ownedItem{other}
+ case "bank":
+ other.Slot = 0
+ player.inventory.Bank = []ownedItem{other}
+ case "carried bag", "banked bag":
+ bag := ownedItem{ID: 19, Type: 51017, Template: 99241, Quality: 1, Slot: 64, Count: 1}
+ if placement == "carried bag" {
+ player.inventory.Items = []ownedItem{bag}
+ } else {
+ bag.Slot = 0
+ player.inventory.Bank = []ownedItem{bag}
+ }
+ other.Slot = 0
+ player.inventory.Containers = map[uint32][]ownedItem{19: {other}}
+ }
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleLootUse(client, lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ err = world.handleInventory(client, lootTakeRequest())
+ after, readErr := readTestItemStore(world)
+ cold := newTestInventoryServer(t)
+
+ accepted := placement == "absent" || placement == "bank" || placement == "banked bag" || placement == "different unique"
+ packets := 3
+ if accepted {
+ packets = 1
+ }
+ if err != nil || readErr != nil || bytes.Equal(before, after) == accepted || len(conn.packets) != packets ||
+ slices.ContainsFunc(player.inventory.Items, func(owned ownedItem) bool { return owned.ID == 17 }) != accepted ||
+ slices.ContainsFunc(cold.characters[1].inventory.Items, func(owned ownedItem) bool { return owned.ID == 17 }) != accepted ||
+ (len(cold.characters[1000000].corpse.items) == 0) != accepted {
+ t.Fatal("Unique loot changed the wrong ownership scope or failed cold recovery", err, readErr, accepted)
+ }
+ key := uint32(0x5e477770)
+ if accepted {
+ key = 0x47537a24
+ }
+ if binary.BigEndian.Uint32(conn.packets[0][16:20]) != key {
+ t.Fatalf("Unique rejection did not restore the corpse window: %x", conn.packets)
+ }
+ if !accepted && (binary.BigEndian.Uint32(conn.packets[0][29:33]) != 146 ||
+ binary.BigEndian.Uint32(conn.packets[0][33:37]) != 107 || binary.BigEndian.Uint32(conn.packets[0][37:41]) != 0 ||
+ binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x4e536976 || binary.BigEndian.Uint32(conn.packets[2][16:20]) != 0x5f4b442a ||
+ !bytes.Contains(conn.packets[2], []byte("You already have this unique item..."))) {
+ t.Fatal("Unique rejection omitted source recovery or its explanation")
+ }
+ })
+ }
+}
+
+func TestLootConcurrentUniquePickupsAcquireOnlyOneInstance(t *testing.T) {
+ world, conn := newLootWorld(t)
+ world.characters[1000000].corpse.items = []ownedItem{
+ {ID: 17, Type: 51005, Template: 29092, Quality: 1, Count: 1},
+ {ID: 18, Type: 51005, Template: 29092, Quality: 1, Slot: 1, Count: 1},
+ }
+ if err := world.flushWorld(); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleLootUse(world.clients[1], lootUseRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+ var workers sync.WaitGroup
+
+ for _, slot := range []uint32{0, 1} {
+ workers.Go(func() {
+ request := lootTakeRequest()
+ binary.BigEndian.PutUint32(request[20:24], slot)
+ if err := world.handleInventory(world.clients[1], request); err != nil {
+ t.Error(err)
+ }
+ })
+ }
+ workers.Wait()
+ cold := newTestInventoryServer(t)
+
+ carried, remaining := cold.characters[1].inventory.Items, cold.characters[1000000].corpse.items
+ if len(carried) != 1 || len(remaining) != 1 || carried[0].ID == remaining[0].ID ||
+ carried[0].Template != 29092 || remaining[0].Template != 29092 || carried[0].Count != 1 || remaining[0].Count != 1 ||
+ len(conn.packets) != 4 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x47537a24 ||
+ binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x5e477770 || binary.BigEndian.Uint32(conn.packets[2][16:20]) != 0x4e536976 {
+ t.Fatal("concurrent Unique requests duplicated ownership, lost a corpse item or acknowledged twice", carried, remaining)
+ }
+}