diff options
| author | 2017-05-06 02:55:51 +0200 | |
|---|---|---|
| committer | 2017-05-05 20:55:51 -0400 | |
| commit | 8bee0161458a082491d611ba4353cda84881b067 (patch) | |
| tree | 776f900e7797f81bef52324cbc3f0202fc7fe8b7 /src | |
| parent | Merge pull request #2606 from wwylele/ir (diff) | |
| download | yuzu-8bee0161458a082491d611ba4353cda84881b067.tar.gz yuzu-8bee0161458a082491d611ba4353cda84881b067.tar.xz yuzu-8bee0161458a082491d611ba4353cda84881b067.zip | |
Create a random console_unique_id (#2668)
* Create a random console_id when config save_file is created
Added button in system config to refresh the console unique id
* Moved the connect for the button from .ui file to constructor of ConfigureSystem
* Added warning and info dialog
Fixup: Make use of qt5 style connects,
renamed the refresh button,
removed some duplicate code,
changed random device and moved all to the generate function
* Changed the random generator to reflect what a real 3DS stores as console unique id
Fixup: Changed the warning message
* Fixup: Set and Create
* Fixup: Added console id label, therfore removed second message box
* Fixup: fixed the endianess
* Fixup: more endianness fixes
* Fixup: Endianness the 3rd
Diffstat (limited to 'src')
| -rw-r--r-- | src/citra_qt/configuration/configure_system.cpp | 30 | ||||
| -rw-r--r-- | src/citra_qt/configuration/configure_system.h | 1 | ||||
| -rw-r--r-- | src/citra_qt/configuration/configure_system.ui | 23 | ||||
| -rw-r--r-- | src/core/hle/service/cfg/cfg.cpp | 55 | ||||
| -rw-r--r-- | src/core/hle/service/cfg/cfg.h | 21 |
5 files changed, 123 insertions, 7 deletions
diff --git a/src/citra_qt/configuration/configure_system.cpp b/src/citra_qt/configuration/configure_system.cpp index a3a9015a4..9b1e6711d 100644 --- a/src/citra_qt/configuration/configure_system.cpp +++ b/src/citra_qt/configuration/configure_system.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <QMessageBox> | ||
| 5 | #include "citra_qt/configuration/configure_system.h" | 6 | #include "citra_qt/configuration/configure_system.h" |
| 6 | #include "citra_qt/ui_settings.h" | 7 | #include "citra_qt/ui_settings.h" |
| 7 | #include "core/core.h" | 8 | #include "core/core.h" |
| @@ -15,8 +16,11 @@ static const std::array<int, 12> days_in_month = {{ | |||
| 15 | 16 | ||
| 16 | ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) { | 17 | ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) { |
| 17 | ui->setupUi(this); | 18 | ui->setupUi(this); |
| 18 | connect(ui->combo_birthmonth, SIGNAL(currentIndexChanged(int)), | 19 | connect(ui->combo_birthmonth, |
| 19 | SLOT(updateBirthdayComboBox(int))); | 20 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, |
| 21 | &ConfigureSystem::updateBirthdayComboBox); | ||
| 22 | connect(ui->button_regenerate_console_id, &QPushButton::clicked, this, | ||
| 23 | &ConfigureSystem::refreshConsoleID); | ||
| 20 | 24 | ||
| 21 | this->setConfiguration(); | 25 | this->setConfiguration(); |
| 22 | } | 26 | } |
| @@ -71,6 +75,10 @@ void ConfigureSystem::ReadSystemSettings() { | |||
| 71 | // set sound output mode | 75 | // set sound output mode |
| 72 | sound_index = Service::CFG::GetSoundOutputMode(); | 76 | sound_index = Service::CFG::GetSoundOutputMode(); |
| 73 | ui->combo_sound->setCurrentIndex(sound_index); | 77 | ui->combo_sound->setCurrentIndex(sound_index); |
| 78 | |||
| 79 | // set the console id | ||
| 80 | u64 console_id = Service::CFG::GetConsoleUniqueId(); | ||
| 81 | ui->label_console_id->setText("Console ID: 0x" + QString::number(console_id, 16).toUpper()); | ||
| 74 | } | 82 | } |
| 75 | 83 | ||
| 76 | void ConfigureSystem::applyConfiguration() { | 84 | void ConfigureSystem::applyConfiguration() { |
| @@ -140,3 +148,21 @@ void ConfigureSystem::updateBirthdayComboBox(int birthmonth_index) { | |||
| 140 | // restore the day selection | 148 | // restore the day selection |
| 141 | ui->combo_birthday->setCurrentIndex(birthday_index); | 149 | ui->combo_birthday->setCurrentIndex(birthday_index); |
| 142 | } | 150 | } |
| 151 | |||
| 152 | void ConfigureSystem::refreshConsoleID() { | ||
| 153 | QMessageBox::StandardButton reply; | ||
| 154 | QString warning_text = tr("This will replace your current virtual 3DS with a new one. " | ||
| 155 | "Your current virtual 3DS will not be recoverable. " | ||
| 156 | "This might have unexpected effects in games. This might fail, " | ||
| 157 | "if you use an outdated config savegame. Continue?"); | ||
| 158 | reply = QMessageBox::critical(this, tr("Warning"), warning_text, | ||
| 159 | QMessageBox::No | QMessageBox::Yes); | ||
| 160 | if (reply == QMessageBox::No) | ||
| 161 | return; | ||
| 162 | u32 random_number; | ||
| 163 | u64 console_id; | ||
| 164 | Service::CFG::GenerateConsoleUniqueId(random_number, console_id); | ||
| 165 | Service::CFG::SetConsoleUniqueId(random_number, console_id); | ||
| 166 | Service::CFG::UpdateConfigNANDSavegame(); | ||
| 167 | ui->label_console_id->setText("Console ID: 0x" + QString::number(console_id, 16).toUpper()); | ||
| 168 | } | ||
diff --git a/src/citra_qt/configuration/configure_system.h b/src/citra_qt/configuration/configure_system.h index db0ead13c..f13de17d4 100644 --- a/src/citra_qt/configuration/configure_system.h +++ b/src/citra_qt/configuration/configure_system.h | |||
| @@ -23,6 +23,7 @@ public: | |||
| 23 | 23 | ||
| 24 | public slots: | 24 | public slots: |
| 25 | void updateBirthdayComboBox(int birthmonth_index); | 25 | void updateBirthdayComboBox(int birthmonth_index); |
| 26 | void refreshConsoleID(); | ||
| 26 | 27 | ||
| 27 | private: | 28 | private: |
| 28 | void ReadSystemSettings(); | 29 | void ReadSystemSettings(); |
diff --git a/src/citra_qt/configuration/configure_system.ui b/src/citra_qt/configuration/configure_system.ui index cc54fa37f..8caf49623 100644 --- a/src/citra_qt/configuration/configure_system.ui +++ b/src/citra_qt/configuration/configure_system.ui | |||
| @@ -220,6 +220,29 @@ | |||
| 220 | </item> | 220 | </item> |
| 221 | </widget> | 221 | </widget> |
| 222 | </item> | 222 | </item> |
| 223 | <item row="4" column="0"> | ||
| 224 | <widget class="QLabel" name="label_console_id"> | ||
| 225 | <property name="text"> | ||
| 226 | <string>Console ID:</string> | ||
| 227 | </property> | ||
| 228 | </widget> | ||
| 229 | </item> | ||
| 230 | <item row="4" column="1"> | ||
| 231 | <widget class="QPushButton" name="button_regenerate_console_id"> | ||
| 232 | <property name="sizePolicy"> | ||
| 233 | <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | ||
| 234 | <horstretch>0</horstretch> | ||
| 235 | <verstretch>0</verstretch> | ||
| 236 | </sizepolicy> | ||
| 237 | </property> | ||
| 238 | <property name="layoutDirection"> | ||
| 239 | <enum>Qt::RightToLeft</enum> | ||
| 240 | </property> | ||
| 241 | <property name="text"> | ||
| 242 | <string>Regenerate</string> | ||
| 243 | </property> | ||
| 244 | </widget> | ||
| 245 | </item> | ||
| 223 | </layout> | 246 | </layout> |
| 224 | </widget> | 247 | </widget> |
| 225 | </item> | 248 | </item> |
diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 4ddb1bc90..8c8c1ec77 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <cryptopp/osrng.h> | ||
| 7 | #include <cryptopp/sha.h> | 8 | #include <cryptopp/sha.h> |
| 8 | #include "common/file_util.h" | 9 | #include "common/file_util.h" |
| 9 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| @@ -50,6 +51,7 @@ enum ConfigBlockID { | |||
| 50 | SoundOutputModeBlockID = 0x00070001, | 51 | SoundOutputModeBlockID = 0x00070001, |
| 51 | ConsoleUniqueID1BlockID = 0x00090000, | 52 | ConsoleUniqueID1BlockID = 0x00090000, |
| 52 | ConsoleUniqueID2BlockID = 0x00090001, | 53 | ConsoleUniqueID2BlockID = 0x00090001, |
| 54 | ConsoleUniqueID3BlockID = 0x00090002, | ||
| 53 | UsernameBlockID = 0x000A0000, | 55 | UsernameBlockID = 0x000A0000, |
| 54 | BirthdayBlockID = 0x000A0001, | 56 | BirthdayBlockID = 0x000A0001, |
| 55 | LanguageBlockID = 0x000A0002, | 57 | LanguageBlockID = 0x000A0002, |
| @@ -86,7 +88,6 @@ struct ConsoleCountryInfo { | |||
| 86 | static_assert(sizeof(ConsoleCountryInfo) == 4, "ConsoleCountryInfo must be exactly 4 bytes"); | 88 | static_assert(sizeof(ConsoleCountryInfo) == 4, "ConsoleCountryInfo must be exactly 4 bytes"); |
| 87 | } | 89 | } |
| 88 | 90 | ||
| 89 | static const u64 CONSOLE_UNIQUE_ID = 0xDEADC0DE; | ||
| 90 | static const ConsoleModelInfo CONSOLE_MODEL = {NINTENDO_3DS_XL, {0, 0, 0}}; | 91 | static const ConsoleModelInfo CONSOLE_MODEL = {NINTENDO_3DS_XL, {0, 0, 0}}; |
| 91 | static const u8 CONSOLE_LANGUAGE = LANGUAGE_EN; | 92 | static const u8 CONSOLE_LANGUAGE = LANGUAGE_EN; |
| 92 | static const UsernameBlock CONSOLE_USERNAME_BLOCK = {u"CITRA", 0, 0}; | 93 | static const UsernameBlock CONSOLE_USERNAME_BLOCK = {u"CITRA", 0, 0}; |
| @@ -438,13 +439,22 @@ ResultCode FormatConfig() { | |||
| 438 | if (!res.IsSuccess()) | 439 | if (!res.IsSuccess()) |
| 439 | return res; | 440 | return res; |
| 440 | 441 | ||
| 441 | res = CreateConfigInfoBlk(ConsoleUniqueID1BlockID, sizeof(CONSOLE_UNIQUE_ID), 0xE, | 442 | u32 random_number; |
| 442 | &CONSOLE_UNIQUE_ID); | 443 | u64 console_id; |
| 444 | GenerateConsoleUniqueId(random_number, console_id); | ||
| 445 | |||
| 446 | u64_le console_id_le = console_id; | ||
| 447 | res = CreateConfigInfoBlk(ConsoleUniqueID1BlockID, sizeof(console_id_le), 0xE, &console_id_le); | ||
| 443 | if (!res.IsSuccess()) | 448 | if (!res.IsSuccess()) |
| 444 | return res; | 449 | return res; |
| 445 | 450 | ||
| 446 | res = CreateConfigInfoBlk(ConsoleUniqueID2BlockID, sizeof(CONSOLE_UNIQUE_ID), 0xE, | 451 | res = CreateConfigInfoBlk(ConsoleUniqueID2BlockID, sizeof(console_id_le), 0xE, &console_id_le); |
| 447 | &CONSOLE_UNIQUE_ID); | 452 | if (!res.IsSuccess()) |
| 453 | return res; | ||
| 454 | |||
| 455 | u32_le random_number_le = random_number; | ||
| 456 | res = CreateConfigInfoBlk(ConsoleUniqueID3BlockID, sizeof(random_number_le), 0xE, | ||
| 457 | &random_number_le); | ||
| 448 | if (!res.IsSuccess()) | 458 | if (!res.IsSuccess()) |
| 449 | return res; | 459 | return res; |
| 450 | 460 | ||
| @@ -663,5 +673,40 @@ SoundOutputMode GetSoundOutputMode() { | |||
| 663 | return static_cast<SoundOutputMode>(block); | 673 | return static_cast<SoundOutputMode>(block); |
| 664 | } | 674 | } |
| 665 | 675 | ||
| 676 | void GenerateConsoleUniqueId(u32& random_number, u64& console_id) { | ||
| 677 | CryptoPP::AutoSeededRandomPool rng; | ||
| 678 | random_number = rng.GenerateWord32(0, 0xFFFF); | ||
| 679 | u64_le local_friend_code_seed; | ||
| 680 | rng.GenerateBlock(reinterpret_cast<byte*>(&local_friend_code_seed), | ||
| 681 | sizeof(local_friend_code_seed)); | ||
| 682 | console_id = (local_friend_code_seed & 0x3FFFFFFFF) | (static_cast<u64>(random_number) << 48); | ||
| 683 | } | ||
| 684 | |||
| 685 | ResultCode SetConsoleUniqueId(u32 random_number, u64 console_id) { | ||
| 686 | u64_le console_id_le = console_id; | ||
| 687 | ResultCode res = | ||
| 688 | SetConfigInfoBlock(ConsoleUniqueID1BlockID, sizeof(console_id_le), 0xE, &console_id_le); | ||
| 689 | if (!res.IsSuccess()) | ||
| 690 | return res; | ||
| 691 | |||
| 692 | res = SetConfigInfoBlock(ConsoleUniqueID2BlockID, sizeof(console_id_le), 0xE, &console_id_le); | ||
| 693 | if (!res.IsSuccess()) | ||
| 694 | return res; | ||
| 695 | |||
| 696 | u32_le random_number_le = random_number; | ||
| 697 | res = SetConfigInfoBlock(ConsoleUniqueID3BlockID, sizeof(random_number_le), 0xE, | ||
| 698 | &random_number_le); | ||
| 699 | if (!res.IsSuccess()) | ||
| 700 | return res; | ||
| 701 | |||
| 702 | return RESULT_SUCCESS; | ||
| 703 | } | ||
| 704 | |||
| 705 | u64 GetConsoleUniqueId() { | ||
| 706 | u64_le console_id_le; | ||
| 707 | GetConfigInfoBlock(ConsoleUniqueID2BlockID, sizeof(console_id_le), 0xE, &console_id_le); | ||
| 708 | return console_id_le; | ||
| 709 | } | ||
| 710 | |||
| 666 | } // namespace CFG | 711 | } // namespace CFG |
| 667 | } // namespace Service | 712 | } // namespace Service |
diff --git a/src/core/hle/service/cfg/cfg.h b/src/core/hle/service/cfg/cfg.h index 618c9647e..1659ebf32 100644 --- a/src/core/hle/service/cfg/cfg.h +++ b/src/core/hle/service/cfg/cfg.h | |||
| @@ -342,5 +342,26 @@ void SetSoundOutputMode(SoundOutputMode mode); | |||
| 342 | */ | 342 | */ |
| 343 | SoundOutputMode GetSoundOutputMode(); | 343 | SoundOutputMode GetSoundOutputMode(); |
| 344 | 344 | ||
| 345 | /** | ||
| 346 | * Generates a new random console unique id. | ||
| 347 | * @param random_number a random generated 16bit number stored at 0x90002, used for generating the | ||
| 348 | * console_id | ||
| 349 | * @param console_id the randomly created console id | ||
| 350 | */ | ||
| 351 | void GenerateConsoleUniqueId(u32& random_number, u64& console_id); | ||
| 352 | |||
| 353 | /** | ||
| 354 | * Sets the random_number and the console unique id in the config savegame. | ||
| 355 | * @param random_number the random_number to set | ||
| 356 | * @param console_id the console id to set | ||
| 357 | */ | ||
| 358 | ResultCode SetConsoleUniqueId(u32 random_number, u64 console_id); | ||
| 359 | |||
| 360 | /** | ||
| 361 | * Gets the console unique id from config savegame. | ||
| 362 | * @returns the console unique id | ||
| 363 | */ | ||
| 364 | u64 GetConsoleUniqueId(); | ||
| 365 | |||
| 345 | } // namespace CFG | 366 | } // namespace CFG |
| 346 | } // namespace Service | 367 | } // namespace Service |