From eace54325097b2e0363bf4589fc5cc87c8c80529 Mon Sep 17 00:00:00 2001 From: aMannus Date: Tue, 28 Mar 2023 13:06:03 +0200 Subject: [PATCH] Forced Hyper Bosses --- .../game-interactor/GameInteractor.h | 4 ++ .../game-interactor/GameInteractor_Hooks.cpp | 4 ++ .../game-interactor/GameInteractor_Hooks.h | 1 + .../GameInteractor_RawAction.cpp | 21 +++++++++ .../game-interactor/GameInteractor_State.cpp | 6 +++ soh/soh/Enhancements/mods.cpp | 45 +++++++++++++++++-- soh/src/code/z_actor.c | 2 + soh/src/code/z_collision_check.c | 35 +++++++++++++++ .../actors/ovl_Boss_Dodongo/z_boss_dodongo.c | 2 +- 9 files changed, 116 insertions(+), 4 deletions(-) diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor.h b/soh/soh/Enhancements/game-interactor/GameInteractor.h index a3e2b4c5c..7676c378d 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor.h @@ -34,6 +34,7 @@ uint8_t GameInteractor_ReverseControlsActive(); int32_t GameInteractor_DefenseModifier(); int32_t GameInteractor_RunSpeedModifier(); GIGravityLevel GameInteractor_GravityLevel(); +uint8_t GameInteractor_SecondCollisionUpdate(); #ifdef __cplusplus } #endif @@ -66,6 +67,7 @@ public: static int32_t DefenseModifier; static int32_t RunSpeedModifier; static GIGravityLevel GravityLevel; + static uint8_t SecondCollisionUpdate; static void SetPacifistMode(bool active); }; @@ -90,6 +92,7 @@ public: DEFINE_HOOK(OnReceiveItem, void(u8 item)); DEFINE_HOOK(OnSceneInit, void(s16 sceneNum)); DEFINE_HOOK(OnPlayerUpdate, void()); + DEFINE_HOOK(OnActorUpdate, void(void* actor)); DEFINE_HOOK(OnSaveFile, void(int32_t fileNum)); DEFINE_HOOK(OnLoadFile, void(int32_t fileNum)); @@ -116,6 +119,7 @@ public: static void GiveDekuShield(); static void SpawnCuccoStorm(); static void ForceInterfaceUpdate(); + static void UpdateActor(void* refActor); static GameInteractionEffectQueryResult SpawnEnemyWithOffset(uint32_t enemyId, int32_t enemyParams); }; diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp index 2ed4758e9..eb1132c74 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp @@ -30,6 +30,10 @@ void GameInteractor_ExecuteOnPlayerUpdate() { GameInteractor::Instance->ExecuteHooks(); } +void GameInteractor_ExecuteOnActorUpdate(void* actor) { + GameInteractor::Instance->ExecuteHooks(actor); +} + // MARK: - Save Files void GameInteractor_ExecuteOnSaveFile(int32_t fileNum) { diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h index 658ca05d4..d50b98f9b 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h @@ -7,6 +7,7 @@ extern "C" void GameInteractor_ExecuteOnGameFrameUpdate(); extern "C" void GameInteractor_ExecuteOnReceiveItemHooks(u8 item); extern "C" void GameInteractor_ExecuteOnSceneInit(s16 sceneNum); extern "C" void GameInteractor_ExecuteOnPlayerUpdate(); +extern "C" void GameInteractor_ExecuteOnActorUpdate(void* actor); // MARK: - Save Files extern "C" void GameInteractor_ExecuteOnSaveFile(int32_t fileNum); diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp b/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp index 2409347ea..e4f66662c 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp @@ -142,6 +142,27 @@ void GameInteractor::RawAction::ForceInterfaceUpdate() { Interface_Update(gPlayState); } +void GameInteractor::RawAction::UpdateActor(void* refActor) { + // Update actor again outside of their normal update cycle. + + Actor* actor = static_cast(refActor); + + // Sometimes the actor is destroyed in the previous Update, so check if the update function still exists. + if (actor->update != NULL) { + // Fix for enemies sometimes taking a "fake" hit, where their invincibility timer is + // reset but damage isn't applied. + if (actor->colorFilterTimer > 0) { + actor->colorFilterTimer--; + } + + // This variable is used to not let the collider subscribe a second time when the actor update function + // is ran a second time, incorrectly applying double damage in some cases. + GameInteractor::State::SecondCollisionUpdate = 1; + actor->update(actor, gPlayState); + GameInteractor::State::SecondCollisionUpdate = 0; + } +} + GameInteractionEffectQueryResult GameInteractor::RawAction::SpawnEnemyWithOffset(uint32_t enemyId, int32_t enemyParams) { if (!GameInteractor::CanSpawnEnemy()) { diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_State.cpp b/soh/soh/Enhancements/game-interactor/GameInteractor_State.cpp index 23222bb4b..ccf48dfb4 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_State.cpp +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_State.cpp @@ -12,6 +12,7 @@ bool GameInteractor::State::ReverseControlsActive = 0; int32_t GameInteractor::State::DefenseModifier = 0; int32_t GameInteractor::State::RunSpeedModifier = 0; GIGravityLevel GameInteractor::State::GravityLevel = GI_GRAVITY_LEVEL_NORMAL; +uint8_t GameInteractor::State::SecondCollisionUpdate = 0; void GameInteractor::State::SetPacifistMode(bool active) { PacifistModeActive = active; @@ -79,3 +80,8 @@ int32_t GameInteractor_RunSpeedModifier() { GIGravityLevel GameInteractor_GravityLevel() { return GameInteractor::State::GravityLevel; } + +// MARK: - GameInteractor::State::SecondCollisionUpdate +uint8_t GameInteractor_SecondCollisionUpdate() { + return GameInteractor::State::SecondCollisionUpdate; +} diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index c7bf6350b..7b32c7197 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -6,11 +6,9 @@ extern "C" { #include #include "macros.h" #include "variables.h" +#include "functions.h" extern SaveContext gSaveContext; extern PlayState* gPlayState; -extern void Play_PerformSave(PlayState* play); -extern s32 Health_ChangeBy(PlayState* play, s16 healthChange); -extern void Rupees_ChangeBy(s16 rupeeChange); } void RegisterInfiniteMoney() { @@ -257,6 +255,46 @@ void RegisterRupeeDash() { }); } +void RegisterHyperBosses() { + GameInteractor::Instance->RegisterGameHook([](void* refActor) { + // Run the update function a second time to make bosses move and act twice as fast. + + Player* player = GET_PLAYER(gPlayState); + Actor* actor = static_cast(refActor); + + uint8_t isBossActor = + actor->id == ACTOR_BOSS_GOMA || // Gohma + actor->id == ACTOR_BOSS_DODONGO || // King Dodongo + actor->id == ACTOR_BOSS_VA || // Barinade + actor->id == ACTOR_BOSS_GANONDROF || // Phantom Ganon + (actor->id == 0 && actor->category == ACTORCAT_BOSS) || // Phantom Ganon/Ganondorf Energy Ball/Thunder + actor->id == ACTOR_EN_FHG || // Phantom Ganon's Horse + actor->id == ACTOR_BOSS_FD || actor->id == ACTOR_BOSS_FD2 || // Volvagia (grounded/flying) + actor->id == ACTOR_BOSS_MO || // Morpha + actor->id == ACTOR_BOSS_SST || // Bongo Bongo + actor->id == ACTOR_BOSS_TW || // Twinrova + actor->id == ACTOR_BOSS_GANON || // Ganondorf + actor->id == ACTOR_BOSS_GANON2; // Ganon + + // Don't apply during cutscenes because it causes weird behaviour and/or crashes on some bosses. + if (isBossActor && !Player_InBlockingCsMode(gPlayState, player)) { + // Barinade needs to be updated in sequence to avoid unintended behaviour. + if (actor->id == ACTOR_BOSS_VA) { + // params -1 is BOSSVA_BODY + if (actor->params == -1) { + Actor* actorList = gPlayState->actorCtx.actorLists[ACTORCAT_BOSS].head; + while (actorList != NULL) { + GameInteractor::RawAction::UpdateActor(actorList); + actorList = actorList->next; + } + } + } else { + GameInteractor::RawAction::UpdateActor(actor); + } + } + }); +} + void InitMods() { RegisterInfiniteMoney(); RegisterInfiniteHealth(); @@ -270,4 +308,5 @@ void InitMods() { RegisterSwitchAge(); RegisterRupeeDash(); RegisterAutoSave(); + RegisterHyperBosses(); } diff --git a/soh/src/code/z_actor.c b/soh/src/code/z_actor.c index 5a4010dda..825f03363 100644 --- a/soh/src/code/z_actor.c +++ b/soh/src/code/z_actor.c @@ -8,6 +8,7 @@ #include "objects/object_bdoor/object_bdoor.h" #include "soh/frame_interpolation.h" #include "soh/Enhancements/enemyrandomizer.h" +#include "soh/Enhancements/game-interactor/GameInteractor.h" #if defined(_MSC_VER) || defined(__GNUC__) #include @@ -2595,6 +2596,7 @@ void Actor_UpdateAll(PlayState* play, ActorContext* actorCtx) { actor->colorFilterTimer--; } actor->update(actor, play); + GameInteractor_ExecuteOnActorUpdate(actor, play); func_8003F8EC(play, &play->colCtx.dyna, actor); } diff --git a/soh/src/code/z_collision_check.c b/soh/src/code/z_collision_check.c index c27f35d6d..785e68836 100644 --- a/soh/src/code/z_collision_check.c +++ b/soh/src/code/z_collision_check.c @@ -1,6 +1,7 @@ #include "global.h" #include "vt.h" #include "overlays/effects/ovl_Effect_Ss_HitMark/z_eff_ss_hitmark.h" +#include "soh/Enhancements/game-interactor/GameInteractor.h" typedef s32 (*ColChkResetFunc)(PlayState*, Collider*); typedef void (*ColChkBloodFunc)(PlayState*, Collider*, Vec3f*); @@ -1177,6 +1178,10 @@ static ColChkResetFunc sATResetFuncs[] = { s32 CollisionCheck_SetAT(PlayState* play, CollisionCheckContext* colChkCtx, Collider* collider) { s32 index; + if (GameInteractor_SecondCollisionUpdate()) { + return -1; + } + if (FrameAdvance_IsEnabled(play) == true) { return -1; } @@ -1206,9 +1211,15 @@ s32 CollisionCheck_SetAT(PlayState* play, CollisionCheckContext* colChkCtx, Coll s32 CollisionCheck_SetAT_SAC(PlayState* play, CollisionCheckContext* colChkCtx, Collider* collider, s32 index) { ASSERT(collider->shape <= COLSHAPE_QUAD); + + if (GameInteractor_SecondCollisionUpdate()) { + return -1; + } + if (FrameAdvance_IsEnabled(play) == true) { return -1; } + sATResetFuncs[collider->shape](play, collider); if (collider->actor != NULL && collider->actor->update == NULL) { return -1; @@ -1246,6 +1257,10 @@ static ColChkResetFunc sACResetFuncs[] = { s32 CollisionCheck_SetAC(PlayState* play, CollisionCheckContext* colChkCtx, Collider* collider) { s32 index; + if (GameInteractor_SecondCollisionUpdate()) { + return -1; + } + if (FrameAdvance_IsEnabled(play) == true) { return -1; } @@ -1275,9 +1290,15 @@ s32 CollisionCheck_SetAC(PlayState* play, CollisionCheckContext* colChkCtx, Coll s32 CollisionCheck_SetAC_SAC(PlayState* play, CollisionCheckContext* colChkCtx, Collider* collider, s32 index) { ASSERT(collider->shape <= COLSHAPE_QUAD); + + if (GameInteractor_SecondCollisionUpdate()) { + return -1; + } + if (FrameAdvance_IsEnabled(play) == true) { return -1; } + sACResetFuncs[collider->shape](play, collider); if (collider->actor != NULL && collider->actor->update == NULL) { return -1; @@ -1315,6 +1336,10 @@ static ColChkResetFunc sOCResetFuncs[] = { s32 CollisionCheck_SetOC(PlayState* play, CollisionCheckContext* colChkCtx, Collider* collider) { s32 index; + if (GameInteractor_SecondCollisionUpdate()) { + return -1; + } + if (FrameAdvance_IsEnabled(play) == true) { return -1; } @@ -1345,9 +1370,15 @@ s32 CollisionCheck_SetOC(PlayState* play, CollisionCheckContext* colChkCtx, Coll */ s32 CollisionCheck_SetOC_SAC(PlayState* play, CollisionCheckContext* colChkCtx, Collider* collider, s32 index) { + + if (GameInteractor_SecondCollisionUpdate()) { + return -1; + } + if (FrameAdvance_IsEnabled(play) == true) { return -1; } + ASSERT(collider->shape <= COLSHAPE_QUAD); sOCResetFuncs[collider->shape](play, collider); if (collider->actor != NULL && collider->actor->update == NULL) { @@ -1380,6 +1411,10 @@ s32 CollisionCheck_SetOC_SAC(PlayState* play, CollisionCheckContext* colChkCtx, s32 CollisionCheck_SetOCLine(PlayState* play, CollisionCheckContext* colChkCtx, OcLine* collider) { s32 index; + if (GameInteractor_SecondCollisionUpdate()) { + return -1; + } + if (FrameAdvance_IsEnabled(play) == true) { return -1; } diff --git a/soh/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c b/soh/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c index 63896bc92..255b0034f 100644 --- a/soh/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c +++ b/soh/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c @@ -35,7 +35,7 @@ void BossDodongo_DrawEffects(PlayState* play); void BossDodongo_UpdateEffects(PlayState* play); const ActorInit Boss_Dodongo_InitVars = { - ACTOR_EN_DODONGO, + ACTOR_BOSS_DODONGO, ACTORCAT_BOSS, FLAGS, OBJECT_KINGDODONGO,