2014-12-21 22:36:18 +01:00
|
|
|
// Copyright 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-12-22 00:02:27 +01:00
|
|
|
#include <algorithm>
|
2017-03-12 09:13:32 +01:00
|
|
|
#include <array>
|
2017-05-06 02:55:51 +02:00
|
|
|
#include <cryptopp/osrng.h>
|
2017-03-12 09:13:32 +01:00
|
|
|
#include <cryptopp/sha.h>
|
2016-03-01 08:42:36 +01:00
|
|
|
#include "common/file_util.h"
|
2015-05-06 09:06:12 +02:00
|
|
|
#include "common/logging/log.h"
|
2015-05-06 07:29:11 +02:00
|
|
|
#include "common/string_util.h"
|
2016-03-01 08:42:36 +01:00
|
|
|
#include "common/swap.h"
|
2015-05-14 08:15:32 +02:00
|
|
|
#include "core/file_sys/archive_systemsavedata.h"
|
2015-05-06 07:15:46 +02:00
|
|
|
#include "core/file_sys/file_backend.h"
|
2016-02-02 07:17:41 +01:00
|
|
|
#include "core/hle/result.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "core/hle/service/cfg/cfg.h"
|
2015-02-27 03:13:08 +01:00
|
|
|
#include "core/hle/service/cfg/cfg_i.h"
|
2016-12-09 07:37:05 +01:00
|
|
|
#include "core/hle/service/cfg/cfg_nor.h"
|
2015-02-27 03:13:08 +01:00
|
|
|
#include "core/hle/service/cfg/cfg_s.h"
|
|
|
|
#include "core/hle/service/cfg/cfg_u.h"
|
2015-05-06 07:15:46 +02:00
|
|
|
#include "core/hle/service/fs/archive.h"
|
|
|
|
#include "core/hle/service/service.h"
|
2016-09-18 02:38:01 +02:00
|
|
|
#include "core/settings.h"
|
2014-12-21 22:36:18 +01:00
|
|
|
|
|
|
|
namespace Service {
|
|
|
|
namespace CFG {
|
|
|
|
|
2015-09-01 19:40:50 +02:00
|
|
|
/// The maximum number of block entries that can exist in the config file
|
|
|
|
static const u32 CONFIG_FILE_MAX_BLOCK_ENTRIES = 1479;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The header of the config savedata file,
|
|
|
|
* contains information about the blocks in the file
|
|
|
|
*/
|
|
|
|
struct SaveFileConfig {
|
2016-09-18 02:38:01 +02:00
|
|
|
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
|
2015-09-01 19:40:50 +02:00
|
|
|
};
|
2016-09-18 02:38:01 +02:00
|
|
|
static_assert(sizeof(SaveFileConfig) == 0x455C,
|
|
|
|
"SaveFileConfig header must be exactly 0x455C bytes");
|
2015-09-01 19:40:50 +02:00
|
|
|
|
2016-06-01 09:40:52 +02:00
|
|
|
enum ConfigBlockID {
|
|
|
|
StereoCameraSettingsBlockID = 0x00050005,
|
2016-09-18 02:38:01 +02:00
|
|
|
SoundOutputModeBlockID = 0x00070001,
|
2016-11-17 18:34:02 +01:00
|
|
|
ConsoleUniqueID1BlockID = 0x00090000,
|
|
|
|
ConsoleUniqueID2BlockID = 0x00090001,
|
2017-05-06 02:55:51 +02:00
|
|
|
ConsoleUniqueID3BlockID = 0x00090002,
|
2016-09-18 02:38:01 +02:00
|
|
|
UsernameBlockID = 0x000A0000,
|
|
|
|
BirthdayBlockID = 0x000A0001,
|
|
|
|
LanguageBlockID = 0x000A0002,
|
|
|
|
CountryInfoBlockID = 0x000B0000,
|
|
|
|
CountryNameBlockID = 0x000B0001,
|
|
|
|
StateNameBlockID = 0x000B0002,
|
|
|
|
EULAVersionBlockID = 0x000D0000,
|
|
|
|
ConsoleModelBlockID = 0x000F0004,
|
2016-06-01 09:40:52 +02:00
|
|
|
};
|
|
|
|
|
2015-09-01 19:40:50 +02:00
|
|
|
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, "UsernameBlock must be exactly 0x1C bytes");
|
|
|
|
|
2016-05-03 18:27:47 +02:00
|
|
|
struct BirthdayBlock {
|
|
|
|
u8 month; ///< The month of the birthday
|
|
|
|
u8 day; ///< The day of the birthday
|
|
|
|
};
|
|
|
|
static_assert(sizeof(BirthdayBlock) == 2, "BirthdayBlock must be exactly 2 bytes");
|
|
|
|
|
2015-09-01 19:40:50 +02:00
|
|
|
struct ConsoleModelInfo {
|
2016-09-18 02:38:01 +02:00
|
|
|
u8 model; ///< The console model (3DS, 2DS, etc)
|
|
|
|
u8 unknown[3]; ///< Unknown data
|
2015-09-01 19:40:50 +02:00
|
|
|
};
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
static const ConsoleModelInfo CONSOLE_MODEL = {NINTENDO_3DS_XL, {0, 0, 0}};
|
2015-09-01 19:40:50 +02:00
|
|
|
static const u8 CONSOLE_LANGUAGE = LANGUAGE_EN;
|
2016-09-18 02:38:01 +02:00
|
|
|
static const UsernameBlock CONSOLE_USERNAME_BLOCK = {u"CITRA", 0, 0};
|
|
|
|
static const BirthdayBlock PROFILE_BIRTHDAY = {3, 25}; // March 25th, 2014
|
2016-06-07 17:27:14 +02:00
|
|
|
static const u8 SOUND_OUTPUT_MODE = SOUND_SURROUND;
|
2015-09-01 19:40:50 +02:00
|
|
|
static const u8 UNITED_STATES_COUNTRY_ID = 49;
|
2014-12-21 22:36:18 +01:00
|
|
|
/// TODO(Subv): Find what the other bytes are
|
2016-09-18 02:38:01 +02:00
|
|
|
static const ConsoleCountryInfo COUNTRY_INFO = {{0, 0, 0}, UNITED_STATES_COUNTRY_ID};
|
2014-12-21 22:36:18 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2016-09-18 02:38:01 +02:00
|
|
|
static const std::array<float, 8> STEREO_CAMERA_SETTINGS = {
|
2016-09-19 03:01:46 +02:00
|
|
|
62.0f, 289.0f, 76.80000305175781f, 46.08000183105469f,
|
|
|
|
10.0f, 5.0f, 55.58000183105469f, 21.56999969482422f,
|
|
|
|
};
|
2016-09-18 02:38:01 +02:00
|
|
|
static_assert(sizeof(STEREO_CAMERA_SETTINGS) == 0x20,
|
|
|
|
"STEREO_CAMERA_SETTINGS must be exactly 0x20 bytes");
|
2014-12-21 22:36:18 +01:00
|
|
|
|
2014-12-22 00:02:27 +01:00
|
|
|
static const u32 CONFIG_SAVEFILE_SIZE = 0x8000;
|
|
|
|
static std::array<u8, CONFIG_SAVEFILE_SIZE> cfg_config_file_buffer;
|
2014-12-21 22:36:18 +01:00
|
|
|
|
2015-02-25 00:02:40 +01:00
|
|
|
static Service::FS::ArchiveHandle cfg_system_save_data_archive;
|
2016-09-19 03:01:46 +02:00
|
|
|
static const std::vector<u8> cfg_system_savedata_id = {
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x01, 0x00,
|
|
|
|
};
|
2014-12-21 22:36:18 +01:00
|
|
|
|
2016-11-30 10:32:09 +01:00
|
|
|
static u32 preferred_region_code = 0;
|
|
|
|
|
2015-05-14 08:15:32 +02:00
|
|
|
void GetCountryCodeString(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
u32 country_code_id = cmd_buff[1];
|
|
|
|
|
|
|
|
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);
|
2016-09-18 02:38:01 +02:00
|
|
|
cmd_buff[1] = ResultCode(ErrorDescription::NotFound, ErrorModule::Config,
|
|
|
|
ErrorSummary::WrongArgument, ErrorLevel::Permanent)
|
|
|
|
.raw;
|
2015-05-14 08:15:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_buff[1] = 0;
|
|
|
|
cmd_buff[2] = country_codes[country_code_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetCountryCodeID(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
u16 country_code = cmd_buff[1];
|
|
|
|
u16 country_code_id = 0;
|
|
|
|
|
|
|
|
// The following algorithm will fail if the first country code isn't 0.
|
|
|
|
DEBUG_ASSERT(country_codes[0] == 0);
|
|
|
|
|
|
|
|
for (u16 id = 0; id < country_codes.size(); ++id) {
|
|
|
|
if (country_codes[id] == country_code) {
|
|
|
|
country_code_id = id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == country_code_id) {
|
2016-09-18 02:38:01 +02:00
|
|
|
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;
|
2015-05-14 08:15:32 +02:00
|
|
|
cmd_buff[2] = 0xFFFF;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_buff[1] = 0;
|
|
|
|
cmd_buff[2] = country_code_id;
|
|
|
|
}
|
|
|
|
|
2016-11-30 10:32:09 +01:00
|
|
|
static u32 GetRegionValue() {
|
|
|
|
if (Settings::values.region_value == Settings::REGION_VALUE_AUTO_SELECT)
|
|
|
|
return preferred_region_code;
|
|
|
|
|
|
|
|
return Settings::values.region_value;
|
|
|
|
}
|
|
|
|
|
2015-05-14 08:15:32 +02:00
|
|
|
void SecureInfoGetRegion(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
2016-11-30 10:32:09 +01:00
|
|
|
cmd_buff[2] = GetRegionValue();
|
2015-05-14 08:15:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenHashConsoleUnique(Service::Interface* self) {
|
2017-03-12 09:13:32 +01:00
|
|
|
IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x03, 1, 0);
|
|
|
|
const u32 app_id_salt = rp.Pop<u32>() & 0x000FFFFF;
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(3, 0);
|
|
|
|
|
|
|
|
std::array<u8, 12> buffer;
|
|
|
|
const ResultCode result = GetConfigInfoBlock(ConsoleUniqueID2BlockID, 8, 2, buffer.data());
|
|
|
|
rb.Push(result);
|
|
|
|
if (result.IsSuccess()) {
|
|
|
|
std::memcpy(&buffer[8], &app_id_salt, sizeof(u32));
|
|
|
|
std::array<u8, CryptoPP::SHA256::DIGESTSIZE> hash;
|
|
|
|
CryptoPP::SHA256().CalculateDigest(hash.data(), buffer.data(), sizeof(buffer));
|
|
|
|
u32 low, high;
|
|
|
|
memcpy(&low, &hash[hash.size() - 8], sizeof(u32));
|
|
|
|
memcpy(&high, &hash[hash.size() - 4], sizeof(u32));
|
|
|
|
rb.Push(low);
|
|
|
|
rb.Push(high);
|
|
|
|
} else {
|
|
|
|
rb.Push<u32>(0);
|
|
|
|
rb.Push<u32>(0);
|
|
|
|
}
|
2015-05-14 08:15:32 +02:00
|
|
|
|
2017-03-12 09:13:32 +01:00
|
|
|
LOG_DEBUG(Service_CFG, "called app_id_salt=0x%X", app_id_salt);
|
2015-05-14 08:15:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetRegionCanadaUSA(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
|
|
|
|
cmd_buff[1] = RESULT_SUCCESS.raw;
|
|
|
|
|
|
|
|
u8 canada_or_usa = 1;
|
2016-11-30 10:32:09 +01:00
|
|
|
if (canada_or_usa == GetRegionValue()) {
|
2015-05-14 08:15:32 +02:00
|
|
|
cmd_buff[2] = 1;
|
|
|
|
} else {
|
|
|
|
cmd_buff[2] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetSystemModel(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
u32 data;
|
|
|
|
|
|
|
|
// TODO(Subv): Find out the correct error codes
|
2016-09-18 02:38:01 +02:00
|
|
|
cmd_buff[1] =
|
|
|
|
Service::CFG::GetConfigInfoBlock(0x000F0004, 4, 0x8, reinterpret_cast<u8*>(&data)).raw;
|
2015-05-14 08:15:32 +02:00
|
|
|
cmd_buff[2] = data & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetModelNintendo2DS(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
u32 data;
|
|
|
|
|
|
|
|
// TODO(Subv): Find out the correct error codes
|
2016-09-18 02:38:01 +02:00
|
|
|
cmd_buff[1] =
|
|
|
|
Service::CFG::GetConfigInfoBlock(0x000F0004, 4, 0x8, reinterpret_cast<u8*>(&data)).raw;
|
2015-05-14 08:15:32 +02:00
|
|
|
|
|
|
|
u8 model = data & 0xFF;
|
|
|
|
if (model == Service::CFG::NINTENDO_2DS)
|
|
|
|
cmd_buff[2] = 0;
|
|
|
|
else
|
|
|
|
cmd_buff[2] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetConfigInfoBlk2(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
u32 size = cmd_buff[1];
|
|
|
|
u32 block_id = cmd_buff[2];
|
2016-04-16 12:51:48 +02:00
|
|
|
VAddr data_pointer = cmd_buff[4];
|
2015-05-14 08:15:32 +02:00
|
|
|
|
2016-04-16 12:51:48 +02:00
|
|
|
if (!Memory::IsValidVirtualAddress(data_pointer)) {
|
2015-05-14 08:15:32 +02:00
|
|
|
cmd_buff[1] = -1; // TODO(Subv): Find the right error code
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-16 12:51:48 +02:00
|
|
|
std::vector<u8> data(size);
|
|
|
|
cmd_buff[1] = Service::CFG::GetConfigInfoBlock(block_id, size, 0x2, data.data()).raw;
|
|
|
|
Memory::WriteBlock(data_pointer, data.data(), data.size());
|
2015-05-14 08:15:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetConfigInfoBlk8(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
u32 size = cmd_buff[1];
|
|
|
|
u32 block_id = cmd_buff[2];
|
2016-04-16 12:51:48 +02:00
|
|
|
VAddr data_pointer = cmd_buff[4];
|
2015-05-14 08:15:32 +02:00
|
|
|
|
2016-04-16 12:51:48 +02:00
|
|
|
if (!Memory::IsValidVirtualAddress(data_pointer)) {
|
2015-05-14 08:15:32 +02:00
|
|
|
cmd_buff[1] = -1; // TODO(Subv): Find the right error code
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-16 12:51:48 +02:00
|
|
|
std::vector<u8> data(size);
|
|
|
|
cmd_buff[1] = Service::CFG::GetConfigInfoBlock(block_id, size, 0x8, data.data()).raw;
|
|
|
|
Memory::WriteBlock(data_pointer, data.data(), data.size());
|
2015-05-14 08:15:32 +02:00
|
|
|
}
|
|
|
|
|
2016-06-01 09:37:57 +02:00
|
|
|
void SetConfigInfoBlk4(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
u32 block_id = cmd_buff[1];
|
|
|
|
u32 size = cmd_buff[2];
|
|
|
|
VAddr data_pointer = cmd_buff[4];
|
|
|
|
|
|
|
|
if (!Memory::IsValidVirtualAddress(data_pointer)) {
|
|
|
|
cmd_buff[1] = -1; // TODO(Subv): Find the right error code
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<u8> data(size);
|
|
|
|
Memory::ReadBlock(data_pointer, data.data(), data.size());
|
|
|
|
cmd_buff[1] = Service::CFG::SetConfigInfoBlock(block_id, size, 0x4, data.data()).raw;
|
|
|
|
}
|
|
|
|
|
2015-05-14 08:15:32 +02:00
|
|
|
void UpdateConfigNANDSavegame(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
cmd_buff[1] = Service::CFG::UpdateConfigNANDSavegame().raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormatConfig(Service::Interface* self) {
|
|
|
|
u32* cmd_buff = Kernel::GetCommandBuffer();
|
|
|
|
cmd_buff[1] = Service::CFG::FormatConfig().raw;
|
|
|
|
}
|
|
|
|
|
2016-06-01 09:37:57 +02:00
|
|
|
static ResultVal<void*> GetConfigInfoBlockPointer(u32 block_id, u32 size, u32 flag) {
|
2014-12-21 22:36:18 +01:00
|
|
|
// Read the header
|
|
|
|
SaveFileConfig* config = reinterpret_cast<SaveFileConfig*>(cfg_config_file_buffer.data());
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
auto itr =
|
|
|
|
std::find_if(std::begin(config->block_entries), std::end(config->block_entries),
|
|
|
|
[&](const SaveConfigBlockEntry& entry) { return entry.block_id == block_id; });
|
2014-12-21 22:36:18 +01:00
|
|
|
|
|
|
|
if (itr == std::end(config->block_entries)) {
|
2016-09-18 02:38:01 +02:00
|
|
|
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);
|
2015-02-18 07:48:30 +01:00
|
|
|
}
|
|
|
|
|
2016-06-01 09:37:57 +02:00
|
|
|
if ((itr->flags & flag) == 0) {
|
2016-09-18 02:38:01 +02:00
|
|
|
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);
|
2016-06-01 09:37:57 +02:00
|
|
|
}
|
|
|
|
|
2015-02-18 07:48:30 +01:00
|
|
|
if (itr->size != size) {
|
2016-09-18 02:38:01 +02:00
|
|
|
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);
|
2014-12-21 22:36:18 +01:00
|
|
|
}
|
|
|
|
|
2016-06-01 09:37:57 +02:00
|
|
|
void* pointer;
|
|
|
|
|
2014-12-21 22:36:18 +01:00
|
|
|
// The data is located in the block header itself if the size is less than 4 bytes
|
|
|
|
if (itr->size <= 4)
|
2016-06-01 09:37:57 +02:00
|
|
|
pointer = &itr->offset_or_data;
|
2014-12-21 22:36:18 +01:00
|
|
|
else
|
2016-06-01 09:37:57 +02:00
|
|
|
pointer = &cfg_config_file_buffer[itr->offset_or_data];
|
|
|
|
|
|
|
|
return MakeResult<void*>(pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, void* output) {
|
|
|
|
void* pointer;
|
|
|
|
CASCADE_RESULT(pointer, GetConfigInfoBlockPointer(block_id, size, flag));
|
|
|
|
memcpy(output, pointer, size);
|
2016-11-30 10:32:09 +01:00
|
|
|
|
2016-06-01 09:37:57 +02:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
2014-12-21 22:36:18 +01:00
|
|
|
|
2016-06-01 09:37:57 +02:00
|
|
|
ResultCode SetConfigInfoBlock(u32 block_id, u32 size, u32 flag, const void* input) {
|
|
|
|
void* pointer;
|
|
|
|
CASCADE_RESULT(pointer, GetConfigInfoBlockPointer(block_id, size, flag));
|
|
|
|
memcpy(pointer, input, size);
|
2014-12-21 22:36:18 +01:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-09-01 17:34:59 +02:00
|
|
|
ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const void* data) {
|
2014-12-21 22:36:18 +01:00
|
|
|
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
|
2016-09-18 02:38:01 +02:00
|
|
|
config->block_entries[config->total_entries] = {block_id, 0, size, flags};
|
2014-12-21 22:36:18 +01:00
|
|
|
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
|
2014-12-21 23:26:51 +01:00
|
|
|
for (int i = config->total_entries - 1; i >= 0; --i) {
|
2014-12-21 22:36:18 +01:00
|
|
|
// Ignore the blocks that don't have a separate data offset
|
2014-12-21 23:26:51 +01:00
|
|
|
if (config->block_entries[i].size > 4) {
|
2016-09-18 02:38:01 +02:00
|
|
|
offset = config->block_entries[i].offset_or_data + config->block_entries[i].size;
|
2014-12-21 22:36:18 +01:00
|
|
|
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);
|
2016-09-18 02:38:01 +02:00
|
|
|
} else {
|
2014-12-21 22:36:18 +01:00
|
|
|
// 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() {
|
2016-10-20 03:43:43 +02:00
|
|
|
FileSys::Path path("/config");
|
2015-02-25 00:02:40 +01:00
|
|
|
return Service::FS::DeleteFileFromArchive(cfg_system_save_data_archive, path);
|
2014-12-21 22:36:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode UpdateConfigNANDSavegame() {
|
|
|
|
FileSys::Mode mode = {};
|
2016-02-11 18:41:15 +01:00
|
|
|
mode.write_flag.Assign(1);
|
|
|
|
mode.create_flag.Assign(1);
|
2015-02-25 00:02:40 +01:00
|
|
|
|
2016-10-20 03:43:43 +02:00
|
|
|
FileSys::Path path("/config");
|
2015-02-25 00:02:40 +01:00
|
|
|
|
|
|
|
auto config_result = Service::FS::OpenFileFromArchive(cfg_system_save_data_archive, path, mode);
|
|
|
|
ASSERT_MSG(config_result.Succeeded(), "could not open file");
|
|
|
|
|
|
|
|
auto config = config_result.MoveFrom();
|
|
|
|
config->backend->Write(0, CONFIG_SAVEFILE_SIZE, 1, cfg_config_file_buffer.data());
|
|
|
|
|
2014-12-21 22:36:18 +01:00
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode FormatConfig() {
|
|
|
|
ResultCode res = DeleteConfigNANDSaveFile();
|
2016-01-16 23:01:01 +01:00
|
|
|
// The delete command fails if the file doesn't exist, so we have to check that too
|
2017-05-21 06:00:18 +02:00
|
|
|
if (!res.IsSuccess() &&
|
|
|
|
res.description != static_cast<u32>(ErrorDescription::FS_FileNotFound)) {
|
2014-12-21 22:36:18 +01:00
|
|
|
return res;
|
2016-10-20 03:43:43 +02:00
|
|
|
}
|
2014-12-21 22:36:18 +01:00
|
|
|
// Delete the old data
|
2014-12-22 00:02:27 +01:00
|
|
|
cfg_config_file_buffer.fill(0);
|
2014-12-21 22:36:18 +01:00
|
|
|
// 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;
|
2015-09-01 17:34:59 +02:00
|
|
|
|
2014-12-21 22:36:18 +01:00
|
|
|
// Insert the default blocks
|
2015-09-01 20:09:50 +02:00
|
|
|
u8 zero_buffer[0xC0] = {};
|
|
|
|
|
|
|
|
// 0x00030001 - Unknown
|
|
|
|
res = CreateConfigInfoBlk(0x00030001, 0x8, 0xE, zero_buffer);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-01 20:09:50 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
res = CreateConfigInfoBlk(StereoCameraSettingsBlockID, sizeof(STEREO_CAMERA_SETTINGS), 0xE,
|
|
|
|
STEREO_CAMERA_SETTINGS.data());
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2016-05-03 18:27:47 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
res = CreateConfigInfoBlk(SoundOutputModeBlockID, sizeof(SOUND_OUTPUT_MODE), 0xE,
|
|
|
|
&SOUND_OUTPUT_MODE);
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2016-05-03 18:27:47 +02:00
|
|
|
|
2017-05-06 02:55:51 +02:00
|
|
|
u32 random_number;
|
|
|
|
u64 console_id;
|
|
|
|
GenerateConsoleUniqueId(random_number, console_id);
|
|
|
|
|
|
|
|
u64_le console_id_le = console_id;
|
|
|
|
res = CreateConfigInfoBlk(ConsoleUniqueID1BlockID, sizeof(console_id_le), 0xE, &console_id_le);
|
2016-11-17 18:34:02 +01:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
|
|
|
|
2017-05-06 02:55:51 +02:00
|
|
|
res = CreateConfigInfoBlk(ConsoleUniqueID2BlockID, sizeof(console_id_le), 0xE, &console_id_le);
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
|
|
|
|
|
|
|
u32_le random_number_le = random_number;
|
|
|
|
res = CreateConfigInfoBlk(ConsoleUniqueID3BlockID, sizeof(random_number_le), 0xE,
|
|
|
|
&random_number_le);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-03 23:31:34 +02:00
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
res = CreateConfigInfoBlk(UsernameBlockID, sizeof(CONSOLE_USERNAME_BLOCK), 0xE,
|
|
|
|
&CONSOLE_USERNAME_BLOCK);
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2016-03-01 08:42:36 +01:00
|
|
|
|
2016-06-01 09:40:52 +02:00
|
|
|
res = CreateConfigInfoBlk(BirthdayBlockID, sizeof(PROFILE_BIRTHDAY), 0xE, &PROFILE_BIRTHDAY);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-03 23:31:34 +02:00
|
|
|
|
2016-06-01 09:40:52 +02:00
|
|
|
res = CreateConfigInfoBlk(LanguageBlockID, sizeof(CONSOLE_LANGUAGE), 0xE, &CONSOLE_LANGUAGE);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2016-05-03 18:27:47 +02:00
|
|
|
|
2016-06-01 09:40:52 +02:00
|
|
|
res = CreateConfigInfoBlk(CountryInfoBlockID, sizeof(COUNTRY_INFO), 0xE, &COUNTRY_INFO);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-01 20:09:50 +02:00
|
|
|
|
2016-03-01 08:56:02 +01:00
|
|
|
u16_le country_name_buffer[16][0x40] = {};
|
|
|
|
std::u16string region_name = Common::UTF8ToUTF16("Gensokyo");
|
2015-09-01 20:09:50 +02:00
|
|
|
for (size_t i = 0; i < 16; ++i) {
|
2016-03-01 08:56:02 +01:00
|
|
|
std::copy(region_name.cbegin(), region_name.cend(), country_name_buffer[i]);
|
2015-09-01 20:09:50 +02:00
|
|
|
}
|
|
|
|
// 0x000B0001 - Localized names for the profile Country
|
2016-09-18 02:38:01 +02:00
|
|
|
res = CreateConfigInfoBlk(CountryNameBlockID, sizeof(country_name_buffer), 0xE,
|
|
|
|
country_name_buffer);
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-01 20:09:50 +02:00
|
|
|
// 0x000B0002 - Localized names for the profile State/Province
|
2016-09-18 02:38:01 +02:00
|
|
|
res = CreateConfigInfoBlk(StateNameBlockID, sizeof(country_name_buffer), 0xE,
|
|
|
|
country_name_buffer);
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-01 20:09:50 +02:00
|
|
|
|
|
|
|
// 0x000B0003 - Unknown, related to country/address (zip code?)
|
|
|
|
res = CreateConfigInfoBlk(0x000B0003, 0x4, 0xE, zero_buffer);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-01 20:09:50 +02:00
|
|
|
|
|
|
|
// 0x000C0000 - Unknown
|
|
|
|
res = CreateConfigInfoBlk(0x000C0000, 0xC0, 0xE, zero_buffer);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-01 20:09:50 +02:00
|
|
|
|
|
|
|
// 0x000C0001 - Unknown
|
|
|
|
res = CreateConfigInfoBlk(0x000C0001, 0x14, 0xE, zero_buffer);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-01 20:09:50 +02:00
|
|
|
|
|
|
|
// 0x000D0000 - Accepted EULA version
|
2016-06-01 09:40:52 +02:00
|
|
|
res = CreateConfigInfoBlk(EULAVersionBlockID, 0x4, 0xE, zero_buffer);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-01 20:09:50 +02:00
|
|
|
|
2016-06-01 09:40:52 +02:00
|
|
|
res = CreateConfigInfoBlk(ConsoleModelBlockID, sizeof(CONSOLE_MODEL), 0xC, &CONSOLE_MODEL);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2015-09-01 17:34:59 +02:00
|
|
|
|
2016-04-29 12:31:29 +02:00
|
|
|
// 0x00170000 - Unknown
|
|
|
|
res = CreateConfigInfoBlk(0x00170000, 0x4, 0xE, zero_buffer);
|
2016-09-18 02:38:01 +02:00
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
2016-04-29 12:31:29 +02:00
|
|
|
|
2014-12-21 22:36:18 +01:00
|
|
|
// Save the buffer to the file
|
|
|
|
res = UpdateConfigNANDSavegame();
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-06-01 09:42:37 +02:00
|
|
|
ResultCode LoadConfigNANDSaveFile() {
|
2015-02-25 00:02:40 +01:00
|
|
|
// Open the SystemSaveData archive 0x00010017
|
|
|
|
FileSys::Path archive_path(cfg_system_savedata_id);
|
2016-09-18 02:38:01 +02:00
|
|
|
auto archive_result =
|
|
|
|
Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path);
|
2015-05-25 20:34:09 +02:00
|
|
|
|
2015-02-25 00:02:40 +01:00
|
|
|
// If the archive didn't exist, create the files inside
|
2017-05-21 06:00:18 +02:00
|
|
|
if (archive_result.Code().description == static_cast<u32>(ErrorDescription::FS_NotFormatted)) {
|
2015-02-25 00:02:40 +01:00
|
|
|
// Format the archive to create the directories
|
2016-09-18 02:38:01 +02:00
|
|
|
Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SystemSaveData,
|
|
|
|
FileSys::ArchiveFormatInfo(), archive_path);
|
2015-02-25 00:02:40 +01:00
|
|
|
|
|
|
|
// Open it again to get a valid archive now that the folder exists
|
2016-09-18 02:38:01 +02:00
|
|
|
archive_result =
|
|
|
|
Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path);
|
2014-12-21 22:36:18 +01:00
|
|
|
}
|
|
|
|
|
2015-02-25 00:02:40 +01:00
|
|
|
ASSERT_MSG(archive_result.Succeeded(), "Could not open the CFG SystemSaveData archive!");
|
|
|
|
|
|
|
|
cfg_system_save_data_archive = *archive_result;
|
|
|
|
|
2016-10-20 03:43:43 +02:00
|
|
|
FileSys::Path config_path("/config");
|
2015-02-25 00:02:40 +01:00
|
|
|
FileSys::Mode open_mode = {};
|
2016-02-11 18:41:15 +01:00
|
|
|
open_mode.read_flag.Assign(1);
|
2014-12-21 22:36:18 +01:00
|
|
|
|
2015-02-25 00:02:40 +01:00
|
|
|
auto config_result = Service::FS::OpenFileFromArchive(*archive_result, config_path, open_mode);
|
|
|
|
|
|
|
|
// Read the file if it already exists
|
|
|
|
if (config_result.Succeeded()) {
|
|
|
|
auto config = config_result.MoveFrom();
|
|
|
|
config->backend->Read(0, CONFIG_SAVEFILE_SIZE, cfg_config_file_buffer.data());
|
2016-06-01 09:42:37 +02:00
|
|
|
return RESULT_SUCCESS;
|
2014-12-21 22:36:18 +01:00
|
|
|
}
|
|
|
|
|
2016-06-01 09:42:37 +02:00
|
|
|
return FormatConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init() {
|
2016-12-09 07:01:35 +01:00
|
|
|
AddService(new CFG_I);
|
2016-12-09 07:37:05 +01:00
|
|
|
AddService(new CFG_NOR);
|
2016-12-09 07:01:35 +01:00
|
|
|
AddService(new CFG_S);
|
|
|
|
AddService(new CFG_U);
|
2016-06-01 09:42:37 +02:00
|
|
|
|
|
|
|
LoadConfigNANDSaveFile();
|
2016-11-30 10:32:09 +01:00
|
|
|
|
|
|
|
preferred_region_code = 0;
|
2014-12-21 22:36:18 +01:00
|
|
|
}
|
|
|
|
|
2016-09-19 03:01:46 +02:00
|
|
|
void Shutdown() {}
|
2014-12-21 22:36:18 +01:00
|
|
|
|
2017-01-18 23:06:52 +01:00
|
|
|
/// Checks if the language is available in the chosen region, and returns a proper one
|
|
|
|
static SystemLanguage AdjustLanguageInfoBlock(u32 region, SystemLanguage language) {
|
|
|
|
static const std::array<std::vector<SystemLanguage>, 7> region_languages{{
|
|
|
|
// JPN
|
|
|
|
{LANGUAGE_JP},
|
|
|
|
// USA
|
|
|
|
{LANGUAGE_EN, LANGUAGE_FR, LANGUAGE_ES, LANGUAGE_PT},
|
|
|
|
// EUR
|
|
|
|
{LANGUAGE_EN, LANGUAGE_FR, LANGUAGE_DE, LANGUAGE_IT, LANGUAGE_ES, LANGUAGE_NL, LANGUAGE_PT,
|
|
|
|
LANGUAGE_RU},
|
|
|
|
// AUS
|
|
|
|
{LANGUAGE_EN, LANGUAGE_FR, LANGUAGE_DE, LANGUAGE_IT, LANGUAGE_ES, LANGUAGE_NL, LANGUAGE_PT,
|
|
|
|
LANGUAGE_RU},
|
|
|
|
// CHN
|
|
|
|
{LANGUAGE_ZH},
|
|
|
|
// KOR
|
|
|
|
{LANGUAGE_KO},
|
|
|
|
// TWN
|
|
|
|
{LANGUAGE_TW},
|
|
|
|
}};
|
|
|
|
const auto& available = region_languages[region];
|
|
|
|
if (std::find(available.begin(), available.end(), language) == available.end()) {
|
|
|
|
return available[0];
|
|
|
|
}
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
2016-11-30 10:32:09 +01:00
|
|
|
void SetPreferredRegionCode(u32 region_code) {
|
|
|
|
preferred_region_code = region_code;
|
|
|
|
LOG_INFO(Service_CFG, "Preferred region code set to %u", preferred_region_code);
|
2017-01-18 23:06:52 +01:00
|
|
|
|
|
|
|
if (Settings::values.region_value == Settings::REGION_VALUE_AUTO_SELECT) {
|
|
|
|
const SystemLanguage current_language = GetSystemLanguage();
|
|
|
|
const SystemLanguage adjusted_language =
|
|
|
|
AdjustLanguageInfoBlock(region_code, current_language);
|
|
|
|
if (current_language != adjusted_language) {
|
|
|
|
LOG_WARNING(Service_CFG, "System language %d does not fit the region. Adjusted to %d",
|
|
|
|
static_cast<int>(current_language), static_cast<int>(adjusted_language));
|
|
|
|
SetSystemLanguage(adjusted_language);
|
|
|
|
}
|
|
|
|
}
|
2016-11-30 10:32:09 +01:00
|
|
|
}
|
|
|
|
|
2016-06-01 09:42:37 +02:00
|
|
|
void SetUsername(const std::u16string& name) {
|
|
|
|
ASSERT(name.size() <= 10);
|
|
|
|
UsernameBlock block{};
|
|
|
|
name.copy(block.username, name.size());
|
|
|
|
SetConfigInfoBlock(UsernameBlockID, sizeof(block), 4, &block);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::u16string GetUsername() {
|
|
|
|
UsernameBlock block;
|
|
|
|
GetConfigInfoBlock(UsernameBlockID, sizeof(block), 8, &block);
|
|
|
|
|
|
|
|
// the username string in the block isn't null-terminated,
|
|
|
|
// so we need to find the end manually.
|
|
|
|
std::u16string username(block.username, ARRAY_SIZE(block.username));
|
|
|
|
const size_t pos = username.find(u'\0');
|
|
|
|
if (pos != std::u16string::npos)
|
|
|
|
username.erase(pos);
|
|
|
|
return username;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetBirthday(u8 month, u8 day) {
|
2016-09-18 02:38:01 +02:00
|
|
|
BirthdayBlock block = {month, day};
|
2016-06-01 09:42:37 +02:00
|
|
|
SetConfigInfoBlock(BirthdayBlockID, sizeof(block), 4, &block);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<u8, u8> GetBirthday() {
|
|
|
|
BirthdayBlock block;
|
|
|
|
GetConfigInfoBlock(BirthdayBlockID, sizeof(block), 8, &block);
|
|
|
|
return std::make_tuple(block.month, block.day);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSystemLanguage(SystemLanguage language) {
|
|
|
|
u8 block = language;
|
|
|
|
SetConfigInfoBlock(LanguageBlockID, sizeof(block), 4, &block);
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemLanguage GetSystemLanguage() {
|
|
|
|
u8 block;
|
|
|
|
GetConfigInfoBlock(LanguageBlockID, sizeof(block), 8, &block);
|
|
|
|
return static_cast<SystemLanguage>(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSoundOutputMode(SoundOutputMode mode) {
|
|
|
|
u8 block = mode;
|
|
|
|
SetConfigInfoBlock(SoundOutputModeBlockID, sizeof(block), 4, &block);
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundOutputMode GetSoundOutputMode() {
|
|
|
|
u8 block;
|
|
|
|
GetConfigInfoBlock(SoundOutputModeBlockID, sizeof(block), 8, &block);
|
|
|
|
return static_cast<SoundOutputMode>(block);
|
|
|
|
}
|
|
|
|
|
2017-05-06 02:55:51 +02:00
|
|
|
void GenerateConsoleUniqueId(u32& random_number, u64& console_id) {
|
|
|
|
CryptoPP::AutoSeededRandomPool rng;
|
|
|
|
random_number = rng.GenerateWord32(0, 0xFFFF);
|
|
|
|
u64_le local_friend_code_seed;
|
|
|
|
rng.GenerateBlock(reinterpret_cast<byte*>(&local_friend_code_seed),
|
|
|
|
sizeof(local_friend_code_seed));
|
|
|
|
console_id = (local_friend_code_seed & 0x3FFFFFFFF) | (static_cast<u64>(random_number) << 48);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResultCode SetConsoleUniqueId(u32 random_number, u64 console_id) {
|
|
|
|
u64_le console_id_le = console_id;
|
|
|
|
ResultCode res =
|
|
|
|
SetConfigInfoBlock(ConsoleUniqueID1BlockID, sizeof(console_id_le), 0xE, &console_id_le);
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res = SetConfigInfoBlock(ConsoleUniqueID2BlockID, sizeof(console_id_le), 0xE, &console_id_le);
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
|
|
|
|
|
|
|
u32_le random_number_le = random_number;
|
|
|
|
res = SetConfigInfoBlock(ConsoleUniqueID3BlockID, sizeof(random_number_le), 0xE,
|
|
|
|
&random_number_le);
|
|
|
|
if (!res.IsSuccess())
|
|
|
|
return res;
|
|
|
|
|
|
|
|
return RESULT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 GetConsoleUniqueId() {
|
|
|
|
u64_le console_id_le;
|
|
|
|
GetConfigInfoBlock(ConsoleUniqueID2BlockID, sizeof(console_id_le), 0xE, &console_id_le);
|
|
|
|
return console_id_le;
|
|
|
|
}
|
|
|
|
|
2014-12-21 22:36:18 +01:00
|
|
|
} // namespace CFG
|
|
|
|
} // namespace Service
|