From 262963bf88e9dd49ce5173f57fa6e8fd4f4fa88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Sun, 17 May 2020 21:06:38 -0300 Subject: [PATCH] Restructuring some of the cheat code --- src/game/mario.c | 29 ++++++++++++++++------------- src/game/mario_actions_moving.c | 8 ++++---- src/game/options_menu.c | 13 +++++++------ src/pc/cheats.c | 1 + src/pc/cheats.h | 13 +++++++++++++ src/pc/configfile.c | 9 --------- src/pc/configfile.h | 6 ------ 7 files changed, 41 insertions(+), 38 deletions(-) create mode 100644 src/pc/cheats.c create mode 100644 src/pc/cheats.h diff --git a/src/game/mario.c b/src/game/mario.c index 1edaa835..afeab9ae 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -32,6 +32,7 @@ #include "level_table.h" #include "thread6.h" #include "pc/configfile.h" +#include "pc/cheats.h" #ifdef BETTERCAMERA #include "bettercamera.h" #endif @@ -1397,12 +1398,14 @@ void update_mario_inputs(struct MarioState *m) { update_mario_geometry_inputs(m); debug_print_speed_action_normal(m); + /* Moonjump cheat */ - while (cheatMoonjump == true && cheatEnablecheats == true && m->controller->buttonDown & L_TRIG ){ + while (Cheats.MoonJump == true && Cheats.EnableCheats == true && m->controller->buttonDown & L_TRIG ){ m->vel[1] = 25; - break; + break; // TODO: Unneeded break? } /*End of moonjump cheat */ + if (gCameraMovementFlags & CAM_MOVE_C_UP_MODE) { if (m->action & ACT_FLAG_ALLOW_FIRST_PERSON) { m->input |= INPUT_FIRST_PERSON; @@ -1726,17 +1729,17 @@ s32 execute_mario_action(UNUSED struct Object *o) { /** * Cheat stuff */ - while (cheatGodmode == true && cheatEnablecheats == true){ - gMarioState->health = 0x880; - break; - } - while (cheatInfinitelives == true && cheatEnablecheats == true && gMarioState->numLives < 99){ - gMarioState->numLives += 1; - break; - } - while (cheatSuperspeed == true && cheatEnablecheats == true && gMarioState->forwardVel > 0 ){ - gMarioState->forwardVel += 100; - break; + + if (Cheats.EnableCheats) + { + if (Cheats.GodMode) + gMarioState->health = 0x880; + + if (Cheats.InfiniteLives && gMarioState->numLives < 99) + gMarioState->numLives += 1; + + if (Cheats.SuperSpeed && gMarioState->forwardVel > 0) + gMarioState->forwardVel += 100; } /** * End of cheat stuff diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index 4d0c8efa..5b4dbb80 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -13,6 +13,7 @@ #include "behavior_data.h" #include "thread6.h" #include "pc/configfile.h" +#include "pc/cheats.h" struct LandingAction { s16 numFrames; @@ -464,13 +465,12 @@ void update_walking_speed(struct MarioState *m) { /* Handles the "Super responsive controls" cheat. The content of the "else" is Mario's original code for turning around.*/ - if (cheatResponsive == true && cheatEnablecheats == true ) { + if (Cheats.Responsive == true && Cheats.EnableCheats == true ) { m->faceAngle[1] = m->intendedYaw; } else { - m->faceAngle[1] = - m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800); - } + m->faceAngle[1] = m->intendedYaw - approach_s32((s16)(m->intendedYaw - m->faceAngle[1]), 0, 0x800, 0x800); + } apply_slope_accel(m); } diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 25996e4d..89e6deb1 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -18,6 +18,7 @@ #include "game/options_menu.h" #include "pc/pc_main.h" #include "pc/cliopts.h" +#include "pc/cheats.h" #include "pc/configfile.h" #include "pc/controller/controller_api.h" @@ -219,12 +220,12 @@ static struct Option optsAudio[] = { }; static struct Option optsCheats[] = { - DEF_OPT_TOGGLE( optsCheatsStr[0], &cheatEnablecheats ), - DEF_OPT_TOGGLE( optsCheatsStr[1], &cheatMoonjump ), - DEF_OPT_TOGGLE( optsCheatsStr[2], &cheatGodmode ), - DEF_OPT_TOGGLE( optsCheatsStr[3], &cheatInfinitelives ), - DEF_OPT_TOGGLE( optsCheatsStr[4], &cheatSuperspeed), - DEF_OPT_TOGGLE( optsCheatsStr[5], &cheatResponsive), + DEF_OPT_TOGGLE( optsCheatsStr[0], &Cheats.EnableCheats ), + DEF_OPT_TOGGLE( optsCheatsStr[1], &Cheats.MoonJump ), + DEF_OPT_TOGGLE( optsCheatsStr[2], &Cheats.GodMode ), + DEF_OPT_TOGGLE( optsCheatsStr[3], &Cheats.InfiniteLives ), + DEF_OPT_TOGGLE( optsCheatsStr[4], &Cheats.SuperSpeed), + DEF_OPT_TOGGLE( optsCheatsStr[5], &Cheats.Responsive), }; diff --git a/src/pc/cheats.c b/src/pc/cheats.c new file mode 100644 index 00000000..89ed004d --- /dev/null +++ b/src/pc/cheats.c @@ -0,0 +1 @@ +struct CheatList Cheats; diff --git a/src/pc/cheats.h b/src/pc/cheats.h new file mode 100644 index 00000000..01a7264b --- /dev/null +++ b/src/pc/cheats.h @@ -0,0 +1,13 @@ +#include + +struct CheatList +{ + bool EnableCheats; + bool MoonJump; + bool GodMode; + bool InfiniteLives; + bool SuperSpeed; + bool Responsive; +}; + +extern struct CheatList Cheats; diff --git a/src/pc/configfile.c b/src/pc/configfile.c index f6623a1d..3c2735c2 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -37,15 +37,6 @@ bool configFullscreen = false; unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME -// Cheat stuff -bool cheatEnablecheats = false; -bool cheatMoonjump = false; -bool cheatGodmode = false; -bool cheatInfinitelives = false; -bool cheatSuperspeed = false; -bool cheatResponsive = false; - - // Keyboard mappings (VK_ values, by default keyboard/gamepad/mouse) unsigned int configKeyA[MAX_BINDS] = { 0x0026, 0x1000, 0x1103 }; unsigned int configKeyB[MAX_BINDS] = { 0x0033, 0x1002, 0x1101 }; diff --git a/src/pc/configfile.h b/src/pc/configfile.h index bdecf0e9..49b48b93 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -24,12 +24,6 @@ extern unsigned int configKeyStickUp[]; extern unsigned int configKeyStickDown[]; extern unsigned int configKeyStickLeft[]; extern unsigned int configKeyStickRight[]; -extern bool cheatMoonjump; -extern bool cheatGodmode; -extern bool cheatEnablecheats; -extern bool cheatInfinitelives; -extern bool cheatSuperspeed; -extern bool cheatResponsive; #ifdef BETTERCAMERA extern unsigned int configCameraXSens; extern unsigned int configCameraYSens;