From 9604b5923d9a11c115bd3550d806b5075cb9c512 Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Thu, 17 Mar 2022 20:29:44 +0100 Subject: [PATCH] romfs_dumper: get latest patch from linked list. --- code_templates/sd_romfs_dumper.c | 25 +++++++++++++++++++++++-- code_templates/usb_romfs_dumper.c | 25 +++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/code_templates/sd_romfs_dumper.c b/code_templates/sd_romfs_dumper.c index a0af8f5..bf48b84 100644 --- a/code_templates/sd_romfs_dumper.c +++ b/code_templates/sd_romfs_dumper.c @@ -357,6 +357,25 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) return (applet_status ? id_offset : (u8)program_count); } +static TitleInfo *get_latest_patch_info(TitleInfo *patch_info) +{ + if (!patch_info || patch_info->meta_key.type != NcmContentMetaType_Patch) return NULL; + + TitleInfo *output = patch_info, *tmp = patch_info; + u32 highest_version = patch_info->version.value; + + while((tmp = tmp->next) != NULL) + { + if (tmp->version.value > highest_version) + { + output = tmp; + highest_version = output->version.value; + } + } + + return output; +} + int main(int argc, char *argv[]) { int ret = 0; @@ -569,8 +588,10 @@ int main(int argc, char *argv[]) if (user_app_data.patch_info) { - if (!ncaInitializeContext(update_nca_ctx, user_app_data.patch_info->storage_id, (user_app_data.patch_info->storage_id == NcmStorageId_GameCard ? GameCardHashFileSystemPartitionType_Secure : 0), \ - titleGetContentInfoByTypeAndIdOffset(user_app_data.patch_info, NcmContentType_Program, program_id_offset), NULL)) + TitleInfo *latest_patch = get_latest_patch_info(user_app_data.patch_info); + + if (!ncaInitializeContext(update_nca_ctx, latest_patch->storage_id, (latest_patch->storage_id == NcmStorageId_GameCard ? GameCardHashFileSystemPartitionType_Secure : 0), \ + titleGetContentInfoByTypeAndIdOffset(latest_patch, NcmContentType_Program, program_id_offset), NULL)) { consolePrint("nca initialize update ctx failed\n"); goto out2; diff --git a/code_templates/usb_romfs_dumper.c b/code_templates/usb_romfs_dumper.c index 105fc7a..5068ae7 100644 --- a/code_templates/usb_romfs_dumper.c +++ b/code_templates/usb_romfs_dumper.c @@ -336,6 +336,25 @@ u8 get_program_id_offset(TitleInfo *info, u32 program_count) return (applet_status ? id_offset : (u8)program_count); } +static TitleInfo *get_latest_patch_info(TitleInfo *patch_info) +{ + if (!patch_info || patch_info->meta_key.type != NcmContentMetaType_Patch) return NULL; + + TitleInfo *output = patch_info, *tmp = patch_info; + u32 highest_version = patch_info->version.value; + + while((tmp = tmp->next) != NULL) + { + if (tmp->version.value > highest_version) + { + output = tmp; + highest_version = output->version.value; + } + } + + return output; +} + int main(int argc, char *argv[]) { int ret = 0; @@ -542,8 +561,10 @@ int main(int argc, char *argv[]) if (user_app_data.patch_info) { - if (!ncaInitializeContext(update_nca_ctx, user_app_data.patch_info->storage_id, (user_app_data.patch_info->storage_id == NcmStorageId_GameCard ? GameCardHashFileSystemPartitionType_Secure : 0), \ - titleGetContentInfoByTypeAndIdOffset(user_app_data.patch_info, NcmContentType_Program, program_id_offset), NULL)) + TitleInfo *latest_patch = get_latest_patch_info(user_app_data.patch_info); + + if (!ncaInitializeContext(update_nca_ctx, latest_patch->storage_id, (latest_patch->storage_id == NcmStorageId_GameCard ? GameCardHashFileSystemPartitionType_Secure : 0), \ + titleGetContentInfoByTypeAndIdOffset(latest_patch, NcmContentType_Program, program_id_offset), NULL)) { consolePrint("nca initialize update ctx failed\n"); goto out2;