From 4f29833476817a91b40da1177d2815e775f91537 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Sun, 31 Jul 2022 21:52:10 -0400 Subject: [PATCH] Adds beta quest Gameshark cheat. (#975) * Adds beta quest Gameshark cheat. * Fixes issue where lus was including a function from soh. * Limits beta quest to 0-8 --- libultraship/libultraship/ImGuiImpl.cpp | 79 +++++++++++++++++++++++++ libultraship/libultraship/ImGuiImpl.h | 12 ++++ soh/src/code/z_common_data.c | 2 +- soh/src/code/z_play.c | 4 +- 4 files changed, 95 insertions(+), 2 deletions(-) diff --git a/libultraship/libultraship/ImGuiImpl.cpp b/libultraship/libultraship/ImGuiImpl.cpp index ea779b677..e01026b10 100644 --- a/libultraship/libultraship/ImGuiImpl.cpp +++ b/libultraship/libultraship/ImGuiImpl.cpp @@ -68,6 +68,13 @@ OSContPad* pads; std::map DefaultAssets; std::vector emptyArgs; +bool isBetaQuestEnabled = false; + +extern "C" { + void enableBetaQuest() { isBetaQuestEnabled = true; } + void disableBetaQuest() { isBetaQuestEnabled = false; } +} + namespace SohImGui { WindowImpl impl; @@ -1404,6 +1411,78 @@ namespace SohImGui { EnhancementCheckbox("Shield with Two-Handed Weapons", "gShieldTwoHanded"); Tooltip("This allows you to put up your shield with any two-handed weapon in hand except for Deku Sticks"); + { + static int32_t betaQuestEnabled = CVar_GetS32("gEnableBetaQuest", 0); + static int32_t lastBetaQuestEnabled = betaQuestEnabled; + static int32_t betaQuestWorld = CVar_GetS32("gBetaQuestWorld", 0xFFEF); + static int32_t lastBetaQuestWorld = betaQuestWorld; + + if (!isBetaQuestEnabled) { + ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); + ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); + } + + EnhancementCheckbox("Enable Beta Quest", "gEnableBetaQuest"); + Tooltip("Turns on OoT Beta Quest. *WARNING* This will reset your game."); + betaQuestEnabled = CVar_GetS32("gEnableBetaQuest", 0); + if (betaQuestEnabled) { + if (betaQuestEnabled != lastBetaQuestEnabled) { + betaQuestWorld = 0; + } + + ImGui::Text("Beta Quest World: %d", betaQuestWorld); + + if (ImGui::Button(" - ##BetaQuest")) { + betaQuestWorld--; + } + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7.0f); + + ImGui::SliderInt("##BetaQuest", &betaQuestWorld, 0, 8, "", ImGuiSliderFlags_AlwaysClamp); + Tooltip("Set the Beta Quest world to explore. *WARNING* Changing this will reset your game.\nCtrl+Click to type in a value."); + + ImGui::Text("After Slider Beta Quest World: %d", betaQuestWorld); + + + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() - 7.0f); + if (ImGui::Button(" + ##BetaQuest")) { + betaQuestWorld++; + } + + if (betaQuestWorld > 8) { + betaQuestWorld = 8; + } + else if (betaQuestWorld < 0) { + betaQuestWorld = 0; + } + + ImGui::Text("After Clamp Beta Quest World: %d", betaQuestWorld); + } + else { + lastBetaQuestWorld = betaQuestWorld = 0xFFEF; + CVar_SetS32("gBetaQuestWorld", betaQuestWorld); + needs_save = true; + } + if (betaQuestEnabled != lastBetaQuestEnabled || betaQuestWorld != lastBetaQuestWorld) + { + // Reset the game if the beta quest state or world changed because beta quest happens on redirecting the title screen cutscene. + lastBetaQuestEnabled = betaQuestEnabled; + lastBetaQuestWorld = betaQuestWorld; + CVar_SetS32("gEnableBetaQuest", betaQuestEnabled); + CVar_SetS32("gBetaQuestWorld", betaQuestWorld); + + console->Commands["reset"].handler(emptyArgs); + + needs_save = true; + } + + if (!isBetaQuestEnabled) { + ImGui::PopItemFlag(); + ImGui::PopStyleVar(); + } + } + ImGui::EndMenu(); } diff --git a/libultraship/libultraship/ImGuiImpl.h b/libultraship/libultraship/ImGuiImpl.h index eb007efeb..01235d411 100644 --- a/libultraship/libultraship/ImGuiImpl.h +++ b/libultraship/libultraship/ImGuiImpl.h @@ -1,5 +1,15 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + void enableBetaQuest(); + void disableBetaQuest(); +#ifdef __cplusplus +} +#endif + +#ifdef __cplusplus #include "GameOverlay.h" #include "Lib/ImGui/imgui.h" #include "Console.h" @@ -97,3 +107,5 @@ namespace SohImGui { std::string BreakTooltip(const char* text, int lineLength = 60); std::string BreakTooltip(const std::string& text, int lineLength = 60); } + +#endif \ No newline at end of file diff --git a/soh/src/code/z_common_data.c b/soh/src/code/z_common_data.c index c92a36b71..53334fb84 100644 --- a/soh/src/code/z_common_data.c +++ b/soh/src/code/z_common_data.c @@ -8,7 +8,7 @@ void SaveContext_Init(void) { gSaveContext.seqId = (u8)NA_BGM_DISABLED; gSaveContext.natureAmbienceId = NATURE_ID_DISABLED; gSaveContext.forcedSeqId = NA_BGM_GENERAL_SFX; - gSaveContext.nextCutsceneIndex = 0xFFEF; + gSaveContext.nextCutsceneIndex = CVar_GetS32("gBetaQuestWorld", 0xFFEF); gSaveContext.cutsceneTrigger = 0; gSaveContext.chamberCutsceneNum = 0; gSaveContext.nextDayTime = 0xFFFF; diff --git a/soh/src/code/z_play.c b/soh/src/code/z_play.c index 5656f4c07..763ed1ee8 100644 --- a/soh/src/code/z_play.c +++ b/soh/src/code/z_play.c @@ -4,7 +4,7 @@ #include #include "soh/Enhancements/gameconsole.h" - +#include "../libultraship/ImGuiImpl.h" #include "soh/frame_interpolation.h" void* D_8012D1F0 = NULL; @@ -190,6 +190,7 @@ void Gameplay_Destroy(GameState* thisx) { KaleidoManager_Destroy(); ZeldaArena_Cleanup(); Fault_RemoveClient(&D_801614B8); + disableBetaQuest(); gGlobalCtx = NULL; } @@ -260,6 +261,7 @@ void GivePlayerRandoRewardSariaGift(GlobalContext* globalCtx, RandomizerCheck ch void Gameplay_Init(GameState* thisx) { GlobalContext* globalCtx = (GlobalContext*)thisx; GraphicsContext* gfxCtx = globalCtx->state.gfxCtx; + enableBetaQuest(); gGlobalCtx = globalCtx; //globalCtx->state.gfxCtx = NULL; uintptr_t zAlloc;