diff --git a/arm9/source/filesys/support.c b/arm9/source/filesys/support.c index 474237b..ae715d1 100644 --- a/arm9/source/filesys/support.c +++ b/arm9/source/filesys/support.c @@ -7,19 +7,25 @@ #define SUPPORT_DIR_PATHS "V:", "0:/gm9", "1:/gm9" -bool CheckSupportFile(const char* fname) +bool CheckSupportFile(const char* fname, size_t* fsize) { // try VRAM0 first - if (FindVTarFileInfo(fname, NULL)) + u64 tar_fsize; + if (FindVTarFileInfo(fname, &tar_fsize)) { + if (fsize) *fsize = tar_fsize; // truncated but should be fine for vtar return true; + } // try support file paths const char* base_paths[] = { SUPPORT_FILE_PATHS }; for (u32 i = 0; i < countof(base_paths); i++) { char path[256]; + FILINFO fno; snprintf(path, sizeof(path), "%s/%s", base_paths[i], fname); - if (fvx_stat(path, NULL) == FR_OK) + if (fvx_stat(path, &fno) == FR_OK) { + if (fsize) *fsize = fno.fsize; return true; + } } return false; diff --git a/arm9/source/filesys/support.h b/arm9/source/filesys/support.h index 26c1ba1..c9b03ad 100644 --- a/arm9/source/filesys/support.h +++ b/arm9/source/filesys/support.h @@ -8,7 +8,7 @@ #define LUASCRIPTS_DIR "luascripts" #define PAYLOADS_DIR "payloads" -bool CheckSupportFile(const char* fname); +bool CheckSupportFile(const char* fname, size_t* fsize); size_t LoadSupportFile(const char* fname, void* buffer, size_t max_len); bool SaveSupportFile(const char* fname, void* buffer, size_t len); bool SetAsSupportFile(const char* fname, const char* source); diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index c07a6bc..e1dd677 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -2164,18 +2164,20 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan return 0; } else if (user_select == font) { // set font - u8* font = (u8*) malloc(0x20000); // arbitrary, should be enough by far + size_t fsize = FileGetSize(file_path); + u8* font = (u8*) malloc(fsize); if (!font) return 1; - u32 font_size = FileGetData(file_path, font, 0x20000, 0); + u32 font_size = FileGetData(file_path, font, fsize, 0); if (font_size) SetFont(font, font_size); ClearScreenF(true, true, COLOR_STD_BG); free(font); return 0; } else if (user_select == translation) { // set translation - u8* translation = (u8*) malloc(0x20000); // arbitrary, should be enough by far + size_t fsize = FileGetSize(file_path); + u8* translation = (u8*) malloc(fsize); if (!translation) return 1; - u32 translation_size = FileGetData(file_path, translation, 0x20000, 0); + u32 translation_size = FileGetData(file_path, translation, fsize, 0); if (translation_size) SetLanguage(translation, translation_size); ClearScreenF(true, true, COLOR_STD_BG); free(translation); @@ -2442,17 +2444,18 @@ u32 GodMode(int entrypoint) { SetScreenBrightness(brightness); // custom font handling - if (CheckSupportFile("font.frf")) { - u8* riff = (u8*) malloc(0x20000); // arbitrary, should be enough by far + size_t support_size; + if (CheckSupportFile("font.frf", &support_size)) { + u8* riff = (u8*) malloc(support_size); if (riff) { - u32 riff_size = LoadSupportFile("font.frf", riff, 0x20000); + u32 riff_size = LoadSupportFile("font.frf", riff, support_size); if (riff_size) SetFont(riff, riff_size); free(riff); } - } else if (CheckSupportFile("font.pbm")) { - u8* pbm = (u8*) malloc(0x10000); // arbitrary, should be enough by far + } else if (CheckSupportFile("font.pbm", &support_size)) { + u8* pbm = (u8*) malloc(support_size); if (pbm) { - u32 pbm_size = LoadSupportFile("font.pbm", pbm, 0x10000); + u32 pbm_size = LoadSupportFile("font.pbm", pbm, support_size); if (pbm_size) SetFont(pbm, pbm_size); free(pbm); } @@ -2460,10 +2463,10 @@ u32 GodMode(int entrypoint) { // language handling bool language_loaded = false; - if (CheckSupportFile("language.trf")) { - char* translation = (char*) malloc(0x20000); // arbitrary, should be enough by far + if (CheckSupportFile("language.trf", &support_size)) { + char* translation = (char*) malloc(support_size); if (translation) { - u32 translation_size = LoadSupportFile("language.trf", translation, 0x20000); + u32 translation_size = LoadSupportFile("language.trf", translation, support_size); if (translation_size) language_loaded = SetLanguage(translation, translation_size); free(translation); }