set_mitm: embed defaults in code, allow for missing ini

This commit is contained in:
Michael Scire 2019-11-27 13:28:54 -08:00 committed by SciresM
parent c10ba67973
commit 8d9c51f204
3 changed files with 84 additions and 26 deletions

View file

@ -1,40 +1,37 @@
; Disable uploading error reports to Nintendo
[eupld]
upload_enabled = u8!0x0
; Enable USB 3.0 superspeed for homebrew
[usb]
usb30_force_enabled = u8!0x0
; upload_enabled = u8!0x0
; Control whether RO should ease its validation of NROs.
; (note: this is normally not necessary, and ips patches can be used.)
[ro]
ease_nro_restriction = u8!0x0
; ease_nro_restriction = u8!0x0
; Atmosphere custom settings
[atmosphere]
; Reboot from fatal automatically after some number of milliseconds.
; If field is not present or 0, fatal will wait indefinitely for user input.
fatal_auto_reboot_interval = u64!0x0
; fatal_auto_reboot_interval = u64!0x0
; Make the power menu's "reboot" button reboot to payload.
; Set to "normal" for normal reboot, "rcm" for rcm reboot.
power_menu_reboot_function = str!payload
; power_menu_reboot_function = str!payload
; Controls whether dmnt cheats should be toggled on or off by
; default. 1 = toggled on by default, 0 = toggled off by default.
dmnt_cheats_enabled_by_default = u8!0x1
; dmnt_cheats_enabled_by_default = u8!0x1
; Controls whether dmnt should always save cheat toggle state
; for restoration on new game launch. 1 = always save toggles,
; 0 = only save toggles if toggle file exists.
dmnt_always_save_cheat_toggles = u8!0x0
; dmnt_always_save_cheat_toggles = u8!0x0
; Controls whether fs.mitm should redirect save files
; to directories on the sd card.
; 0 = Do not redirect, 1 = Redirect.
; NOTE: EXPERIMENTAL
; If you do not know what you are doing, do not touch this yet.
fsmitm_redirect_saves_to_sd = u8!0x0
; fsmitm_redirect_saves_to_sd = u8!0x0
[hbloader]
; Controls the size of the homebrew heap when running as applet.
; If set to zero, all available applet memory is used as heap.
; The default is zero.
applet_heap_size = u64!0x0
; applet_heap_size = u64!0x0
; Controls the amount of memory to reserve when running as applet
; for usage by other applets. This setting has no effect if
; applet_heap_size is non-zero. The default is zero.
applet_heap_reservation_size = u64!0x8000000
; applet_heap_size is non-zero. The default is 0x8000000.
; applet_heap_reservation_size = u64!0x8000000

View file

@ -13,6 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../amsmitm_initialization.hpp"
#include "nsmitm_module.hpp"
#include "ns_am_mitm_service.hpp"
#include "ns_web_mitm_service.hpp"
@ -22,7 +23,7 @@ namespace ams::mitm::ns {
namespace {
constexpr sm::ServiceName NsAmMitmServiceName = sm::ServiceName::Encode("ns:am");
constexpr sm::ServiceName NsWebMitmServiceName = sm::ServiceName::Encode("ns:am");
constexpr sm::ServiceName NsWebMitmServiceName = sm::ServiceName::Encode("ns:web");
constexpr size_t MaxServers = 1;
constexpr size_t MaxSessions = 5;
@ -32,6 +33,9 @@ namespace ams::mitm::ns {
}
void MitmModule::ThreadFunction(void *arg) {
/* Wait until initialization is complete. */
mitm::WaitInitialized();
/* Create mitm servers. */
if (hos::GetVersion() < hos::Version_300) {
R_ASSERT(g_server_manager.RegisterMitmServer<NsAmMitmService>(NsAmMitmServiceName));

View file

@ -291,34 +291,91 @@ namespace ams::settings::fwdbg {
Result LoadSdCardKeyValueStore() {
/* Open file. */
FsFile config_file;
R_TRY(ams::mitm::fs::OpenAtmosphereSdFile(&config_file, "/system_settings.ini", FsOpenMode_Read));
if (R_FAILED(ams::mitm::fs::OpenAtmosphereSdFile(&config_file, "/system_settings.ini", FsOpenMode_Read))) {
/* It's okay if the file isn't readable/present, because we already loaded defaults. */
return ResultSuccess();
}
ON_SCOPE_EXIT { fsFileClose(&config_file); };
Result parse_result = ResultSuccess();
util::ini::ParseFile(&config_file, &parse_result, SystemSettingsIniHandler);
R_TRY(parse_result);
for (size_t i = 0; i < util::size(g_entries); i++) {
if (!g_entries[i].HasValue()) {
g_num_entries = i;
break;
}
}
if (g_num_entries) {
std::sort(g_entries, g_entries + g_num_entries);
}
return ResultSuccess();
}
void LoadDefaultCustomSettings() {
/* Disable uploading error reports to Nintendo. */
R_ASSERT(ParseSettingsItemValue("eupld", "upload_enabled", "u8!0x0"));
/* Control whether RO should ease its validation of NROs. */
/* (note: this is normally not necessary, and ips patches can be used.) */
R_ASSERT(ParseSettingsItemValue("ro", "ease_nro_restriction", "u8!0x0"));
/* Atmosphere custom settings. */
/* Reboot from fatal automatically after some number of milliseconds. */
/* If field is not present or 0, fatal will wait indefinitely for user input. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "fatal_auto_reboot_interval", "u64!0x0"));
/* Make the power menu's "reboot" button reboot to payload. */
/* Set to "normal" for normal reboot, "rcm" for rcm reboot. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "power_menu_reboot_function", "str!payload"));
/* Controls whether dmnt cheats should be toggled on or off by */
/* default. 1 = toggled on by default, 0 = toggled off by default. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "dmnt_cheats_enabled_by_default", "u8!0x1"));
/* Controls whether dmnt should always save cheat toggle state */
/* for restoration on new game launch. 1 = always save toggles, */
/* 0 = only save toggles if toggle file exists. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "dmnt_always_save_cheat_toggles", "u8!0x0"));
/* Controls whether fs.mitm should redirect save files */
/* to directories on the sd card. */
/* 0 = Do not redirect, 1 = Redirect. */
/* NOTE: EXPERIMENTAL */
/* If you do not know what you are doing, do not touch this yet. */
R_ASSERT(ParseSettingsItemValue("atmosphere", "fsmitm_redirect_saves_to_sd", "u8!0x0"));
/* Hbloader custom settings. */
/* Controls the size of the homebrew heap when running as applet. */
/* If set to zero, all available applet memory is used as heap. */
/* The default is zero. */
R_ASSERT(ParseSettingsItemValue("hbloader", "applet_heap_size", "u64!0x0"));
/* Controls the amount of memory to reserve when running as applet */
/* for usage by other applets. This setting has no effect if */
/* applet_heap_size is non-zero. The default is 0x8000000. */
R_ASSERT(ParseSettingsItemValue("hbloader", "applet_heap_reservation_size", "u64!0x8000000"));
}
}
void InitializeSdCardKeyValueStore() {
/* Load in hardcoded defaults. */
/* These will be overwritten if present on the SD card. */
LoadDefaultCustomSettings();
/* Parse custom settings off the SD card. */
const Result parse_result = LoadSdCardKeyValueStore();
if (R_FAILED(parse_result)) {
ams::mitm::ThrowResultForDebug(parse_result);
}
/* Determine how many custom settings are present. */
for (size_t i = 0; i < util::size(g_entries); i++) {
if (!g_entries[i].HasValue()) {
g_num_entries = i;
break;
}
}
/* Ensure that the custom settings entries are sorted. */
if (g_num_entries) {
std::sort(g_entries, g_entries + g_num_entries);
}
}
Result GetSdCardKeyValueStoreSettingsItemValueSize(size_t *out_size, const char *name, const char *key) {