diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 15cc68fb6..78da8675f 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -15,7 +15,7 @@ namespace hex::plugin::builtin { /* General */ ContentRegistry::Settings::add("hex.builtin.setting.general", "hex.builtin.setting.general.show_tips", 1, [](auto name, nlohmann::json &setting) { - static bool enabled = setting.is_number() ? static_cast(setting) : 1; + static bool enabled = static_cast(setting); if (ImGui::Checkbox(name.data(), &enabled)) { setting = static_cast(enabled); @@ -28,7 +28,7 @@ namespace hex::plugin::builtin { /* Interface */ ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.color", 0, [](auto name, nlohmann::json &setting) { - static int selection = setting.is_number() ? static_cast(setting) : 0; + static int selection = static_cast(setting); const char* themes[] = { "hex.builtin.setting.interface.color.dark"_lang, @@ -45,7 +45,7 @@ namespace hex::plugin::builtin { }); ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.scaling", 0, [](auto name, nlohmann::json &setting) { - static int selection = setting.is_number() ? static_cast(setting) : 0; + static int selection = static_cast(setting); const char* scaling[] = { "hex.builtin.setting.interface.scaling.native"_lang, @@ -81,7 +81,7 @@ namespace hex::plugin::builtin { }(); static auto languageNames = [&]() { - std::vector result; + std::vector result(languages.size()); for (auto &[languageCode, languageName] : languages) result.push_back(languageName.c_str()); @@ -107,7 +107,7 @@ namespace hex::plugin::builtin { }); ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.fps", 60, [](auto name, nlohmann::json &setting) { - static int fps = setting.is_number() ? static_cast(setting) : 60; + static int fps = static_cast(setting); if (ImGui::SliderInt(name.data(), &fps, 15, 60)) { setting = fps; @@ -118,7 +118,7 @@ namespace hex::plugin::builtin { }); ContentRegistry::Settings::add("hex.builtin.setting.interface", "hex.builtin.setting.interface.highlight_alpha", 0x80, [](auto name, nlohmann::json &setting) { - static int alpha = setting.is_number() ? static_cast(setting) : 0x80; + static int alpha = static_cast(setting); if (ImGui::SliderInt(name.data(), &alpha, 0x00, 0xFF)) { setting = alpha; diff --git a/plugins/libimhex/source/api/content_registry.cpp b/plugins/libimhex/source/api/content_registry.cpp index d9dfdfc19..133049155 100644 --- a/plugins/libimhex/source/api/content_registry.cpp +++ b/plugins/libimhex/source/api/content_registry.cpp @@ -97,6 +97,9 @@ namespace hex { if (!json[unlocalizedCategory].contains(unlocalizedName)) return defaultValue; + if (!json[unlocalizedCategory][unlocalizedName].is_number()) + json[unlocalizedCategory][unlocalizedName] = defaultValue; + return json[unlocalizedCategory][unlocalizedName].get(); } @@ -108,6 +111,9 @@ namespace hex { if (!json[unlocalizedCategory].contains(unlocalizedName)) return defaultValue; + if (!json[unlocalizedCategory][unlocalizedName].is_string()) + json[unlocalizedCategory][unlocalizedName] = defaultValue; + return json[unlocalizedCategory][unlocalizedName].get(); } @@ -119,6 +125,9 @@ namespace hex { if (!json[unlocalizedCategory].contains(unlocalizedName)) return defaultValue; + if (!json[unlocalizedCategory][unlocalizedName].is_number()) + json[unlocalizedCategory][unlocalizedName] = defaultValue; + return json[unlocalizedCategory][unlocalizedName].get>(); } diff --git a/source/init/tasks.cpp b/source/init/tasks.cpp index d1f47872e..24effb2b7 100644 --- a/source/init/tasks.cpp +++ b/source/init/tasks.cpp @@ -304,8 +304,8 @@ namespace hex::init { { "Downloading information...", downloadInformation }, { "Creating directories...", createDirectories }, { "Loading default views...", loadDefaultViews }, - { "Loading plugins...", loadPlugins }, { "Loading settings...", loadSettings }, + { "Loading plugins...", loadPlugins }, { "Loading fonts...", loadFonts }, }; } diff --git a/source/window/window.cpp b/source/window/window.cpp index 9c5927719..f57fcd3eb 100644 --- a/source/window/window.cpp +++ b/source/window/window.cpp @@ -248,6 +248,7 @@ namespace hex { this->m_logoTexture = ImGui::LoadImageFromMemory(imhex_logo, imhex_logo_size); + ContentRegistry::Settings::store(); EventManager::post(); }