mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2024-11-27 01:34:19 +01:00
input_common: Allow mifare files
This commit is contained in:
parent
a4725bcb73
commit
752236caad
@ -47,20 +47,20 @@ Common::Input::NfcState VirtualAmiibo::SupportsNfc(
|
|||||||
|
|
||||||
Common::Input::NfcState VirtualAmiibo::WriteNfcData(
|
Common::Input::NfcState VirtualAmiibo::WriteNfcData(
|
||||||
[[maybe_unused]] const PadIdentifier& identifier_, const std::vector<u8>& data) {
|
[[maybe_unused]] const PadIdentifier& identifier_, const std::vector<u8>& data) {
|
||||||
const Common::FS::IOFile amiibo_file{file_path, Common::FS::FileAccessMode::ReadWrite,
|
const Common::FS::IOFile nfc_file{file_path, Common::FS::FileAccessMode::ReadWrite,
|
||||||
Common::FS::FileType::BinaryFile};
|
Common::FS::FileType::BinaryFile};
|
||||||
|
|
||||||
if (!amiibo_file.IsOpen()) {
|
if (!nfc_file.IsOpen()) {
|
||||||
LOG_ERROR(Core, "Amiibo is already on use");
|
LOG_ERROR(Core, "Amiibo is already on use");
|
||||||
return Common::Input::NfcState::WriteFailed;
|
return Common::Input::NfcState::WriteFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!amiibo_file.Write(data)) {
|
if (!nfc_file.Write(data)) {
|
||||||
LOG_ERROR(Service_NFP, "Error writting to file");
|
LOG_ERROR(Service_NFP, "Error writting to file");
|
||||||
return Common::Input::NfcState::WriteFailed;
|
return Common::Input::NfcState::WriteFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
amiibo_data = data;
|
nfc_data = data;
|
||||||
|
|
||||||
return Common::Input::NfcState::Success;
|
return Common::Input::NfcState::Success;
|
||||||
}
|
}
|
||||||
@ -70,32 +70,44 @@ VirtualAmiibo::State VirtualAmiibo::GetCurrentState() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
VirtualAmiibo::Info VirtualAmiibo::LoadAmiibo(const std::string& filename) {
|
VirtualAmiibo::Info VirtualAmiibo::LoadAmiibo(const std::string& filename) {
|
||||||
const Common::FS::IOFile amiibo_file{filename, Common::FS::FileAccessMode::Read,
|
const Common::FS::IOFile nfc_file{filename, Common::FS::FileAccessMode::Read,
|
||||||
Common::FS::FileType::BinaryFile};
|
Common::FS::FileType::BinaryFile};
|
||||||
|
|
||||||
if (state != State::WaitingForAmiibo) {
|
if (state != State::WaitingForAmiibo) {
|
||||||
return Info::WrongDeviceState;
|
return Info::WrongDeviceState;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!amiibo_file.IsOpen()) {
|
if (!nfc_file.IsOpen()) {
|
||||||
return Info::UnableToLoad;
|
return Info::UnableToLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
amiibo_data.resize(amiibo_size);
|
switch (nfc_file.GetSize()) {
|
||||||
|
case AmiiboSize:
|
||||||
if (amiibo_file.Read(amiibo_data) < amiibo_size_without_password) {
|
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;
|
return Info::NotAnAmiibo;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_path = filename;
|
file_path = filename;
|
||||||
state = State::AmiiboIsOpen;
|
state = State::AmiiboIsOpen;
|
||||||
SetNfc(identifier, {Common::Input::NfcState::NewAmiibo, amiibo_data});
|
SetNfc(identifier, {Common::Input::NfcState::NewAmiibo, nfc_data});
|
||||||
return Info::Success;
|
return Info::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
VirtualAmiibo::Info VirtualAmiibo::ReloadAmiibo() {
|
VirtualAmiibo::Info VirtualAmiibo::ReloadAmiibo() {
|
||||||
if (state == State::AmiiboIsOpen) {
|
if (state == State::AmiiboIsOpen) {
|
||||||
SetNfc(identifier, {Common::Input::NfcState::NewAmiibo, amiibo_data});
|
SetNfc(identifier, {Common::Input::NfcState::NewAmiibo, nfc_data});
|
||||||
return Info::Success;
|
return Info::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,12 +53,13 @@ public:
|
|||||||
std::string GetLastFilePath() const;
|
std::string GetLastFilePath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr std::size_t amiibo_size = 0x21C;
|
static constexpr std::size_t AmiiboSize = 0x21C;
|
||||||
static constexpr std::size_t amiibo_size_without_password = amiibo_size - 0x8;
|
static constexpr std::size_t AmiiboSizeWithoutPassword = AmiiboSize - 0x8;
|
||||||
|
static constexpr std::size_t MifareSize = 0x400;
|
||||||
|
|
||||||
std::string file_path{};
|
std::string file_path{};
|
||||||
State state{State::Initialized};
|
State state{State::Initialized};
|
||||||
std::vector<u8> amiibo_data;
|
std::vector<u8> nfc_data;
|
||||||
Common::Input::PollingMode polling_mode{Common::Input::PollingMode::Pasive};
|
Common::Input::PollingMode polling_mode{Common::Input::PollingMode::Pasive};
|
||||||
};
|
};
|
||||||
} // namespace InputCommon
|
} // namespace InputCommon
|
||||||
|
Loading…
Reference in New Issue
Block a user