Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light Sensitivity Build (WIP) #4408

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
36 changes: 36 additions & 0 deletions soh/soh/Enhancements/accessibility/accessibility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "accessibility.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/OTRGlobals.h"

extern "C" {
#include <z64.h>
#include "macros.h"
#include "functions.h"
#include "variables.h"
extern SaveContext gSaveContext;
extern PlayState* gPlayState;
}

void RegisterLightSensitivityBehavior() {
static uint32_t shouldHookId1 = 0;
GameInteractor::Instance->UnregisterGameHookForID<GameInteractor::OnVanillaBehavior>(shouldHookId1);
shouldHookId1 = 0;

if (!CVarGetInteger(CVAR_SETTING("Lightsensitivity"), 0)) {
return;
}

shouldHookId1 = REGISTER_VB_SHOULD(VB_ALLOW_FLASHING_LIGHTS, {
if (!gPlayState) {
return;
}

// Requires Scene Change to update Storm Weather
if (gPlayState->envCtx.lightningMode != 0) {
gPlayState->envCtx.lightningMode = 0;
}

*should = false;
return;
});
}
9 changes: 9 additions & 0 deletions soh/soh/Enhancements/accessibility/accessibility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
typedef enum {
VISUALSTATE_RED,
VISUALSTATE_DEFAULT,
VISUALSTATE_DEFEATED,
VISUALSTATE_STUNNED = 4,
VISUALSTATE_HIT
};

void RegisterLightSensitivityBehavior();
4 changes: 4 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ typedef enum {
// Vanilla condition: Actor is ACTOR_EN_ELF, ACTOR_EN_FISH, ACTOR_EN_ICE_HONO, or ACTOR_EN_INSECT
// Opt: *Actor
VB_BOTTLE_ACTOR,

/*** Accessibility ***/
// Vanilla Condition: true
VB_ALLOW_FLASHING_LIGHTS,
} GIVanillaBehavior;

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ DEFINE_HOOK(OnFlagSet, (int16_t flagType, int16_t flag));
DEFINE_HOOK(OnFlagUnset, (int16_t flagType, int16_t flag));
DEFINE_HOOK(OnSceneSpawnActors, ());
DEFINE_HOOK(OnPlayerUpdate, ());
DEFINE_HOOK(OnPlayerHealthChange, ());
DEFINE_HOOK(OnOcarinaSongAction, ());
DEFINE_HOOK(OnShopSlotChange, (uint8_t cursorIndex, int16_t price));
DEFINE_HOOK(OnActorInit, (void* actor));
Expand Down
4 changes: 4 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ void GameInteractor_ExecuteOnPlayerUpdate() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayerUpdate>();
}

void GameInteractor_ExecuteOnPlayerHealthChange() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayerHealthChange>();
}

void GameInteractor_ExecuteOnOcarinaSongAction() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnOcarinaSongAction>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void GameInteractor_ExecuteOnFlagSet(int16_t flagType, int16_t flag);
void GameInteractor_ExecuteOnFlagUnset(int16_t flagType, int16_t flag);
void GameInteractor_ExecuteOnSceneSpawnActors();
void GameInteractor_ExecuteOnPlayerUpdate();
void GameInteractor_ExecuteOnPlayerHealthChange();
void GameInteractor_ExecuteOnOcarinaSongAction();
void GameInteractor_ExecuteOnActorInit(void* actor);
void GameInteractor_ExecuteOnActorUpdate(void* actor);
Expand Down
5 changes: 5 additions & 0 deletions soh/soh/Enhancements/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "objects/object_link_child/object_link_child.h"
#include "kaleido.h"

#include "soh/Enhancements/accessibility/accessibility.h"

extern "C" {
#include <z64.h>
#include "align_asset_macro.h"
Expand Down Expand Up @@ -1451,4 +1453,7 @@ void InitMods() {
RegisterHurtContainerModeHandler();
RegisterPauseMenuHooks();
RandoKaleido_RegisterHooks();

// Accessibility Mod Inits
RegisterLightSensitivityBehavior();
}
7 changes: 7 additions & 0 deletions soh/soh/SohMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include "Enhancements/resolution-editor/ResolutionEditor.h"
#include "Enhancements/enemyrandomizer.h"

#include "soh/Enhancements/accessibility/accessibility.h";

// FA icons are kind of wonky, if they worked how I expected them to the "+ 2.0f" wouldn't be needed, but
// they don't work how I expect them to so I added that because it looked good when I eyeballed it
#define FA_ICON_BUTTON_FRAME_PADDING_X(icon) (((optionsButtonSize.x - ImGui::CalcTextSize(icon).x) / 2) + 2.0f)
Expand Down Expand Up @@ -549,6 +551,11 @@ void DrawSettingsMenu() {
#endif
UIWidgets::PaddedEnhancementCheckbox("Disable Idle Camera Re-Centering", CVAR_SETTING("A11yDisableIdleCam"));
UIWidgets::Tooltip("Disables the automatic re-centering of the camera when idle.");

if (UIWidgets::PaddedEnhancementCheckbox("Enable Lightsensitivity Assistance", CVAR_SETTING("Lightsensitivity"))) {
RegisterLightSensitivityBehavior();
}
UIWidgets::Tooltip("Reduces effects that would cause impact to those sensitive to Light.");

ImGui::EndMenu();
}
Expand Down
11 changes: 7 additions & 4 deletions soh/src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3582,7 +3582,9 @@ Actor* Actor_Find(ActorContext* actorCtx, s32 actorId, s32 actorCategory) {
* While the screen flashes, the game freezes.
*/
void Enemy_StartFinishingBlow(PlayState* play, Actor* actor) {
play->actorCtx.freezeFlashTimer = 5;
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, true)) {
play->actorCtx.freezeFlashTimer = 5;
}
SoundSource_PlaySfxAtFixedWorldPos(play, &actor->world.pos, 20, NA_SE_EN_LAST_DAMAGE);
}

Expand Down Expand Up @@ -4171,9 +4173,10 @@ void Actor_SetColorFilter(Actor* actor, s16 colorFlag, s16 colorIntensityMax, s1
if ((colorFlag == 0x8000) && !(colorIntensityMax & 0x8000)) {
Audio_PlayActorSound2(actor, NA_SE_EN_LIGHT_ARROW_HIT);
}

actor->colorFilterParams = colorFlag | xluFlag | ((colorIntensityMax & 0xF8) << 5) | duration;
actor->colorFilterTimer = duration;
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, true)) {
actor->colorFilterParams = colorFlag | xluFlag | ((colorIntensityMax & 0xF8) << 5) | duration;
actor->colorFilterTimer = duration;
}
}

Hilite* func_800342EC(Vec3f* object, PlayState* play) {
Expand Down
28 changes: 15 additions & 13 deletions soh/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,8 @@ void BossDodongo_SetupInhale(BossDodongo* this) {

void BossDodongo_Damaged(BossDodongo* this, PlayState* play) {
SkelAnime_Update(&this->skelAnime);
Math_SmoothStepToF(&this->unk_1F8, 1.0f, 0.5f, 0.02f, 0.001f);
Math_SmoothStepToF(&this->unk_208, 0.05f, 1.0f, 0.005f, 0.0f);
//Math_SmoothStepToF(&this->unk_1F8, 1.0f, 0.5f, 0.02f, 0.001f);
//Math_SmoothStepToF(&this->unk_208, 0.05f, 1.0f, 0.005f, 0.0f);

if (Animation_OnFrame(&this->skelAnime, Animation_GetLastFrame(&object_kingdodongo_Anim_001074))) {
BossDodongo_SetupRoll(this);
Expand Down Expand Up @@ -1074,18 +1074,20 @@ void BossDodongo_Update(Actor* thisx, PlayState* play2) {
}

if (this->unk_1BE != 0) {
if (this->unk_1BE >= 1000) {
Math_SmoothStepToF(&this->colorFilterR, 30.0f, 1, 20.0f, 0.0);
Math_SmoothStepToF(&this->colorFilterG, 10.0f, 1, 20.0f, 0.0);
} else {
this->unk_1BE--;
Math_SmoothStepToF(&this->colorFilterR, 255.0f, 1, 20.0f, 0.0);
Math_SmoothStepToF(&this->colorFilterG, 0.0f, 1, 20.0f, 0.0);
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, true)) {
if (this->unk_1BE >= 1000) {
Math_SmoothStepToF(&this->colorFilterR, 30.0f, 1, 20.0f, 0.0);
Math_SmoothStepToF(&this->colorFilterG, 10.0f, 1, 20.0f, 0.0);
} else {
this->unk_1BE--;
Math_SmoothStepToF(&this->colorFilterR, 255.0f, 1, 20.0f, 0.0);
Math_SmoothStepToF(&this->colorFilterG, 0.0f, 1, 20.0f, 0.0);
}

Math_SmoothStepToF(&this->colorFilterB, 0.0f, 1, 20.0f, 0.0);
Math_SmoothStepToF(&this->colorFilterMin, 900.0f, 1, 10.0f, 0.0);
Math_SmoothStepToF(&this->colorFilterMax, 1099.0f, 1, 10.0f, 0.0);
}

Math_SmoothStepToF(&this->colorFilterB, 0.0f, 1, 20.0f, 0.0);
Math_SmoothStepToF(&this->colorFilterMin, 900.0f, 1, 10.0f, 0.0);
Math_SmoothStepToF(&this->colorFilterMax, 1099.0f, 1, 10.0f, 0.0);
} else {
Math_SmoothStepToF(&this->colorFilterR, play->lightCtx.fogColor[0], 1, 5.0f, 0.0);
Math_SmoothStepToF(&this->colorFilterG, play->lightCtx.fogColor[1], 1.0f, 5.0f, 0.0);
Expand Down
40 changes: 22 additions & 18 deletions soh/src/overlays/actors/ovl_Boss_Goma/z_boss_goma.c
Original file line number Diff line number Diff line change
Expand Up @@ -1878,24 +1878,26 @@ void BossGoma_UpdateMainEnvColor(BossGoma* this) {
{ 0.0f, 255.0f, 170.0f }, { 0.0f, 0.0f, 255.0f }, { 255.0f, 17.0f, 0.0f },
};

if (this->visualState == VISUALSTATE_DEFAULT && this->frameCount & 0x10) {
Math_ApproachF(&this->mainEnvColor[0], 50.0f, 0.5f, 20.0f);
Math_ApproachF(&this->mainEnvColor[1], 50.0f, 0.5f, 20.0f);
Math_ApproachF(&this->mainEnvColor[2], 50.0f, 0.5f, 20.0f);
} else if (this->invincibilityFrames != 0) {
if (this->invincibilityFrames & 2) {
this->mainEnvColor[0] = colors2[this->visualState][0];
this->mainEnvColor[1] = colors2[this->visualState][1];
this->mainEnvColor[2] = colors2[this->visualState][2];
} else {
this->mainEnvColor[0] = colors1[this->visualState][0];
this->mainEnvColor[1] = colors1[this->visualState][1];
this->mainEnvColor[2] = colors1[this->visualState][2];
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, true)) {
if (this->visualState == VISUALSTATE_DEFAULT && this->frameCount & 0x10) {
Math_ApproachF(&this->mainEnvColor[0], 50.0f, 0.5f, 20.0f);
Math_ApproachF(&this->mainEnvColor[1], 50.0f, 0.5f, 20.0f);
Math_ApproachF(&this->mainEnvColor[2], 50.0f, 0.5f, 20.0f);
} else if (this->invincibilityFrames != 0) {
if (this->invincibilityFrames & 2) {
this->mainEnvColor[0] = colors2[this->visualState][0];
this->mainEnvColor[1] = colors2[this->visualState][1];
this->mainEnvColor[2] = colors2[this->visualState][2];
} else {
this->mainEnvColor[0] = colors1[this->visualState][0];
this->mainEnvColor[1] = colors1[this->visualState][1];
this->mainEnvColor[2] = colors1[this->visualState][2];
}
}
} else {
Math_ApproachF(&this->mainEnvColor[0], colors1[this->visualState][0], 0.5f, 20.0f);
Math_ApproachF(&this->mainEnvColor[1], colors1[this->visualState][1], 0.5f, 20.0f);
Math_ApproachF(&this->mainEnvColor[2], colors1[this->visualState][2], 0.5f, 20.0f);
Math_ApproachF(&this->mainEnvColor[0], colors1[this->visualState][0], 0.5f, 20.0f);
Math_ApproachF(&this->mainEnvColor[1], colors1[this->visualState][1], 0.5f, 20.0f);
Math_ApproachF(&this->mainEnvColor[2], colors1[this->visualState][2], 0.5f, 20.0f);
}
}

Expand Down Expand Up @@ -1982,8 +1984,10 @@ s32 BossGoma_OverrideLimbDraw(PlayState* play, s32 limbIndex, Gfx** dList, Vec3f
if (this->eyeState == EYESTATE_IRIS_FOLLOW_BONUS_IFRAMES && this->eyeLidBottomRotX < -0xA8C) {
*dList = NULL;
} else if (this->invincibilityFrames != 0) {
gDPSetEnvColor(POLY_OPA_DISP++, (s16)(Rand_ZeroOne() * 255.0f), (s16)(Rand_ZeroOne() * 255.0f),
(s16)(Rand_ZeroOne() * 255.0f), 63);
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, true)) {
gDPSetEnvColor(POLY_OPA_DISP++, (s16)(Rand_ZeroOne() * 255.0f), (s16)(Rand_ZeroOne() * 255.0f),
(s16)(Rand_ZeroOne() * 255.0f), 63);
}
} else {
gDPSetEnvColor(POLY_OPA_DISP++, (s16)this->eyeEnvColor[0], (s16)this->eyeEnvColor[1],
(s16)this->eyeEnvColor[2], 63);
Expand Down
7 changes: 6 additions & 1 deletion soh/src/overlays/actors/ovl_En_Arrow/z_en_arrow.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "z_en_arrow.h"
#include "objects/gameplay_keep/gameplay_keep.h"
#include "objects/object_gi_nuts/object_gi_nuts.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"

#define FLAGS (ACTOR_FLAG_UPDATE_WHILE_CULLED | ACTOR_FLAG_DRAW_WHILE_CULLED)

Expand Down Expand Up @@ -315,7 +317,10 @@ void EnArrow_Fly(EnArrow* this, PlayState* play) {
}

if (this->actor.params == ARROW_NUT) {
iREG(50) = -1;
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, true)) {
iREG(50) = -1;
}

Actor_Spawn(&play->actorCtx, play, ACTOR_EN_M_FIRE1, this->actor.world.pos.x,
this->actor.world.pos.y, this->actor.world.pos.z, 0, 0, 0, 0, true);
sfxId = NA_SE_IT_DEKU;
Expand Down
11 changes: 7 additions & 4 deletions soh/src/overlays/actors/ovl_En_Bom/z_en_bom.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "overlays/effects/ovl_Effect_Ss_Dead_Sound/z_eff_ss_dead_sound.h"
#include "objects/gameplay_keep/gameplay_keep.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
#include <stdlib.h>

#define FLAGS (ACTOR_FLAG_UPDATE_WHILE_CULLED | ACTOR_FLAG_DRAW_WHILE_CULLED)
Expand Down Expand Up @@ -320,10 +321,12 @@ void EnBom_Update(Actor* thisx, PlayState* play2) {
this->flashSpeedScale >>= 1;
}

if ((this->timer < 100) && ((this->timer & (this->flashSpeedScale + 1)) != 0)) {
Math_SmoothStepToF(&this->flashIntensity, 140.0f, 1.0f, 140.0f / this->flashSpeedScale, 0.0f);
} else {
Math_SmoothStepToF(&this->flashIntensity, 0.0f, 1.0f, 140.0f / this->flashSpeedScale, 0.0f);
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, false)) {
if ((this->timer < 100) && ((this->timer & (this->flashSpeedScale + 1)) != 0)) {
Math_SmoothStepToF(&this->flashIntensity, 140.0f, 1.0f, 140.0f / this->flashSpeedScale, 0.0f);
} else {
Math_SmoothStepToF(&this->flashIntensity, 0.0f, 1.0f, 140.0f / this->flashSpeedScale, 0.0f);
}
}

if (this->timer < 3) {
Expand Down
31 changes: 17 additions & 14 deletions soh/src/overlays/actors/ovl_En_Bom_Chu/z_en_bom_chu.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "z_en_bom_chu.h"
#include "overlays/actors/ovl_En_Bom/z_en_bom.h"
#include "objects/gameplay_keep/gameplay_keep.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"

#define FLAGS ACTOR_FLAG_UPDATE_WHILE_CULLED

Expand Down Expand Up @@ -497,24 +499,25 @@ void EnBomChu_Draw(Actor* thisx, PlayState* play) {

Gfx_SetupDL_25Opa(play->state.gfxCtx);
func_8002EBCC(&this->actor, play, 0);
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, false)) {
if (this->timer >= 40) {
blinkTime = this->timer % 20;
blinkHalfPeriod = 10;
} else if (this->timer >= 10) {
blinkTime = this->timer % 10;
blinkHalfPeriod = 5;
} else {
blinkTime = this->timer & 1;
blinkHalfPeriod = 1;
}

if (this->timer >= 40) {
blinkTime = this->timer % 20;
blinkHalfPeriod = 10;
} else if (this->timer >= 10) {
blinkTime = this->timer % 10;
blinkHalfPeriod = 5;
} else {
blinkTime = this->timer & 1;
blinkHalfPeriod = 1;
}
if (blinkTime > blinkHalfPeriod) {
blinkTime = 2 * blinkHalfPeriod - blinkTime;
}

if (blinkTime > blinkHalfPeriod) {
blinkTime = 2 * blinkHalfPeriod - blinkTime;
colorIntensity = blinkTime / (f32)blinkHalfPeriod;
}

colorIntensity = blinkTime / (f32)blinkHalfPeriod;

if (CVarGetInteger(CVAR_COSMETIC("Equipment.ChuBody.Changed"), 0)) {
Color_RGB8 color = CVarGetColor24(CVAR_COSMETIC("Equipment.ChuBody.Value"), (Color_RGB8){ 209.0f, 34.0f, -35.0f });
gDPSetEnvColor(POLY_OPA_DISP++, (colorIntensity * color.r), (colorIntensity * color.g),
Expand Down
12 changes: 8 additions & 4 deletions soh/src/overlays/actors/ovl_En_Bombf/z_en_bombf.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "z_en_bombf.h"
#include "objects/object_bombf/object_bombf.h"
#include "overlays/effects/ovl_Effect_Ss_Dead_Sound/z_eff_ss_dead_sound.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"

#define FLAGS (ACTOR_FLAG_TARGETABLE | ACTOR_FLAG_UPDATE_WHILE_CULLED)

Expand Down Expand Up @@ -396,10 +398,12 @@ void EnBombf_Update(Actor* thisx, PlayState* play) {
this->flashSpeedScale >>= 1;
}

if ((this->timer < 100) && ((this->timer & (this->flashSpeedScale + 1)) != 0)) {
Math_SmoothStepToF(&this->flashIntensity, 150.0f, 1.0f, 150.0f / this->flashSpeedScale, 0.0f);
} else {
Math_SmoothStepToF(&this->flashIntensity, 0.0f, 1.0f, 150.0f / this->flashSpeedScale, 0.0f);
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, false)) {
if ((this->timer < 100) && ((this->timer & (this->flashSpeedScale + 1)) != 0)) {
Math_SmoothStepToF(&this->flashIntensity, 150.0f, 1.0f, 150.0f / this->flashSpeedScale, 0.0f);
} else {
Math_SmoothStepToF(&this->flashIntensity, 0.0f, 1.0f, 150.0f / this->flashSpeedScale, 0.0f);
}
}

if (this->timer < 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "z_en_okarina_effect.h"
#include "vt.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"

#define FLAGS (ACTOR_FLAG_UPDATE_WHILE_CULLED | ACTOR_FLAG_NO_FREEZE_OCARINA)

Expand Down Expand Up @@ -64,7 +66,9 @@ void EnOkarinaEffect_TriggerStorm(EnOkarinaEffect* this, PlayState* play) {
if ((gWeatherMode != 0) || play->envCtx.unk_17 != 0) {
play->envCtx.unk_DE = 1;
}
play->envCtx.lightningMode = LIGHTNING_MODE_ON;
if (GameInteractor_Should(VB_ALLOW_FLASHING_LIGHTS, true)) {
play->envCtx.lightningMode = LIGHTNING_MODE_ON;
}
Environment_PlayStormNatureAmbience(play);
EnOkarinaEffect_SetupAction(this, EnOkarinaEffect_ManageStorm);
}
Expand Down
Loading
Loading