commit 2883ccaace793831372eadb5995822b62efb7a8b
parent 955873d524a40a4a84abb18eb8a376a7219031ca
Author: anon <anon@example.com>
Date: Sat, 17 Oct 2026 07:34:54 +0000
Read resident terrain corners without repeated guest dispatch
Diffstat:
4 files changed, 71 insertions(+), 1 deletion(-)
diff --git a/src/Makefile.linux b/src/Makefile.linux
@@ -437,7 +437,7 @@ build/linux/water-ring: tests/water_ring.c game/bbr.dll/lifted-0012.c game/bbr.d
test: build/linux/water-ring
-build/linux/tile-corners: tests/tile_corners.c game/llr.dll/lifted-0021.c game/llr.dll/lifted-0022.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_memory.h
+build/linux/tile-corners: tests/tile_corners.c game/llr.dll/lifted-0021.c game/llr.dll/lifted-0022.c game/bbr.dll/lifted-0013.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 $@
diff --git a/src/Makefile.wasm b/src/Makefile.wasm
@@ -89,3 +89,7 @@ build/wasm/web/capture-test.js: tests/browser_capture.c runtime/gl_renderer.c ru
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 $@
+
+build/wasm/tile-corners.js: tests/tile_corners.c game/llr.dll/lifted-0021.c game/llr.dll/lifted-0022.c game/bbr.dll/lifted-0013.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/llr.dll/lifted-0021.c b/src/game/llr.dll/lifted-0021.c
@@ -7749,6 +7749,29 @@ void sub_38038370(void)
data = MEM32(tilemap + 12);
uint32_t ground = MEM32(data + 0x8258);
double scale = *(float *)ADDR(data + 0x1c);
+ /* Read resident samples directly; retain the final call's guest state.
+ * bbr.dll!AnarchyGroundData_t::{PatchHandle,RawHeight,Height}.
+ * Re-read data on every corner, including after the eviction stamp. */
+ if (i < 3 && MEM32(0x3804E24C) == 0x25040C80u &&
+ MEM32(0x3804E248) == 0x25040CB0u && MEM32(0x3804E244) == 0x25040840u) {
+ unsigned full_height = MEM8(ground + 0x29);
+ unsigned shift = MEM32(ground + 0x3c) & 31;
+ uint32_t mask = MEM32(ground + 0x40);
+ uint32_t patch_index = (uint32_t)((int32_t)iz[i] >> shift) * MEM32(ground + 0x48)
+ + (uint32_t)((int32_t)ix[i] >> shift);
+ uint32_t patch = MEM32(ground + 0x50) + patch_index * 0x54;
+ if (MEM32(patch + 0x1c)) {
+ MEM32(patch + 0x18) = MEM32(ground + 0x24);
+ uint32_t index = (MEM32(ground + 0x38) + 1) * (iz[i] & mask) + (ix[i] & mask);
+ eax = MEM16(MEM32(patch + 0x1c) + index * 2);
+ if (!full_height) eax >>= 8;
+ if (!(i & 1)) scale = *(float *)ADDR(MEM32(tilemap + 12) + 0x1c);
+ *(float *)ADDR(corners[i] + 4) = (float)((double)eax * scale);
+ _st[7] = 0;
+ g_st_i64[7] = 0;
+ continue;
+ }
+ }
if (!(i & 1)) {
unsigned full_height = MEM8(ground + 0x29);
unsigned shift = MEM32(ground + 0x3c) & 31;
diff --git a/src/tests/tile_corners.c b/src/tests/tile_corners.c
@@ -8,6 +8,10 @@ void sub_38039DC0(void);
void sub_38039E60(void);
void sub_38039EC0(void);
+void sub_25040840(void);
+void sub_25040C80(void);
+void sub_25040CB0(void);
+
static unsigned patch_calls, raw_calls, height_calls;
static uint32_t patch_coordinates[2][2], raw_coordinates[2][2], height_coordinates[2][2];
@@ -55,6 +59,9 @@ recomp_func_t recomp_lookup(uint32_t address)
case 0x38039db0: return sub_38039DB0;
case 0x38039e60: return sub_38039E60;
case 0x38039ec0: return sub_38039EC0;
+ case 0x25040840: return sub_25040840;
+ case 0x25040c80: return sub_25040C80;
+ case 0x25040cb0: return sub_25040CB0;
case 0x500: return patch_handle;
case 0x504: return raw_height;
case 0x508: return height;
@@ -182,6 +189,40 @@ static void aliased_corner_rounding(void)
assert_preserved_state();
}
+static void resident_patch_boundary(unsigned full)
+{
+ arrange_tilemap();
+ MEM32(0x3804e24c) = 0x25040c80;
+ MEM32(0x3804e248) = 0x25040cb0;
+ MEM32(0x3804e244) = 0x25040840;
+ MEM8(0x5000a029) = full;
+ MEM32(0x5000a024) = 12345;
+ MEM32(0x5000a038) = 16;
+ MEM32(0x5000a048) = 2;
+ MEM32(0x5000a050) = 0x5000b000;
+ for (unsigned i = 0; i < 4; ++i)
+ MEM32(0x5000b000 + i * 84 + 0x1c) = 0x50010000 + i * 0x1000;
+ MEM16(0x5001021c) = 0x0102;
+ MEM16(0x500111fe) = 0x0304;
+ MEM16(0x50013000) = 0x0506;
+ MEM16(0x5001201e) = 0x0708;
+ MEM32(g_esp + 4) = 15;
+ MEM32(g_esp + 8) = 15;
+ const float expected8[] = {48.75f,.5f,48.75f, 52,1.5f,48.75f,
+ 52,2.5f,52, 48.75f,3.5f,52};
+ const float expected16[] = {48.75f,129,48.75f, 52,386,48.75f,
+ 52,643,52, 48.75f,900,52};
+
+ sub_38038370();
+
+ assert(!memcmp((void *)ADDR(0x5000f000), full ? expected16 : expected8, sizeof(expected8)));
+ for (unsigned i = 0; i < 4; ++i)
+ assert(MEM32(0x5000b000 + i * 84 + 0x18) == 12345);
+ assert((g_eax & 255) == 1);
+ assert(g_ecx == 0x5000f024);
+ assert_preserved_state();
+}
+
int main(void)
{
assert(guest_map("tilemap test", 0x50000000, 0x20000));
@@ -193,5 +234,7 @@ int main(void)
ground_16bit();
dungeon_heights();
aliased_corner_rounding();
+ resident_patch_boundary(0);
+ resident_patch_boundary(1);
puts("tile corner contracts passed");
}