From eccbc72cbea420298163f72b349f28f7622b7e3c Mon Sep 17 00:00:00 2001 From: Pepper0ni <93387759+Pepper0ni@users.noreply.github.com> Date: Thu, 24 Sep 2026 23:39:33 +0100 Subject: [PATCH] Fix and hookify full health on spawn (#7239) --- .../Difficulty/FullHealthSpawn.cpp | 20 +++++++++++++++++++ .../vanilla-behavior/GIVanillaBehavior.h | 8 ++++++++ soh/src/code/z_sram.c | 6 +++--- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 soh/soh/Enhancements/Difficulty/FullHealthSpawn.cpp diff --git a/soh/soh/Enhancements/Difficulty/FullHealthSpawn.cpp b/soh/soh/Enhancements/Difficulty/FullHealthSpawn.cpp new file mode 100644 index 0000000000..1240b678bd --- /dev/null +++ b/soh/soh/Enhancements/Difficulty/FullHealthSpawn.cpp @@ -0,0 +1,20 @@ +#include + +#include "soh/Enhancements/game-interactor/GameInteractor.h" +#include "soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h" +#include "soh/ShipInit.hpp" +#include "variables.h" + +#define CVAR_FULL_HEALTH_SPAWN_NAME CVAR_ENHANCEMENT("FullHealthSpawn") +#define CVAR_FULL_HEALTH_SPAWN_VALUE CVarGetInteger(CVAR_FULL_HEALTH_SPAWN_NAME, 0) + +static void RegisterFullhealthSpawn() { + COND_VB_SHOULD(VB_FULL_HEALTH_SPAWN, CVAR_FULL_HEALTH_SPAWN_VALUE, { + if (gSaveContext.health < gSaveContext.healthCapacity) { + gSaveContext.health = gSaveContext.healthCapacity; + } + *should = false; + }); +} + +static RegisterShipInitFunc initFunc(RegisterFullhealthSpawn, { CVAR_FULL_HEALTH_SPAWN_NAME }); \ No newline at end of file diff --git a/soh/soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h b/soh/soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h index f6275bd940..41e82e5853 100644 --- a/soh/soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h +++ b/soh/soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h @@ -926,6 +926,14 @@ typedef enum { // - `s32` (drop id) VB_FLEX_DROP_AMMO, + // #### `result` + // ```c + // gSaveContext.health < STARTING_HEALTH + // ``` + // #### `args` + // - None + VB_FULL_HEALTH_SPAWN, + // #### `result` // ```c // true diff --git a/soh/src/code/z_sram.c b/soh/src/code/z_sram.c index b9d828b816..1e0dffca60 100644 --- a/soh/src/code/z_sram.c +++ b/soh/src/code/z_sram.c @@ -1,4 +1,5 @@ #include "global.h" +#include "soh/Enhancements/game-interactor/vanilla-behavior/GIVanillaBehavior.h" #include "vt.h" #include @@ -147,9 +148,8 @@ void Sram_OpenSave() { osSyncPrintf("scene_no = %d\n", gSaveContext.entranceIndex); osSyncPrintf(VT_RST); - if (gSaveContext.health < STARTING_HEALTH) { - gSaveContext.health = - CVarGetInteger(CVAR_ENHANCEMENT("FullHealthSpawn"), 0) ? gSaveContext.healthCapacity : STARTING_HEALTH; + if (GameInteractor_Should(VB_FULL_HEALTH_SPAWN, gSaveContext.health < STARTING_HEALTH)) { + gSaveContext.health = STARTING_HEALTH; } if (gSaveContext.scarecrowLongSongSet) {