From 075a3d11723d629148e016d089e2c533264ae831 Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Thu, 16 Mar 2023 17:47:32 -0600 Subject: [PATCH] service: nfp: Replace crc function with boost equivalent --- src/core/hle/service/nfp/nfp_device.cpp | 44 ++++++++++--------------- src/core/hle/service/nfp/nfp_device.h | 1 - 2 files changed, 17 insertions(+), 28 deletions(-) diff --git a/src/core/hle/service/nfp/nfp_device.cpp b/src/core/hle/service/nfp/nfp_device.cpp index 61a7ea7ac..268337d2e 100644 --- a/src/core/hle/service/nfp/nfp_device.cpp +++ b/src/core/hle/service/nfp/nfp_device.cpp @@ -3,6 +3,17 @@ #include +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4701) // Potentially uninitialized local variable 'result' used +#endif + +#include + +#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 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 data{}; - memcpy(data.data(), &crc_data, sizeof(CrcData)); - tag_data.register_info_crc = CalculateCrc(data); -} - -u32 NfpDevice::CalculateCrc(std::span 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 diff --git a/src/core/hle/service/nfp/nfp_device.h b/src/core/hle/service/nfp/nfp_device.h index fc7fbd578..8813df998 100644 --- a/src/core/hle/service/nfp/nfp_device.h +++ b/src/core/hle/service/nfp/nfp_device.h @@ -81,7 +81,6 @@ private: u64 RemoveVersionByte(u64 application_id) const; void UpdateSettingsCrc(); void UpdateRegisterInfoCrc(); - u32 CalculateCrc(std::span); bool is_controller_set{}; int callback_key;