Skip to content

Commit

Permalink
Use new hook instead of static variable for nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
Eblo committed Nov 26, 2024
1 parent e8e9013 commit 5ff6185
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 18 deletions.
46 changes: 36 additions & 10 deletions mm/2s2h/Enhancements/Masks/FierceDeityAnywhere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
#include "z64.h"
#include "overlays/actors/ovl_En_Bigokuta/z_en_bigokuta.h"
#include "overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.h"
#include "overlays/actors/ovl_En_Firefly/z_en_firefly.h"
#include "overlays/actors/ovl_En_Fz/z_en_fz.h"
#include "overlays/actors/ovl_En_Neo_Reeba/z_en_neo_reeba.h"

#define HIT_BY_SWORD_BEAM 1
#define NOT_HIT_BY_SWORD_BEAM 0

/*
* Stored to handle cases where the drawn actor is null (e.g. Leevers)
*/
static Actor* currentlyDrawnActor = nullptr;

void RegisterFierceDeityAnywhere() {
REGISTER_VB_SHOULD(VB_DISABLE_FD_MASK, {
if (CVarGetInteger("gEnhancements.Masks.FierceDeitysAnywhere", 0)) {
Expand Down Expand Up @@ -79,19 +77,47 @@ void RegisterFierceDeityAnywhere() {
});

/*
* Use a hook before an actor draws to store which actor is being drawn. Some actors call Actor_DrawDamageEffects()
* with a null actor (e.g. leevers), so we cannot just check the actor in the draw damage hook directly.
* Keese, Freezards, and Leevers are unique in that they call Actor_DrawDamageEffects() with NULL for the actor.
* Normally, that method only uses the actor for playing positional sound effects. For sword beams only, we
* overwrite these calls and pass in the actor so that the sword beam draws can be handled properly in the
* VB_DRAW_DAMAGE_EFFECT hook.
*/
GameInteractor::Instance->RegisterGameHook<GameInteractor::ShouldActorDraw>(
[](Actor* actor, bool* result) { currentlyDrawnActor = actor; });
REGISTER_VB_SHOULD(VB_USE_NULL_FOR_DRAW_DAMAGE_EFFECTS, {
if (CVarGetInteger("gEnhancements.Masks.FierceDeitysAnywhere", 0)) {
Actor* actor = va_arg(args, Actor*);
// Only change the call if there is a sword beam collision
if (actor->shape.face & HIT_BY_SWORD_BEAM) {
*should = false;
if (actor->id == ACTOR_EN_FIREFLY) { // Keese
EnFirefly* enFireFly = (EnFirefly*)actor;
Actor_DrawDamageEffects(gPlayState, actor, enFireFly->bodyPartsPos, KEESE_BODYPART_MAX,
enFireFly->drawDmgEffScale * actor->scale.y * 200.0f,
enFireFly->drawDmgEffFrozenSteamScale, enFireFly->drawDmgEffAlpha,
enFireFly->drawDmgEffType);
} else if (actor->id == ACTOR_EN_FZ) { // Freezard
EnFz* enFz = (EnFz*)actor;
Vec3f* bodyPartsPos = va_arg(args, Vec3f*);
Actor_DrawDamageEffects(gPlayState, actor, bodyPartsPos, ARRAY_COUNT(bodyPartsPos),
enFz->drawDmgEffScale * 4.0f, 0.5f, enFz->drawDmgEffAlpha,
ACTOR_DRAW_DMGEFF_LIGHT_ORBS);
} else if (actor->id == ACTOR_EN_NEO_REEBA) { // Leever
EnNeoReeba* enNeoReeba = (EnNeoReeba*)actor;
Actor_DrawDamageEffects(gPlayState, actor, enNeoReeba->bodyPartsPos, EN_NEO_REEBA_BODYPART_MAX,
enNeoReeba->drawEffectScale, 0.5f, enNeoReeba->drawEffectAlpha,
enNeoReeba->drawEffectType);
}
}
}
});

/*
* If we're drawing the light arrow damage effect, but we know it's from a sword beam, then quietly change the type
* to the blue lights effect.
*/
REGISTER_VB_SHOULD(VB_DRAW_DAMAGE_EFFECT, {
if (CVarGetInteger("gEnhancements.Masks.FierceDeitysAnywhere", 0)) {
if (currentlyDrawnActor->shape.face & HIT_BY_SWORD_BEAM) {
Actor* actor = va_arg(args, Actor*);
if (actor != nullptr && actor->shape.face & HIT_BY_SWORD_BEAM) {
u8* type = va_arg(args, u8*);
if (*type == ACTOR_DRAW_DMGEFF_LIGHT_ORBS) {
*type = ACTOR_DRAW_DMGEFF_BLUE_LIGHT_ORBS;
Expand Down
1 change: 1 addition & 0 deletions mm/2s2h/GameInteractor/GameInteractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ typedef enum {
VB_DAMAGE_MULTIPLIER,
VB_DAMAGE_EFFECT,
VB_DRAW_DAMAGE_EFFECT,
VB_USE_NULL_FOR_DRAW_DAMAGE_EFFECTS,
VB_CHECK_BUMPER_COLLISION,
VB_PLAY_HEART_CONTAINER_GET_FANFARE,
VB_BE_HOOKSHOT_SURFACE,
Expand Down
2 changes: 1 addition & 1 deletion mm/src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -5077,7 +5077,7 @@ TexturePtr sElectricSparkTextures[] = {
*/
void Actor_DrawDamageEffects(PlayState* play, Actor* actor, Vec3f bodyPartsPos[], s16 bodyPartsCount, f32 effectScale,
f32 frozenSteamScale, f32 effectAlpha, u8 type) {
if (!GameInteractor_Should(VB_DRAW_DAMAGE_EFFECT, true, &type)) {
if (!GameInteractor_Should(VB_DRAW_DAMAGE_EFFECT, true, actor, &type)) {
return;
}

Expand Down
9 changes: 6 additions & 3 deletions mm/src/overlays/actors/ovl_En_Firefly/z_en_firefly.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "z_en_firefly.h"
#include "overlays/actors/ovl_En_Clear_Tag/z_en_clear_tag.h"
#include "overlays/actors/ovl_Obj_Syokudai/z_obj_syokudai.h"
#include "2s2h/GameInteractor/GameInteractor.h"

#define FLAGS (ACTOR_FLAG_TARGETABLE | ACTOR_FLAG_UNFRIENDLY | ACTOR_FLAG_IGNORE_QUAKE | ACTOR_FLAG_4000)

Expand Down Expand Up @@ -844,9 +845,11 @@ void EnFirefly_Draw(Actor* thisx, PlayState* play) {
POLY_OPA_DISP = gfx;
}

Actor_DrawDamageEffects(play, NULL, this->bodyPartsPos, KEESE_BODYPART_MAX,
this->drawDmgEffScale * this->actor.scale.y * 200.0f, this->drawDmgEffFrozenSteamScale,
this->drawDmgEffAlpha, this->drawDmgEffType);
if (GameInteractor_Should(VB_USE_NULL_FOR_DRAW_DAMAGE_EFFECTS, true, this)) {
Actor_DrawDamageEffects(play, NULL, this->bodyPartsPos, KEESE_BODYPART_MAX,
this->drawDmgEffScale * this->actor.scale.y * 200.0f, this->drawDmgEffFrozenSteamScale,
this->drawDmgEffAlpha, this->drawDmgEffType);
}
this->lastDrawnFrame = play->gameplayFrames;

CLOSE_DISPS(play->state.gfxCtx);
Expand Down
7 changes: 5 additions & 2 deletions mm/src/overlays/actors/ovl_En_Fz/z_en_fz.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "objects/object_fz/object_fz.h"
#include "objects/gameplay_keep/gameplay_keep.h"
#include "2s2h/Enhancements/FrameInterpolation/FrameInterpolation.h"
#include "2s2h/GameInteractor/GameInteractor.h"

#define FLAGS (ACTOR_FLAG_TARGETABLE | ACTOR_FLAG_UNFRIENDLY | ACTOR_FLAG_10)

Expand Down Expand Up @@ -871,8 +872,10 @@ void EnFz_Draw(Actor* thisx, PlayState* play) {
bodyPartsPos[1] = this->actor.world.pos;
bodyPartsPos[0].y += 20.0f;
bodyPartsPos[1].y += 40.0f;
Actor_DrawDamageEffects(play, NULL, bodyPartsPos, ARRAY_COUNT(bodyPartsPos), this->drawDmgEffScale * 4.0f, 0.5f,
this->drawDmgEffAlpha, ACTOR_DRAW_DMGEFF_LIGHT_ORBS);
if (GameInteractor_Should(VB_USE_NULL_FOR_DRAW_DAMAGE_EFFECTS, true, this, bodyPartsPos)) {
Actor_DrawDamageEffects(play, NULL, bodyPartsPos, ARRAY_COUNT(bodyPartsPos), this->drawDmgEffScale * 4.0f,
0.5f, this->drawDmgEffAlpha, ACTOR_DRAW_DMGEFF_LIGHT_ORBS);
}
}

CLOSE_DISPS(play->state.gfxCtx);
Expand Down
7 changes: 5 additions & 2 deletions mm/src/overlays/actors/ovl_En_Neo_Reeba/z_en_neo_reeba.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "z_en_neo_reeba.h"
#include "objects/object_rb/object_rb.h"
#include "2s2h/GameInteractor/GameInteractor.h"

#define FLAGS (ACTOR_FLAG_TARGETABLE | ACTOR_FLAG_UNFRIENDLY | ACTOR_FLAG_200)

Expand Down Expand Up @@ -656,8 +657,10 @@ void EnNeoReeba_DrawEffects(EnNeoReeba* this, PlayState* play) {
}

this->bodyPartsPos[EN_NEO_REEBA_BODYPART_3] = this->actor.world.pos;
Actor_DrawDamageEffects(play, NULL, this->bodyPartsPos, EN_NEO_REEBA_BODYPART_MAX, this->drawEffectScale, 0.5f,
this->drawEffectAlpha, this->drawEffectType);
if (GameInteractor_Should(VB_USE_NULL_FOR_DRAW_DAMAGE_EFFECTS, true, this)) {
Actor_DrawDamageEffects(play, NULL, this->bodyPartsPos, EN_NEO_REEBA_BODYPART_MAX, this->drawEffectScale,
0.5f, this->drawEffectAlpha, this->drawEffectType);
}
}
}

Expand Down

0 comments on commit 5ff6185

Please sign in to comment.