diff --git a/injector/source/patcher.c b/injector/source/patcher.c index 0d257fd..fdd4f9d 100644 --- a/injector/source/patcher.c +++ b/injector/source/patcher.c @@ -95,7 +95,7 @@ static void loadCFWInfo(void) svcGetCFWInfo(&info); IFile file; - if(BOOTCONFIG(5, 1) && R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ))) //Init SD card if SAFE_MODE is being booted + if(BOOTCFG_SAFEMODE && R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, "/", FS_OPEN_READ))) //Init SD card if SAFE_MODE is being booted IFile_Close(&file); infoLoaded = true; @@ -360,7 +360,7 @@ void patchCode(u64 progId, u8 *code, u32 size) ); //Apply only if the updated NAND hasn't been booted - if((BOOTCONFIG(0, 3) != 0) == (BOOTCONFIG(2, 1) && CONFIG(1))) + if((BOOTCFG_NAND != 0) == (BOOTCFG_FIRM != 0 && CONFIG_USESYSFIRM)) { static const u8 skipEshopUpdateCheckPattern[] = { 0x30, 0xB5, 0xF1, 0xB0 @@ -404,7 +404,7 @@ void patchCode(u64 progId, u8 *code, u32 size) case 0x0004001000027000LL: // KOR MSET case 0x0004001000028000LL: // TWN MSET { - if(CONFIG(4)) + if(CONFIG_SHOWNAND) { static const u16 verPattern[] = u"Ver."; const u32 currentNand = BOOTCONFIG(0, 3); @@ -440,7 +440,7 @@ void patchCode(u64 progId, u8 *code, u32 size) sizeof(stopCartUpdatesPatch), 2 ); - u32 cpuSetting = MULTICONFIG(2); + u32 cpuSetting = CONFIG_NEWCPU; if(cpuSetting) { @@ -540,7 +540,7 @@ void patchCode(u64 progId, u8 *code, u32 size) case 0x0004003000008A02LL: // ErrDisp { - if(MULTICONFIG(2) == 0) + if(CONFIG_DEVOPTIONS == 0) { static const u8 unitinfoCheckPattern1[] = { 0x14, 0x00, 0xD0, 0xE5, 0xDB @@ -572,7 +572,7 @@ void patchCode(u64 progId, u8 *code, u32 size) } default: - if(CONFIG(3)) + if(CONFIG_USELANGEMUANDCODE) { u32 tidHigh = (progId & 0xFFFFFFF000000000LL) >> 0x24; diff --git a/injector/source/patcher.h b/injector/source/patcher.h index e67e9e6..ce4f0fb 100644 --- a/injector/source/patcher.h +++ b/injector/source/patcher.h @@ -4,8 +4,17 @@ #define PATH_MAX 255 -#define CONFIG(a) (((info.config >> (a + 16)) & 1) != 0) +#define CONFIG(a) (((info.config >> (a + 20)) & 1) != 0) #define MULTICONFIG(a) ((info.config >> (a * 2 + 6)) & 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 CONFIG_DEVOPTIONS MULTICONFIG(3) +#define CONFIG_USESYSFIRM CONFIG(1) +#define CONFIG_USELANGEMUANDCODE CONFIG(3) +#define CONFIG_SHOWNAND CONFIG(4) + void patchCode(u64 progId, u8 *code, u32 size); \ No newline at end of file diff --git a/source/config.c b/source/config.c index 6d9cfe9..e920833 100644 --- a/source/config.c +++ b/source/config.c @@ -72,7 +72,7 @@ void configMenu(bool oldPinStatus) drawString("Press A to select, START to save", 10, 30, COLOR_WHITE); const char *multiOptionsText[] = { "Screen brightness: 4( ) 3( ) 2( ) 1( )", - "PIN length: 4( ) 5( ) 6( ) 7( )", + "PIN lock: Off( ) 4( ) 6( ) 8( ) digits", "New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )", "Dev. features: ErrDisp( ) UNITINFO( ) None( )" }; @@ -83,7 +83,6 @@ void configMenu(bool oldPinStatus) "( ) Show current NAND in System Settings", "( ) Show GBA boot screen in patched AGB_FIRM", "( ) Display splash screen before payloads", - "( ) Use a PIN", "( ) Patch SVC/service/archive/ARM9 access" }; struct multiOption { @@ -226,7 +225,7 @@ void configMenu(bool oldPinStatus) } } - u32 oldPinLength = MULTICONFIG(1); + u32 oldPinLength = CONFIG_PIN; //Preserve the last-used boot options (last 12 bits) configData.config &= 0x3F; @@ -235,9 +234,9 @@ void configMenu(bool oldPinStatus) for(u32 i = 0; i < multiOptionsAmount; i++) configData.config |= multiOptions[i].enabled << (i * 2 + 6); for(u32 i = 0; i < singleOptionsAmount; i++) - configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 16); + configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 20); - if(CONFIG(7)) newPin(oldPinStatus && MULTICONFIG(1) == oldPinLength); + if(CONFIG_PIN != 0) newPin(oldPinStatus && CONFIG_PIN == oldPinLength); else if(oldPinStatus) fileDelete(PIN_PATH); //Wait for the pressed buttons to change diff --git a/source/config.h b/source/config.h index 4a861eb..b5f223d 100644 --- a/source/config.h +++ b/source/config.h @@ -24,15 +24,28 @@ #include "types.h" -#define CONFIG(a) (((configData.config >> (a + 16)) & 1) != 0) +#define CONFIG(a) (((configData.config >> (a + 20)) & 1) != 0) #define MULTICONFIG(a) ((configData.config >> (a * 2 + 6)) & 3) #define BOOTCONFIG(a, b) ((configData.config >> a) & b) -#define DEV_OPTIONS MULTICONFIG(3) - #define CONFIG_PATH "/luma/config.bin" #define CONFIG_VERSIONMAJOR 1 -#define CONFIG_VERSIONMINOR 1 +#define CONFIG_VERSIONMINOR 2 + +#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 CONFIG_DEVOPTIONS MULTICONFIG(3) +#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_PATCHACCESS CONFIG(7) typedef struct __attribute__((packed)) { diff --git a/source/firm.c b/source/firm.c index f89278c..b850fca 100755 --- a/source/firm.c +++ b/source/firm.c @@ -86,9 +86,9 @@ void main(void) //'0' = NATIVE_FIRM, '1' = TWL_FIRM, '2' = AGB_FIRM firmType = launchedFirmTidLow[7] == u'3' ? SAFE_FIRM : (FirmwareType)(launchedFirmTidLow[5] - u'0'); - nandType = (FirmwareSource)BOOTCONFIG(0, 3); - firmSource = (FirmwareSource)BOOTCONFIG(2, 1); - isA9lh = BOOTCONFIG(3, 1) != 0; + nandType = (FirmwareSource)BOOTCFG_NAND; + firmSource = (FirmwareSource)BOOTCFG_FIRM; + isA9lh = BOOTCFG_A9LH != 0; if(isA9lh) installArm9Handlers(); } @@ -115,7 +115,7 @@ void main(void) if(CFG_BOOTENV == 7) { nandType = FIRMWARE_SYSNAND; - firmSource = CONFIG(1) ? FIRMWARE_SYSNAND : (FirmwareSource)BOOTCONFIG(2, 1); + firmSource = CONFIG_USESYSFIRM ? FIRMWARE_SYSNAND : (FirmwareSource)BOOTCFG_FIRM; needConfig = DONT_CONFIGURE; //Flag to prevent multiple boot options-forcing @@ -124,10 +124,10 @@ void main(void) /* Else, force the last used boot options unless a button is pressed or the no-forcing flag is set */ - else if(needConfig != CREATE_CONFIGURATION && !pressed && !BOOTCONFIG(4, 1)) + else if(needConfig != CREATE_CONFIGURATION && !pressed && !BOOTCFG_NOFORCEFLAG) { - nandType = (FirmwareSource)BOOTCONFIG(0, 3); - firmSource = (FirmwareSource)BOOTCONFIG(2, 1); + nandType = (FirmwareSource)BOOTCFG_NAND; + firmSource = (FirmwareSource)BOOTCFG_FIRM; needConfig = DONT_CONFIGURE; } } @@ -135,7 +135,7 @@ void main(void) //Boot options aren't being forced if(needConfig != DONT_CONFIGURE) { - bool pinExists = CONFIG(7) && verifyPin(); + bool pinExists = CONFIG_PIN != 0 && verifyPin(); //If no configuration file exists or SELECT is held, load configuration menu bool shouldLoadConfigMenu = needConfig == CREATE_CONFIGURATION || ((pressed & BUTTON_SELECT) && !(pressed & BUTTON_L1)); @@ -165,7 +165,7 @@ void main(void) } else { - if(CONFIG(6) && loadSplash()) pressed = HID_PAD; + if(CONFIG_PAYLOADSPLASH && loadSplash()) pressed = HID_PAD; /* If L and R/A/Select or one of the single payload buttons are pressed, chainload an external payload */ @@ -173,10 +173,10 @@ void main(void) if(shouldLoadPayload) loadPayload(pressed); - if(!CONFIG(6)) loadSplash(); + if(!CONFIG_PAYLOADSPLASH) loadSplash(); //Determine if the user chose to use the SysNAND FIRM as default for a R boot - bool useSysAsDefault = isA9lh ? CONFIG(1) : false; + bool useSysAsDefault = isA9lh ? CONFIG_USESYSFIRM : false; //If R is pressed, boot the non-updated NAND with the FIRM of the opposite one if(pressed & BUTTON_R1) @@ -189,13 +189,13 @@ void main(void) with their own FIRM */ else { - nandType = (CONFIG(0) != !(pressed & BUTTON_L1)) ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND; + nandType = (CONFIG_AUTOBOOTSYS != !(pressed & BUTTON_L1)) ? FIRMWARE_EMUNAND : FIRMWARE_SYSNAND; firmSource = nandType; } /* 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(2) == !(pressed & BUTTON_B))) nandType = FIRMWARE_EMUNAND2; + if(nandType != FIRMWARE_SYSNAND && (CONFIG_USESECONDEMU == !(pressed & BUTTON_B))) nandType = FIRMWARE_EMUNAND2; } } } @@ -259,7 +259,7 @@ static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource) if(firmSource != FIRMWARE_SYSNAND) error("An old unsupported EmuNAND has been detected.\nLuma3DS is unable to boot it"); - if(BOOTCONFIG(5, 1)) error("SAFE_MODE is not supported on 1.x/2.x FIRM"); + if(BOOTCFG_SAFEMODE) error("SAFE_MODE is not supported on 1.x/2.x FIRM"); *firmType = NATIVE_FIRM1X2X; } @@ -337,9 +337,9 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 implementSvcGetCFWInfo(arm11Section1, arm11SvcTable, &freeK11Space); //Apply UNITINFO patch - if(DEV_OPTIONS == 1) patchUnitInfoValueSet(arm9Section, section[2].size); + if(CONFIG_DEVOPTIONS == 1) patchUnitInfoValueSet(arm9Section, section[2].size); - if(isA9lh && DEV_OPTIONS != 2) + if(isA9lh && CONFIG_DEVOPTIONS != 2) { //Install ARM11 exception handlers u32 codeSetOffset; @@ -358,7 +358,7 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 patchKernel11Panic(arm11Section1, section[1].size); } - if(CONFIG(8)) + if(CONFIG_PATCHACCESS) { patchArm11SvcAccessChecks(arm11SvcHandler); patchK11ModuleChecks(arm11Section1, section[1].size, &freeK11Space); @@ -378,7 +378,7 @@ static inline void patchLegacyFirm(FirmwareType firmType) } //Apply UNITINFO patch - if(DEV_OPTIONS == 1) patchUnitInfoValueSet(arm9Section, section[3].size); + if(CONFIG_DEVOPTIONS == 1) patchUnitInfoValueSet(arm9Section, section[3].size); applyLegacyFirmPatches((u8 *)firm, firmType); } @@ -397,7 +397,7 @@ static inline void patch1x2xNativeAndSafeFirm(void) } else patchOldFirmWrites(arm9Section, section[2].size); - if(DEV_OPTIONS != 2) + if(CONFIG_DEVOPTIONS != 2) { //Kernel9/Process9 debugging patchArm9ExceptionHandlersInstall(arm9Section, section[2].size); diff --git a/source/patches.c b/source/patches.c index b00dd37..97b26e1 100644 --- a/source/patches.c +++ b/source/patches.c @@ -191,7 +191,7 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType) /* Calculate the amount of patches to apply. Only count the boot screen patch for AGB_FIRM if the matching option was enabled (keep it as last) */ u32 numPatches = firmType == TWL_FIRM ? (sizeof(twlPatches) / sizeof(patchData)) : - (sizeof(agbPatches) / sizeof(patchData) - !CONFIG(5)); + (sizeof(agbPatches) / sizeof(patchData) - !CONFIG_SHOWGBABOOT); const patchData *patches = firmType == TWL_FIRM ? twlPatches : agbPatches; //Patch diff --git a/source/pin.c b/source/pin.c index 7057292..5e7b7dc 100644 --- a/source/pin.c +++ b/source/pin.c @@ -56,7 +56,7 @@ void newPin(bool allowSkipping) //Pad to AES block length with zeroes u8 __attribute__((aligned(4))) enteredPassword[0x10] = {0}; - u8 length = 4 + MULTICONFIG(1), + u8 length = 4 + 2 * (CONFIG_PIN - 1), cnt = 0; int charDrawPos = 5 * SPACING_X; @@ -113,7 +113,7 @@ bool verifyPin(void) memcmp(pin.magic, "PINF", 4) != 0 || pin.formatVersionMajor != PIN_VERSIONMAJOR || pin.formatVersionMinor != PIN_VERSIONMINOR || - pin.length != 4 + MULTICONFIG(1)) + pin.length != 4 + 2 * (CONFIG_PIN - 1)) return false; u8 __attribute__((aligned(4))) zeroes[0x10] = {0}; diff --git a/source/pin.h b/source/pin.h index 831882e..462094c 100644 --- a/source/pin.h +++ b/source/pin.h @@ -32,7 +32,7 @@ #define PIN_PATH "/luma/pin.bin" #define PIN_VERSIONMAJOR 1 -#define PIN_VERSIONMINOR 1 +#define PIN_VERSIONMINOR 2 typedef struct __attribute__((packed)) { diff --git a/source/screen.c b/source/screen.c index ffcf863..fc06222 100644 --- a/source/screen.c +++ b/source/screen.c @@ -147,7 +147,7 @@ void initScreens(void) //Disable interrupts __asm(".word 0xF10C01C0"); - u32 brightnessLevel = brightness[MULTICONFIG(0)]; + u32 brightnessLevel = brightness[CONFIG_BRIGHTNESS]; *(vu32 *)0x10141200 = 0x1007F; *(vu32 *)0x10202014 = 0x00000001; @@ -254,6 +254,6 @@ void initScreens(void) else { clearScreens(); - updateBrightness(MULTICONFIG(0)); + updateBrightness(CONFIG_BRIGHTNESS); } } \ No newline at end of file