From f84e0796ab9d6e36005d011cd5b5b5e3c5942a18 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Tue, 9 May 2023 17:48:13 +0200 Subject: [PATCH] early-access version 3575 --- README.md | 2 +- src/common/settings.h | 2 ++ src/core/hle/service/nfc/common/device.cpp | 17 +++++++++---- .../joycon_protocol/common_protocol.cpp | 7 +++--- .../helpers/joycon_protocol/common_protocol.h | 2 +- .../helpers/joycon_protocol/joycon_types.h | 7 ++++-- .../helpers/joycon_protocol/nfc.cpp | 24 +++++++++---------- src/yuzu/configuration/config.cpp | 2 ++ .../configure_input_advanced.cpp | 2 ++ .../configuration/configure_input_advanced.ui | 22 ++++++++++++++--- src/yuzu_cmd/config.cpp | 1 + 11 files changed, 61 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index c84cd2705..cb283a976 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 3574. +This is the source code for early-access 3575. ## Legal Notice diff --git a/src/common/settings.h b/src/common/settings.h index eb1bc34ed..bf93556e3 100755 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -536,6 +536,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 e5de65ce0..9b0685bdb 100755 --- 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/input_common/helpers/joycon_protocol/common_protocol.cpp b/src/input_common/helpers/joycon_protocol/common_protocol.cpp index 2b42a4555..077d72cd0 100755 --- a/src/input_common/helpers/joycon_protocol/common_protocol.cpp +++ b/src/input_common/helpers/joycon_protocol/common_protocol.cpp @@ -236,13 +236,13 @@ DriverResult JoyconCommonProtocol::GetMCUDataResponse(ReportMode report_mode, return DriverResult::Success; } -DriverResult JoyconCommonProtocol::SendMCUData(ReportMode report_mode, SubCommand sc, +DriverResult JoyconCommonProtocol::SendMCUData(ReportMode report_mode, MCUSubCommand sc, std::span buffer, MCUCommandResponse& output) { SubCommandPacket packet{ .output_report = OutputReport::MCU_DATA, .packet_counter = GetCounter(), - .sub_command = sc, + .mcu_sub_command = sc, .command_data = {}, }; @@ -269,8 +269,7 @@ DriverResult JoyconCommonProtocol::WaitSetMCUMode(ReportMode report_mode, MCUMod std::size_t tries{}; do { - const std::vector mcu_data{static_cast(MCUMode::Standby)}; - const auto result = SendMCUData(report_mode, SubCommand::STATE, mcu_data, output); + const auto result = SendMCUData(report_mode, MCUSubCommand::SetDeviceMode, {}, output); if (result != DriverResult::Success) { return result; diff --git a/src/input_common/helpers/joycon_protocol/common_protocol.h b/src/input_common/helpers/joycon_protocol/common_protocol.h index 62cae739a..411ec018a 100755 --- a/src/input_common/helpers/joycon_protocol/common_protocol.h +++ b/src/input_common/helpers/joycon_protocol/common_protocol.h @@ -156,7 +156,7 @@ public: * @param buffer data to be send * @returns output buffer containing the response */ - DriverResult SendMCUData(ReportMode report_mode, SubCommand sc, std::span buffer, + DriverResult SendMCUData(ReportMode report_mode, MCUSubCommand sc, std::span buffer, MCUCommandResponse& output); /** diff --git a/src/input_common/helpers/joycon_protocol/joycon_types.h b/src/input_common/helpers/joycon_protocol/joycon_types.h index dcac0e422..b03143e04 100755 --- a/src/input_common/helpers/joycon_protocol/joycon_types.h +++ b/src/input_common/helpers/joycon_protocol/joycon_types.h @@ -575,7 +575,6 @@ struct NFCPollingCommandData { static_assert(sizeof(NFCPollingCommandData) == 0x05, "NFCPollingCommandData is an invalid size"); struct NFCRequestState { - MCUSubCommand sub_command; NFCReadCommand command_argument; u8 packet_id; INSERT_PADDING_BYTES(0x1); @@ -587,6 +586,7 @@ struct NFCRequestState { NFCPollingCommandData nfc_polling; }; u8 crc; + INSERT_PADDING_BYTES(0x1); }; static_assert(sizeof(NFCRequestState) == 0x26, "NFCRequestState is an invalid size"); @@ -659,7 +659,10 @@ struct SubCommandPacket { OutputReport output_report; u8 packet_counter; INSERT_PADDING_BYTES(0x8); // This contains vibration data - SubCommand sub_command; + union { + SubCommand sub_command; + MCUSubCommand mcu_sub_command; + }; std::array command_data; }; static_assert(sizeof(SubCommandPacket) == 0x31, "SubCommandPacket is an invalid size"); diff --git a/src/input_common/helpers/joycon_protocol/nfc.cpp b/src/input_common/helpers/joycon_protocol/nfc.cpp index eeba82986..77ea6d5cf 100755 --- a/src/input_common/helpers/joycon_protocol/nfc.cpp +++ b/src/input_common/helpers/joycon_protocol/nfc.cpp @@ -278,7 +278,6 @@ DriverResult NfcProtocol::GetAmiiboData(std::vector& ntag_data) { DriverResult NfcProtocol::SendStartPollingRequest(MCUCommandResponse& output) { NFCRequestState request{ - .sub_command = MCUSubCommand::ReadDeviceMode, .command_argument = NFCReadCommand::StartPolling, .packet_id = 0x0, .packet_flag = MCUPacketFlag::LastCommandPacket, @@ -296,13 +295,13 @@ DriverResult NfcProtocol::SendStartPollingRequest(MCUCommandResponse& output) { std::array request_data{}; memcpy(request_data.data(), &request, sizeof(NFCRequestState)); - request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36); - return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, SubCommand::STATE, request_data, output); + request_data[36] = CalculateMCU_CRC8(request_data.data(), 36); + return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, MCUSubCommand::ReadDeviceMode, request_data, + output); } DriverResult NfcProtocol::SendStopPollingRequest(MCUCommandResponse& output) { NFCRequestState request{ - .sub_command = MCUSubCommand::ReadDeviceMode, .command_argument = NFCReadCommand::StopPolling, .packet_id = 0x0, .packet_flag = MCUPacketFlag::LastCommandPacket, @@ -313,13 +312,13 @@ DriverResult NfcProtocol::SendStopPollingRequest(MCUCommandResponse& output) { std::array request_data{}; memcpy(request_data.data(), &request, sizeof(NFCRequestState)); - request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36); - return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, SubCommand::STATE, request_data, output); + request_data[36] = CalculateMCU_CRC8(request_data.data(), 36); + return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, MCUSubCommand::ReadDeviceMode, request_data, + output); } DriverResult NfcProtocol::SendStartWaitingRecieveRequest(MCUCommandResponse& output) { NFCRequestState request{ - .sub_command = MCUSubCommand::ReadDeviceMode, .command_argument = NFCReadCommand::StartWaitingRecieve, .packet_id = 0x0, .packet_flag = MCUPacketFlag::LastCommandPacket, @@ -330,13 +329,13 @@ DriverResult NfcProtocol::SendStartWaitingRecieveRequest(MCUCommandResponse& out std::vector request_data(sizeof(NFCRequestState)); memcpy(request_data.data(), &request, sizeof(NFCRequestState)); - request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36); - return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, SubCommand::STATE, request_data, output); + request_data[36] = CalculateMCU_CRC8(request_data.data(), 36); + return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, MCUSubCommand::ReadDeviceMode, request_data, + output); } DriverResult NfcProtocol::SendReadAmiiboRequest(MCUCommandResponse& output, NFCPages ntag_pages) { NFCRequestState request{ - .sub_command = MCUSubCommand::ReadDeviceMode, .command_argument = NFCReadCommand::Ntag, .packet_id = 0x0, .packet_flag = MCUPacketFlag::LastCommandPacket, @@ -355,8 +354,9 @@ DriverResult NfcProtocol::SendReadAmiiboRequest(MCUCommandResponse& output, NFCP std::array request_data{}; memcpy(request_data.data(), &request, sizeof(NFCRequestState)); - request_data[37] = CalculateMCU_CRC8(request_data.data() + 1, 36); - return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, SubCommand::STATE, request_data, output); + request_data[36] = CalculateMCU_CRC8(request_data.data(), 36); + return SendMCUData(ReportMode::NFC_IR_MODE_60HZ, MCUSubCommand::ReadDeviceMode, request_data, + output); } NFCReadBlockCommand NfcProtocol::GetReadBlockCommand(NFCPages pages) const { diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index d96b97162..76ea086a7 100755 --- 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); @@ -1151,6 +1152,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 59209b0d3..56bf8d409 100755 --- 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 4ef8d77df..75a32160f 100755 --- 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 85951c1ef..41f531a65 100755 --- 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);