diff options
author | Narr the Reg <juangerman-13@hotmail.com> | 2022-12-02 02:42:39 +0100 |
---|---|---|
committer | german77 <juangerman-13@hotmail.com> | 2022-12-05 03:02:48 +0100 |
commit | 752236caad5d1d3ed097c22929081919f27b190e (patch) | |
tree | d05fae1721175fbbd0c149b258cb58de94d40fef /src/input_common/drivers/virtual_amiibo.cpp | |
parent | service: nfc: Implement mifare service (diff) | |
download | yuzu-752236caad5d1d3ed097c22929081919f27b190e.tar yuzu-752236caad5d1d3ed097c22929081919f27b190e.tar.gz yuzu-752236caad5d1d3ed097c22929081919f27b190e.tar.bz2 yuzu-752236caad5d1d3ed097c22929081919f27b190e.tar.lz yuzu-752236caad5d1d3ed097c22929081919f27b190e.tar.xz yuzu-752236caad5d1d3ed097c22929081919f27b190e.tar.zst yuzu-752236caad5d1d3ed097c22929081919f27b190e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/input_common/drivers/virtual_amiibo.cpp | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/input_common/drivers/virtual_amiibo.cpp b/src/input_common/drivers/virtual_amiibo.cpp index 564a188e5..63ffaca67 100644 --- a/src/input_common/drivers/virtual_amiibo.cpp +++ b/src/input_common/drivers/virtual_amiibo.cpp @@ -47,20 +47,20 @@ Common::Input::NfcState VirtualAmiibo::SupportsNfc( Common::Input::NfcState VirtualAmiibo::WriteNfcData( [[maybe_unused]] const PadIdentifier& identifier_, const std::vector<u8>& data) { - const Common::FS::IOFile amiibo_file{file_path, Common::FS::FileAccessMode::ReadWrite, - Common::FS::FileType::BinaryFile}; + const Common::FS::IOFile nfc_file{file_path, Common::FS::FileAccessMode::ReadWrite, + Common::FS::FileType::BinaryFile}; - if (!amiibo_file.IsOpen()) { + if (!nfc_file.IsOpen()) { LOG_ERROR(Core, "Amiibo is already on use"); return Common::Input::NfcState::WriteFailed; } - if (!amiibo_file.Write(data)) { + if (!nfc_file.Write(data)) { LOG_ERROR(Service_NFP, "Error writting to file"); return Common::Input::NfcState::WriteFailed; } - amiibo_data = data; + nfc_data = data; return Common::Input::NfcState::Success; } @@ -70,32 +70,44 @@ VirtualAmiibo::State VirtualAmiibo::GetCurrentState() const { } VirtualAmiibo::Info VirtualAmiibo::LoadAmiibo(const std::string& filename) { - const Common::FS::IOFile amiibo_file{filename, Common::FS::FileAccessMode::Read, - Common::FS::FileType::BinaryFile}; + const Common::FS::IOFile nfc_file{filename, Common::FS::FileAccessMode::Read, + Common::FS::FileType::BinaryFile}; if (state != State::WaitingForAmiibo) { return Info::WrongDeviceState; } - if (!amiibo_file.IsOpen()) { + if (!nfc_file.IsOpen()) { return Info::UnableToLoad; } - amiibo_data.resize(amiibo_size); - - if (amiibo_file.Read(amiibo_data) < amiibo_size_without_password) { + switch (nfc_file.GetSize()) { + case AmiiboSize: + case AmiiboSizeWithoutPassword: + nfc_data.resize(AmiiboSize); + if (nfc_file.Read(nfc_data) < AmiiboSizeWithoutPassword) { + return Info::NotAnAmiibo; + } + break; + case MifareSize: + nfc_data.resize(MifareSize); + if (nfc_file.Read(nfc_data) < MifareSize) { + return Info::NotAnAmiibo; + } + break; + default: return Info::NotAnAmiibo; } file_path = filename; state = State::AmiiboIsOpen; - SetNfc(identifier, {Common::Input::NfcState::NewAmiibo, amiibo_data}); + SetNfc(identifier, {Common::Input::NfcState::NewAmiibo, nfc_data}); return Info::Success; } VirtualAmiibo::Info VirtualAmiibo::ReloadAmiibo() { if (state == State::AmiiboIsOpen) { - SetNfc(identifier, {Common::Input::NfcState::NewAmiibo, amiibo_data}); + SetNfc(identifier, {Common::Input::NfcState::NewAmiibo, nfc_data}); return Info::Success; } |