From 4dc96d37e84e341cf8e0aecc1a26c1e0f84b4004 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Fri, 23 Jul 2021 14:01:19 +0200 Subject: [PATCH] Fix #720 --- arm9/source/filesys/filetype.h | 2 +- arm9/source/godmode.c | 4 ++-- arm9/source/utils/gameutil.c | 16 ++++++++++++++++ arm9/source/utils/gameutil.h | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/arm9/source/filesys/filetype.h b/arm9/source/filesys/filetype.h index d6d929a..31b53a6 100644 --- a/arm9/source/filesys/filetype.h +++ b/arm9/source/filesys/filetype.h @@ -55,7 +55,7 @@ #define FTYPE_CIAINSTALL(tp) ((tp&(GAME_NCSD|GAME_NCCH|GAME_CIA|GAME_CDNTMD|GAME_TWLTMD)) || ((tp&GAME_NDS)&&(tp&(FLAG_DSIW)))) #define FTYPE_TIKINSTALL(tp) (tp&(GAME_TICKET)) #define FTYPE_TIKDUMP(tp) (tp&(GAME_TIE)) -#define FTYPE_CXIDUMP(tp) (tp&(GAME_TMD)) +#define FTYPE_CXIDUMP(tp) (tp&(GAME_TMD|GAME_TIE)) #define FTYPE_UNINSTALL(tp) (tp&(GAME_TIE)) #define FTYPE_TIKBUILD(tp) (tp&(GAME_TICKET|SYS_TICKDB|BIN_TIKDB)) #define FTYPE_KEYBUILD(tp) (tp&(BIN_KEYDB|BIN_LEGKEY)) diff --git a/arm9/source/godmode.c b/arm9/source/godmode.c index 94666ed..ab44658 100644 --- a/arm9/source/godmode.c +++ b/arm9/source/godmode.c @@ -1551,7 +1551,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan } DrawDirContents(current_dir, (*cursor = i), scroll); if (((user_select != cxi_dump) && (BuildCiaFromGameFile(path, force_legit) == 0)) || - ((user_select == cxi_dump) && (DumpCxiSrlFromTmdFile(path) == 0))) n_success++; + ((user_select == cxi_dump) && (DumpCxiSrlFromGameFile(path) == 0))) n_success++; else { // on failure: show error, continue char lpathstr[32+1]; TruncateString(lpathstr, path, 32, 8); @@ -1571,7 +1571,7 @@ u32 FileHandlerMenu(char* current_path, u32* cursor, u32* scroll, PaneData** pan } } else { if (((user_select != cxi_dump) && (BuildCiaFromGameFile(file_path, force_legit) == 0)) || - ((user_select == cxi_dump) && (DumpCxiSrlFromTmdFile(file_path) == 0))) { + ((user_select == cxi_dump) && (DumpCxiSrlFromGameFile(file_path) == 0))) { ShowPrompt(false, "%s\n%s built to %s", pathstr, type, OUTPUT_PATH); if (in_output_path) GetDirContents(current_dir, current_path); } else { diff --git a/arm9/source/utils/gameutil.c b/arm9/source/utils/gameutil.c index 2249e6c..b36b306 100644 --- a/arm9/source/utils/gameutil.c +++ b/arm9/source/utils/gameutil.c @@ -3020,6 +3020,22 @@ u32 DumpCxiSrlFromTmdFile(const char* path) { return 0; } +u32 DumpCxiSrlFromGameFile(const char* path) { + u64 filetype = IdentifyFileType(path); + const char* path_tmd = path; + char path_data[256]; + if (!(filetype & (GAME_TIE|GAME_TMD))) + return 1; + + if (filetype & GAME_TIE) { + if (GetTieTmdPath(path_data, path) != 0) + return 1; + path_tmd = path_data; + } + + return DumpCxiSrlFromTmdFile(path_tmd); +} + u32 ExtractCodeFromCxiFile(const char* path, const char* path_out, char* extstr) { u64 filetype = IdentifyFileType(path); char dest[256]; diff --git a/arm9/source/utils/gameutil.h b/arm9/source/utils/gameutil.h index 9fcfa9a..89ed407 100644 --- a/arm9/source/utils/gameutil.h +++ b/arm9/source/utils/gameutil.h @@ -9,7 +9,7 @@ u32 BuildCiaFromGameFile(const char* path, bool force_legit); u32 InstallGameFile(const char* path, bool to_emunand); u32 InstallTicketFile(const char* path, bool to_emunand); u32 DumpTicketForGameFile(const char* path, bool force_legit); -u32 DumpCxiSrlFromTmdFile(const char* path); +u32 DumpCxiSrlFromGameFile(const char* path); u32 ExtractCodeFromCxiFile(const char* path, const char* path_out, char* extstr); u32 CompressCode(const char* path, const char* path_out); u64 GetGameFileTrimmedSize(const char* path);