aorecomp

Anarchy Online classic in the browser

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


commit aa72127330a85460b57fec6d5b6882780a6b8df3
parent e33e8b9df2f5ccfc65360c980231dc2c4781e3e0
Author: anon <anon@example.com>
Date:   Wed, 28 Oct 2026 06:50:09 +0000

Support selected-quality recovery supplies through shared item data

Diffstat:
MTODO.md | 14+++++++++++++-
Adocs/medical-quality.md | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/npc-loot.md | 5+++--
Mserver/gamedata/item_families.yaml | 4++++
Mserver/gamedata/item_quality_test.go | 1+
Mserver/resource_kit.go | 31++++++++++++++++++++++++++++---
Aserver/resource_kit_quality_test.go | 261+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 418 insertions(+), 6 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -974,6 +974,16 @@ replay/failure tests and WASM checks are recorded in [IP training](docs/ip-train ## Usable items +- [x] Support selected-quality regular recovery supplies through shared item data. + Reviewed laboratory, nano-kit and nano-recharger pairs cover QL1..200. Both + endpoint contracts must be supported; requirements, restoration limits, value, + native endpoints and charge removal use the selected quality. Tests cover + boundaries, strict equality, locks, ignored/failed writes, retry and cold state. + Hardware WASM checks verify QL2 use of all three families, QL100/101 laboratory + requirements/restoration, cooldown rejection, final-charge removal and cold + recovery. Controlled fixtures establish use, not historical stock or earned + acquisition. QL201..399, complete medical stock and combat health-stim delivery + remain open. See [medical qualities](docs/medical-quality.md). - [ ] [P0] Use one First Aid item. Check: it restores the expected health, consumes the applicable quantity/charge and cannot be reused during its skill lock. Resolve incoming queued-hit delivery without fake weapon outcomes: two-client @@ -1258,7 +1268,9 @@ introduction and starting-item gameplay remain open below. - [ ] [P1] Recover medical and ammunition stock membership and QL generation beyond the current basic QL1 recovery subset. Original medical descriptions establish broad families, while tier descriptors differ; do not copy basic stock into - advanced/superior or starter terminals. Four ordinary ammo definitions have + advanced/superior or starter terminals. Regular recovery supplies now support + reviewed QL1..200 families through shared use/interpolation; their historical + stock ranges and rotation remain unresolved. Four ordinary ammo definitions have 100-round packages, but their exact booth bindings remain unresolved. Reuse the item/vendor hashes, descriptors and placements in `local/charged-shop-research/catalog/README.md` and the period source audit. diff --git a/docs/medical-quality.md b/docs/medical-quality.md @@ -0,0 +1,108 @@ +# Selected-quality recovery supplies + +Regular treatment laboratories, nano kits and nano rechargers now support the +reviewed QL1..200 interval through the shared item-family rules. Either endpoint +can identify an instance. Its selected QL drives requirements, restoration, +price, native low/high delivery and persistence. + +| Family | QL1 / QL200 templates | Restoration at endpoints | Package | Lock | +| --- | --- | --- | --- | --- | +| Treatment Laboratory | 25812 / 25811 | 30 / 1500 health | 50 | Patient Treatment, 15s | +| Nano Kit | 85366 / 85367 | 10..12 / 1000 nano | 25 | User First Aid, 40s | +| Nano Recharger | 25820 / 25821 | 30 / 2000 nano | 50 | Patient Time and Space, 20s | + +These pairs have matching immediate-use structures, apart from the interpolated +restoration limits and skill requirements. Laboratory activation metadata +AddSkill53028 changes target1 to target3 between endpoints; this initializes the +item's skill list, as described in [medical consumables](medical-consumables.md). +Both metadata forms are supported; no character skill buff is applied. The original +resource 1000020 payloads were freshly decoded and compared with the maintained +catalog. Complete records, offsets, hashes and the comparison are retained under +`local/medical-quality/`. The original index SHA-256 remains +`46e5dc54af9358cc9bff05f4358e86af630e497bc677f361c133c88073b84d71`. + +Original KKR `FUN_100f00a0` selects parameter keys 2/37 for Hit53002, and +`FUN_100f0aa0` applies the shared `FUN_100eff20` integer interpolation. The +existing requirement interpolation and stat74 price curve use the same selected +quality. KKR SHA-256 is +`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`; +retained REA records are `native-basics.json`, `native-function-dispatch.json` +and `native-argument-0.json` / `native-argument-1.json`. + +## Shared consumer + +`resourceKit` decodes both endpoint contracts before interpolating the two +restoration limits. Both must be fully supported and agree on resource kinds, +lock and feedback. An unknown effect at either endpoint rejects the entire +use. Item IDs do not appear in the consumer; the three pairs live in +`server/gamedata/item_families.yaml`. + +The existing use handler still evaluates the selected-quality requirements, +target, range, posture, combat state and cooldown. It commits charge consumption, +resources and the appropriate actor's lock together before acknowledging success. +An exhausted stack is removed with the resolved native endpoint pair. Ordinary +low-significance simulation persistence is unchanged. + +Native categorical properties come from the nearer endpoint. At QL100 the +laboratory retains its low name/icon; at QL101 it uses HQ Health Treatment +Laboratory. Numeric restoration and requirements continue interpolating across +that boundary rather than jumping to the endpoint's values. + +The authored QL400 definitions remain supported at their exact qualities. +QL201..399 is still unreviewed, and the startup laboratory remains fixed QL1. +Health First Aid remains blocked by the separate incoming-hit delivery issue in +[First Aid](first-aid.md). This change supplies no new stock, loot membership or +quality-generation policy. In particular, the training terminal's QETS contents +remain unresolved; the basic medical booths retain their existing QL1 subset. + +## Verification + +The public item-use handler tests both stored anchors at QL1,2,100,101,199,200. +Hardcoded expectations cover restoration limits, strict skill thresholds, price, +native endpoint delivery, charge debit, fixed cooldown and cold ownership. +Failure cases cover a required charge write, ignored charge/health writes, lock +failure, deferred commit, retry and immediate replay. Another case rejects an +unsupported upper effect. Last-charge checks retain the unrelated weapon and +remove the consumed record and its native proxy for all three families. + +The corrected negative baseline overlays only the old consumer while retaining +the reviewed pairs and valid fixtures. It fails 45 child cases and their three +root tests, with six endpoint controls and the unsupported-contract control +passing. Earlier logs `red.json` / `focused.json` used invalid zero abilities; +they are fixture failures and are excluded from that result. `red-valid.json` +and `focused-valid.json` retain the corrected comparison. + +The final focused recovery/startup/family run passed 14 roots / 129 total results. +Race checks passed the +quality/use and concurrent-replay cases, with the corrected last-charge test +passing separately. Its initial assertion had used server slot65 instead of +native slot49; charge removal itself was correct. Build and vet passed. The +broader maintained run uses a 60-minute timeout; its status and the assertion +correction are tracked in the retained checkpoint. The earlier default 10-minute +run timed out without an assertion failure and is not counted as a completed suite. + +One owned, controlled visitor tested the actual WASM client on GPU/OpenGL. +Its skills, level, resources and five items were fixtures; this is a quality/use +check, not ordinary acquisition or an earned-income progression claim. + +| Native check | Selected QL | Observed result | +| --- | --- | --- | +| Laboratory | 2 | Treatment11 rejected; 12 accepted; +37 health | +| Nano Kit | 2 | +16 nano on first use, within 15..17 limits | +| Nano Recharger | 2 | +40 nano | +| Laboratory | 100 | Treatment451 rejected; 452 accepted; +761 health | +| Laboratory | 101 | Treatment452 rejected; 457 accepted; +769 health | + +Received TemplateAction and subsequent absolute resource updates establish those +deltas separately from passive regeneration. The native information windows +independently show selected QLs, names and thresholds. Immediate cooldown repeats +preserved charges. Two further QL2 nano-kit uses restored15 each; the final charge +removed its exact instance. Page reconnect and an unchanged-database server +restart retained the other four instances, qualities, endpoints and quantities. + +Both native error lists are empty. The test client closed, and only its visitor +and four remaining items were removed. Every unrelated table hash matched across +cleanup, with foreign-key/integrity checks. The retained earned Enforcer's full +profile, wallet, eight item rows and learned program matched the pre-test snapshot. +One LAN preview remains on the default ports. Native streams, screenshots, +frozen SQL phases and assertion results are retained in `local/medical-quality/`. diff --git a/docs/npc-loot.md b/docs/npc-loot.md @@ -80,10 +80,11 @@ Startup rejects missing/zero or reversed bounds, unknown templates and intervals outside the template's reviewed family. Fixed-QL items accept only their authored quality as both bounds. Quality is sampled after successful membership; fixed and empty drops do not consume a quality roll. The shared -`server/gamedata/item_families.yaml` lists eleven reviewed endpoint pairs: +`server/gamedata/item_families.yaml` lists fourteen reviewed endpoint pairs: six Metaplast pieces, Backpack of Survival, NCU Hacker Interface, the QL1..11 Rusty OT M-10 Flechette Pistol, regular QL1..400 Monster Parts and QL1..200 -Low-Tech gloves. +Low-Tech gloves, and three regular QL1..200 recovery-supply families described in +[medical qualities](medical-quality.md). Either endpoint identifies a family. No name or neighboring-ID heuristic pairs additional definitions, and listing a pair does not implement its effects. diff --git a/server/gamedata/item_families.yaml b/server/gamedata/item_families.yaml @@ -17,3 +17,7 @@ - [42640, 42641] # Low-Tech gloves: complete original descriptor audit; docs/early-armor.md. - [70562, 85597] +# Regular recovery supplies, QL1..200: docs/medical-quality.md. +- [25812, 25811] +- [85366, 85367] +- [25820, 25821] diff --git a/server/gamedata/item_quality_test.go b/server/gamedata/item_quality_test.go @@ -14,6 +14,7 @@ func TestReviewedItemFamilyQualityRanges(t *testing.T) { {85638, 85637, 1, 200}, {85686, 85685, 1, 200}, {85742, 85741, 1, 200}, {42640, 42641, 1, 400}, {206730, 206731, 50, 150}, {158416, 158417, 1, 200}, {123742, 123743, 1, 11}, {70562, 85597, 1, 200}, + {25812, 25811, 1, 200}, {85366, 85367, 1, 200}, {25820, 25821, 1, 200}, } { for _, template := range [2]uint32{family.lowTemplate, family.highTemplate} { t.Run(fmt.Sprint(template), func(t *testing.T) { diff --git a/server/resource_kit.go b/server/resource_kit.go @@ -18,9 +18,34 @@ type resourceKit struct { func (item ownedItem) resourceKit() (resourceKit, bool) { definition := gamedata.ItemTemplates[item.Template] - kit := resourceKit{} if item.Type != 51005 || definition == nil || definition.HeaderWords[0] != item.Type || - item.Quality != *definition.Quality || itemStat(definition, 76) != 0 || + !gamedata.ItemQualitySupported(item.Template, item.Quality) { + return resourceKit{}, false + } + low, high := item.templateIDs() + first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high] + kit, supported := decodeResourceKit(first) + if !supported || first == second { + return kit, supported + } + + // Both endpoints must implement the same complete restoration and lock contract. + upper, supported := decodeResourceKit(second) + if !supported || kit.lockSkill != upper.lockSkill || kit.lockSeconds != upper.lockSeconds || kit.text != upper.text || + (kit.health[1] == 0) != (upper.health[1] == 0) || (kit.nano[1] == 0) != (upper.nano[1] == 0) { + return resourceKit{}, false + } + // kkr.dll FUN_100f00a0/100f0aa0 interpolate Hit's two resource limits. + for index := range 2 { + kit.health[index] = uint32(interpolateItemValue(int32(kit.health[index]), int32(upper.health[index]), *first.Quality, *second.Quality, item.Quality)) + kit.nano[index] = uint32(interpolateItemValue(int32(kit.nano[index]), int32(upper.nano[index]), *first.Quality, *second.Quality, item.Quality)) + } + return kit, true +} + +func decodeResourceKit(definition *gamedata.Item) (resourceKit, bool) { + kit := resourceKit{} + if definition.HeaderWords[0] != 51005 || itemStat(definition, 76) != 0 || itemStat(definition, 30)&40 != 40 || itemStat(definition, 212) == 0 || itemStat(definition, 294) != 0 { return kit, false } @@ -147,7 +172,7 @@ func (server *server) useResourceKit_locked(client *worldClient, index int, body first := predictedPosition_locked(player, now) second := predictedPosition_locked(target, now) x, y, z := first[0]-second[0], first[1]-second[1], first[2]-second[2] - distance := float32(itemStat(gamedata.ItemTemplates[item.Template], 287)) + player.physicalExtent() + target.physicalExtent() + distance := float32(item.templateStat(287)) + player.physicalExtent() + target.physicalExtent() accepted = accepted && x*x+y*y+z*z <= distance*distance } if accepted { diff --git a/server/resource_kit_quality_test.go b/server/resource_kit_quality_test.go @@ -0,0 +1,261 @@ +package main + +import ( + "ao/server/gamedata" + "bytes" + "encoding/binary" + "fmt" + "slices" + "testing" + "time" +) + +func newQualityKitWorld(t *testing.T, template, quality uint32) (*server, *combatTestConn) { + t.Helper() + world, output := newEquipmentWorld(t) + player := world.characters[1] + player.level = 200 + player.stats.Abilities = characterAbilitiesStats{1, 1, 1, 1, 1, 1} + player.stats.Body.BodyDevelopment, player.stats.Body.NanoPool = 6000, 6000 + player.stats.NanoAiding.Treatment, player.stats.NanoAiding.FirstAid, player.stats.NanoAiding.TimeAndSpace = 1500, 1500, 1500 + player.health, player.nano, player.sitting = 1, 1, true + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, template); !granted || err != nil { + t.Fatal(granted, err) + } + player.inventory.Items[1].Quality, player.inventory.Items[1].Count = quality, 3 + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + world.clients[1].selectedTarget = [2]uint32{50000, 1} + output.packets = nil + return world, output +} + +func TestResourceKitSelectedQualityRestorationAndColdOwnership(t *testing.T) { + for _, scenario := range []struct { + low, high, quality uint32 + health, nano [2]uint32 + price, skill uint32 + seconds time.Duration + }{ + {25812, 25811, 1, [2]uint32{30, 30}, [2]uint32{}, 150, 124, 15}, + {25812, 25811, 2, [2]uint32{37, 37}, [2]uint32{}, 151, 124, 15}, + {25812, 25811, 100, [2]uint32{761, 761}, [2]uint32{}, 12487, 124, 15}, + {25812, 25811, 101, [2]uint32{769, 769}, [2]uint32{}, 12737, 124, 15}, + {25812, 25811, 199, [2]uint32{1493, 1493}, [2]uint32{}, 49499, 124, 15}, + {25812, 25811, 200, [2]uint32{1500, 1500}, [2]uint32{}, 50000, 124, 15}, + {85366, 85367, 1, [2]uint32{}, [2]uint32{10, 12}, 20, 123, 40}, + {85366, 85367, 2, [2]uint32{}, [2]uint32{15, 17}, 20, 123, 40}, + {85366, 85367, 100, [2]uint32{}, [2]uint32{503, 504}, 2490, 123, 40}, + {85366, 85367, 101, [2]uint32{}, [2]uint32{507, 508}, 2540, 123, 40}, + {85366, 85367, 199, [2]uint32{}, [2]uint32{995, 995}, 9900, 123, 40}, + {85366, 85367, 200, [2]uint32{}, [2]uint32{1000, 1000}, 10000, 123, 40}, + {25820, 25821, 1, [2]uint32{}, [2]uint32{30, 30}, 250, 131, 20}, + {25820, 25821, 2, [2]uint32{}, [2]uint32{40, 40}, 252, 131, 20}, + {25820, 25821, 100, [2]uint32{}, [2]uint32{1010, 1010}, 24937, 131, 20}, + {25820, 25821, 101, [2]uint32{}, [2]uint32{1020, 1020}, 25439, 131, 20}, + {25820, 25821, 199, [2]uint32{}, [2]uint32{1990, 1990}, 99000, 131, 20}, + {25820, 25821, 200, [2]uint32{}, [2]uint32{2000, 2000}, 100000, 131, 20}, + } { + for _, anchor := range []uint32{scenario.low, scenario.high} { + t.Run(fmt.Sprintf("%d/QL%d", anchor, scenario.quality), func(t *testing.T) { + world, output := newQualityKitWorld(t, anchor, scenario.quality) + player := world.characters[1] + weapon := player.inventory.Items[0] + started := time.Now() + + if err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 65, 1)[20:]); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + t.Cleanup(func() { cold.db.Close() }) + + expected := []ownedItem{weapon, {ID: 2, Type: 51005, Template: anchor, Quality: scenario.quality, Slot: 65, Count: 2}} + if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) || + player.health < 1+scenario.health[0] || player.health > 1+scenario.health[1] || + player.nano < 1+scenario.nano[0] || player.nano > 1+scenario.nano[1] || + cold.characters[1].health != player.health || cold.characters[1].nano != player.nano || + player.inventory.Items[1].shopPrice() != scenario.price || world.nextItem != 2 { + t.Fatal("selected quality lost restoration, price, charges or cold ownership", player.inventory, player.health, player.nano) + } + deadline := player.skillLocks[scenario.skill] + if deadline.Before(started.Add(scenario.seconds*time.Second)) || deadline.After(time.Now().Add(scenario.seconds*time.Second)) || + !cold.characters[1].skillLocks[scenario.skill].Equal(deadline) { + t.Fatal("selected quality changed the authored durable cooldown") + } + low, high := scenario.low, scenario.high + if scenario.quality == 1 { + high = low + } else if scenario.quality == 200 { + low = high + } + if len(output.packets) < 2 || binary.BigEndian.Uint32(output.packets[0][29:33]) != 1 || + binary.BigEndian.Uint32(output.packets[1][16:20]) != 0x35505644 || + binary.BigEndian.Uint32(output.packets[1][29:33]) != low || binary.BigEndian.Uint32(output.packets[1][33:37]) != high || + binary.BigEndian.Uint32(output.packets[1][37:41]) != scenario.quality { + t.Fatal("native use lost selected quality or endpoint identities", output.packets) + } + }) + } + } +} + +func TestResourceKitSelectedQualityStrictSkillThresholds(t *testing.T) { + for _, scenario := range []struct { + template, quality uint32 + field string + threshold uint16 + }{ + {25812, 2, "treatment", 11}, {25812, 100, "treatment", 451}, {25811, 101, "treatment", 456}, + {85366, 2, "first aid", 12}, {85366, 100, "first aid", 501}, {85367, 101, "first aid", 506}, + {25820, 2, "treatment", 10}, {25820, 2, "time space", 10}, + {25821, 101, "treatment", 355}, {25821, 101, "time space", 355}, + } { + t.Run(fmt.Sprintf("%d/QL%d/%s", scenario.template, scenario.quality, scenario.field), func(t *testing.T) { + world, output := newQualityKitWorld(t, scenario.template, scenario.quality) + player := world.characters[1] + field := &player.stats.NanoAiding.Treatment + switch scenario.field { + case "first aid": + field = &player.stats.NanoAiding.FirstAid + case "time space": + field = &player.stats.NanoAiding.TimeAndSpace + } + *field = scenario.threshold + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + + err = world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 65, 1)[20:]) + after, readErr := readTestItemStore(world) + + if err != nil || readErr != nil || !bytes.Equal(before, after) || player.health != 1 || player.nano != 1 || + player.inventory.Items[1].Count != 3 || len(player.skillLocks) != 0 || len(output.packets) != 1 || + binary.BigEndian.Uint32(output.packets[0][29:33]) != 2 { + t.Fatal("threshold equality restored resources, consumed a charge or acquired a lock", err, readErr) + } + + *field++ + output.packets = nil + if err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 65, 2)[20:]); err != nil { + t.Fatal(err) + } + + if player.inventory.Items[1].Count != 2 || len(output.packets) < 2 || binary.BigEndian.Uint32(output.packets[0][29:33]) != 1 { + t.Fatal("one point above the selected-quality threshold did not permit use") + } + }) + } +} + +func TestResourceKitSelectedQualityRollbackAndReplay(t *testing.T) { + for _, failure := range []struct{ name, sql string }{ + {"charge error", "CREATE TRIGGER reject_kit BEFORE UPDATE OF count ON items BEGIN SELECT RAISE(FAIL, 'charge'); END"}, + {"ignored charge", "CREATE TRIGGER reject_kit BEFORE UPDATE OF count ON items BEGIN SELECT RAISE(IGNORE); END"}, + {"lock error", "CREATE TRIGGER reject_kit BEFORE INSERT ON skill_locks BEGIN SELECT RAISE(FAIL, 'lock'); END"}, + {"ignored health", "CREATE TRIGGER reject_kit BEFORE UPDATE OF health ON characters BEGIN SELECT RAISE(IGNORE); END"}, + {"commit error", "CREATE TABLE pending_kit (id INTEGER REFERENCES items(id) DEFERRABLE INITIALLY DEFERRED); CREATE TRIGGER reject_kit AFTER UPDATE OF count ON items BEGIN INSERT INTO pending_kit VALUES (999999); END"}, + } { + t.Run(failure.name, func(t *testing.T) { + world, output := newQualityKitWorld(t, 25812, 101) + player := world.characters[1] + if _, err := world.db.Exec(failure.sql); err != nil { + t.Fatal(err) + } + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + + failure := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 65, 1)[20:]) + after, readErr := readTestItemStore(world) + + if failure == nil || readErr != nil || !bytes.Equal(before, after) || len(output.packets) != 0 || + player.health != 1 || player.nano != 1 || player.inventory.Items[1].Count != 3 || len(player.skillLocks) != 0 { + t.Fatal("failed selected-quality use published a partial restoration or debit", failure, readErr) + } + + if _, err := world.db.Exec("DROP TRIGGER reject_kit"); err != nil { + t.Fatal(err) + } + for _, sequence := range []uint32{2, 3} { + if err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 65, sequence)[20:]); err != nil { + t.Fatal(err) + } + } + cold := newTestInventoryServer(t) + t.Cleanup(func() { cold.db.Close() }) + + if player.health != 770 || player.inventory.Items[1].Count != 2 || cold.characters[1].health != 770 || + !slices.Equal(cold.characters[1].inventory.Items, player.inventory.Items) || world.nextItem != 2 || len(player.skillLocks) != 1 { + t.Fatal("retry or immediate locked replay lost or repeated the selected-quality effect") + } + }) + } +} + +func TestResourceKitSelectedQualityRejectsUnsupportedUpperContract(t *testing.T) { + world, output := newQualityKitWorld(t, 25812, 2) + original := gamedata.ItemTemplates[25811] + definition := *original + definition.Sections = slices.Clone(original.Sections) + functions := slices.Clone(*definition.Sections[0].Functions) + functions[0].ID = 53051 + definition.Sections[0].Functions = &functions + gamedata.ItemTemplates[25811] = &definition + t.Cleanup(func() { gamedata.ItemTemplates[25811] = original }) + before, err := readTestItemStore(world) + if err != nil { + t.Fatal(err) + } + + err = world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 65, 1)[20:]) + after, readErr := readTestItemStore(world) + + if err != nil || readErr != nil || !bytes.Equal(before, after) || world.characters[1].health != 1 || + world.characters[1].inventory.Items[1].Count != 3 || len(output.packets) != 1 || binary.BigEndian.Uint32(output.packets[0][29:33]) != 2 { + t.Fatal("a supported lower endpoint enabled part of an unsupported upper contract", err, readErr) + } +} + +func TestResourceKitSelectedQualityLastChargeRemovesItsNativeEndpoints(t *testing.T) { + for _, scenario := range []struct{ template, quality, low, high uint32 }{ + {25812, 2, 25812, 25811}, {85367, 2, 85366, 85367}, {25820, 100, 25820, 25821}, + } { + t.Run(fmt.Sprint(scenario.template), func(t *testing.T) { + world, output := newQualityKitWorld(t, scenario.template, scenario.quality) + player := world.characters[1] + player.inventory.Items[1].Count = 1 + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + weapon := player.inventory.Items[0] + + if err := world.handleOwnedItemUse(world.clients[1], backpackUseRequest(1, 65, 1)[20:]); err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t) + t.Cleanup(func() { cold.db.Close() }) + + var body []byte + // Native inventory slot 49 represents the server's ordinary slot 65. + for _, value := range []uint32{112, 104, 49, scenario.low, scenario.high} { + body = binary.BigEndian.AppendUint32(body, value) + } + removed := slices.ContainsFunc(output.packets, func(packet []byte) bool { + return binary.BigEndian.Uint32(packet[16:20]) == 0x5e477770 && bytes.Equal(packet[29:49], body) + }) + if !removed || !slices.Equal(player.inventory.Items, []ownedItem{weapon}) || + !slices.Equal(cold.characters[1].inventory.Items, []ownedItem{weapon}) || len(cold.items) != 1 || cold.nextItem != 2 { + t.Fatalf("last selected-quality charge: removal=%t live=%+v cold=%+v items=%d next=%d packets=%x", removed, player.inventory.Items, cold.characters[1].inventory.Items, len(cold.items), cold.nextItem, output.packets) + } + }) + } +}