2020-10-03 18:09:29 +01:00
|
|
|
/*
|
|
|
|
* nacp.c
|
|
|
|
*
|
2022-03-17 12:58:40 +00:00
|
|
|
* Copyright (c) 2020-2022, DarkMatterCore <pabloacurielz@gmail.com>.
|
2020-10-03 18:09:29 +01:00
|
|
|
*
|
|
|
|
* This file is part of nxdumptool (https://github.com/DarkMatterCore/nxdumptool).
|
|
|
|
*
|
2021-03-25 19:26:58 +00:00
|
|
|
* nxdumptool is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-10-03 18:09:29 +01:00
|
|
|
*
|
2021-03-25 19:26:58 +00:00
|
|
|
* nxdumptool is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-10-03 18:09:29 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-03-25 19:26:58 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-10-03 18:09:29 +01:00
|
|
|
*/
|
|
|
|
|
2021-03-26 04:35:14 +00:00
|
|
|
#include "nxdt_utils.h"
|
2020-10-03 18:09:29 +01:00
|
|
|
#include "nacp.h"
|
|
|
|
#include "title.h"
|
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
/* Helper macros. */
|
|
|
|
|
|
|
|
#define NACP_ADD_FMT_STR_T1(fmt, ...) utilsAppendFormattedStringToBuffer(&xml_buf, &xml_buf_size, fmt, ##__VA_ARGS__)
|
|
|
|
#define NACP_ADD_FMT_STR_T2(fmt, ...) utilsAppendFormattedStringToBuffer(xml_buf, xml_buf_size, fmt, ##__VA_ARGS__)
|
|
|
|
#define NACP_ADD_STR(tag_name, value) nacpAddStringFieldToAuthoringToolXml(&xml_buf, &xml_buf_size, tag_name, value)
|
|
|
|
#define NACP_ADD_ENUM(tag_name, value, str_func) nacpAddEnumFieldToAuthoringToolXml(&xml_buf, &xml_buf_size, tag_name, value, \
|
|
|
|
&str_func)
|
|
|
|
#define NACP_ADD_BITFLAG(tag_name, flag, flag_width, max_flag_idx, str_func, allow_empty_str) nacpAddBitflagFieldToAuthoringToolXml(&xml_buf, &xml_buf_size, tag_name, flag, \
|
|
|
|
flag_width, max_flag_idx, &(str_func), \
|
|
|
|
allow_empty_str)
|
|
|
|
#define NACP_ADD_U16(tag_name, value, hex, prefix) nacpAddU16FieldToAuthoringToolXml(&xml_buf, &xml_buf_size, tag_name, value, hex, \
|
|
|
|
prefix)
|
|
|
|
#define NACP_ADD_U32(tag_name, value, hex, prefix) nacpAddU32FieldToAuthoringToolXml(&xml_buf, &xml_buf_size, tag_name, value, hex, \
|
|
|
|
prefix)
|
|
|
|
#define NACP_ADD_U64(tag_name, value, hex, prefix) nacpAddU64FieldToAuthoringToolXml(&xml_buf, &xml_buf_size, tag_name, value, hex, \
|
|
|
|
prefix)
|
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Type definitions. */
|
|
|
|
|
|
|
|
typedef const char *(*NacpStringFunction)(u8 value); /* Used while adding fields to the AuthoringTool-like XML. */
|
|
|
|
|
|
|
|
/* Global variables. */
|
|
|
|
|
|
|
|
static const char *g_unknownString = "Unknown";
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpLanguageStrings[NacpLanguage_Count] = {
|
|
|
|
"AmericanEnglish",
|
|
|
|
"BritishEnglish",
|
|
|
|
"Japanese",
|
|
|
|
"French",
|
|
|
|
"German",
|
|
|
|
"LatinAmericanSpanish",
|
|
|
|
"Spanish",
|
|
|
|
"Italian",
|
|
|
|
"Dutch",
|
|
|
|
"CanadianFrench",
|
|
|
|
"Portuguese",
|
|
|
|
"Russian",
|
|
|
|
"Korean",
|
|
|
|
"TraditionalChinese",
|
|
|
|
"SimplifiedChinese",
|
|
|
|
"BrazilianPortuguese"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpStartupUserAccountStrings[NacpStartupUserAccount_Count] = {
|
|
|
|
"None",
|
|
|
|
"Required",
|
|
|
|
"RequiredWithNetworkServiceAccountAvailable"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpUserAccountSwitchLockStrings[NacpUserAccountSwitchLock_Count] = {
|
|
|
|
"Disable",
|
|
|
|
"Enable"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpAddOnContentRegistrationTypeStrings[NacpAddOnContentRegistrationType_Count] = {
|
|
|
|
"AllOnLaunch",
|
|
|
|
"OnDemand"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpAttributeStrings[NacpAttribute_Count] = {
|
|
|
|
"Demo",
|
2022-03-18 16:48:16 +00:00
|
|
|
"RetailInteractiveDisplay",
|
|
|
|
"DownloadPlay"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpParentalControlStrings[NacpParentalControl_Count] = {
|
|
|
|
"FreeCommunication"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpScreenshotStrings[NacpScreenshot_Count] = {
|
|
|
|
"Allow",
|
|
|
|
"Deny"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpVideoCaptureStrings[NacpVideoCapture_Count] = {
|
|
|
|
"Disable",
|
|
|
|
"Manual",
|
|
|
|
"Enable"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpDataLossConfirmationStrings[NacpDataLossConfirmation_Count] = {
|
|
|
|
"None",
|
|
|
|
"Required"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpPlayLogPolicyStrings[NacpPlayLogPolicy_Count] = {
|
|
|
|
"Open",
|
|
|
|
"LogOnly",
|
|
|
|
"None",
|
|
|
|
"Closed"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpRatingAgeOrganizationStrings[NacpRatingAgeOrganization_Count] = {
|
|
|
|
"CERO",
|
|
|
|
"GRACGCRB",
|
|
|
|
"GSRMR",
|
|
|
|
"ESRB",
|
|
|
|
"ClassInd",
|
|
|
|
"USK",
|
|
|
|
"PEGI",
|
|
|
|
"PEGIPortugal",
|
|
|
|
"PEGIBBFC",
|
|
|
|
"Russian",
|
|
|
|
"ACB",
|
|
|
|
"OFLC",
|
|
|
|
"IARCGeneric"
|
2020-10-03 18:09:29 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpLogoTypeStrings[NacpLogoType_Count] = {
|
|
|
|
"LicensedByNintendo",
|
|
|
|
"DistributedByNintendo",
|
|
|
|
"Nintendo"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpLogoHandlingStrings[NacpLogoHandling_Count] = {
|
|
|
|
"Auto",
|
|
|
|
"Manual"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpRuntimeAddOnContentInstallStrings[NacpRuntimeAddOnContentInstall_Count] = {
|
|
|
|
"Deny",
|
|
|
|
"AllowAppend",
|
|
|
|
"AllowAppendButDontDownloadWhenUsingNetwork"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
static const char *g_nacpRuntimeParameterDeliveryStrings[NacpRuntimeParameterDelivery_Count] = {
|
2020-10-08 19:31:09 +01:00
|
|
|
"Always",
|
|
|
|
"AlwaysIfUserStateMatched",
|
|
|
|
"OnRestart"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
static const char *g_nacpAppropriateAgeForChinaStrings[NacpAppropriateAgeForChina_Count] = {
|
|
|
|
"None",
|
|
|
|
"Age8",
|
|
|
|
"Age12",
|
|
|
|
"Age16"
|
|
|
|
};
|
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
static const char *g_nacpUndecidedParameter75b8bStrings[NacpUndecidedParameter75b8b_Count] = {
|
|
|
|
"a",
|
|
|
|
"b"
|
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpCrashReportStrings[NacpCrashReport_Count] = {
|
|
|
|
"Deny",
|
|
|
|
"Allow"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpHdcpStrings[NacpHdcp_Count] = {
|
|
|
|
"None",
|
|
|
|
"Required"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpStartupUserAccountOptionStrings[NacpStartupUserAccountOption_Count] = {
|
|
|
|
"IsOptional"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
static const char *g_nacpRuntimeUpgradeStrings[NacpRuntimeUpgrade_Count] = {
|
|
|
|
"Deny",
|
|
|
|
"Allow"
|
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpPlayLogQueryCapabilityStrings[NacpPlayLogQueryCapability_Count] = {
|
|
|
|
"None",
|
|
|
|
"WhiteList",
|
|
|
|
"All"
|
2020-10-06 16:41:26 +01:00
|
|
|
};
|
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpRepairStrings[NacpRepair_Count] = {
|
|
|
|
"SuppressGameCardAccess"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpRequiredNetworkServiceLicenseOnLaunchStrings[NacpRequiredNetworkServiceLicenseOnLaunch_Count] = {
|
|
|
|
"Common"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpCrashScreenshotForProdStrings[NacpCrashScreenshotForProd_Count] = {
|
|
|
|
"Deny",
|
|
|
|
"Allow"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-08 19:31:09 +01:00
|
|
|
static const char *g_nacpCrashScreenshotForDevStrings[NacpCrashScreenshotForDev_Count] = {
|
|
|
|
"Deny",
|
|
|
|
"Allow"
|
2020-10-04 08:05:05 +01:00
|
|
|
};
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
static const char *g_nacpContentsAvailabilityTransitionPolicyStrings[NacpContentsAvailabilityTransitionPolicy_Count] = {
|
|
|
|
"NoPolicy",
|
|
|
|
"Stable",
|
|
|
|
"Changeable"
|
|
|
|
};
|
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Function prototypes. */
|
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
NX_INLINE bool nacpCheckBitflagField(const void *flag, u8 flag_bitcount, u8 idx);
|
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
static bool nacpAddStringFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, const char *value);
|
|
|
|
static bool nacpAddEnumFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u8 value, NacpStringFunction str_func);
|
2022-03-18 16:48:16 +00:00
|
|
|
static bool nacpAddBitflagFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, const void *flag, u8 flag_width, u8 max_flag_idx, NacpStringFunction str_func, bool allow_empty_str);
|
2021-09-26 22:59:41 +01:00
|
|
|
static bool nacpAddU16FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u16 value, bool hex, bool prefix);
|
|
|
|
static bool nacpAddU32FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u32 value, bool hex, bool prefix);
|
|
|
|
static bool nacpAddU64FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u64 value, bool hex, bool prefix);
|
2020-10-03 18:09:29 +01:00
|
|
|
|
|
|
|
bool nacpInitializeContext(NacpContext *out, NcaContext *nca_ctx)
|
|
|
|
{
|
2020-10-15 01:06:53 +01:00
|
|
|
if (!out || !nca_ctx || !*(nca_ctx->content_id_str) || nca_ctx->content_type != NcmContentType_Control || nca_ctx->content_size < NCA_FULL_HEADER_LENGTH || \
|
2020-10-03 18:09:29 +01:00
|
|
|
(nca_ctx->storage_id != NcmStorageId_GameCard && !nca_ctx->ncm_storage) || (nca_ctx->storage_id == NcmStorageId_GameCard && !nca_ctx->gamecard_offset) || \
|
2020-11-08 19:08:30 +00:00
|
|
|
nca_ctx->header.content_type != NcaContentType_Control || nca_ctx->content_type_ctx || !out)
|
2020-10-03 18:09:29 +01:00
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid parameters!");
|
2020-10-03 18:09:29 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
const char *language_str = NULL;
|
|
|
|
char icon_path[0x80] = {0};
|
|
|
|
RomFileSystemFileEntry *icon_entry = NULL;
|
|
|
|
NacpIconContext *tmp_icon_ctx = NULL;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
bool success = false;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Free output context beforehand. */
|
|
|
|
nacpFreeContext(out);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Initialize RomFS context. */
|
2022-07-04 13:30:48 +01:00
|
|
|
if (!romfsInitializeContext(&(out->romfs_ctx), &(nca_ctx->fs_ctx[0]), NULL))
|
2020-10-03 18:09:29 +01:00
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Failed to initialize RomFS context!");
|
2020-10-03 18:09:29 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Retrieve RomFS file entry for 'control.nacp'. */
|
|
|
|
if (!(out->romfs_file_entry = romfsGetFileEntryByPath(&(out->romfs_ctx), "/control.nacp")))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Failed to retrieve file entry for \"control.nacp\" from RomFS!");
|
2020-10-03 18:09:29 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-03-07 23:22:49 +00:00
|
|
|
//LOG_MSG("Found 'control.nacp' entry in Control NCA \"%s\".", nca_ctx->content_id_str);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Verify NACP size. */
|
|
|
|
if (out->romfs_file_entry->size != sizeof(_NacpStruct))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid NACP size!");
|
2020-10-03 18:09:29 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Allocate memory for the NACP data. */
|
2020-10-09 10:58:53 +01:00
|
|
|
if (!(out->data = malloc(sizeof(_NacpStruct))))
|
2020-10-03 18:09:29 +01:00
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Failed to allocate memory for the NACP data!");
|
2020-10-03 18:09:29 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Read NACP data into memory buffer. */
|
|
|
|
if (!romfsReadFileEntryData(&(out->romfs_ctx), out->romfs_file_entry, out->data, sizeof(_NacpStruct), 0))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Failed to read NACP data!");
|
2020-10-03 18:09:29 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Calculate SHA-256 checksum for the whole NACP. */
|
|
|
|
sha256CalculateHash(out->data_hash, out->data, sizeof(_NacpStruct));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Retrieve NACP icon data. */
|
2020-10-08 19:31:09 +01:00
|
|
|
for(u8 i = 0; i < NacpSupportedLanguage_Count; i++)
|
2020-10-03 18:09:29 +01:00
|
|
|
{
|
|
|
|
NacpIconContext *icon_ctx = NULL;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Get language string. */
|
|
|
|
language_str = nacpGetLanguageString(i);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-03-20 07:13:16 +00:00
|
|
|
/* Check if the current language is supported. */
|
|
|
|
if (!nacpCheckBitflagField(&(out->data->supported_language), sizeof(out->data->supported_language) * 8, i))
|
|
|
|
{
|
|
|
|
//LOG_MSG("\"%s\" language not supported (flag 0x%08X, index %u).", language_str, out->data->supported_language, i);
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Generate icon path. */
|
|
|
|
sprintf(icon_path, "/icon_%s.dat", language_str);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Retrieve RomFS file entry for this icon. */
|
2021-03-20 07:13:16 +00:00
|
|
|
if (!(icon_entry = romfsGetFileEntryByPath(&(out->romfs_ctx), icon_path)))
|
|
|
|
{
|
|
|
|
//LOG_MSG("\"%s\" file entry not found (flag 0x%08X, index %u).", icon_path, out->data->supported_language, i);
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Check icon size. */
|
|
|
|
if (!icon_entry->size || icon_entry->size > NACP_MAX_ICON_SIZE)
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid NACP icon size!");
|
2020-10-03 18:09:29 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Reallocate icon context buffer. */
|
|
|
|
if (!(tmp_icon_ctx = realloc(out->icon_ctx, (out->icon_count + 1) * sizeof(NacpIconContext))))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Failed to reallocate NACP icon context buffer!");
|
2020-10-03 18:09:29 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
out->icon_ctx = tmp_icon_ctx;
|
|
|
|
tmp_icon_ctx = NULL;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
icon_ctx = &(out->icon_ctx[out->icon_count]);
|
|
|
|
memset(icon_ctx, 0, sizeof(NacpIconContext));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Allocate memory for this icon data. */
|
|
|
|
if (!(icon_ctx->icon_data = malloc(icon_entry->size)))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Failed to allocate memory for NACP icon data!");
|
2020-10-03 18:09:29 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Read icon data. */
|
|
|
|
if (!romfsReadFileEntryData(&(out->romfs_ctx), icon_entry, icon_ctx->icon_data, icon_entry->size, 0))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Failed to read NACP icon data!");
|
2020-10-03 18:09:29 +01:00
|
|
|
goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Fill icon context. */
|
|
|
|
icon_ctx->language = i;
|
|
|
|
icon_ctx->icon_size = icon_entry->size;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Update icon count. */
|
|
|
|
out->icon_count++;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-21 05:27:48 +01:00
|
|
|
/* Update NCA context pointer in output context. */
|
|
|
|
out->nca_ctx = nca_ctx;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-21 05:27:48 +01:00
|
|
|
/* Update content type context info in NCA context. */
|
|
|
|
nca_ctx->content_type_ctx = out;
|
|
|
|
nca_ctx->content_type_ctx_patch = false;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
success = true;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
end:
|
|
|
|
if (!success) nacpFreeContext(out);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2021-06-01 02:12:15 +01:00
|
|
|
bool nacpGenerateNcaPatch(NacpContext *nacp_ctx, bool patch_sua, bool patch_screenshot, bool patch_video_capture, bool patch_hdcp)
|
2020-10-28 22:48:46 +00:00
|
|
|
{
|
|
|
|
if (!nacpIsValidContext(nacp_ctx))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid parameters!");
|
2020-10-28 22:48:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
_NacpStruct *data = nacp_ctx->data;
|
|
|
|
u8 nacp_hash[SHA256_HASH_SIZE] = {0};
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Check if we're not patching anything. */
|
2021-06-01 02:12:15 +01:00
|
|
|
if (!patch_sua && !patch_screenshot && !patch_video_capture && !patch_hdcp) return true;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Patch StartupUserAccount, StartupUserAccountOption and UserAccountSwitchLock. */
|
|
|
|
if (patch_sua)
|
|
|
|
{
|
|
|
|
data->startup_user_account = NacpStartupUserAccount_None;
|
|
|
|
data->startup_user_account_option &= ~NacpStartupUserAccountOption_IsOptional;
|
|
|
|
data->user_account_switch_lock = NacpUserAccountSwitchLock_Disable;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Patch Screenshot. */
|
|
|
|
if (patch_screenshot) data->screenshot = NacpScreenshot_Allow;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Patch VideoCapture. */
|
|
|
|
if (patch_video_capture) data->video_capture = NacpVideoCapture_Enable;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-06-01 02:12:15 +01:00
|
|
|
/* Patch Hdcp. */
|
|
|
|
if (patch_hdcp) data->hdcp = NacpHdcp_None;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Check if we really need to generate this patch. */
|
|
|
|
sha256CalculateHash(nacp_hash, data, sizeof(_NacpStruct));
|
|
|
|
if (!memcmp(nacp_hash, nacp_ctx->data_hash, sizeof(nacp_hash)))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Skipping NACP patching - no flags have changed.");
|
2020-10-28 22:48:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Generate RomFS file entry patch. */
|
|
|
|
if (!romfsGenerateFileEntryPatch(&(nacp_ctx->romfs_ctx), nacp_ctx->romfs_file_entry, data, sizeof(_NacpStruct), 0, &(nacp_ctx->nca_patch)))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Failed to generate RomFS file entry patch!");
|
2020-10-28 22:48:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Update NCA content type context patch status. */
|
|
|
|
nacp_ctx->nca_ctx->content_type_ctx_patch = true;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nacpWriteNcaPatch(NacpContext *nacp_ctx, void *buf, u64 buf_size, u64 buf_offset)
|
|
|
|
{
|
2020-11-08 19:08:30 +00:00
|
|
|
NcaContext *nca_ctx = NULL;
|
|
|
|
RomFileSystemFileEntryPatch *nca_patch = (nacp_ctx ? &(nacp_ctx->nca_patch) : NULL);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Using nacpIsValidContext() here would probably take up precious CPU cycles. */
|
2020-11-08 19:08:30 +00:00
|
|
|
if (!nca_patch || nca_patch->written || !(nca_ctx = nacp_ctx->nca_ctx) || nca_ctx->content_type != NcmContentType_Control || !nca_ctx->content_type_ctx_patch) return;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Attempt to write RomFS file entry patch. */
|
2020-11-08 19:08:30 +00:00
|
|
|
romfsWriteFileEntryPatchToMemoryBuffer(&(nacp_ctx->romfs_ctx), nca_patch, buf, buf_size, buf_offset);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-28 22:48:46 +00:00
|
|
|
/* Check if we need to update the NCA content type context patch status. */
|
2020-11-08 19:08:30 +00:00
|
|
|
if (nca_patch->written)
|
2020-10-28 22:48:46 +00:00
|
|
|
{
|
2020-11-08 19:08:30 +00:00
|
|
|
nca_ctx->content_type_ctx_patch = false;
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("NACP RomFS file entry patch successfully written to NCA \"%s\"!", nca_ctx->content_id_str);
|
2020-10-28 22:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
bool nacpGenerateAuthoringToolXml(NacpContext *nacp_ctx, u32 version, u32 required_system_version)
|
2020-10-03 18:09:29 +01:00
|
|
|
{
|
|
|
|
if (!nacpIsValidContext(nacp_ctx))
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid parameters!");
|
2020-10-03 18:09:29 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
_NacpStruct *nacp = nacp_ctx->data;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
Version app_ver = { .value = version };
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
u8 i = 0, count = 0;
|
|
|
|
char *xml_buf = NULL;
|
|
|
|
u64 xml_buf_size = 0;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
u8 icon_hash[SHA256_HASH_SIZE] = {0};
|
|
|
|
char icon_hash_str[SHA256_HASH_SIZE + 1] = {0};
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 07:00:18 +01:00
|
|
|
u8 null_key[0x10] = {0};
|
|
|
|
char key_str[0x21] = {0};
|
|
|
|
bool ndcc_sgc_available = false, ndcc_rgc_available = false;
|
|
|
|
NacpNeighborDetectionClientConfiguration *ndcc = &(nacp->neighbor_detection_client_configuration);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 07:00:18 +01:00
|
|
|
NacpRequiredAddOnContentsSetBinaryDescriptor *raocsbd = &(nacp->required_add_on_contents_set_binary_descriptor);
|
2022-03-18 16:48:16 +00:00
|
|
|
bool raocsbd_available = false;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
bool alrv_available = false;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
bool success = false;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Free AuthoringTool-like XML data if needed. */
|
|
|
|
if (nacp_ctx->authoring_tool_xml) free(nacp_ctx->authoring_tool_xml);
|
|
|
|
nacp_ctx->authoring_tool_xml = NULL;
|
|
|
|
nacp_ctx->authoring_tool_xml_size = 0;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" \
|
|
|
|
"<Application>\n")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Title. */
|
|
|
|
for(i = 0, count = 0; i < NacpLanguage_Count; i++)
|
|
|
|
{
|
2020-10-14 19:58:33 +01:00
|
|
|
NacpTitle *title = &(nacp->title[i]);
|
2020-10-15 01:06:53 +01:00
|
|
|
if (!*(title->name) || !*(title->publisher)) continue;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <Title>\n" \
|
|
|
|
" <Language>%s</Language>\n" \
|
|
|
|
" <Name>%s</Name>\n" \
|
|
|
|
" <Publisher>%s</Publisher>\n" \
|
|
|
|
" </Title>\n", \
|
|
|
|
nacpGetLanguageString(i), \
|
|
|
|
title->name, \
|
|
|
|
title->publisher)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
count++;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!count && !NACP_ADD_FMT_STR_T1(" <Title />\n")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Isbn. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_STR("Isbn", nacp->isbn)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* StartupUserAccount. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("StartupUserAccount", nacp->startup_user_account, nacpGetStartupUserAccountString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* StartupUserAccountOption. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_BITFLAG("StartupUserAccountOption", &(nacp->startup_user_account_option), sizeof(nacp->startup_user_account_option), NacpStartupUserAccountOption_Count, \
|
|
|
|
nacpGetStartupUserAccountOptionString, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* UserAccountSwitchLock. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("UserAccountSwitchLock", nacp->user_account_switch_lock, nacpGetUserAccountSwitchLockString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* Attribute. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_BITFLAG("Attribute", &(nacp->attribute), sizeof(nacp->attribute), NacpAttribute_Count, nacpGetAttributeString, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* ParentalControl. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_BITFLAG("ParentalControl", &(nacp->parental_control), sizeof(nacp->parental_control), NacpParentalControl_Count, nacpGetParentalControlString, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* SupportedLanguage. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_BITFLAG("SupportedLanguage", &(nacp->supported_language), sizeof(nacp->supported_language), NacpSupportedLanguage_Count, nacpGetLanguageString, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Screenshot. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("Screenshot", nacp->screenshot, nacpGetScreenshotString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* VideoCapture. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("VideoCapture", nacp->video_capture, nacpGetVideoCaptureString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* PresenceGroupId. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("PresenceGroupId", nacp->presence_group_id, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* DisplayVersion. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_STR("DisplayVersion", nacp->display_version)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* Rating. */
|
2020-10-03 18:09:29 +01:00
|
|
|
for(i = 0, count = 0; i < NacpRatingAgeOrganization_Count; i++)
|
|
|
|
{
|
2020-10-28 22:48:46 +00:00
|
|
|
s8 age = *(((s8*)&(nacp->rating_age)) + i);
|
|
|
|
if (age < 0) continue;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <Rating>\n" \
|
|
|
|
" <Organization>%s</Organization>\n" \
|
|
|
|
" <Age>%d</Age>\n" \
|
|
|
|
" </Rating>\n", \
|
|
|
|
nacpGetRatingAgeOrganizationString(i), \
|
|
|
|
age)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
count++;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!count && !NACP_ADD_FMT_STR_T1(" <Rating />\n")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* DataLossConfirmation. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("DataLossConfirmation", nacp->data_loss_confirmation, nacpGetDataLossConfirmationString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* PlayLogPolicy. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("PlayLogPolicy", nacp->play_log_policy, nacpGetPlayLogPolicyString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* SaveDataOwnerId. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("SaveDataOwnerId", nacp->save_data_owner_id, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* UserAccountSaveDataSize. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("UserAccountSaveDataSize", (u64)nacp->user_account_save_data_size, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* UserAccountSaveDataJournalSize. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("UserAccountSaveDataJournalSize", (u64)nacp->user_account_save_data_journal_size, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
/* UserAccountSaveDataTotalSize. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("UserAccountSaveDataTotalSize", (u64)(nacp->user_account_save_data_size + nacp->user_account_save_data_journal_size), true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* DeviceSaveDataSize. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("DeviceSaveDataSize", (u64)nacp->device_save_data_size, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* DeviceSaveDataJournalSize. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("DeviceSaveDataJournalSize", (u64)nacp->device_save_data_journal_size, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* BcatDeliveryCacheStorageSize. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("BcatDeliveryCacheStorageSize", (u64)nacp->bcat_delivery_cache_storage_size, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* ApplicationErrorCodeCategory. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_STR("ApplicationErrorCodeCategory", nacp->application_error_code_category)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* AddOnContentBaseId. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("AddOnContentBaseId", nacp->add_on_content_base_id, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* Version. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U32("Version", version, false, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
/* ReleaseVersion. */
|
|
|
|
if (!NACP_ADD_U32("ReleaseVersion", app_ver.application_version.release_ver, false, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
/* PrivateVersion. */
|
|
|
|
if (!NACP_ADD_U32("PrivateVersion", app_ver.application_version.private_ver, false, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* LogoType. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("LogoType", nacp->logo_type, nacpGetLogoTypeString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* RequiredSystemVersion. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U32("RequiredSystemVersion", required_system_version, false, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* LocalCommunicationId. */
|
2022-03-18 16:48:16 +00:00
|
|
|
for(i = 0; i < 0x8; i++)
|
2020-10-03 18:09:29 +01:00
|
|
|
{
|
|
|
|
if (!nacp->local_communication_id[i]) continue;
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("LocalCommunicationId", nacp->local_communication_id[i], true, true)) goto end;
|
2020-10-03 18:09:29 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* LogoHandling. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("LogoHandling", nacp->logo_handling, nacpGetLogoHandlingString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* Icon. */
|
|
|
|
for(i = 0, count = 0; i < nacp_ctx->icon_count; i++)
|
|
|
|
{
|
|
|
|
NacpIconContext *icon_ctx = &(nacp_ctx->icon_ctx[i]);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* Calculate icon hash. */
|
|
|
|
sha256CalculateHash(icon_hash, icon_ctx->icon_data, icon_ctx->icon_size);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* Generate icon hash string. Only the first half from the hash is used. */
|
2021-05-11 23:36:15 +01:00
|
|
|
utilsGenerateHexStringFromData(icon_hash_str, sizeof(icon_hash_str), icon_hash, sizeof(icon_hash) / 2, false);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* Add XML element. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <Icon>\n" \
|
|
|
|
" <Language>%s</Language>\n" \
|
|
|
|
/*" <IconPath />\n" \
|
|
|
|
" <NxIconPath />\n" \
|
|
|
|
" <RawIconHash />\n" \*/
|
|
|
|
" <NxIconHash>%s</NxIconHash>\n" \
|
|
|
|
" </Icon>\n", \
|
|
|
|
nacpGetLanguageString(icon_ctx->language), \
|
|
|
|
icon_hash_str)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
count++;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!count && !NACP_ADD_FMT_STR_T1(" <Icon />\n")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* HtmlDocumentPath, LegalInformationFilePath and AccessibleUrlsFilePath. Unused but kept anyway. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <HtmlDocumentPath UseEnvironmentVariable=\"false\" />\n" \
|
|
|
|
" <LegalInformationFilePath UseEnvironmentVariable=\"false\" />\n" \
|
|
|
|
" <AccessibleUrlsFilePath UseEnvironmentVariable=\"false\" />\n")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* SeedForPseudoDeviceId. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("SeedForPseudoDeviceId", nacp->seed_for_pseudo_device_id, true, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* BcatPassphrase. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_STR("BcatPassphrase", nacp->bcat_passphrase)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* AddOnContentRegistrationType. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("AddOnContentRegistrationType", nacp->add_on_content_registration_type, nacpGetAddOnContentRegistrationTypeString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* UserAccountSaveDataSizeMax. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("UserAccountSaveDataSizeMax", (u64)nacp->user_account_save_data_size_max, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* UserAccountSaveDataJournalSizeMax. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("UserAccountSaveDataJournalSizeMax", (u64)nacp->user_account_save_data_journal_size_max, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* DeviceSaveDataSizeMax. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("DeviceSaveDataSizeMax", (u64)nacp->device_save_data_size_max, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* DeviceSaveDataJournalSizeMax. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("DeviceSaveDataJournalSizeMax", (u64)nacp->device_save_data_journal_size_max, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* TemporaryStorageSize. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("TemporaryStorageSize", (u64)nacp->temporary_storage_size, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* CacheStorageSize. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("CacheStorageSize", (u64)nacp->cache_storage_size, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* CacheStorageJournalSize. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("CacheStorageJournalSize", (u64)nacp->cache_storage_journal_size, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* CacheStorageDataAndJournalSizeMax. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("CacheStorageDataAndJournalSizeMax", (u64)nacp->cache_storage_data_and_journal_size_max, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* CacheStorageIndexMax. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("CacheStorageIndexMax", (u64)nacp->cache_storage_index_max, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* Hdcp. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("Hdcp", nacp->hdcp, nacpGetHdcpString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* CrashReport. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("CrashReport", nacp->crash_report, nacpGetCrashReportString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
/* CrashScreenshotForProd. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("CrashScreenshotForProd", nacp->crash_screenshot_for_prod, nacpGetCrashScreenshotForProdString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
/* CrashScreenshotForDev. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("CrashScreenshotForDev", nacp->crash_screenshot_for_dev, nacpGetCrashScreenshotForDevString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* RuntimeAddOnContentInstall. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("RuntimeAddOnContentInstall", nacp->runtime_add_on_content_install, nacpGetRuntimeAddOnContentInstallString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* PlayLogQueryableApplicationId. */
|
2022-03-18 16:48:16 +00:00
|
|
|
for(i = 0; i < 0x10; i++)
|
2020-10-04 08:05:05 +01:00
|
|
|
{
|
|
|
|
if (!nacp->play_log_queryable_application_id[i]) continue;
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("PlayLogQueryableApplicationId", nacp->play_log_queryable_application_id[i], true, true)) goto end;
|
2020-10-04 08:05:05 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* PlayLogQueryCapability. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("PlayLogQueryCapability", nacp->play_log_query_capability, nacpGetPlayLogQueryCapabilityString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* Repair. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_BITFLAG("Repair", &(nacp->repair), sizeof(nacp->repair), NacpRepair_Count, nacpGetRepairString, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* ProgramIndex. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U16("ProgramIndex", nacp->program_index, false, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* RequiredNetworkServiceLicenseOnLaunch. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_BITFLAG("RequiredNetworkServiceLicenseOnLaunch", &(nacp->required_network_service_license_on_launch), sizeof(nacp->required_network_service_license_on_launch), \
|
|
|
|
NacpRequiredNetworkServiceLicenseOnLaunch_Count, nacpGetRequiredNetworkServiceLicenseOnLaunchString, false)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 07:00:18 +01:00
|
|
|
/* NeighborDetectionClientConfiguration. */
|
|
|
|
ndcc_sgc_available = (ndcc->send_group_configuration.group_id && memcmp(ndcc->send_group_configuration.key, null_key, sizeof(null_key)));
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 07:00:18 +01:00
|
|
|
for(i = 0; i < 0x10; i++)
|
|
|
|
{
|
|
|
|
ndcc_rgc_available = (ndcc->receivable_group_configurations[i].group_id && memcmp(ndcc->receivable_group_configurations[i].key, null_key, sizeof(null_key)));
|
|
|
|
if (ndcc_rgc_available) break;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 07:00:18 +01:00
|
|
|
if (ndcc_sgc_available || ndcc_rgc_available)
|
|
|
|
{
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <NeighborDetectionClientConfiguration>\n")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* SendGroupConfiguration. */
|
2021-05-11 23:36:15 +01:00
|
|
|
utilsGenerateHexStringFromData(key_str, sizeof(key_str), ndcc->send_group_configuration.key, sizeof(ndcc->send_group_configuration.key), false);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <SendGroupConfiguration>\n" \
|
|
|
|
" <GroupId>0x%016lx</GroupId>\n" \
|
|
|
|
" <Key>%s</Key>\n" \
|
|
|
|
" </SendGroupConfiguration>\n", \
|
|
|
|
ndcc->send_group_configuration.group_id, \
|
|
|
|
key_str)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* ReceivableGroupConfiguration. */
|
2020-10-06 07:00:18 +01:00
|
|
|
for(i = 0; i < 0x10; i++)
|
|
|
|
{
|
2020-10-14 19:58:33 +01:00
|
|
|
NacpApplicationNeighborDetectionGroupConfiguration *rgc = &(ndcc->receivable_group_configurations[i]);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-05-11 23:36:15 +01:00
|
|
|
utilsGenerateHexStringFromData(key_str, sizeof(key_str), rgc->key, sizeof(rgc->key), false);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <ReceivableGroupConfiguration>\n" \
|
|
|
|
" <GroupId>0x%016lx</GroupId>\n" \
|
|
|
|
" <Key>%s</Key>\n" \
|
|
|
|
" </ReceivableGroupConfiguration>\n", \
|
|
|
|
rgc->group_id, \
|
|
|
|
key_str)) goto end;
|
2020-10-06 07:00:18 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" </NeighborDetectionClientConfiguration>\n")) goto end;
|
2020-10-06 07:00:18 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* JitConfiguration. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <Jit>\n" \
|
|
|
|
" <IsEnabled>%s</IsEnabled>\n" \
|
|
|
|
" <MemorySize>%lu</MemorySize>\n" \
|
|
|
|
" </Jit>\n", \
|
|
|
|
(nacp->jit_configuration.jit_configuration_flag & NacpJitConfigurationFlag_Enabled) ? "true" : "false", \
|
|
|
|
nacp->jit_configuration.memory_size)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
/* History. */
|
|
|
|
//if (!NACP_ADD_FMT_STR_T1(" <History />\n")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
/* RuntimeParameterDelivery. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("RuntimeParameterDelivery", nacp->runtime_parameter_delivery, nacpGetRuntimeParameterDeliveryString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
/* AppropriateAgeForChina. */
|
|
|
|
if (!NACP_ADD_ENUM("AppropriateAgeForChina", nacp->appropriate_age_for_china, nacpGetAppropriateAgeForChina)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* RequiredAddOnContentsSet. */
|
2022-03-18 16:48:16 +00:00
|
|
|
for(i = 0; i < 0x20; i++)
|
2020-10-06 07:00:18 +01:00
|
|
|
{
|
2022-03-18 16:48:16 +00:00
|
|
|
NacpRequiredAddOnContentsSetDescriptor *descriptor = &(raocsbd->descriptors[i]);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (descriptor->index)
|
|
|
|
{
|
|
|
|
raocsbd_available = true;
|
|
|
|
break;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (descriptor->flag != NacpRequiredAddOnContentsSetDescriptorFlag_Continue) break;
|
2020-10-06 07:00:18 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (raocsbd_available)
|
|
|
|
{
|
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <RequiredAddOnContentsSet>\n")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
for(i = 0; i < 0x20; i++)
|
|
|
|
{
|
|
|
|
NacpRequiredAddOnContentsSetDescriptor *descriptor = &(raocsbd->descriptors[i]);
|
|
|
|
if (!descriptor->index) continue;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <Index>%u</Index>\n", descriptor->index)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (descriptor->flag != NacpRequiredAddOnContentsSetDescriptorFlag_Continue) break;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" </RequiredAddOnContentsSet>\n")) goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
/* PlayReportPermission. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <PlayReportPermission>\n" \
|
|
|
|
" <TargetMarketing>%s</TargetMarketing>\n" \
|
|
|
|
" </PlayReportPermission>\n", \
|
|
|
|
(nacp->play_report_permission & NacpPlayReportPermission_TargetMarketing) ? "Allow" : "Deny")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* AccessibleLaunchRequiredVersion. */
|
2022-03-18 16:48:16 +00:00
|
|
|
for(i = 0; i < 0x8; i++)
|
2020-10-04 08:05:05 +01:00
|
|
|
{
|
2022-03-18 16:48:16 +00:00
|
|
|
if (nacp->accessible_launch_required_version.application_id[i])
|
|
|
|
{
|
|
|
|
alrv_available = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (alrv_available)
|
|
|
|
{
|
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <AccessibleLaunchRequiredVersion>\n")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
for(i = 0; i < 0x8; i++)
|
|
|
|
{
|
|
|
|
u64 id = nacp->accessible_launch_required_version.application_id[i];
|
|
|
|
if (!id) continue;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <ApplicationId>0x%016lx</ApplicationId>\n", id)) goto end;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T1(" </AccessibleLaunchRequiredVersion>\n")) goto end;
|
|
|
|
} else {
|
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <AccessibleLaunchRequiredVersion />\n")) goto end;
|
2020-10-04 08:05:05 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
/* UndecidedParameter75b8b. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_ENUM("UndecidedParameter75b8b", nacp->undecided_parameter_75b8b, nacpGetUndecidedParameter75b8bString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* ApplicationId. */
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_U64("ApplicationId", nacp_ctx->nca_ctx->header.program_id, true, true)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
/* FilterDescriptionFilePath and CompressionFileConfigurationFilePath. */
|
|
|
|
/*if (!NACP_ADD_FMT_STR_T1(" <FilterDescriptionFilePath />\n" \
|
|
|
|
" <CompressionFileConfigurationFilePath />\n")) goto end;*/
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
/* ContentsAvailabilityTransitionPolicy. */
|
|
|
|
if (!NACP_ADD_ENUM("ContentsAvailabilityTransitionPolicy", nacp->contents_availability_transition_policy, nacpGetContentsAvailabilityTransitionPolicyString)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
/* LimitedLicenseSettings. */
|
|
|
|
if (!NACP_ADD_FMT_STR_T1(" <LimitedLicenseSettings>\n" \
|
|
|
|
" <RuntimeUpgrade>%s</RuntimeUpgrade>\n" \
|
|
|
|
" <SupportingLimitedLicenses>\n" \
|
|
|
|
" <LimitedLicense>%s</LimitedLicense>\n" \
|
|
|
|
" </SupportingLimitedLicenses>\n" \
|
|
|
|
" </LimitedLicenseSettings>\n", \
|
|
|
|
nacpGetRuntimeUpgradeString(nacp->runtime_upgrade), \
|
|
|
|
(nacp->supporting_limited_licenses & NacpSupportingLimitedLicenses_Demo) ? "Demo" : "None")) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!(success = NACP_ADD_FMT_STR_T1("</Application>"))) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
/* Update NACP context. */
|
|
|
|
nacp_ctx->authoring_tool_xml = xml_buf;
|
|
|
|
nacp_ctx->authoring_tool_xml_size = strlen(xml_buf);
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
end:
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
if (xml_buf) free(xml_buf);
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Failed to generate NACP AuthoringTool XML!");
|
2020-10-03 18:09:29 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetLanguageString(u8 language)
|
|
|
|
{
|
|
|
|
return (language < NacpLanguage_Count ? g_nacpLanguageStrings[language] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetStartupUserAccountString(u8 startup_user_account)
|
|
|
|
{
|
|
|
|
return (startup_user_account < NacpStartupUserAccount_Count ? g_nacpStartupUserAccountStrings[startup_user_account] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetUserAccountSwitchLockString(u8 user_account_switch_lock)
|
|
|
|
{
|
|
|
|
return (user_account_switch_lock < NacpUserAccountSwitchLock_Count ? g_nacpUserAccountSwitchLockStrings[user_account_switch_lock] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetAddOnContentRegistrationTypeString(u8 add_on_content_registration_type)
|
|
|
|
{
|
|
|
|
return (add_on_content_registration_type < NacpAddOnContentRegistrationType_Count ? g_nacpAddOnContentRegistrationTypeStrings[add_on_content_registration_type] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetAttributeString(u8 attribute)
|
|
|
|
{
|
|
|
|
return (attribute < NacpAttribute_Count ? g_nacpAttributeStrings[attribute] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetParentalControlString(u8 parental_control)
|
|
|
|
{
|
|
|
|
return (parental_control < NacpParentalControl_Count ? g_nacpParentalControlStrings[parental_control] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetScreenshotString(u8 screenshot)
|
|
|
|
{
|
|
|
|
return (screenshot < NacpScreenshot_Count ? g_nacpScreenshotStrings[screenshot] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetVideoCaptureString(u8 video_capture)
|
|
|
|
{
|
|
|
|
return (video_capture < NacpVideoCapture_Count ? g_nacpVideoCaptureStrings[video_capture] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetDataLossConfirmationString(u8 data_loss_confirmation)
|
|
|
|
{
|
|
|
|
return (data_loss_confirmation < NacpDataLossConfirmation_Count ? g_nacpDataLossConfirmationStrings[data_loss_confirmation] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetPlayLogPolicyString(u8 play_log_policy)
|
|
|
|
{
|
|
|
|
return (play_log_policy < NacpPlayLogPolicy_Count ? g_nacpPlayLogPolicyStrings[play_log_policy] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *nacpGetRatingAgeOrganizationString(u8 rating_age_organization)
|
|
|
|
{
|
|
|
|
return (rating_age_organization < NacpRatingAgeOrganization_Count ? g_nacpRatingAgeOrganizationStrings[rating_age_organization] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetLogoTypeString(u8 logo_type)
|
|
|
|
{
|
|
|
|
return (logo_type < NacpLogoType_Count ? g_nacpLogoTypeStrings[logo_type] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetLogoHandlingString(u8 logo_handling)
|
|
|
|
{
|
|
|
|
return (logo_handling < NacpLogoHandling_Count ? g_nacpLogoHandlingStrings[logo_handling] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetRuntimeAddOnContentInstallString(u8 runtime_add_on_content_install)
|
|
|
|
{
|
|
|
|
return (runtime_add_on_content_install < NacpRuntimeAddOnContentInstall_Count ? g_nacpRuntimeAddOnContentInstallStrings[runtime_add_on_content_install] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetRuntimeParameterDeliveryString(u8 runtime_parameter_delivery)
|
|
|
|
{
|
2021-09-26 22:59:41 +01:00
|
|
|
return (runtime_parameter_delivery < NacpRuntimeParameterDelivery_Count ? g_nacpRuntimeParameterDeliveryStrings[runtime_parameter_delivery] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
const char *nacpGetAppropriateAgeForChina(u8 appropriate_age_for_china)
|
|
|
|
{
|
|
|
|
return (appropriate_age_for_china < NacpAppropriateAgeForChina_Count ? g_nacpAppropriateAgeForChinaStrings[appropriate_age_for_china] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
const char *nacpGetUndecidedParameter75b8bString(u8 undecided_parameter_75b8b)
|
|
|
|
{
|
|
|
|
return (undecided_parameter_75b8b < NacpUndecidedParameter75b8b_Count ? g_nacpUndecidedParameter75b8bStrings[undecided_parameter_75b8b] : g_unknownString);
|
2020-10-04 08:05:05 +01:00
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetCrashReportString(u8 crash_report)
|
|
|
|
{
|
|
|
|
return (crash_report < NacpCrashReport_Count ? g_nacpCrashReportStrings[crash_report] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetHdcpString(u8 hdcp)
|
|
|
|
{
|
|
|
|
return (hdcp < NacpHdcp_Count ? g_nacpHdcpStrings[hdcp] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetStartupUserAccountOptionString(u8 startup_user_account_option)
|
|
|
|
{
|
|
|
|
return (startup_user_account_option < NacpStartupUserAccountOption_Count ? g_nacpStartupUserAccountOptionStrings[startup_user_account_option] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
const char *nacpGetRuntimeUpgradeString(u8 runtime_upgrade)
|
|
|
|
{
|
|
|
|
return (runtime_upgrade < NacpRuntimeUpgrade_Count ? g_nacpRuntimeUpgradeStrings[runtime_upgrade] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
const char *nacpGetPlayLogQueryCapabilityString(u8 play_log_query_capability)
|
|
|
|
{
|
|
|
|
return (play_log_query_capability < NacpPlayLogQueryCapability_Count ? g_nacpPlayLogQueryCapabilityStrings[play_log_query_capability] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetRepairString(u8 repair)
|
|
|
|
{
|
|
|
|
return (repair < NacpRepair_Count ? g_nacpRepairStrings[repair] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetRequiredNetworkServiceLicenseOnLaunchString(u8 required_network_service_license_on_launch)
|
|
|
|
{
|
|
|
|
return (required_network_service_license_on_launch < NacpRequiredNetworkServiceLicenseOnLaunch_Count ? \
|
|
|
|
g_nacpRequiredNetworkServiceLicenseOnLaunchStrings[required_network_service_license_on_launch] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetCrashScreenshotForProdString(u8 crash_screenshot_for_prod)
|
|
|
|
{
|
|
|
|
return (crash_screenshot_for_prod < NacpCrashScreenshotForProd_Count ? g_nacpCrashScreenshotForProdStrings[crash_screenshot_for_prod] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
const char *nacpGetCrashScreenshotForDevString(u8 crash_screenshot_for_dev)
|
|
|
|
{
|
|
|
|
return (crash_screenshot_for_dev < NacpCrashScreenshotForDev_Count ? g_nacpCrashScreenshotForDevStrings[crash_screenshot_for_dev] : g_unknownString);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
const char *nacpGetContentsAvailabilityTransitionPolicyString(u8 contents_availability_transition_policy)
|
|
|
|
{
|
|
|
|
return (contents_availability_transition_policy < NacpContentsAvailabilityTransitionPolicy_Count ? \
|
|
|
|
g_nacpContentsAvailabilityTransitionPolicyStrings[contents_availability_transition_policy] : g_unknownString);
|
|
|
|
}
|
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
NX_INLINE bool nacpCheckBitflagField(const void *flag, u8 flag_bitcount, u8 idx)
|
|
|
|
{
|
2022-07-02 11:09:49 +01:00
|
|
|
if (!flag || !IS_POWER_OF_TWO(flag_bitcount) || idx >= flag_bitcount) return false;
|
2020-10-04 08:05:05 +01:00
|
|
|
const u8 *flag_u8 = (const u8*)flag;
|
|
|
|
u8 byte_idx = (idx >> 3);
|
|
|
|
u8 bitmask = BIT(idx - ALIGN_DOWN(idx, 8));
|
|
|
|
return (flag_u8[byte_idx] & bitmask);
|
|
|
|
}
|
2020-10-03 18:09:29 +01:00
|
|
|
|
|
|
|
static bool nacpAddStringFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, const char *value)
|
|
|
|
{
|
2020-10-15 01:06:53 +01:00
|
|
|
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name || !value)
|
2020-10-04 08:05:05 +01:00
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid parameters!");
|
2020-10-04 08:05:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
return (*value ? NACP_ADD_FMT_STR_T2(" <%s>%s</%s>\n", tag_name, value, tag_name) : NACP_ADD_FMT_STR_T2(" <%s />\n", tag_name));
|
2020-10-03 18:09:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool nacpAddEnumFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u8 value, NacpStringFunction str_func)
|
|
|
|
{
|
2020-10-15 01:06:53 +01:00
|
|
|
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name || !str_func)
|
2020-10-04 08:05:05 +01:00
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid parameters!");
|
2020-10-04 08:05:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
return NACP_ADD_FMT_STR_T2(" <%s>%s</%s>\n", tag_name, str_func(value), tag_name);
|
2020-10-03 18:09:29 +01:00
|
|
|
}
|
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
static bool nacpAddBitflagFieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, const void *flag, u8 flag_width, u8 max_flag_idx, NacpStringFunction str_func, bool allow_empty_str)
|
2020-10-03 18:09:29 +01:00
|
|
|
{
|
2020-10-04 08:05:05 +01:00
|
|
|
u8 flag_bitcount = 0, i = 0, count = 0;
|
|
|
|
const u8 *flag_u8 = (const u8*)flag;
|
|
|
|
bool success = false, empty_flag = true;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-15 01:06:53 +01:00
|
|
|
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name || !flag || !flag_width || (flag_width > 1 && !IS_POWER_OF_TWO(flag_width)) || flag_width > 0x10 || \
|
2020-10-04 08:05:05 +01:00
|
|
|
(flag_bitcount = (flag_width * 8)) < max_flag_idx || !str_func)
|
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid parameters!");
|
2020-10-04 08:05:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
for(i = 0; i < flag_width; i++)
|
|
|
|
{
|
|
|
|
if (flag_u8[i])
|
|
|
|
{
|
|
|
|
empty_flag = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-04 08:05:05 +01:00
|
|
|
if (!empty_flag)
|
2020-10-03 18:09:29 +01:00
|
|
|
{
|
|
|
|
for(i = 0; i < max_flag_idx; i++)
|
|
|
|
{
|
2020-10-04 08:05:05 +01:00
|
|
|
if (!nacpCheckBitflagField(flag, flag_bitcount, i)) continue;
|
2022-03-18 16:48:16 +00:00
|
|
|
if (!NACP_ADD_FMT_STR_T2(" <%s>%s</%s>\n", tag_name, str_func(i), tag_name)) goto end;
|
2020-10-03 18:09:29 +01:00
|
|
|
count++;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
/* Edge case for new, unsupported flags. */
|
|
|
|
if (!count) empty_flag = true;
|
2020-10-03 18:09:29 +01:00
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
if (empty_flag && allow_empty_str && !NACP_ADD_FMT_STR_T2(" <%s />\n", tag_name)) goto end;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-06 16:41:26 +01:00
|
|
|
success = true;
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2020-10-03 18:09:29 +01:00
|
|
|
end:
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
static bool nacpAddU16FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u16 value, bool hex, bool prefix)
|
2020-10-03 18:09:29 +01:00
|
|
|
{
|
2020-10-15 01:06:53 +01:00
|
|
|
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name)
|
2020-10-04 08:05:05 +01:00
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid parameters!");
|
2020-10-04 08:05:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
const char *str = (hex ? (prefix ? " <%s>0x%04x</%s>\n" : " <%s>%04x</%s>\n") : " <%s>%u</%s>\n");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
return NACP_ADD_FMT_STR_T2(str, tag_name, value, tag_name);
|
2020-10-03 18:09:29 +01:00
|
|
|
}
|
2020-10-04 08:05:05 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
static bool nacpAddU32FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u32 value, bool hex, bool prefix)
|
2020-10-04 08:05:05 +01:00
|
|
|
{
|
2020-10-15 01:06:53 +01:00
|
|
|
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name)
|
2020-10-04 08:05:05 +01:00
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid parameters!");
|
2020-10-04 08:05:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
const char *str = (hex ? (prefix ? " <%s>0x%08x</%s>\n" : " <%s>%08x</%s>\n") : " <%s>%u</%s>\n");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
return NACP_ADD_FMT_STR_T2(str, tag_name, value, tag_name);
|
2020-10-06 16:41:26 +01:00
|
|
|
}
|
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
static bool nacpAddU64FieldToAuthoringToolXml(char **xml_buf, u64 *xml_buf_size, const char *tag_name, u64 value, bool hex, bool prefix)
|
2020-10-06 16:41:26 +01:00
|
|
|
{
|
2020-10-15 01:06:53 +01:00
|
|
|
if (!xml_buf || !xml_buf_size || !tag_name || !*tag_name)
|
2020-10-06 16:41:26 +01:00
|
|
|
{
|
2021-03-07 23:22:49 +00:00
|
|
|
LOG_MSG("Invalid parameters!");
|
2020-10-06 16:41:26 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2021-09-26 22:59:41 +01:00
|
|
|
const char *str = (hex ? (prefix ? " <%s>0x%016lx</%s>\n" : " <%s>%016lx</%s>\n") : " <%s>%lu</%s>\n");
|
2022-07-05 02:04:28 +01:00
|
|
|
|
2022-03-18 16:48:16 +00:00
|
|
|
return NACP_ADD_FMT_STR_T2(str, tag_name, value, tag_name);
|
2020-10-04 08:05:05 +01:00
|
|
|
}
|