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

[Enhancement] Custom Zora Egg Count #624

Merged
merged 10 commits into from
Aug 24, 2024
2 changes: 2 additions & 0 deletions mm/2s2h/BenGui/BenMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,8 @@ void DrawEnhancementsMenu() {
UIWidgets::CVarCheckbox("Pause Owl Warp", "gEnhancements.Songs.PauseOwlWarp",
{ .tooltip = "Allows the player to use the pause menu map to owl warp instead of "
"having to play the Song of Soaring." });
UIWidgets::CVarSliderInt("Zora Eggs For Bossa Nova", "gEnhancements.Songs.ZoraEggCount", 1, 7, 7,
{ .tooltip = "The number of eggs required to unlock new wave bossa nova." });

ImGui::EndMenu();
}
Expand Down
1 change: 1 addition & 0 deletions mm/2s2h/Enhancements/Enhancements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void InitEnhancements() {
// Songs
RegisterEnableSunsSong();
RegisterPauseOwlWarp();
RegisterZoraEggCount();

// Restorations
RegisterPowerCrouchStab();
Expand Down
1 change: 1 addition & 0 deletions mm/2s2h/Enhancements/Enhancements.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "Player/Player.h"
#include "Songs/EnableSunsSong.h"
#include "Songs/PauseOwlWarp.h"
#include "Songs/ZoraEggCount.h"
#include "Saving/SavingEnhancements.h"
#include "Graphics/DisableBlackBars.h"
#include "Modes/TimeMovesWhenYouMove.h"
Expand Down
38 changes: 38 additions & 0 deletions mm/2s2h/Enhancements/Songs/ZoraEggCount.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "ZoraEggCount.h"
#include <libultraship/bridge.h>
#include "Enhancements/GameInteractor/GameInteractor.h"

extern "C" {
#include "src/overlays/actors/ovl_En_Mk/z_en_mk.h"
}

const uint32_t MAX_EGGS = 7;

void RegisterZoraEggCount() {
// marine researcher, his actor update call is more consistent than the eggs
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::OnActorInit>(ACTOR_EN_MK, [](Actor* outerActor) {
static uint32_t enMkUpdateHook = 0;
static uint32_t enMkKillHook = 0;
GameInteractor::Instance->UnregisterGameHookForPtr<GameInteractor::OnActorUpdate>(enMkUpdateHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnSceneInit>(enMkKillHook);
enMkUpdateHook = 0;
enMkKillHook = 0;

enMkUpdateHook = GameInteractor::Instance->RegisterGameHookForPtr<GameInteractor::OnActorUpdate>(
(uintptr_t)outerActor, [](Actor* actor) {
// complete quest if you have enough eggs
if (gSaveContext.save.saveInfo.permanentSceneFlags[SCENE_LABO].unk_14 != MAX_EGGS &&
CVarGetInteger("gEnhancements.Songs.ZoraEggCount", MAX_EGGS) <=
gSaveContext.save.saveInfo.permanentSceneFlags[SCENE_LABO].unk_14) {
gSaveContext.save.saveInfo.permanentSceneFlags[SCENE_LABO].unk_14 = MAX_EGGS;
}
});
enMkKillHook =
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnSceneInit>([](s8 sceneId, s8 spawnNum) {
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnActorUpdate>(enMkUpdateHook);
GameInteractor::Instance->UnregisterGameHook<GameInteractor::OnSceneInit>(enMkKillHook);
enMkUpdateHook = 0;
enMkKillHook = 0;
});
});
}
6 changes: 6 additions & 0 deletions mm/2s2h/Enhancements/Songs/ZoraEggCount.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef VARIABLE_ZORA_EGG_COUNT_H
#define VARIABLE_ZORA_EGG_COUNT_H

void RegisterZoraEggCount();

#endif // VARIABLE_ZORA_EGG_COUNT_H