aorecomp

Anarchy Online classic in the browser

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


commit ea21d70080f82c7f15a4d6117a933be2df476bcf
parent e7dc5cf1f61ee9841bf6febfd45a6daa2ee452ac
Author: anon <anon@example.com>
Date:   Fri, 23 Oct 2026 21:33:42 +0000

test(client): cover original critical-result routing and impact

Diffstat:
MTODO.md | 3+++
Mclient/Makefile.linux | 7+++++++
Aclient/tests/critical_result.c | 293+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adocs/critical-hits.md | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 390 insertions(+), 0 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -135,6 +135,9 @@ capacity checks are recorded in [belts and NCU](docs/belts-ncu.md). - [ ] Resolve a critical hit. Check: a known weapon and controlled roll produce the expected critical damage and client feedback. Include CriticalIncrease stat 379; Sniper's Friend modifies weapon range stat 380 instead. + The unchanged original activation/queue/impact path now has Linux and WASM + contract coverage. Probability, critical AC/OE arithmetic and the server + selection remain open. See [critical-result findings](docs/critical-hits.md). - [x] Apply damage-type equipment modifiers to normal hits in the recovered order. Check: Robust Backpack's projectile, energy, radiation and fire bonuses affect the matching attacks, leave other types unchanged, and interact correctly with diff --git a/client/Makefile.linux b/client/Makefile.linux @@ -173,6 +173,7 @@ test: build/linux/window build/linux/graphics build/linux/atoi build/linux/stric ./build/linux/weapon-range ./build/linux/ip-training ./build/linux/fling-result + ./build/linux/critical-result ./build/linux/guest-crt ./build/linux/getenv ./build/linux/linux-platform @@ -667,3 +668,9 @@ build/linux/fling-result: tests/fling_result.c game/kkr.dll/lifted-0053.c runtim $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@ test: build/linux/fling-result + +build/linux/critical-result: tests/critical_result.c game/kkr.dll/lifted-0034.c game/kkr.dll/lifted-0035.c game/kkr.dll/lifted-0050.c game/kkr.dll/lifted-0051.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h + @mkdir -p $(@D) + $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@ + +test: build/linux/critical-result diff --git a/client/tests/critical_result.c b/client/tests/critical_result.c @@ -0,0 +1,293 @@ +#include "recomp_types.h" +#include <assert.h> + +void sub_360AECB0(void); +void sub_3607A320(void); +void sub_3607A660(void); +void sub_360AB4C0(void); +void sub_360AB500(void); +void sub_360AB560(void); +void sub_360AB580(void); +void sub_360AB5A0(void); +void sub_36075DB0(void); +void sub_3607BE50(void); + +static unsigned reads, writes, feedbacks, generic_feedbacks, deaths, ammo_updates; +static unsigned missing_attacker, missing_target, target_local; +static uint32_t expected_result, death_reason; +static int32_t ammunition; + +static void actor_lookup(void) +{ + uint32_t identity = MEM32(g_esp + 4); + assert(MEM32(identity) == 50000); + switch (MEM32(identity + 4)) { + case 1: g_eax = missing_attacker ? 0 : 0x50001000; break; + case 2: g_eax = missing_target ? 0 : 0x50002000; break; + default: abort(); + } + g_esp += 4; +} + +static void current_opponent(void) +{ + assert(g_ecx == 0x50003000); + g_eax = 0x50002000; + g_esp += 4; +} + +static void is_local(void) +{ + assert(g_ecx == 0x50001000 || g_ecx == 0x50002000); + g_eax = g_ecx == 0x50002000 && target_local; + g_esp += 4; +} + +static void actor_cast(void) +{ + assert(MEM32(g_esp + 4) == 0x50002000); + g_eax = MEM32(g_esp + 4); + g_esp += 4; +} + +static void actor_getter(void) +{ + if (MEM32(g_esp + 4) == 339) { + assert(g_ecx == 0x500010e4 && MEM32(g_esp + 8) == 0); + g_eax = 0; + } else { + assert(g_ecx == 0x500020e4); + assert(MEM32(g_esp + 4) == 27 && MEM32(g_esp + 8) == 2); + reads++; + g_eax = MEM32(0x50002300); + } + g_esp += 12; +} + +static void actor_setter(void) +{ + assert(g_ecx == 0x500020e4); + assert(MEM32(g_esp + 4) == 27 && MEM32(g_esp + 8) == 87); + writes++; + MEM32(0x50002300) = MEM32(g_esp + 8); + g_esp += 12; +} + +static void weapon_setter(void) +{ + assert(g_ecx == 0x50006000 && MEM32(g_esp + 4) == 26); + assert((int32_t)MEM32(g_esp + 8) == ammunition); + ammo_updates++; + MEM32(0x50006020) = MEM32(g_esp + 8); + g_esp += 12; +} + +static void damage_type(void) +{ + assert(g_ecx == 0x50005000); + g_eax = 90; + g_esp += 4; +} + +static void target_state(void) +{ + assert(g_ecx == 0x50001000); + g_eax = 0; + g_esp += 4; +} + +static void feedback_interface(void) +{ + g_eax = 0x50000900; + g_esp += 4; +} + +static void feedback(void) +{ + assert(g_ecx == 0x50000900); + assert(MEM32(g_esp + 4) == (target_local ? 30 : 32)); + assert(MEM32(g_esp + 8) == 0x50002000); + assert(MEM32(g_esp + 12) == 13); + assert(MEM32(g_esp + 16) == 0x50001000); + assert(MEM32(g_esp + 20) == 0 && MEM32(g_esp + 24) == 90); + assert(MEM32(g_esp + 28) == expected_result); + feedbacks++; + g_esp += 32; +} + +static void generic_format(void) +{ + assert(MEM32(g_esp + 8) == 0x361b4e14 && MEM32(g_esp + 12) == 13); + strcpy((char *)ADDR(MEM32(g_esp + 4)), "fixture damage text"); + g_esp += 4; +} + +static void generic_feedback(void) +{ + assert(g_ecx == 0x50000900 && MEM32(g_esp + 8) == 23); + assert(strcmp((char *)ADDR(MEM32(g_esp + 4)), "fixture damage text") == 0); + generic_feedbacks++; + g_esp += 12; +} + +static void target_death(void) +{ + assert(g_ecx == 0x50002000 && MEM32(g_esp + 4) == death_reason); + assert(MEM32(0x50002300) == 87 && writes == 1); + deaths++; + g_esp += 8; +} + +recomp_func_t recomp_lookup(uint32_t address) +{ + switch (address) { + case 0x3606da90: return actor_lookup; + case 0x3607a320: return sub_3607A320; + case 0x3607a660: return sub_3607A660; + case 0x360ab4c0: return sub_360AB4C0; + case 0x360ab500: return sub_360AB500; + case 0x360ab560: return sub_360AB560; + case 0x360ab580: return sub_360AB580; + case 0x360ab7b0: return damage_type; + case 0x36075db0: return sub_36075DB0; + case 0x3607be50: return sub_3607BE50; + case 0x36072310: return target_state; + case 0x3601c590: return feedback_interface; + case 0x3601d0b0: return feedback; + case 0x3601c8c0: return generic_feedback; + case 0x36072340: return target_death; + case 0x3615fd86: return actor_cast; + case 0x50000400: return actor_getter; + case 0x50000404: return actor_setter; + case 0x50000408: return weapon_setter; + case 0x5000040c: return current_opponent; + case 0x50000410: return is_local; + case 0x50000414: return generic_format; + default: fprintf(stderr, "unexpected critical-result call: %08x\n", address); abort(); + } +} +recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } +recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } + +static void setup(void) +{ + reads = writes = feedbacks = generic_feedbacks = deaths = ammo_updates = 0; + memset((void *)ADDR(0x50000000), 0, 0x10000); + MEM32(0x50000004) = MEM32(0x5000002c) = 50000; + MEM32(0x50000008) = 1; + // Known-attacker delivery ignores this different payload target identity. + MEM32(0x50000030) = missing_attacker ? 2 : 3; + MEM32(0x50000020) = 6; + MEM32(0x50000024) = 13; + MEM32(0x50000028) = ammunition; + MEM32(0x50000034) = death_reason; + MEM32(0x50000038) = expected_result; + MEM32(0x50001300) = MEM32(0x50002300) = MEM32(0x50004300) = 100; + MEM32(0x5000116c) = 0x50003000; + MEM32(0x5000216c) = 0x50003800; + MEM32(0x50003000) = 0x50000200; + MEM32(0x50003004) = 0x50001000; + MEM32(0x50003024) = 0x50005000; + MEM32(0x50003804) = 0x50002000; + MEM32(0x50000250) = 0x5000040c; + MEM32(0x500020e4) = MEM32(0x500010e4) = 0x50000100; + MEM32(0x50000104) = 0x50000400; + MEM32(0x50000108) = 0x50000404; + MEM32(0x50002154) = 0x50007000; + MEM32(0x50007014) = 0x50002000; + MEM32(0x50005010) = 0x50008000; + MEM32(0x50008004) = 0x50008100; + MEM32(0x50005020) = 0x50006000; + MEM32(0x50006000) = 0x50000300; + MEM32(0x50000308) = 0x50000408; + MEM32(0x50006020) = 5; + MEM32(0x361700d4) = 0x50000410; + MEM32(0x3616f25c) = 0x50000414; + g_esp = 0x5000ff00; + g_ecx = 0x50000000; +} + +static void queued_results(void) +{ + const struct { uint32_t result, death, index, local; int32_t ammo; } cases[] = { + {4, 0, 0, 1, 3}, {5, 0, 0, 1, 3}, + {4, 7, 49, 0, 0}, {5, 7, 49, 0, -1} + }; + for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + expected_result = cases[i].result; + death_reason = cases[i].death; + ammunition = cases[i].ammo; + target_local = cases[i].local; + missing_attacker = missing_target = 0; + setup(); + MEM32(0x50005014) = MEM32(0x50005018) = cases[i].index; + + sub_360AECB0(); + + assert(g_eax == 0 && g_esp == 0x5000ff04); + assert(MEM32(0x50002300) == 100 && reads == 0 && writes == 0); + assert(feedbacks == 0 && deaths == 0 && ammo_updates == 1); + assert((int32_t)MEM32(0x50006020) == ammunition); + assert(MEM32(0x50008100 + cases[i].index * 8) == 13); + assert(MEM32(0x50008104 + cases[i].index * 8) == expected_result); + assert(MEM32(0x50005014) == (cases[i].index == 49 ? 0 : 1)); + assert(MEM32(0x50003874) == death_reason); + + g_esp = 0x5000ff00; + g_ecx = 0x50005000; + MEM32(g_esp + 4) = 0x50002000; + MEM32(g_esp + 8) = 0x50001000; + sub_360AB5A0(); + + assert(g_esp == 0x5000ff0c); + assert(MEM32(0x50002300) == 87 && reads == 1 && writes == 1); + assert(MEM32(0x50001300) == 100 && MEM32(0x50004300) == 100); + assert(feedbacks == 1 && generic_feedbacks == 0 && ammo_updates == 1); + assert(deaths == (death_reason != 0)); + assert(MEM32(0x50005014) == MEM32(0x50005018)); + + g_esp = 0x5000ff00; + g_ecx = 0x50005000; + sub_360AB5A0(); + + assert(g_esp == 0x5000ff0c); + assert(MEM32(0x50002300) == 87 && reads == 1 && writes == 1); + assert(feedbacks == 1 && deaths == (death_reason != 0)); + } +} + +static void missing_attacker_results(void) +{ + const struct { uint32_t result, death, local, missing; } cases[] = { + {4, 0, 1, 0}, {5, 0, 1, 0}, {5, 7, 1, 0}, + {5, 0, 0, 0}, {5, 0, 1, 1} + }; + for (unsigned i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) { + expected_result = cases[i].result; + death_reason = cases[i].death; + target_local = cases[i].local; + missing_attacker = 1; + missing_target = cases[i].missing; + ammunition = 3; + setup(); + + sub_360AECB0(); + + assert(g_eax == 0 && g_esp == 0x5000ff04); + unsigned applied = target_local && !missing_target; + assert(MEM32(0x50002300) == (applied ? 87 : 100)); + assert(reads == applied && writes == applied && generic_feedbacks == applied); + assert(feedbacks == 0 && deaths == (applied && death_reason != 0)); + assert(ammo_updates == 0 && MEM32(0x50006020) == 5); + assert(MEM32(0x50005014) == 0 && MEM32(0x50005018) == 0); + } +} + +int main(void) +{ + assert(guest_map("critical result fixture", 0x50000000, 0x10000)); + assert(guest_map("critical result imports", 0x36160000, 0x20000)); + queued_results(); + missing_attacker_results(); + puts("native critical results: queue, single damage, feedback result, death and ammo routing passed"); +} diff --git a/docs/critical-hits.md b/docs/critical-hits.md @@ -0,0 +1,87 @@ +# Critical results: verified routing and unresolved selection + +The server still emits normal weapon results. Critical probability and damage +selection remain open; result code 5 alone does not calculate critical damage. +The original client accepts an already resolved damage amount and presents it +through the weapon animation queue. + +## Original-code contract + +`client/tests/critical_result.c` links unchanged lifted 14.9.1 functions from +`kkr.dll`, SHA-256 +`a37bc1c15053fdcc5572772309f7074c4f83baffe2faa164df40b059b7c480c0`. +It executes AttackInfo activation `100aecb0`, holder delivery/slot lookup +`1007a660`/`1007a320`, ring insertion `100ab4c0`, peek/pop/nonempty helpers, +impact consumption `100ab5a0`, raw-stat assignment helper `10075db0` and +missing-attacker fallback `1007be50`. + +Nine cases pass on Linux and WASM. For a known attacker, receipt queues the +supplied amount 13 and result 4 or 5, assigns ammunition immediately, and leaves +HP 100 until impact. Impact changes HP to 87 exactly once. A second empty-queue +consumption changes nothing. Other cases cover index 49 wrapping to 0, +ammunition 3/0/-1, local defender/observer feedback and death routing. Death +reason 7 is an arbitrary branch probe, not an established weapon-death reason. + +The fixture's amount 13 is an input, not a critical-damage calculation. It +also deliberately supplies a different packet target: the known attacker's +impact uses its current opponent, which is why target changes and weapon +replacement must account for queued results. The missing-attacker path instead +subtracts from a local payload target immediately and uses generic feedback +for either result 4 or 5. A missing or nonlocal payload target is ignored. + +Identity lookup/casts, locality, damage type, actor/item stat storage, feedback +formatting and death are fixture boundaries. The actual critical text formatter +is outside the C contract. Retained static evidence for its result-5 branch is +`ev_16fbb07444de249fd19ed14114c99abb43239d8f64214cc0e4494b36dc8a7c77`; +the complete routing evidence and boundary list are in +`local/critical-hit-research/result-contract.md` and +`local/reports/combat-outcomes-1491-evidence.json`. + +## WASM presentation check + +Two browser clients completed a controlled packet fixture against the shared +preview. For one ordinary pistol hit, the fixture changed only the AttackInfo +result DWORD from 4 to 5 on each client's incoming stream. The supplied damage +10, ammunition 18, identities and death field stayed unchanged. This exercises +the original packet reader, animation and text formatter; it does not test +server critical probability or critical-damage arithmetic. + +Both screens displayed the 10-point projectile hit followed by `Critical hit!`. +Read-only samples observed result 5 queued while target HP remained 100, then +the queue emptied. The observer reached 90 HP. The owner's first post-impact +sample was 91, consistent with one recovery tick between 100 ms samples; +the C contract above separately verifies the exact single subtraction. +The database retained all 192 item rows, with only the pistol's ammunition +changing from 19 to 18. The successful run had no adapter or page errors. +Both test browser contexts were closed afterward. + +## Calculation evidence and gaps + +The [July 2002 weapon guide](https://forums-archive.anarchy-online.com/showthread.php?37266-How-to-Choose-A-Weapon-Guide-for-the-MP=) +gives an example consistent with `(maximum + critical bonus) * (1 + AR/400)` +before armor. The selected catalog supplies maximum stat 285 and critical +bonus stat 284. Fractional rounding, the critical AC floor, partial/zero +overequipping and modifier order still need independent checks. The native +result contract cannot establish these server rules. + +[Vampi's September 2001 guide](https://martin.brenner.de/ao/vampiguide/weapeval.html#whynocrits) +attributes a three-percent minimum and an attack-versus-evade contribution to +the Sybex guide. The exact book is Chris W. McCubbin's 2001 *Anarchy Online: +Sybex Official Strategies & Secrets*, ISBN 0782129935, 240 pages. Its original +combat pages have not been inspected. Vampi does not supply controlled critical +counts, and the claimed caps, zero-evade behavior and roll ordering remain +unknown. A later October 2003 three-percent assertion falls after Shadowlands +and does not establish the 14.9.1 equation. + +A [February 2002 pistol guide](https://www.geocities.ws/cratpistol/) +reports fewer incoming criticals after lowering AggDef to about 75 percent. +This is a first-person qualitative observation without counts or an equation; +it cannot select a numeric AggDef or defense term. + +Subconscious Guidance 95526 authors CriticalIncrease stat 379 equal to +8 and +describes an eight-percent increase. This establishes the intended modifier, +but not the hidden baseline or its complete combination with evades and other +defenses. Sniper's Friend modifies range stat 380, not critical chance. +The bounded follow-up found no stronger target-era numerical proof. Exact +source dates, provenance and search limits are retained in +`local/critical-hit-research/period-sources.md`.