diff options
Diffstat (limited to 'src/core/hle/service/cfg/cfg.cpp')
-rw-r--r-- | src/core/hle/service/cfg/cfg.cpp | 191 |
1 files changed, 114 insertions, 77 deletions
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index a5dc47322..fe97a69d1 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -11,7 +11,6 @@ #include "core/file_sys/archive_systemsavedata.h" #include "core/file_sys/file_backend.h" -#include "core/settings.h" #include "core/hle/result.h" #include "core/hle/service/cfg/cfg.h" #include "core/hle/service/cfg/cfg_i.h" @@ -19,6 +18,7 @@ #include "core/hle/service/cfg/cfg_u.h" #include "core/hle/service/fs/archive.h" #include "core/hle/service/service.h" +#include "core/settings.h" namespace Service { namespace CFG { @@ -33,25 +33,29 @@ namespace { * contains information about the blocks in the file */ struct SaveFileConfig { - u16 total_entries; ///< The total number of set entries in the config file - u16 data_entries_offset; ///< The offset where the data for the blocks start, this is hardcoded to 0x455C as per hardware - SaveConfigBlockEntry block_entries[CONFIG_FILE_MAX_BLOCK_ENTRIES]; ///< The block headers, the maximum possible value is 1479 as per hardware - u32 unknown; ///< This field is unknown, possibly padding, 0 has been observed in hardware + u16 total_entries; ///< The total number of set entries in the config file + u16 data_entries_offset; ///< The offset where the data for the blocks start, this is hardcoded + /// to 0x455C as per hardware + SaveConfigBlockEntry block_entries[CONFIG_FILE_MAX_BLOCK_ENTRIES]; ///< The block headers, the + /// maximum possible value is + /// 1479 as per hardware + u32 unknown; ///< This field is unknown, possibly padding, 0 has been observed in hardware }; -static_assert(sizeof(SaveFileConfig) == 0x455C, "SaveFileConfig header must be exactly 0x455C bytes"); +static_assert(sizeof(SaveFileConfig) == 0x455C, + "SaveFileConfig header must be exactly 0x455C bytes"); enum ConfigBlockID { StereoCameraSettingsBlockID = 0x00050005, - SoundOutputModeBlockID = 0x00070001, - ConsoleUniqueIDBlockID = 0x00090001, - UsernameBlockID = 0x000A0000, - BirthdayBlockID = 0x000A0001, - LanguageBlockID = 0x000A0002, - CountryInfoBlockID = 0x000B0000, - CountryNameBlockID = 0x000B0001, - StateNameBlockID = 0x000B0002, - EULAVersionBlockID = 0x000D0000, - ConsoleModelBlockID = 0x000F0004, + SoundOutputModeBlockID = 0x00070001, + ConsoleUniqueIDBlockID = 0x00090001, + UsernameBlockID = 0x000A0000, + BirthdayBlockID = 0x000A0001, + LanguageBlockID = 0x000A0002, + CountryInfoBlockID = 0x000B0000, + CountryNameBlockID = 0x000B0001, + StateNameBlockID = 0x000B0002, + EULAVersionBlockID = 0x000D0000, + ConsoleModelBlockID = 0x000F0004, }; struct UsernameBlock { @@ -68,8 +72,8 @@ struct BirthdayBlock { static_assert(sizeof(BirthdayBlock) == 2, "BirthdayBlock must be exactly 2 bytes"); struct ConsoleModelInfo { - u8 model; ///< The console model (3DS, 2DS, etc) - u8 unknown[3]; ///< Unknown data + u8 model; ///< The console model (3DS, 2DS, etc) + u8 unknown[3]; ///< Unknown data }; static_assert(sizeof(ConsoleModelInfo) == 4, "ConsoleModelInfo must be exactly 4 bytes"); @@ -78,36 +82,36 @@ struct ConsoleCountryInfo { u8 country_code; ///< The country code of the console }; static_assert(sizeof(ConsoleCountryInfo) == 4, "ConsoleCountryInfo must be exactly 4 bytes"); - } static const u64 CFG_SAVE_ID = 0x00010017; static const u64 CONSOLE_UNIQUE_ID = 0xDEADC0DE; -static const ConsoleModelInfo CONSOLE_MODEL = { NINTENDO_3DS_XL, { 0, 0, 0 } }; +static const ConsoleModelInfo CONSOLE_MODEL = {NINTENDO_3DS_XL, {0, 0, 0}}; static const u8 CONSOLE_LANGUAGE = LANGUAGE_EN; -static const UsernameBlock CONSOLE_USERNAME_BLOCK = { u"CITRA", 0, 0 }; -static const BirthdayBlock PROFILE_BIRTHDAY = { 3, 25 }; // March 25th, 2014 +static const UsernameBlock CONSOLE_USERNAME_BLOCK = {u"CITRA", 0, 0}; +static const BirthdayBlock PROFILE_BIRTHDAY = {3, 25}; // March 25th, 2014 static const u8 SOUND_OUTPUT_MODE = SOUND_SURROUND; static const u8 UNITED_STATES_COUNTRY_ID = 49; /// TODO(Subv): Find what the other bytes are -static const ConsoleCountryInfo COUNTRY_INFO = { { 0, 0, 0 }, UNITED_STATES_COUNTRY_ID }; +static const ConsoleCountryInfo COUNTRY_INFO = {{0, 0, 0}, UNITED_STATES_COUNTRY_ID}; /** * TODO(Subv): Find out what this actually is, these values fix some NaN uniforms in some games, * for example Nintendo Zone * Thanks Normmatt for providing this information */ -static const std::array<float, 8> STEREO_CAMERA_SETTINGS = {{ - 62.0f, 289.0f, 76.80000305175781f, 46.08000183105469f, - 10.0f, 5.0f, 55.58000183105469f, 21.56999969482422f -}}; -static_assert(sizeof(STEREO_CAMERA_SETTINGS) == 0x20, "STEREO_CAMERA_SETTINGS must be exactly 0x20 bytes"); +static const std::array<float, 8> STEREO_CAMERA_SETTINGS = { + {62.0f, 289.0f, 76.80000305175781f, 46.08000183105469f, 10.0f, 5.0f, 55.58000183105469f, + 21.56999969482422f}}; +static_assert(sizeof(STEREO_CAMERA_SETTINGS) == 0x20, + "STEREO_CAMERA_SETTINGS must be exactly 0x20 bytes"); static const u32 CONFIG_SAVEFILE_SIZE = 0x8000; static std::array<u8, CONFIG_SAVEFILE_SIZE> cfg_config_file_buffer; static Service::FS::ArchiveHandle cfg_system_save_data_archive; -static const std::vector<u8> cfg_system_savedata_id = { 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x01, 0x00 }; +static const std::vector<u8> cfg_system_savedata_id = {0x00, 0x00, 0x00, 0x00, + 0x17, 0x00, 0x01, 0x00}; void GetCountryCodeString(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); @@ -115,7 +119,9 @@ void GetCountryCodeString(Service::Interface* self) { if (country_code_id >= country_codes.size() || 0 == country_codes[country_code_id]) { LOG_ERROR(Service_CFG, "requested country code id=%d is invalid", country_code_id); - cmd_buff[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw; + cmd_buff[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, + ErrorSummary::WrongArgument, ErrorLevel::Permanent) + .raw; return; } @@ -139,8 +145,11 @@ void GetCountryCodeID(Service::Interface* self) { } if (0 == country_code_id) { - LOG_ERROR(Service_CFG, "requested country code name=%c%c is invalid", country_code & 0xff, country_code >> 8); - cmd_buff[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent).raw; + LOG_ERROR(Service_CFG, "requested country code name=%c%c is invalid", country_code & 0xff, + country_code >> 8); + cmd_buff[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config, + ErrorSummary::WrongArgument, ErrorLevel::Permanent) + .raw; cmd_buff[2] = 0xFFFF; return; } @@ -185,8 +194,8 @@ void GetSystemModel(Service::Interface* self) { u32 data; // TODO(Subv): Find out the correct error codes - cmd_buff[1] = Service::CFG::GetConfigInfoBlock(0x000F0004, 4, 0x8, - reinterpret_cast<u8*>(&data)).raw; + cmd_buff[1] = + Service::CFG::GetConfigInfoBlock(0x000F0004, 4, 0x8, reinterpret_cast<u8*>(&data)).raw; cmd_buff[2] = data & 0xFF; } @@ -195,8 +204,8 @@ void GetModelNintendo2DS(Service::Interface* self) { u32 data; // TODO(Subv): Find out the correct error codes - cmd_buff[1] = Service::CFG::GetConfigInfoBlock(0x000F0004, 4, 0x8, - reinterpret_cast<u8*>(&data)).raw; + cmd_buff[1] = + Service::CFG::GetConfigInfoBlock(0x000F0004, 4, 0x8, reinterpret_cast<u8*>(&data)).raw; u8 model = data & 0xFF; if (model == Service::CFG::NINTENDO_2DS) @@ -267,24 +276,29 @@ static ResultVal<void*> GetConfigInfoBlockPointer(u32 block_id, u32 size, u32 fl // Read the header SaveFileConfig* config = reinterpret_cast<SaveFileConfig*>(cfg_config_file_buffer.data()); - auto itr = std::find_if(std::begin(config->block_entries), std::end(config->block_entries), - [&](const SaveConfigBlockEntry& entry) { - return entry.block_id == block_id; - }); + auto itr = + std::find_if(std::begin(config->block_entries), std::end(config->block_entries), + [&](const SaveConfigBlockEntry& entry) { return entry.block_id == block_id; }); if (itr == std::end(config->block_entries)) { - LOG_ERROR(Service_CFG, "Config block 0x%X with flags %u and size %u was not found", block_id, flag, size); - return ResultCode(ErrorDescription::NotFound, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent); + LOG_ERROR(Service_CFG, "Config block 0x%X with flags %u and size %u was not found", + block_id, flag, size); + return ResultCode(ErrorDescription::NotFound, ErrorModule::Config, + ErrorSummary::WrongArgument, ErrorLevel::Permanent); } if ((itr->flags & flag) == 0) { - LOG_ERROR(Service_CFG, "Invalid flag %u for config block 0x%X with size %u", flag, block_id, size); - return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent); + LOG_ERROR(Service_CFG, "Invalid flag %u for config block 0x%X with size %u", flag, block_id, + size); + return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::Config, + ErrorSummary::WrongArgument, ErrorLevel::Permanent); } if (itr->size != size) { - LOG_ERROR(Service_CFG, "Invalid size %u for config block 0x%X with flags %u", size, block_id, flag); - return ResultCode(ErrorDescription::InvalidSize, ErrorModule::Config, ErrorSummary::WrongArgument, ErrorLevel::Permanent); + LOG_ERROR(Service_CFG, "Invalid size %u for config block 0x%X with flags %u", size, + block_id, flag); + return ResultCode(ErrorDescription::InvalidSize, ErrorModule::Config, + ErrorSummary::WrongArgument, ErrorLevel::Permanent); } void* pointer; @@ -318,7 +332,7 @@ ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const void* da return ResultCode(-1); // TODO(Subv): Find the right error code // Insert the block header with offset 0 for now - config->block_entries[config->total_entries] = { block_id, 0, size, flags }; + config->block_entries[config->total_entries] = {block_id, 0, size, flags}; if (size > 4) { u32 offset = config->data_entries_offset; // Perform a search to locate the next offset for the new data @@ -326,8 +340,7 @@ ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const void* da for (int i = config->total_entries - 1; i >= 0; --i) { // Ignore the blocks that don't have a separate data offset if (config->block_entries[i].size > 4) { - offset = config->block_entries[i].offset_or_data + - config->block_entries[i].size; + offset = config->block_entries[i].offset_or_data + config->block_entries[i].size; break; } } @@ -336,8 +349,7 @@ ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const void* da // Write the data at the new offset memcpy(&cfg_config_file_buffer[offset], data, size); - } - else { + } else { // The offset_or_data field in the header contains the data itself if it's 4 bytes or less memcpy(&config->block_entries[config->total_entries].offset_or_data, data, size); } @@ -384,28 +396,40 @@ ResultCode FormatConfig() { // 0x00030001 - Unknown res = CreateConfigInfoBlk(0x00030001, 0x8, 0xE, zero_buffer); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; - res = CreateConfigInfoBlk(StereoCameraSettingsBlockID, sizeof(STEREO_CAMERA_SETTINGS), 0xE, STEREO_CAMERA_SETTINGS.data()); - if (!res.IsSuccess()) return res; + res = CreateConfigInfoBlk(StereoCameraSettingsBlockID, sizeof(STEREO_CAMERA_SETTINGS), 0xE, + STEREO_CAMERA_SETTINGS.data()); + if (!res.IsSuccess()) + return res; - res = CreateConfigInfoBlk(SoundOutputModeBlockID, sizeof(SOUND_OUTPUT_MODE), 0xE, &SOUND_OUTPUT_MODE); - if (!res.IsSuccess()) return res; + res = CreateConfigInfoBlk(SoundOutputModeBlockID, sizeof(SOUND_OUTPUT_MODE), 0xE, + &SOUND_OUTPUT_MODE); + if (!res.IsSuccess()) + return res; - res = CreateConfigInfoBlk(ConsoleUniqueIDBlockID, sizeof(CONSOLE_UNIQUE_ID), 0xE, &CONSOLE_UNIQUE_ID); - if (!res.IsSuccess()) return res; + res = CreateConfigInfoBlk(ConsoleUniqueIDBlockID, sizeof(CONSOLE_UNIQUE_ID), 0xE, + &CONSOLE_UNIQUE_ID); + if (!res.IsSuccess()) + return res; - res = CreateConfigInfoBlk(UsernameBlockID, sizeof(CONSOLE_USERNAME_BLOCK), 0xE, &CONSOLE_USERNAME_BLOCK); - if (!res.IsSuccess()) return res; + res = CreateConfigInfoBlk(UsernameBlockID, sizeof(CONSOLE_USERNAME_BLOCK), 0xE, + &CONSOLE_USERNAME_BLOCK); + if (!res.IsSuccess()) + return res; res = CreateConfigInfoBlk(BirthdayBlockID, sizeof(PROFILE_BIRTHDAY), 0xE, &PROFILE_BIRTHDAY); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; res = CreateConfigInfoBlk(LanguageBlockID, sizeof(CONSOLE_LANGUAGE), 0xE, &CONSOLE_LANGUAGE); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; res = CreateConfigInfoBlk(CountryInfoBlockID, sizeof(COUNTRY_INFO), 0xE, &COUNTRY_INFO); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; u16_le country_name_buffer[16][0x40] = {}; std::u16string region_name = Common::UTF8ToUTF16("Gensokyo"); @@ -413,34 +437,44 @@ ResultCode FormatConfig() { std::copy(region_name.cbegin(), region_name.cend(), country_name_buffer[i]); } // 0x000B0001 - Localized names for the profile Country - res = CreateConfigInfoBlk(CountryNameBlockID, sizeof(country_name_buffer), 0xE, country_name_buffer); - if (!res.IsSuccess()) return res; + res = CreateConfigInfoBlk(CountryNameBlockID, sizeof(country_name_buffer), 0xE, + country_name_buffer); + if (!res.IsSuccess()) + return res; // 0x000B0002 - Localized names for the profile State/Province - res = CreateConfigInfoBlk(StateNameBlockID, sizeof(country_name_buffer), 0xE, country_name_buffer); - if (!res.IsSuccess()) return res; + res = CreateConfigInfoBlk(StateNameBlockID, sizeof(country_name_buffer), 0xE, + country_name_buffer); + if (!res.IsSuccess()) + return res; // 0x000B0003 - Unknown, related to country/address (zip code?) res = CreateConfigInfoBlk(0x000B0003, 0x4, 0xE, zero_buffer); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; // 0x000C0000 - Unknown res = CreateConfigInfoBlk(0x000C0000, 0xC0, 0xE, zero_buffer); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; // 0x000C0001 - Unknown res = CreateConfigInfoBlk(0x000C0001, 0x14, 0xE, zero_buffer); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; // 0x000D0000 - Accepted EULA version res = CreateConfigInfoBlk(EULAVersionBlockID, 0x4, 0xE, zero_buffer); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; res = CreateConfigInfoBlk(ConsoleModelBlockID, sizeof(CONSOLE_MODEL), 0xC, &CONSOLE_MODEL); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; // 0x00170000 - Unknown res = CreateConfigInfoBlk(0x00170000, 0x4, 0xE, zero_buffer); - if (!res.IsSuccess()) return res; + if (!res.IsSuccess()) + return res; // Save the buffer to the file res = UpdateConfigNANDSavegame(); @@ -452,15 +486,18 @@ ResultCode FormatConfig() { ResultCode LoadConfigNANDSaveFile() { // Open the SystemSaveData archive 0x00010017 FileSys::Path archive_path(cfg_system_savedata_id); - auto archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); + auto archive_result = + Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); // If the archive didn't exist, create the files inside if (archive_result.Code().description == ErrorDescription::FS_NotFormatted) { // Format the archive to create the directories - Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SystemSaveData, FileSys::ArchiveFormatInfo(), archive_path); + Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SystemSaveData, + FileSys::ArchiveFormatInfo(), archive_path); // Open it again to get a valid archive now that the folder exists - archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); + archive_result = + Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); } ASSERT_MSG(archive_result.Succeeded(), "Could not open the CFG SystemSaveData archive!"); @@ -515,7 +552,7 @@ std::u16string GetUsername() { } void SetBirthday(u8 month, u8 day) { - BirthdayBlock block = { month, day }; + BirthdayBlock block = {month, day}; SetConfigInfoBlock(BirthdayBlockID, sizeof(block), 4, &block); } |