From 43a91b2b4b5147291e2108ce0e62fbaa5617601c Mon Sep 17 00:00:00 2001 From: GreaseMonkey Date: Tue, 29 Aug 2023 13:11:58 +1200 Subject: [PATCH] Fix "mpindex=4" UB cases for various view gadgets --- src/game/bondview.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/game/bondview.c b/src/game/bondview.c index 2b24a6516..2ced8b44f 100644 --- a/src/game/bondview.c +++ b/src/game/bondview.c @@ -1952,6 +1952,9 @@ Gfx *bviewDrawNvLens(Gfx *gdl) s32 viewbottom = viewtop + viewheight; s32 brightness; s32 y; +#ifdef AVOID_UB + u32 mpindex = g_Vars.currentplayerstats->mpindex % MAX_PLAYERS; +#endif var8007f840++; @@ -1973,9 +1976,15 @@ Gfx *bviewDrawNvLens(Gfx *gdl) skySetOverexposure(brightness, brightness, brightness); } +#ifdef AVOID_UB + if (g_Menus[mpindex].curdialog == NULL) { + gdl = bviewDrawMotionBlur(gdl, 0x00ff0000, 0x60); + } +#else if (g_Menus[g_Vars.currentplayerstats->mpindex].curdialog == NULL) { gdl = bviewDrawMotionBlur(gdl, 0x00ff0000, 0x60); } +#endif gDPPipeSync(gdl++); @@ -2034,6 +2043,9 @@ Gfx *bviewDrawIrLens(Gfx *gdl) s32 viewcentrey; f32 viewheightf; s32 a0; +#ifdef AVOID_UB + u32 mpindex = g_Vars.currentplayerstats->mpindex % MAX_PLAYERS; +#endif #if VERSION < VERSION_NTSC_1_0 static s32 fsscanline = 0; @@ -2198,9 +2210,15 @@ Gfx *bviewDrawIrLens(Gfx *gdl) #endif } +#ifdef AVOID_UB + if (g_Menus[mpindex].curdialog == NULL) { + gdl = bviewDrawMotionBlur(gdl, 0xff000000, 0x40); + } +#else if (g_Menus[g_Vars.currentplayerstats->mpindex].curdialog == NULL) { gdl = bviewDrawMotionBlur(gdl, 0xff000000, 0x40); } +#endif return gdl; }