Skip to content

Commit f4f46f9

Browse files
committed
Fix: load stored SelectedProfile in Use() instead of OnRegisterOverlay
1 parent 83e26df commit f4f46f9

1 file changed

Lines changed: 38 additions & 18 deletions

File tree

src/utils/settings.hpp

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "./bitwise.hpp"
1414
#include "./icons.hpp"
15+
#include "./log.hpp"
1516
#include "./mutex.hpp"
1617

1718
namespace renodx::utils::settings {
@@ -364,23 +365,6 @@ static void WriteGlobalString(const std::string& key, const std::string& value)
364365
// Runs first
365366
// https://pthom.github.io/imgui_manual_online/manual/imgui_manual.html
366367
static void OnRegisterOverlay(reshade::api::effect_runtime* runtime) {
367-
// Load last selected profile from reshade.ini (section [renodx], key SelectedProfile).
368-
// If the key is present, apply that preset on startup.
369-
{
370-
int stored_profile = preset_index;
371-
if (reshade::get_config_value(nullptr, global_name.c_str(), "SelectedProfile", stored_profile)) {
372-
if (stored_profile < 0) {
373-
stored_profile = 0;
374-
} else if (stored_profile >= static_cast<int>(preset_strings.size())) {
375-
stored_profile = static_cast<int>(preset_strings.size() - 1);
376-
}
377-
preset_index = stored_profile;
378-
if (preset_index != 0) {
379-
LoadSettings(GetCurrentPresetName());
380-
}
381-
}
382-
}
383-
384368
bool changed_preset = false;
385369
bool has_drawn_presets = !use_presets;
386370

@@ -675,7 +659,43 @@ static void Use(DWORD fdw_reason, Settings* new_settings, void (*new_on_preset_o
675659
on_preset_off_callbacks.emplace_back(new_on_preset_off);
676660
}
677661
LoadGlobalSettings();
678-
LoadSettings(global_name + "-preset1");
662+
663+
if (use_presets) {
664+
// Decide which preset to apply on startup
665+
int stored_profile = preset_index;
666+
const bool has_stored = reshade::get_config_value(nullptr, global_name.c_str(), "SelectedProfile", stored_profile);
667+
668+
if (!has_stored) {
669+
// No stored profile -> default to preset 1
670+
preset_index = 1;
671+
renodx::utils::log::d("utils::settings::Use(No SelectedProfile -> Defaulting to ", GetCurrentPresetName(), ")");
672+
LoadSettings(GetCurrentPresetName());
673+
} else {
674+
// Clamp stored value to valid range
675+
if (stored_profile < 0) {
676+
stored_profile = 0;
677+
} else if (stored_profile >= static_cast<int>(preset_strings.size())) {
678+
stored_profile = static_cast<int>(preset_strings.size() - 1);
679+
}
680+
preset_index = stored_profile;
681+
682+
if (preset_index == 0) {
683+
renodx::utils::log::d("utils::settings::Use(SelectedProfile=", preset_index, " -> Applying Off)");
684+
for (auto& callback : on_preset_off_callbacks) {
685+
callback();
686+
}
687+
} else {
688+
// Load the named preset section
689+
renodx::utils::log::d("utils::settings::Use(SelectedProfile=", preset_index, " -> Loading ", GetCurrentPresetName(), ")");
690+
LoadSettings(GetCurrentPresetName());
691+
}
692+
}
693+
} else {
694+
// Presets disabled — keep previous behavior (load preset1 by default)
695+
preset_index = 1;
696+
LoadSettings(global_name + "-preset1");
697+
}
698+
679699
reshade::register_overlay(overlay_title.c_str(), OnRegisterOverlay);
680700

681701
break;

0 commit comments

Comments
 (0)