summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/core/hle/service/cfg/cfg.cpp141
-rw-r--r--src/core/hle/service/cfg/cfg.h57
3 files changed, 108 insertions, 92 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index fa6463b01..604362e57 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,7 +74,7 @@ if (NOT MSVC)
74 endif() 74 endif()
75else() 75else()
76 # Silence "deprecation" warnings 76 # Silence "deprecation" warnings
77 add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE) 77 add_definitions(/D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /D_SCL_SECURE_NO_WARNINGS)
78 # Avoid windows.h junk 78 # Avoid windows.h junk
79 add_definitions(/DNOMINMAX) 79 add_definitions(/DNOMINMAX)
80 80
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp
index 62ad90fdc..6f2cf0190 100644
--- a/src/core/hle/service/cfg/cfg.cpp
+++ b/src/core/hle/service/cfg/cfg.cpp
@@ -21,28 +21,67 @@
21namespace Service { 21namespace Service {
22namespace CFG { 22namespace CFG {
23 23
24const u64 CFG_SAVE_ID = 0x00010017; 24/// The maximum number of block entries that can exist in the config file
25const u64 CONSOLE_UNIQUE_ID = 0xDEADC0DE; 25static const u32 CONFIG_FILE_MAX_BLOCK_ENTRIES = 1479;
26const ConsoleModelInfo CONSOLE_MODEL = { NINTENDO_3DS_XL, { 0, 0, 0 } }; 26
27const u8 CONSOLE_LANGUAGE = LANGUAGE_EN; 27namespace {
28const char CONSOLE_USERNAME[0x14] = "CITRA"; 28
29/**
30 * The header of the config savedata file,
31 * contains information about the blocks in the file
32 */
33struct SaveFileConfig {
34 u16 total_entries; ///< The total number of set entries in the config file
35 u16 data_entries_offset; ///< The offset where the data for the blocks start, this is hardcoded to 0x455C as per hardware
36 SaveConfigBlockEntry block_entries[CONFIG_FILE_MAX_BLOCK_ENTRIES]; ///< The block headers, the maximum possible value is 1479 as per hardware
37 u32 unknown; ///< This field is unknown, possibly padding, 0 has been observed in hardware
38};
39static_assert(sizeof(SaveFileConfig) == 0x455C, "SaveFileConfig header must be exactly 0x455C bytes");
40
41struct UsernameBlock {
42 char16_t username[10]; ///< Exactly 20 bytes long, padded with zeros at the end if necessary
43 u32 zero;
44 u32 ng_word;
45};
46static_assert(sizeof(UsernameBlock) == 0x1C, "UsernameBlock must be exactly 0x1C bytes");
47
48struct ConsoleModelInfo {
49 u8 model; ///< The console model (3DS, 2DS, etc)
50 u8 unknown[3]; ///< Unknown data
51};
52static_assert(sizeof(ConsoleModelInfo) == 4, "ConsoleModelInfo must be exactly 4 bytes");
53
54struct ConsoleCountryInfo {
55 u8 unknown[3]; ///< Unknown data
56 u8 country_code; ///< The country code of the console
57};
58static_assert(sizeof(ConsoleCountryInfo) == 4, "ConsoleCountryInfo must be exactly 4 bytes");
59
60}
61
62static const u64 CFG_SAVE_ID = 0x00010017;
63static const u64 CONSOLE_UNIQUE_ID = 0xDEADC0DE;
64static const ConsoleModelInfo CONSOLE_MODEL = { NINTENDO_3DS_XL, { 0, 0, 0 } };
65static const u8 CONSOLE_LANGUAGE = LANGUAGE_EN;
66static const char CONSOLE_USERNAME[0x14] = "CITRA";
29/// This will be initialized in Init, and will be used when creating the block 67/// This will be initialized in Init, and will be used when creating the block
30UsernameBlock CONSOLE_USERNAME_BLOCK; 68static UsernameBlock CONSOLE_USERNAME_BLOCK;
31/// TODO(Subv): Find out what this actually is 69/// TODO(Subv): Find out what this actually is
32const u8 SOUND_OUTPUT_MODE = 2; 70static const u8 SOUND_OUTPUT_MODE = 2;
33const u8 UNITED_STATES_COUNTRY_ID = 49; 71static const u8 UNITED_STATES_COUNTRY_ID = 49;
34/// TODO(Subv): Find what the other bytes are 72/// TODO(Subv): Find what the other bytes are
35const ConsoleCountryInfo COUNTRY_INFO = { { 0, 0, 0 }, UNITED_STATES_COUNTRY_ID }; 73static const ConsoleCountryInfo COUNTRY_INFO = { { 0, 0, 0 }, UNITED_STATES_COUNTRY_ID };
36 74
37/** 75/**
38 * TODO(Subv): Find out what this actually is, these values fix some NaN uniforms in some games, 76 * TODO(Subv): Find out what this actually is, these values fix some NaN uniforms in some games,
39 * for example Nintendo Zone 77 * for example Nintendo Zone
40 * Thanks Normmatt for providing this information 78 * Thanks Normmatt for providing this information
41 */ 79 */
42const std::array<float, 8> STEREO_CAMERA_SETTINGS = { 80static const std::array<float, 8> STEREO_CAMERA_SETTINGS = {
43 62.0f, 289.0f, 76.80000305175781f, 46.08000183105469f, 81 62.0f, 289.0f, 76.80000305175781f, 46.08000183105469f,
44 10.0f, 5.0f, 55.58000183105469f, 21.56999969482422f 82 10.0f, 5.0f, 55.58000183105469f, 21.56999969482422f
45}; 83};
84static_assert(sizeof(STEREO_CAMERA_SETTINGS) == 0x20, "STEREO_CAMERA_SETTINGS must be exactly 0x20 bytes");
46 85
47static const u32 CONFIG_SAVEFILE_SIZE = 0x8000; 86static const u32 CONFIG_SAVEFILE_SIZE = 0x8000;
48static std::array<u8, CONFIG_SAVEFILE_SIZE> cfg_config_file_buffer; 87static std::array<u8, CONFIG_SAVEFILE_SIZE> cfg_config_file_buffer;
@@ -212,7 +251,7 @@ ResultCode GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, u8* output) {
212 return RESULT_SUCCESS; 251 return RESULT_SUCCESS;
213} 252}
214 253
215ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const u8* data) { 254ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const void* data) {
216 SaveFileConfig* config = reinterpret_cast<SaveFileConfig*>(cfg_config_file_buffer.data()); 255 SaveFileConfig* config = reinterpret_cast<SaveFileConfig*>(cfg_config_file_buffer.data());
217 if (config->total_entries >= CONFIG_FILE_MAX_BLOCK_ENTRIES) 256 if (config->total_entries >= CONFIG_FILE_MAX_BLOCK_ENTRIES)
218 return ResultCode(-1); // TODO(Subv): Find the right error code 257 return ResultCode(-1); // TODO(Subv): Find the right error code
@@ -277,33 +316,63 @@ ResultCode FormatConfig() {
277 SaveFileConfig* config = reinterpret_cast<SaveFileConfig*>(cfg_config_file_buffer.data()); 316 SaveFileConfig* config = reinterpret_cast<SaveFileConfig*>(cfg_config_file_buffer.data());
278 // This value is hardcoded, taken from 3dbrew, verified by hardware, it's always the same value 317 // This value is hardcoded, taken from 3dbrew, verified by hardware, it's always the same value
279 config->data_entries_offset = 0x455C; 318 config->data_entries_offset = 0x455C;
319
280 // Insert the default blocks 320 // Insert the default blocks
281 res = CreateConfigInfoBlk(0x00050005, sizeof(STEREO_CAMERA_SETTINGS), 0xE, 321 u8 zero_buffer[0xC0] = {};
282 reinterpret_cast<const u8*>(STEREO_CAMERA_SETTINGS.data())); 322
283 if (!res.IsSuccess()) 323 // 0x00030001 - Unknown
284 return res; 324 res = CreateConfigInfoBlk(0x00030001, 0x8, 0xE, zero_buffer);
285 res = CreateConfigInfoBlk(0x00090001, sizeof(CONSOLE_UNIQUE_ID), 0xE, 325 if (!res.IsSuccess()) return res;
286 reinterpret_cast<const u8*>(&CONSOLE_UNIQUE_ID)); 326
287 if (!res.IsSuccess()) 327 res = CreateConfigInfoBlk(0x00050005, sizeof(STEREO_CAMERA_SETTINGS), 0xE, STEREO_CAMERA_SETTINGS.data());
288 return res; 328 if (!res.IsSuccess()) return res;
289 res = CreateConfigInfoBlk(0x000F0004, sizeof(CONSOLE_MODEL), 0x8,
290 reinterpret_cast<const u8*>(&CONSOLE_MODEL));
291 if (!res.IsSuccess())
292 return res;
293 res = CreateConfigInfoBlk(0x000A0002, sizeof(CONSOLE_LANGUAGE), 0xA, &CONSOLE_LANGUAGE);
294 if (!res.IsSuccess())
295 return res;
296 res = CreateConfigInfoBlk(0x00070001, sizeof(SOUND_OUTPUT_MODE), 0xE, &SOUND_OUTPUT_MODE); 329 res = CreateConfigInfoBlk(0x00070001, sizeof(SOUND_OUTPUT_MODE), 0xE, &SOUND_OUTPUT_MODE);
297 if (!res.IsSuccess()) 330 if (!res.IsSuccess()) return res;
298 return res; 331 res = CreateConfigInfoBlk(0x00090001, sizeof(CONSOLE_UNIQUE_ID), 0xE, &CONSOLE_UNIQUE_ID);
299 res = CreateConfigInfoBlk(0x000B0000, sizeof(COUNTRY_INFO), 0xE, 332 if (!res.IsSuccess()) return res;
300 reinterpret_cast<const u8*>(&COUNTRY_INFO)); 333 res = CreateConfigInfoBlk(0x000A0000, sizeof(CONSOLE_USERNAME_BLOCK), 0xE, &CONSOLE_USERNAME_BLOCK);
301 if (!res.IsSuccess()) 334 if (!res.IsSuccess()) return res;
302 return res; 335
303 res = CreateConfigInfoBlk(0x000A0000, sizeof(CONSOLE_USERNAME_BLOCK), 0xE, 336 // 0x000A0001 - Profile birthday
304 reinterpret_cast<const u8*>(&CONSOLE_USERNAME_BLOCK)); 337 const u8 profile_birthday[2] = {3, 25}; // March 25th, 2014
305 if (!res.IsSuccess()) 338 res = CreateConfigInfoBlk(0x000A0001, sizeof(profile_birthday), 0xE, profile_birthday);
306 return res; 339 if (!res.IsSuccess()) return res;
340
341 res = CreateConfigInfoBlk(0x000A0002, sizeof(CONSOLE_LANGUAGE), 0xE, &CONSOLE_LANGUAGE);
342 if (!res.IsSuccess()) return res;
343 res = CreateConfigInfoBlk(0x000B0000, sizeof(COUNTRY_INFO), 0xE, &COUNTRY_INFO);
344 if (!res.IsSuccess()) return res;
345
346 char16_t country_name_buffer[16][0x40] = {};
347 for (size_t i = 0; i < 16; ++i) {
348 auto size = Common::UTF8ToUTF16("Gensokyo").copy(country_name_buffer[i], 0x40);
349 }
350 // 0x000B0001 - Localized names for the profile Country
351 res = CreateConfigInfoBlk(0x000B0001, sizeof(country_name_buffer), 0xE, country_name_buffer);
352 if (!res.IsSuccess()) return res;
353 // 0x000B0002 - Localized names for the profile State/Province
354 res = CreateConfigInfoBlk(0x000B0002, sizeof(country_name_buffer), 0xE, country_name_buffer);
355 if (!res.IsSuccess()) return res;
356
357 // 0x000B0003 - Unknown, related to country/address (zip code?)
358 res = CreateConfigInfoBlk(0x000B0003, 0x4, 0xE, zero_buffer);
359 if (!res.IsSuccess()) return res;
360
361 // 0x000C0000 - Unknown
362 res = CreateConfigInfoBlk(0x000C0000, 0xC0, 0xE, zero_buffer);
363 if (!res.IsSuccess()) return res;
364
365 // 0x000C0001 - Unknown
366 res = CreateConfigInfoBlk(0x000C0001, 0x14, 0xE, zero_buffer);
367 if (!res.IsSuccess()) return res;
368
369 // 0x000D0000 - Accepted EULA version
370 res = CreateConfigInfoBlk(0x000D0000, 0x4, 0xE, zero_buffer);
371 if (!res.IsSuccess()) return res;
372
373 res = CreateConfigInfoBlk(0x000F0004, sizeof(CONSOLE_MODEL), 0xC, &CONSOLE_MODEL);
374 if (!res.IsSuccess()) return res;
375
307 // Save the buffer to the file 376 // Save the buffer to the file
308 res = UpdateConfigNANDSavegame(); 377 res = UpdateConfigNANDSavegame();
309 if (!res.IsSuccess()) 378 if (!res.IsSuccess())
diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h
index ff76dc9dc..7b7a76b08 100644
--- a/src/core/hle/service/cfg/cfg.h
+++ b/src/core/hle/service/cfg/cfg.h
@@ -42,7 +42,7 @@ struct SaveConfigBlockEntry {
42}; 42};
43 43
44// TODO(Link Mauve): use a constexpr once MSVC starts supporting it. 44// TODO(Link Mauve): use a constexpr once MSVC starts supporting it.
45#define C(code) ((code)[0] | ((code)[1] << 8)) 45#define C(code) (u16)((code)[0] | ((code)[1] << 8))
46 46
47static const std::array<u16, 187> country_codes = { 47static const std::array<u16, 187> country_codes = {
48 0, C("JP"), 0, 0, 0, 0, 0, 0, // 0-7 48 0, C("JP"), 0, 0, 0, 0, 0, 0, // 0-7
@@ -204,59 +204,6 @@ void UpdateConfigNANDSavegame(Service::Interface* self);
204 */ 204 */
205void FormatConfig(Service::Interface* self); 205void FormatConfig(Service::Interface* self);
206 206
207/// The maximum number of block entries that can exist in the config file
208static const u32 CONFIG_FILE_MAX_BLOCK_ENTRIES = 1479;
209
210/**
211* The header of the config savedata file,
212* contains information about the blocks in the file
213*/
214struct SaveFileConfig {
215 u16 total_entries; ///< The total number of set entries in the config file
216 u16 data_entries_offset; ///< The offset where the data for the blocks start, this is hardcoded to 0x455C as per hardware
217 SaveConfigBlockEntry block_entries[CONFIG_FILE_MAX_BLOCK_ENTRIES]; ///< The block headers, the maximum possible value is 1479 as per hardware
218 u32 unknown; ///< This field is unknown, possibly padding, 0 has been observed in hardware
219};
220static_assert(sizeof(SaveFileConfig) == 0x455C, "The SaveFileConfig header must be exactly 0x455C bytes");
221
222struct UsernameBlock {
223 char16_t username[10]; ///< Exactly 20 bytes long, padded with zeros at the end if necessary
224 u32 zero;
225 u32 ng_word;
226};
227static_assert(sizeof(UsernameBlock) == 0x1C, "Size of UsernameBlock must be 0x1C");
228
229struct ConsoleModelInfo {
230 u8 model; ///< The console model (3DS, 2DS, etc)
231 u8 unknown[3]; ///< Unknown data
232};
233static_assert(sizeof(ConsoleModelInfo) == 4, "ConsoleModelInfo must be exactly 4 bytes");
234
235struct ConsoleCountryInfo {
236 u8 unknown[3]; ///< Unknown data
237 u8 country_code; ///< The country code of the console
238};
239static_assert(sizeof(ConsoleCountryInfo) == 4, "ConsoleCountryInfo must be exactly 4 bytes");
240
241extern const u64 CFG_SAVE_ID;
242extern const u64 CONSOLE_UNIQUE_ID;
243extern const ConsoleModelInfo CONSOLE_MODEL;
244extern const u8 CONSOLE_LANGUAGE;
245extern const char CONSOLE_USERNAME[0x14];
246/// This will be initialized in the Interface constructor, and will be used when creating the block
247extern UsernameBlock CONSOLE_USERNAME_BLOCK;
248/// TODO(Subv): Find out what this actually is
249extern const u8 SOUND_OUTPUT_MODE;
250extern const u8 UNITED_STATES_COUNTRY_ID;
251/// TODO(Subv): Find what the other bytes are
252extern const ConsoleCountryInfo COUNTRY_INFO;
253extern const std::array<float, 8> STEREO_CAMERA_SETTINGS;
254
255static_assert(sizeof(STEREO_CAMERA_SETTINGS) == 0x20, "STEREO_CAMERA_SETTINGS must be exactly 0x20 bytes");
256static_assert(sizeof(CONSOLE_UNIQUE_ID) == 8, "CONSOLE_UNIQUE_ID must be exactly 8 bytes");
257static_assert(sizeof(CONSOLE_LANGUAGE) == 1, "CONSOLE_LANGUAGE must be exactly 1 byte");
258static_assert(sizeof(SOUND_OUTPUT_MODE) == 1, "SOUND_OUTPUT_MODE must be exactly 1 byte");
259
260/** 207/**
261 * Reads a block with the specified id and flag from the Config savegame buffer 208 * Reads a block with the specified id and flag from the Config savegame buffer
262 * and writes the output to output. 209 * and writes the output to output.
@@ -278,7 +225,7 @@ ResultCode GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, u8* output);
278 * @param data A pointer containing the data we will write to the new block 225 * @param data A pointer containing the data we will write to the new block
279 * @returns ResultCode indicating the result of the operation, 0 on success 226 * @returns ResultCode indicating the result of the operation, 0 on success
280 */ 227 */
281ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const u8* data); 228ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const void* data);
282 229
283/** 230/**
284 * Deletes the config savegame file from the filesystem, the buffer in memory is not affected 231 * Deletes the config savegame file from the filesystem, the buffer in memory is not affected