aorecomp

Anarchy Online classic in the browser

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


commit b042ac23b29eecee096862d326de9b01a6384507
parent e23f8d31c788a3f4467e39922b5bf0f2c153f50a
Author: anon <anon@example.com>
Date:   Mon, 26 Oct 2026 11:49:54 +0000

Apply authored vehicle forms to shared collision bodies

Replay shape and scale effects in authored order, preserving incremental
sphere scaling, signed modifier refreshes and forced human body restoration.
Retain all 21 human meshes and reconstruct ordinary bodies on fresh loading.

Send live vehicle scale separately from the saved original in FullCharacter,
so owner and observer agree after reconnect and removal restores the profile
height. Apply collision effects only after committed equipment moves and
preserve lazy initialization for actors without a constructed body.

Validation: 1,288 server tests / 14,251 results; 201 affected race tests /
788 results; gamedata and export checks; vet; source-bound native evidence;
paired GPU WASM checks for both vehicles, signed Pioneer scale ordering,
cold reconstruction and removal. Final round-trip position error is under
4 cm. Owned clients and fixtures are cleaned up; the sole HTTPS preview is
healthy on the standard port.

Diffstat:
MTODO.md | 16+++++++++++++---
Mdocs/player-geometry.md | 68+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mdocs/vehicles.md | 5+++++
Mserver/gamedata/player_appearances.go | 2+-
Mserver/gamedata/player_appearances.yaml | 14+++++++-------
Mserver/inventory.go | 16++++++++++++++++
Mserver/player_collision.go | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
Aserver/player_form_test.go | 309+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/target_protocol.go | 7++++---
Mserver/world.go | 18+++++++++++++++---
Mserver/world_actions.go | 1+
Mtools/data/extract_player_appearances.py | 2+-
12 files changed, 542 insertions(+), 46 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -1245,10 +1245,20 @@ disconnect retention and succession policy still need period corroboration. ranges across multiple forms/scales. Finish fall-damage rules and special-mode jump/landing behavior, late observers during ascent, midair reconnect and roots/snares during a jump. Ordinary jump/landing is implemented below. Finish - internal/nonzero orientation modes, live Chest mass and encumbrance, and vehicle - and Grid form entry/exit body rebuilding (including current thin/fat mesh on - return). Add indoor room transforms, actor colliders and dynamic platforms. + internal/nonzero orientation modes, live Chest mass and encumbrance, and Grid + form entry/exit body rebuilding. Vehicle body replacement is implemented below; + flight activation/removal offsets, orientation modes and in-flight gravity + still need shared simulation and native trajectory checks. Add indoor room + transforms, actor colliders and dynamic platforms. See [player geometry](docs/player-geometry.md). +- [x] Apply supported vehicles' authored shape/scale effects to collision bodies. + Preserve OnWear order, separate form-setup and extent scale clamps, incremental + sphere scaling, and forced human restoration using all21 breed/sex/fatness + meshes. FullCharacter must carry live vehicle scale20 separately from the saved + original height, so removal after reconnect restores that height. Check equip + deadlines, rejected completion, failed persistence, signed Pioneer scale, + owner/observer reconstruction and actual ground projection. See + [vehicle collision bodies](docs/player-geometry.md#vehicle-forms-and-human-restoration). - [x] Simulate ordinary outdoor jumping and physical landing. Movement13 uses raw Strength/Agility, the native upward ceiling probe and mass/impulse float stores. Preserve horizontal controls, reject swimming/sitting and repeated airborne diff --git a/docs/player-geometry.md b/docs/player-geometry.md @@ -171,8 +171,9 @@ These are different transition rules, so one universal effective-scale clamp would be incorrect. Incremental native scale updates multiply the existing primitive by new/old scale instead of re-decoding metadata. Replacing the CAT through SetCatMesh rebuilds it. Grid form99902 resolves CAT99894, with radius -0.1000479981 and offsetY0.2507500052. Full Grid entry/exit and special appearance -flag lifecycles remain separate verification work. +0.1000479981 and offsetY0.2507500052. Supported vehicle forms and forced human +restoration are implemented below; Grid entry/exit and special appearance flag +lifecycles remain separate verification work. Six GPU WASM captures corroborate these contracts through normal control edits and read-only probes. Height1 becomes native base20, visual scale @@ -269,9 +270,66 @@ This verifies the formula and replicated limits, not exact swimming trajectories Remaining work includes shoreline/shallow-water and smoothing cadence, stairs, corners, narrow passages, blocked interactions, special jump modes and fall damage, -internal and nonzero orientation modes, live carried mass/encumbrance and full -vehicle/Grid/body-replacement lifecycles. Indoor room transforms, dynamic -platforms and actor colliders also remain separate work. +internal and nonzero orientation modes, live carried mass/encumbrance, Grid body +replacement and full flight lifecycles. Indoor room transforms, dynamic platforms +and actor colliders also remain separate work. + +## Vehicle forms and human restoration + +Collision follows the admitted item's ordered OnWear functions, using the same +MonsterData catalog as explicit actor templates. ChangeShape53060 selects the +form's stat12 CAT rather than retaining the human torso sphere. Kodaik99468 uses +CAT99458; Yalmaha99470 uses CAT42370. Both retain the player's breed/sex mass. +The in-memory body stores its current form, live base scale and signed modifier +balance, so movement predictions copy the actual collision history. + +Kodaik applies Shape then ChangeStat360; Yalmaha applies ChangeStat360 then +Shape. Removal runs functions in that same authored order. Form setup clamps +effective scale to20; an extent refresh clamps it to1. With Modified Pioneer +Backpack's -3 scale already worn, accepted Kodaik wear ends at scale0.17, while +Yalmaha wear ends at0.2. A later modifier refresh can change the latter to0.17. +These are event-specific clamps, not a universal minimum vehicle size. + +Form0 restoration forces the current human CAT to be reconstructed even when +its identity matches a previous CAT. The catalog retains all21 ordinary +breed/sex/fatness meshes. This differs from initial login: a slim Nanomage male +initially retains the normal5921 collision body despite render mesh17909; after +vehicle removal its new17909 body has authored offsetY0. Scale changes multiply +the existing primitive by new/old rather than decoding it again. Repeated ticks +and unrelated inventory changes preserve that restored body. A fresh owner +construction starts with the normal collision CAT again. + +FullCharacter installs its plain-counted saved-stat map before initial OnWear, +then applies its four live stat lists afterward. While driving, live360 is20; +the saved map carries the original profile height. Sending only the profile +height as live360 overrides the vehicle's earlier ChangeStat and makes owner +and observer scales disagree. The native tail for saved height150 is +`[1,360,150,0,1009,1009]`: map count/pair, optional-section presence, empty +encoded list and empty encoded effect list. The protocol adapter preserves +the variable-length saved map. Neither the stored profile height nor ownership +is replaced by the temporary scale20. + +Durable equipment moves finish before any live collision effects or success +packets. Pending, rejected and failed moves retain the previous body. Initial +reconstruction applies implants32..47, then ordinary worn slots0..31 in native +slot order, followed by the live base-scale refresh. Body changes themselves +do not force ground alignment; changed pose or simulation reconciles contact. +Position remains in memory until the usual checkpoint. + +The final full suite passes1,288 top-level tests and14,251 total test results; +the affected race cohort passes201 top-level tests and788 results. Data checks +and vet pass. The final-build Kodaik cold-load/removal round trip has maximum +position error0.03989 metres and height error below0.000001 metres across the +two native clients. Four earlier and one final native FullCharacter captures +verify the live20/saved150 fields. Nine earlier paired states additionally +verify Yalmaha, signed Pioneer effects and their distinct manual/cold scales. +No WASM page errors occurred. Six owned visitors and four fixture items were +removed; database checks and hashes preserve all unrelated rows. The sole +HTTPS preview remains on8443. + +This does not complete Grid replacement, special appearance flags, arbitrary +concurrent forms, flight activation/removal height offsets, orientation changes, +in-flight gravity or indoor vehicle policy. Those remain explicit TODOs. ## Ordinary outdoor jumps and landing diff --git a/docs/vehicles.md b/docs/vehicles.md @@ -42,6 +42,11 @@ and restoring the saved scale. The ordinary radius 421 is 2; native physical extent is `Scale * radius * 0.01`, giving 0.4 while driving and 2 afterward. The server rejects forged attack requests while the vehicle is equipped. +The shared movement simulation also applies the authored collision CAT and +ordered scale changes. Reconnect keeps live scale20 separate from the saved +profile height, and removal forces the current human fatness mesh. Details and +verification are in [vehicle collision bodies](player-geometry.md#vehicle-forms-and-human-restoration). + Existing TemplateAction `0x35505644` action 6/7, page 101 and slot 1 applies and removes the effects for both the owner and same-playfield observers. Owner FullCharacter initialization already applies worn effects once, so it diff --git a/server/gamedata/player_appearances.go b/server/gamedata/player_appearances.go @@ -10,6 +10,6 @@ type PlayerHead struct { type PlayerBody struct { Breed uint16 `yaml:"breed"` Sex uint16 `yaml:"sex"` - Mesh uint32 `yaml:"mesh"` + Meshes [3]uint32 `yaml:"meshes"` Textures map[uint16][5]uint32 `yaml:"textures"` } diff --git a/server/gamedata/player_appearances.yaml b/server/gamedata/player_appearances.yaml @@ -258,40 +258,40 @@ heads: bodies: - breed: 1 sex: 2 - mesh: 5907 + meshes: [17534, 5907, 17532] textures: 1: [8714, 8710, 8773, 8713, 8709] 2: [8714, 8710, 8770, 8713, 8709] 3: [8714, 8710, 8771, 8713, 8709] - breed: 1 sex: 3 - mesh: 5927 + meshes: [17530, 5927, 17528] textures: 1: [8849, 8850, 8865, 8853, 8848] 2: [8849, 8850, 8863, 8853, 8848] 3: [8849, 8850, 8864, 8853, 8848] - breed: 2 sex: 2 - mesh: 5914 + meshes: [23378, 5914, 23377] textures: 1: [8964, 8960, 8963, 8965, 8961] - breed: 2 sex: 3 - mesh: 5934 + meshes: [23374, 5934, 23373] textures: 1: [8885, 8886, 8887, 8884, 8883] - breed: 3 sex: 2 - mesh: 5921 + meshes: [17909, 5921, 17905] textures: 1: [8986, 8983, 8984, 8985, 8982] - breed: 3 sex: 3 - mesh: 5941 + meshes: [23370, 5941, 23368] textures: 1: [9028, 9024, 9023, 9027, 9026] - breed: 4 sex: 1 - mesh: 5900 + meshes: [23366, 5900, 23365] textures: 1: [9233, 9231, 9240, 9234, 9236] diff --git a/server/inventory.go b/server/inventory.go @@ -117,7 +117,23 @@ func (server *server) saveInventory_locked(character *character, inventory playe if err := server.writeItemStore_locked(store); err != nil { return err } + previous := *character character.inventory = inventory + if character.body.mesh != 0 { + // Existing bodies follow only the committed wear transitions. + previous.collisionBody() + character.body = previous.body + for _, item := range previous.inventory.Items { + if !slices.ContainsFunc(inventory.Items, func(other ownedItem) bool { return other.ID == item.ID && other.Slot == item.Slot }) { + character.wearCollisionBody(item, true) + } + } + for _, item := range inventory.Items { + if !slices.ContainsFunc(previous.inventory.Items, func(other ownedItem) bool { return other.ID == item.ID && other.Slot == item.Slot }) { + character.wearCollisionBody(item, false) + } + } + } if character.maximumHealth() < healthMaximum { character.health = min(character.health, character.maximumHealth()) } diff --git a/server/player_collision.go b/server/player_collision.go @@ -9,44 +9,128 @@ type playerCollisionBody struct { mesh uint32 scale float32 sphere collisionSphere + form uint32 + base int32 + bonus int32 } func (player *character) collisionBody() collisionSphere { - // Ordinary setup constructs the normal breed/sex CIR before render fatness changes. - appearance := player.resolvedAppearance() - var mesh uint32 - for _, body := range gamedata.PlayerAppearances.Bodies { - if body.Breed == appearance.Breed && body.Sex == appearance.Sex { - mesh = body.Mesh - break + if player.body.mesh == 0 { + // Setup constructs the normal CIR before render-only fatness changes. + player.body.base, player.body.scale = int32(player.baseScale()), 1 + mesh := player.humanCollisionMesh(1) + if template := gamedata.MonsterTemplates[player.monsterData]; template != nil { + mesh = template.Stats[12] } + player.replaceCollisionMesh(mesh) + player.scaleCollisionBody(1) + + // FullCharacter applies implants first, then ordinary equipment in slot order. + // Source: client/game/kkr.dll/lifted-0029.c, sub_3605F220/sub_3605F150. + for _, slots := range [][2]uint32{{32, 48}, {0, 32}} { + for slot := slots[0]; slot < slots[1]; slot++ { + for _, item := range player.inventory.Items { + if item.Slot == slot && slot != 6 && slot != 8 { + player.wearCollisionBody(item, false) + } + } + } + } + // FullCharacter restores the live base stat list after the worn effects. + player.scaleCollisionBody(1) } - if template := gamedata.MonsterTemplates[player.monsterData]; template != nil { - mesh = template.Stats[12] - } + + // Base edits and numeric modifiers refresh extent without rebuilding the CAT. base := int32(player.baseScale()) if player.driving() { base = 20 } - effective := base + player.inventory.equipmentBonus(360) + player.nanoBonus(360) - if player.body.mesh != 0 && player.body.mesh != mesh { - effective = max(int32(20), effective) - } else { - effective = max(int32(1), effective) + bonus := player.inventory.equipmentBonus(360) + player.nanoBonus(360) + if player.body.base != base || player.body.bonus != bonus { + player.body.base, player.body.bonus = base, bonus + player.scaleCollisionBody(1) + } + return player.body.sphere +} + +func (player *character) humanCollisionMesh(fatness uint16) uint32 { + appearance := player.resolvedAppearance() + for _, body := range gamedata.PlayerAppearances.Bodies { + if body.Breed == appearance.Breed && body.Sex == appearance.Sex { + return body.Meshes[fatness] + } } - scale := float32(effective) * float32(.01) - if player.body.mesh != mesh { - player.body = playerCollisionBody{mesh: mesh, scale: scale, sphere: player.geometry.model(mesh)} - player.body.sphere.radius *= scale - player.body.sphere.offset[1] *= scale - } else if player.body.scale != scale { - // Scale-only updates multiply the existing primitive instead of decoding it again. + panic("missing player collision body") +} + +func (player *character) replaceCollisionMesh(mesh uint32) { + player.body.mesh, player.body.sphere = mesh, player.geometry.model(mesh) + player.body.sphere.radius *= player.body.scale + player.body.sphere.offset[1] *= player.body.scale +} + +func (player *character) scaleCollisionBody(minimum int32) { + scale := float32(max(minimum, player.body.base+player.body.bonus)) * float32(.01) + if player.body.scale != scale { + // SetBodyScale multiplies the existing primitive instead of decoding it again. ratio := scale / player.body.scale player.body.sphere.radius *= ratio player.body.sphere.offset[1] *= ratio player.body.scale = scale } - return player.body.sphere +} + +func (player *character) wearCollisionBody(item ownedItem, remove bool) { + if !item.fitsEquipmentSlot(item.Slot) { + return + } + low, high := item.templateIDs() + first, second := gamedata.ItemTemplates[low], gamedata.ItemTemplates[high] + for sectionIndex, section := range first.Sections { + if section.Type != 2 || section.Subtype != 14 { + continue + } + // Shape and scale effects run in authored order on both wear and removal. + for index, function := range *section.Functions { + switch function.ID { + case 53012, 53045: + if *function.Arguments[0].Integer == 360 { + value := interpolateItemValue(*function.Arguments[1].Integer, *(*second.Sections[sectionIndex].Functions)[index].Arguments[1].Integer, *first.Quality, *second.Quality, item.Quality) + if remove { + value = -value + } + player.body.bonus += value + player.scaleCollisionBody(1) + } + case 53060: + form := uint32(*function.Arguments[0].Integer) + if remove && player.body.form == form { + player.body.form = 0 + fatness := player.resolvedAppearance().Fatness + if fatness > 2 { + fatness = 1 + } + player.replaceCollisionMesh(player.humanCollisionMesh(fatness)) + player.scaleCollisionBody(1) + } else if !remove && player.body.form == 0 { + player.body.form = form + mesh := gamedata.MonsterTemplates[form].Stats[12] + if player.body.mesh != mesh { + player.replaceCollisionMesh(mesh) + } + player.scaleCollisionBody(20) + } + case 53110: + if *function.Arguments[0].Integer == 360 { + player.body.base = max(int32(20), int32(*function.Arguments[1].Integer)) + if remove { + player.body.base = int32(player.baseScale()) + } + player.scaleCollisionBody(1) + } + } + } + } } func collisionDirection(vector [3]float32) [3]float32 { diff --git a/server/player_form_test.go b/server/player_form_test.go @@ -0,0 +1,309 @@ +package main + +import ( + "bytes" + "encoding/binary" + "fmt" + "math" + "testing" + "time" +) + +func newPlayerFormWorld(t *testing.T, template uint32) *server { + t.Helper() + world := newPlayerCollisionWorld(t) + player := world.characters[1] + player.appearance, player.height = 0x130, 150 + player.rotation = [4]float32{0, 0, 0, 1} + player.stats.Navigation.VehicleGround, player.stats.Navigation.VehicleAir = 100, 100 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + world.clients[1].loading = true + if err := world.handleCharacterReady(world.clients[1]); err != nil { + t.Fatal(err) + } + if granted, err := world.grantItem_locked(player, template); err != nil || !granted { + t.Fatal(granted, err) + } + return world +} + +func TestPlayerFormUsesAuthoredVehicleModelsAfterTheEquipDeadline(t *testing.T) { + for _, scenario := range []struct { + template, mesh uint32 + radius, offsetY float32 + }{ + {117294, 99458, .47679999470710754, .20959998667240143}, + {117322, 42370, .09999999403953552, -.010001200251281261}, + } { + t.Run(fmt.Sprint(scenario.template), func(t *testing.T) { + world := newPlayerFormWorld(t, scenario.template) + player, client := world.characters[1], world.clients[1] + before := player.body + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil || client.equipment == nil { + t.Fatal("vehicle wear was not scheduled", err) + } + finish := client.equipment.readyAt + + world.advanceEquipment(finish.Add(-time.Nanosecond)) + pending := player.body + world.advanceEquipment(finish) + + if pending != before || before.mesh != 5921 || before.sphere.radius != .3761250078678131 { + t.Fatal("pending wear changed the initial normal collision body", before, pending) + } + if player.body.mesh != scenario.mesh || player.body.scale != .19999998807907104 || math.Abs(float64(player.body.sphere.radius-scenario.radius)) > .0000001 || math.Abs(float64(player.body.sphere.offset[1]-scenario.offsetY)) > .0000001 { + t.Fatal("accepted wear did not apply the authored CAT and scale while idle", player.body) + } + if player.height != 150 || player.position[1] != 16.41 { + t.Fatal("body replacement must retain the saved height without snapping position", player.height, player.position) + } + }) + } +} + +func TestPlayerFormGroundProjectionUsesTheVehicleAndRestoredHumanSpheres(t *testing.T) { + world := newPlayerFormWorld(t, 117294) + player, client := world.characters[1], world.clients[1] + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + + if err := world.handleMovement(client, playerMovementRequest(player, 9)); err != nil { + t.Fatal(err) + } + world.advancePlayerMovement(player.movement.updatedAt.Add(100 * time.Millisecond)) + vehicleY := player.position[1] + if err := world.handleInventory(client, itemMovePacket(1, 1, 111)[20:]); err != nil || client.equipment == nil { + t.Fatal("vehicle removal was rejected", err) + } + world.advanceEquipment(client.equipment.readyAt) + world.advancePlayerMovement(player.movement.updatedAt.Add(100 * time.Millisecond)) + world.advancePlayerMovement(player.movement.updatedAt.Add(100 * time.Millisecond)) + + if math.Abs(float64(vehicleY)-16.677200317382812) > .000003 || math.Abs(float64(player.position[1])-16.78612518310547) > .000003 { + t.Fatal("body-bottom projection disagrees with paired native form lifecycle", vehicleY, player.position) + } + if player.body.mesh != 17909 || player.body.sphere.offset != [3]float32{} || player.inventory.Items[0].Slot != 64 || player.height != 150 { + t.Fatal("removal lost the owned vehicle, saved scale or thin human body", player.body, player.inventory) + } +} + +func TestPlayerFormRestoresEveryHumanBreedSexAndFatness(t *testing.T) { + for _, scenario := range []struct { + breed, sex uint16 + meshes [3]uint32 + }{ + {1, 2, [3]uint32{17534, 5907, 17532}}, {1, 3, [3]uint32{17530, 5927, 17528}}, + {2, 2, [3]uint32{23378, 5914, 23377}}, {2, 3, [3]uint32{23374, 5934, 23373}}, + {3, 2, [3]uint32{17909, 5921, 17905}}, {3, 3, [3]uint32{23370, 5941, 23368}}, + {4, 1, [3]uint32{23366, 5900, 23365}}, + } { + for fatness, mesh := range scenario.meshes { + t.Run(fmt.Sprintf("%d/%d/%d", scenario.breed, scenario.sex, fatness), func(t *testing.T) { + world := newPlayerFormWorld(t, 117294) + player, client := world.characters[1], world.clients[1] + player.appearance = (appearanceFields{Breed: scenario.breed, Sex: scenario.sex, Fatness: uint16(fatness)}).packed() + client.loading = true + if err := world.handleCharacterReady(client); err != nil { + t.Fatal(err) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + + if err := world.handleInventory(client, itemMovePacket(1, 1, 111)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + restored := player.body + if err := world.handleMovement(client, playerMovementRequest(player, 9)); err != nil { + t.Fatal(err) + } + world.advancePlayerMovement(player.movement.updatedAt.Add(100 * time.Millisecond)) + + if restored.mesh != mesh || player.body != restored || math.Abs(float64(restored.sphere.radius)-.3761250078678131) > .0000001 { + t.Fatal("form0 must force the current human CAT and retain it across ticks", mesh, restored, player.body) + } + if mesh == 17909 && restored.sphere.offset != [3]float32{} || mesh != 17909 && math.Abs(float64(restored.sphere.offset[1])-.3761250078678131) > .0000001 { + t.Fatal("restoration discarded the selected human torso metadata", restored) + } + }) + } + } +} + +func TestPlayerFormFailedSaveCannotChangeTheCollisionBody(t *testing.T) { + for _, removal := range []bool{false, true} { + t.Run(fmt.Sprint(removal), func(t *testing.T) { + world := newPlayerFormWorld(t, 117294) + player, client := world.characters[1], world.clients[1] + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + if removal { + world.advanceEquipment(client.equipment.readyAt) + if err := world.handleInventory(client, itemMovePacket(1, 1, 111)[20:]); err != nil { + t.Fatal(err) + } + } + before, item := player.body, player.inventory.Items[0] + finish := client.equipment.readyAt + failDatabaseWrites(t, world) + + world.advanceEquipment(finish) + + if player.body != before || player.inventory.Items[0] != item { + t.Fatal("failed durable move changed collision or owned placement", before, player.body, item, player.inventory) + } + }) + } +} + +func TestPlayerFormRechecksEligibilityBeforeChangingItsBody(t *testing.T) { + for _, scenario := range []string{"skill", "combat", "loading", "dead", "stale session"} { + t.Run(scenario, func(t *testing.T) { + world := newPlayerFormWorld(t, 117294) + player, client := world.characters[1], world.clients[1] + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + finish := client.equipment.readyAt + before := player.body + switch scenario { + case "skill": + player.stats.Navigation.VehicleGround = 0 + case "combat": + player.fighting = 1000000 + world.fighting[1] = player + case "loading": + client.loading = true + case "dead": + player.health = 0 + case "stale session": + world.clients[1] = &worldClient{id: 1, ready: true} + } + + world.advanceEquipment(finish) + + if player.body != before || player.inventory.Items[0].Slot != 64 { + t.Fatal("rejected completion changed body or owned vehicle", before, player.body, player.inventory) + } + }) + } +} + +func TestPlayerFormScaleCompanionRefreshesWithoutReplacingTheVehicle(t *testing.T) { + world := newPlayerFormWorld(t, 117322) + player, client := world.characters[1], world.clients[1] + if granted, err := world.grantItem_locked(player, 156831); err != nil || !granted { + t.Fatal(granted, err) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + + if err := world.handleInventory(client, inventoryMovePacket(1, 65, 19)[20:]); err != nil || client.equipment == nil { + t.Fatal("scale companion wear rejected", err) + } + world.advanceEquipment(client.equipment.readyAt) + modified := player.body + if err := world.handleInventory(client, itemMovePacket(1, 19, 111)[20:]); err != nil || client.equipment == nil { + t.Fatal("scale companion removal rejected", err) + } + world.advanceEquipment(client.equipment.readyAt) + + if modified.mesh != 42370 || modified.scale != .17000000178813934 || player.body.mesh != 42370 || player.body.scale != .19999998807907104 || player.height != 150 || player.inventory.Items[0].Slot != 1 { + t.Fatal("extent refresh must retain the current form and saved base scale", modified, player.body, player.inventory) + } +} + +func TestPlayerFormScaleEffectsPreserveAuthoredOrderAndColdRefresh(t *testing.T) { + for _, scenario := range []struct { + template uint32 + scale float32 + }{{117294, .17000000178813934}, {117322, .19999998807907104}} { + t.Run(fmt.Sprint(scenario.template), func(t *testing.T) { + world := newPlayerFormWorld(t, scenario.template) + player, client := world.characters[1], world.clients[1] + if granted, err := world.grantItem_locked(player, 156831); err != nil || !granted { + t.Fatal(granted, err) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 65, 19)[20:]); err != nil || client.equipment == nil { + t.Fatal("Modified Pioneer wear rejected", err) + } + world.advanceEquipment(client.equipment.readyAt) + + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + manual := player.body.scale + client.loading = true + if err := world.handleCharacterReady(client); err != nil { + t.Fatal(err) + } + + if manual != scenario.scale || player.body.scale != .17000000178813934 || player.height != 150 { + t.Fatal("form's minimum20 and later extent's minimum1 lost event order", manual, player.body) + } + }) + } +} + +func TestPlayerFormReconnectSeparatesLiveScaleFromSavedScale(t *testing.T) { + for _, template := range []uint32{117294, 117322} { + t.Run(fmt.Sprint(template), func(t *testing.T) { + world := newPlayerFormWorld(t, template) + player, client := world.characters[1], world.clients[1] + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + restored := newTestInventoryServer(t).characters[1] + + packet := targetPacket(fullCharacterPacket(restored)) + cursor := 61 + len(restored.inventory.Items)*32 + count := int(binary.BigEndian.Uint32(packet[cursor:])/1009 - 1) + stats := make(map[uint32]uint32) + for offset := cursor + 4; offset < cursor+4+count*8; offset += 8 { + stats[binary.BigEndian.Uint32(packet[offset:])] = binary.BigEndian.Uint32(packet[offset+4:]) + } + cursor += 4 + count*8 + 3*4 + + if stats[360] != 20 || restored.height != 150 || !bytes.Equal(packet[cursor:cursor+24], []byte{0, 0, 0, 1, 0, 0, 1, 104, 0, 0, 0, 150, 0, 0, 0, 0, 0, 0, 3, 241, 0, 0, 3, 241}) { + t.Fatal("FullCharacter must restore live20 separately from saved150", stats[360], restored.height, packet[cursor:]) + } + if player.inventory.Items[0].ID != restored.inventory.Items[0].ID || restored.inventory.Items[0].Slot != 1 { + t.Fatal("cold restoration changed the vehicle identity or HUD1 placement") + } + }) + } +} + +func TestPlayerFormReconnectReconstructsTheNormalHumanBody(t *testing.T) { + world := newPlayerFormWorld(t, 117294) + player, client := world.characters[1], world.clients[1] + if err := world.handleInventory(client, inventoryMovePacket(1, 64, 1)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + if err := world.handleInventory(client, itemMovePacket(1, 1, 111)[20:]); err != nil { + t.Fatal(err) + } + world.advanceEquipment(client.equipment.readyAt) + before := player.body + client.loading = true + + if err := world.handleCharacterReady(client); err != nil { + t.Fatal(err) + } + + if before.mesh != 17909 || before.sphere.offset != [3]float32{} || player.body.mesh != 5921 || player.body.sphere.offset[1] != .3761250078678131 || player.body.sphere.radius != .3761250078678131 { + t.Fatal("fresh native owner construction must rebuild the normal login body", before, player.body) + } +} diff --git a/server/target_protocol.go b/server/target_protocol.go @@ -102,9 +102,10 @@ func targetPacket(packet []byte) []byte { tail := append([]byte(nil), packet[inventoryEnd:]...) packet = binary.BigEndian.AppendUint32(packet[:inventoryEnd], 1009) packet = append(packet, tail...) - // kkr.dll FullChar 0x1007f5b0: empty stat map, lists and auxiliary identity. - packet = packet[:len(packet)-20] - for _, value := range []uint32{0, 0, 1009, 1009} { + // Preserve the plain-counted saved-stat map before the remaining groups. + // kkr.dll sub_3607F5B0: presence DWORD, encoded list and encoded effect list. + packet = packet[:len(packet)-16] + for _, value := range []uint32{0, 1009, 1009} { packet = binary.BigEndian.AppendUint32(packet, value) } case 0x47537a24: diff --git a/server/world.go b/server/world.go @@ -218,6 +218,10 @@ func fullCharacterPacket(character *character) []byte { body = binary.BigEndian.AppendUint32(body, lock[1]) } lowerXP, upperXP := character.experienceBounds() + scale := character.baseScale() + if character.driving() { + scale = 20 + } stats := [][2]uint32{{54, uint32(character.level)}, {52, lowerXP + character.experience}, {57, lowerXP}, {350, upperXP}, {236, max(lowerXP, character.insuredExperience)}} stats = append(stats, character.baseStats().nativeStats()...) for index, flags := range character.inventory.MapFlags { @@ -233,7 +237,7 @@ func fullCharacterPacket(character *character) []byte { [2]uint32{37, character.titleLevel()}, [2]uint32{368, uint32(max(1, character.profession))}, [2]uint32{51, uint32(character.aggDef)}, [2]uint32{61, character.inventory.Credits}, [2]uint32{47, uint32(character.appearance >> 2 & 3)}, - [2]uint32{360, uint32(character.baseScale())}, + [2]uint32{360, uint32(scale)}, [2]uint32{214, character.nano}, [2]uint32{221, character.maximumNano() - uint32(character.inventory.equipmentBonus(221))}) if time.Now().Before(character.implantChangesUntil) { // Surgery access supplements the native base Features value of 6. @@ -248,8 +252,16 @@ func fullCharacterPacket(character *character) []byte { body = binary.BigEndian.AppendUint32(body, 1009) } - // Empty stat map, remaining lists, and auxiliary identity. - for _, value := range []uint32{0, 1009, 0, 0, 1009} { + // ChangeStat restores the saved base on removal, including after a reconnect. + // The native saved-stat map is installed before initial OnWear execution. + if character.driving() { + for _, value := range []uint32{1, 360, uint32(character.baseScale())} { + body = binary.BigEndian.AppendUint32(body, value) + } + } else { + body = binary.BigEndian.AppendUint32(body, 0) + } + for _, value := range []uint32{1009, 0, 0, 1009} { body = binary.BigEndian.AppendUint32(body, value) } return n3Packet(0x29304349, 50000, character.id, body) diff --git a/server/world_actions.go b/server/world_actions.go @@ -43,6 +43,7 @@ func (server *server) handleCharacterReady(client *worldClient) error { resources := make(map[*worldClient][][]byte) if client.loading { player := server.characters[client.id] + player.body = playerCollisionBody{} player.movement.prepare(player, time.Now()) player.alignSurface([3]float32{}, true) motion = server.playerMovementReplay_locked(client, time.Now()) diff --git a/tools/data/extract_player_appearances.py b/tools/data/extract_player_appearances.py @@ -163,7 +163,7 @@ for head in heads: lines.append('bodies:') for body in bodies: lines.extend([f" - breed: {body['breed']}", f" sex: {body['creation_sex']}", - f" mesh: {body['body_meshes'][1]['mesh']}", + ' meshes: ' + json.dumps([mesh['mesh'] for mesh in body['body_meshes']]), ' textures:']) for race, materials in body['resolved_default_materials'].items(): lines.append(f' {race}: ' + json.dumps([materials[name]['texture'] for name in ['arms', 'feet', 'hands', 'legs', 'body']]))