fix handling of contents whose index and ID are unrelated

This commit is contained in:
aspargas2 2020-07-26 14:12:48 -04:00 committed by d0k3
parent 24d2a4ea5b
commit 9766a0be5e
2 changed files with 6 additions and 6 deletions

View File

@ -5,7 +5,7 @@ CmdHeader* BuildAllocCmdData(TitleMetaData* tmd) {
CmdHeader proto; CmdHeader proto;
CmdHeader* cmd = NULL; CmdHeader* cmd = NULL;
u32 content_count = getbe16(tmd->content_count); u32 content_count = getbe16(tmd->content_count);
u32 max_cnt_id = 0; u16 max_cnt_idx = 0;
// sanity check // sanity check
if (!content_count) if (!content_count)
@ -14,11 +14,11 @@ CmdHeader* BuildAllocCmdData(TitleMetaData* tmd) {
// find max content id // find max content id
TmdContentChunk* chunk = (TmdContentChunk*) (tmd + 1); TmdContentChunk* chunk = (TmdContentChunk*) (tmd + 1);
for (u32 i = 0; (i < content_count) && (i < TMD_MAX_CONTENTS); i++, chunk++) 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 // allocate memory for CMD / basic setup
proto.cmd_id = 1; proto.cmd_id = 1;
proto.n_entries = max_cnt_id + 1; proto.n_entries = max_cnt_idx + 1;
proto.n_cmacs = content_count; proto.n_cmacs = content_count;
proto.unknown = 1; proto.unknown = 1;
cmd = (CmdHeader*) malloc(CMD_SIZE(&proto)); cmd = (CmdHeader*) malloc(CMD_SIZE(&proto));
@ -33,7 +33,7 @@ CmdHeader* BuildAllocCmdData(TitleMetaData* tmd) {
memset(cnt_id, 0xFF, cmd->n_entries * sizeof(u32)); memset(cnt_id, 0xFF, cmd->n_entries * sizeof(u32));
for (u32 i = 0; (i < content_count) && (i < TMD_MAX_CONTENTS); i++, chunk++) { for (u32 i = 0; (i < content_count) && (i < TMD_MAX_CONTENTS); i++, chunk++) {
u32 chunk_id = getbe32(chunk->id); u32 chunk_id = getbe32(chunk->id);
cnt_id[chunk_id] = chunk_id; cnt_id[getbe16(chunk->index)] = chunk_id;
*(cnt_id_2nd++) = chunk_id; *(cnt_id_2nd++) = chunk_id;
} }

View File

@ -1950,14 +1950,14 @@ u32 BuildInstallFromNcsdFile(const char* path_ncsd, const char* path_dest, bool
// insert / install NCSD content // insert / install NCSD content
TmdContentChunk* chunk = cia->content_list; 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; NcchPartition* partition = ncsd.partitions + i;
u32 offset = partition->offset * NCSD_MEDIA_UNIT; u32 offset = partition->offset * NCSD_MEDIA_UNIT;
u32 size = partition->size * NCSD_MEDIA_UNIT; u32 size = partition->size * NCSD_MEDIA_UNIT;
if (!size) continue; if (!size) continue;
memset(chunk, 0, sizeof(TmdContentChunk)); memset(chunk, 0, sizeof(TmdContentChunk));
chunk->id[3] = i; chunk->id[3] = i;
chunk->index[1] = idx++; chunk->index[1] = i;
if ((!install && (InsertCiaContent(path_dest, path_ncsd, if ((!install && (InsertCiaContent(path_dest, path_ncsd,
offset, size, chunk++, NULL, false, (i == 0), false) != 0)) || offset, size, chunk++, NULL, false, (i == 0), false) != 0)) ||
(install && (InstallCiaContent(path_dest, path_ncsd, (install && (InstallCiaContent(path_dest, path_ncsd,