commit d851cc2af176949c4fd2b30c906587735433860c
parent fba855beec2d057e6eb7b0416d4736ef4ece3a18
Author: anon <anon@example.com>
Date: Thu, 22 Oct 2026 11:50:02 +0000
Support native Metaplast armor equipment
Diffstat:
11 files changed, 504 insertions(+), 20 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -51,7 +51,7 @@ recorded in [inventory behavior](docs/inventory.md).
data replace fists; unequipping restores fists, including for another observer.
- [x] Enforce that weapon's requirements. Check: a character below one required
skill cannot equip it, while a qualifying character can.
-- [ ] Equip one armor piece. Check: the correct native slot and appearance
+- [x] Equip one armor piece. Check: the correct native slot and appearance
update, and its armor stats appear and disappear with equip/unequip.
- [ ] Apply one equipment stat bonus. Check: a known bonus affects derived stats
exactly once and unequipping restores the baseline.
@@ -66,6 +66,10 @@ recorded in [inventory behavior](docs/inventory.md).
- [ ] Apply overequipping rules to one weapon. Check: dropping below a verified
requirement threshold changes effectiveness at the correct boundary.
+The supported Metaplast pieces, native appearance and AC modifier checks are
+recorded in [armor](docs/armor.md). Server-side damage reduction and broader
+derived-stat bonuses remain separate milestones.
+
## Combat calculations
- [ ] Resolve hit versus miss. Check: controlled test rolls produce the matching
diff --git a/docs/armor.md b/docs/armor.md
@@ -0,0 +1,127 @@
+# Metaplast armor in 14.9.1
+
+The first supported armor pieces are exact QL 1 catalog records. Their native
+identity type is 51022. Acquisition remains fixture-controlled, like the first
+weapon and corpse items.
+
+| Item | Template | Native slot | Catalog |
+| --- | --- | --- | --- |
+| Worn Metaplast Body Armor | 85686 | 21, chest | `server/gamedata/items/items_005.yaml` |
+| Worn Metaplast Armor Boots | 85638 | 30, feet | `server/gamedata/items/items_004.yaml` |
+
+Both Wear actions require Strength 16 and Agility 17 strictly greater than 7.
+Both have EquipDelay 211 equal to 10 centiseconds, processed on the existing
+250 ms equipment tick. Their default armor positions are 5 and 14, within the
+armor range starting at 16. The native inventory remains 48..77; armor slots
+are not shifted by the ordinary-inventory conversion.
+
+The chest's OnWear section (type 2, subtype 14) adds 5 to AC stats 90..93 and
+1 to 94..97. The boots add 1 to all eight. These are authored Modify 53045
+functions, rather than raw base-stat assignments. The accompanying Texture
+53039 functions use texture/category pairs 8736/1 and 9424/2. Both records have
+one tick, interval zero, target 2 and no effect requirements.
+
+The native labels map these totals as follows:
+
+| Protection | Stat | Chest | Boots | Both |
+| --- | --- | --- | --- | --- |
+| Projectile | 90 | 5 | 1 | 6 |
+| Melee | 91 | 5 | 1 | 6 |
+| Energy | 92 | 5 | 1 | 6 |
+| Chemical | 93 | 5 | 1 | 6 |
+| Radiation | 94 | 1 | 1 | 2 |
+| Cold | 95 | 1 | 1 | 2 |
+| Disease | 96 | 1 | 1 | 2 |
+| Fire | 97 | 1 | 1 | 2 |
+
+## Native move and effect messages
+
+Native left-click pickup/place sends ContainerAddItem `0x47537a24` from
+ordinary page 104 to slot 21 or 30. Removal uses page 102 and destination 111,
+which the server resolves to the first free ordinary slot while preserving 111
+in the acknowledgement. Wrong pages, foreign owners, unsupported templates or
+qualities, occupied slots and insufficient abilities cannot change ownership.
+The entire inventory is saved before acknowledging a completed move. Failed
+writes and a full inventory retain the equipped item and its effects.
+
+TemplateAction `0x35505644` executes the item's authored effects. Its payload
+is nine network-order uint32 values:
+
+```text
+low_template, high_template, quality, count,
+action, placement_type, placement_slot, auxiliary_type, auxiliary_instance
+```
+
+For these items the endpoints are identical, count is 1, placement is page
+102 and the actual equipped slot, and the auxiliary identity is 0/0. Action 6
+wears; action 7 removes. Live equipment sends only the changed item's action.
+Removing one piece therefore leaves the other piece's modifier contribution.
+The owner also receives the container acknowledgement; observers receive the
+appearance action without another player's inventory transfer.
+
+The owner restores equipped effects while processing its FullCharacter
+inventory. It must not receive another wear action after that initialization:
+that would add the AC contribution twice. Observers, which receive only the
+SimpleChar spawn, receive one wear action per equipped piece after that spawn.
+Weapon instance restoration retains its separate existing path.
+
+Player SimpleChar spawns also set flag bit 3. Native `FUN_100821d0` assigns
+that bit to CanChangeClothes stat 223, and `FUN_1006c8d0` passes it to
+`n3VisualDynel_t::SetCatMesh`. The resulting VisualCATMesh constructor stores
+it at offset 0x80; its `ChangeClothes` returns immediately when that field is
+zero. Correct item effects alone therefore cannot update a character whose
+spawn disabled clothing changes. This flag is enabled for human players.
+
+This chain is retained in `local/reports/armor-1491-visual-evidence.json`,
+including `ev_3b0a69b2fc083c0a402327c55b2989657a34cc90de80c8e469e5d01e58060287`
+for spawn activation and
+`ev_c2f421b82b6d3873c446577a1086572fdacfcf04fb090f41afe4f56ecb5f1db6`
+for mesh recreation. The remaining calls are preserved in generated
+`llr.dll/lifted-0024.c`, `sub_3803DBE0`, and
+`bbr.dll/lifted-0032.c`, `sub_25094C90` and `sub_25096190`.
+
+The native registration, reader and dispatch are established by original
+`kkr.dll` `FUN_10010820`, `FUN_100848d0`, `FUN_100849c0` and
+`FUN_1005e980`. The latter dispatches action 6 to the item's wear method and
+7 to removal. `FUN_1005e150` identifies the armor slot range 16..31.
+`FUN_100bdbd0` applies/removes Texture effects; the existing
+[effect findings](combat-client-effects.md) establish additive Modify behavior.
+The binary's SHA-256 is
+`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`.
+
+Retained REA evidence is `local/reports/armor-1491-evidence.json`. Relevant IDs:
+
+- Registration: `ev_025c239a4146bc05fdba8c82ad2de28fe96c6f9e882a87c282ad43660dc5d98c`.
+- Reader: `ev_518cb4fc0a5f0d47407eb112c8bb777ef3a39156eec999ea0011ab26318c4031`.
+- Activation: `ev_82adf3a0d509e883a80d1484997c274ef958e017ee63fd3f38125aea9a868dda`.
+- Action dispatch: `ev_4203147dbcdc433f3644bb1d2da1a6842f4328e5ccabf19a21a0fd2f7459c324`.
+- Slot ranges: `ev_21dea5efecb173a3113d482b7e7334a8bff2b0e65d6b20b5b78419d1783ac687`.
+- Texture execution: `ev_cc608ed85cc16c5372eeb247db3e76457e61ad0dd1e0502d22dae1e7e43b603e`.
+
+## Verification boundary
+
+`server/armor_test.go` checks the catalog effects, delay, exact ability
+boundary, invalid slots/pages/qualities/identities, occupied slots, changed
+requirements, failed saves, full bags, two-piece removal, native payloads and
+restart initialization. Existing weapon and inventory bounds regressions also
+cover the extended equipment handler.
+
+These messages establish equipped ownership, native appearance and native AC
+modifiers. Authoritative damage reduction by AC remains a separate combat
+milestone; the current damage calculation still does not consult armor.
+
+The two-client Chromium WASM run is retained in `local/armor-smoke/` with
+`verification.json`, per-step screenshots/state and packet logs. Native pickup
+and placement equipped both pieces, then removed each independently. Owner and
+observer saw matching chest/boot appearance; the native Protection window
+showed 6/2 with both pieces, 5/1 with the chest alone, and eight 1s with boots
+alone. Both removals restored eight zeroes in the initial protocol pass.
+A server restart restored the same IDs 100/101 and QL 1 at slots 21/30, with
+6/2 rather than doubled modifiers; the observer automatically reconnected
+and saw the restored armor. There were no page errors or adapter failures.
+The only console failures were 16 expected socket connection refusals during
+the intentional restart. Both browser contexts and the test server closed in
+the driver's `finally` block.
+
+The full `go test ./server/...` suite passes. Focused race checks for armor,
+equipment, inventory and reclaim also pass.
diff --git a/docs/combat-client-reconstruction.md b/docs/combat-client-reconstruction.md
@@ -79,7 +79,8 @@ unknowns for each area:
| Player max/current health and nano | Native formula, breed/title resources, browser 37/37 | Derived from editable abilities and base Body Development/Nano Pool; Soldier profession |
| Martial Arts selecting fist QL | Period observation; exact native selector not found | Fixed QL 1, not a recovered MA-to-QL selection rule |
| NPC health, damage and weapons | Level-1 Leet weapon data verified; binding and actor stats provisional | Exact-level Leet profile with replicated bite weapon; other NPCs retain prototype values |
-| Armor, evade/critical rolls and damage modifiers | Client data/handlers do not alone establish authoritative calculation | Not implemented |
+| QL 1 Metaplast chest armor and boots | Shipped wear effects and native packets, owner/observer WASM checks | Persistent equip/unequip, appearance and native AC modifiers; [armor notes](armor.md) |
+| Armor damage reduction, evade/critical rolls and damage modifiers | Client data/handlers do not alone establish authoritative calculation | Not implemented |
| Range and physical extents | Native formula recovered; instance extent construction needs full reconciliation | Four-meter center-distance approximation |
| Line of sight | Client checks cannot establish original server validation | Not implemented on the server |
| Dual wield, ammunition/reload, specials and nanos | Scheduling, core effect streams and skill-lock contract recovered; full effect semantics remain partial | Not implemented |
diff --git a/docs/inventory.md b/docs/inventory.md
@@ -19,7 +19,8 @@ Only individual items at an exact catalog quality are supported. Template
endpoints are identical; arbitrary-quality interpolation, stacks, backpacks
and starter loadouts remain separate milestones. Native corpse pickup is
described in [the corpse and loot protocol](corpse-loot.md). QL 1 Kinetic Axe equipment
-is described below; other equipment is not supported yet.
+is described below. Exact QL 1 Metaplast chest armor and boots use the
+[native armor path](armor.md). Other equipment remains unsupported.
## Native messages
diff --git a/server/armor_test.go b/server/armor_test.go
@@ -0,0 +1,292 @@
+package main
+
+import (
+ "ao/server/gamedata"
+ "bytes"
+ "encoding/binary"
+ "net"
+ "os"
+ "reflect"
+ "testing"
+ "time"
+)
+
+func newArmorWorld(t *testing.T) (*server, *combatTestConn) {
+ t.Helper()
+ world, conn := newEquipmentWorld(t)
+ world.characters[1].stats.Strength, world.characters[1].stats.Agility = 8, 8
+ for _, template := range []uint32{85686, 85638} {
+ if granted, err := world.grantItem_locked(world.characters[1], template); err != nil || !granted {
+ t.Fatalf("grant armor: %v %v", granted, err)
+ }
+ }
+ return world, conn
+}
+
+func TestArmorNativeMoveDelayAndRestart(t *testing.T) {
+ world, conn := newArmorWorld(t)
+ observer := &combatTestConn{}
+ world.characters[2] = &character{id: 2, playfield: 950, health: 100}
+ world.clients[2] = &worldClient{id: 2, conn: observer, target: true, ready: true}
+ before, err := os.ReadFile("data/players/1/inventory.yaml")
+ if err != nil {
+ t.Fatal(err)
+ }
+ request := inventoryMovePacket(1, 65, 21)[20:]
+
+ started := time.Now()
+ if err := world.handleInventory(world.clients[1], request); err != nil {
+ t.Fatal(err)
+ }
+ finish := world.clients[1].equipment.readyAt
+ if finish.Before(started.Add(100*time.Millisecond)) || finish.After(time.Now().Add(100*time.Millisecond)) {
+ t.Fatalf("armor delay differs from the catalog: %v", finish.Sub(started))
+ }
+ world.handleInventory(world.clients[1], request)
+ world.advanceEquipment(finish.Add(-time.Nanosecond))
+ unchanged, err := os.ReadFile("data/players/1/inventory.yaml")
+ if err != nil || !bytes.Equal(before, unchanged) || len(conn.packets) != 0 {
+ t.Fatalf("pending wear changed state: %v", err)
+ }
+ world.advanceEquipment(finish)
+ restarted := newTestInventoryServer(t)
+
+ if !reflect.DeepEqual(restarted.characters[1].inventory.Items, []ownedItem{{1, 51018, 209283, 1, 64}, {2, 51022, 85686, 1, 21}, {3, 51022, 85638, 1, 66}}) {
+ t.Fatalf("armor identity or slot did not persist: %+v", restarted.characters[1].inventory)
+ }
+ if len(conn.packets) != 2 || len(observer.packets) != 1 ||
+ binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x47537a24 ||
+ binary.BigEndian.Uint32(conn.packets[0][45:49]) != 21 ||
+ binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x35505644 ||
+ !bytes.Equal(conn.packets[1][16:], observer.packets[0][16:]) {
+ t.Fatalf("armor replication: owner=%x observer=%x", conn.packets, observer.packets)
+ }
+ var expected []byte
+ for _, value := range []uint32{85686, 85686, 1, 1, 6, 102, 21, 0, 0} {
+ expected = binary.BigEndian.AppendUint32(expected, value)
+ }
+ if !bytes.Equal(conn.packets[1][29:65], expected) {
+ t.Fatalf("native wear payload: %x", conn.packets[1])
+ }
+}
+
+func TestArmorTwoPiecesAndRemovalNotifyOnlyChangedItem(t *testing.T) {
+ for _, slot := range []uint32{21, 30} {
+ t.Run(map[uint32]string{21: "chest", 30: "boots"}[slot], func(t *testing.T) {
+ world, conn := newArmorWorld(t)
+ for _, move := range [][2]uint32{{65, 21}, {66, 30}} {
+ world.handleInventory(world.clients[1], inventoryMovePacket(1, move[0], move[1])[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ }
+ initial := equippedItemPackets(world.characters[1])
+ conn.packets = nil
+
+ world.handleInventory(world.clients[1], itemMovePacket(1, slot, 111)[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ world.handleInventory(world.clients[1], itemMovePacket(1, slot, 111)[20:])
+ restarted := newTestInventoryServer(t)
+
+ if len(initial) != 2 || len(conn.packets) != 2 ||
+ binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x35505644 ||
+ binary.BigEndian.Uint32(conn.packets[0][45:49]) != 7 ||
+ binary.BigEndian.Uint32(conn.packets[0][53:57]) != slot ||
+ binary.BigEndian.Uint32(conn.packets[1][29:33]) != 102 ||
+ binary.BigEndian.Uint32(conn.packets[1][45:49]) != 111 {
+ t.Fatalf("removal repeated or changed another modifier: %x", conn.packets)
+ }
+ packets := equippedItemPackets(restarted.characters[1])
+ other := uint32(30)
+ if slot == 30 {
+ other = 21
+ }
+ if len(packets) != 1 || binary.BigEndian.Uint32(packets[0][60:64]) != other {
+ t.Fatalf("reconnect restored removed armor or lost the other piece: %x", packets)
+ }
+ if len(restarted.characters[1].inventory.Items) != 3 {
+ t.Fatal("armor removal lost an item")
+ }
+ })
+ }
+}
+
+func TestArmorRejectsRequirementsAndInterruptedWear(t *testing.T) {
+ for _, scenario := range []string{"strength", "agility", "wrong slot", "unsupported quality", "unsupported identity", "occupied", "changed requirement", "failed save"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, _ := newArmorWorld(t)
+ player := world.characters[1]
+ destination := uint32(21)
+ switch scenario {
+ case "strength":
+ player.stats.Strength = 7
+ case "agility":
+ player.stats.Agility = 7
+ case "wrong slot":
+ destination = 30
+ case "unsupported quality":
+ player.inventory.Items[1].Quality = 2
+ case "unsupported identity":
+ player.inventory.Items[1].Type = 51018
+ case "occupied":
+ player.inventory.Items = append(player.inventory.Items, ownedItem{4, 51022, 85686, 1, 21})
+ }
+ before := append([]ownedItem(nil), player.inventory.Items...)
+
+ world.handleInventory(world.clients[1], inventoryMovePacket(1, 65, destination)[20:])
+ if scenario == "changed requirement" || scenario == "failed save" {
+ if world.clients[1].equipment == nil {
+ t.Fatal("valid armor move was rejected")
+ }
+ if scenario == "changed requirement" {
+ player.stats.Agility = 7
+ } else {
+ os.Remove("data/players/1/inventory.yaml")
+ os.Mkdir("data/players/1/inventory.yaml", 0700)
+ }
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ }
+
+ if world.clients[1].equipment != nil || !reflect.DeepEqual(before, player.inventory.Items) {
+ t.Fatalf("rejected armor move changed ownership: %+v", player.inventory)
+ }
+ })
+ }
+}
+
+func TestArmorNativeSlotsAndForgedPage(t *testing.T) {
+ world, conn := newArmorWorld(t)
+ body := inventoryMovePacket(1, 65, 21)[20:]
+ binary.BigEndian.PutUint32(body[20:24], 49)
+ decodeInventory1491(body)
+
+ if err := world.handleInventory(world.clients[1], body); err != nil {
+ t.Fatal(err)
+ }
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ conn.packets = nil
+ forged := itemMovePacket(1, 21, 111)[20:]
+ binary.BigEndian.PutUint32(forged[16:20], 104)
+ world.handleInventory(world.clients[1], forged)
+ world.clients[1].send(fullCharacterPacket(world.characters[1]))
+
+ if world.characters[1].inventory.Items[1].Slot != 21 || world.clients[1].equipment != nil || len(conn.packets) != 1 ||
+ binary.BigEndian.Uint32(conn.packets[0][69:73]) != 21 {
+ t.Fatalf("armor native slot or page validation: %x %+v", conn.packets, world.characters[1].inventory)
+ }
+}
+
+func TestArmorCatalogProtectionAndTexture(t *testing.T) {
+ for _, item := range []struct {
+ template uint32
+ armor [8]int32
+ texture int32
+ category int32
+ }{
+ {85686, [8]int32{5, 5, 5, 5, 1, 1, 1, 1}, 8736, 1},
+ {85638, [8]int32{1, 1, 1, 1, 1, 1, 1, 1}, 9424, 2},
+ } {
+ t.Run(gamedata.ItemTemplates[item.template].Name, func(t *testing.T) {
+ var armor [8]int32
+ var texture, category int32
+
+ for _, section := range gamedata.ItemTemplates[item.template].Sections {
+ if section.Type != 2 || section.Subtype != 14 {
+ continue
+ }
+ for _, function := range *section.Functions {
+ switch function.ID {
+ case 53045:
+ armor[*function.Arguments[0].Integer-90] += *function.Arguments[1].Integer
+ case 53039:
+ texture, category = *function.Arguments[0].Integer, *function.Arguments[1].Integer
+ }
+ }
+ }
+
+ if armor != item.armor || texture != item.texture || category != item.category {
+ t.Fatalf("catalog wear effects differ: %v %d/%d", armor, texture, category)
+ }
+ })
+ }
+}
+
+func TestArmorFullInventoryRetainsEquippedPiece(t *testing.T) {
+ world, conn := newArmorWorld(t)
+ world.handleInventory(world.clients[1], inventoryMovePacket(1, 65, 21)[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ for range 28 {
+ if granted, err := world.grantItem_locked(world.characters[1], 121567); err != nil || !granted {
+ t.Fatalf("fill inventory: %v %v", granted, err)
+ }
+ }
+ before, err := os.ReadFile("data/players/1/inventory.yaml")
+ if err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ err = world.handleInventory(world.clients[1], itemMovePacket(1, 21, 111)[20:])
+ after, readErr := os.ReadFile("data/players/1/inventory.yaml")
+
+ if err != nil || readErr != nil || !bytes.Equal(before, after) || world.clients[1].equipment != nil || len(conn.packets) != 1 ||
+ binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x47537a24 || binary.BigEndian.Uint32(conn.packets[0][45:49]) != 21 {
+ t.Fatalf("full inventory changed armor or removed its effects: %v %v %x", err, readErr, conn.packets)
+ }
+}
+
+func TestArmorReconnectUsesInventoryWithoutRepeatingWear(t *testing.T) {
+ world, _ := newArmorWorld(t)
+ for _, move := range [][2]uint32{{65, 21}, {66, 30}} {
+ world.handleInventory(world.clients[1], inventoryMovePacket(1, move[0], move[1])[20:])
+ world.advanceEquipment(world.clients[1].equipment.readyAt)
+ }
+ world = newTestInventoryServer(t)
+ client, connection := net.Pipe()
+ defer client.Close()
+ client.SetDeadline(time.Now().Add(5 * time.Second))
+ done := make(chan error, 1)
+ go func() { defer connection.Close(); done <- world.serveWorldConnection(connection) }()
+ cookie := systemPacket(0x1b, []byte{0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0})
+ binary.BigEndian.PutUint16(cookie, 0xdfdf)
+
+ client.Write(cookie)
+ var slots []uint32
+ inventorySeen := false
+ for {
+ packet, err := readPacket(client)
+ if err != nil {
+ t.Fatal(err)
+ }
+ key := binary.BigEndian.Uint32(packet[16:20])
+ if key == 0x29304349 {
+ inventorySeen = true
+ if binary.BigEndian.Uint32(packet[69:73]) != 21 || binary.BigEndian.Uint32(packet[101:105]) != 30 {
+ t.Fatalf("reconnect inventory omitted armor slots: %x", packet)
+ }
+ }
+ if key == 0x35505644 {
+ if !inventorySeen || binary.BigEndian.Uint32(packet[45:49]) != 6 {
+ t.Fatalf("wear before owner inventory: %x", packet)
+ }
+ slots = append(slots, binary.BigEndian.Uint32(packet[53:57]))
+ }
+ if key == 0x5f52412e {
+ break
+ }
+ }
+ client.Close()
+ err := <-done
+
+ if err != nil || !inventorySeen || len(slots) != 0 {
+ t.Fatalf("reconnect repeated armor wear: slots=%v err=%v", slots, err)
+ }
+}
+
+func TestArmorPlayerSpawnEnablesNativeClothingChanges(t *testing.T) {
+ player := &character{id: 1, appearance: 0x515, level: 1}
+
+ packet := targetPacket(characterPacket(player))
+
+ if binary.BigEndian.Uint32(packet[30:34])&8 == 0 {
+ t.Fatal("player spawn disabled native clothing changes")
+ }
+}
diff --git a/server/equipment.go b/server/equipment.go
@@ -20,6 +20,29 @@ func (item ownedItem) isKineticAxe() bool {
return item.Type == 51018 && item.Template == 209283 && item.Quality == 1
}
+func (item ownedItem) equipmentSlot() uint32 {
+ if item.isKineticAxe() {
+ return 6
+ }
+ if item.Type == 51022 && item.Quality == 1 {
+ switch item.Template {
+ case 85686:
+ return 21
+ case 85638:
+ return 30
+ }
+ }
+ return 0
+}
+
+func (character *character) canEquip(item ownedItem) bool {
+ if item.isKineticAxe() {
+ return character.canWieldKineticAxe()
+ }
+ // Both QL 1 Metaplast pieces require Strength and Agility greater than 7.
+ return character.baseStats().Strength > 7 && character.baseStats().Agility > 7
+}
+
func (character *character) meleeWeapon() *gamedata.Item {
if character.npc && character.combatProfile != nil {
return gamedata.ItemTemplates[character.combatProfile.Weapon]
@@ -53,6 +76,8 @@ func itemMovePacket(owner, source, destination uint32) []byte {
page := uint32(104)
if source == 6 {
page = 101
+ } else if source == 21 || source == 30 {
+ page = 102
}
var body []byte
for _, value := range []uint32{page, source, 50000, owner, destination} {
@@ -78,16 +103,16 @@ func (server *server) beginEquipment_locked(client *worldClient, index int, dest
character := server.characters[client.id]
item := character.inventory.Items[index]
requestedSlot := destination
- if destination == 111 && item.Slot == 6 {
+ if destination == 111 && item.Slot < 64 {
for destination = 64; destination < 94; destination++ {
if !slices.ContainsFunc(character.inventory.Items, func(other ownedItem) bool { return other.Slot == destination }) {
break
}
}
}
- if !item.isKineticAxe() || destination == item.Slot ||
- (destination != 6 && (destination < 64 || destination >= 94)) ||
- (destination == 6 && !character.canWieldKineticAxe()) ||
+ if item.equipmentSlot() == 0 || destination == item.Slot ||
+ (destination != item.equipmentSlot() && (destination < 64 || destination >= 94)) ||
+ (destination < 64 && !character.canEquip(item)) ||
slices.ContainsFunc(character.inventory.Items, func(other ownedItem) bool { return other.Slot == destination }) ||
server.equipmentBlocked_locked(character, time.Now()) {
return client.send(itemMovePacket(client.id, item.Slot, item.Slot))
@@ -119,13 +144,14 @@ func (server *server) advanceEquipment(now time.Time) {
continue
}
if server.equipmentBlocked_locked(character, now) ||
- (move.destination == 6 && !character.canWieldKineticAxe()) ||
+ (move.destination < 64 && !character.canEquip(character.inventory.Items[index])) ||
slices.ContainsFunc(character.inventory.Items, func(item ownedItem) bool { return item.Slot == move.destination }) {
updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.source))
continue
}
// Save the entire move before publishing inventory or appearance changes.
+ item := character.inventory.Items[index]
inventory := character.inventory
inventory.Items = slices.Clone(character.inventory.Items)
inventory.Items[index].Slot = move.destination
@@ -134,6 +160,9 @@ func (server *server) advanceEquipment(now time.Time) {
updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.source))
continue
}
+ if move.source == 21 || move.source == 30 {
+ server.queueCombat_locked(updates, character, character, armorActionPacket(character.id, item, 7))
+ }
if move.source == 6 {
server.queueCombat_locked(updates, character, character, weaponUnequipPacket(client.id))
for id, observer := range server.clients {
@@ -143,7 +172,12 @@ func (server *server) advanceEquipment(now time.Time) {
}
}
updates[client] = append(updates[client], itemMovePacket(client.id, move.source, move.requestedSlot))
- server.queueCombat_locked(updates, character, character, equippedWeaponPackets(character)...)
+ if move.destination == 21 || move.destination == 30 {
+ server.queueCombat_locked(updates, character, character, armorActionPacket(character.id, character.inventory.Items[index], 6))
+ }
+ if move.source == 6 || move.destination == 6 {
+ server.queueCombat_locked(updates, character, character, equippedWeaponPackets(character)...)
+ }
}
server.mutex.Unlock()
server.sendCombatUpdates(updates)
@@ -176,3 +210,22 @@ func equippedWeaponPackets(character *character) [][]byte {
}
return nil
}
+
+func armorActionPacket(owner uint32, item ownedItem, action uint32) []byte {
+ // kkr.dll FUN_100848d0: template endpoints, QL, count, action and two identities.
+ var body []byte
+ for _, value := range []uint32{item.Template, item.Template, item.Quality, 1, action, 102, item.Slot, 0, 0} {
+ body = binary.BigEndian.AppendUint32(body, value)
+ }
+ return n3Packet(0x35505644, 50000, owner, body)
+}
+
+func equippedItemPackets(character *character) [][]byte {
+ packets := equippedWeaponPackets(character)
+ for _, item := range character.inventory.Items {
+ if item.Slot == 21 || item.Slot == 30 {
+ packets = append(packets, armorActionPacket(character.id, item, 6))
+ }
+ }
+ return packets
+}
diff --git a/server/inventory.go b/server/inventory.go
@@ -34,8 +34,8 @@ func (inventory playerInventory) validate() error {
slots := make(map[uint32]bool)
for _, item := range inventory.Items {
if item.ID == 0 || item.ID > inventory.LastID || ids[item.ID] ||
- (item.Slot != 6 && (item.Slot < 64 || item.Slot >= 94)) || slots[item.Slot] ||
- (item.Slot == 6 && !item.isKineticAxe()) {
+ (item.Slot < 64 && (item.equipmentSlot() == 0 || item.Slot != item.equipmentSlot())) ||
+ item.Slot >= 94 || slots[item.Slot] {
return fmt.Errorf("invalid inventory item identity or slot")
}
ids[item.ID], slots[item.Slot] = true, true
@@ -119,22 +119,24 @@ func (server *server) handleInventory(client *worldClient, body []byte) error {
return server.takeLoot_locked(client, body)
}
index := slices.IndexFunc(character.inventory.Items, func(item ownedItem) bool { return item.Slot == sourceSlot })
- if index < 0 || (sourceSlot != 6 && sourceType != 104) || (sourceSlot == 6 && sourceType != 101) {
+ if index < 0 || (sourceSlot >= 64 && sourceType != 104) ||
+ (sourceSlot == 6 && sourceType != 101) ||
+ ((sourceSlot == 21 || sourceSlot == 30) && sourceType != 102) {
return nil
}
- if key == 0x47537a24 && (sourceSlot == 6 || binary.BigEndian.Uint32(body[32:36]) == 6) {
+ destination := binary.BigEndian.Uint32(body[32:36])
+ if key == 0x47537a24 && (sourceSlot < 64 || destination == 6 || destination == 21 || destination == 30) {
if binary.BigEndian.Uint32(body[24:28]) != 50000 || binary.BigEndian.Uint32(body[28:32]) != client.id {
return nil
}
- return server.beginEquipment_locked(client, index, binary.BigEndian.Uint32(body[32:36]))
+ return server.beginEquipment_locked(client, index, destination)
}
- if sourceSlot == 6 {
+ if sourceSlot < 64 {
return nil
}
inventory := character.inventory
inventory.Items = slices.Clone(character.inventory.Items)
if key == 0x47537a24 {
- destination := binary.BigEndian.Uint32(body[32:36])
if binary.BigEndian.Uint32(body[24:28]) != 50000 || binary.BigEndian.Uint32(body[28:32]) != client.id ||
destination < 64 || destination >= 94 ||
slices.ContainsFunc(inventory.Items, func(item ownedItem) bool { return item.Slot == destination }) {
diff --git a/server/main.go b/server/main.go
@@ -318,7 +318,7 @@ func (server *server) serveWorldClient(client *worldClient) error {
for id, other := range server.characters {
if id != character.id && other.playfield == character.playfield && server.clients[id] != nil {
updates = append(updates, characterPacket(other))
- updates = append(updates, equippedWeaponPackets(other)...)
+ updates = append(updates, equippedItemPackets(other)...)
if other.health == 0 {
updates = append(updates, deathPacket(other))
}
@@ -334,7 +334,7 @@ func (server *server) serveWorldClient(client *worldClient) error {
updates = append(updates, server.combatInterest_locked(client, nil)...)
updates = append(updates, gameTimePacket(character.id, server.gameSeconds_locked()))
spawn := characterPacket(character)
- equipment := equippedWeaponPackets(character)
+ equipment := equippedItemPackets(character)
playfield := character.playfield
server.mutex.Unlock()
server.sendCombatUpdates(combatUpdates)
diff --git a/server/main_test.go b/server/main_test.go
@@ -360,7 +360,7 @@ func TestWorldCookieThenPing(t *testing.T) {
if hex.EncodeToString(updates[1][122:154]) != "0000001c00000000000000000000000002010001000100010001000000020000" {
t.Fatalf("player vehicle state: %x", updates[1][122:154])
}
- if hex.EncodeToString(updates[1][37:41]) != "000002d0" || hex.EncodeToString(updates[1][154:158]) != "00009eea" {
+ if hex.EncodeToString(updates[1][37:41]) != "000002d8" || hex.EncodeToString(updates[1][154:158]) != "00009eea" {
t.Fatalf("player head mesh: %x", updates[1])
}
if hex.EncodeToString(updates[1][159:163]) != "000017a6" || hex.EncodeToString(updates[1][197:215]) != "68616e647300000022450000000000000000" {
diff --git a/server/target_protocol.go b/server/target_protocol.go
@@ -143,7 +143,7 @@ func decodeInventory1491(body []byte) {
binary.BigEndian.PutUint32(body[20:24], decodeInventorySlot1491(binary.BigEndian.Uint32(body[20:24])))
}
destination := binary.BigEndian.Uint32(body[32:36])
- if destination != 6 && destination != 111 {
+ if destination != 6 && destination != 21 && destination != 30 && destination != 111 {
binary.BigEndian.PutUint32(body[32:36], decodeInventorySlot1491(destination))
}
case 0x5e477770:
diff --git a/server/world.go b/server/world.go
@@ -61,6 +61,10 @@ func characterPacket(character *character) []byte {
}
if human {
flags |= 0x90
+ // kkr.dll FUN_100821d0: bit 3 enables CanChangeClothes (stat 223).
+ if !character.npc {
+ flags |= 8
+ }
}
if character.level > 255 {
flags |= 0x1000