From b66623c152d24df78fb5ea699e5206a20eafe037 Mon Sep 17 00:00:00 2001 From: Archez Date: Fri, 28 Mar 2025 04:30:56 -0400 Subject: [PATCH] Fix freezard graphics crash with enemy health scaling (#5232) --- soh/src/overlays/actors/ovl_En_Fz/z_en_fz.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/soh/src/overlays/actors/ovl_En_Fz/z_en_fz.c b/soh/src/overlays/actors/ovl_En_Fz/z_en_fz.c index 8aaab1631..3f843446d 100644 --- a/soh/src/overlays/actors/ovl_En_Fz/z_en_fz.c +++ b/soh/src/overlays/actors/ovl_En_Fz/z_en_fz.c @@ -720,6 +720,15 @@ void EnFz_Draw(Actor* thisx, PlayState* play) { index = (6 - this->actor.colChkInfo.health) >> 1; + // SOH [Enhancement] - With enemy health scaling, the Freezards health could cause an index out of bounds for the + // displayLists, so we need to recompute the index based on the scaled health (using the maximum health value) and + // clamp the final result for safety. + if (CVarGetInteger(CVAR_ENHANCEMENT("EnemySizeScalesHealth"), 0)) { + u8 scaledHealth = (u8)(((f32)this->actor.colChkInfo.health / this->actor.maximumHealth) * 6); + index = (6 - scaledHealth) >> 1; + index = CLAMP(index, 0, 2); + } + OPEN_DISPS(play->state.gfxCtx); if (this->actor.colChkInfo.health == 0) {