mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-30 21:30:04 +00:00 
			
		
		
		
	Merge pull request #312 from Subv/still_more_savedata_stuff
CFG: Implemented the GetConfigInfoBlk2 function.
This commit is contained in:
		
						commit
						ec1ddc17e2
					
				
					 14 changed files with 508 additions and 30 deletions
				
			
		|  | @ -37,8 +37,9 @@ set(SRCS | |||
|             hle/service/apt_u.cpp | ||||
|             hle/service/boss_u.cpp | ||||
|             hle/service/cecd_u.cpp | ||||
|             hle/service/cfg_i.cpp | ||||
|             hle/service/cfg_u.cpp | ||||
|             hle/service/cfg/cfg.cpp | ||||
|             hle/service/cfg/cfg_i.cpp | ||||
|             hle/service/cfg/cfg_u.cpp | ||||
|             hle/service/csnd_snd.cpp | ||||
|             hle/service/dsp_dsp.cpp | ||||
|             hle/service/err_f.cpp | ||||
|  | @ -122,8 +123,9 @@ set(HEADERS | |||
|             hle/service/apt_u.h | ||||
|             hle/service/boss_u.h | ||||
|             hle/service/cecd_u.h | ||||
|             hle/service/cfg_i.h | ||||
|             hle/service/cfg_u.h | ||||
|             hle/service/cfg/cfg.h | ||||
|             hle/service/cfg/cfg_i.h | ||||
|             hle/service/cfg/cfg_u.h | ||||
|             hle/service/csnd_snd.h | ||||
|             hle/service/dsp_dsp.h | ||||
|             hle/service/err_f.h | ||||
|  |  | |||
|  | @ -45,6 +45,11 @@ public: | |||
|     { | ||||
|     } | ||||
| 
 | ||||
|     Path(const char* path): | ||||
|         type(Char), string(path) | ||||
|     { | ||||
|     } | ||||
| 
 | ||||
|     Path(LowPathType type, u32 size, u32 pointer): | ||||
|         type(type) | ||||
|     { | ||||
|  |  | |||
|  | @ -16,8 +16,14 @@ | |||
| 
 | ||||
| namespace FileSys { | ||||
| 
 | ||||
| Archive_SystemSaveData::Archive_SystemSaveData(const std::string& mount_point) | ||||
|         : DiskArchive(mount_point) { | ||||
| static std::string GetSystemSaveDataPath(const std::string& mount_point, u64 save_id) { | ||||
|     u32 save_high = static_cast<u32>((save_id >> 32) & 0xFFFFFFFF); | ||||
|     u32 save_low = static_cast<u32>(save_id & 0xFFFFFFFF); | ||||
|     return Common::StringFromFormat("%s%08X/%08X/", mount_point.c_str(), save_low, save_high); | ||||
| } | ||||
| 
 | ||||
| Archive_SystemSaveData::Archive_SystemSaveData(const std::string& mount_point, u64 save_id) | ||||
|         : DiskArchive(GetSystemSaveDataPath(mount_point, save_id)) { | ||||
|     LOG_INFO(Service_FS, "Directory %s set as SystemSaveData.", this->mount_point.c_str()); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ namespace FileSys { | |||
| /// specifically nand:/data/<ID0>/sysdata/<SaveID-Low>/<SaveID-High>
 | ||||
| class Archive_SystemSaveData final : public DiskArchive { | ||||
| public: | ||||
|     Archive_SystemSaveData(const std::string& mount_point); | ||||
|     Archive_SystemSaveData(const std::string& mount_point, u64 save_id); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Initialize the archive. | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include "common/common_types.h" | ||||
| #include "common/file_util.h" | ||||
| 
 | ||||
| #include "core/file_sys/archive_backend.h" | ||||
| #include "core/loader/loader.h" | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ | |||
| #include "core/hle/kernel/thread.h" | ||||
| #include "core/hle/service/service.h" | ||||
| #include "core/hle/service/fs/archive.h" | ||||
| #include "core/hle/service/cfg/cfg.h" | ||||
| 
 | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////
 | ||||
| 
 | ||||
|  | @ -58,6 +59,7 @@ void RegisterAllModules() { | |||
| void Init() { | ||||
|     Service::Init(); | ||||
|     Service::FS::ArchiveInit(); | ||||
|     Service::CFG::CFGInit(); | ||||
| 
 | ||||
|     RegisterAllModules(); | ||||
| 
 | ||||
|  | @ -65,6 +67,7 @@ void Init() { | |||
| } | ||||
| 
 | ||||
| void Shutdown() { | ||||
|     Service::CFG::CFGShutdown(); | ||||
|     Service::FS::ArchiveShutdown(); | ||||
|     Service::Shutdown(); | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										202
									
								
								src/core/hle/service/cfg/cfg.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										202
									
								
								src/core/hle/service/cfg/cfg.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,202 @@ | |||
| // Copyright 2014 Citra Emulator Project
 | ||||
| // Licensed under GPLv2 or any later version
 | ||||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include <algorithm> | ||||
| #include "common/log.h" | ||||
| #include "common/make_unique.h" | ||||
| #include "core/file_sys/archive_systemsavedata.h" | ||||
| #include "core/hle/service/cfg/cfg.h" | ||||
| 
 | ||||
| namespace Service { | ||||
| namespace CFG { | ||||
| 
 | ||||
| const u64 CFG_SAVE_ID = 0x00010017; | ||||
| const u64 CONSOLE_UNIQUE_ID = 0xDEADC0DE; | ||||
| const ConsoleModelInfo CONSOLE_MODEL = { NINTENDO_3DS_XL, { 0, 0, 0 } }; | ||||
| const u8 CONSOLE_LANGUAGE = LANGUAGE_EN; | ||||
| const char CONSOLE_USERNAME[0x14] = "CITRA"; | ||||
| /// This will be initialized in CFGInit, and will be used when creating the block
 | ||||
| UsernameBlock CONSOLE_USERNAME_BLOCK; | ||||
| /// TODO(Subv): Find out what this actually is
 | ||||
| const u8 SOUND_OUTPUT_MODE = 2; | ||||
| const u8 UNITED_STATES_COUNTRY_ID = 49; | ||||
| /// TODO(Subv): Find what the other bytes are
 | ||||
| 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 | ||||
|  */ | ||||
| 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 const u32 CONFIG_SAVEFILE_SIZE = 0x8000; | ||||
| static std::array<u8, CONFIG_SAVEFILE_SIZE> cfg_config_file_buffer; | ||||
| 
 | ||||
| static std::unique_ptr<FileSys::Archive_SystemSaveData> cfg_system_save_data; | ||||
| 
 | ||||
| ResultCode GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, u8* output) { | ||||
|     // 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 && entry.size == size && (entry.flags & flag); | ||||
|             }); | ||||
| 
 | ||||
|     if (itr == std::end(config->block_entries)) { | ||||
|         LOG_ERROR(Service_CFG, "Config block %u with size %u and flags %u not found", block_id, size, flag); | ||||
|         return ResultCode(-1); // TODO(Subv): Find the correct error code
 | ||||
|     } | ||||
| 
 | ||||
|     // The data is located in the block header itself if the size is less than 4 bytes
 | ||||
|     if (itr->size <= 4) | ||||
|         memcpy(output, &itr->offset_or_data, itr->size); | ||||
|     else | ||||
|         memcpy(output, &cfg_config_file_buffer[itr->offset_or_data], itr->size); | ||||
| 
 | ||||
|     return RESULT_SUCCESS; | ||||
| } | ||||
| 
 | ||||
| ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const u8* data) { | ||||
|     SaveFileConfig* config = reinterpret_cast<SaveFileConfig*>(cfg_config_file_buffer.data()); | ||||
|     if (config->total_entries >= CONFIG_FILE_MAX_BLOCK_ENTRIES) | ||||
|         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 }; | ||||
|     if (size > 4) { | ||||
|         u32 offset = config->data_entries_offset; | ||||
|         // Perform a search to locate the next offset for the new data
 | ||||
|         // use the offset and size of the previous block to determine the new position
 | ||||
|         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; | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         config->block_entries[config->total_entries].offset_or_data = offset; | ||||
| 
 | ||||
|         // Write the data at the new offset
 | ||||
|         memcpy(&cfg_config_file_buffer[offset], data, size); | ||||
|     } | ||||
|     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); | ||||
|     } | ||||
| 
 | ||||
|     ++config->total_entries; | ||||
|     return RESULT_SUCCESS; | ||||
| } | ||||
| 
 | ||||
| ResultCode DeleteConfigNANDSaveFile() { | ||||
|     FileSys::Path path("config"); | ||||
|     if (cfg_system_save_data->DeleteFile(path)) | ||||
|         return RESULT_SUCCESS; | ||||
|     return ResultCode(-1); // TODO(Subv): Find the right error code
 | ||||
| } | ||||
| 
 | ||||
| ResultCode UpdateConfigNANDSavegame() { | ||||
|     FileSys::Mode mode = {}; | ||||
|     mode.write_flag = 1; | ||||
|     mode.create_flag = 1; | ||||
|     FileSys::Path path("config"); | ||||
|     auto file = cfg_system_save_data->OpenFile(path, mode); | ||||
|     _assert_msg_(Service_CFG, file != nullptr, "could not open file"); | ||||
|     file->Write(0, CONFIG_SAVEFILE_SIZE, 1, cfg_config_file_buffer.data()); | ||||
|     return RESULT_SUCCESS; | ||||
| } | ||||
| 
 | ||||
| ResultCode FormatConfig() { | ||||
|     ResultCode res = DeleteConfigNANDSaveFile(); | ||||
|     if (!res.IsSuccess()) | ||||
|         return res; | ||||
|     // Delete the old data
 | ||||
|     cfg_config_file_buffer.fill(0); | ||||
|     // Create the header
 | ||||
|     SaveFileConfig* config = reinterpret_cast<SaveFileConfig*>(cfg_config_file_buffer.data()); | ||||
|     // This value is hardcoded, taken from 3dbrew, verified by hardware, it's always the same value
 | ||||
|     config->data_entries_offset = 0x455C; | ||||
|     // Insert the default blocks
 | ||||
|     res = CreateConfigInfoBlk(0x00050005, sizeof(STEREO_CAMERA_SETTINGS), 0xE, | ||||
|                               reinterpret_cast<const u8*>(STEREO_CAMERA_SETTINGS.data())); | ||||
|     if (!res.IsSuccess()) | ||||
|         return res; | ||||
|     res = CreateConfigInfoBlk(0x00090001, sizeof(CONSOLE_UNIQUE_ID), 0xE, | ||||
|                               reinterpret_cast<const u8*>(&CONSOLE_UNIQUE_ID)); | ||||
|     if (!res.IsSuccess()) | ||||
|         return res; | ||||
|     res = CreateConfigInfoBlk(0x000F0004, sizeof(CONSOLE_MODEL), 0x8, | ||||
|                               reinterpret_cast<const u8*>(&CONSOLE_MODEL)); | ||||
|     if (!res.IsSuccess()) | ||||
|         return res; | ||||
|     res = CreateConfigInfoBlk(0x000A0002, sizeof(CONSOLE_LANGUAGE), 0xA, &CONSOLE_LANGUAGE); | ||||
|     if (!res.IsSuccess()) | ||||
|         return res; | ||||
|     res = CreateConfigInfoBlk(0x00070001, sizeof(SOUND_OUTPUT_MODE), 0xE, &SOUND_OUTPUT_MODE); | ||||
|     if (!res.IsSuccess()) | ||||
|         return res; | ||||
|     res = CreateConfigInfoBlk(0x000B0000, sizeof(COUNTRY_INFO), 0xE, | ||||
|                               reinterpret_cast<const u8*>(&COUNTRY_INFO)); | ||||
|     if (!res.IsSuccess()) | ||||
|         return res; | ||||
|     res = CreateConfigInfoBlk(0x000A0000, sizeof(CONSOLE_USERNAME_BLOCK), 0xE, | ||||
|                               reinterpret_cast<const u8*>(&CONSOLE_USERNAME_BLOCK)); | ||||
|     if (!res.IsSuccess()) | ||||
|         return res; | ||||
|     // Save the buffer to the file
 | ||||
|     res = UpdateConfigNANDSavegame(); | ||||
|     if (!res.IsSuccess()) | ||||
|         return res; | ||||
|     return RESULT_SUCCESS; | ||||
| } | ||||
| 
 | ||||
| void CFGInit() { | ||||
|     // TODO(Subv): In the future we should use the FS service to query this archive, 
 | ||||
|     // currently it is not possible because you can only have one open archive of the same type at any time
 | ||||
|     std::string syssavedata_directory = FileUtil::GetUserPath(D_SYSSAVEDATA_IDX); | ||||
|     cfg_system_save_data = Common::make_unique<FileSys::Archive_SystemSaveData>( | ||||
|                            syssavedata_directory, CFG_SAVE_ID); | ||||
|     if (!cfg_system_save_data->Initialize()) { | ||||
|         LOG_CRITICAL(Service_CFG, "Could not initialize SystemSaveData archive for the CFG:U service"); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     // TODO(Subv): All this code should be moved to cfg:i, 
 | ||||
|     // it's only here because we do not currently emulate the lower level code that uses that service
 | ||||
|     // Try to open the file in read-only mode to check its existence
 | ||||
|     FileSys::Mode mode = {}; | ||||
|     mode.read_flag = 1; | ||||
|     FileSys::Path path("config"); | ||||
|     auto file = cfg_system_save_data->OpenFile(path, mode); | ||||
| 
 | ||||
|     // Load the config if it already exists
 | ||||
|     if (file != nullptr) { | ||||
|         file->Read(0, CONFIG_SAVEFILE_SIZE, cfg_config_file_buffer.data()); | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     // Initialize the Username block
 | ||||
|     // TODO(Subv): Initialize this directly in the variable when MSVC supports char16_t string literals
 | ||||
|     CONSOLE_USERNAME_BLOCK.ng_word = 0; | ||||
|     CONSOLE_USERNAME_BLOCK.zero = 0; | ||||
|     // Copy string to buffer and pad with zeros at the end
 | ||||
|     auto size = Common::UTF8ToUTF16(CONSOLE_USERNAME).copy(CONSOLE_USERNAME_BLOCK.username, 0x14); | ||||
|     std::fill(std::begin(CONSOLE_USERNAME_BLOCK.username) + size, | ||||
|               std::end(CONSOLE_USERNAME_BLOCK.username), 0); | ||||
|     FormatConfig(); | ||||
| } | ||||
| 
 | ||||
| void CFGShutdown() { | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| } // namespace CFG
 | ||||
| } // namespace Service
 | ||||
							
								
								
									
										144
									
								
								src/core/hle/service/cfg/cfg.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										144
									
								
								src/core/hle/service/cfg/cfg.h
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,144 @@ | |||
| // Copyright 2014 Citra Emulator Project
 | ||||
| // Licensed under GPLv2 or any later version
 | ||||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <array> | ||||
| #include "core/hle/result.h" | ||||
| 
 | ||||
| namespace Service { | ||||
| namespace CFG { | ||||
| 
 | ||||
| enum SystemModel { | ||||
|     NINTENDO_3DS = 0, | ||||
|     NINTENDO_3DS_XL = 1, | ||||
|     NEW_NINTENDO_3DS = 2, | ||||
|     NINTENDO_2DS = 3, | ||||
|     NEW_NINTENDO_3DS_XL = 4 | ||||
| }; | ||||
| 
 | ||||
| enum SystemLanguage { | ||||
|     LANGUAGE_JP = 0, | ||||
|     LANGUAGE_EN = 1, | ||||
|     LANGUAGE_FR = 2, | ||||
|     LANGUAGE_DE = 3, | ||||
|     LANGUAGE_IT = 4, | ||||
|     LANGUAGE_ES = 5, | ||||
|     LANGUAGE_ZH = 6, | ||||
|     LANGUAGE_KO = 7, | ||||
|     LANGUAGE_NL = 8, | ||||
|     LANGUAGE_PT = 9, | ||||
|     LANGUAGE_RU = 10 | ||||
| }; | ||||
| 
 | ||||
| /// Block header in the config savedata file
 | ||||
| struct SaveConfigBlockEntry { | ||||
|     u32 block_id;       ///< The id of the current block
 | ||||
|     u32 offset_or_data; ///< This is the absolute offset to the block data if the size is greater than 4 bytes, otherwise it contains the data itself
 | ||||
|     u16 size;           ///< The size of the block
 | ||||
|     u16 flags;          ///< The flags of the block, possibly used for access control
 | ||||
| }; | ||||
| 
 | ||||
| /// The maximum number of block entries that can exist in the config file
 | ||||
| static const u32 CONFIG_FILE_MAX_BLOCK_ENTRIES = 1479; | ||||
| 
 | ||||
| /**
 | ||||
| * The header of the config savedata file, | ||||
| * 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
 | ||||
| }; | ||||
| static_assert(sizeof(SaveFileConfig) == 0x455C, "The SaveFileConfig header must be exactly 0x455C bytes"); | ||||
| 
 | ||||
| struct UsernameBlock { | ||||
|     char16_t username[10]; ///< Exactly 20 bytes long, padded with zeros at the end if necessary
 | ||||
|     u32 zero; | ||||
|     u32 ng_word; | ||||
| }; | ||||
| static_assert(sizeof(UsernameBlock) == 0x1C, "Size of UsernameBlock must be 0x1C"); | ||||
| 
 | ||||
| struct ConsoleModelInfo { | ||||
|     u8 model;       ///< The console model (3DS, 2DS, etc)
 | ||||
|     u8 unknown[3];  ///< Unknown data
 | ||||
| }; | ||||
| static_assert(sizeof(ConsoleModelInfo) == 4, "ConsoleModelInfo must be exactly 4 bytes"); | ||||
| 
 | ||||
| struct ConsoleCountryInfo { | ||||
|     u8 unknown[3];   ///< Unknown data
 | ||||
|     u8 country_code; ///< The country code of the console
 | ||||
| }; | ||||
| static_assert(sizeof(ConsoleCountryInfo) == 4, "ConsoleCountryInfo must be exactly 4 bytes"); | ||||
| 
 | ||||
| extern const u64 CFG_SAVE_ID; | ||||
| extern const u64 CONSOLE_UNIQUE_ID; | ||||
| extern const ConsoleModelInfo CONSOLE_MODEL; | ||||
| extern const u8 CONSOLE_LANGUAGE; | ||||
| extern const char CONSOLE_USERNAME[0x14]; | ||||
| /// This will be initialized in the Interface constructor, and will be used when creating the block
 | ||||
| extern UsernameBlock CONSOLE_USERNAME_BLOCK; | ||||
| /// TODO(Subv): Find out what this actually is
 | ||||
| extern const u8 SOUND_OUTPUT_MODE; | ||||
| extern const u8 UNITED_STATES_COUNTRY_ID; | ||||
| /// TODO(Subv): Find what the other bytes are
 | ||||
| extern const ConsoleCountryInfo COUNTRY_INFO; | ||||
| extern const std::array<float, 8> STEREO_CAMERA_SETTINGS; | ||||
| 
 | ||||
| static_assert(sizeof(STEREO_CAMERA_SETTINGS) == 0x20, "STEREO_CAMERA_SETTINGS must be exactly 0x20 bytes"); | ||||
| static_assert(sizeof(CONSOLE_UNIQUE_ID) == 8, "CONSOLE_UNIQUE_ID must be exactly 8 bytes"); | ||||
| static_assert(sizeof(CONSOLE_LANGUAGE) == 1, "CONSOLE_LANGUAGE must be exactly 1 byte"); | ||||
| static_assert(sizeof(SOUND_OUTPUT_MODE) == 1, "SOUND_OUTPUT_MODE must be exactly 1 byte"); | ||||
| 
 | ||||
| /**
 | ||||
|  * Reads a block with the specified id and flag from the Config savegame buffer | ||||
|  * and writes the output to output. | ||||
|  * The input size must match exactly the size of the requested block | ||||
|  * @param block_id The id of the block we want to read | ||||
|  * @param size The size of the block we want to read | ||||
|  * @param flag The requested block must have this flag set | ||||
|  * @param output A pointer where we will write the read data | ||||
|  * @returns ResultCode indicating the result of the operation, 0 on success | ||||
|  */ | ||||
| ResultCode GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, u8* output); | ||||
| 
 | ||||
| /**
 | ||||
|  * Creates a block with the specified id and writes the input data to the cfg savegame buffer in memory. | ||||
|  * The config savegame file in the filesystem is not updated. | ||||
|  * @param block_id The id of the block we want to create | ||||
|  * @param size The size of the block we want to create | ||||
|  * @param flag The flags of the new block | ||||
|  * @param data A pointer containing the data we will write to the new block | ||||
|  * @returns ResultCode indicating the result of the operation, 0 on success | ||||
|  */ | ||||
| ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const u8* data); | ||||
| 
 | ||||
| /**
 | ||||
|  * Deletes the config savegame file from the filesystem, the buffer in memory is not affected | ||||
|  * @returns ResultCode indicating the result of the operation, 0 on success | ||||
|  */ | ||||
| ResultCode DeleteConfigNANDSaveFile(); | ||||
| 
 | ||||
| /**
 | ||||
|  * Writes the config savegame memory buffer to the config savegame file in the filesystem | ||||
|  * @returns ResultCode indicating the result of the operation, 0 on success | ||||
|  */ | ||||
| ResultCode UpdateConfigNANDSavegame(); | ||||
| 
 | ||||
| /**
 | ||||
|  * Re-creates the config savegame file in memory and the filesystem with the default blocks | ||||
|  * @returns ResultCode indicating the result of the operation, 0 on success | ||||
|  */ | ||||
| ResultCode FormatConfig(); | ||||
| 
 | ||||
| /// Initialize the config service
 | ||||
| void CFGInit(); | ||||
| 
 | ||||
| /// Shutdown the config service
 | ||||
| void CFGShutdown(); | ||||
| 
 | ||||
| } // namespace CFG
 | ||||
| } // namespace Service
 | ||||
|  | @ -4,29 +4,83 @@ | |||
| 
 | ||||
| #include "common/log.h" | ||||
| #include "core/hle/hle.h" | ||||
| #include "core/hle/service/cfg_i.h" | ||||
| #include "core/hle/service/cfg/cfg.h" | ||||
| #include "core/hle/service/cfg/cfg_i.h" | ||||
| 
 | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////
 | ||||
| // Namespace CFG_I
 | ||||
| 
 | ||||
| namespace CFG_I { | ||||
|      | ||||
| /**
 | ||||
|  * CFG_I::GetConfigInfoBlk8 service function | ||||
|  * This function is called by two command headers, | ||||
|  * there appears to be no difference between them according to 3dbrew | ||||
|  *  Inputs: | ||||
|  *      0 : 0x04010082 / 0x08010082 | ||||
|  *      1 : Size | ||||
|  *      2 : Block ID | ||||
|  *      3 : Descriptor for the output buffer | ||||
|  *      4 : Output buffer pointer | ||||
|  *  Outputs: | ||||
|  *      1 : Result of function, 0 on success, otherwise error code | ||||
|  */ | ||||
| static void GetConfigInfoBlk8(Service::Interface* self) { | ||||
|     u32* cmd_buffer = Kernel::GetCommandBuffer(); | ||||
|     u32 size = cmd_buffer[1]; | ||||
|     u32 block_id = cmd_buffer[2]; | ||||
|     u8* data_pointer = Memory::GetPointer(cmd_buffer[4]); | ||||
| 
 | ||||
|     if (data_pointer == nullptr) { | ||||
|         cmd_buffer[1] = -1; // TODO(Subv): Find the right error code
 | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     cmd_buffer[1] = Service::CFG::GetConfigInfoBlock(block_id, size, 0x8, data_pointer).raw; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * CFG_I::UpdateConfigNANDSavegame service function | ||||
|  * This function is called by two command headers,  | ||||
|  * there appears to be no difference between them according to 3dbrew | ||||
|  *  Inputs: | ||||
|  *      0 : 0x04030000 / 0x08030000 | ||||
|  *  Outputs: | ||||
|  *      1 : Result of function, 0 on success, otherwise error code | ||||
|  */ | ||||
| static void UpdateConfigNANDSavegame(Service::Interface* self) { | ||||
|     u32* cmd_buffer = Kernel::GetCommandBuffer(); | ||||
|     cmd_buffer[1] = Service::CFG::UpdateConfigNANDSavegame().raw; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * CFG_I::FormatConfig service function | ||||
|  *  Inputs: | ||||
|  *      0 : 0x08060000 | ||||
|  *  Outputs: | ||||
|  *      1 : Result of function, 0 on success, otherwise error code | ||||
|  */ | ||||
| static void FormatConfig(Service::Interface* self) { | ||||
|     u32* cmd_buffer = Kernel::GetCommandBuffer(); | ||||
|     cmd_buffer[1] = Service::CFG::FormatConfig().raw; | ||||
| } | ||||
| 
 | ||||
| const Interface::FunctionInfo FunctionTable[] = { | ||||
|     {0x04010082, nullptr,               "GetConfigInfoBlk8"}, | ||||
|     {0x04020082, nullptr,               "GetConfigInfoBlk4"}, | ||||
|     {0x04030000, nullptr,               "UpdateConfigNANDSavegame"}, | ||||
|     {0x04010082, GetConfigInfoBlk8,     "GetConfigInfoBlk8"}, | ||||
|     {0x04020082, nullptr,               "SetConfigInfoBlk4"}, | ||||
|     {0x04030000, UpdateConfigNANDSavegame, "UpdateConfigNANDSavegame"}, | ||||
|     {0x04040042, nullptr,               "GetLocalFriendCodeSeedData"}, | ||||
|     {0x04050000, nullptr,               "GetLocalFriendCodeSeed"}, | ||||
|     {0x04060000, nullptr,               "SecureInfoGetRegion"}, | ||||
|     {0x04070000, nullptr,               "SecureInfoGetByte101"}, | ||||
|     {0x04080042, nullptr,               "SecureInfoGetSerialNo"}, | ||||
|     {0x04090000, nullptr,               "UpdateConfigBlk00040003"}, | ||||
|     {0x08010082, nullptr,               "GetConfigInfoBlk8"}, | ||||
|     {0x08020082, nullptr,               "GetConfigInfoBlk4"}, | ||||
|     {0x08030000, nullptr,               "UpdateConfigNANDSavegame"}, | ||||
|     {0x08010082, GetConfigInfoBlk8,     "GetConfigInfoBlk8"}, | ||||
|     {0x08020082, nullptr,               "SetConfigInfoBlk4"}, | ||||
|     {0x08030000, UpdateConfigNANDSavegame, "UpdateConfigNANDSavegame"}, | ||||
|     {0x080400C2, nullptr,               "CreateConfigInfoBlk"}, | ||||
|     {0x08050000, nullptr,               "DeleteConfigNANDSavefile"}, | ||||
|     {0x08060000, nullptr,               "FormatConfig"}, | ||||
|     {0x08060000, FormatConfig,          "FormatConfig"}, | ||||
|     {0x08070000, nullptr,               "Unknown"}, | ||||
|     {0x08080000, nullptr,               "UpdateConfigBlk1"}, | ||||
|     {0x08090000, nullptr,               "UpdateConfigBlk2"}, | ||||
|  | @ -2,9 +2,13 @@ | |||
| // Licensed under GPLv2 or any later version
 | ||||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include "common/file_util.h" | ||||
| #include "common/log.h" | ||||
| #include "common/string_util.h" | ||||
| #include "core/file_sys/archive_systemsavedata.h" | ||||
| #include "core/hle/hle.h" | ||||
| #include "core/hle/service/cfg_u.h" | ||||
| #include "core/hle/service/cfg/cfg.h" | ||||
| #include "core/hle/service/cfg/cfg_u.h" | ||||
| 
 | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////
 | ||||
| // Namespace CFG_U
 | ||||
|  | @ -99,13 +103,79 @@ static void GetCountryCodeID(Service::Interface* self) { | |||
|     cmd_buffer[2] = country_code_id; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * CFG_User::GetConfigInfoBlk2 service function | ||||
|  *  Inputs: | ||||
|  *      0 : 0x00010082 | ||||
|  *      1 : Size | ||||
|  *      2 : Block ID | ||||
|  *      3 : Descriptor for the output buffer | ||||
|  *      4 : Output buffer pointer | ||||
|  *  Outputs: | ||||
|  *      1 : Result of function, 0 on success, otherwise error code | ||||
|  */ | ||||
| static void GetConfigInfoBlk2(Service::Interface* self) { | ||||
|     u32* cmd_buffer = Kernel::GetCommandBuffer(); | ||||
|     u32 size = cmd_buffer[1]; | ||||
|     u32 block_id = cmd_buffer[2]; | ||||
|     u8* data_pointer = Memory::GetPointer(cmd_buffer[4]); | ||||
|      | ||||
|     if (data_pointer == nullptr) { | ||||
|         cmd_buffer[1] = -1; // TODO(Subv): Find the right error code
 | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     cmd_buffer[1] = Service::CFG::GetConfigInfoBlock(block_id, size, 0x2, data_pointer).raw; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * CFG_User::GetSystemModel service function | ||||
|  *  Inputs: | ||||
|  *      0 : 0x00050000 | ||||
|  *  Outputs: | ||||
|  *      1 : Result of function, 0 on success, otherwise error code | ||||
|  *      2 : Model of the console | ||||
|  */ | ||||
| static void GetSystemModel(Service::Interface* self) { | ||||
|     u32* cmd_buffer = Kernel::GetCommandBuffer(); | ||||
|     u32 data; | ||||
| 
 | ||||
|     // TODO(Subv): Find out the correct error codes
 | ||||
|     cmd_buffer[1] = Service::CFG::GetConfigInfoBlock(0x000F0004, 4, 0x8, | ||||
|                                                      reinterpret_cast<u8*>(&data)).raw;  | ||||
|     cmd_buffer[2] = data & 0xFF; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
|  * CFG_User::GetModelNintendo2DS service function | ||||
|  *  Inputs: | ||||
|  *      0 : 0x00060000 | ||||
|  *  Outputs: | ||||
|  *      1 : Result of function, 0 on success, otherwise error code | ||||
|  *      2 : 0 if the system is a Nintendo 2DS, 1 otherwise | ||||
|  */ | ||||
| static void GetModelNintendo2DS(Service::Interface* self) { | ||||
|     u32* cmd_buffer = Kernel::GetCommandBuffer(); | ||||
|     u32 data; | ||||
| 
 | ||||
|     // TODO(Subv): Find out the correct error codes
 | ||||
|     cmd_buffer[1] = Service::CFG::GetConfigInfoBlock(0x000F0004, 4, 0x8, | ||||
|                                                      reinterpret_cast<u8*>(&data)).raw;  | ||||
|      | ||||
|     u8 model = data & 0xFF; | ||||
|     if (model == Service::CFG::NINTENDO_2DS) | ||||
|         cmd_buffer[2] = 0; | ||||
|     else | ||||
|         cmd_buffer[2] = 1; | ||||
| } | ||||
| 
 | ||||
| const Interface::FunctionInfo FunctionTable[] = { | ||||
|     {0x00010082, nullptr,               "GetConfigInfoBlk2"}, | ||||
|     {0x00010082, GetConfigInfoBlk2,     "GetConfigInfoBlk2"}, | ||||
|     {0x00020000, nullptr,               "SecureInfoGetRegion"}, | ||||
|     {0x00030000, nullptr,               "GenHashConsoleUnique"}, | ||||
|     {0x00040000, nullptr,               "GetRegionCanadaUSA"}, | ||||
|     {0x00050000, nullptr,               "GetSystemModel"}, | ||||
|     {0x00060000, nullptr,               "GetModelNintendo2DS"}, | ||||
|     {0x00050000, GetSystemModel,        "GetSystemModel"}, | ||||
|     {0x00060000, GetModelNintendo2DS,   "GetModelNintendo2DS"}, | ||||
|     {0x00070040, nullptr,               "unknown"}, | ||||
|     {0x00080080, nullptr,               "unknown"}, | ||||
|     {0x00090040, GetCountryCodeString,  "GetCountryCodeString"}, | ||||
|  | @ -428,15 +428,6 @@ void ArchiveInit() { | |||
|         CreateArchive(std::move(sdmc_archive), ArchiveIdCode::SDMC); | ||||
|     else | ||||
|         LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str()); | ||||
| 
 | ||||
|     std::string systemsavedata_directory = FileUtil::GetUserPath(D_SYSSAVEDATA_IDX); | ||||
|     auto systemsavedata_archive = Common::make_unique<FileSys::Archive_SDMC>(systemsavedata_directory); | ||||
|     if (systemsavedata_archive->Initialize()) { | ||||
|         CreateArchive(std::move(systemsavedata_archive), ArchiveIdCode::SystemSaveData); | ||||
|     } else { | ||||
|         LOG_ERROR(Service_FS, "Can't instantiate SystemSaveData archive with path %s", | ||||
|             systemsavedata_directory.c_str()); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /// Shutdown archives
 | ||||
|  |  | |||
|  | @ -12,8 +12,8 @@ | |||
| #include "core/hle/service/apt_u.h" | ||||
| #include "core/hle/service/boss_u.h" | ||||
| #include "core/hle/service/cecd_u.h" | ||||
| #include "core/hle/service/cfg_i.h" | ||||
| #include "core/hle/service/cfg_u.h" | ||||
| #include "core/hle/service/cfg/cfg_i.h" | ||||
| #include "core/hle/service/cfg/cfg_u.h" | ||||
| #include "core/hle/service/csnd_snd.h" | ||||
| #include "core/hle/service/dsp_dsp.h" | ||||
| #include "core/hle/service/err_f.h" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue