This repository has been archived on 2022-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Luma3DS-3GX/source/config.c

407 lines
18 KiB
C
Raw Normal View History

2016-04-05 05:27:28 +02:00
/*
2016-07-05 16:05:53 +02:00
* This file is part of Luma3DS
* Copyright (C) 2016 Aurora Wright, TuxSH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b of GPLv3 applies to this file: Requiring preservation of specified
* reasonable legal notices or author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
2016-04-05 05:27:28 +02:00
*/
#include "config.h"
#include "memory.h"
#include "fs.h"
2016-04-05 05:27:28 +02:00
#include "utils.h"
#include "screen.h"
2016-04-05 05:27:28 +02:00
#include "draw.h"
#include "buttons.h"
#include "pin.h"
2016-04-05 05:27:28 +02:00
CfgData configData;
2017-04-13 03:38:36 +02:00
ConfigurationStatus needConfig;
2017-04-14 05:02:45 +02:00
static u32 oldConfig;
bool readConfig(void)
{
2017-04-13 03:38:36 +02:00
bool ret;
2016-10-12 02:28:08 +02:00
if(fileRead(&configData, CONFIG_FILE, sizeof(CfgData)) != sizeof(CfgData) ||
memcmp(configData.magic, "CONF", 4) != 0 ||
configData.formatVersionMajor != CONFIG_VERSIONMAJOR ||
configData.formatVersionMinor != CONFIG_VERSIONMINOR)
{
configData.config = 0;
2017-04-13 03:38:36 +02:00
ret = false;
}
2017-04-13 03:38:36 +02:00
else ret = true;
2017-04-14 05:02:45 +02:00
oldConfig = configData.config;
2017-04-13 03:38:36 +02:00
return ret;
}
2017-04-13 03:38:36 +02:00
void writeConfig(bool isPayloadLaunch)
{
2017-04-14 05:02:45 +02:00
if(isPayloadLaunch) configData.config = (configData.config & 0xFFFFFF00) | (oldConfig & 0xFF);
/* If the configuration is different from previously, overwrite it.
Just the no-forcing flag being set is not enough */
2017-04-14 05:02:45 +02:00
if(needConfig != CREATE_CONFIGURATION && (configData.config & 0xFFFFFF7F) == oldConfig) return;
if(needConfig == CREATE_CONFIGURATION)
{
memcpy(configData.magic, "CONF", 4);
configData.formatVersionMajor = CONFIG_VERSIONMAJOR;
configData.formatVersionMinor = CONFIG_VERSIONMINOR;
}
if(!fileWrite(&configData, CONFIG_FILE, sizeof(CfgData)))
error("Error writing the configuration file");
}
void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode)
2016-04-05 05:27:28 +02:00
{
const char *multiOptionsText[] = { "Default EmuNAND: 1( ) 2( ) 3( ) 4( )",
"Screen brightness: 4( ) 3( ) 2( ) 1( )",
2016-09-19 14:03:55 +02:00
"Splash: Off( ) Before( ) After( ) payloads",
"PIN lock: Off( ) 4( ) 6( ) 8( ) digits",
2016-09-19 14:03:55 +02:00
"New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )",
2016-09-08 18:47:13 +02:00
};
const char *singleOptionsText[] = { "( ) Autoboot SysNAND",
"( ) Use SysNAND FIRM if booting with R",
"( ) Enable loading external FIRMs and modules",
"( ) Use custom path",
"( ) Enable game patching",
"( ) Show NAND or user string in System Settings",
"( ) Show GBA boot screen in patched AGB_FIRM",
2017-01-19 22:48:09 +01:00
"( ) Patch SVC/service/archive/ARM9 access",
"( ) Set developer UNITINFO",
"( ) Enable exception handlers"
2016-09-08 18:47:13 +02:00
};
const char *optionsDescription[] = { "Select the default EmuNAND.\n\n"
2016-09-19 18:36:47 +02:00
"It will be booted when no\n"
"directional pad buttons are pressed.",
2016-09-18 18:05:51 +02:00
"Select the screen brightness.",
2016-09-19 14:03:55 +02:00
"Enable splash screen support.\n\n"
"\t* 'Before payloads' displays it\n"
"before booting payloads\n"
2016-09-23 21:34:47 +02:00
"(intended for splashes that display\n"
"button hints).\n\n"
"\t* 'After payloads' displays it\n"
"afterwards.",
2016-09-19 14:03:55 +02:00
"Activate a PIN lock.\n\n"
"The PIN will be asked each time\n"
"Luma3DS boots.\n\n"
"4, 6 or 8 digits can be selected.\n\n"
"The ABXY buttons and the directional\n"
2016-09-26 15:46:12 +02:00
"pad buttons can be used as keys.\n\n"
"A message can also be displayed\n"
"(refer to the wiki for instructions).",
"Select the New 3DS CPU mode.\n\n"
"This won't apply to\n"
"New 3DS exclusive/enhanced games.\n\n"
"'Clock+L2' can cause issues with some\n"
"games.",
2016-09-19 14:03:55 +02:00
2016-09-19 18:36:47 +02:00
"If enabled, SysNAND will be launched\n"
"on boot.\n\n"
"Otherwise, an EmuNAND will.\n\n"
"Hold L on boot to switch NAND.\n\n"
"To use a different EmuNAND from the\n"
"default, hold a directional pad button\n"
"(Up/Right/Down/Left equal EmuNANDs\n"
"1/2/3/4).",
"If enabled, when holding R on boot\n"
"EmuNAND will be booted with the\n"
2016-09-19 18:36:47 +02:00
"SysNAND FIRM.\n\n"
"Otherwise, SysNAND will be booted\n"
"with an EmuNAND FIRM.\n\n"
"To use a different EmuNAND from the\n"
"default, hold a directional pad button\n"
"(Up/Right/Down/Left equal EmuNANDs\n"
2016-09-19 18:36:47 +02:00
"1/2/3/4), also add A if you have\n"
"a matching payload.",
"Enable loading external FIRMs and\n"
"system modules.\n\n"
2016-09-26 15:46:12 +02:00
"This isn't needed in most cases.\n\n"
"Refer to the wiki for instructions.",
2016-09-19 14:03:55 +02:00
"Use a custom path for the\n"
"Luma3DS payload.\n\n"
"Refer to the wiki for instructions.",
"Enable overriding the region and\n"
"language configuration and the usage\n"
2017-04-14 18:14:46 +02:00
"of patched code binaries,\n"
"IPS code patches and LayeredFS\n"
"for specific games.\n\n"
"Also makes certain DLCs\n"
"for out-of-region games work.\n\n"
"Enabling this requires the\n"
"archive patch to be applied.\n\n"
"Refer to the wiki for instructions.",
2016-09-26 15:46:12 +02:00
"Enable showing the current NAND/FIRM:\n\n"
"\t* Sys = SysNAND\n"
"\t* Emu = EmuNAND 1\n"
"\t* EmuX = EmuNAND X\n"
"\t* SysE = SysNAND with EmuNAND 1 FIRM\n"
"\t* SyEX = SysNAND with EmuNAND X FIRM\n"
2016-09-26 15:46:12 +02:00
"\t* EmuS = EmuNAND 1 with SysNAND FIRM\n"
"\t* EmXS = EmuNAND X with SysNAND FIRM\n\n"
2016-09-14 22:31:25 +02:00
"or an user-defined custom string in\n"
"System Settings.\n\n"
"Refer to the wiki for instructions.",
2016-09-19 18:36:47 +02:00
"Enable showing the GBA boot screen\n"
"when booting GBA games.",
2016-09-19 14:03:55 +02:00
"Disable SVC, service, archive and ARM9\n"
"exheader access checks.\n\n"
"The service and archive patches\n"
"don't work on New 3DS FIRMs between\n"
"9.3 and 10.4.\n\n"
2016-09-19 14:03:55 +02:00
"Only change this if you know what you\n"
"are doing!",
2017-03-05 14:12:49 +01:00
"Make the console be always detected\n"
"as a development unit\n"
"(which breaks online features, amiibo\n"
"and retail CIAs, but allows installing\n"
"and booting some developer software).\n\n"
2017-03-05 14:12:49 +01:00
"Only select this if you know what you\n"
"are doing!",
2017-03-05 14:12:49 +01:00
"Enable Luma3DS's ARM9/ARM11 exception\n"
"handlers.\n"
"A9LH is required, and Luma3DS should\n"
"be ran as arm9loaderhax.bin.\n"
"Useful for debugging."
};
struct multiOption {
u32 posXs[4];
u32 posY;
2016-04-05 05:27:28 +02:00
u32 enabled;
bool visible;
} multiOptions[] = {
{ .posXs = {19, 24, 29, 34}, .visible = isSdMode },
{ .posXs = {21, 26, 31, 36}, .visible = true },
{ .posXs = {12, 22, 31, 0}, .visible = true },
{ .posXs = {14, 19, 24, 29}, .visible = true },
{ .posXs = {17, 26, 32, 44}, .visible = ISN3DS },
};
struct singleOption {
u32 posY;
bool enabled;
bool visible;
} singleOptions[] = {
{ .visible = isSdMode },
{ .visible = isSdMode },
{ .visible = true },
{ .visible = true },
{ .visible = true },
{ .visible = true },
{ .visible = true },
2017-01-19 22:48:09 +01:00
{ .visible = true },
{ .visible = true },
{ .visible = true}
};
//Calculate the amount of the various kinds of options and pre-select the first single one
u32 multiOptionsAmount = sizeof(multiOptions) / sizeof(struct multiOption),
singleOptionsAmount = sizeof(singleOptions) / sizeof(struct singleOption),
2016-04-13 15:19:35 +02:00
totalIndexes = multiOptionsAmount + singleOptionsAmount - 1,
selectedOption,
singleSelected;
2016-11-13 18:13:12 +01:00
bool isMultiOption = false;
2016-04-05 05:27:28 +02:00
//Parse the existing options
for(u32 i = 0; i < multiOptionsAmount; i++)
multiOptions[i].enabled = MULTICONFIG(i);
for(u32 i = 0; i < singleOptionsAmount; i++)
singleOptions[i].enabled = CONFIG(i);
initScreens();
drawString(CONFIG_TITLE, true, 10, 10, COLOR_TITLE);
drawString("Press A to select, START to save", true, 10, 10 + SPACING_Y, COLOR_TITLE);
//Character to display a selected option
char selected = 'x';
u32 endPos = 10 + 2 * SPACING_Y;
//Display all the multiple choice options in white
for(u32 i = 0; i < multiOptionsAmount; i++)
{
if(!multiOptions[i].visible) continue;
multiOptions[i].posY = endPos + SPACING_Y;
endPos = drawString(multiOptionsText[i], true, 10, multiOptions[i].posY, COLOR_WHITE);
drawCharacter(selected, true, 10 + multiOptions[i].posXs[multiOptions[i].enabled] * SPACING_X, multiOptions[i].posY, COLOR_WHITE);
}
2016-04-05 05:27:28 +02:00
2016-04-13 15:19:35 +02:00
endPos += SPACING_Y / 2;
2016-04-05 05:27:28 +02:00
//Display all the normal options in white except for the first one
2016-10-13 00:52:18 +02:00
for(u32 i = 0, color = COLOR_RED; i < singleOptionsAmount; i++)
{
if(!singleOptions[i].visible) continue;
2016-10-13 00:52:18 +02:00
singleOptions[i].posY = endPos + SPACING_Y;
endPos = drawString(singleOptionsText[i], true, 10, singleOptions[i].posY, color);
if(singleOptions[i].enabled) drawCharacter(selected, true, 10 + SPACING_X, singleOptions[i].posY, color);
if(color == COLOR_RED)
{
singleSelected = i;
selectedOption = i + multiOptionsAmount;
color = COLOR_WHITE;
}
}
2016-04-05 05:27:28 +02:00
drawString(optionsDescription[selectedOption], false, 10, 10, COLOR_WHITE);
//Boring configuration menu
while(true)
{
u32 pressed;
2016-04-13 15:19:35 +02:00
do
{
pressed = waitInput(true);
2016-04-05 05:27:28 +02:00
}
while(!(pressed & MENU_BUTTONS));
if(pressed == BUTTON_START) break;
if(pressed != BUTTON_A)
2016-04-05 05:27:28 +02:00
{
2016-04-13 15:19:35 +02:00
//Remember the previously selected option
u32 oldSelectedOption = selectedOption;
while(true)
{
switch(pressed)
{
case BUTTON_UP:
selectedOption = !selectedOption ? totalIndexes : selectedOption - 1;
break;
case BUTTON_DOWN:
selectedOption = selectedOption == totalIndexes ? 0 : selectedOption + 1;
break;
case BUTTON_LEFT:
pressed = BUTTON_DOWN;
selectedOption = 0;
break;
case BUTTON_RIGHT:
pressed = BUTTON_UP;
selectedOption = totalIndexes;
break;
2016-11-13 22:31:00 +01:00
default:
break;
}
if(selectedOption < multiOptionsAmount)
{
if(!multiOptions[selectedOption].visible) continue;
isMultiOption = true;
break;
}
else
{
singleSelected = selectedOption - multiOptionsAmount;
if(!singleOptions[singleSelected].visible) continue;
isMultiOption = false;
break;
}
}
2016-04-13 15:19:35 +02:00
if(selectedOption == oldSelectedOption) continue;
//The user moved to a different option, print the old option in white and the new one in red. Only print 'x's if necessary
if(oldSelectedOption < multiOptionsAmount)
{
drawString(multiOptionsText[oldSelectedOption], true, 10, multiOptions[oldSelectedOption].posY, COLOR_WHITE);
drawCharacter(selected, true, 10 + multiOptions[oldSelectedOption].posXs[multiOptions[oldSelectedOption].enabled] * SPACING_X, multiOptions[oldSelectedOption].posY, COLOR_WHITE);
}
else
{
u32 singleOldSelected = oldSelectedOption - multiOptionsAmount;
drawString(singleOptionsText[singleOldSelected], true, 10, singleOptions[singleOldSelected].posY, COLOR_WHITE);
if(singleOptions[singleOldSelected].enabled) drawCharacter(selected, true, 10 + SPACING_X, singleOptions[singleOldSelected].posY, COLOR_WHITE);
}
2016-04-05 05:27:28 +02:00
if(isMultiOption) drawString(multiOptionsText[selectedOption], true, 10, multiOptions[selectedOption].posY, COLOR_RED);
else drawString(singleOptionsText[singleSelected], true, 10, singleOptions[singleSelected].posY, COLOR_RED);
2016-11-15 14:08:58 +01:00
drawString(optionsDescription[oldSelectedOption], false, 10, 10, COLOR_BLACK);
drawString(optionsDescription[selectedOption], false, 10, 10, COLOR_WHITE);
}
else
{
2016-04-13 15:19:35 +02:00
//The selected option's status changed, print the 'x's accordingly
if(isMultiOption)
{
u32 oldEnabled = multiOptions[selectedOption].enabled;
drawCharacter(selected, true, 10 + multiOptions[selectedOption].posXs[oldEnabled] * SPACING_X, multiOptions[selectedOption].posY, COLOR_BLACK);
multiOptions[selectedOption].enabled = (oldEnabled == 3 || !multiOptions[selectedOption].posXs[oldEnabled + 1]) ? 0 : oldEnabled + 1;
2016-07-01 20:27:28 +02:00
2016-09-11 19:17:56 +02:00
if(selectedOption == BRIGHTNESS) updateBrightness(multiOptions[BRIGHTNESS].enabled);
}
else
{
bool oldEnabled = singleOptions[singleSelected].enabled;
singleOptions[singleSelected].enabled = !oldEnabled;
if(oldEnabled) drawCharacter(selected, true, 10 + SPACING_X, singleOptions[singleSelected].posY, COLOR_BLACK);
}
}
2016-04-13 15:19:35 +02:00
//In any case, if the current option is enabled (or a multiple choice option is selected) we must display a red 'x'
if(isMultiOption) drawCharacter(selected, true, 10 + multiOptions[selectedOption].posXs[multiOptions[selectedOption].enabled] * SPACING_X, multiOptions[selectedOption].posY, COLOR_RED);
else if(singleOptions[singleSelected].enabled) drawCharacter(selected, true, 10 + SPACING_X, singleOptions[singleSelected].posY, COLOR_RED);
2016-04-05 05:27:28 +02:00
}
//Preserve the last-used boot options (first 9 bits)
configData.config &= 0xFF;
2016-04-05 05:27:28 +02:00
//Parse and write the new configuration
for(u32 i = 0; i < multiOptionsAmount; i++)
configData.config |= multiOptions[i].enabled << (i * 2 + 8);
for(u32 i = 0; i < singleOptionsAmount; i++)
configData.config |= (singleOptions[i].enabled ? 1 : 0) << (i + 20);
2016-04-05 05:27:28 +02:00
2016-09-19 14:57:36 +02:00
u32 newPinMode = MULTICONFIG(PIN);
if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode);
2016-10-12 02:28:08 +02:00
else if(oldPinStatus) fileDelete(PIN_FILE);
while(HID_PAD & PIN_BUTTONS);
2016-11-29 20:11:30 +01:00
wait(2000ULL);
2017-01-21 21:20:48 +01:00
}