From 1968cc7b106159e2bd2166459c3cb04d5f79601f Mon Sep 17 00:00:00 2001 From: german77 Date: Mon, 8 May 2023 22:03:32 -0600 Subject: [PATCH] service: nfp: Allow to load with a different amiibo id --- src/common/settings.h | 2 ++ src/core/hle/service/nfc/common/device.cpp | 17 ++++++++++---- src/yuzu/configuration/config.cpp | 2 ++ .../configure_input_advanced.cpp | 2 ++ .../configuration/configure_input_advanced.ui | 22 ++++++++++++++++--- src/yuzu_cmd/config.cpp | 1 + 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/common/settings.h b/src/common/settings.h index f4eb4e3cde..5f4caaab98 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -535,6 +535,8 @@ struct Values { Setting enable_ir_sensor{false, "enable_ir_sensor"}; Setting ir_sensor_device{"auto", "ir_sensor_device"}; + Setting random_amiibo_id{false, "random_amiibo_id"}; + // Data Storage Setting use_virtual_sd{true, "use_virtual_sd"}; Setting gamecard_inserted{false, "gamecard_inserted"}; diff --git a/src/core/hle/service/nfc/common/device.cpp b/src/core/hle/service/nfc/common/device.cpp index e5de65ce01..9b0685bdb2 100644 --- a/src/core/hle/service/nfc/common/device.cpp +++ b/src/core/hle/service/nfc/common/device.cpp @@ -227,11 +227,20 @@ Result NfcDevice::GetTagInfo(NFP::TagInfo& tag_info, bool is_mifare) const { return ResultWrongDeviceState; } + UniqueSerialNumber uuid = encrypted_tag_data.uuid.uid; + + // Generate random UUID to bypass amiibo load limits + if (Settings::values.random_amiibo_id) { + Common::TinyMT rng{}; + rng.GenerateRandomBytes(uuid.data(), sizeof(UniqueSerialNumber)); + uuid[3] = 0x88 ^ uuid[0] ^ uuid[1] ^ uuid[2]; + } + if (is_mifare) { tag_info = { - .uuid = encrypted_tag_data.uuid.uid, + .uuid = uuid, .uuid_extension = {}, - .uuid_length = static_cast(encrypted_tag_data.uuid.uid.size()), + .uuid_length = static_cast(uuid.size()), .protocol = NfcProtocol::TypeA, .tag_type = TagType::Type4, }; @@ -240,9 +249,9 @@ Result NfcDevice::GetTagInfo(NFP::TagInfo& tag_info, bool is_mifare) const { // Protocol and tag type may change here tag_info = { - .uuid = encrypted_tag_data.uuid.uid, + .uuid = uuid, .uuid_extension = {}, - .uuid_length = static_cast(encrypted_tag_data.uuid.uid.size()), + .uuid_length = static_cast(uuid.size()), .protocol = NfcProtocol::TypeA, .tag_type = TagType::Type2, }; diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index a49d122669..b94d368388 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -443,6 +443,7 @@ void Config::ReadControlValues() { ReadBasicSetting(Settings::values.mouse_panning_sensitivity); ReadBasicSetting(Settings::values.enable_joycon_driver); ReadBasicSetting(Settings::values.enable_procon_driver); + ReadBasicSetting(Settings::values.random_amiibo_id); ReadBasicSetting(Settings::values.tas_enable); ReadBasicSetting(Settings::values.tas_loop); @@ -1150,6 +1151,7 @@ void Config::SaveControlValues() { WriteBasicSetting(Settings::values.enable_raw_input); WriteBasicSetting(Settings::values.enable_joycon_driver); WriteBasicSetting(Settings::values.enable_procon_driver); + WriteBasicSetting(Settings::values.random_amiibo_id); WriteBasicSetting(Settings::values.keyboard_enabled); WriteBasicSetting(Settings::values.emulate_analog_keyboard); WriteBasicSetting(Settings::values.mouse_panning_sensitivity); diff --git a/src/yuzu/configuration/configure_input_advanced.cpp b/src/yuzu/configuration/configure_input_advanced.cpp index 8d81322f3a..f131564343 100644 --- a/src/yuzu/configuration/configure_input_advanced.cpp +++ b/src/yuzu/configuration/configure_input_advanced.cpp @@ -140,6 +140,7 @@ void ConfigureInputAdvanced::ApplyConfiguration() { Settings::values.enable_ir_sensor = ui->enable_ir_sensor->isChecked(); Settings::values.enable_joycon_driver = ui->enable_joycon_driver->isChecked(); Settings::values.enable_procon_driver = ui->enable_procon_driver->isChecked(); + Settings::values.random_amiibo_id = ui->random_amiibo_id->isChecked(); } void ConfigureInputAdvanced::LoadConfiguration() { @@ -176,6 +177,7 @@ void ConfigureInputAdvanced::LoadConfiguration() { ui->enable_ir_sensor->setChecked(Settings::values.enable_ir_sensor.GetValue()); ui->enable_joycon_driver->setChecked(Settings::values.enable_joycon_driver.GetValue()); ui->enable_procon_driver->setChecked(Settings::values.enable_procon_driver.GetValue()); + ui->random_amiibo_id->setChecked(Settings::values.random_amiibo_id.GetValue()); UpdateUIEnabled(); } diff --git a/src/yuzu/configuration/configure_input_advanced.ui b/src/yuzu/configuration/configure_input_advanced.ui index 0eb2b34bcc..2e8b136600 100644 --- a/src/yuzu/configuration/configure_input_advanced.ui +++ b/src/yuzu/configuration/configure_input_advanced.ui @@ -2728,6 +2728,22 @@ + + + Allows unlimited uses of the same Amiibo in games that would otherwise limit you to one use. + + + + 0 + 23 + + + + Use random Amiibo ID + + + + @@ -2740,7 +2756,7 @@ - + Mouse sensitivity @@ -2762,14 +2778,14 @@ - + Motion / Touch - + Configure diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index abe7092fcf..dc9a3d68f1 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -169,6 +169,7 @@ void Config::ReadValues() { ReadSetting("ControlsGeneral", Settings::values.enable_raw_input); ReadSetting("ControlsGeneral", Settings::values.enable_joycon_driver); ReadSetting("ControlsGeneral", Settings::values.enable_procon_driver); + ReadSetting("ControlsGeneral", Settings::values.random_amiibo_id); ReadSetting("ControlsGeneral", Settings::values.emulate_analog_keyboard); ReadSetting("ControlsGeneral", Settings::values.vibration_enabled); ReadSetting("ControlsGeneral", Settings::values.enable_accurate_vibrations);