From 9766a0be5e90a14397324dd44c8de33637781698 Mon Sep 17 00:00:00 2001 From: aspargas2 Date: Sun, 26 Jul 2020 14:12:48 -0400 Subject: [PATCH] fix handling of contents whose index and ID are unrelated --- arm9/source/game/cmd.c | 8 ++++---- arm9/source/utils/gameutil.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arm9/source/game/cmd.c b/arm9/source/game/cmd.c index 24048a2..fbaa0fe 100644 --- a/arm9/source/game/cmd.c +++ b/arm9/source/game/cmd.c @@ -5,7 +5,7 @@ CmdHeader* BuildAllocCmdData(TitleMetaData* tmd) { CmdHeader proto; CmdHeader* cmd = NULL; u32 content_count = getbe16(tmd->content_count); - u32 max_cnt_id = 0; + u16 max_cnt_idx = 0; // sanity check if (!content_count) @@ -14,11 +14,11 @@ CmdHeader* BuildAllocCmdData(TitleMetaData* tmd) { // find max content id TmdContentChunk* chunk = (TmdContentChunk*) (tmd + 1); for (u32 i = 0; (i < content_count) && (i < TMD_MAX_CONTENTS); i++, chunk++) - if (getbe32(chunk->id) > max_cnt_id) max_cnt_id = getbe32(chunk->id); + if (getbe16(chunk->index) > max_cnt_idx) max_cnt_idx = getbe16(chunk->index); // allocate memory for CMD / basic setup proto.cmd_id = 1; - proto.n_entries = max_cnt_id + 1; + proto.n_entries = max_cnt_idx + 1; proto.n_cmacs = content_count; proto.unknown = 1; cmd = (CmdHeader*) malloc(CMD_SIZE(&proto)); @@ -33,7 +33,7 @@ CmdHeader* BuildAllocCmdData(TitleMetaData* tmd) { memset(cnt_id, 0xFF, cmd->n_entries * sizeof(u32)); for (u32 i = 0; (i < content_count) && (i < TMD_MAX_CONTENTS); i++, chunk++) { u32 chunk_id = getbe32(chunk->id); - cnt_id[chunk_id] = chunk_id; + cnt_id[getbe16(chunk->index)] = chunk_id; *(cnt_id_2nd++) = chunk_id; } diff --git a/arm9/source/utils/gameutil.c b/arm9/source/utils/gameutil.c index f76a8dd..2f5f713 100644 --- a/arm9/source/utils/gameutil.c +++ b/arm9/source/utils/gameutil.c @@ -1950,14 +1950,14 @@ u32 BuildInstallFromNcsdFile(const char* path_ncsd, const char* path_dest, bool // insert / install NCSD content TmdContentChunk* chunk = cia->content_list; - for (u32 i = 0, idx = 0; i < 3; i++) { + for (u32 i = 0; i < 3; i++) { NcchPartition* partition = ncsd.partitions + i; u32 offset = partition->offset * NCSD_MEDIA_UNIT; u32 size = partition->size * NCSD_MEDIA_UNIT; if (!size) continue; memset(chunk, 0, sizeof(TmdContentChunk)); chunk->id[3] = i; - chunk->index[1] = idx++; + chunk->index[1] = i; if ((!install && (InsertCiaContent(path_dest, path_ncsd, offset, size, chunk++, NULL, false, (i == 0), false) != 0)) || (install && (InstallCiaContent(path_dest, path_ncsd,