aorecomp

Anarchy Online classic in the browser

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


commit 8542a848638308b1bacbe4c85d796348a58be6ab
parent 3cb33f7f887fb958e74cb8ee774f942e2ea5cade
Author: anon <anon@example.com>
Date:   Sat, 24 Oct 2026 10:54:23 +0000

Isolate player reference rendering from shop state

Diffstat:
MTODO.md | 18+++++++++++-------
Mclient/Makefile.linux | 7+++++++
Mclient/Makefile.wasm | 4++++
Mclient/game/ddr.dll/lifted-0030.c | 10++++++++--
Aclient/tests/character_reference.c | 185+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mdocs/character-info.md | 42+++++++++++++++++++++++++++++++-----------
6 files changed, 246 insertions(+), 20 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -726,15 +726,19 @@ and unresolved indoor lifecycle are explicit in [flight](docs/vehicles.md#yalmah repeated adds, self-add rejection, NPC reference suppression and the full right-hold/hover/release Accept/Remove gesture. CharacterAction 105 now has its original InfoPacket reply; C adapters fix reached `_strdate` and - `strcspn` crashes. Description values and reference persistence remain below. + `strcspn` crashes. Description verification and reference persistence follow. See [player information](docs/character-info.md). -- [ ] Correct native reference description stats. Check: a level-150 Engineer +- [x] Correct native reference description stats. Check: a level-150 Engineer reference shows the actual level/profession/title, rather than level 0 and - no profession. Live raw actor stats are correct after InfoPacket, and the - original effective-stat getter chain passes controlled Linux/WASM fixtures. - Resolve the live renderer/lookup discrepancy without replacing original - stat behavior with a raw-value shortcut. Evidence: `local/reference-research/render.md` - and `local/reference-smoke/reference-description-final.png`. + no profession. The reference callback now scopes normal-stat mode around + its renderer, preserving the previous shop context and original effective + getters. The constructor leaves this mode byte uninitialized. Linux/WASM + callback regressions cover normal/shop/arbitrary modes, unrelated replies, + NPCs, event payload and ABI. Two GPU WASM clients verified Level 150 + Master Engineer, Level 150 Meta-Physicist/Spiritual Leader and Level 1 + Soldier/Militiaman, including injected mode bytes 1 and 141 with restoration. + See [player information](docs/character-info.md), `local/reference-debug/` + and `local/reference-research/mode.md`. - [ ] Persist Knowledge references in the browser using the original native format and save timing. Check: player references and their descriptions survive reload/reconnect and remain separate between characters. The verified diff --git a/client/Makefile.linux b/client/Makefile.linux @@ -171,6 +171,7 @@ test: build/linux/window build/linux/graphics build/linux/atoi build/linux/stric ./build/linux/guest-heap ./build/linux/native-input ./build/linux/team-header + ./build/linux/character-reference ./build/linux/weapon-range ./build/linux/ip-training ./build/linux/fling-result @@ -681,3 +682,9 @@ build/linux/critical-result: tests/critical_result.c game/kkr.dll/lifted-0034.c $(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -lm -o $@ test: build/linux/critical-result + +build/linux/character-reference: tests/character_reference.c game/ddr.dll/lifted-0030.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/character-reference diff --git a/client/Makefile.wasm b/client/Makefile.wasm @@ -232,3 +232,7 @@ build/wasm/jpeg-idct.js: tests/jpeg_idct.c game/bbr.dll/lifted-0042.c runtime/gu build/wasm/inflate-fast.js: tests/inflate_fast.c game/bbr.dll/lifted-0044.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 $@ + +build/wasm/character-reference.js: tests/character_reference.c game/ddr.dll/lifted-0030.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 $@ diff --git a/client/game/ddr.dll/lifted-0030.c b/client/game/ddr.dll/lifted-0030.c @@ -39445,8 +39445,14 @@ L_2B074A58: PUSH32(esp, 1); /* 0x2B074A58: push 1 */ PUSH32(esp, esi); /* 0x2B074A5A: push esi */ ecx = ebx; /* 0x2B074A5B: mov ecx, ebx */ - RECOMP_ICALL(0x2B06FC30u); /* 0x2B074A5D: call 0x2b06fc30 */ /* not lifted */ - RECOMP_FLAGS_IN(); + /* Character references use actor stats regardless of the open shop view. */ + { + uint8_t shop_mode = MEM8(ebx + 0x1C); + MEM8(ebx + 0x1C) = 0; + RECOMP_ICALL(0x2B06FC30u); /* 0x2B074A5D: call 0x2b06fc30 */ /* not lifted */ + RECOMP_FLAGS_IN(); + MEM8(ebx + 0x1C) = shop_mode; + } goto L_2B074AB4; /* 0x2B074A62: jmp 0x2b074ab4 */ L_2B074A64: edx = MEM32(ebx + 0x28); /* 0x2B074A64: mov edx, dword ptr [ebx + 0x28] */ diff --git a/client/tests/character_reference.c b/client/tests/character_reference.c @@ -0,0 +1,185 @@ +#include "recomp_types.h" +#include <assert.h> + +void sub_2B074A20(void); +void sub_2B0735D0(void); +static unsigned renders, queries, publications, identities, allocations; +static uint32_t level, profession, title; +static int npc; +static char published[80]; + +static void instance(void) { g_eax = 0x50002000; g_esp += 4; } +static void is_npc(void) { g_eax = npc; g_esp += 8; } +static void actor_skill(void) +{ + assert(g_ecx == 0x50002000); + uint32_t identity = MEM32(g_esp + 4); + assert(MEM32(identity) == 50000 && MEM32(identity + 4) == 52); + switch (MEM32(g_esp + 8)) { + case 54: g_eax = level; break; + case 368: g_eax = profession; break; + case 37: g_eax = title; break; + default: abort(); + } + ++queries; + g_esp += 12; +} +static void shop_skill(void) { g_eax = 0; g_esp += 12; } + +/* Keep formatting as a sink; exercise the real callback and stat selector. */ +static void render_description(void) +{ + assert(g_ecx == 0x50000000 && MEM32(g_esp + 8) == 1); + uint32_t identity = MEM32(g_esp + 4), stack = g_esp, values[3]; + const uint32_t stats[] = {54, 368, 37}; + for (unsigned i = 0; i < 3; ++i) { + g_esp -= 12; + MEM32(g_esp + 4) = identity; + MEM32(g_esp + 8) = stats[i]; + g_ecx = 0x50000000; + sub_2B0735D0(); + assert(g_esp == stack); + values[i] = g_eax; + } + int length = snprintf((char *)ADDR(0x50000300), 80, "%u/%u/%u", values[0], values[1], values[2]); + MEM32(0x50000208) = length; + ++renders; + g_esp += 12; +} +static void allocate_text(void) +{ + assert(MEM32(g_esp + 4) == MEM32(0x50000208) + 1); + ++allocations; + g_eax = 0x50000400; + g_esp += 4; +} +static void copy_text(void) +{ + assert(g_ecx == 0x50000200 && MEM32(g_esp + 8) == 0); + strcpy((char *)ADDR(MEM32(g_esp + 4)), (char *)ADDR(0x50000300)); + g_esp += 12; +} +static void publish_text(void) +{ + assert(g_ecx == 0x50002000); + assert(MEM32(g_esp + 4) == 0x20 && MEM32(g_esp + 8) == 0xb2); + assert(MEM32(g_esp + 16) == strlen((char *)ADDR(MEM32(g_esp + 12))) + 1); + snprintf(published, sizeof(published), "%s", (char *)ADDR(MEM32(g_esp + 12))); + ++publications; + g_esp += 20; +} +static void publish_identity(void) +{ + assert(g_ecx == 0x50002000 && MEM32(g_esp + 4) == 0x50000100); + ++identities; + g_esp += 8; +} +static void release_text(void) { assert(MEM32(g_esp + 4) == 0x50000400); g_esp += 4; } +static void resize_text(void) +{ + assert(g_ecx == 0x50000200 && MEM32(g_esp + 4) == 3 && MEM32(g_esp + 8) == 1); + g_eax = 1; + g_esp += 12; +} + +recomp_func_t recomp_lookup_manual(uint32_t address) { return NULL; } +recomp_func_t recomp_lookup_import(uint32_t address) { abort(); } +recomp_func_t recomp_lookup(uint32_t address) +{ + switch (address) { + case 1: return instance; + case 2: return is_npc; + case 3: return actor_skill; + case 4: return shop_skill; + case 5: return copy_text; + case 6: return publish_text; + case 7: return publish_identity; + case 9: return resize_text; + case 0x2b06fc30: return render_description; + case 0x2b0ab212: return allocate_text; + case 0x2b0ab1ba: return release_text; + default: fprintf(stderr, "unexpected reference call: %08x\n", address); abort(); + } +} + +static void arrange(uint8_t mode) +{ + memset((void *)ADDR(0x50000000), 0, 0x10000); + MEM8(0x5000001c) = mode; + MEM32(0x50000000) = MEM32(0x50000020) = MEM32(0x50000100) = 50000; + MEM32(0x50000004) = MEM32(0x50000024) = MEM32(0x50000104) = 52; + MEM32(0x50000028) = 0x50000200; + MEM32(0x50000204) = 0x50000300; + g_esp = 0x5000ff00; + MEM32(g_esp + 4) = 0x50000100; + g_ecx = 0x50000000; + g_ebx = 111; g_esi = 222; g_edi = 333; g_ebp = 444; + renders = queries = publications = identities = allocations = 0; + published[0] = 0; + npc = 0; +} + +static void assert_abi(void) +{ + assert(g_esp == 0x5000ff08); + assert(g_ebx == 111 && g_esi == 222 && g_edi == 333 && g_ebp == 444); +} + +static void test_player_description(uint8_t mode) +{ + arrange(mode); + level = 150; profession = 12; title = 5; + + sub_2B074A20(); + + assert(!strcmp(published, "150/12/5")); + assert(renders == 1 && queries == 3 && publications == 1 && identities == 1 && allocations == 1); + assert(MEM8(0x5000001c) == mode); + assert(MEM32(0x50000000) == 0 && MEM32(0x50000004) == 0); + assert_abi(); +} + +static void test_unrelated_reply(unsigned offset) +{ + arrange(141); + MEM32(0x50000100 + offset) = 53; + + sub_2B074A20(); + + assert(renders == 0 && queries == 0 && publications == 0 && identities == 0 && allocations == 0); + assert(MEM8(0x5000001c) == 141 && MEM32(0x50000000) == 50000 && MEM32(0x50000004) == 52); + assert_abi(); +} + +static void test_npc_description(void) +{ + arrange(1); + npc = 1; + + sub_2B074A20(); + + assert(!strcmp(published, "npc")); + assert(renders == 0 && queries == 0 && publications == 1 && identities == 1 && allocations == 1); + assert(MEM8(0x5000001c) == 1); + assert_abi(); +} + +int main(void) +{ + assert(guest_map("reference imports and text", 0x2b000000, 0x100000)); + assert(guest_map("reference fixture", 0x50000000, 0x10000)); + MEM32(0x2b0b5d6c) = MEM32(0x2b0b53cc) = 1; + MEM32(0x2b0b5e94) = 2; + MEM32(0x2b0b5ee0) = 3; MEM32(0x2b0b5e74) = 4; + MEM32(0x2b0b5b84) = 5; MEM32(0x2b0b53c4) = 6; + MEM32(0x2b0b53b4) = 7; MEM32(0x2b0b5154) = 9; + strcpy((char *)ADDR(0x2b0e517c), "npc"); + test_player_description(0); + test_player_description(1); + test_player_description(141); + test_player_description(255); + test_unrelated_reply(0); + test_unrelated_reply(4); + test_npc_description(); + puts("character references: actor stats, mode isolation, reply identity, NPC and ABI passed"); +} diff --git a/docs/character-info.md b/docs/character-info.md @@ -99,7 +99,7 @@ repeated delimiters, embedded NUL and high bytes, unchanged inputs and ABI. Two hardware WASM clients verified Alt/G creation, reference pickup/drop, repeated friend additions, self-reference/self-add rejection, NPC suppression, native Accept/Remove, owner reload, profile variation and equipped-resource -accounting. A level-150 female Engineer retained Level 150 and ProfessionLevel +accounting. A level-150 female Meta-Physicist retained Level 150 and ProfessionLevel 1 while InfoPacket corrected remote profession/title/regeneration fields. Dust Collector inspection changed raw maximum HP from 931 plus modifier 90 to 1021 plus modifier 0, preserving the nano modifier. Removal and replacement @@ -110,14 +110,34 @@ requests and eight InfoPacket replies with no adapter/page errors. Owned characters/items were then removed with all unrelated rows unchanged and SQLite integrity and foreign-key checks passing. -The description currently displays Level 0 and no profession despite those -correct actor stats. The original renderer uses the effective-stat identity -getter for these fields. Its actual lifted DDR/EER/KKR chain passes controlled +The original renderer uses the effective-stat identity getter for profession, +title level and level. The actual lifted DDR/EER/KKR chain passes controlled Linux and WASM fixtures, including production optimization settings, register/ -stack/FPU preservation and real trickle math. Live shop mode, actor backpointer, -raw getter and import targets have been checked; the live loss remains -unresolved. Do not replace that getter with raw reads as a workaround. -Knowledge references also disappear on browser reload; only the resulting -Friends entry is durable. Both remaining issues are tracked in TODO. -Runtime artifacts and diagnostic commands are in `local/reference-smoke/` and -`local/reference-research/render.md`. +stack/FPU preservation, real actor lookup/RTTI and trickle math. A live trace +found that the reference callback instead selected shop stats: InfoSystem's +mode byte was 141. Constructor 0x1006b660 leaves that byte uninitialized, and +reference callback 0x10074a20 bypasses the general display's mode setup. + +The callback now temporarily sets normal-stat mode around its player renderer +call at 0x10074a5d, then restores the previous byte. This follows the scope +already used by item renderer 0x1006f480 and preserves an open shop's context. +Initializing only the constructor would still allow a preceding shop view to +affect player references. The effective getters and stat calculations remain +unchanged. The regression exercises the real callback and stat selector with +mode bytes 0, 1, 141 and 255, verifies the description event and identity, +rejects unrelated replies, checks NPC handling and preserves the guest ABI. +Formatting is a test sink; actual rendered text requires the live WASM check. + +Two GPU WASM clients verified the rendered descriptions for a level-150 +female Meta-Physicist (Spiritual Leader), the same player changed to Engineer +(Master Engineer), and a level-1 male Soldier (Militiaman). Deliberate mode +bytes 141 and 1 in the owned test client still produced correct self/remote +descriptions and were restored after rendering. These are mode fault-injection +checks, not an end-to-end shop transaction test. The normal published bundle +contains no diagnostic tracing and produced no adapter or page errors. + +Knowledge references still disappear on browser reload; only the resulting +Friends entry is durable. This remains tracked in TODO. Runtime artifacts and +diagnostic commands are in `local/reference-smoke/`, `local/reference-debug/` +and `local/reference-research/`. `mode.md` retains the original constructor, +mode-writer, renderer-caller and callback ABI evidence.