diff --git a/nx/include/switch/applets/error.h b/nx/include/switch/applets/error.h index bd169919..6f8f78ca 100644 --- a/nx/include/switch/applets/error.h +++ b/nx/include/switch/applets/error.h @@ -10,11 +10,7 @@ /// Error configuration struct. typedef struct { - u32 major_code; ///< First part of the error code. - u32 minor_code; ///< Second part of the error code. - bool custom_text; ///< Whether to display a custom error message. - char* short_description; ///< Short description of the error. - char* detailed_description; ///< More detailed description of the error. Shown when the user clicks on "Details". + u8 args[0x1018]; } ErrorConfig; /** diff --git a/nx/source/applets/error.cpp b/nx/source/applets/error.cpp index 1bf30f2d..0305ea61 100644 --- a/nx/source/applets/error.cpp +++ b/nx/source/applets/error.cpp @@ -7,20 +7,16 @@ #include "applets/error.h" void errorCreate(ErrorConfig* c) { - c->major_code = 2000; - c->minor_code = 0; - c->custom_text = false; + memset(c->args, 0, 0x1018); - c->detailed_description = (char*) malloc(sizeof(char) * (strlen("") + 1)); - strcpy(c->detailed_description, ""); - - c->short_description = (char*) malloc(sizeof(char) * (strlen("") + 1)); - strcpy(c->short_description, ""); + c->args[0x0] = 0; + *(u64*) &c->args[0x8] = 2000; + *(u64*) &c->args[0xC] = 0; + strcpy((char*) &c->args[0x18], ""); + strcpy((char*) &c->args[0x818], ""); } void errorClose(ErrorConfig* c) { - free(c->short_description); - free(c->detailed_description); memset(c, 0, sizeof(ErrorConfig)); } @@ -34,15 +30,7 @@ void errorShow(ErrorConfig* c) { libappletArgsPush(&errArgs, &err); appletCreateStorage(&errStor, 4120); - - u8 args[0x1018] = {0}; - args[0] = (c->custom_text ? 1 : 0); - - *(u64*) &args[8] = c->major_code; - *(u64*) &args[0xC] = c->minor_code; - strcpy((char*) &args[0x18], c->short_description); - strcpy((char*) &args[0x818], c->detailed_description); - appletStorageWrite(&errStor, 0, args, 0x1018); + appletStorageWrite(&errStor, 0, c->args, 0x1018); appletHolderPushInData(&err, &errStor); @@ -51,26 +39,22 @@ void errorShow(ErrorConfig* c) { appletHolderClose(&err); } -void errorConfigSetMajorCode(ErrorConfig* c, u32 code) { - c->major_code = code; +void errorConfigSetMajorCode(ErrorConfig* c, u64 code) { + *(u64*) &c->args[0x8] = code; } -void errorConfigSetMinorCode(ErrorConfig* c, u32 code) { - c->minor_code = code; +void errorConfigSetMinorCode(ErrorConfig* c, u64 code) { + *(u64*) &c->args[0xC] = code; } void errorConfigSetCustomText(ErrorConfig* c, bool customText) { - c->custom_text = customText; + c->args[0x0] = customText; } void errorConfigSetShortDescription(ErrorConfig* c, const char* str) { - free(c->short_description); - c->short_description = (char*) malloc(sizeof(char) * (strlen(str) + 1)); - strcpy(c->short_description, str); + strcpy((char*) &c->args[0x18], str); } void errorConfigSetDetailedDescription(ErrorConfig* c, const char* str) { - free(c->detailed_description); - c->detailed_description = (char*) malloc(sizeof(char) * (strlen(str) + 1)); - strcpy(c->detailed_description, str); + strcpy((char*) &c->args[0x818], str); }