diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 9c69eb4..188a524 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -345,15 +345,34 @@ void patchCode(u64 progId, u8 *code, u32 size) if(CONFIG_SHOWNAND) { static const u16 verPattern[] = u"Ver."; - const u32 currentNand = BOOTCONFIG(0, 3); - const u32 matchingFirm = BOOTCONFIG(2, 1) == (currentNand != 0); + const u32 currentNand = BOOTCFG_NAND; + const u32 matchingFirm = BOOTCFG_FIRM == (currentNand != 0); + + u16 *verString; + switch(currentNand) + { + case 1: + verString = matchingFirm ? u" Emu" : u"EmuS"; + break; + case 2: + verString = matchingFirm ? u"Emu2" : u"Em2S"; + break; + case 3: + verString = matchingFirm ? u"Emu3" : u"Em3S"; + break; + case 4: + verString = matchingFirm ? u"Emu4" : u"Em4S"; + break; + default: + verString = matchingFirm ? u" Sys" : u"SysE"; + break; + } //Patch Ver. string patchMemory(code, size, verPattern, sizeof(verPattern) - sizeof(u16), 0, - !currentNand ? ((matchingFirm) ? u" Sys" : u"SysE") : - ((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuS") : ((matchingFirm) ? u"Emu2" : u"Em2S")), + verString, sizeof(verPattern) - sizeof(u16), 1 ); } diff --git a/injector/source/patcher.h b/injector/source/patcher.h index dc48b1a..4f7b503 100644 --- a/injector/source/patcher.h +++ b/injector/source/patcher.h @@ -4,16 +4,16 @@ #define PATH_MAX 255 -#define CONFIG(a) (((info.config >> (a + 20)) & 1) != 0) -#define MULTICONFIG(a) ((info.config >> (a * 2 + 6)) & 3) +#define CONFIG(a) (((info.config >> (a + 21)) & 1) != 0) +#define MULTICONFIG(a) ((info.config >> (a * 2 + 7)) & 3) #define BOOTCONFIG(a, b) ((info.config >> a) & b) -#define BOOTCFG_NAND BOOTCONFIG(0, 3) -#define BOOTCFG_FIRM BOOTCONFIG(2, 1) -#define BOOTCFG_SAFEMODE BOOTCONFIG(5, 1) -#define CONFIG_NEWCPU MULTICONFIG(2) +#define BOOTCFG_NAND BOOTCONFIG(0, 7) +#define BOOTCFG_FIRM BOOTCONFIG(3, 1) +#define BOOTCFG_SAFEMODE BOOTCONFIG(6, 1) +#define CONFIG_NEWCPU MULTICONFIG(3) #define CONFIG_USESYSFIRM CONFIG(1) -#define CONFIG_USELANGEMUANDCODE CONFIG(3) -#define CONFIG_SHOWNAND CONFIG(4) +#define CONFIG_USELANGEMUANDCODE CONFIG(2) +#define CONFIG_SHOWNAND CONFIG(3) void patchCode(u64 progId, u8 *code, u32 size); \ No newline at end of file diff --git a/source/buttons.h b/source/buttons.h index 7c85fff..24c2adc 100644 --- a/source/buttons.h +++ b/source/buttons.h @@ -40,7 +40,8 @@ #define BUTTON_DOWN (1 << 7) #define SAFE_MODE (BUTTON_R1 | BUTTON_L1 | BUTTON_A | BUTTON_UP) -#define SINGLE_PAYLOAD_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN | BUTTON_START | BUTTON_X | BUTTON_Y) +#define SINGLE_PAYLOAD_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN | BUTTON_START | BUTTON_B | BUTTON_X | BUTTON_Y) #define L_PAYLOAD_BUTTONS (BUTTON_R1 | BUTTON_A | BUTTON_SELECT) +#define EMUNAND_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN) #define MENU_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN | BUTTON_A | BUTTON_START) #define PIN_BUTTONS (BUTTON_A | BUTTON_B | BUTTON_X | BUTTON_Y | BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN | BUTTON_START) \ No newline at end of file diff --git a/source/config.c b/source/config.c index 9dd0e32..006e253 100644 --- a/source/config.c +++ b/source/config.c @@ -71,13 +71,13 @@ void configMenu(bool oldPinStatus) drawString(CONFIG_TITLE, 10, 10, COLOR_TITLE); drawString("Press A to select, START to save", 10, 30, COLOR_WHITE); - const char *multiOptionsText[] = { "Screen brightness: 4( ) 3( ) 2( ) 1( )", + const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )", + "Screen brightness: 4( ) 3( ) 2( ) 1( )", "PIN lock: Off( ) 4( ) 6( ) 8( ) digits", "New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )" }; const char *singleOptionsText[] = { "( ) Autoboot SysNAND", "( ) Use SysNAND FIRM if booting with R (A9LH)", - "( ) Use second EmuNAND as default", "( ) Enable region/language emu. and ext. .code", "( ) Show current NAND in System Settings", "( ) Show GBA boot screen in patched AGB_FIRM", @@ -88,6 +88,7 @@ void configMenu(bool oldPinStatus) int posY; u32 enabled; } multiOptions[] = { + { .posXs = {19, 24, 29, 34} }, { .posXs = {21, 26, 31, 36} }, { .posXs = {14, 19, 24, 29} }, { .posXs = {17, 26, 32, 44} } @@ -201,7 +202,7 @@ void configMenu(bool oldPinStatus) drawCharacter(selected, 10 + multiOptions[selectedOption].posXs[oldEnabled] * SPACING_X, multiOptions[selectedOption].posY, COLOR_BLACK); multiOptions[selectedOption].enabled = oldEnabled == 3 ? 0 : oldEnabled + 1; - if(!selectedOption) updateBrightness(multiOptions[0].enabled); + if(selectedOption == 1) updateBrightness(multiOptions[1].enabled); } else { @@ -228,9 +229,9 @@ void configMenu(bool oldPinStatus) //Parse and write the new configuration for(u32 i = 0; i < multiOptionsAmount; i++) - configData.config |= multiOptions[i].enabled << (i * 2 + 6); + configData.config |= multiOptions[i].enabled << (i * 2 + 7); for(u32 i = 0; i < singleOptionsAmount; i++) - configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 20); + configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 21); if(CONFIG_PIN != 0) newPin(oldPinStatus && CONFIG_PIN == oldPinLength); else if(oldPinStatus) fileDelete(PIN_PATH); diff --git a/source/config.h b/source/config.h index 2209697..425ca76 100644 --- a/source/config.h +++ b/source/config.h @@ -24,26 +24,26 @@ #include "types.h" -#define CONFIG(a) (((configData.config >> (a + 20)) & 1) != 0) -#define MULTICONFIG(a) ((configData.config >> (a * 2 + 6)) & 3) +#define CONFIG(a) (((configData.config >> (a + 21)) & 1) != 0) +#define MULTICONFIG(a) ((configData.config >> (a * 2 + 7)) & 3) #define BOOTCONFIG(a, b) ((configData.config >> a) & b) #define CONFIG_PATH "/luma/config.bin" #define CONFIG_VERSIONMAJOR 1 -#define CONFIG_VERSIONMINOR 2 +#define CONFIG_VERSIONMINOR 3 -#define BOOTCFG_NAND BOOTCONFIG(0, 3) -#define BOOTCFG_FIRM BOOTCONFIG(2, 1) -#define BOOTCFG_A9LH BOOTCONFIG(3, 1) -#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(4, 1) -#define BOOTCFG_SAFEMODE BOOTCONFIG(5, 1) -#define CONFIG_BRIGHTNESS MULTICONFIG(0) -#define CONFIG_PIN MULTICONFIG(1) +#define BOOTCFG_NAND BOOTCONFIG(0, 7) +#define BOOTCFG_FIRM BOOTCONFIG(3, 1) +#define BOOTCFG_A9LH BOOTCONFIG(4, 1) +#define BOOTCFG_NOFORCEFLAG BOOTCONFIG(5, 1) +#define BOOTCFG_SAFEMODE BOOTCONFIG(6, 1) +#define CONFIG_DEFAULTEMU MULTICONFIG(0) +#define CONFIG_BRIGHTNESS MULTICONFIG(1) +#define CONFIG_PIN MULTICONFIG(2) #define CONFIG_AUTOBOOTSYS CONFIG(0) #define CONFIG_USESYSFIRM CONFIG(1) -#define CONFIG_USESECONDEMU CONFIG(2) -#define CONFIG_SHOWGBABOOT CONFIG(5) -#define CONFIG_PAYLOADSPLASH CONFIG(6) +#define CONFIG_SHOWGBABOOT CONFIG(4) +#define CONFIG_PAYLOADSPLASH CONFIG(5) typedef struct __attribute__((packed)) { diff --git a/source/emunand.c b/source/emunand.c index 93aff58..80915af 100644 --- a/source/emunand.c +++ b/source/emunand.c @@ -47,6 +47,8 @@ void locateEmuNand(u32 *emuHeader, FirmwareSource *emuNand) break; } + if(*emuNand != FIRMWARE_EMUNAND) nandOffset *= ((u32)*emuNand - 1); + //Check for RedNAND if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && *(u32 *)(temp + 0x100) == NCSD_MAGIC) { diff --git a/source/firm.c b/source/firm.c index eeb2df2..56719e3 100755 --- a/source/firm.c +++ b/source/firm.c @@ -98,7 +98,7 @@ void main(void) u32 pressed = HID_PAD; //Save old options and begin saving the new boot configuration - configTemp = (configData.config & 0xFFFFFFC0) | ((u32)isA9lh << 3); + configTemp = (configData.config & 0xFFFFFFC0) | ((u32)isA9lh << 4); //If it's a MCU reboot, try to force boot options if(isA9lh && CFG_BOOTENV) @@ -111,7 +111,7 @@ void main(void) needConfig = DONT_CONFIGURE; //Flag to prevent multiple boot options-forcing - configTemp |= 1 << 4; + configTemp |= 1 << 5; } /* Else, force the last used boot options unless a button is pressed @@ -146,7 +146,7 @@ void main(void) firmSource = FIRMWARE_SYSNAND; //Flag to tell loader to init SD - configTemp |= 1 << 5; + configTemp |= 1 << 6; //If the PIN has been verified, wait to make it easier to press the SAFE_MODE combo if(pinExists && !shouldLoadConfigMenu) @@ -161,7 +161,8 @@ void main(void) /* If L and R/A/Select or one of the single payload buttons are pressed, chainload an external payload */ - bool shouldLoadPayload = (pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS)); + bool shouldLoadPayload = ((pressed & SINGLE_PAYLOAD_BUTTONS) && !(pressed & (BUTTON_L1 | BUTTON_R1))) || + ((pressed & L_PAYLOAD_BUTTONS) && (pressed & BUTTON_L1)); if(shouldLoadPayload) loadPayload(pressed); @@ -187,7 +188,24 @@ void main(void) /* If we're booting emuNAND the second emuNAND is set as default and B isn't pressed, or vice-versa, boot the second emuNAND */ - if(nandType != FIRMWARE_SYSNAND && (CONFIG_USESECONDEMU == !(pressed & BUTTON_B))) nandType = FIRMWARE_EMUNAND2; + if(nandType == FIRMWARE_EMUNAND) + switch(pressed & EMUNAND_BUTTONS) + { + case BUTTON_UP: + break; + case BUTTON_RIGHT: + nandType = FIRMWARE_EMUNAND2; + break; + case BUTTON_DOWN: + nandType = FIRMWARE_EMUNAND3; + break; + case BUTTON_LEFT: + nandType = FIRMWARE_EMUNAND4; + break; + default: + nandType = (FirmwareSource)(1 + CONFIG_DEFAULTEMU); + break; + } } } } @@ -205,7 +223,7 @@ void main(void) if(!isFirmlaunch) { - configTemp |= (u32)nandType | ((u32)firmSource << 2); + configTemp |= (u32)nandType | ((u32)firmSource << 3); writeConfig(needConfig, configTemp); } diff --git a/source/fs.c b/source/fs.c index abd2bde..79d68fe 100644 --- a/source/fs.c +++ b/source/fs.c @@ -103,15 +103,16 @@ void loadPayload(u32 pressed) { const char *pattern; - if(pressed & BUTTON_RIGHT) pattern = PATTERN("right"); - else if(pressed & BUTTON_LEFT) pattern = PATTERN("left"); + if(pressed & BUTTON_LEFT) pattern = PATTERN("left"); + else if(pressed & BUTTON_RIGHT) pattern = PATTERN("right"); else if(pressed & BUTTON_UP) pattern = PATTERN("up"); else if(pressed & BUTTON_DOWN) pattern = PATTERN("down"); + else if(pressed & BUTTON_START) pattern = PATTERN("start"); + else if(pressed & BUTTON_B) pattern = PATTERN("b"); else if(pressed & BUTTON_X) pattern = PATTERN("x"); else if(pressed & BUTTON_Y) pattern = PATTERN("y"); else if(pressed & BUTTON_R1) pattern = PATTERN("r"); else if(pressed & BUTTON_A) pattern = PATTERN("a"); - else if(pressed & BUTTON_START) pattern = PATTERN("start"); else pattern = PATTERN("select"); DIR dir; diff --git a/source/types.h b/source/types.h index d5fd269..6b0e9ee 100644 --- a/source/types.h +++ b/source/types.h @@ -41,7 +41,9 @@ typedef enum FirmwareSource { FIRMWARE_SYSNAND = 0, FIRMWARE_EMUNAND = 1, - FIRMWARE_EMUNAND2 = 2 + FIRMWARE_EMUNAND2 = 2, + FIRMWARE_EMUNAND3 = 3, + FIRMWARE_EMUNAND4 = 4 } FirmwareSource; typedef enum FirmwareType