aorecomp

Anarchy Online classic in the browser

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


commit e100edd15488b6b53aa14e94d4502805d5901a48
parent 69975c04b44c5ae491bfbcdab6179b93bc42e314
Author: anon <anon@example.com>
Date:   Sat, 17 Oct 2026 22:37:49 +0000

Share animation lookups within event scans

Diffstat:
Msrc/Makefile.linux | 6++++++
Msrc/game/kkr.dll/lifted-0025.c | 25+++++++++++++++++++++++++
Asrc/tests/animation_events.c | 163+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 194 insertions(+), 0 deletions(-)

diff --git a/src/Makefile.linux b/src/Makefile.linux @@ -548,3 +548,9 @@ build/linux/stdio-concurrency: tests/stdio_concurrency.c runtime/guest_stdio.c r $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -pthread -lm -Wl,--wrap=read -o $@ test: build/linux/stdio-concurrency + +build/linux/animation-events: tests/animation_events.c game/kkr.dll/lifted-0025.c game/bbr.dll/lifted-0032.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 -pthread -lm -o $@ + +test: build/linux/animation-events diff --git a/src/game/kkr.dll/lifted-0025.c b/src/game/kkr.dll/lifted-0025.c @@ -8402,6 +8402,7 @@ L_3604F160: } void sub_3604F180(void) { + int animation_forward = -1; int _fpu_cmp = 0; uint32_t _cf = 0; int _df = 1; @@ -8484,6 +8485,24 @@ L_3604F1CC: ebp = POP32_VAL(esp); /* 0x3604F1D2: pop ebp */ RECOMP_FLAGS_OUT(); esp += 8; { RECOMP_REGS_OUT(); return; } /* 0x3604F1D3: ret 4 */ L_3604F1D6: + /* Snapshot the standard VisualCATMesh getters once per event scan. A + * cooperative guest thread may change the animation at a backedge, so + * retain the individual calls when the native32 yield hook is installed. */ + if (!recomp_yield_hook && + MEM32(0x3616F980) == 0x250975F0u && + MEM32(0x3616F990) == 0x250975A0u && + MEM32(0x3616F984) == 0x250975D0u && + MEM32(0x3616F974) == 0x25097550u) { + PUSH32(esp, MEM32(esi)); + ecx = ebx; + RECOMP_ICALL(0x250973C0u); /* VisualCATMesh::FindAnim */ + MEM32(esi + 0x20) = eax ? MEM32(eax + 0x44) : 0; + MEM32(esi + 0x24) = eax && (int32_t)MEM32(esi) >= 0 ? MEM32(eax + 0x40) : 0; + MEM32(esi + 0x28) = eax ? MEM32(eax + 0x3C) : 0; + animation_forward = eax && MEM32(eax + 0x24) == 0; + eax = animation_forward; + goto L_3604F20B; + } eax = MEM32(esi); /* 0x3604F1D6: mov eax, dword ptr [esi] */ PUSH32(esp, eax); /* 0x3604F1D8: push eax */ ecx = ebx; /* 0x3604F1D9: mov ecx, ebx */ @@ -8507,6 +8526,7 @@ L_3604F1D6: ecx = ebx; /* 0x3604F203: mov ecx, ebx */ RECOMP_ICALL(MEM32(0x3616F974)); /* 0x3604F205: call dword ptr [0x3616f974] */ RECOMP_FLAGS_IN(); +L_3604F20B: /* test LO8(eax), LO8(eax) */ /* 0x3604F20B: test al, al */ _flag_a = (uint32_t)(LO8(eax)) << 24; _flag_b = (uint32_t)(LO8(eax)) << 24; _cf = 0; @@ -8590,11 +8610,16 @@ L_3604F24C: RECOMP_BACKEDGE(); if (CMP_G(_flag_a, _flag_b)) goto L_3604F248; /* 0x3604F256: jg 0x3604f248 */ L_3604F258: + if (animation_forward >= 0) { + eax = animation_forward; + goto L_3604F263; + } edx = MEM32(esi); /* 0x3604F258: mov edx, dword ptr [esi] */ PUSH32(esp, edx); /* 0x3604F25A: push edx */ ecx = ebx; /* 0x3604F25B: mov ecx, ebx */ RECOMP_ICALL(MEM32(0x3616F974)); /* 0x3604F25D: call dword ptr [0x3616f974] */ RECOMP_FLAGS_IN(); +L_3604F263: /* test LO8(eax), LO8(eax) */ /* 0x3604F263: test al, al */ _flag_a = (uint32_t)(LO8(eax)) << 24; _flag_b = (uint32_t)(LO8(eax)) << 24; _cf = 0; diff --git a/src/tests/animation_events.c b/src/tests/animation_events.c @@ -0,0 +1,163 @@ +#include "recomp_types.h" +#include <assert.h> + +void sub_3604F180(void); +void sub_250973C0(void); +void sub_25097550(void); +void sub_250975A0(void); +void sub_250975D0(void); +void sub_250975F0(void); +static unsigned lookups; + +static void get_mesh(void) +{ + g_eax = MEM32(g_ecx); + g_esp += 4; +} + +static void find_animation(void) +{ + ++lookups; + sub_250973C0(); +} + +static void yield(void) {} +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 get_mesh; + case 2: return sub_250975F0; + case 0x250973C0: return find_animation; + case 0x25097550: return sub_25097550; + case 0x250975A0: return sub_250975A0; + case 0x250975D0: return sub_250975D0; + case 0x250975F0: return sub_250975F0; + default: abort(); + } +} + +static void fixture(unsigned direction, unsigned previous, unsigned current, unsigned actual) +{ + memset((void *)ADDR(0x50000000), 0, 0x10000); + MEM32(0x3616FFE8) = 1; + MEM32(0x3616F980) = 0x250975F0; + MEM32(0x3616F990) = 0x250975A0; + MEM32(0x3616F984) = 0x250975D0; + MEM32(0x3616F974) = 0x25097550; + recomp_yield_hook = NULL; + lookups = 0; + + /* One mesh with a circular animation list and a three-event iterator. */ + MEM32(0x50000000) = 0x50000100; + MEM32(0x50000120) = 0x50000200; + MEM32(0x50000204) = 0x50000300; + MEM32(0x50000300) = 0x50000400; + MEM32(0x50000400) = 0x50000300; + MEM32(0x50000408) = 0x50000500; + MEM32(0x50000510) = 7; + MEM32(0x50000524) = direction; + MEM32(0x50000544) = previous; + MEM32(0x50000540) = current; + MEM32(0x5000053C) = actual; + MEM32(0x50000600) = 7; + MEM32(0x50000604) = -1; + MEM32(0x50000618) = 0; + MEM32(0x5000061C) = 40; + MEM32(0x5000062C) = 3; + MEM32(0x50000638) = 0x50000700; + for (unsigned i = 0; i < 3; ++i) { + MEM32(0x50000720 + i * 0x28) = 101 + i; + MEM32(0x50000724 + i * 0x28) = 10 + i * 10; + } +} + +static unsigned next_event(recomp_func_t function) +{ + g_ecx = 0x50000600; + g_esp = 0x5000ff00; + MEM32(g_esp + 4) = 0x50000000; + g_ebx = 111; g_esi = 222; g_edi = 333; g_ebp = 444; + function(); + assert(g_esp == 0x5000ff08); + assert(g_ebx == 111 && g_esi == 222 && g_edi == 333 && g_ebp == 444); + return g_eax; +} + +static void test_forward(unsigned fallback) +{ + fixture(0, 5, 25, 25); + if (fallback == 1) recomp_yield_hook = yield; + if (fallback == 2) MEM32(0x3616F980) = 2; + + unsigned first = next_event(sub_3604F180); + unsigned first_lookups = lookups; + unsigned second = next_event(sub_3604F180); + unsigned end = next_event(sub_3604F180); + + assert(first == 101 && second == 102 && end == UINT32_MAX); + assert(first_lookups == (fallback ? 5 : 1)); + assert(MEM32(0x50000630) == 2 && MEM32(0x50000634) == 3); +} + +static void test_reverse(void) +{ + fixture(1, 25, 5, 5); + + unsigned first = next_event(sub_3604F180); + unsigned second = next_event(sub_3604F180); + unsigned end = next_event(sub_3604F180); + + assert(first == 102 && second == 101 && end == UINT32_MAX); +} + +static void test_wrap(void) +{ + fixture(0, 25, 45, 15); + + unsigned first = next_event(sub_3604F180); + unsigned second = next_event(sub_3604F180); + unsigned end = next_event(sub_3604F180); + + assert(first == 103 && second == 101 && end == UINT32_MAX); +} + +static void test_absent(unsigned kind) +{ + fixture(0, 5, 25, 25); + if (kind == 0) MEM32(0x50000600) = 8; + if (kind == 1) MEM32(0x50000300) = 0x50000300; + if (kind == 2) MEM32(0x5000062C) = 0; + if (kind == 3) MEM32(0x50000000) = 0; + + unsigned event = next_event(sub_3604F180); + + assert(event == UINT32_MAX); +} + +static void test_negative_id(void) +{ + fixture(0, 5, 25, 25); + MEM32(0x50000510) = MEM32(0x50000600) = -2; + + next_event(sub_3604F180); + + assert(MEM32(0x50000620) == 5); + assert(MEM32(0x50000624) == 0); + assert(MEM32(0x50000628) == 25); +} + +int main(void) +{ + assert(guest_map("animation event fixture", 0x50000000, 0x10000)); + assert(guest_map("animation imports", 0x36160000, 0x10000)); + test_forward(0); + test_forward(1); + test_forward(2); + test_reverse(); + test_wrap(); + for (unsigned i = 0; i < 4; ++i) test_absent(i); + test_negative_id(); + puts("animation events: forward, reverse, wrap, absent, negative ID and fallback checks pass"); +}