Skip to content

Commit

Permalink
Migrate enhancements to ShipInit pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjoecox committed Nov 29, 2024
1 parent 3917e3b commit 44f0306
Show file tree
Hide file tree
Showing 58 changed files with 1,011 additions and 1,213 deletions.
50 changes: 18 additions & 32 deletions mm/2s2h/BenGui/BenMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <unordered_map>
#include <string>
#include "2s2h/Enhancements/Enhancements.h"
#include "2s2h/Enhancements/Graphics/Graphics.h"
#include "2s2h/Enhancements/GfxPatcher/AuthenticGfxPatches.h"
#include "2s2h/DeveloperTools/DeveloperTools.h"
#include "HudEditor.h"
Expand Down Expand Up @@ -649,10 +650,8 @@ void DrawEnhancementsMenu() {
"model and texture on the boot logo start screen" });
UIWidgets::CVarCheckbox("Bow Reticle", "gEnhancements.Graphics.BowReticle",
{ .tooltip = "Gives the bow a reticle when you draw an arrow" });
if (UIWidgets::CVarCheckbox("3D Item Drops", "gEnhancements.Graphics.3DItemDrops",
{ .tooltip = "Makes item drops 3D" })) {
Register3DItemDrops();
}
UIWidgets::CVarCheckbox("3D Item Drops", "gEnhancements.Graphics.3DItemDrops",
{ .tooltip = "Makes item drops 3D" });
UIWidgets::CVarCheckbox(
"Disable Black Bar Letterboxes", "gEnhancements.Graphics.DisableBlackBars",
{ .tooltip = "Disables Black Bar Letterboxes during cutscenes and Z-targeting\nNote: there may be "
Expand Down Expand Up @@ -686,11 +685,9 @@ void DrawEnhancementsMenu() {
UIWidgets::CVarCheckbox("Fierce Deity's Mask Anywhere", "gEnhancements.Masks.FierceDeitysAnywhere",
{ .tooltip = "Allow using Fierce Deity's mask outside of boss rooms." });
UIWidgets::CVarCheckbox("No Blast Mask Cooldown", "gEnhancements.Masks.NoBlastMaskCooldown", {});
if (UIWidgets::CVarCheckbox("Persistent Bunny Hood", "gEnhancements.Masks.PersistentBunnyHood.Enabled",
{ .tooltip = "Permanently toggle a speed boost from the bunny hood by pressing "
"'A' on it in the mask menu." })) {
UpdatePersistentMasksState();
}
UIWidgets::CVarCheckbox("Persistent Bunny Hood", "gEnhancements.Masks.PersistentBunnyHood.Enabled",
{ .tooltip = "Permanently toggle a speed boost from the bunny hood by pressing "
"'A' on it in the mask menu." });

ImGui::EndMenu();
}
Expand All @@ -717,9 +714,7 @@ void DrawEnhancementsMenu() {
UIWidgets::CVarCheckbox("Hyrule Warriors Young Link", "gModes.HyruleWarriorsStyledLink",
{ .tooltip = "When acquired, places the Keaton and Fierce Deity masks on Link "
"similarly to how he wears them in Hyrule Warriors" });
if (UIWidgets::CVarCheckbox("Time Moves When You Move", "gModes.TimeMovesWhenYouMove")) {
RegisterTimeMovesWhenYouMove();
}
UIWidgets::CVarCheckbox("Time Moves When You Move", "gModes.TimeMovesWhenYouMove");
if (UIWidgets::CVarCheckbox("Mirrored World", "gModes.MirroredWorld.Mode")) {
if (CVarGetInteger("gModes.MirroredWorld.Mode", 0)) {
CVarSetInteger("gModes.MirroredWorld.State", 1);
Expand All @@ -734,12 +729,9 @@ void DrawEnhancementsMenu() {
if (UIWidgets::BeginMenu("Player")) {
UIWidgets::CVarSliderInt("Climb speed", "gEnhancements.Player.ClimbSpeed", 1, 5, 1,
{ .tooltip = "Increases the speed at which Link climbs vines and ladders." });
if (UIWidgets::CVarCheckbox("Fast Deku Flower Launch", "gEnhancements.Player.FastFlowerLaunch",
{ .tooltip =
"Speeds up the time it takes to be able to get maximum height from "
"launching out of a deku flower" })) {
RegisterFastFlowerLaunch();
}
UIWidgets::CVarCheckbox("Fast Deku Flower Launch", "gEnhancements.Player.FastFlowerLaunch",
{ .tooltip = "Speeds up the time it takes to be able to get maximum height from "
"launching out of a deku flower" });
UIWidgets::CVarCheckbox("Instant Putaway", "gEnhancements.Player.InstantPutaway",
{ .tooltip = "Allows Link to instantly puts away held item without waiting." });
UIWidgets::CVarCheckbox("Fierce Deity Putaway", "gEnhancements.Player.FierceDeityPutaway",
Expand Down Expand Up @@ -793,11 +785,9 @@ void DrawEnhancementsMenu() {
}

if (UIWidgets::BeginMenu("Difficulty Options")) {
if (UIWidgets::CVarCheckbox("Disable Takkuri Steal", "gEnhancements.Cheats.DisableTakkuriSteal",
{ .tooltip = "Prevents the Takkuri from stealing key items like bottles and "
"swords. It may still steal other items." })) {
RegisterDisableTakkuriSteal();
}
UIWidgets::CVarCheckbox("Disable Takkuri Steal", "gEnhancements.Cheats.DisableTakkuriSteal",
{ .tooltip = "Prevents the Takkuri from stealing key items like bottles and "
"swords. It may still steal other items." });

UIWidgets::CVarCombobox(
"Deku Guard Search Balls", "gEnhancements.Cheats.DekuGuardSearchBalls", dekuGuardSearchBallsOptions,
Expand Down Expand Up @@ -833,21 +823,17 @@ void DrawCheatsMenu() {
UIWidgets::CVarCheckbox("Infinite Magic", "gCheats.InfiniteMagic");
UIWidgets::CVarCheckbox("Infinite Rupees", "gCheats.InfiniteRupees");
UIWidgets::CVarCheckbox("Infinite Consumables", "gCheats.InfiniteConsumables");
if (UIWidgets::CVarCheckbox(
"Longer Deku Flower Glide", "gCheats.LongerFlowerGlide",
{ .tooltip = "Allows Deku Link to glide longer, no longer dropping after a certain distance" })) {
RegisterLongerFlowerGlide();
}
UIWidgets::CVarCheckbox(
"Longer Deku Flower Glide", "gCheats.LongerFlowerGlide",
{ .tooltip = "Allows Deku Link to glide longer, no longer dropping after a certain distance" });
UIWidgets::CVarCheckbox("No Clip", "gCheats.NoClip");
UIWidgets::CVarCheckbox("Unbreakable Razor Sword", "gCheats.UnbreakableRazorSword");
UIWidgets::CVarCheckbox("Unrestricted Items", "gCheats.UnrestrictedItems");
UIWidgets::CVarCheckbox("Hookshot Anywhere", "gCheats.HookshotAnywhere",
{ .tooltip = "Allows most surfaces to be hookshot-able" });

if (UIWidgets::CVarCheckbox("Moon Jump on L", "gCheats.MoonJumpOnL",
{ .tooltip = "Holding L makes you float into the air" })) {
RegisterMoonJumpOnL();
}
UIWidgets::CVarCheckbox("Moon Jump on L", "gCheats.MoonJumpOnL",
{ .tooltip = "Holding L makes you float into the air" });
UIWidgets::CVarCheckbox("Elegy of Emptiness Anywhere", "gCheats.ElegyAnywhere",
{ .tooltip = "Allows Elegy of Emptiness outside of Ikana" });
UIWidgets::CVarCombobox(
Expand Down
59 changes: 15 additions & 44 deletions mm/2s2h/BenGui/SearchableMenuItems.h
Original file line number Diff line number Diff line change
Expand Up @@ -1014,25 +1014,18 @@ void AddEnhancements() {
{ "Infinite Rupees", "gCheats.InfiniteRupees", "Always have a full Wallet.", WIDGET_CVAR_CHECKBOX, {} },
{ "Infinite Consumables", "gCheats.InfiniteConsumables",
"Always have max Consumables, you must have collected the consumables first.", WIDGET_CVAR_CHECKBOX },
{ "Longer Deku Flower Glide",
"gCheats.LongerFlowerGlide",
{ "Longer Deku Flower Glide", "gCheats.LongerFlowerGlide",
"Allows Deku Link to glide longer, no longer dropping after a certain distance.",
WIDGET_CVAR_CHECKBOX,
{},
[](widgetInfo& info) { RegisterLongerFlowerGlide(); } },
WIDGET_CVAR_CHECKBOX },
{ "No Clip", "gCheats.NoClip", "Allows Link to phase through collision.", WIDGET_CVAR_CHECKBOX },
{ "Unbreakable Razor Sword", "gCheats.UnbreakableRazorSword",
"Allows to Razor Sword to be used indefinitely without dulling its blade.", WIDGET_CVAR_CHECKBOX },
{ "Unrestricted Items", "gCheats.UnrestrictedItems", "Allows all Forms to use all Items.",
WIDGET_CVAR_CHECKBOX },
{ "Hookshot Anywhere", "gCheats.HookshotAnywhere", "Allows most surfaces to be hookshot-able",
WIDGET_CVAR_CHECKBOX },
{ "Moon Jump on L",
"gCheats.MoonJumpOnL",
"Holding L makes you float into the air.",
WIDGET_CVAR_CHECKBOX,
{},
[](widgetInfo& info) { RegisterMoonJumpOnL(); } },
{ "Moon Jump on L", "gCheats.MoonJumpOnL", "Holding L makes you float into the air.",
WIDGET_CVAR_CHECKBOX },
{ "Elegy of Emptiness Anywhere", "gCheats.ElegyAnywhere", "Allows Elegy of Emptiness outside of Ikana",
WIDGET_CVAR_CHECKBOX },
{ "Stop Time in Dungeons",
Expand All @@ -1049,12 +1042,9 @@ void AddEnhancements() {
{ "Gameplay",
3,
{ { { .widgetName = "Player", .widgetType = WIDGET_SEPARATOR_TEXT },
{ "Fast Deku Flower Launch",
"gEnhancements.Player.FastFlowerLaunch",
{ "Fast Deku Flower Launch", "gEnhancements.Player.FastFlowerLaunch",
"Speeds up the time it takes to be able to get maximum height from launching out of a deku flower",
WIDGET_CVAR_CHECKBOX,
{},
([](widgetInfo& info) { RegisterFastFlowerLaunch(); }) },
WIDGET_CVAR_CHECKBOX },
{ "Instant Putaway", "gEnhancements.Player.InstantPutaway",
"Allows Link to instantly puts away held item without waiting.", WIDGET_CVAR_CHECKBOX },
{ "Fierce Deity Putaway", "gEnhancements.Player.FierceDeityPutaway",
Expand Down Expand Up @@ -1103,12 +1093,8 @@ void AddEnhancements() {
"When acquired, places the Keaton and Fierce Deity masks on Link similarly to how he wears them in "
"Hyrule Warriors",
WIDGET_CVAR_CHECKBOX },
{ "Time Moves when you Move",
"gModes.TimeMovesWhenYouMove",
"Time only moves when Link is not standing still.",
WIDGET_CVAR_CHECKBOX,
{},
([](widgetInfo& info) { RegisterTimeMovesWhenYouMove(); }) },
{ "Time Moves when you Move", "gModes.TimeMovesWhenYouMove",
"Time only moves when Link is not standing still.", WIDGET_CVAR_CHECKBOX },
{ "Mirrored World",
"gModes.MirroredWorld.Mode",
"Mirrors the world horizontally.",
Expand Down Expand Up @@ -1241,12 +1227,7 @@ void AddEnhancements() {
disabledMap.at(DISABLE_FOR_MOTION_BLUR_OFF).active;
} },
{ .widgetName = "Other", .widgetType = WIDGET_SEPARATOR_TEXT },
{ "3D Item Drops",
"gEnhancements.Graphics.3DItemDrops",
"Makes item drops 3D",
WIDGET_CVAR_CHECKBOX,
{},
[](widgetInfo& info) { Register3DItemDrops(); } },
{ "3D Item Drops", "gEnhancements.Graphics.3DItemDrops", "Makes item drops 3D", WIDGET_CVAR_CHECKBOX },
{ "Authentic Logo", "gEnhancements.Graphics.AuthenticLogo",
"Hide the game version and build details and display the authentic "
"model and texture on the boot logo start screen",
Expand Down Expand Up @@ -1291,13 +1272,10 @@ void AddEnhancements() {
"Removes the delay when using transformation masks.", WIDGET_CVAR_CHECKBOX },
{ "Fierce Deity's Mask Anywhere", "gEnhancements.Masks.FierceDeitysAnywhere",
"Allow using Fierce Deity's mask outside of boss rooms.", WIDGET_CVAR_CHECKBOX },
{ "Persistent Bunny Hood",
"gEnhancements.Masks.PersistentBunnyHood.Enabled",
{ "Persistent Bunny Hood", "gEnhancements.Masks.PersistentBunnyHood.Enabled",
"Permanently toggle a speed boost from the bunny hood by pressing "
"'A' on it in the mask menu.",
WIDGET_CVAR_CHECKBOX,
{},
[](widgetInfo& info) { UpdatePersistentMasksState(); } },
WIDGET_CVAR_CHECKBOX },
{ "No Blast Mask Cooldown", "gEnhancements.Masks.NoBlastMaskCooldown",
"Eliminates the Cooldown between Blast Mask usage.", WIDGET_CVAR_CHECKBOX } },
// Song Enhancements
Expand All @@ -1322,12 +1300,8 @@ void AddEnhancements() {
"Prevent dropping inputs when playing the ocarina quickly.", WIDGET_CVAR_CHECKBOX },
{ "Skip Scarecrow Song", "gEnhancements.Playback.SkipScarecrowSong",
"Pierre appears when the Ocarina is pulled out.", WIDGET_CVAR_CHECKBOX },
{ "Faster Song Playback",
"gEnhancements.Songs.FasterSongPlayback",
"Speeds up the playback of songs.",
WIDGET_CVAR_CHECKBOX,
{},
[](widgetInfo& info) { RegisterFasterSongPlayback(); } } } } });
{ "Faster Song Playback", "gEnhancements.Songs.FasterSongPlayback", "Speeds up the playback of songs.",
WIDGET_CVAR_CHECKBOX } } } });
enhancementsSidebar.push_back(
{ "Time Savers",
3,
Expand Down Expand Up @@ -1423,12 +1397,9 @@ void AddEnhancements() {
enhancementsSidebar.push_back(
{ "Difficulty Options",
3,
{ { { "Disable Takkuri Steal",
"gEnhancements.Cheats.DisableTakkuriSteal",
{ { { "Disable Takkuri Steal", "gEnhancements.Cheats.DisableTakkuriSteal",
"Prevents the Takkuri from stealing key items like bottles and swords. It may still steal other items.",
WIDGET_CVAR_CHECKBOX,
{},
[](widgetInfo& info) { RegisterDisableTakkuriSteal(); } },
WIDGET_CVAR_CHECKBOX },
{ "Deku Guard Search Balls",
"gEnhancements.Cheats.DekuGuardSearchBalls",
"Choose when to show the Deku Palace Guards' search balls\n"
Expand Down
13 changes: 0 additions & 13 deletions mm/2s2h/Enhancements/Cheats/Cheats.h

This file was deleted.

12 changes: 7 additions & 5 deletions mm/2s2h/Enhancements/Cheats/ElegyAnywhere.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <libultraship/bridge.h>
#include "2s2h/GameInteractor/GameInteractor.h"
#include "2s2h/ShipInit.hpp"

#define CVAR_NAME "gCheats.ElegyAnywhere"
#define CVAR CVarGetInteger(CVAR_NAME, 0)

void RegisterElegyAnywhere() {
REGISTER_VB_SHOULD(VB_ELEGY_CHECK_SCENE, {
if (CVarGetInteger("gCheats.ElegyAnywhere", 0)) {
*should = true;
}
});
COND_VB_SHOULD(VB_ELEGY_CHECK_SCENE, CVAR, { *should = true; });
}

static RegisterShipInitFunc initFunc(RegisterElegyAnywhere, { CVAR_NAME });
14 changes: 8 additions & 6 deletions mm/2s2h/Enhancements/Cheats/HookshotAnywhere.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <libultraship/bridge.h>
#include "GameInteractor/GameInteractor.h"
#include "2s2h/GameInteractor/GameInteractor.h"
#include "2s2h/ShipInit.hpp"

#define CVAR_NAME "gCheats.HookshotAnywhere"
#define CVAR CVarGetInteger(CVAR_NAME, 0)

void RegisterHookshotAnywhere() {
REGISTER_VB_SHOULD(VB_BE_HOOKSHOT_SURFACE, {
if (CVarGetInteger("gCheats.HookshotAnywhere", 0)) {
*should = true;
}
});
COND_VB_SHOULD(VB_BE_HOOKSHOT_SURFACE, CVAR, { *should = true; });
}

static RegisterShipInitFunc initFunc(RegisterHookshotAnywhere, { CVAR_NAME });
44 changes: 28 additions & 16 deletions mm/2s2h/Enhancements/Cheats/Infinite.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
#include <libultraship/bridge.h>
#include "2s2h/GameInteractor/GameInteractor.h"
#include "variables.h"
#include "2s2h/ShipInit.hpp"

void RegisterInfiniteCheats() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnGameStateUpdate>([]() {
if (gPlayState == nullptr)
return;
extern "C" {
#include "variables.h"
}

if (CVarGetInteger("gCheats.InfiniteHealth", 0)) {
static RegisterShipInitFunc healthInitFunc(
[]() {
COND_HOOK(OnGameStateUpdate, CVarGetInteger("gCheats.InfiniteHealth", 0), []() {
gSaveContext.save.saveInfo.playerData.health = gSaveContext.save.saveInfo.playerData.healthCapacity;
}
});
},
{ "gCheats.InfiniteHealth" });

if (CVarGetInteger("gCheats.InfiniteMagic", 0)) {
static RegisterShipInitFunc magicInitFunc(
[]() {
COND_HOOK(OnGameStateUpdate, CVarGetInteger("gCheats.InfiniteMagic", 0), []() {
uint8_t magicLevel = gSaveContext.save.saveInfo.playerData.magicLevel;
if (magicLevel == 1) {
gSaveContext.save.saveInfo.playerData.magic = MAGIC_NORMAL_METER;
} else if (magicLevel == 2) {
gSaveContext.save.saveInfo.playerData.magic = MAGIC_DOUBLE_METER;
}
}
});
},
{ "gCheats.InfiniteMagic" });

if (CVarGetInteger("gCheats.InfiniteRupees", 0)) {
gSaveContext.save.saveInfo.playerData.rupees = CUR_CAPACITY(UPG_WALLET);
}
static RegisterShipInitFunc rupeesInitFunc(
[]() {
COND_HOOK(OnGameStateUpdate, CVarGetInteger("gCheats.InfiniteRupees", 0),
[]() { gSaveContext.save.saveInfo.playerData.rupees = CUR_CAPACITY(UPG_WALLET); });
},
{ "gCheats.InfiniteRupees" });

if (CVarGetInteger("gCheats.InfiniteConsumables", 0)) {
static RegisterShipInitFunc consumeablesInitFunc(
[]() {
COND_HOOK(OnGameStateUpdate, CVarGetInteger("gCheats.InfiniteConsumables", 0), []() {
if (INV_CONTENT(ITEM_BOW) == ITEM_BOW) {
AMMO(ITEM_BOW) = CUR_CAPACITY(UPG_QUIVER);
}
Expand Down Expand Up @@ -52,6 +64,6 @@ void RegisterInfiniteCheats() {
if (INV_CONTENT(ITEM_POWDER_KEG) == ITEM_POWDER_KEG) {
AMMO(ITEM_POWDER_KEG) = 1;
}
}
});
}
});
},
{ "gCheats.InfiniteConsumables" });
10 changes: 8 additions & 2 deletions mm/2s2h/Enhancements/Cheats/LongerFlowerGlide.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#include <libultraship/bridge.h>
#include "2s2h/ShipInit.hpp"

extern "C" {
#include "z64.h";
#include "variables.h";
extern f32 D_8085D958[2];
}

#define CVAR_NAME "gCheats.LongerFlowerGlide"
#define CVAR CVarGetInteger(CVAR_NAME, 0)

void RegisterLongerFlowerGlide() {
if (CVarGetInteger("gCheats.LongerFlowerGlide", 0)) {
if (CVAR) {
D_8085D958[0] = 99999.9f;
D_8085D958[1] = 99999.9f;
} else {
D_8085D958[0] = 600.0f;
D_8085D958[1] = 960.0f;
}
}

static RegisterShipInitFunc initFunc(RegisterLongerFlowerGlide, { CVAR_NAME });
Loading

0 comments on commit 44f0306

Please sign in to comment.