From 4c4f6377f63d46e41ee9a091d608051813879386 Mon Sep 17 00:00:00 2001 From: Rainchus Date: Wed, 16 Apr 2025 01:46:00 -0500 Subject: [PATCH] fix some array definitions, fix invalid GX command, add AVOID_UB define and fix one UB instance --- CMakeLists.txt | 8 ++++---- src/REL/m413Dll/main.c | 13 ++++++------- src/REL/m455Dll/main.c | 2 +- src/REL/selmenuDll/main.c | 2 +- src/game/ClusterExec.c | 4 ++++ src/game/board/mushroom.c | 2 +- src/game/board/player.c | 2 +- src/game/minigame_seq.c | 2 +- src/game/sreset.c | 4 ++-- src/game/window.c | 5 +++++ 10 files changed, 26 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 51bc4561..dc5f51f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ elseif (MSVC) add_compile_options(/bigobj) endif () -add_compile_options(-fsanitize=address) +#add_compile_options(-fsanitize=address) add_subdirectory(extern/aurora EXCLUDE_FROM_ALL) add_subdirectory(extern/musyx EXCLUDE_FROM_ALL) @@ -148,7 +148,7 @@ endif () add_library(dol SHARED ${DOLPHIN_FILES} ${GAME_FILES} ${PORT_FILES}) -target_compile_definitions(dol PRIVATE TARGET_PC NON_MATCHING TARGET_DOL VERSION=${VERSION} MUSY_VERSION_MAJOR=1 MUSY_VERSION_MINOR=5 MUSY_VERSION_PATCH=4) +target_compile_definitions(dol PRIVATE TARGET_PC AVOID_UB NON_MATCHING TARGET_DOL VERSION=${VERSION} MUSY_VERSION_MAJOR=1 MUSY_VERSION_MINOR=5 MUSY_VERSION_PATCH=4) target_include_directories(dol PRIVATE include build/GMPE01_00/include) target_link_libraries(dol PRIVATE aurora::core aurora::gx aurora::si aurora::vi aurora::pad musyx) if (MSVC) @@ -164,7 +164,7 @@ else () endif () add_executable(marioparty4 src/port/portmain.c) -target_compile_definitions(marioparty4 PRIVATE TARGET_PC NON_MATCHING VERSION=${VERSION}) +target_compile_definitions(marioparty4 PRIVATE TARGET_PC AVOID_UB NON_MATCHING VERSION=${VERSION}) target_include_directories(marioparty4 PRIVATE include) target_link_libraries(marioparty4 PRIVATE dol aurora::main) @@ -183,7 +183,7 @@ foreach (dir ${REL_DIRS}) if (dir MATCHES "^w..Dll") target_sources(${dir} PRIVATE src/REL/board_executor.c) endif() - target_compile_definitions(${dir} PRIVATE TARGET_PC NON_MATCHING VERSION=${VERSION}) + target_compile_definitions(${dir} PRIVATE TARGET_PC AVOID_UB NON_MATCHING VERSION=${VERSION}) target_include_directories(${dir} PRIVATE include build/GMPE01_00/include) if (MSVC) set_target_properties(${dir} PROPERTIES LINK_FLAGS "/EXPORT:ObjectSetup") diff --git a/src/REL/m413Dll/main.c b/src/REL/m413Dll/main.c index 4325a00c..7a1fb9ac 100644 --- a/src/REL/m413Dll/main.c +++ b/src/REL/m413Dll/main.c @@ -468,12 +468,12 @@ void fn_1_10B8(Work19C8 *arg0) { s32 temp_r31; s32 temp_r30; - u8 sp16C[12][17] = {}; - u8 sp6C[12] = {}; + u8 sp16C[12][17] = {0}; + u8 sp6C[12] = {0}; s32 temp_r22 = (arg0->unk48[0]->unk18 - 4 < 0) ? 0 : (arg0->unk48[0]->unk18 - 4); s32 temp_r21 = (arg0->unk48[0]->unk18 + 4 > 11) ? 11 : (arg0->unk48[0]->unk18 + 4); - s32 sp44[2] = {}; - s32 sp3C[2] = {}; + s32 sp44[2] = {0}; + s32 sp3C[2] = {0}; s32 sp34[2] = { 9, 9 }; s32 temp_r20 = 0; s32 temp_r19 = 0; @@ -722,12 +722,11 @@ void fn_1_19C8(omObjData *object) HuSprAttrReset(temp_r31->unkA4, 0, HUSPR_ATTR_DISPOFF); HuSprAttrReset(temp_r31->unkA4, 0, HUSPR_ATTR_REVERSE); { - s32 sp258[12] = {}; + s32 sp258[12] = {0}; s32 sp194; for (sp194 = 0; sp194 < 3; sp194++) { StructBss2A6C *sp190; for (sp190 = lbl_1_bss_7884[sp194 + (temp_r31->unk10 * 3)]; sp190; sp190 = sp190->unk48) { - sp258[sp194] += (sp190 && sp190->unk0 && (sp190->unk1 & 0x2) == 0 && sp258[sp194] < 9); } } @@ -942,7 +941,7 @@ void fn_1_8AC8(StructBss2A6C *arg0, StructSp14C8 *arg1); void fn_1_52A4(s32 arg0) { omObjData *sp1EC = lbl_1_bss_30; - StructBss2A6C *sp2E48[14][19] = {}; + StructBss2A6C *sp2E48[14][19] = {NULL}; StructBss2A6C *sp1E8 = NULL; StructBss2A6C *temp_r31; StructBss2A6C *temp_r30; diff --git a/src/REL/m455Dll/main.c b/src/REL/m455Dll/main.c index ce3adb79..3b7af6c8 100644 --- a/src/REL/m455Dll/main.c +++ b/src/REL/m455Dll/main.c @@ -744,7 +744,7 @@ void fn_1_27A0(Vec *arg0, Vec *arg1, float arg2) arg1->z = fn_1_26F8(arg2, arg0[0].z, arg0[1].z, arg0[2].z, arg0[3].z); } -float lbl_1_data_184[2] = {}; +float lbl_1_data_184[2] = {0.0f, 0.0f}; void fn_1_2AF4(s32 arg0, s32 arg1, float arg2); diff --git a/src/REL/selmenuDll/main.c b/src/REL/selmenuDll/main.c index 02b9d40d..4cab5e56 100644 --- a/src/REL/selmenuDll/main.c +++ b/src/REL/selmenuDll/main.c @@ -133,7 +133,7 @@ static u16 keyDStkDown; static u16 btnDownAll[4]; static u16 keyDStkAll[4]; static u16 keyDStkAllDown[4]; -static u16 keyDStkAllPrev[4] = {}; +static u16 keyDStkAllPrev[4] = {0, 0, 0, 0}; static void SMInit(omObjData *object); static void SMRand8Tick(omObjData *object); diff --git a/src/game/ClusterExec.c b/src/game/ClusterExec.c index 7acb081c..c7f96a3e 100644 --- a/src/game/ClusterExec.c +++ b/src/game/ClusterExec.c @@ -154,7 +154,11 @@ void ClusterMotionExec(ModelData *arg0) HsfTrack *var_r30; MotionData *var_r23; +#ifdef AVOID_UB + //var_r31 = temp_r27->track; +#else var_r31 = temp_r27->track; +#endif for (i = 0; i < 4; i++) { if (arg0->unk_10[i] != -1) { var_r20 = arg0->unk_10[i]; diff --git a/src/game/board/mushroom.c b/src/game/board/mushroom.c index 81ad5e88..90e9efaa 100644 --- a/src/game/board/mushroom.c +++ b/src/game/board/mushroom.c @@ -27,7 +27,7 @@ static void MarkKillBox(void); static void InitBox(s32 arg0); static const float boxOfs[2] = {-150.0f, 150.0f}; -static omObjData *boxObj[2] = {}; +static omObjData *boxObj[2] = {NULL, NULL}; static s16 itemMdl = -1; static s8 itemResult; static u8 pickerChoice; diff --git a/src/game/board/player.c b/src/game/board/player.c index 2ac2680e..f791cbc2 100644 --- a/src/game/board/player.c +++ b/src/game/board/player.c @@ -185,7 +185,7 @@ static s32 boardSparkSfxTblAlt[] = { 0x2E3, }; -static omObjData *megaSquishObj[4] = {}; +static omObjData *megaSquishObj[4] = {NULL, NULL, NULL, NULL}; static s32 megaSquishSfxTbl[] = { 0x128, diff --git a/src/game/minigame_seq.c b/src/game/minigame_seq.c index 71fedf72..e74486ee 100644 --- a/src/game/minigame_seq.c +++ b/src/game/minigame_seq.c @@ -752,7 +752,7 @@ static char seqFontKanaTbl[] = { "アイウエオカキク" static char seqFontNumTbl[] = "0123456789"; -static s32 *letterBufTbl[5] = {}; +static s32 *letterBufTbl[5] = {NULL, NULL, NULL, NULL, NULL}; static char wordStartE[] = "START!"; diff --git a/src/game/sreset.c b/src/game/sreset.c index 10d49ef4..36b5810b 100644 --- a/src/game/sreset.c +++ b/src/game/sreset.c @@ -20,10 +20,10 @@ extern s32 HuDvdErrWait; -static s32 SR_PreRstChk[4] = {}; +static s32 SR_PreRstChk[4] = {0, 0, 0, 0}; #if VERSION_JP -static s32 padding[4] = {}; +static s32 padding[4] = {0, 0, 0, 0}; #endif #if VERSION_ENG diff --git a/src/game/window.c b/src/game/window.c index 8e8bacc0..43d56855 100644 --- a/src/game/window.c +++ b/src/game/window.c @@ -404,7 +404,12 @@ static void MesDispFunc(HuSprite *sprite) GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); +#ifdef TARGET_PC + GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); +#else + //@bug: this passes GX_CLR_RGB but then uses GX_RGBA8 (should use either alpha variants of both or neither) GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGB, GX_RGBA8, 0); +#endif GXSetCullMode(GX_CULL_NONE); GXSetNumTexGens(1); GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);