mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-20 08:49:59 +00:00
service: nfp: Replace crc function with boost equivalent
This commit is contained in:
parent
7187732454
commit
075a3d1172
2 changed files with 17 additions and 28 deletions
|
@ -3,6 +3,17 @@
|
|||
|
||||
#include <array>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4701) // Potentially uninitialized local variable 'result' used
|
||||
#endif
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#include "common/input.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/string_util.h"
|
||||
|
@ -843,7 +854,9 @@ void NfpDevice::UpdateSettingsCrc() {
|
|||
|
||||
// TODO: this reads data from a global, find what it is
|
||||
std::array<u8, 8> unknown_input{};
|
||||
settings.crc = CalculateCrc(unknown_input);
|
||||
boost::crc_32_type crc;
|
||||
crc.process_bytes(&unknown_input, sizeof(unknown_input));
|
||||
settings.crc = crc.checksum();
|
||||
}
|
||||
|
||||
void NfpDevice::UpdateRegisterInfoCrc() {
|
||||
|
@ -866,32 +879,9 @@ void NfpDevice::UpdateRegisterInfoCrc() {
|
|||
.unknown2 = tag_data.unknown2,
|
||||
};
|
||||
|
||||
std::array<u8, sizeof(CrcData)> data{};
|
||||
memcpy(data.data(), &crc_data, sizeof(CrcData));
|
||||
tag_data.register_info_crc = CalculateCrc(data);
|
||||
}
|
||||
|
||||
u32 NfpDevice::CalculateCrc(std::span<const u8> data) {
|
||||
constexpr u32 magic = 0xedb88320;
|
||||
u32 crc = 0xffffffff;
|
||||
|
||||
if (data.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (u8 input : data) {
|
||||
crc ^= input;
|
||||
crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
|
||||
crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
|
||||
crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
|
||||
crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
|
||||
crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
|
||||
crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
|
||||
crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
|
||||
crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
|
||||
}
|
||||
|
||||
return ~crc;
|
||||
boost::crc_32_type crc;
|
||||
crc.process_bytes(&crc_data, sizeof(CrcData));
|
||||
tag_data.register_info_crc = crc.checksum();
|
||||
}
|
||||
|
||||
} // namespace Service::NFP
|
||||
|
|
|
@ -81,7 +81,6 @@ private:
|
|||
u64 RemoveVersionByte(u64 application_id) const;
|
||||
void UpdateSettingsCrc();
|
||||
void UpdateRegisterInfoCrc();
|
||||
u32 CalculateCrc(std::span<const u8>);
|
||||
|
||||
bool is_controller_set{};
|
||||
int callback_key;
|
||||
|
|
Loading…
Reference in a new issue