From 06060c67b5915a36f972a1f86f63a668c3123370 Mon Sep 17 00:00:00 2001 From: Aurora Date: Sun, 17 Apr 2016 18:57:25 +0200 Subject: [PATCH] Changed the chainloader to load payloads named "BUTTON_NAME.bin", to remember which payload is which. Original idea and code by @habbbe (many thanks!) --- injector/source/patcher.c | 4 +-- loader/source/buttons.h | 17 ++++++------ loader/source/fatfs/ffconf.h | 4 +-- loader/source/main.c | 52 ++++++++++++++++++++++-------------- source/fatfs/ffconf.h | 2 +- source/fs.c | 12 ++++----- source/fs.h | 2 +- source/loader.c | 2 +- 8 files changed, 53 insertions(+), 42 deletions(-) diff --git a/injector/source/patcher.c b/injector/source/patcher.c index db86fe1..a3a5b82 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -382,8 +382,8 @@ void patchCode(u64 progId, u8 *code, u32 size) patchMemory(code, size, verPattern, sizeof(verPattern) - sizeof(u16), 0, - !currentNand ? ((matchingFirm) ? u" Sys" : u"SysA") : - ((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuA") : ((matchingFirm) ? u"Emu2" : u"Em2A")), + !currentNand ? ((matchingFirm) ? u" Sys" : u"SysE") : + ((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuS") : ((matchingFirm) ? u"Emu2" : u"Em2S")), sizeof(verPattern) - sizeof(u16), 1 ); } diff --git a/loader/source/buttons.h b/loader/source/buttons.h index e6897e6..faace53 100644 --- a/loader/source/buttons.h +++ b/loader/source/buttons.h @@ -2,12 +2,11 @@ #include "types.h" -#define HID_PAD (*(vu32 *)0x10146000 ^ 0xFFF) -#define BUTTON_X (1 << 10) -#define BUTTON_Y (1 << 11) -#define BUTTON_R1 (1 << 8) -#define BUTTON_SELECT (1 << 2) -#define BUTTON_RIGHT (1 << 4) -#define BUTTON_LEFT (1 << 5) -#define BUTTON_UP (1 << 6) -#define BUTTON_DOWN (1 << 7) \ No newline at end of file +#define HID_PAD (*(vu32 *)0x10146000 ^ 0xFFF) +#define BUTTON_RIGHT (1 << 4) +#define BUTTON_LEFT (1 << 5) +#define BUTTON_UP (1 << 6) +#define BUTTON_DOWN (1 << 7) +#define BUTTON_X (1 << 10) +#define BUTTON_Y (1 << 11) +#define BUTTON_R1 (1 << 8) \ No newline at end of file diff --git a/loader/source/fatfs/ffconf.h b/loader/source/fatfs/ffconf.h index f3dacda..2d6d76d 100755 --- a/loader/source/fatfs/ffconf.h +++ b/loader/source/fatfs/ffconf.h @@ -15,7 +15,7 @@ / and optional writing functions as well. */ -#define _FS_MINIMIZE 3 +#define _FS_MINIMIZE 1 /* This option defines minimization level to remove some basic API functions. / / 0: All basic functions are enabled. @@ -34,7 +34,7 @@ / 2: Enable with LF-CRLF conversion. */ -#define _USE_FIND 0 +#define _USE_FIND 1 /* This option switches filtered directory read feature and related functions, / f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */ diff --git a/loader/source/main.c b/loader/source/main.c index f783184..57be0fd 100644 --- a/loader/source/main.c +++ b/loader/source/main.c @@ -3,23 +3,36 @@ #include "fatfs/ff.h" #define PAYLOAD_ADDRESS 0x23F00000 -#define PAYLOADS_FOLDER "/aurei/payloads/" -#define PAYLOAD_PATH(a) PAYLOADS_FOLDER a ".bin" +#define LOAD_PAYLOAD(a) loadPayload(a "_*.bin") -static u32 loadPayload(const char *path) +static u32 loadPayload(const char *pattern) { + char path[30] = "/aurei/payloads"; + + DIR dir; + FILINFO info = { .lfname = NULL }; + + FRESULT result = f_findfirst(&dir, &info, path, pattern); + + f_closedir(&dir); + + if(result != FR_OK || !info.fname[0]) + return 0; + + path[15] = '/'; + u32 i; + for(i = 0; info.fname[i]; i++) + path[16 + i] = info.fname[i]; + path[16 + i] = '\0'; + FIL payload; unsigned int br; - if(f_open(&payload, path, FA_READ) == FR_OK) - { - f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br); - f_close(&payload); + f_open(&payload, path, FA_READ); + f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br); + f_close(&payload); - return 1; - } - - return 0; + return 1; } void main(void) @@ -31,14 +44,13 @@ void main(void) //Get pressed buttons u32 pressed = HID_PAD; - if(((pressed & BUTTON_RIGHT) && loadPayload(PAYLOAD_PATH("right"))) || - ((pressed & BUTTON_LEFT) && loadPayload(PAYLOAD_PATH("left"))) || - ((pressed & BUTTON_UP) && loadPayload(PAYLOAD_PATH("up"))) || - ((pressed & BUTTON_DOWN) && loadPayload(PAYLOAD_PATH("down"))) || - ((pressed & BUTTON_X) && loadPayload(PAYLOAD_PATH("x"))) || - ((pressed & BUTTON_Y) && loadPayload(PAYLOAD_PATH("y"))) || - ((pressed & BUTTON_SELECT) && loadPayload(PAYLOAD_PATH("select"))) || - ((pressed & BUTTON_R1) && loadPayload(PAYLOAD_PATH("r"))) || - loadPayload(PAYLOAD_PATH("default"))) + if(((pressed & BUTTON_RIGHT) && LOAD_PAYLOAD("right")) || + ((pressed & BUTTON_LEFT) && LOAD_PAYLOAD("left")) || + ((pressed & BUTTON_UP) && LOAD_PAYLOAD("up")) || + ((pressed & BUTTON_DOWN) && LOAD_PAYLOAD("down")) || + ((pressed & BUTTON_X) && LOAD_PAYLOAD("x")) || + ((pressed & BUTTON_Y) && LOAD_PAYLOAD("y")) || + ((pressed & BUTTON_R1) && LOAD_PAYLOAD("r")) || + LOAD_PAYLOAD("def")) ((void (*)())PAYLOAD_ADDRESS)(); } diff --git a/source/fatfs/ffconf.h b/source/fatfs/ffconf.h index cf87256..6b6e12c 100755 --- a/source/fatfs/ffconf.h +++ b/source/fatfs/ffconf.h @@ -34,7 +34,7 @@ / 2: Enable with LF-CRLF conversion. */ -#define _USE_FIND 0 +#define _USE_FIND 1 /* This option switches filtered directory read feature and related functions, / f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */ diff --git a/source/fs.c b/source/fs.c index f5376bb..a660ebf 100644 --- a/source/fs.c +++ b/source/fs.c @@ -64,16 +64,16 @@ u32 fileSize(const char *path) return size; } -u32 fileExists(const char *path) +u32 defPayloadExists(void) { - FIL fp; - u32 exists = 0; + DIR dir; + FILINFO info = { .lfname = NULL }; - if(f_open(&fp, path, FA_READ) == FR_OK) exists = 1; + FRESULT result = f_findfirst(&dir, &info, "/aurei/payloads", "def_*.bin"); - f_close(&fp); + f_closedir(&dir); - return exists; + return (result == FR_OK && info.fname[0]); } void firmRead(void *dest, const char *firmFolder) diff --git a/source/fs.h b/source/fs.h index c25f204..e4e48a3 100644 --- a/source/fs.h +++ b/source/fs.h @@ -12,5 +12,5 @@ u32 mountFs(void); u32 fileRead(void *dest, const char *path, u32 size); u32 fileWrite(const void *buffer, const char *path, u32 size); u32 fileSize(const char *path); -u32 fileExists(const char *path); +u32 defPayloadExists(void); void firmRead(void *dest, const char *firmFolder); \ No newline at end of file diff --git a/source/loader.c b/source/loader.c index db33c8c..19c0de5 100644 --- a/source/loader.c +++ b/source/loader.c @@ -14,7 +14,7 @@ void loadPayload(void) { - if(fileExists("aurei/payloads/default.bin")) + if(defPayloadExists()) { initScreens(); memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size);