diff --git a/soh/soh/Enhancements/debugconsole.cpp b/soh/soh/Enhancements/debugconsole.cpp index 9f6847d9c..bea848d7f 100644 --- a/soh/soh/Enhancements/debugconsole.cpp +++ b/soh/soh/Enhancements/debugconsole.cpp @@ -4,6 +4,7 @@ #include "debugconsole.h" #include "../libultraship/ImGuiImpl.h" +#include "../libultraship/Utils.h" #include "savestates.h" #include "Console.h" @@ -36,7 +37,7 @@ extern GlobalContext* gGlobalCtx; uint32_t defenseModifier; uint32_t giantLink; uint32_t minishLink; -uint32_t highGravity; +uint32_t gravityLevel; uint32_t resetLinkScale; uint32_t noUi; uint32_t invisibleLink; @@ -90,7 +91,6 @@ static bool ActorSpawnHandler(std::shared_ptr Console, const std: return CMD_SUCCESS; } - static bool KillPlayerHandler(std::shared_ptr Console, const std::vector&) { gSaveContext.health = 0; SohImGui::console->SendInfoMessage("[SOH] You've met with a terrible fate, haven't you?"); @@ -123,7 +123,6 @@ static bool SetPlayerHealthHandler(std::shared_ptr Console, const return CMD_SUCCESS; } - static bool LoadSceneHandler(std::shared_ptr Console, const std::vector&) { gSaveContext.respawnFlag = 0; gSaveContext.seqId = 0xFF; @@ -387,19 +386,88 @@ static bool InvisibleHandler(std::shared_ptr Console, const std:: return CMD_FAILED; } - bool invisible; - try { - invisible = std::stoi(args[1], nullptr, 10); + invisibleLink = std::stoi(args[1], nullptr, 10) == 0 ? 0 : 1; + return CMD_SUCCESS; } catch (std::invalid_argument const& ex) { SohImGui::console->SendErrorMessage("[SOH] Invisible value must be a number."); return CMD_FAILED; } - - invisibleLink = invisible; +} + +static bool GiantLinkHandler(std::shared_ptr Console, const std::vector& args) { + if (args.size() != 2) { + SohImGui::console->SendErrorMessage("[SOH] Unexpected arguments passed"); + return CMD_FAILED; + } + + try { + giantLink = std::stoi(args[1], nullptr, 10) == 0 ? 0 : 1; + if (giantLink) + minishLink = 0; + else + resetLinkScale = 1; + + return CMD_SUCCESS; + } catch (std::invalid_argument const& ex) { + SohImGui::console->SendErrorMessage("[SOH] Giant value must be a number."); + return CMD_FAILED; + } +} + +static bool MinishLinkHandler(std::shared_ptr Console, const std::vector& args) { + if (args.size() != 2) { + SohImGui::console->SendErrorMessage("[SOH] Unexpected arguments passed"); + return CMD_FAILED; + } + + try { + resetLinkScale = 1; + minishLink = std::stoi(args[1], nullptr, 10) == 0 ? 0 : 1; + + if (minishLink) + giantLink = 0; + else + resetLinkScale = 1; + + return CMD_SUCCESS; + } catch (std::invalid_argument const& ex) { + SohImGui::console->SendErrorMessage("[SOH] Minish value must be a number."); + return CMD_FAILED; + } +} + +static bool AddHeartContainerHandler(std::shared_ptr Console, const std::vector& args) { + if (gSaveContext.healthCapacity >= 0x140) + return CMD_FAILED; + + gSaveContext.healthCapacity += 0x10; return CMD_SUCCESS; } +static bool RemoveHeartContainerHandler(std::shared_ptr Console, const std::vector& args) { + if ((gSaveContext.healthCapacity - 0x10) < 3) + return CMD_FAILED; + + gSaveContext.healthCapacity -= 0x10; + return CMD_SUCCESS; +} + +static bool GravityHandler(std::shared_ptr Console, const std::vector& args) { + if (args.size() != 2) { + SohImGui::console->SendErrorMessage("[SOH] Unexpected arguments passed"); + return CMD_FAILED; + } + + try { + gravityLevel = Ship::Math::clamp(std::stoi(args[1], nullptr, 10), 0.0f, 2.0f); + return CMD_SUCCESS; + } catch (std::invalid_argument const& ex) { + SohImGui::console->SendErrorMessage("[SOH] Minish value must be a number."); + return CMD_FAILED; + } +} + #define VARTYPE_INTEGER 0 #define VARTYPE_FLOAT 1 #define VARTYPE_STRING 2 @@ -460,7 +528,6 @@ static bool SetCVarHandler(std::shared_ptr Console, const std::ve return CMD_SUCCESS; } - static bool GetCVarHandler(std::shared_ptr Console, const std::vector& args) { if (args.size() < 2) return CMD_FAILED; @@ -546,8 +613,25 @@ void DebugConsole_Init(void) { { "Slot number", Ship::ArgumentType::NUMBER, } }}); - CMD_REGISTER("invisible", { InvisibleHandler, "Toggles invisibility.", { - { "invisible", Ship::ArgumentType::NUMBER } + // Console effects + CMD_REGISTER("invisible", { InvisibleHandler, "Activate Link's Elvish cloak, making him appear invisible.", { + { "value", Ship::ArgumentType::NUMBER } + }}); + + CMD_REGISTER("giant_link", { GiantLinkHandler, "Turn Link into a giant Lonky boi.", { + { "value", Ship::ArgumentType::NUMBER } + }}); + + CMD_REGISTER("minish_link", { MinishLinkHandler, "Turn Link into a minish boi.", { + { "value", Ship::ArgumentType::NUMBER } + }}); + + CMD_REGISTER("add_heart_container", { AddHeartContainerHandler, "Give Link a heart! The maximum amount of hearts is 20!" }); + + CMD_REGISTER("remove_heart_container", { RemoveHeartContainerHandler, "Remove a heart from Link. The minimal amount of hearts is 3." }); + + CMD_REGISTER("gravity", { GravityHandler, "Set gravity level.", { + { "value", Ship::ArgumentType::NUMBER } }}); CVar_Load(); diff --git a/soh/soh/Enhancements/debugconsole.h b/soh/soh/Enhancements/debugconsole.h index 22875dc43..d9f63f1a3 100644 --- a/soh/soh/Enhancements/debugconsole.h +++ b/soh/soh/Enhancements/debugconsole.h @@ -8,7 +8,7 @@ extern "C" { extern uint32_t defenseModifier; extern uint32_t giantLink; extern uint32_t minishLink; -extern uint32_t highGravity; +extern uint32_t gravityLevel; extern uint32_t resetLinkScale; extern uint32_t noUi; extern uint32_t invisibleLink; diff --git a/soh/src/code/z_play.c b/soh/src/code/z_play.c index 991a6306a..b67713087 100644 --- a/soh/src/code/z_play.c +++ b/soh/src/code/z_play.c @@ -1559,7 +1559,7 @@ void RemoveEffect(const char* effectId) { Player_SetBootData(gGlobalCtx, player); return; } else if (strcmp(effectId, "high_gravity") == 0 || strcmp(effectId, "low_gravity") == 0) { - highGravity = 0; + gravityLevel = 1; return; } else if (strcmp(effectId, "no_ui") == 0) { noUi = 0; @@ -1597,10 +1597,10 @@ u8 ExecuteEffect(const char* effectId, uint32_t value) { if (player != NULL && !Player_InBlockingCsMode(gGlobalCtx, player) && gGlobalCtx->pauseCtx.state == 0) { if (strcmp(effectId, "high_gravity") == 0) { - highGravity = 1; + gravityLevel = 2; return 1; } else if (strcmp(effectId, "low_gravity") == 0) { - highGravity = 2; + gravityLevel = 0; return 1; } else if (strcmp(effectId, "giant_link") == 0) { giantLink = 1; diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 95015cd9f..d28e188cc 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -11128,11 +11128,11 @@ void Player_Update(Actor* thisx, GlobalContext* globalCtx) { resetLinkScale = 0; } - if (highGravity == 1) { + if (gravityLevel == 2) { this->actor.gravity = -4.0f; } - if (highGravity == 2) { + if (gravityLevel == 0) { this->actor.gravity = -0.3f; } }