commit 955873d524a40a4a84abb18eb8a376a7219031ca
parent 060207060075e3fa70a2fe38fd84abd69d0ffca9
Author: anon <anon@example.com>
Date: Sat, 17 Oct 2026 07:12:06 +0000
Initialize mesh bind poses before the first animation update
Diffstat:
4 files changed, 115 insertions(+), 0 deletions(-)
diff --git a/src/Makefile.linux b/src/Makefile.linux
@@ -222,6 +222,7 @@ test: build/linux/window build/linux/graphics build/linux/atoi build/linux/stric
./build/linux/fpu-stack
./build/linux/water-ring
./build/linux/skinning
+ ./build/linux/vertex-initialization
./build/linux/ground-height
./build/linux/tile-corners
./build/linux/terrain-line
@@ -484,3 +485,9 @@ build/linux/ground-height: tests/ground_height.c game/bbr.dll/lifted-0013.c runt
$(CC) $(CPPFLAGS) $(CFLAGS) -ffunction-sections -fdata-sections $(filter %.c,$^) -Wl,--gc-sections -pthread -lm -o $@
test: build/linux/ground-height
+
+build/linux/vertex-initialization: tests/vertex_initialization.c game/bbr.dll/lifted-0061.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/vertex-initialization
diff --git a/src/Makefile.wasm b/src/Makefile.wasm
@@ -85,3 +85,7 @@ build/wasm/web/capture-test.html: tests/browser_capture.html build/wasm/web/capt
build/wasm/web/capture-test.js: tests/browser_capture.c runtime/gl_renderer.c runtime/gl_renderer.h Makefile.wasm
@mkdir -p $(@D)
$(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -sPROXY_TO_PTHREAD -sPTHREAD_POOL_SIZE=1 -sOFFSCREENCANVAS_SUPPORT -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -o $@
+
+build/wasm/vertex-initialization.js: tests/vertex_initialization.c game/bbr.dll/lifted-0061.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/src/game/bbr.dll/lifted-0061.c b/src/game/bbr.dll/lifted-0061.c
@@ -4825,6 +4825,8 @@ L_250F5D10:
eax = eax + 0x1Cu; /* 0x250F5D12: add eax, 0x1c */
_flag_k = FK_ADD;
L_250F5D15:
+ /* Initialize the bind pose before the first animation update. */
+ memcpy((void *)ADDR(eax - 0x1C), (void *)ADDR(MEM32(esi + 0xC) + ecx + 0x18), 24);
ebx = MEM32(esi + 0xC); /* 0x250F5D15: mov ebx, dword ptr [esi + 0xc] */
ebx = MEM32(ebx + ecx + 0x30); /* 0x250F5D18: mov ebx, dword ptr [ebx + ecx + 0x30] */
MEM32(eax + (-0x4)) = ebx; /* 0x250F5D1C: mov dword ptr [eax - 4], ebx */
diff --git a/src/tests/vertex_initialization.c b/src/tests/vertex_initialization.c
@@ -0,0 +1,102 @@
+#include "recomp_types.h"
+#include <assert.h>
+
+void sub_250F5C40(void);
+static unsigned locks, unlocks;
+
+static void retain(void) { g_esp += 4; }
+
+static void resize_sections(void)
+{
+ assert(g_ecx == 0x5000000c);
+ MEM32(g_ecx) = MEM32(g_esp + 4);
+ MEM32(g_ecx + 4) = 0x50000100;
+ g_esp += 8;
+}
+
+static void resize_parts(void)
+{
+ assert(g_ecx == 0x50000104);
+ MEM32(g_ecx) = MEM32(g_esp + 4);
+ MEM32(g_ecx + 4) = 0x50000200;
+ g_esp += 8;
+}
+
+static void create_vertices(void)
+{
+ assert(g_ecx == 0x50000200);
+ assert(MEM32(g_esp + 4) == 2);
+ memset((void *)ADDR(0x50008000), 0xa5, 64);
+ g_esp += 8;
+}
+
+static void lock_vertices(void)
+{
+ assert(g_ecx == 0x50000200);
+ ++locks;
+ g_eax = 0x50008000;
+ g_esp += 4;
+}
+
+static void unlock_vertices(void)
+{
+ assert(g_ecx == 0x50000200);
+ ++unlocks;
+ g_esp += 4;
+}
+
+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 0x250e6360: case 0x70000000: return retain;
+ case 0x250f7470: return resize_sections;
+ case 0x250f73a0: return resize_parts;
+ case 0x250f7270: return create_vertices;
+ case 0x250f72e0: return lock_vertices;
+ case 0x25118ef0: return unlock_vertices;
+ default: fprintf(stderr, "unexpected %08x\n", address); abort();
+ }
+}
+
+static void test_initial_vertices(void)
+{
+ memset((void *)ADDR(0x50000000), 0, 0x10000);
+ MEM32(0x50000000) = 0x50000900;
+ MEM32(0x50000908) = 0x70000000;
+ MEM32(0x50001040) = 1;
+ MEM32(0x50001044) = 0x50002000;
+ MEM32(0x50002010) = 1;
+ MEM32(0x50002014) = 0x50003000;
+ MEM32(0x50003008) = 2;
+ MEM32(0x5000300c) = 0x50004000;
+ const float vertices[] = {
+ 11,12,13, 14,15,16, -7,8,9, 0,1,0, .25f,.5f, 0,0,1,
+ 21,22,23, 24,25,26, 17,-18,19, 1,0,0, .75f,1, 0,0,1,
+ };
+ memcpy((void *)ADDR(0x50004000), vertices, sizeof(vertices));
+ g_ecx = 0x50000000;
+ g_esp = 0x5000ff00;
+ MEM32(g_esp + 4) = 0x50001000;
+ g_ebx = 111; g_esi = 222; g_edi = 333; g_ebp = 444;
+ locks = unlocks = 0;
+
+ sub_250F5C40();
+
+ const float expected[] = {-7,8,9, 0,1,0, .25f,.5f,
+ 17,-18,19, 1,0,0, .75f,1};
+ assert(!memcmp((void *)ADDR(0x50008000), expected, sizeof(expected)));
+ assert(locks == 1 && unlocks == 1);
+ assert(MEM32(0x50000004) == 0x50001000);
+ assert(MEM32(0x50000024) == 1);
+ assert(g_esp == 0x5000ff08);
+ assert(g_ebx == 111 && g_esi == 222 && g_edi == 333 && g_ebp == 444);
+}
+
+int main(void)
+{
+ assert(guest_map("vertex initialization fixture", 0x50000000, 0x10000));
+ test_initial_vertices();
+ puts("vertex initialization: complete bind pose before animation passed");
+}