From 28fc53c2079799f3138e3b7b9867dbbf2f428b43 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 17 May 2020 22:56:06 +0100 Subject: [PATCH 01/14] Enabled a Cheat menu Enabled a cheat menu. It includes 4 cheats, and all of them rely on the global "Enable cheats" option so the user can quickly turn all the selected cheats off and back on. --- include/text_strings.h.in | 9 ++++++++- src/game/mario.c | 27 +++++++++++++++++++++++++-- src/game/options_menu.c | 22 ++++++++++++++++++++++ src/pc/configfile.c | 8 ++++++++ src/pc/configfile.h | 5 +++++ 5 files changed, 68 insertions(+), 3 deletions(-) diff --git a/include/text_strings.h.in b/include/text_strings.h.in index 3246699..01f7ff8 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -1,4 +1,4 @@ -#ifndef TEXT_STRINGS_H + #ifndef TEXT_STRINGS_H #define TEXT_STRINGS_H #include "text_menu_strings.h" @@ -45,6 +45,13 @@ #define TEXT_BIND_LEFT _("Stick Left") #define TEXT_BIND_RIGHT _("Stick Right") +#define TEXT_OPT_CHEATS _("CHEATS") +#define TEXT_OPT_CHEAT1 _("Enable cheats") +#define TEXT_OPT_CHEAT2 _("Moonjump (Press L)") +#define TEXT_OPT_CHEAT3 _("Invincible Mario") +#define TEXT_OPT_CHEAT4 _("Infinite lives") +#define TEXT_OPT_CHEAT5 _("Super speed") + /** * Global Symbols */ diff --git a/src/game/mario.c b/src/game/mario.c index 164f92f..1edaa83 100644 --- a/src/game/mario.c +++ b/src/game/mario.c @@ -31,6 +31,7 @@ #include "engine/surface_collision.h" #include "level_table.h" #include "thread6.h" +#include "pc/configfile.h" #ifdef BETTERCAMERA #include "bettercamera.h" #endif @@ -1396,7 +1397,12 @@ 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 ){ + m->vel[1] = 25; + 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; @@ -1717,7 +1723,24 @@ void func_sh_8025574C(void) { */ s32 execute_mario_action(UNUSED struct Object *o) { s32 inLoop = TRUE; - + /** + * 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; + } + /** + * End of cheat stuff + */ if (gMarioState->action) { gMarioState->marioObj->header.gfx.node.flags &= ~GRAPH_RENDER_INVISIBLE; mario_reset_bodystate(gMarioState); diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 752a539..01a0817 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -50,6 +50,8 @@ static const u8 menuStr[][32] = { { TEXT_OPT_VIDEO }, { TEXT_OPT_AUDIO }, { TEXT_EXIT_GAME }, + { TEXT_OPT_CHEATS }, + }; static const u8 optsCameraStr[][32] = { @@ -75,6 +77,14 @@ static const u8 optsAudioStr[][32] = { { TEXT_OPT_MVOLUME }, }; +static const u8 optsCheatsStr[][64] = { + { TEXT_OPT_CHEAT1 }, + { TEXT_OPT_CHEAT2 }, + { TEXT_OPT_CHEAT3 }, + { TEXT_OPT_CHEAT4 }, + { TEXT_OPT_CHEAT5 }, +}; + static const u8 bindStr[][32] = { { TEXT_OPT_UNBOUND }, { TEXT_OPT_PRESSKEY }, @@ -207,6 +217,15 @@ static struct Option optsAudio[] = { DEF_OPT_SCROLL( optsAudioStr[0], &configMasterVolume, 0, MAX_VOLUME, 1 ), }; +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), + +}; + /* submenu definitions */ #ifdef BETTERCAMERA @@ -215,6 +234,7 @@ static struct SubMenu menuCamera = DEF_SUBMENU( menuStr[4], optsCamera ); static struct SubMenu menuControls = DEF_SUBMENU( menuStr[5], optsControls ); static struct SubMenu menuVideo = DEF_SUBMENU( menuStr[6], optsVideo ); static struct SubMenu menuAudio = DEF_SUBMENU( menuStr[7], optsAudio ); +static struct SubMenu menuCheats = DEF_SUBMENU( menuStr[9], optsCheats ); /* main options menu definition */ @@ -226,6 +246,8 @@ static struct Option optsMain[] = { DEF_OPT_SUBMENU( menuStr[6], &menuVideo ), DEF_OPT_SUBMENU( menuStr[7], &menuAudio ), DEF_OPT_BUTTON ( menuStr[8], optmenu_act_exit ), + DEF_OPT_SUBMENU( menuStr[9], &menuCheats ), + }; static struct SubMenu menuMain = DEF_SUBMENU( menuStr[3], optsMain ); diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 3c2735c..c9d025c 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -37,6 +37,14 @@ 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; + + // 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 49b48b9..42ee7a6 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -24,6 +24,11 @@ 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; #ifdef BETTERCAMERA extern unsigned int configCameraXSens; extern unsigned int configCameraYSens; From 1a9c8dbe477af5cde8adaad4c3802e48b27ee839 Mon Sep 17 00:00:00 2001 From: Leon422 Date: Sun, 17 May 2020 23:27:40 +0100 Subject: [PATCH 02/14] Fixed tabs/spaces --- src/pc/configfile.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 42ee7a6..7911f6b 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -24,11 +24,12 @@ 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 cheatMoonjump; +extern bool cheatGodmode; +extern bool cheatEnablecheats; +extern bool cheatInfinitelives; +extern bool cheatSuperspeed; + #ifdef BETTERCAMERA extern unsigned int configCameraXSens; extern unsigned int configCameraYSens; From 181e18dfea084f1da2ddd09ca2b1fead9621b133 Mon Sep 17 00:00:00 2001 From: kurethedead Date: Sun, 17 May 2020 15:48:06 -0700 Subject: [PATCH 03/14] Implemented LoadTile f3d command, I4/I8/RGBA32 texture formats. --- src/pc/gfx/gfx_pc.c | 93 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) diff --git a/src/pc/gfx/gfx_pc.c b/src/pc/gfx/gfx_pc.c index 3b11a46..4f6968f 100644 --- a/src/pc/gfx/gfx_pc.c +++ b/src/pc/gfx/gfx_pc.c @@ -285,6 +285,12 @@ static bool gfx_texture_cache_lookup(int tile, struct TextureHashmapNode **n, co return false; } +static void import_texture_rgba32(int tile) { + uint32_t width = rdp.texture_tile.line_size_bytes / 2; + uint32_t height = (rdp.loaded_texture[tile].size_bytes / 2) / rdp.texture_tile.line_size_bytes; + gfx_rapi->upload_texture(rdp.loaded_texture[tile].addr, width, height); +} + static void import_texture_rgba16(int tile) { uint8_t rgba32_buf[8192]; @@ -371,6 +377,41 @@ static void import_texture_ia16(int tile) { gfx_rapi->upload_texture(rgba32_buf, width, height); } +static void import_texture_i4(int tile) { + uint8_t rgba32_buf[32768]; + + for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes * 2; i++) { + uint8_t byte = rdp.loaded_texture[tile].addr[i / 2]; + uint8_t intensity = (byte >> (4 - (i % 2) * 4)) & 0xf; + rgba32_buf[4*i + 0] = SCALE_4_8(intensity); + rgba32_buf[4*i + 1] = SCALE_4_8(intensity); + rgba32_buf[4*i + 2] = SCALE_4_8(intensity); + rgba32_buf[4*i + 3] = 255; + } + + uint32_t width = rdp.texture_tile.line_size_bytes * 2; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + + gfx_rapi->upload_texture(rgba32_buf, width, height); +} + +static void import_texture_i8(int tile) { + uint8_t rgba32_buf[16384]; + + for (uint32_t i = 0; i < rdp.loaded_texture[tile].size_bytes; i++) { + uint8_t intensity = rdp.loaded_texture[tile].addr[i]; + rgba32_buf[4*i + 0] = intensity; + rgba32_buf[4*i + 1] = intensity; + rgba32_buf[4*i + 2] = intensity; + rgba32_buf[4*i + 3] = 255; + } + + uint32_t width = rdp.texture_tile.line_size_bytes; + uint32_t height = rdp.loaded_texture[tile].size_bytes / rdp.texture_tile.line_size_bytes; + + gfx_rapi->upload_texture(rgba32_buf, width, height); +} + static void import_texture_ci4(int tile) { uint8_t rgba32_buf[32768]; @@ -426,7 +467,10 @@ static void import_texture(int tile) { int t0 = get_time(); if (fmt == G_IM_FMT_RGBA) { - if (siz == G_IM_SIZ_16b) { + if (siz == G_IM_SIZ_32b) { + import_texture_rgba32(tile); + } + else if (siz == G_IM_SIZ_16b) { import_texture_rgba16(tile); } else { abort(); @@ -449,6 +493,14 @@ static void import_texture(int tile) { } else { abort(); } + } else if (fmt == G_IM_FMT_I) { + if (siz == G_IM_SIZ_4b) { + import_texture_i4(tile); + } else if (siz == G_IM_SIZ_8b) { + import_texture_i8(tile); + } else { + abort(); + } } else { abort(); } @@ -976,7 +1028,6 @@ static void gfx_dp_set_texture_image(uint32_t format, uint32_t size, uint32_t wi } static void gfx_dp_set_tile(uint8_t fmt, uint32_t siz, uint32_t line, uint32_t tmem, uint8_t tile, uint32_t palette, uint32_t cmt, uint32_t maskt, uint32_t shiftt, uint32_t cms, uint32_t masks, uint32_t shifts) { - SUPPORT_CHECK(siz != G_IM_SIZ_32b); if (tile == G_TX_RENDERTILE) { SUPPORT_CHECK(palette == 0); // palette should set upper 4 bits of color index in 4b mode @@ -1035,12 +1086,45 @@ static void gfx_dp_load_block(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t } uint32_t size_bytes = (lrs + 1) << word_size_shift; rdp.loaded_texture[rdp.texture_to_load.tile_number].size_bytes = size_bytes; - assert(size_bytes <= 4096 && "bug: too big texture"); rdp.loaded_texture[rdp.texture_to_load.tile_number].addr = rdp.texture_to_load.addr; rdp.textures_changed[rdp.texture_to_load.tile_number] = true; } +static void gfx_dp_load_tile(uint8_t tile, uint32_t uls, uint32_t ult, uint32_t lrs, uint32_t lrt) { + if (tile == 1) return; + SUPPORT_CHECK(tile == G_TX_LOADTILE); + SUPPORT_CHECK(uls == 0); + SUPPORT_CHECK(ult == 0); + + uint32_t word_size_shift; + switch (rdp.texture_to_load.siz) { + case G_IM_SIZ_4b: + word_size_shift = 0; // Or -1? It's unused in SM64 anyway. + break; + case G_IM_SIZ_8b: + word_size_shift = 0; + break; + case G_IM_SIZ_16b: + word_size_shift = 1; + break; + case G_IM_SIZ_32b: + word_size_shift = 2; + break; + } + + uint32_t size_bytes = (((lrs >> G_TEXTURE_IMAGE_FRAC) + 1) * ((lrt >> G_TEXTURE_IMAGE_FRAC) + 1)) << word_size_shift; + rdp.loaded_texture[rdp.texture_to_load.tile_number].size_bytes = size_bytes; + + rdp.loaded_texture[rdp.texture_to_load.tile_number].addr = rdp.texture_to_load.addr; + rdp.texture_tile.uls = uls; + rdp.texture_tile.ult = ult; + rdp.texture_tile.lrs = lrs; + rdp.texture_tile.lrt = lrt; + + rdp.textures_changed[rdp.texture_to_load.tile_number] = true; +} + static uint8_t color_comb_component(uint32_t v) { switch (v) { case G_CCMUX_TEXEL0: @@ -1384,6 +1468,9 @@ static void gfx_run_dl(Gfx* cmd) { case G_LOADBLOCK: gfx_dp_load_block(C1(24, 3), C0(12, 12), C0(0, 12), C1(12, 12), C1(0, 12)); break; + case G_LOADTILE: + gfx_dp_load_tile(C1(24, 3), C0(12, 12), C0(0, 12), C1(12, 12), C1(0, 12)); + break; case G_SETTILE: gfx_dp_set_tile(C0(21, 3), C0(19, 2), C0(9, 9), C0(0, 9), C1(24, 3), C1(20, 4), C1(18, 2), C1(14, 4), C1(10, 4), C1(8, 2), C1(4, 4), C1(0, 4)); break; From 17c6e569078c69fea666902c66408201b37013ef Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 18 May 2020 00:05:26 +0100 Subject: [PATCH 04/14] Added a "super responsive controls" cheat Added a "super responsive controls" cheat. When enabled, Mario will look straight into the direction the user inputs when changing directions, with no interpolation at all. (you can still slide / side jump / etc ) The change is especially noticeable when playing with keyboard. --- include/text_strings.h.in | 1 + src/game/mario_actions_moving.c | 10 +++++++++- src/game/options_menu.c | 2 ++ src/pc/configfile.c | 1 + src/pc/configfile.h | 12 ++++++------ 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/include/text_strings.h.in b/include/text_strings.h.in index 01f7ff8..6065fb7 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -51,6 +51,7 @@ #define TEXT_OPT_CHEAT3 _("Invincible Mario") #define TEXT_OPT_CHEAT4 _("Infinite lives") #define TEXT_OPT_CHEAT5 _("Super speed") +#define TEXT_OPT_CHEAT6 _("Super responsive controls") /** * Global Symbols diff --git a/src/game/mario_actions_moving.c b/src/game/mario_actions_moving.c index 57290d2..4d0c8ef 100644 --- a/src/game/mario_actions_moving.c +++ b/src/game/mario_actions_moving.c @@ -12,6 +12,7 @@ #include "memory.h" #include "behavior_data.h" #include "thread6.h" +#include "pc/configfile.h" struct LandingAction { s16 numFrames; @@ -461,8 +462,15 @@ void update_walking_speed(struct MarioState *m) { m->forwardVel = 48.0f; } - m->faceAngle[1] = + /* Handles the "Super responsive controls" cheat. The content of the "else" is Mario's original code for turning around.*/ + + if (cheatResponsive == true && cheatEnablecheats == true ) { + m->faceAngle[1] = m->intendedYaw; + } + else { + 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 01a0817..25996e4 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -83,6 +83,7 @@ static const u8 optsCheatsStr[][64] = { { TEXT_OPT_CHEAT3 }, { TEXT_OPT_CHEAT4 }, { TEXT_OPT_CHEAT5 }, + { TEXT_OPT_CHEAT6 }, }; static const u8 bindStr[][32] = { @@ -223,6 +224,7 @@ static struct Option optsCheats[] = { DEF_OPT_TOGGLE( optsCheatsStr[2], &cheatGodmode ), DEF_OPT_TOGGLE( optsCheatsStr[3], &cheatInfinitelives ), DEF_OPT_TOGGLE( optsCheatsStr[4], &cheatSuperspeed), + DEF_OPT_TOGGLE( optsCheatsStr[5], &cheatResponsive), }; diff --git a/src/pc/configfile.c b/src/pc/configfile.c index c9d025c..f6623a1 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -43,6 +43,7 @@ bool cheatMoonjump = false; bool cheatGodmode = false; bool cheatInfinitelives = false; bool cheatSuperspeed = false; +bool cheatResponsive = false; // Keyboard mappings (VK_ values, by default keyboard/gamepad/mouse) diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 7911f6b..bdecf0e 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -24,12 +24,12 @@ 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 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; 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 05/14] 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 1edaa83..afeab9a 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 4d0c8ef..5b4dbb8 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 25996e4..89e6deb 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 0000000..89ed004 --- /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 0000000..01a7264 --- /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 f6623a1..3c2735c 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 bdecf0e..49b48b9 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; From 6811d9e01cedc026b7e75f98f4846a3e0ea0d873 Mon Sep 17 00:00:00 2001 From: "V. R. Miguel" <36349314+vrmiguel@users.noreply.github.com> Date: Sun, 17 May 2020 21:17:27 -0300 Subject: [PATCH 06/14] Fixed a dumb thing --- src/pc/cheats.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pc/cheats.c b/src/pc/cheats.c index 89ed004..5663d77 100644 --- a/src/pc/cheats.c +++ b/src/pc/cheats.c @@ -1 +1,2 @@ +#include "cheats.h" struct CheatList Cheats; From 5e637bd12115b0cea1de89eeca035aeed70ce501 Mon Sep 17 00:00:00 2001 From: IvanDSM Date: Sun, 17 May 2020 21:23:30 -0300 Subject: [PATCH 07/14] Fix crashing when OOB in BETTERCAMERA builds Previously, an attempt to read gMarioState->floor->type was being made even when gMarioState->floor was a null pointer. This commit makes bettercamera check if gMarioState->floor is not null before accessing it. --- src/game/bettercamera.inc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index 0f58b2e..f585447 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -617,7 +617,7 @@ static void newcam_apply_values(struct Camera *c) gLakituState.yaw = -newcam_yaw+0x4000; //Adds support for wing mario tower - if (gMarioState->floor->type == SURFACE_LOOK_UP_WARP) { + if (gMarioState->floor && gMarioState->floor->type == SURFACE_LOOK_UP_WARP) { if (save_file_get_total_star_count(gCurrSaveFileNum - 1, 0, 0x18) >= 10) { if (newcam_tilt < -8000 && gMarioState->forwardVel == 0) { level_trigger_warp(gMarioState, 1); From d6495550f54207ebf675e61d94cb43f425195459 Mon Sep 17 00:00:00 2001 From: IvanDSM Date: Sun, 17 May 2020 22:37:52 -0300 Subject: [PATCH 08/14] Release mouse when paused --- src/pc/controller/controller_sdl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pc/controller/controller_sdl.c b/src/pc/controller/controller_sdl.c index 62aa2ac..cbdd617 100644 --- a/src/pc/controller/controller_sdl.c +++ b/src/pc/controller/controller_sdl.c @@ -14,6 +14,8 @@ #include "controller_sdl.h" #include "../configfile.h" +#include "game/level_update.h" + // mouse buttons are also in the controller namespace (why), just offset 0x100 #define VK_OFS_SDL_MOUSE 0x0100 #define VK_BASE_SDL_MOUSE (VK_BASE_SDL_GAMEPAD + VK_OFS_SDL_MOUSE) @@ -101,7 +103,7 @@ static void controller_sdl_read(OSContPad *pad) { } #ifdef BETTERCAMERA - if (newcam_mouse == 1) + if (newcam_mouse == 1 && sCurrPlayMode != 2) SDL_SetRelativeMouseMode(SDL_TRUE); else SDL_SetRelativeMouseMode(SDL_FALSE); From 0fa331d96101eb95f8b2fb51516724b2f594b4f7 Mon Sep 17 00:00:00 2001 From: Heaven Volkoff Date: Sun, 17 May 2020 16:17:47 -0300 Subject: [PATCH 09/14] Implement save/restore window dimensions/position - Add an entry in options menu to reset window --- include/text_strings.h.in | 1 + src/game/options_menu.c | 6 +++ src/pc/configfile.c | 13 +++++++ src/pc/configfile.h | 6 +++ src/pc/gfx/gfx_sdl2.c | 78 +++++++++++++++++++++------------------ 5 files changed, 68 insertions(+), 36 deletions(-) diff --git a/include/text_strings.h.in b/include/text_strings.h.in index 6065fb7..0617369 100644 --- a/include/text_strings.h.in +++ b/include/text_strings.h.in @@ -27,6 +27,7 @@ #define TEXT_OPT_NEAREST _("Nearest") #define TEXT_OPT_LINEAR _("Linear") #define TEXT_OPT_MVOLUME _("Master Volume") +#define TEXT_RESET_WINDOW _("Reset Window") #define TEXT_OPT_UNBOUND _("NONE") #define TEXT_OPT_PRESSKEY _("...") diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 89e6deb..61b50b5 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -72,6 +72,7 @@ static const u8 optsVideoStr[][32] = { { TEXT_OPT_TEXFILTER }, { TEXT_OPT_NEAREST }, { TEXT_OPT_LINEAR }, + { TEXT_RESET_WINDOW } }; static const u8 optsAudioStr[][32] = { @@ -177,6 +178,10 @@ static void optmenu_act_exit(UNUSED struct Option *self, s32 arg) { if (!arg) game_exit(); // only exit on A press and not directions } +static void optvide_reset_window(UNUSED struct Option *self, s32 arg) { + if (!arg) configWindow.reset = true;; // Restrict reset to A press and not directions +} + /* submenu option lists */ #ifdef BETTERCAMERA @@ -213,6 +218,7 @@ static struct Option optsControls[] = { static struct Option optsVideo[] = { DEF_OPT_TOGGLE( optsVideoStr[0], &configFullscreen ), DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ), + DEF_OPT_BUTTON( optsVideoStr[4], optvide_reset_window ), }; static struct Option optsAudio[] = { diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 3c2735c..75f792f 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -5,8 +5,10 @@ #include #include #include +#include #include "configfile.h" +#include "gfx/gfx_screen_config.h" #include "controller/controller_api.h" #define ARRAY_LEN(arr) (sizeof(arr) / sizeof(arr[0])) @@ -34,6 +36,13 @@ struct ConfigOption { // Video/audio stuff bool configFullscreen = false; +ConfigWindow configWindow = { + .x = SDL_WINDOWPOS_CENTERED, + .y = SDL_WINDOWPOS_CENTERED, + .w = DESIRED_SCREEN_WIDTH, + .h = DESIRED_SCREEN_HEIGHT, + .reset = false +}; unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME @@ -69,6 +78,10 @@ unsigned int configSkipIntro = 0; static const struct ConfigOption options[] = { {.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configFullscreen}, + {.name = "window_x", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.x}, + {.name = "window_y", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.y}, + {.name = "window_w", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.w}, + {.name = "window_h", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.h}, {.name = "texture_filtering", .type = CONFIG_TYPE_UINT, .uintValue = &configFiltering}, {.name = "master_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMasterVolume}, {.name = "key_a", .type = CONFIG_TYPE_BIND, .uintValue = configKeyA}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index 49b48b9..d45a60c 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -7,7 +7,13 @@ #define MAX_VOLUME 127 #define VOLUME_SHIFT 7 +typedef struct { + unsigned int x, y, w, h; + bool reset; +} ConfigWindow; + extern bool configFullscreen; +extern ConfigWindow configWindow; extern unsigned int configFiltering; extern unsigned int configMasterVolume; extern unsigned int configKeyA[]; diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index b73b6ae..00529d4 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -40,10 +40,7 @@ static SDL_Window *wnd; static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; - -static bool window_fullscreen; static bool window_vsync; -static int window_width, window_height; const SDL_Scancode windows_scancode_table[] = { @@ -96,22 +93,34 @@ const SDL_Scancode scancode_rmapping_nonextended[][2] = { {SDL_SCANCODE_KP_MULTIPLY, SDL_SCANCODE_PRINTSCREEN} }; -static void gfx_sdl_set_fullscreen(bool fullscreen) { - if (fullscreen == window_fullscreen) return; +#define IS_FULLSCREEN (SDL_GetWindowFlags(wnd) & SDL_WINDOW_FULLSCREEN_DESKTOP) - if (fullscreen) { +static void gfx_sdl_set_fullscreen() { + if (configFullscreen == IS_FULLSCREEN) + return; + if (configFullscreen) { SDL_SetWindowFullscreen(wnd, SDL_WINDOW_FULLSCREEN_DESKTOP); SDL_ShowCursor(SDL_DISABLE); } else { SDL_SetWindowFullscreen(wnd, 0); SDL_ShowCursor(SDL_ENABLE); - // reset back to small window just in case - window_width = DESIRED_SCREEN_WIDTH; - window_height = DESIRED_SCREEN_HEIGHT; - SDL_SetWindowSize(wnd, window_width, window_height); + SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); + SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); } +} - window_fullscreen = fullscreen; +static void gfx_sdl_reset_dimension_and_pos() { + if (!configWindow.reset) return; + configWindow.x = SDL_WINDOWPOS_CENTERED; + configWindow.y = SDL_WINDOWPOS_CENTERED; + configWindow.w = DESIRED_SCREEN_WIDTH; + configWindow.h = DESIRED_SCREEN_HEIGHT; + configWindow.reset = false; + + if (!IS_FULLSCREEN) { + SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); + SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); + } } static bool test_vsync(void) { @@ -157,25 +166,15 @@ static void gfx_sdl_init(void) { "Super Mario 64 PC port (OpenGL_ES2)"; #endif - Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE; - - window_fullscreen = configFullscreen; - - if (configFullscreen) { - window_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; - SDL_ShowCursor(SDL_DISABLE); - } else { - SDL_ShowCursor(SDL_ENABLE); - } - - wnd = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - DESIRED_SCREEN_WIDTH, DESIRED_SCREEN_HEIGHT, window_flags); - + wnd = SDL_CreateWindow( + window_title, + configWindow.x, configWindow.y, configWindow.w, configWindow.h, + SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE + ); ctx = SDL_GL_CreateContext(wnd); SDL_GL_SetSwapInterval(2); - // in case FULLSCREEN_DESKTOP set our size to god knows what - SDL_GetWindowSize(wnd, &window_width, &window_height); + gfx_sdl_set_fullscreen(); window_vsync = test_vsync(); if (!window_vsync) @@ -201,8 +200,7 @@ static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) { } static void gfx_sdl_get_dimensions(uint32_t *width, uint32_t *height) { - *width = window_width; - *height = window_height; + SDL_GetWindowSize(wnd, width, height); } static int translate_scancode(int scancode) { @@ -241,10 +239,18 @@ static void gfx_sdl_handle_events(void) { gfx_sdl_onkeyup(event.key.keysym.scancode); break; #endif - case SDL_WINDOWEVENT: - if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { - window_width = event.window.data1; - window_height = event.window.data2; + case SDL_WINDOWEVENT: // FIX-ME: Check if this makes sense to be include in Web build + if (!IS_FULLSCREEN) { + switch (event.window.event) { + case SDL_WINDOWEVENT_MOVED: + configWindow.x = event.window.data1; + configWindow.y = event.window.data2; + break; + case SDL_WINDOWEVENT_SIZE_CHANGED: + configWindow.w = event.window.data1; + configWindow.h = event.window.data2; + break; + } } break; case SDL_QUIT: @@ -252,9 +258,9 @@ static void gfx_sdl_handle_events(void) { break; } } - // just check if the fullscreen value has changed and toggle fullscreen if it has - if (configFullscreen != window_fullscreen) - gfx_sdl_set_fullscreen(configFullscreen); + + gfx_sdl_reset_dimension_and_pos(); + gfx_sdl_set_fullscreen(); } static bool gfx_sdl_start_frame(void) { From 9927b3555dd481a0eea579272a9dc3dc0b052b09 Mon Sep 17 00:00:00 2001 From: Heaven Volkoff Date: Sun, 17 May 2020 23:08:12 -0300 Subject: [PATCH 10/14] Fix fullscreen exit resulting in a slightly lower Y position --- src/pc/configfile.c | 4 +++- src/pc/configfile.h | 2 ++ src/pc/gfx/gfx_sdl2.c | 40 ++++++++++++++++++++++------------------ 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 75f792f..2b97c5f 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -41,7 +41,9 @@ ConfigWindow configWindow = { .y = SDL_WINDOWPOS_CENTERED, .w = DESIRED_SCREEN_WIDTH, .h = DESIRED_SCREEN_HEIGHT, - .reset = false + .reset = false, + .vsync = false, + .exiting_fullscreen = false, }; unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME diff --git a/src/pc/configfile.h b/src/pc/configfile.h index d45a60c..b2368c8 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -10,6 +10,8 @@ typedef struct { unsigned int x, y, w, h; bool reset; + bool vsync; + bool exiting_fullscreen; } ConfigWindow; extern bool configFullscreen; diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 00529d4..3c534d0 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -22,6 +22,8 @@ #endif // End of OS-Specific GL defines +#include + #include "gfx_window_manager_api.h" #include "gfx_screen_config.h" #include "../pc_main.h" @@ -40,7 +42,6 @@ static SDL_Window *wnd; static SDL_GLContext ctx = NULL; static int inverted_scancode_table[512]; -static bool window_vsync; const SDL_Scancode windows_scancode_table[] = { @@ -104,23 +105,26 @@ static void gfx_sdl_set_fullscreen() { } else { SDL_SetWindowFullscreen(wnd, 0); SDL_ShowCursor(SDL_ENABLE); - SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); - SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); + configWindow.exiting_fullscreen = true; } } static void gfx_sdl_reset_dimension_and_pos() { - if (!configWindow.reset) return; - configWindow.x = SDL_WINDOWPOS_CENTERED; - configWindow.y = SDL_WINDOWPOS_CENTERED; - configWindow.w = DESIRED_SCREEN_WIDTH; - configWindow.h = DESIRED_SCREEN_HEIGHT; - configWindow.reset = false; + if (configWindow.exiting_fullscreen) + configWindow.exiting_fullscreen = false; + else if (configWindow.reset) { + configWindow.x = SDL_WINDOWPOS_CENTERED; + configWindow.y = SDL_WINDOWPOS_CENTERED; + configWindow.w = DESIRED_SCREEN_WIDTH; + configWindow.h = DESIRED_SCREEN_HEIGHT; + configWindow.reset = false; - if (!IS_FULLSCREEN) { - SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); - SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); - } + if (IS_FULLSCREEN) return; + } else + return; + + SDL_SetWindowSize(wnd, configWindow.w, configWindow.h); + SDL_SetWindowPosition(wnd, configWindow.x, configWindow.y); } static bool test_vsync(void) { @@ -176,8 +180,8 @@ static void gfx_sdl_init(void) { gfx_sdl_set_fullscreen(); - window_vsync = test_vsync(); - if (!window_vsync) + configWindow.vsync = test_vsync(); + if (!configWindow.vsync) printf("Warning: VSync is not enabled or not working. Falling back to timer for synchronization\n"); for (size_t i = 0; i < sizeof(windows_scancode_table) / sizeof(SDL_Scancode); i++) { @@ -239,8 +243,8 @@ static void gfx_sdl_handle_events(void) { gfx_sdl_onkeyup(event.key.keysym.scancode); break; #endif - case SDL_WINDOWEVENT: // FIX-ME: Check if this makes sense to be include in Web build - if (!IS_FULLSCREEN) { + case SDL_WINDOWEVENT: // TODO: Check if this makes sense to be included in the Web build + if (!(IS_FULLSCREEN || configWindow.exiting_fullscreen)) { switch (event.window.event) { case SDL_WINDOWEVENT_MOVED: configWindow.x = event.window.data1; @@ -280,7 +284,7 @@ static void sync_framerate_with_timer(void) { } static void gfx_sdl_swap_buffers_begin(void) { - if (!window_vsync) + if (!configWindow.vsync) sync_framerate_with_timer(); SDL_GL_SwapWindow(wnd); } From 98efed7c51cca39758f8a5b7326c69206b4ab881 Mon Sep 17 00:00:00 2001 From: Heaven Volkoff Date: Sun, 17 May 2020 23:29:41 -0300 Subject: [PATCH 11/14] Reset Window now exit fullscreen Change configFullscreen to configWindow.fullscreen --- src/game/options_menu.c | 2 +- src/pc/configfile.c | 4 ++-- src/pc/configfile.h | 2 +- src/pc/gfx/gfx_sdl2.c | 17 ++++++++++------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/game/options_menu.c b/src/game/options_menu.c index 61b50b5..b9033be 100644 --- a/src/game/options_menu.c +++ b/src/game/options_menu.c @@ -216,7 +216,7 @@ static struct Option optsControls[] = { }; static struct Option optsVideo[] = { - DEF_OPT_TOGGLE( optsVideoStr[0], &configFullscreen ), + DEF_OPT_TOGGLE( optsVideoStr[0], &configWindow.fullscreen ), DEF_OPT_CHOICE( optsVideoStr[1], &configFiltering, filterChoices ), DEF_OPT_BUTTON( optsVideoStr[4], optvide_reset_window ), }; diff --git a/src/pc/configfile.c b/src/pc/configfile.c index 2b97c5f..0b6fe37 100644 --- a/src/pc/configfile.c +++ b/src/pc/configfile.c @@ -35,7 +35,6 @@ struct ConfigOption { */ // Video/audio stuff -bool configFullscreen = false; ConfigWindow configWindow = { .x = SDL_WINDOWPOS_CENTERED, .y = SDL_WINDOWPOS_CENTERED, @@ -43,6 +42,7 @@ ConfigWindow configWindow = { .h = DESIRED_SCREEN_HEIGHT, .reset = false, .vsync = false, + .fullscreen = false, .exiting_fullscreen = false, }; unsigned int configFiltering = 1; // 0=force nearest, 1=linear, (TODO) 2=three-point @@ -79,7 +79,7 @@ bool configCameraMouse = false; unsigned int configSkipIntro = 0; static const struct ConfigOption options[] = { - {.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configFullscreen}, + {.name = "fullscreen", .type = CONFIG_TYPE_BOOL, .boolValue = &configWindow.fullscreen}, {.name = "window_x", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.x}, {.name = "window_y", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.y}, {.name = "window_w", .type = CONFIG_TYPE_UINT, .uintValue = &configWindow.w}, diff --git a/src/pc/configfile.h b/src/pc/configfile.h index b2368c8..4343ebd 100644 --- a/src/pc/configfile.h +++ b/src/pc/configfile.h @@ -11,10 +11,10 @@ typedef struct { unsigned int x, y, w, h; bool reset; bool vsync; + bool fullscreen; bool exiting_fullscreen; } ConfigWindow; -extern bool configFullscreen; extern ConfigWindow configWindow; extern unsigned int configFiltering; extern unsigned int configMasterVolume; diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index 3c534d0..e34086b 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -97,9 +97,9 @@ const SDL_Scancode scancode_rmapping_nonextended[][2] = { #define IS_FULLSCREEN (SDL_GetWindowFlags(wnd) & SDL_WINDOW_FULLSCREEN_DESKTOP) static void gfx_sdl_set_fullscreen() { - if (configFullscreen == IS_FULLSCREEN) + if (configWindow.fullscreen == IS_FULLSCREEN) return; - if (configFullscreen) { + if (configWindow.fullscreen) { SDL_SetWindowFullscreen(wnd, SDL_WINDOW_FULLSCREEN_DESKTOP); SDL_ShowCursor(SDL_DISABLE); } else { @@ -119,7 +119,10 @@ static void gfx_sdl_reset_dimension_and_pos() { configWindow.h = DESIRED_SCREEN_HEIGHT; configWindow.reset = false; - if (IS_FULLSCREEN) return; + if (IS_FULLSCREEN) { + configWindow.fullscreen = false; + return; + } } else return; @@ -161,7 +164,7 @@ static void gfx_sdl_init(void) { //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); if (gCLIOpts.FullScreen) - configFullscreen = true; + configWindow.fullscreen = true; const char* window_title = #ifndef USE_GLES @@ -221,9 +224,9 @@ static void gfx_sdl_onkeydown(int scancode) { const Uint8 *state = SDL_GetKeyboardState(NULL); if (state[SDL_SCANCODE_LALT] && state[SDL_SCANCODE_RETURN]) - configFullscreen = !configFullscreen; - else if (state[SDL_SCANCODE_ESCAPE] && configFullscreen) - configFullscreen = false; + configWindow.fullscreen = !configWindow.fullscreen; + else if (state[SDL_SCANCODE_ESCAPE] && configWindow.fullscreen) + configWindow.fullscreen = false; } static void gfx_sdl_onkeyup(int scancode) { From ba04643b61f480b06f0953233b88b29075e72518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Sun, 17 May 2020 23:55:17 -0300 Subject: [PATCH 12/14] Potential fix for #172 Adds a null-terminator to gCLIOpts.ConfigFile --- src/pc/cliopts.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 514c142..996b308 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -13,6 +13,7 @@ void parse_cli_opts(int argc, char* argv[]) gCLIOpts.FullScreen = 0; gCLIOpts.ConfigFile = malloc(31); strncpy(gCLIOpts.ConfigFile, "sm64config.txt", strlen("sm64config.txt")); + gCLIOpts.ConfigFile[strlen("sm64config.txt") + 1] = '\0'; // Scan arguments for options if (argc > 1) @@ -48,6 +49,7 @@ void parse_cli_opts(int argc, char* argv[]) } else { memset(gCLIOpts.ConfigFile, 0, 30); strncpy(gCLIOpts.ConfigFile, argv[i+1], strlen(argv[i+1])); + gCLIOpts.ConfigFile[strlen(argv[i+1]) + 1] = '\0'; } } } From 4246242138c008ca9cf8d3fcf91dfc6079fd18ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Sun, 17 May 2020 23:58:22 -0300 Subject: [PATCH 13/14] Still about #172 --- src/pc/cliopts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pc/cliopts.c b/src/pc/cliopts.c index 996b308..ee9bc13 100644 --- a/src/pc/cliopts.c +++ b/src/pc/cliopts.c @@ -13,7 +13,7 @@ void parse_cli_opts(int argc, char* argv[]) gCLIOpts.FullScreen = 0; gCLIOpts.ConfigFile = malloc(31); strncpy(gCLIOpts.ConfigFile, "sm64config.txt", strlen("sm64config.txt")); - gCLIOpts.ConfigFile[strlen("sm64config.txt") + 1] = '\0'; + gCLIOpts.ConfigFile[strlen("sm64config.txt")] = '\0'; // Scan arguments for options if (argc > 1) @@ -49,7 +49,7 @@ void parse_cli_opts(int argc, char* argv[]) } else { memset(gCLIOpts.ConfigFile, 0, 30); strncpy(gCLIOpts.ConfigFile, argv[i+1], strlen(argv[i+1])); - gCLIOpts.ConfigFile[strlen(argv[i+1]) + 1] = '\0'; + gCLIOpts.ConfigFile[strlen(argv[i+1])] = '\0'; } } } From bd186569de1b9a65ae8c90c3d816437b103f21b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Mon, 18 May 2020 00:28:05 -0300 Subject: [PATCH 14/14] Fixes --fullscreen and --windowed problems --- src/pc/gfx/gfx_sdl2.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pc/gfx/gfx_sdl2.c b/src/pc/gfx/gfx_sdl2.c index e34086b..363d920 100644 --- a/src/pc/gfx/gfx_sdl2.c +++ b/src/pc/gfx/gfx_sdl2.c @@ -163,9 +163,13 @@ static void gfx_sdl_init(void) { //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); //SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); - if (gCLIOpts.FullScreen) + if (gCLIOpts.FullScreen == 1) configWindow.fullscreen = true; + if (gCLIOpts.FullScreen == 2) + configWindow.fullscreen = false; + + const char* window_title = #ifndef USE_GLES "Super Mario 64 PC port (OpenGL)";