From f6287086d31bd603b8ccc759fe379e9949fbec56 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Wed, 27 Mar 2019 22:37:37 -0400 Subject: [PATCH] Added errorResultShow/errorCodeShow. Updated ErrorCommonHeader and added ErrorPctlArg. --- nx/include/switch/applets/error.h | 30 +++++++++++++++++- nx/source/applets/error.c | 51 +++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/nx/include/switch/applets/error.h b/nx/include/switch/applets/error.h index 59a6e112..ccd7e0fc 100644 --- a/nx/include/switch/applets/error.h +++ b/nx/include/switch/applets/error.h @@ -20,7 +20,7 @@ typedef struct { u8 unk_x2[3]; u8 contextFlag; u8 resultFlag; ///< \ref ErrorCommonArg: When clear, errorCode is used, otherwise the applet generates the error-code from res. - u8 contextFlag2; ///< Same as contextFlag except for ErrorCommonArg? + u8 contextFlag2; ///< Similar to contextFlag except for ErrorCommonArg, indicating \ref ErrorContext is used. } ErrorCommonHeader; /// Error arg data for non-{System/Application}. @@ -30,6 +30,12 @@ typedef struct { Result res; } ErrorCommonArg; +/// Error arg data for certain errors with module PCTL. +typedef struct { + ErrorCommonHeader hdr; + Result res; +} ErrorPctlArg; + /// ResultBacktrace typedef struct { s32 count; @@ -79,6 +85,28 @@ typedef struct { ErrorContext ctx; } ErrorApplicationConfig; +/** + * @brief Launches the applet for displaying the specified Result. + * @param res Result + * @param jumpFlag Jump flag, normally this is true. + * @param ctx \ref ErrorContext, unused when jumpFlag=false. Ignored on pre-4.0.0, since it's only available for [4.0.0+]. + * @note Sets the following fields: jumpFlag and contextFlag2. Uses type=0 normally. + * @note For module=PCTL errors with desc 100-119 this sets \ref ErrorCommonHeader type=4, in which case the applet will display the following dialog (without the report logging mentioned below): "This software is restricted by Parental Controls". + * @warning This applet creates an error report that is logged in the system. Proceed at your own risk! + */ +Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx); + +/** + * @brief Launches the applet for displaying the specified ErrorCode. + * @param low The module portion of the error, normally this should be set to module + 2000. + * @param desc The error description. + * @param jumpFlag Jump flag, normally this is true. + * @param ctx \ref ErrorContext, unused when jumpFlag=false. Ignored on pre-4.0.0, since it's only available for [4.0.0+]. + * @note Sets the following fields: jumpFlag and contextFlag2. type=0 and resultFlag=1. + * @warning This applet creates an error report that is logged in the system. Proceed at your own risk! + */ +Result errorCodeShow(u32 low, u32 desc, bool jumpFlag, ErrorContext* ctx); + /** * @brief Creates an ErrorResultBacktrace struct. * @param backtrace \ref ErrorResultBacktrace struct. diff --git a/nx/source/applets/error.c b/nx/source/applets/error.c index f75a9929..a82e7725 100644 --- a/nx/source/applets/error.c +++ b/nx/source/applets/error.c @@ -76,6 +76,53 @@ static Result _errorShowContext(const void* indata, size_t insize, ErrorContext* return _errorShow(indata, insize, ctx_ptr, ctx_size); } +// {Result/Code}Show + +Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx) { + if (!jumpFlag) ctx = NULL; + ErrorCommonArg arg_common; + ErrorPctlArg arg_pctl; + ErrorCommonHeader *hdr = NULL; + bool flag = hosversionAtLeast(4,0,0) && ctx!=NULL; + bool argtype; + u32 tmp = R_DESCRIPTION(res); + + argtype = R_MODULE(res)==142 && tmp >= 100 && tmp <= 100+19; + if (!argtype) hdr = &arg_common.hdr; + if (argtype) hdr = &arg_pctl.hdr; + + memset(&arg_common, 0, sizeof(arg_common)); + memset(&arg_pctl, 0, sizeof(arg_pctl)); + + hdr->type = !argtype ? 0 : 4; + hdr->jumpFlag = jumpFlag!=0; + if (flag) hdr->contextFlag2 = 1; + + if (!argtype) { + arg_common.res = res; + return _errorShowContext(&arg_common, sizeof(arg_common), ctx); + } + else { + arg_pctl.res = res; + return _errorShowContext(&arg_pctl, sizeof(arg_pctl), ctx); + } +} + +Result errorCodeShow(u32 low, u32 desc, bool jumpFlag, ErrorContext* ctx) { + if (!jumpFlag) ctx = NULL; + bool flag = hosversionAtLeast(4,0,0) && ctx!=NULL; + ErrorCommonArg arg; + + memset(&arg, 0, sizeof(arg)); + arg.hdr.type = 0; + arg.hdr.jumpFlag = jumpFlag!=0; + if (flag) arg.hdr.contextFlag2 = 1; + arg.hdr.resultFlag = 1; + arg.errorCode = (u64)low | ((u64)desc<<32); + + return _errorShowContext(&arg, sizeof(arg), ctx); +} + // Backtrace Result errorResultBacktraceCreate(ErrorResultBacktrace* backtrace, s32 count, Result* entries) { @@ -144,6 +191,10 @@ Result errorSystemUpdateEulaShow(SetRegion RegionCode, ErrorEulaData* eula) { return rc; } +// Record + +//TODO + // System Result errorSystemCreate(ErrorSystemConfig* c, const char* dialog_message, const char* fullscreen_message) {