aorecomp

Anarchy Online classic in the browser

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


commit 267ba0ac3c9972b7a8f6c54e9265492c408128e5
parent cfad4e81cf774fe0832f3e7837b8d3ffb2278d62
Author: anon <anon@example.com>
Date:   Thu, 22 Oct 2026 17:22:58 +0000

Use actor extents for melee range validation

Diffstat:
MTODO.md | 5++++-
Mdocs/combat-client-reconstruction.md | 2+-
Mdocs/combat-client-state-machine.md | 54++++++++++++++++++++++++++++++++++++++++++++++++------
Mdocs/combat-npc-balance.md | 6++++--
Mdocs/combat-rules.md | 19+++++++++++--------
Mserver/combat.go | 19++++++++++++++++++-
Aserver/combat_range_test.go | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/combat_test.go | 4++--
8 files changed, 138 insertions(+), 21 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -101,7 +101,7 @@ capacity checks are recorded in [belts and NCU](docs/belts-ncu.md). match documented expected amounts at representative boundaries. - [ ] Select Martial Arts fist QL from skill. Check: known MA values select the evidenced template/QL and change damage without equipping a weapon. -- [ ] Replace the approximate melee range check. Check: two actors at known +- [x] Replace the approximate melee range check. Check: two actors at known positions and sizes are accepted or rejected at the recovered range boundary. - [ ] Reject attacks through one solid obstruction. Check: the same stationary encounter works in the open and fails with a wall between the actors. @@ -114,6 +114,9 @@ fractional endpoint rounding remains provisional. See [attack-rating damage](docs/combat-attack-rating.md) for sources and checks. The unresolved fist curve, native weapon-list fields and original refresh stub are recorded in [fist selection research](docs/combat-fist-selection.md). +Melee uses the recovered client range predicate and actual actor extents; +its boundary checks and original-server evidence limits are recorded in +[combat client range](docs/combat-client-state-machine.md#range-line-of-sight-and-movement). ## Additional weapon actions diff --git a/docs/combat-client-reconstruction.md b/docs/combat-client-reconstruction.md @@ -83,7 +83,7 @@ unknowns for each area: | Metaplast chest armor (QL 1/200) and boots (QL 1) | Shipped wear effects and native packets, owner/observer WASM checks | Persistent equip/unequip, appearance and AC modifiers; [armor notes](armor.md) | | Armor damage reduction and damage-type selection | Period AC/10 observations and shipped damage types | Normal hits respect the weapon minimum; fractional integer ordering is provisional; [armor notes](armor.md) | | 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 | +| Range and physical extents | Native predicate and extent construction recovered; WASM player/Leet extents verified | Catalog radius at scale 100; 9m player-to-Leet and 10m reverse boundary checks; original server tolerance unknown | | 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 | | Resource regeneration | Native prediction formulas and injured-client probes | Authoritative player recovery; absolute quiet corrections reconcile prediction | diff --git a/docs/combat-client-state-machine.md b/docs/combat-client-state-machine.md @@ -62,8 +62,9 @@ For a runtime read with an already known engine instance, its `+0x88` points to the local `SimpleChar`; `*(character + 0x188) + 0x30` is the physical extent used by the range routine. The current target identity is at `*(character + 0x16c) + 0x58/+0x5c`. Use the dynel registry to resolve -that identity, then the same physical-helper chain for the target. Runtime -values were not read during this static investigation. +that identity, then the same physical-helper chain for the target. A later +WASM check read player extent 2 and Leet extent 3 through these pointers; +see the range verification below. Relevant holder fields, initialized by `0x100783e0`: @@ -267,15 +268,56 @@ sum of two radii. Item targets instead use `d < r`. `0x100aae10` supplies `r = min(40, trunc(itemRange * (1 + WeaponRangeIncreaser380/100)))`. Physical extent starts at 1.0 in -`0x10059770`, then `0x1005a790` replaces it with -`max(1, MonsterScale360(mode3)) * CharRadius421(mode2) * .01`. It also -applies `MonsterScale*.01` to body scale. A default constructor value is -not evidence that every spawned Leet retains radius 1.0. In fact the stat +`0x10059770`, then `0x1005a790` replaces it with the float32 conversion of +the signed integer product `max(1, MonsterScale360(mode3)) * CharRadius421(mode2)`, +multiplied by float32 `.01`. It also applies `MonsterScale*.01` to body scale. +A default constructor value is not evidence that every spawned Leet retains +radius 1.0. In fact the stat initializer `0x10072760` sets CharRadius421 to 2 and MonsterScale360 to 100, giving extent 2.0 after this refresh when neither stat is replaced. Even those stat defaults must not be substituted for actual NPC values or treated as proof of an original-server melee hit threshold. +The extracted Leet template 17655 supplies CharRadius421=3 in +`server/gamedata/monsters.yaml`. Published actors currently use scale 100; +the server therefore derives player extent 2 and Leet extent 3. It uses the +predicate above for authoritative melee validation, replacing the fixed +four-meter approximation. Fists, Kinetic Axe 209283 and Leet Bite 120910 have +item range 2. With no range modifiers, player-to-Leet range is consequently +9 meters and Leet-to-player range is 10 meters. Direction matters because +the attacker's extent is counted twice. Movement prediction still supplies +player positions before the three-dimensional distance check. Scale-changing +effects and weapon range modifiers are not currently supported. + +This is an explicit reconstruction choice based on the client contract, not +a recovered original-server normal-attack tolerance. The source distinction +below still applies. + +Extent follow-up evidence is retained in +`local/reports/actor-range-extents-1491-evidence.json`: refreshed extent +`ev_4871dfa06ad951f22eec434d4895dfba2c4127bec7a148226a75f1460e9e04e3`, +float constant +`ev_09c60b565e012a81f81e9d3c94ec67d0c24254ef6f3b10e62c82b7bed44dbf50`, +defaults `ev_262150600e8d5205a324934ce17968bf1440814efc918e5344b3ad29103466e9`, +and stat-triggered refresh +`ev_a2f43ae98c55ad9d0b1c3b494017da7794f4d5b185e6be899d0665f31d4fbb11`. + +Automated public combat-handler checks accept a Leet at `(9,0,0)` and +`(6,3,6)` relative to the player and reject `(9.125,0,0)` and `(6,3.125,6)`. +Retaliation separately accepts 10 meters and rejects 10.125 meters. Existing +movement tests continue to check predicted positions. + +An actual published WASM client also targeted the Leet and pressed Q with +the player at `(918,20.7,578)`. At `(927.125,20.7,578)` the request was rejected +and Leet HP remained 8971. At `(927,20.7,578)` combat started and Leet HP fell +to 8903 during the six-second observation. Read-only guest-memory probes +confirmed extents 2 and 3; they did not change guest state. The fixture used +a 10000-HP Leet to keep the encounter available, without changing its radius +or weapon. State, packet logs and screenshots are retained under +`local/first-aid-smoke/range-*`; the extent probes are in +`self-heal-verified-trace.json` in that directory. No browser errors or native +adapter aborts were reported. Test-owned processes were closed afterward. + The predicate has two established uses: special-attack validation `0x10078990` and selected-target range UI via `0x10078c70` -> `0x1007acf0` -> events `0x1001c910/0x1001c930`. It also supports range diff --git a/docs/combat-npc-balance.md b/docs/combat-npc-balance.md @@ -74,8 +74,10 @@ and AggDef outside -100..100. | Corpse lifetime from death | 180 seconds | Provisional; independent of respawn, contents and whether the corpse is open | The first bite lands after the attack phase; subsequent bites are 3.5 seconds -apart before world-tick quantization. Range still uses the existing four-metre -approximation rather than the weapon's two-metre range with physical extents. +apart before world-tick quantization. Range uses the weapon's two-meter range +and recovered physical extents: Leet-to-player acceptance reaches 10 meters. +The [range checks](combat-client-state-machine.md#range-line-of-sight-and-movement) +distinguish this client-derived reconstruction from original server tolerance. Health, hit distribution, effective ratings, armor and original spawn binding remain gaps in canonical balance; the profile does not make those values historically verified. diff --git a/docs/combat-rules.md b/docs/combat-rules.md @@ -46,11 +46,12 @@ rules from provisional integer ordering. Level-1 Leets use an explicit catalog-weapon profile; other NPCs retain 100 health, 5 damage and 1s/1s timing. Profile settings and their verified/provisional status are recorded in [NPC balance](combat-npc-balance.md). The uniform normal-damage roll is a reconstruction choice; the item establishes -the endpoints, not the historical server's random distribution. The four-meter -range approximates physical extents, and there is no server line-of-sight -test. Other equipment, nanos, specials, aggression/taunt AI and XP awards -are not implemented. Player resurrection and private reclaim have separate -documented lifecycle implementations. Fixed corpse loot and the provisional +the endpoints, not the historical server's random distribution. Melee range +uses the recovered client predicate with catalog actor extents; see +[range evidence and checks](combat-client-state-machine.md#range-line-of-sight-and-movement). +There is no server line-of-sight test. Other equipment, nanos, specials, +aggression/taunt AI and XP awards are not implemented. Player resurrection and +private reclaim have separate documented lifecycle implementations. Fixed corpse loot and the provisional level-1 Leet [respawn lifecycle](npc-respawn.md) are supported. Reload revival is a local test convenience. These limitations prevent a claim of canonical combat balance. @@ -172,13 +173,15 @@ at `*(character + 0x188) + 0x30`, measures 3D center distance, and compares against effective item range plus those extents. Its outer check actually adds the actor extent twice and target extent once; confirmed in assembly `ev_9862c91fdfb306342e1a4bada390db357a4002667850e7704ed97713cc8510be`. -The physical meaning and construction of these extents remain unresolved. +The refreshed extents are 2 for the default player and 3 for Leet template +17655 at scale 100. Construction, WASM probes and server boundary tests are +recorded in the [range follow-up](combat-client-state-machine.md#range-line-of-sight-and-movement). `FUN_100aae10` computes effective item range as the truncated value of `range * (1 + WeaponRangeIncreaser380 / 100)`, capped at 40. Its assembly is `ev_caffa5ac96df90e71084d5f068e035270b37d97a28beb95abb889dd010d2527d`. -A fixed four-meter center limit is an approximation; simply replacing it -with two meters would not match the shipped client's range calculation. +The server uses these extents with the recovered client predicate; this does +not establish the unavailable original server's normal-attack tolerance. ## Damage and unresolved server rules diff --git a/server/combat.go b/server/combat.go @@ -176,6 +176,17 @@ func (attacker *character) normalDamage(target *character, roll func(uint32) uin return damage - min(damage-minimum, target.inventory.equipmentBonus(damageType)/10) } +func (character *character) physicalExtent() float32 { + // FUN_1005a790 scales CharRadius421. Published actors currently use Scale360=100. + radius := uint32(2) + if monster, exists := gamedata.MonsterTemplates[character.monsterData]; exists { + if value, exists := monster.Stats[421]; exists { + radius = value + } + } + return float32(int32(100*radius)) * float32(0.01) +} + func (server *server) combatInRange_locked(attacker, target *character, now time.Time) bool { first, second := attacker.position, target.position if !attacker.npc { @@ -185,7 +196,13 @@ func (server *server) combatInRange_locked(attacker, target *character, now time second = predictedPosition_locked(target, server.clients[target.id], now) } x, y, z := first[0]-second[0], first[1]-second[1], first[2]-second[2] - return x*x+y*y+z*z <= 4*4 + itemRange := uint32(2) + if weapon := attacker.meleeWeapon(); weapon != nil { + itemRange = itemStat(weapon, 287) + } + // FUN_10078cb0 adds the attacker's extent twice and the target's once. + distance := float32(min(40, itemRange)) + 2*attacker.physicalExtent() + target.physicalExtent() + return x*x+y*y+z*z <= distance*distance } func (server *server) startAttack_locked(attacker, target *character, now time.Time, updates map[*worldClient][][]byte) { diff --git a/server/combat_range_test.go b/server/combat_range_test.go @@ -0,0 +1,50 @@ +package main + +import "testing" + +func TestCombatMeleeUsesActorExtentsAtThreeDimensionalBoundary(t *testing.T) { + for _, scenario := range []struct { + name string + position [3]float32 + accepted bool + }{ + {"axis boundary", [3]float32{9, 0, 0}, true}, + {"outside axis", [3]float32{9.125, 0, 0}, false}, + {"diagonal boundary", [3]float32{6, 3, 6}, true}, + {"outside diagonal", [3]float32{6, 3.125, 6}, false}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, _ := newCombatWorld() + npc := world.characters[1000000] + npc.monsterData, npc.position = 17655, scenario.position + + err := world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:]) + if world.characters[1].fighting != 0 { + world.advanceCombat(world.characters[1].nextAttack) + } + + if err != nil || (npc.health < 100) != scenario.accepted || (world.characters[1].fighting != 0) != scenario.accepted { + t.Fatalf("extent-based 9m range: accepted=%v hp=%d err=%v", scenario.accepted, npc.health, err) + } + }) + } +} + +func TestCombatLeetRangeIncludesItsOwnExtentTwice(t *testing.T) { + for _, distance := range []float32{10, 10.125} { + world, _ := newCombatWorld() + player, npc := world.characters[1], world.characters[1000000] + npc.monsterData = 17655 + world.handleCombat(world.clients[1], attackPacket(1, 1000000)[20:]) + world.advanceCombat(player.nextAttack) + world.handleCombat(world.clients[1], stopFightPacket(1)[20:]) + player.position[0] = npc.position[0] + distance + before := player.health + + world.advanceCombat(npc.nextAttack) + + if (player.health < before) != (distance == 10) || (npc.fighting != 0) != (distance == 10) { + t.Fatalf("Leet 10m range: distance=%v health=%d target=%d", distance, player.health, npc.fighting) + } + } +} diff --git a/server/combat_test.go b/server/combat_test.go @@ -95,7 +95,7 @@ func TestCombatRejectsInvalidTargetsAndSessions(t *testing.T) { case "hidden": delete(client.npcs, 1000000) case "far": - npc.position[0] = 5 + npc.position[0] = 9 case "loading": client.loading = true case "replaced": @@ -134,7 +134,7 @@ func TestCombatRangeUsesPredictedPlayerPosition(t *testing.T) { first := world.characters[1].nextAttack world.characters[1].rotation = [4]float32{0, 0, 0, 1} world.clients[1].forward = 1 - world.clients[1].movementStarted = first.Add(-4 * time.Second) + world.clients[1].movementStarted = first.Add(-8 * time.Second) world.advanceCombat(first)