diff options
| author | 2023-09-17 10:45:24 -0600 | |
|---|---|---|
| committer | 2023-09-17 16:06:25 -0600 | |
| commit | bd409c34162783d512d71a1c9e46bc874f73de38 (patch) | |
| tree | 5ad8613891c29b0f86aae89d56490d3b352f06d6 /src/core/hle/service/mii | |
| parent | service: nfc: Fully Implement GetRegisterInfoPrivate (diff) | |
| download | yuzu-bd409c34162783d512d71a1c9e46bc874f73de38.tar.gz yuzu-bd409c34162783d512d71a1c9e46bc874f73de38.tar.xz yuzu-bd409c34162783d512d71a1c9e46bc874f73de38.zip | |
service: mii: Add device crc16
Diffstat (limited to 'src/core/hle/service/mii')
| -rw-r--r-- | src/core/hle/service/mii/mii_util.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/core/hle/service/mii/mii_util.h b/src/core/hle/service/mii/mii_util.h index ddb544c23..3534fa31d 100644 --- a/src/core/hle/service/mii/mii_util.h +++ b/src/core/hle/service/mii/mii_util.h | |||
| @@ -28,6 +28,32 @@ public: | |||
| 28 | return Common::swap16(static_cast<u16>(crc)); | 28 | return Common::swap16(static_cast<u16>(crc)); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | static u16 CalculateDeviceCrc16(const Common::UUID& uuid, std::size_t data_size) { | ||
| 32 | constexpr u16 magic{0x1021}; | ||
| 33 | s32 crc{}; | ||
| 34 | |||
| 35 | for (std::size_t i = 0; i < uuid.uuid.size(); i++) { | ||
| 36 | for (std::size_t j = 0; j < 8; j++) { | ||
| 37 | crc <<= 1; | ||
| 38 | if ((crc & 0x10000) != 0) { | ||
| 39 | crc = crc ^ magic; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | crc ^= uuid.uuid[i]; | ||
| 43 | } | ||
| 44 | |||
| 45 | // As much as this looks wrong this is what N's does | ||
| 46 | |||
| 47 | for (std::size_t i = 0; i < data_size * 8; i++) { | ||
| 48 | crc <<= 1; | ||
| 49 | if ((crc & 0x10000) != 0) { | ||
| 50 | crc = crc ^ magic; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | return Common::swap16(static_cast<u16>(crc)); | ||
| 55 | } | ||
| 56 | |||
| 31 | static Common::UUID MakeCreateId() { | 57 | static Common::UUID MakeCreateId() { |
| 32 | return Common::UUID::MakeRandomRFC4122V4(); | 58 | return Common::UUID::MakeRandomRFC4122V4(); |
| 33 | } | 59 | } |