diff --git a/stratosphere/fs_mitm/source/fsmitm_utils.cpp b/stratosphere/fs_mitm/source/fsmitm_utils.cpp index f726357c6..c8791607a 100644 --- a/stratosphere/fs_mitm/source/fsmitm_utils.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_utils.cpp @@ -34,6 +34,9 @@ static std::atomic_bool g_has_hid_session = false; static u64 g_override_key_combination = KEY_R; static bool g_override_by_default = true; +/* Static buffer for loader.ini contents at runtime. */ +static char g_config_ini_data[0x800]; + static bool IsHexadecimal(const char *str) { while (*str) { if (isxdigit(*str)) { @@ -93,12 +96,7 @@ void Utils::InitializeSdThreadFunc(void *args) { fsDirClose(&titles_dir); } - FsFile config_file; - if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, "/atmosphere/loader.ini", FS_OPEN_READ, &config_file))) { - Utils::LoadConfiguration(&config_file); - fsFileClose(&config_file); - } - + Utils::RefreshConfiguration(); g_has_initialized = true; @@ -251,6 +249,9 @@ bool Utils::HasOverrideButton(u64 tid) { return true; } + /* Unconditionally refresh loader.ini contents. */ + RefreshConfiguration(); + u64 kDown = 0; bool keys_triggered = (R_SUCCEEDED(GetKeysDown(&kDown)) && ((kDown & g_override_key_combination) != 0)); return IsSdInitialized() && (g_override_by_default ^ keys_triggered); @@ -314,27 +315,26 @@ static int FsMitMIniHandler(void *user, const char *section, const char *name, c } -void Utils::LoadConfiguration(FsFile *f) { - if (f == NULL) { +void Utils::RefreshConfiguration() { + FsFile config_file; + if (R_FAILED(fsFsOpenFile(&g_sd_filesystem, "/atmosphere/loader.ini", FS_OPEN_READ, &config_file))) { return; } u64 size; - if (R_FAILED(fsFileGetSize(f, &size))) { + if (R_FAILED(fsFileGetSize(&config_file, &size))) { return; } size = std::min(size, (decltype(size))0x7FF); - char *config_str = new char[0x800]; - if (config_str != NULL) { - /* Read in string. */ - std::fill(config_str, config_str + 0x800, 0); - size_t r_s; - fsFileRead(f, 0, config_str, size, &r_s); + /* Read in string. */ + std::fill(g_config_ini_data, g_config_ini_data + 0x800, 0); + size_t r_s; + fsFileRead(&config_file, 0, g_config_ini_data, size, &r_s); + + ini_parse_string(g_config_ini_data, FsMitMIniHandler, NULL); - ini_parse_string(config_str, FsMitMIniHandler, NULL); - - delete[] config_str; - } + + fsFileClose(&config_file); } \ No newline at end of file diff --git a/stratosphere/fs_mitm/source/fsmitm_utils.hpp b/stratosphere/fs_mitm/source/fsmitm_utils.hpp index 77b9d20bc..42d547481 100644 --- a/stratosphere/fs_mitm/source/fsmitm_utils.hpp +++ b/stratosphere/fs_mitm/source/fsmitm_utils.hpp @@ -45,5 +45,5 @@ class Utils { static Result GetKeysDown(u64 *keys); static bool HasOverrideButton(u64 tid); private: - static void LoadConfiguration(FsFile *f); + static void RefreshConfiguration(); }; \ No newline at end of file diff --git a/stratosphere/loader/source/ldr_content_management.cpp b/stratosphere/loader/source/ldr_content_management.cpp index 93ebb8812..2d5850016 100644 --- a/stratosphere/loader/source/ldr_content_management.cpp +++ b/stratosphere/loader/source/ldr_content_management.cpp @@ -40,6 +40,9 @@ static u64 g_override_key_combination = KEY_R; static bool g_override_by_default = true; static u64 g_override_hbl_tid = 0x010000000000100D; +/* Static buffer for loader.ini contents at runtime. */ +static char g_config_ini_data[0x800]; + Result ContentManagement::MountCode(u64 tid, FsStorageId sid) { char path[FS_MAX_PATH] = {0}; Result rc; @@ -49,6 +52,10 @@ Result ContentManagement::MountCode(u64 tid, FsStorageId sid) { TryMountSdCard(); } + if (g_has_initialized_fs_dev) { + RefreshConfigurationData(); + } + if (ShouldOverrideContents() && R_SUCCEEDED(MountCodeNspOnSd(tid))) { return 0x0; } @@ -259,23 +266,17 @@ static int LoaderIniHandler(void *user, const char *section, const char *name, c return 1; } -void ContentManagement::LoadConfiguration(FILE *config) { +void ContentManagement::RefreshConfigurationData() { + FILE *config = fopen("sdmc:/atmosphere/loader.ini", "r"); if (config == NULL) { return; } - char *config_str = new char[0x800]; - if (config_str != NULL) { - /* Read in string. */ - std::fill(config_str, config_str + 0x800, 0); - fread(config_str, 1, 0x7FF, config); - - ini_parse_string(config_str, LoaderIniHandler, NULL); - - delete[] config_str; - } - + std::fill(g_config_ini_data, g_config_ini_data + 0x800, 0); + fread(g_config_ini_data, 1, 0x7FF, config); fclose(config); + + ini_parse_string(g_config_ini_data, LoaderIniHandler, NULL); } void ContentManagement::TryMountSdCard() { @@ -292,7 +293,6 @@ void ContentManagement::TryMountSdCard() { } if (R_SUCCEEDED(fsdevMountSdmc())) { - ContentManagement::LoadConfiguration(fopen("sdmc:/atmosphere/loader.ini", "r")); g_has_initialized_fs_dev = true; } } diff --git a/stratosphere/loader/source/ldr_content_management.hpp b/stratosphere/loader/source/ldr_content_management.hpp index c241092a4..92ce721e2 100644 --- a/stratosphere/loader/source/ldr_content_management.hpp +++ b/stratosphere/loader/source/ldr_content_management.hpp @@ -34,6 +34,7 @@ class ContentManagement { static bool HasCreatedTitle(u64 tid); static void SetCreatedTitle(u64 tid); + static void RefreshConfigurationData(); static void LoadConfiguration(FILE *config); static void TryMountSdCard();