diff --git a/source/core/util.c b/source/core/util.c index cc4af0b..c52f181 100644 --- a/source/core/util.c +++ b/source/core/util.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -52,7 +53,23 @@ static int util_get_lines(PrintConsole* console, const char* str) { return lines; } +static const devoptab_t* consoleStdOut = NULL; +static const devoptab_t* consoleStdErr = NULL; + +void util_store_console_std() { + consoleStdOut = devoptab_list[STD_OUT]; + consoleStdErr = devoptab_list[STD_ERR]; +} + void util_panic(const char* s, ...) { + if(consoleStdOut != NULL) { + devoptab_list[STD_OUT] = consoleStdOut; + } + + if(consoleStdErr != NULL) { + devoptab_list[STD_ERR] = consoleStdErr; + } + va_list list; va_start(list, s); diff --git a/source/core/util.h b/source/core/util.h index eeaa8f5..530466f 100644 --- a/source/core/util.h +++ b/source/core/util.h @@ -38,6 +38,7 @@ typedef struct { u16 animationSequence[0x40]; } BNR; +void util_store_console_std(); void util_panic(const char* s, ...); FS_Path* util_make_path_utf8(const char* path); diff --git a/source/main.c b/source/main.c index 33a3503..71533ce 100644 --- a/source/main.c +++ b/source/main.c @@ -1,4 +1,6 @@ +#include #include +#include #include <3ds.h> @@ -86,7 +88,21 @@ void init() { } if(R_FAILED(init_services())) { + const devoptab_t* oldStdOut = devoptab_list[STD_OUT]; + const devoptab_t* oldStdErr = devoptab_list[STD_ERR]; + + consoleInit(GFX_TOP, NULL); + util_store_console_std(); + + printf("Attempting to acquire kernel access..."); svchax_init(true); + + devoptab_list[STD_OUT] = oldStdOut; + devoptab_list[STD_ERR] = oldStdErr; + + gfxSetScreenFormat(GFX_TOP, GSP_BGR8_OES); + gfxSetDoubleBuffering(GFX_TOP, true); + if(!__ctr_svchax || !__ctr_svchax_srv) { util_panic("Failed to acquire kernel access."); return;