diff options
author | german77 <juangerman-13@hotmail.com> | 2023-03-26 22:26:21 +0200 |
---|---|---|
committer | german77 <juangerman-13@hotmail.com> | 2023-03-26 22:26:36 +0200 |
commit | 880264673068c61ef680deffc1a26b4089713282 (patch) | |
tree | ca4ed2d85b94abed946a6bda6cbfcb1f781846f4 /src/core/hle/service/nfp/nfp_device.cpp | |
parent | Merge pull request #9992 from liamwhite/climits (diff) | |
download | yuzu-880264673068c61ef680deffc1a26b4089713282.tar yuzu-880264673068c61ef680deffc1a26b4089713282.tar.gz yuzu-880264673068c61ef680deffc1a26b4089713282.tar.bz2 yuzu-880264673068c61ef680deffc1a26b4089713282.tar.lz yuzu-880264673068c61ef680deffc1a26b4089713282.tar.xz yuzu-880264673068c61ef680deffc1a26b4089713282.tar.zst yuzu-880264673068c61ef680deffc1a26b4089713282.zip |
Diffstat (limited to 'src/core/hle/service/nfp/nfp_device.cpp')
-rw-r--r-- | src/core/hle/service/nfp/nfp_device.cpp | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/core/hle/service/nfp/nfp_device.cpp b/src/core/hle/service/nfp/nfp_device.cpp index 5990e1473..607e70968 100644 --- a/src/core/hle/service/nfp/nfp_device.cpp +++ b/src/core/hle/service/nfp/nfp_device.cpp @@ -121,7 +121,16 @@ bool NfpDevice::LoadAmiibo(std::span<const u8> data) { // TODO: Filter by allowed_protocols here - memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File)); + memcpy(&tag_data, data.data(), sizeof(EncryptedNTAG215File)); + is_plain_amiibo = AmiiboCrypto::IsAmiiboValid(tag_data); + + if (is_plain_amiibo) { + encrypted_tag_data = AmiiboCrypto::EncodedDataToNfcData(tag_data); + LOG_INFO(Service_NFP, "Using plain amiibo"); + } else { + tag_data = {}; + memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File)); + } device_state = DeviceState::TagFound; deactivate_event->GetReadableEvent().Clear(); @@ -232,13 +241,17 @@ Result NfpDevice::Flush() { tag_data.write_counter++; - if (!AmiiboCrypto::EncodeAmiibo(tag_data, encrypted_tag_data)) { - LOG_ERROR(Service_NFP, "Failed to encode data"); - return WriteAmiiboFailed; - } + std::vector<u8> data(sizeof(EncryptedNTAG215File)); + if (is_plain_amiibo) { + memcpy(data.data(), &tag_data, sizeof(tag_data)); + } else { + if (!AmiiboCrypto::EncodeAmiibo(tag_data, encrypted_tag_data)) { + LOG_ERROR(Service_NFP, "Failed to encode data"); + return WriteAmiiboFailed; + } - std::vector<u8> data(sizeof(encrypted_tag_data)); - memcpy(data.data(), &encrypted_tag_data, sizeof(encrypted_tag_data)); + memcpy(data.data(), &encrypted_tag_data, sizeof(encrypted_tag_data)); + } if (!npad_device->WriteNfc(data)) { LOG_ERROR(Service_NFP, "Error writing to file"); @@ -256,6 +269,13 @@ Result NfpDevice::Mount(MountTarget mount_target_) { return WrongDeviceState; } + // The loaded amiibo is not encrypted + if (is_plain_amiibo) { + device_state = DeviceState::TagMounted; + mount_target = mount_target_; + return ResultSuccess; + } + if (!AmiiboCrypto::IsAmiiboValid(encrypted_tag_data)) { LOG_ERROR(Service_NFP, "Not an amiibo"); return NotAnAmiibo; |