summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/nfp/nfp_device.cpp44
-rw-r--r--src/core/hle/service/nfp/nfp_device.h1
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 @@
3 3
4#include <array> 4#include <array>
5 5
6#ifdef _MSC_VER
7#pragma warning(push)
8#pragma warning(disable : 4701) // Potentially uninitialized local variable 'result' used
9#endif
10
11#include <boost/crc.hpp>
12
13#ifdef _MSC_VER
14#pragma warning(pop)
15#endif
16
6#include "common/input.h" 17#include "common/input.h"
7#include "common/logging/log.h" 18#include "common/logging/log.h"
8#include "common/string_util.h" 19#include "common/string_util.h"
@@ -843,7 +854,9 @@ void NfpDevice::UpdateSettingsCrc() {
843 854
844 // TODO: this reads data from a global, find what it is 855 // TODO: this reads data from a global, find what it is
845 std::array<u8, 8> unknown_input{}; 856 std::array<u8, 8> unknown_input{};
846 settings.crc = CalculateCrc(unknown_input); 857 boost::crc_32_type crc;
858 crc.process_bytes(&unknown_input, sizeof(unknown_input));
859 settings.crc = crc.checksum();
847} 860}
848 861
849void NfpDevice::UpdateRegisterInfoCrc() { 862void NfpDevice::UpdateRegisterInfoCrc() {
@@ -866,32 +879,9 @@ void NfpDevice::UpdateRegisterInfoCrc() {
866 .unknown2 = tag_data.unknown2, 879 .unknown2 = tag_data.unknown2,
867 }; 880 };
868 881
869 std::array<u8, sizeof(CrcData)> data{}; 882 boost::crc_32_type crc;
870 memcpy(data.data(), &crc_data, sizeof(CrcData)); 883 crc.process_bytes(&crc_data, sizeof(CrcData));
871 tag_data.register_info_crc = CalculateCrc(data); 884 tag_data.register_info_crc = crc.checksum();
872}
873
874u32 NfpDevice::CalculateCrc(std::span<const u8> data) {
875 constexpr u32 magic = 0xedb88320;
876 u32 crc = 0xffffffff;
877
878 if (data.size() == 0) {
879 return 0;
880 }
881
882 for (u8 input : data) {
883 crc ^= input;
884 crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
885 crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
886 crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
887 crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
888 crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
889 crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
890 crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
891 crc = crc >> 1 ^ ((crc & 1) ? magic : 0x0);
892 }
893
894 return ~crc;
895} 885}
896 886
897} // namespace Service::NFP 887} // 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:
81 u64 RemoveVersionByte(u64 application_id) const; 81 u64 RemoveVersionByte(u64 application_id) const;
82 void UpdateSettingsCrc(); 82 void UpdateSettingsCrc();
83 void UpdateRegisterInfoCrc(); 83 void UpdateRegisterInfoCrc();
84 u32 CalculateCrc(std::span<const u8>);
85 84
86 bool is_controller_set{}; 85 bool is_controller_set{};
87 int callback_key; 86 int callback_key;