From 3e332f4c9887f6686981c521a494a24656c7486a Mon Sep 17 00:00:00 2001 From: DimensionWarped Date: Tue, 26 May 2020 18:30:19 -0500 Subject: [PATCH] Add cheat to remove star/key requirements on doors --- include/text_options_strings.h.in | 1 + src/game/interaction.c | 29 ++++++++++++++++++++++++++++- src/game/options_menu.c | 2 ++ src/pc/cheats.h | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/include/text_options_strings.h.in b/include/text_options_strings.h.in index 7580ec9e..244d5017 100644 --- a/include/text_options_strings.h.in +++ b/include/text_options_strings.h.in @@ -132,6 +132,7 @@ #define TEXT_OPT_CHEAT7 _("Exit course at any time") #define TEXT_OPT_CHEAT8 _("Huge Mario") #define TEXT_OPT_CHEAT9 _("Tiny Mario") +#define TEXT_OPT_CHEAT10 _("No Keys Required") #endif // VERSION diff --git a/src/game/interaction.c b/src/game/interaction.c index b8f3f881..91beb317 100644 --- a/src/game/interaction.c +++ b/src/game/interaction.c @@ -21,6 +21,7 @@ #include "seq_ids.h" #include "course_table.h" #include "thread6.h" +#include "pc/cheats.h" #define INT_GROUND_POUND_OR_TWIRL (1 << 0) // 0x01 #define INT_PUNCH (1 << 1) // 0x02 @@ -904,6 +905,11 @@ u32 interact_warp_door(struct MarioState *m, UNUSED u32 interactType, struct Obj u32 actionArg; if (m->action == ACT_WALKING || m->action == ACT_DECELERATING) { + if (Cheats.EnableCheats && Cheats.UnlockDoors) { + /* If the unlock doors cheat is enabled, skip key checks */ + goto postkeycheck; + } + if (warpDoorId == 1 && !(saveFlags & SAVE_FLAG_UNLOCKED_UPSTAIRS_DOOR)) { if (!(saveFlags & SAVE_FLAG_HAVE_KEY_2)) { if (!sDisplayingDoorText) { @@ -933,6 +939,7 @@ u32 interact_warp_door(struct MarioState *m, UNUSED u32 interactType, struct Obj doorAction = ACT_UNLOCKING_KEY_DOOR; } +postkeycheck: if (m->action == ACT_WALKING || m->action == ACT_DECELERATING) { actionArg = should_push_or_pull_door(m, o) + 0x00000004; @@ -998,7 +1005,27 @@ u32 interact_door(struct MarioState *m, UNUSED u32 interactType, struct Object * s16 numStars = save_file_get_total_star_count(gCurrSaveFileNum - 1, COURSE_MIN - 1, COURSE_MAX - 1); if (m->action == ACT_WALKING || m->action == ACT_DECELERATING) { - if (numStars >= requiredNumStars) { + if (Cheats.EnableCheats && Cheats.UnlockDoors) { + /* If the UnlockDoors Cheat is enabled, it's the same as the approach with >= requiredNumStars, + * but never use the action that 'unlocks' the door for the save file */ + u32 actionArg = should_push_or_pull_door(m, o); + u32 enterDoorAction; + + if (actionArg & 0x00000001) { + enterDoorAction = ACT_PULLING_DOOR; + } else { + enterDoorAction = ACT_PUSHING_DOOR; + } + + m->interactObj = o; + m->usedObj = o; + + if (o->oInteractionSubtype & INT_SUBTYPE_STAR_DOOR) { + enterDoorAction = ACT_ENTERING_STAR_DOOR; + } + + return set_mario_action(m, enterDoorAction, actionArg); + } else if (numStars >= requiredNumStars) { u32 actionArg = should_push_or_pull_door(m, o); u32 enterDoorAction; u32 doorSaveFileFlag; diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 4e08dbdb..bedb7d76 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -96,6 +96,7 @@ static const u8 optsCheatsStr[][64] = { { TEXT_OPT_CHEAT7 }, { TEXT_OPT_CHEAT8 }, { TEXT_OPT_CHEAT9 }, + { TEXT_OPT_CHEAT10 }, }; static const u8 bindStr[][32] = { @@ -257,6 +258,7 @@ static struct Option optsCheats[] = { DEF_OPT_TOGGLE( optsCheatsStr[6], &Cheats.ExitAnywhere ), DEF_OPT_TOGGLE( optsCheatsStr[7], &Cheats.HugeMario ), DEF_OPT_TOGGLE( optsCheatsStr[8], &Cheats.TinyMario ), + DEF_OPT_TOGGLE( optsCheatsStr[9], &Cheats.UnlockDoors ), }; diff --git a/src/pc/cheats.h b/src/pc/cheats.h index eaf71ab4..f515cdfa 100644 --- a/src/pc/cheats.h +++ b/src/pc/cheats.h @@ -13,6 +13,7 @@ struct CheatList { bool ExitAnywhere; bool HugeMario; bool TinyMario; + bool UnlockDoors; }; extern struct CheatList Cheats;