VERY experimental Nintendo Switch 2 emulator
C++
nfp: Allow files without password data
german77c2942fa5c3df
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cppindex 63e257975a..513107715f 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) {}bool Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) {- if (buffer.size() < sizeof(NTAG215File)) {- LOG_ERROR(Service_NFP, "Wrong file size");+ if (device_state != DeviceState::SearchingForTag) {+ LOG_ERROR(Service_NFP, "Game is not looking for amiibos, current state {}", device_state);return false;}- if (device_state != DeviceState::SearchingForTag) {- LOG_ERROR(Service_NFP, "Game is not looking for amiibos, current state {}", device_state);+ constexpr auto tag_size = sizeof(NTAG215File);+ constexpr auto tag_size_without_password = sizeof(NTAG215File) - sizeof(NTAG215Password);++ std::vector<u8> amiibo_buffer = buffer;++ if (amiibo_buffer.size() < tag_size_without_password) {+ LOG_ERROR(Service_NFP, "Wrong file size {}", buffer.size());return false;}+ // Ensure it has the correct size+ if (amiibo_buffer.size() != tag_size) {+ amiibo_buffer.resize(tag_size, 0);+ }+LOG_INFO(Service_NFP, "Amiibo detected");- std::memcpy(&tag_data, buffer.data(), sizeof(tag_data));+ std::memcpy(&tag_data, buffer.data(), tag_size);if (!IsAmiiboValid()) {return false;}// This value can't be dumped from a tag. Generate it- tag_data.PWD = GetTagPassword(tag_data.uuid);+ tag_data.password.PWD = GetTagPassword(tag_data.uuid);device_state = DeviceState::TagFound;activate_event->GetWritableEvent().Signal();diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.hindex bc3b1967fe..022f13b29a 100644--- a/src/core/hle/service/nfp/nfp.h+++ b/src/core/hle/service/nfp/nfp.h@@ -153,6 +153,13 @@ public:};static_assert(sizeof(EncryptedAmiiboFile) == 0x1F8, "AmiiboFile is an invalid size");+ struct NTAG215Password {+ u32 PWD; // Password to allow write access+ u16 PACK; // Password acknowledge reply+ u16 RFUI; // Reserved for future use+ };+ static_assert(sizeof(NTAG215Password) == 0x8, "NTAG215Password is an invalid size");+struct NTAG215File {TagUuid uuid; // Unique serial numberu16 lock_bytes; // Set defined pages as read only@@ -161,9 +168,7 @@ public:u32 dynamic_lock; // Dynamic locku32 CFG0; // Defines memory protected by passwordu32 CFG1; // Defines number of verification attempts- u32 PWD; // Password to allow write access- u16 PACK; // Password acknowledge reply- u16 RFUI; // Reserved for future use+ NTAG215Password password; // Password data};static_assert(sizeof(NTAG215File) == 0x21C, "NTAG215File is an invalid size");