From 9492456dcd5a6f53ddb2b72e8d0d5881dec83b4b Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Mon, 13 Jan 2025 21:09:54 +0000 Subject: [PATCH] Options: Remove dependency on demomode --- Source/diablo.cpp | 14 ++++++++------ Source/gamemenu.cpp | 3 ++- Source/gmenu.cpp | 4 +++- Source/options.cpp | 7 ------- test/timedemo_test.cpp | 1 + 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 2b403b840..aca3828d0 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -495,7 +495,7 @@ void PressKey(SDL_Keycode vkey, uint16_t modState) if (vkey == SDLK_RETURN || vkey == SDLK_KP_ENTER) { if ((modState & KMOD_ALT) != 0) { options.Graphics.fullscreen.SetValue(!IsFullScreen()); - SaveOptions(); + if (!demo::IsRunning()) SaveOptions(); } else { TypeChatMessage(); } @@ -530,7 +530,7 @@ void PressKey(SDL_Keycode vkey, uint16_t modState) if (PauseMode == 2) { if ((vkey == SDLK_RETURN || vkey == SDLK_KP_ENTER) && (modState & KMOD_ALT) != 0) { options.Graphics.fullscreen.SetValue(!IsFullScreen()); - SaveOptions(); + if (!demo::IsRunning()) SaveOptions(); } return; } @@ -568,7 +568,7 @@ void PressKey(SDL_Keycode vkey, uint16_t modState) case SDLK_KP_ENTER: if ((modState & KMOD_ALT) != 0) { options.Graphics.fullscreen.SetValue(!IsFullScreen()); - SaveOptions(); + if (!demo::IsRunning()) SaveOptions(); } else if (ActiveStore != TalkID::None) { StoreEnter(); } else if (QuestLogIsOpen) { @@ -1234,7 +1234,7 @@ void DiabloSplash() play_movie("gendata\\diablo1.smk", true); if (*intro == StartUpIntro::Once) { intro.SetValue(StartUpIntro::Off); - SaveOptions(); + if (!demo::IsRunning()) SaveOptions(); } } @@ -2565,12 +2565,14 @@ int DiabloMain(int argc, char **argv) // Read settings including translation next. This will use the presence of fonts.mpq and look for assets in devilutionx.mpq LoadOptions(); + if (demo::IsRunning()) demo::OverrideOptions(); + // Then look for a voice pack file based on the selected translation LoadLanguageArchive(); ApplicationInit(); LuaInitialize(); - SaveOptions(); + if (!demo::IsRunning()) SaveOptions(); // Finally load game data LoadGameArchives(); @@ -2589,7 +2591,7 @@ int DiabloMain(int argc, char **argv) #ifdef __UWP__ onInitialized(); #endif - SaveOptions(); + if (!demo::IsRunning()) SaveOptions(); DiabloSplash(); mainmenu_loop(); diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index 23d05b430..6ad584a4c 100644 --- a/Source/gamemenu.cpp +++ b/Source/gamemenu.cpp @@ -8,6 +8,7 @@ #include "cursor.h" #include "diablo_msg.hpp" #include "engine/backbuffer_state.hpp" +#include "engine/demomode.h" #include "engine/events.hpp" #include "engine/sound.h" #include "engine/sound_defs.hpp" @@ -358,7 +359,7 @@ void gamemenu_save_game(bool /*bActivate*/) NewCursor(CURSOR_HAND); if (CornerStone.activated) { CornerstoneSave(); - SaveOptions(); + if (!demo::IsRunning()) SaveOptions(); } interface_msg_pump(); SetEventHandler(saveProc); diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index c5fb3b2d3..051d52852 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -14,6 +14,7 @@ #include "controls/axis_direction.h" #include "controls/controller_motion.h" #include "engine/clx_sprite.hpp" +#include "engine/demomode.h" #include "engine/load_cel.hpp" #include "engine/render/clx_render.hpp" #include "engine/render/primitive_render.hpp" @@ -232,8 +233,9 @@ void gmenu_set_items(TMenuItem *pItem, void (*gmFunc)()) // BUGFIX: OOB access when sgCurrentMenuIdx is 0; should be set to NULL instead. (fixed) sgpCurrItem = sgCurrentMenuIdx > 0 ? &sgpCurrentMenu[sgCurrentMenuIdx - 1] : nullptr; GmenuUpDown(true); - if (sgpCurrentMenu == nullptr) + if (sgpCurrentMenu == nullptr && !demo::IsRunning()) { SaveOptions(); + } } void gmenu_draw(const Surface &out) diff --git a/Source/options.cpp b/Source/options.cpp index b9221c30d..7eca451a9 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -27,7 +27,6 @@ #include "controls/game_controls.h" #include "controls/plrctrls.h" #include "engine/assets.hpp" -#include "engine/demomode.h" #include "engine/sound_defs.hpp" #include "platform/locale.hpp" #include "quick_messages.hpp" @@ -193,16 +192,10 @@ void LoadOptions() #ifdef __vita__ options.Controller.bRearTouch = ini->getBool("Controller", "Enable Rear Touchpad", true); #endif - - if (demo::IsRunning()) - demo::OverrideOptions(); } void SaveOptions() { - if (demo::IsRunning()) - return; - Options &options = GetOptions(); for (OptionCategoryBase *pCategory : options.GetCategories()) { for (const OptionEntryBase *pEntry : pCategory->GetEntries()) { diff --git a/test/timedemo_test.cpp b/test/timedemo_test.cpp index d8c19de51..6ebb3f4ff 100644 --- a/test/timedemo_test.cpp +++ b/test/timedemo_test.cpp @@ -50,6 +50,7 @@ void RunTimedemo(std::string timedemoFolderName) InitKeymapActions(); LoadOptions(); + demo::OverrideOptions(); LuaInitialize(); const int demoNumber = 0;