summaryrefslogtreecommitdiffstats
path: root/src/input_common/drivers
diff options
context:
space:
mode:
authorNarr the Reg <juangerman-13@hotmail.com>2022-12-02 02:42:39 +0100
committergerman77 <juangerman-13@hotmail.com>2022-12-05 03:02:48 +0100
commit752236caad5d1d3ed097c22929081919f27b190e (patch)
treed05fae1721175fbbd0c149b258cb58de94d40fef /src/input_common/drivers
parentservice: nfc: Implement mifare service (diff)
downloadyuzu-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 'src/input_common/drivers')
-rw-r--r--src/input_common/drivers/virtual_amiibo.cpp38
-rw-r--r--src/input_common/drivers/virtual_amiibo.h7
2 files changed, 29 insertions, 16 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;
}
diff --git a/src/input_common/drivers/virtual_amiibo.h b/src/input_common/drivers/virtual_amiibo.h
index 9baeb3997..0f9dad333 100644
--- a/src/input_common/drivers/virtual_amiibo.h
+++ b/src/input_common/drivers/virtual_amiibo.h
@@ -53,12 +53,13 @@ public:
std::string GetLastFilePath() const;
private:
- static constexpr std::size_t amiibo_size = 0x21C;
- static constexpr std::size_t amiibo_size_without_password = amiibo_size - 0x8;
+ static constexpr std::size_t AmiiboSize = 0x21C;
+ static constexpr std::size_t AmiiboSizeWithoutPassword = AmiiboSize - 0x8;
+ static constexpr std::size_t MifareSize = 0x400;
std::string file_path{};
State state{State::Initialized};
- std::vector<u8> amiibo_data;
+ std::vector<u8> nfc_data;
Common::Input::PollingMode polling_mode{Common::Input::PollingMode::Pasive};
};
} // namespace InputCommon