diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index bf2639633..651b5ca1b 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -436,6 +436,7 @@ void UiHandleEvents(SDL_Event *event) const Uint8 *state = SDLC_GetKeyState(); if (state[SDLC_KEYSTATE_LALT] != 0 || state[SDLC_KEYSTATE_RALT] != 0) { sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen()); + SaveOptions(); if (gfnFullscreen != nullptr) gfnFullscreen(); return; diff --git a/Source/DiabloUI/selstart.cpp b/Source/DiabloUI/selstart.cpp index 30b177d1a..1b1b78548 100644 --- a/Source/DiabloUI/selstart.cpp +++ b/Source/DiabloUI/selstart.cpp @@ -19,6 +19,7 @@ void ItemSelected(int value) { auto option = static_cast(vecDialogItems[value]->m_value); sgOptions.StartUp.gameMode.SetValue(option); + SaveOptions(); endMenu = true; } diff --git a/Source/DiabloUI/settingsmenu.cpp b/Source/DiabloUI/settingsmenu.cpp index 2a7080a9b..b6a203bc3 100644 --- a/Source/DiabloUI/settingsmenu.cpp +++ b/Source/DiabloUI/settingsmenu.cpp @@ -354,6 +354,8 @@ void UiSettingsMenu() CleanUpSettingsUI(); } while (!backToMain); + + SaveOptions(); } } // namespace devilution diff --git a/Source/diablo.cpp b/Source/diablo.cpp index 150dd35f7..f629b7932 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -437,10 +437,12 @@ void PressKey(int vkey) } sgOptions.Keymapper.KeyPressed(vkey); if (vkey == DVL_VK_RETURN) { - if (GetAsyncKeyState(DVL_VK_MENU)) + if (GetAsyncKeyState(DVL_VK_MENU)) { sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen()); - else + SaveOptions(); + } else { control_type_message(); + } } if (vkey != DVL_VK_ESCAPE) { return; @@ -461,14 +463,17 @@ void PressKey(int vkey) sgOptions.Keymapper.KeyPressed(vkey); if (PauseMode == 2) { - if (vkey == DVL_VK_RETURN && GetAsyncKeyState(DVL_VK_MENU)) + if (vkey == DVL_VK_RETURN && GetAsyncKeyState(DVL_VK_MENU)) { sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen()); + SaveOptions(); + } return; } if (vkey == DVL_VK_RETURN) { if (GetAsyncKeyState(DVL_VK_MENU)) { sgOptions.Graphics.fullscreen.SetValue(!IsFullScreen()); + SaveOptions(); } else if (stextflag != STORE_NONE) { StoreEnter(); } else if (QuestLogIsOpen) { @@ -995,8 +1000,10 @@ void DiabloSplash() play_movie("gendata\\Hellfire.smk", true); else play_movie("gendata\\diablo1.smk", true); - if (*intro == StartUpIntro::Once) + if (*intro == StartUpIntro::Once) { intro.SetValue(StartUpIntro::Off); + SaveOptions(); + } } if (IsAnyOf(*sgOptions.StartUp.splash, StartUpSplash::TitleDialog, StartUpSplash::LogoAndTitleDialog)) @@ -1007,8 +1014,6 @@ void DiabloDeinit() { FreeItemGFX(); - if (sbWasOptionsLoaded && !demo::IsRunning()) - SaveOptions(); if (was_snd_init) effects_cleanup_sfx(); snd_deinit(); @@ -1726,6 +1731,7 @@ int DiabloMain(int argc, char **argv) // Finally load game data LoadGameArchives(); + SaveOptions(); DiabloInit(); #ifdef __UWP__ diff --git a/Source/gamemenu.cpp b/Source/gamemenu.cpp index cc9cb5dec..7ee28c1d6 100644 --- a/Source/gamemenu.cpp +++ b/Source/gamemenu.cpp @@ -341,6 +341,7 @@ void gamemenu_save_game(bool /*bActivate*/) NewCursor(CURSOR_HAND); if (CornerStone.activated) { CornerstoneSave(); + SaveOptions(); } interface_msg_pump(); SetWindowProc(saveProc); diff --git a/Source/gmenu.cpp b/Source/gmenu.cpp index 4ecefda2e..125fa75f3 100644 --- a/Source/gmenu.cpp +++ b/Source/gmenu.cpp @@ -14,6 +14,7 @@ #include "engine/load_cel.hpp" #include "engine/render/cel_render.hpp" #include "engine/render/text_render.hpp" +#include "options.h" #include "stores.h" #include "utils/language.h" #include "utils/stdcompat/optional.hpp" @@ -216,6 +217,8 @@ 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) + SaveOptions(); } void gmenu_draw(const Surface &out) diff --git a/Source/options.cpp b/Source/options.cpp index 1f4044317..4970d268b 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -302,7 +302,6 @@ void OptionAudioChanged() /** Game options */ Options sgOptions; -bool sbWasOptionsLoaded = false; #if SDL_VERSION_ATLEAST(2, 0, 0) bool HardwareCursorSupported() @@ -354,12 +353,13 @@ void LoadOptions() if (demo::IsRunning()) demo::OverrideOptions(); - - sbWasOptionsLoaded = true; } void SaveOptions() { + if (demo::IsRunning()) + return; + for (OptionCategoryBase *pCategory : sgOptions.GetCategories()) { for (OptionEntryBase *pEntry : pCategory->GetEntries()) { pEntry->SaveToIni(pCategory->GetKey()); diff --git a/Source/options.h b/Source/options.h index 805dd76f5..9176233a4 100644 --- a/Source/options.h +++ b/Source/options.h @@ -605,7 +605,6 @@ struct Options { }; extern DVL_API_FOR_TEST Options sgOptions; -extern bool sbWasOptionsLoaded; bool HardwareCursorSupported();