yuzu-emu
/
yuzu
Archived
1
0
Fork 0

service: nfp: Replace crc function with boost equivalent

This commit is contained in:
Narr the Reg 2023-03-16 17:47:32 -06:00
parent 7187732454
commit 075a3d1172
2 changed files with 17 additions and 28 deletions

View File

@ -3,6 +3,17 @@
#include <array> #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/input.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/string_util.h" #include "common/string_util.h"
@ -843,7 +854,9 @@ void NfpDevice::UpdateSettingsCrc() {
// TODO: this reads data from a global, find what it is // TODO: this reads data from a global, find what it is
std::array<u8, 8> unknown_input{}; 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() { void NfpDevice::UpdateRegisterInfoCrc() {
@ -866,32 +879,9 @@ void NfpDevice::UpdateRegisterInfoCrc() {
.unknown2 = tag_data.unknown2, .unknown2 = tag_data.unknown2,
}; };
std::array<u8, sizeof(CrcData)> data{}; boost::crc_32_type crc;
memcpy(data.data(), &crc_data, sizeof(CrcData)); crc.process_bytes(&crc_data, sizeof(CrcData));
tag_data.register_info_crc = CalculateCrc(data); tag_data.register_info_crc = crc.checksum();
}
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;
} }
} // namespace Service::NFP } // namespace Service::NFP

View File

@ -81,7 +81,6 @@ private:
u64 RemoveVersionByte(u64 application_id) const; u64 RemoveVersionByte(u64 application_id) const;
void UpdateSettingsCrc(); void UpdateSettingsCrc();
void UpdateRegisterInfoCrc(); void UpdateRegisterInfoCrc();
u32 CalculateCrc(std::span<const u8>);
bool is_controller_set{}; bool is_controller_set{};
int callback_key; int callback_key;