From d7d9a39c7402f11fedd304dfffecf47ee7c96884 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Mon, 8 Sep 2025 01:56:32 -0400 Subject: [PATCH] Disable map model transform tagging temporarily, begin work on prop transform tagging --- patches/map_transform_tagging.c | 10 ++- ...n_patches.c => marker_extension_patches.c} | 0 patches/prop_extension_patches.c | 85 +++++++++++++++++++ patches/syms.ld | 1 + src/game/recomp_api.cpp | 7 ++ 5 files changed, 99 insertions(+), 4 deletions(-) rename patches/{object_extension_patches.c => marker_extension_patches.c} (100%) create mode 100644 patches/prop_extension_patches.c diff --git a/patches/map_transform_tagging.c b/patches/map_transform_tagging.c index 303bc75..6f2d541 100644 --- a/patches/map_transform_tagging.c +++ b/patches/map_transform_tagging.c @@ -157,8 +157,9 @@ RECOMP_PATCH void mapModel_opa_draw(Gfx **gfx, Mtx **mtx, Vtx **vtx) { } modelRender_setEnvColor(mapModel.env_red, mapModel.env_green, mapModel.env_blue, 0xFF); - // @recomp Set the map opaque model transform id. - cur_drawn_model_transform_id = MAP_MODEL_OPA_TRANSFORM_ID_START; + // TODO improve modelbin rendering to prevent culling and sorting from causing interpolation glitches. + // // @recomp Set the map opaque model transform id. + // cur_drawn_model_transform_id = MAP_MODEL_OPA_TRANSFORM_ID_START; modelRender_draw(gfx, mtx, NULL, NULL, mapModel.description->scale, NULL, mapModel.model_bin_opa); @@ -186,8 +187,9 @@ RECOMP_PATCH void mapModel_xlu_draw(Gfx **gfx, Mtx **mtx, Vtx **vtx) { } modelRender_setEnvColor(mapModel.env_red, mapModel.env_green, mapModel.env_blue, 0xFF); - // @recomp Set the map opaque model transform id. - cur_drawn_model_transform_id = MAP_MODEL_XLU_TRANSFORM_ID_START; + // TODO improve modelbin rendering to prevent culling and sorting from causing interpolation glitches. + // // @recomp Set the map opaque model transform id. + // cur_drawn_model_transform_id = MAP_MODEL_XLU_TRANSFORM_ID_START; modelRender_draw(gfx, mtx, NULL, NULL, mapModel.description->scale, NULL, mapModel.model_bin_xlu); diff --git a/patches/object_extension_patches.c b/patches/marker_extension_patches.c similarity index 100% rename from patches/object_extension_patches.c rename to patches/marker_extension_patches.c diff --git a/patches/prop_extension_patches.c b/patches/prop_extension_patches.c new file mode 100644 index 0000000..c7bc2e5 --- /dev/null +++ b/patches/prop_extension_patches.c @@ -0,0 +1,85 @@ +#include "patches.h" +#include "prop.h" +#include "actor.h" +#include "functions.h" +#include "object_extension_funcs.h" +#include "bk_api.h" +#include "core2/coords.h" + +// Max props per cube, limited by cube->prop2Cnt which is only 6 bits. +#define CUBE_MAX_PROPS 63 +// Hardcoded cube limit, TODO implement a better solution that doesn't involve dedicating this much memory and allows for larger cube counts. +#define MAX_CUBES 4000 +u32 prop_handles[MAX_CUBES][CUBE_MAX_PROPS]; + +void vtxList_getBounds_s32(BKVertexList *, s32[3], s32[3]); +enum map_e map_get(void); + +extern struct { + Cube *cubes; + f32 margin; + s32 min[3]; + s32 max[3]; + s32 stride[2]; + s32 cubeCnt; + s32 unk2C; + s32 width[3]; + Cube *unk3C; // fallback cube? + Cube *unk40; // some other fallback cube? + s32 unk44; // index of some sort +} sCubeList; + +typedef struct { + s16 map_id; //enum map_e + s16 opa_model_id; //enum asset_e level_model_id + s16 xlu_model_id; //enum asset_e level2_model_id + s16 unk6[3]; // min bounds (for cubes?) + s16 unkC[3]; // max bounds (for cubes?) + // u8 pad12[0x2]; + f32 scale; +}MapModelDescription; + +extern struct { + void *unk0; + void *unk4; + BKCollisionList *collision_opa; + BKCollisionList *collision_xlu; + BKModel *model_opa; + BKModel *model_xlu; + BKModelBin *model_bin_opa; + BKModelBin *model_bin_xlu; + s32 unk20; + struct5Bs *unk24; + MapModelDescription *description; + u8 env_red; + u8 env_green; + u8 env_blue; + f32 scale; +}mapModel; + +void recomp_abort(const char* msg); + +// @recomp Patched to verify the cube count is less than the fixed amount. +RECOMP_PATCH void mapModel_getCubeBounds(s32 min[3], s32 max[3]) { + vtxList_getBounds_s32(model_getVtxList(mapModel.model_bin_opa), min, max); + coords_scale(min, max, 1000); + min[0] = min[0] + mapModel.description->unk6[0]; + min[1] = min[1] + mapModel.description->unk6[1]; + min[2] = min[2] + mapModel.description->unk6[2]; + max[0] = max[0] + mapModel.description->unkC[0]; + max[1] = max[1] + mapModel.description->unkC[1]; + max[2] = max[2] + mapModel.description->unkC[2]; + + // @recomp Calculate and validate the cube count. + u32 width0 = max[0] - min[0] + 1; + u32 width1 = max[1] - min[1] + 1; + u32 width2 = max[2] - min[2] + 1; + u32 stride0 = width0; + u32 stride1 = stride0 * width1; + u32 cubeCnt = stride1 * width2; + + recomp_printf("Cube count for map %d: %u\n", map_get(), cubeCnt); + if (cubeCnt > MAX_CUBES) { + recomp_abort("Cube count too high\n"); + } +} diff --git a/patches/syms.ld b/patches/syms.ld index 997b588..96bb9a1 100644 --- a/patches/syms.ld +++ b/patches/syms.ld @@ -33,3 +33,4 @@ __umoddi3_recomp = 0x8F000070; strlen_recomp = 0x8F000074; osVirtualToPhysical_recomp = 0x8F000078; osPiStartDma_recomp = 0x8F00007C; +recomp_abort = 0x8F000080; diff --git a/src/game/recomp_api.cpp b/src/game/recomp_api.cpp index 182ac0c..04f6343 100644 --- a/src/game/recomp_api.cpp +++ b/src/game/recomp_api.cpp @@ -212,3 +212,10 @@ extern "C" void recomp_load_overlays_by_rom(uint8_t* rdram, recomp_context* ctx) load_overlays(rom_addr, ram_addr, size); } + +extern "C" void recomp_abort(uint8_t* rdram, recomp_context* ctx) { + std::string msg = _arg_string<0>(rdram, ctx); + recompui::message_box(msg.c_str()); + assert(false); + ultramodern::error_handling::quick_exit(__FILE__, __LINE__, __FUNCTION__); +}