Skip to content

Commit 9189320

Browse files
committed
fix installing from CDN files
1 parent 896d548 commit 9189320

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

arm9/source/utils/gameutil.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ u32 UninstallGameDataTie(const char* path, bool remove_tie, bool remove_ticket,
14941494
}
14951495

14961496
u32 InstallCiaContent(const char* drv, const char* path_content, u32 offset, u32 size,
1497-
TmdContentChunk* chunk, const u8* title_id, const u8* titlekey, bool cxi_fix) {
1497+
TmdContentChunk* chunk, const u8* title_id, const u8* titlekey, bool cxi_fix, bool cdn_decrypt) {
14981498
char dest[256];
14991499

15001500
// create destination path and ensure it exists
@@ -1547,7 +1547,7 @@ u32 InstallCiaContent(const char* drv, const char* path_content, u32 offset, u32
15471547
for (u32 i = 0; (i < size) && (ret == 0); i += STD_BUFFER_SIZE) {
15481548
u32 read_bytes = min(STD_BUFFER_SIZE, (size - i));
15491549
if (fvx_read(&ofile, buffer, read_bytes, &bytes_read) != FR_OK) ret = 1;
1550-
if (cia_crypto && (DecryptCiaContentSequential(buffer, read_bytes, ctr_in, titlekey) != 0)) ret = 1;
1550+
if ((cia_crypto || cdn_decrypt) && (DecryptCiaContentSequential(buffer, read_bytes, ctr_in, titlekey) != 0)) ret = 1;
15511551
if ((i == 0) && cxi_fix && (SetNcchSdFlag(buffer) != 0)) ret = 1;
15521552
if (i == 0) sha_init(SHA256_MODE);
15531553
sha_update(buffer, read_bytes);
@@ -1820,7 +1820,7 @@ u32 InstallFromCiaFile(const char* path_cia, const char* path_dest) {
18201820
u16 index = getbe16(chunk->index);
18211821
if (!(cnt_index[index/8] & (1 << (7-(index%8))))) continue; // don't try to install missing contents
18221822
if (InstallCiaContent(path_dest, path_cia, next_offset, size,
1823-
chunk, title_id, titlekey, false) != 0) {
1823+
chunk, title_id, titlekey, false, false) != 0) {
18241824
free(cia);
18251825
return 1;
18261826
}
@@ -1926,6 +1926,8 @@ u32 BuildInstallFromTmdFileBuffered(const char* path_tmd, const char* path_dest,
19261926
free(ticket_tmp);
19271927
return 1;
19281928
}
1929+
memcpy(ticket->titlekey, ticket_tmp->titlekey, 0x10);
1930+
ticket->commonkey_idx = ticket_tmp->commonkey_idx;
19291931
free(ticket_tmp);
19301932
} else {
19311933
Ticket* ticket_tmp = NULL;
@@ -1983,7 +1985,7 @@ u32 BuildInstallFromTmdFileBuffered(const char* path_tmd, const char* path_dest,
19831985
return 1;
19841986
}
19851987
if (install && (InstallCiaContent(path_dest, path_content, 0, (u32) getbe64(chunk->size),
1986-
chunk, title_id, titlekey, false) != 0)) {
1988+
chunk, title_id, titlekey, false, cdn) != 0)) {
19871989
ShowPrompt(false, "ID %016llX.%08lX\nInstall content failed", getbe64(title_id), getbe32(chunk->id));
19881990
return 1;
19891991
}
@@ -2023,7 +2025,7 @@ u32 InstallFromTmdFile(const char* path_tmd, const char* path_dest) {
20232025
void* buffer = (void*) malloc(sizeof(CiaStub));
20242026
if (!buffer) return 1;
20252027

2026-
u32 ret = BuildInstallFromTmdFileBuffered(path_tmd, path_dest, false, true, buffer, true);
2028+
u32 ret = BuildInstallFromTmdFileBuffered(path_tmd, path_dest, true, true, buffer, true);
20272029

20282030
free(buffer);
20292031
return ret;
@@ -2088,7 +2090,7 @@ u32 BuildInstallFromNcchFile(const char* path_ncch, const char* path_dest, bool
20882090
TmdContentChunk* chunk = cia->content_list;
20892091
memset(chunk, 0, sizeof(TmdContentChunk)); // nothing else to do
20902092
if ((!install && (InsertCiaContent(path_dest, path_ncch, 0, 0, chunk, NULL, false, true, false) != 0)) ||
2091-
(install && (InstallCiaContent(path_dest, path_ncch, 0, 0, chunk, title_id, NULL, true) != 0))) {
2093+
(install && (InstallCiaContent(path_dest, path_ncch, 0, 0, chunk, title_id, NULL, true, false) != 0))) {
20922094
free(cia);
20932095
return 1;
20942096
}
@@ -2167,7 +2169,7 @@ u32 BuildInstallFromNcsdFile(const char* path_ncsd, const char* path_dest, bool
21672169
if ((!install && (InsertCiaContent(path_dest, path_ncsd,
21682170
offset, size, chunk++, NULL, false, (i == 0), false) != 0)) ||
21692171
(install && (InstallCiaContent(path_dest, path_ncsd,
2170-
offset, size, chunk++, title_id, NULL, (i == 0)) != 0))) {
2172+
offset, size, chunk++, title_id, NULL, (i == 0), false) != 0))) {
21712173
free(cia);
21722174
return 1;
21732175
}
@@ -2255,7 +2257,7 @@ u32 BuildInstallFromNdsFile(const char* path_nds, const char* path_dest, bool in
22552257
TmdContentChunk* chunk = cia->content_list;
22562258
memset(chunk, 0, sizeof(TmdContentChunk)); // nothing else to do
22572259
if ((!install && (InsertCiaContent(path_dest, path_nds, 0, 0, chunk, NULL, false, false, false) != 0)) ||
2258-
(install && (InstallCiaContent(path_dest, path_nds, 0, 0, chunk, title_id, NULL, false) != 0))) {
2260+
(install && (InstallCiaContent(path_dest, path_nds, 0, 0, chunk, title_id, NULL, false, false) != 0))) {
22592261
free(cia);
22602262
return 1;
22612263
}

0 commit comments

Comments
 (0)