diff options
| -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 | } |