diff options
| author | 2022-02-13 11:59:47 -0600 | |
|---|---|---|
| committer | 2022-02-13 13:52:34 -0600 | |
| commit | b57d61010f347e74875f0c8a1003b4f84fa7b062 (patch) | |
| tree | dd80e607949efe0f545803a9db95444c5a1f6c6b /src | |
| parent | nfp: Separate nfc tag from amiibo data (diff) | |
| download | yuzu-b57d61010f347e74875f0c8a1003b4f84fa7b062.tar.gz yuzu-b57d61010f347e74875f0c8a1003b4f84fa7b062.tar.xz yuzu-b57d61010f347e74875f0c8a1003b4f84fa7b062.zip | |
nfp: Allow files without password data
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/nfp/nfp.cpp | 22 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp.h | 11 |
2 files changed, 24 insertions, 9 deletions
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 63e257975..513107715 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp | |||
| @@ -479,25 +479,35 @@ void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { | |||
| 479 | } | 479 | } |
| 480 | 480 | ||
| 481 | bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) { | 481 | bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) { |
| 482 | if (buffer.size() < sizeof(NTAG215File)) { | 482 | if (device_state != DeviceState::SearchingForTag) { |
| 483 | LOG_ERROR(Service_NFP, "Wrong file size"); | 483 | LOG_ERROR(Service_NFP, "Game is not looking for amiibos, current state {}", device_state); |
| 484 | return false; | 484 | return false; |
| 485 | } | 485 | } |
| 486 | 486 | ||
| 487 | if (device_state != DeviceState::SearchingForTag) { | 487 | constexpr auto tag_size = sizeof(NTAG215File); |
| 488 | LOG_ERROR(Service_NFP, "Game is not looking for amiibos, current state {}", device_state); | 488 | constexpr auto tag_size_without_password = sizeof(NTAG215File) - sizeof(NTAG215Password); |
| 489 | |||
| 490 | std::vector<u8> amiibo_buffer = buffer; | ||
| 491 | |||
| 492 | if (amiibo_buffer.size() < tag_size_without_password) { | ||
| 493 | LOG_ERROR(Service_NFP, "Wrong file size {}", buffer.size()); | ||
| 489 | return false; | 494 | return false; |
| 490 | } | 495 | } |
| 491 | 496 | ||
| 497 | // Ensure it has the correct size | ||
| 498 | if (amiibo_buffer.size() != tag_size) { | ||
| 499 | amiibo_buffer.resize(tag_size, 0); | ||
| 500 | } | ||
| 501 | |||
| 492 | LOG_INFO(Service_NFP, "Amiibo detected"); | 502 | LOG_INFO(Service_NFP, "Amiibo detected"); |
| 493 | std::memcpy(&tag_data, buffer.data(), sizeof(tag_data)); | 503 | std::memcpy(&tag_data, buffer.data(), tag_size); |
| 494 | 504 | ||
| 495 | if (!IsAmiiboValid()) { | 505 | if (!IsAmiiboValid()) { |
| 496 | return false; | 506 | return false; |
| 497 | } | 507 | } |
| 498 | 508 | ||
| 499 | // This value can't be dumped from a tag. Generate it | 509 | // This value can't be dumped from a tag. Generate it |
| 500 | tag_data.PWD = GetTagPassword(tag_data.uuid); | 510 | tag_data.password.PWD = GetTagPassword(tag_data.uuid); |
| 501 | 511 | ||
| 502 | device_state = DeviceState::TagFound; | 512 | device_state = DeviceState::TagFound; |
| 503 | activate_event->GetWritableEvent().Signal(); | 513 | activate_event->GetWritableEvent().Signal(); |
diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h index bc3b1967f..022f13b29 100644 --- a/src/core/hle/service/nfp/nfp.h +++ b/src/core/hle/service/nfp/nfp.h | |||
| @@ -153,6 +153,13 @@ public: | |||
| 153 | }; | 153 | }; |
| 154 | static_assert(sizeof(EncryptedAmiiboFile) == 0x1F8, "AmiiboFile is an invalid size"); | 154 | static_assert(sizeof(EncryptedAmiiboFile) == 0x1F8, "AmiiboFile is an invalid size"); |
| 155 | 155 | ||
| 156 | struct NTAG215Password { | ||
| 157 | u32 PWD; // Password to allow write access | ||
| 158 | u16 PACK; // Password acknowledge reply | ||
| 159 | u16 RFUI; // Reserved for future use | ||
| 160 | }; | ||
| 161 | static_assert(sizeof(NTAG215Password) == 0x8, "NTAG215Password is an invalid size"); | ||
| 162 | |||
| 156 | struct NTAG215File { | 163 | struct NTAG215File { |
| 157 | TagUuid uuid; // Unique serial number | 164 | TagUuid uuid; // Unique serial number |
| 158 | u16 lock_bytes; // Set defined pages as read only | 165 | u16 lock_bytes; // Set defined pages as read only |
| @@ -161,9 +168,7 @@ public: | |||
| 161 | u32 dynamic_lock; // Dynamic lock | 168 | u32 dynamic_lock; // Dynamic lock |
| 162 | u32 CFG0; // Defines memory protected by password | 169 | u32 CFG0; // Defines memory protected by password |
| 163 | u32 CFG1; // Defines number of verification attempts | 170 | u32 CFG1; // Defines number of verification attempts |
| 164 | u32 PWD; // Password to allow write access | 171 | NTAG215Password password; // Password data |
| 165 | u16 PACK; // Password acknowledge reply | ||
| 166 | u16 RFUI; // Reserved for future use | ||
| 167 | }; | 172 | }; |
| 168 | static_assert(sizeof(NTAG215File) == 0x21C, "NTAG215File is an invalid size"); | 173 | static_assert(sizeof(NTAG215File) == 0x21C, "NTAG215File is an invalid size"); |
| 169 | 174 | ||