forked from suyu/suyu
input_common: Allow mifare files
This commit is contained in:
parent
a4725bcb73
commit
752236caad
2 changed files with 29 additions and 16 deletions
|
@ -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,
|
||||
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,
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue