diff options
| author | 2022-02-10 21:52:13 -0700 | |
|---|---|---|
| committer | 2022-02-10 21:52:13 -0700 | |
| commit | ca9da569ce8d5ce8106ff69afce484d9516570a8 (patch) | |
| tree | db8f98fcfcd3d3d77f77c52b3be696c073f90f6e /src | |
| parent | Merge pull request #7861 from german77/user_features (diff) | |
| parent | common: uuid: Use sizeof(u64) instead of 8 in Hash() (diff) | |
| download | yuzu-ca9da569ce8d5ce8106ff69afce484d9516570a8.tar.gz yuzu-ca9da569ce8d5ce8106ff69afce484d9516570a8.tar.xz yuzu-ca9da569ce8d5ce8106ff69afce484d9516570a8.zip | |
Merge pull request #7852 from Morph1984/new-uuid
common: Revise and fix the UUID implementation
Diffstat (limited to 'src')
31 files changed, 370 insertions, 193 deletions
diff --git a/src/common/uuid.cpp b/src/common/uuid.cpp index d7435a6e9..2b6a530e3 100644 --- a/src/common/uuid.cpp +++ b/src/common/uuid.cpp | |||
| @@ -1,23 +1,25 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | 1 | // Copyright 2022 yuzu Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <bit> | ||
| 6 | #include <optional> | ||
| 5 | #include <random> | 7 | #include <random> |
| 6 | 8 | ||
| 7 | #include <fmt/format.h> | 9 | #include <fmt/format.h> |
| 8 | 10 | ||
| 9 | #include "common/assert.h" | 11 | #include "common/assert.h" |
| 12 | #include "common/tiny_mt.h" | ||
| 10 | #include "common/uuid.h" | 13 | #include "common/uuid.h" |
| 11 | 14 | ||
| 12 | namespace Common { | 15 | namespace Common { |
| 13 | 16 | ||
| 14 | namespace { | 17 | namespace { |
| 15 | 18 | ||
| 16 | bool IsHexDigit(char c) { | 19 | constexpr size_t RawStringSize = sizeof(UUID) * 2; |
| 17 | return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); | 20 | constexpr size_t FormattedStringSize = RawStringSize + 4; |
| 18 | } | ||
| 19 | 21 | ||
| 20 | u8 HexCharToByte(char c) { | 22 | std::optional<u8> HexCharToByte(char c) { |
| 21 | if (c >= '0' && c <= '9') { | 23 | if (c >= '0' && c <= '9') { |
| 22 | return static_cast<u8>(c - '0'); | 24 | return static_cast<u8>(c - '0'); |
| 23 | } | 25 | } |
| @@ -28,60 +30,184 @@ u8 HexCharToByte(char c) { | |||
| 28 | return static_cast<u8>(c - 'A' + 10); | 30 | return static_cast<u8>(c - 'A' + 10); |
| 29 | } | 31 | } |
| 30 | ASSERT_MSG(false, "{} is not a hexadecimal digit!", c); | 32 | ASSERT_MSG(false, "{} is not a hexadecimal digit!", c); |
| 31 | return u8{0}; | 33 | return std::nullopt; |
| 32 | } | 34 | } |
| 33 | 35 | ||
| 34 | } // Anonymous namespace | 36 | std::array<u8, 0x10> ConstructFromRawString(std::string_view raw_string) { |
| 37 | std::array<u8, 0x10> uuid; | ||
| 38 | |||
| 39 | for (size_t i = 0; i < RawStringSize; i += 2) { | ||
| 40 | const auto upper = HexCharToByte(raw_string[i]); | ||
| 41 | const auto lower = HexCharToByte(raw_string[i + 1]); | ||
| 42 | if (!upper || !lower) { | ||
| 43 | return {}; | ||
| 44 | } | ||
| 45 | uuid[i / 2] = static_cast<u8>((*upper << 4) | *lower); | ||
| 46 | } | ||
| 47 | |||
| 48 | return uuid; | ||
| 49 | } | ||
| 35 | 50 | ||
| 36 | u128 HexStringToU128(std::string_view hex_string) { | 51 | std::array<u8, 0x10> ConstructFromFormattedString(std::string_view formatted_string) { |
| 37 | const size_t length = hex_string.length(); | 52 | std::array<u8, 0x10> uuid; |
| 38 | 53 | ||
| 39 | // Detect "0x" prefix. | 54 | size_t i = 0; |
| 40 | const bool has_0x_prefix = length > 2 && hex_string[0] == '0' && hex_string[1] == 'x'; | ||
| 41 | const size_t offset = has_0x_prefix ? 2 : 0; | ||
| 42 | 55 | ||
| 43 | // Check length. | 56 | // Process the first 8 characters. |
| 44 | if (length > 32 + offset) { | 57 | const auto* str = formatted_string.data(); |
| 45 | ASSERT_MSG(false, "hex_string has more than 32 hexadecimal characters!"); | 58 | |
| 46 | return INVALID_UUID; | 59 | for (; i < 4; ++i) { |
| 60 | const auto upper = HexCharToByte(*(str++)); | ||
| 61 | const auto lower = HexCharToByte(*(str++)); | ||
| 62 | if (!upper || !lower) { | ||
| 63 | return {}; | ||
| 64 | } | ||
| 65 | uuid[i] = static_cast<u8>((*upper << 4) | *lower); | ||
| 66 | } | ||
| 67 | |||
| 68 | // Process the next 4 characters. | ||
| 69 | ++str; | ||
| 70 | |||
| 71 | for (; i < 6; ++i) { | ||
| 72 | const auto upper = HexCharToByte(*(str++)); | ||
| 73 | const auto lower = HexCharToByte(*(str++)); | ||
| 74 | if (!upper || !lower) { | ||
| 75 | return {}; | ||
| 76 | } | ||
| 77 | uuid[i] = static_cast<u8>((*upper << 4) | *lower); | ||
| 47 | } | 78 | } |
| 48 | 79 | ||
| 49 | u64 lo = 0; | 80 | // Process the next 4 characters. |
| 50 | u64 hi = 0; | 81 | ++str; |
| 51 | for (size_t i = 0; i < length - offset; ++i) { | 82 | |
| 52 | const char c = hex_string[length - 1 - i]; | 83 | for (; i < 8; ++i) { |
| 53 | if (!IsHexDigit(c)) { | 84 | const auto upper = HexCharToByte(*(str++)); |
| 54 | ASSERT_MSG(false, "{} is not a hexadecimal digit!", c); | 85 | const auto lower = HexCharToByte(*(str++)); |
| 55 | return INVALID_UUID; | 86 | if (!upper || !lower) { |
| 87 | return {}; | ||
| 56 | } | 88 | } |
| 57 | if (i < 16) { | 89 | uuid[i] = static_cast<u8>((*upper << 4) | *lower); |
| 58 | lo |= u64{HexCharToByte(c)} << (i * 4); | 90 | } |
| 91 | |||
| 92 | // Process the next 4 characters. | ||
| 93 | ++str; | ||
| 94 | |||
| 95 | for (; i < 10; ++i) { | ||
| 96 | const auto upper = HexCharToByte(*(str++)); | ||
| 97 | const auto lower = HexCharToByte(*(str++)); | ||
| 98 | if (!upper || !lower) { | ||
| 99 | return {}; | ||
| 59 | } | 100 | } |
| 60 | if (i >= 16) { | 101 | uuid[i] = static_cast<u8>((*upper << 4) | *lower); |
| 61 | hi |= u64{HexCharToByte(c)} << ((i - 16) * 4); | 102 | } |
| 103 | |||
| 104 | // Process the last 12 characters. | ||
| 105 | ++str; | ||
| 106 | |||
| 107 | for (; i < 16; ++i) { | ||
| 108 | const auto upper = HexCharToByte(*(str++)); | ||
| 109 | const auto lower = HexCharToByte(*(str++)); | ||
| 110 | if (!upper || !lower) { | ||
| 111 | return {}; | ||
| 62 | } | 112 | } |
| 113 | uuid[i] = static_cast<u8>((*upper << 4) | *lower); | ||
| 114 | } | ||
| 115 | |||
| 116 | return uuid; | ||
| 117 | } | ||
| 118 | |||
| 119 | std::array<u8, 0x10> ConstructUUID(std::string_view uuid_string) { | ||
| 120 | const auto length = uuid_string.length(); | ||
| 121 | |||
| 122 | if (length == 0) { | ||
| 123 | return {}; | ||
| 124 | } | ||
| 125 | |||
| 126 | // Check if the input string contains 32 hexadecimal characters. | ||
| 127 | if (length == RawStringSize) { | ||
| 128 | return ConstructFromRawString(uuid_string); | ||
| 129 | } | ||
| 130 | |||
| 131 | // Check if the input string has the length of a RFC 4122 formatted UUID string. | ||
| 132 | if (length == FormattedStringSize) { | ||
| 133 | return ConstructFromFormattedString(uuid_string); | ||
| 63 | } | 134 | } |
| 64 | return u128{lo, hi}; | 135 | |
| 136 | ASSERT_MSG(false, "UUID string has an invalid length of {} characters!", length); | ||
| 137 | |||
| 138 | return {}; | ||
| 139 | } | ||
| 140 | |||
| 141 | } // Anonymous namespace | ||
| 142 | |||
| 143 | UUID::UUID(std::string_view uuid_string) : uuid{ConstructUUID(uuid_string)} {} | ||
| 144 | |||
| 145 | std::string UUID::RawString() const { | ||
| 146 | return fmt::format("{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}" | ||
| 147 | "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", | ||
| 148 | uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], | ||
| 149 | uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], | ||
| 150 | uuid[15]); | ||
| 151 | } | ||
| 152 | |||
| 153 | std::string UUID::FormattedString() const { | ||
| 154 | return fmt::format("{:02x}{:02x}{:02x}{:02x}" | ||
| 155 | "-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-" | ||
| 156 | "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", | ||
| 157 | uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], | ||
| 158 | uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], | ||
| 159 | uuid[15]); | ||
| 160 | } | ||
| 161 | |||
| 162 | size_t UUID::Hash() const noexcept { | ||
| 163 | u64 upper_hash; | ||
| 164 | u64 lower_hash; | ||
| 165 | |||
| 166 | std::memcpy(&upper_hash, uuid.data(), sizeof(u64)); | ||
| 167 | std::memcpy(&lower_hash, uuid.data() + sizeof(u64), sizeof(u64)); | ||
| 168 | |||
| 169 | return upper_hash ^ std::rotl(lower_hash, 1); | ||
| 65 | } | 170 | } |
| 66 | 171 | ||
| 67 | UUID UUID::Generate() { | 172 | u128 UUID::AsU128() const { |
| 173 | u128 uuid_old; | ||
| 174 | std::memcpy(&uuid_old, uuid.data(), sizeof(UUID)); | ||
| 175 | return uuid_old; | ||
| 176 | } | ||
| 177 | |||
| 178 | UUID UUID::MakeRandom() { | ||
| 68 | std::random_device device; | 179 | std::random_device device; |
| 69 | std::mt19937 gen(device()); | 180 | |
| 70 | std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); | 181 | return MakeRandomWithSeed(device()); |
| 71 | return UUID{distribution(gen), distribution(gen)}; | ||
| 72 | } | 182 | } |
| 73 | 183 | ||
| 74 | std::string UUID::Format() const { | 184 | UUID UUID::MakeRandomWithSeed(u32 seed) { |
| 75 | return fmt::format("{:016x}{:016x}", uuid[1], uuid[0]); | 185 | // Create and initialize our RNG. |
| 186 | TinyMT rng; | ||
| 187 | rng.Initialize(seed); | ||
| 188 | |||
| 189 | UUID uuid; | ||
| 190 | |||
| 191 | // Populate the UUID with random bytes. | ||
| 192 | rng.GenerateRandomBytes(uuid.uuid.data(), sizeof(UUID)); | ||
| 193 | |||
| 194 | return uuid; | ||
| 76 | } | 195 | } |
| 77 | 196 | ||
| 78 | std::string UUID::FormatSwitch() const { | 197 | UUID UUID::MakeRandomRFC4122V4() { |
| 79 | std::array<u8, 16> s{}; | 198 | auto uuid = MakeRandom(); |
| 80 | std::memcpy(s.data(), uuid.data(), sizeof(u128)); | 199 | |
| 81 | return fmt::format("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{" | 200 | // According to Proposed Standard RFC 4122 Section 4.4, we must: |
| 82 | ":02x}{:02x}{:02x}{:02x}{:02x}", | 201 | |
| 83 | s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], | 202 | // 1. Set the two most significant bits (bits 6 and 7) of the |
| 84 | s[12], s[13], s[14], s[15]); | 203 | // clock_seq_hi_and_reserved to zero and one, respectively. |
| 204 | uuid.uuid[8] = 0x80 | (uuid.uuid[8] & 0x3F); | ||
| 205 | |||
| 206 | // 2. Set the four most significant bits (bits 12 through 15) of the | ||
| 207 | // time_hi_and_version field to the 4-bit version number from Section 4.1.3. | ||
| 208 | uuid.uuid[6] = 0x40 | (uuid.uuid[6] & 0xF); | ||
| 209 | |||
| 210 | return uuid; | ||
| 85 | } | 211 | } |
| 86 | 212 | ||
| 87 | } // namespace Common | 213 | } // namespace Common |
diff --git a/src/common/uuid.h b/src/common/uuid.h index 8ea01f8da..fe31e64e6 100644 --- a/src/common/uuid.h +++ b/src/common/uuid.h | |||
| @@ -1,9 +1,11 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | 1 | // Copyright 2022 yuzu Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 8 | #include <functional> | ||
| 7 | #include <string> | 9 | #include <string> |
| 8 | #include <string_view> | 10 | #include <string_view> |
| 9 | 11 | ||
| @@ -11,69 +13,119 @@ | |||
| 11 | 13 | ||
| 12 | namespace Common { | 14 | namespace Common { |
| 13 | 15 | ||
| 14 | constexpr u128 INVALID_UUID{{0, 0}}; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * Converts a hex string to a 128-bit unsigned integer. | ||
| 18 | * | ||
| 19 | * The hex string can be formatted in lowercase or uppercase, with or without the "0x" prefix. | ||
| 20 | * | ||
| 21 | * This function will assert and return INVALID_UUID under the following conditions: | ||
| 22 | * - If the hex string is more than 32 characters long | ||
| 23 | * - If the hex string contains non-hexadecimal characters | ||
| 24 | * | ||
| 25 | * @param hex_string Hexadecimal string | ||
| 26 | * | ||
| 27 | * @returns A 128-bit unsigned integer if successfully converted, INVALID_UUID otherwise. | ||
| 28 | */ | ||
| 29 | [[nodiscard]] u128 HexStringToU128(std::string_view hex_string); | ||
| 30 | |||
| 31 | struct UUID { | 16 | struct UUID { |
| 32 | // UUIDs which are 0 are considered invalid! | 17 | std::array<u8, 0x10> uuid{}; |
| 33 | u128 uuid; | 18 | |
| 34 | UUID() = default; | 19 | /// Constructs an invalid UUID. |
| 35 | constexpr explicit UUID(const u128& id) : uuid{id} {} | 20 | constexpr UUID() = default; |
| 36 | constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {} | 21 | |
| 37 | explicit UUID(std::string_view hex_string) { | 22 | /// Constructs a UUID from a reference to a 128 bit array. |
| 38 | uuid = HexStringToU128(hex_string); | 23 | constexpr explicit UUID(const std::array<u8, 16>& uuid_) : uuid{uuid_} {} |
| 39 | } | 24 | |
| 40 | 25 | /** | |
| 41 | [[nodiscard]] constexpr explicit operator bool() const { | 26 | * Constructs a UUID from either: |
| 42 | return uuid != INVALID_UUID; | 27 | * 1. A 32 hexadecimal character string representing the bytes of the UUID |
| 43 | } | 28 | * 2. A RFC 4122 formatted UUID string, in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 44 | 29 | * | |
| 45 | [[nodiscard]] constexpr bool operator==(const UUID& rhs) const { | 30 | * The input string may contain uppercase or lowercase characters, but they must: |
| 46 | return uuid == rhs.uuid; | 31 | * 1. Contain valid hexadecimal characters (0-9, a-f, A-F) |
| 47 | } | 32 | * 2. Not contain the "0x" hexadecimal prefix |
| 48 | 33 | * | |
| 49 | [[nodiscard]] constexpr bool operator!=(const UUID& rhs) const { | 34 | * Should the input string not meet the above requirements, |
| 50 | return !operator==(rhs); | 35 | * an assert will be triggered and an invalid UUID is set instead. |
| 51 | } | 36 | */ |
| 52 | 37 | explicit UUID(std::string_view uuid_string); | |
| 53 | // TODO(ogniK): Properly generate uuids based on RFC-4122 | 38 | |
| 54 | [[nodiscard]] static UUID Generate(); | 39 | ~UUID() = default; |
| 55 | 40 | ||
| 56 | // Set the UUID to {0,0} to be considered an invalid user | 41 | constexpr UUID(const UUID&) noexcept = default; |
| 57 | constexpr void Invalidate() { | 42 | constexpr UUID(UUID&&) noexcept = default; |
| 58 | uuid = INVALID_UUID; | 43 | |
| 44 | constexpr UUID& operator=(const UUID&) noexcept = default; | ||
| 45 | constexpr UUID& operator=(UUID&&) noexcept = default; | ||
| 46 | |||
| 47 | /** | ||
| 48 | * Returns whether the stored UUID is valid or not. | ||
| 49 | * | ||
| 50 | * @returns True if the stored UUID is valid, false otherwise. | ||
| 51 | */ | ||
| 52 | constexpr bool IsValid() const { | ||
| 53 | return uuid != std::array<u8, 0x10>{}; | ||
| 59 | } | 54 | } |
| 60 | 55 | ||
| 61 | [[nodiscard]] constexpr bool IsInvalid() const { | 56 | /** |
| 62 | return uuid == INVALID_UUID; | 57 | * Returns whether the stored UUID is invalid or not. |
| 63 | } | 58 | * |
| 64 | [[nodiscard]] constexpr bool IsValid() const { | 59 | * @returns True if the stored UUID is invalid, false otherwise. |
| 65 | return !IsInvalid(); | 60 | */ |
| 61 | constexpr bool IsInvalid() const { | ||
| 62 | return !IsValid(); | ||
| 66 | } | 63 | } |
| 67 | 64 | ||
| 68 | // TODO(ogniK): Properly generate a Nintendo ID | 65 | /** |
| 69 | [[nodiscard]] constexpr u64 GetNintendoID() const { | 66 | * Returns a 32 hexadecimal character string representing the bytes of the UUID. |
| 70 | return uuid[0]; | 67 | * |
| 68 | * @returns A 32 hexadecimal character string of the UUID. | ||
| 69 | */ | ||
| 70 | std::string RawString() const; | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Returns a RFC 4122 formatted UUID string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. | ||
| 74 | * | ||
| 75 | * @returns A RFC 4122 formatted UUID string. | ||
| 76 | */ | ||
| 77 | std::string FormattedString() const; | ||
| 78 | |||
| 79 | /** | ||
| 80 | * Returns a 64-bit hash of the UUID for use in hash table data structures. | ||
| 81 | * | ||
| 82 | * @returns A 64-bit hash of the UUID. | ||
| 83 | */ | ||
| 84 | size_t Hash() const noexcept; | ||
| 85 | |||
| 86 | /// DO NOT USE. Copies the contents of the UUID into a u128. | ||
| 87 | u128 AsU128() const; | ||
| 88 | |||
| 89 | /** | ||
| 90 | * Creates a default UUID "yuzu Default UID". | ||
| 91 | * | ||
| 92 | * @returns A UUID with its bytes set to the ASCII values of "yuzu Default UID". | ||
| 93 | */ | ||
| 94 | static constexpr UUID MakeDefault() { | ||
| 95 | return UUID{ | ||
| 96 | {'y', 'u', 'z', 'u', ' ', 'D', 'e', 'f', 'a', 'u', 'l', 't', ' ', 'U', 'I', 'D'}, | ||
| 97 | }; | ||
| 71 | } | 98 | } |
| 72 | 99 | ||
| 73 | [[nodiscard]] std::string Format() const; | 100 | /** |
| 74 | [[nodiscard]] std::string FormatSwitch() const; | 101 | * Creates a random UUID. |
| 102 | * | ||
| 103 | * @returns A random UUID. | ||
| 104 | */ | ||
| 105 | static UUID MakeRandom(); | ||
| 106 | |||
| 107 | /** | ||
| 108 | * Creates a random UUID with a seed. | ||
| 109 | * | ||
| 110 | * @param seed A seed to initialize the Mersenne-Twister RNG | ||
| 111 | * | ||
| 112 | * @returns A random UUID. | ||
| 113 | */ | ||
| 114 | static UUID MakeRandomWithSeed(u32 seed); | ||
| 115 | |||
| 116 | /** | ||
| 117 | * Creates a random UUID. The generated UUID is RFC 4122 Version 4 compliant. | ||
| 118 | * | ||
| 119 | * @returns A random UUID that is RFC 4122 Version 4 compliant. | ||
| 120 | */ | ||
| 121 | static UUID MakeRandomRFC4122V4(); | ||
| 122 | |||
| 123 | friend constexpr bool operator==(const UUID& lhs, const UUID& rhs) = default; | ||
| 75 | }; | 124 | }; |
| 76 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); | 125 | static_assert(sizeof(UUID) == 0x10, "UUID has incorrect size."); |
| 126 | |||
| 127 | /// An invalid UUID. This UUID has all its bytes set to 0. | ||
| 128 | constexpr UUID InvalidUUID = {}; | ||
| 77 | 129 | ||
| 78 | } // namespace Common | 130 | } // namespace Common |
| 79 | 131 | ||
| @@ -82,7 +134,7 @@ namespace std { | |||
| 82 | template <> | 134 | template <> |
| 83 | struct hash<Common::UUID> { | 135 | struct hash<Common::UUID> { |
| 84 | size_t operator()(const Common::UUID& uuid) const noexcept { | 136 | size_t operator()(const Common::UUID& uuid) const noexcept { |
| 85 | return uuid.uuid[1] ^ uuid.uuid[0]; | 137 | return uuid.Hash(); |
| 86 | } | 138 | } |
| 87 | }; | 139 | }; |
| 88 | 140 | ||
diff --git a/src/core/frontend/applets/profile_select.cpp b/src/core/frontend/applets/profile_select.cpp index 3e4f90be2..4c58c310f 100644 --- a/src/core/frontend/applets/profile_select.cpp +++ b/src/core/frontend/applets/profile_select.cpp | |||
| @@ -13,8 +13,7 @@ ProfileSelectApplet::~ProfileSelectApplet() = default; | |||
| 13 | void DefaultProfileSelectApplet::SelectProfile( | 13 | void DefaultProfileSelectApplet::SelectProfile( |
| 14 | std::function<void(std::optional<Common::UUID>)> callback) const { | 14 | std::function<void(std::optional<Common::UUID>)> callback) const { |
| 15 | Service::Account::ProfileManager manager; | 15 | Service::Account::ProfileManager manager; |
| 16 | callback(manager.GetUser(Settings::values.current_user.GetValue()) | 16 | callback(manager.GetUser(Settings::values.current_user.GetValue()).value_or(Common::UUID{})); |
| 17 | .value_or(Common::UUID{Common::INVALID_UUID})); | ||
| 18 | LOG_INFO(Service_ACC, "called, selecting current user instead of prompting..."); | 17 | LOG_INFO(Service_ACC, "called, selecting current user instead of prompting..."); |
| 19 | } | 18 | } |
| 20 | 19 | ||
diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index a7cdf45e6..2bee173b3 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp | |||
| @@ -269,7 +269,8 @@ void EmulatedController::ReloadInput() { | |||
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | // Use a common UUID for TAS | 271 | // Use a common UUID for TAS |
| 272 | const auto tas_uuid = Common::UUID{0x0, 0x7A5}; | 272 | static constexpr Common::UUID TAS_UUID = Common::UUID{ |
| 273 | {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0xA5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; | ||
| 273 | 274 | ||
| 274 | // Register TAS devices. No need to force update | 275 | // Register TAS devices. No need to force update |
| 275 | for (std::size_t index = 0; index < tas_button_devices.size(); ++index) { | 276 | for (std::size_t index = 0; index < tas_button_devices.size(); ++index) { |
| @@ -278,8 +279,8 @@ void EmulatedController::ReloadInput() { | |||
| 278 | } | 279 | } |
| 279 | tas_button_devices[index]->SetCallback({ | 280 | tas_button_devices[index]->SetCallback({ |
| 280 | .on_change = | 281 | .on_change = |
| 281 | [this, index, tas_uuid](const Common::Input::CallbackStatus& callback) { | 282 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 282 | SetButton(callback, index, tas_uuid); | 283 | SetButton(callback, index, TAS_UUID); |
| 283 | }, | 284 | }, |
| 284 | }); | 285 | }); |
| 285 | } | 286 | } |
| @@ -290,8 +291,8 @@ void EmulatedController::ReloadInput() { | |||
| 290 | } | 291 | } |
| 291 | tas_stick_devices[index]->SetCallback({ | 292 | tas_stick_devices[index]->SetCallback({ |
| 292 | .on_change = | 293 | .on_change = |
| 293 | [this, index, tas_uuid](const Common::Input::CallbackStatus& callback) { | 294 | [this, index](const Common::Input::CallbackStatus& callback) { |
| 294 | SetStick(callback, index, tas_uuid); | 295 | SetStick(callback, index, TAS_UUID); |
| 295 | }, | 296 | }, |
| 296 | }); | 297 | }); |
| 297 | } | 298 | } |
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index cf204f570..026257115 100644 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h | |||
| @@ -404,6 +404,11 @@ inline s32 RequestParser::Pop() { | |||
| 404 | return static_cast<s32>(Pop<u32>()); | 404 | return static_cast<s32>(Pop<u32>()); |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | // Ignore the -Wclass-memaccess warning on memcpy for non-trivially default constructible objects. | ||
| 408 | #if defined(__GNUC__) | ||
| 409 | #pragma GCC diagnostic push | ||
| 410 | #pragma GCC diagnostic ignored "-Wclass-memaccess" | ||
| 411 | #endif | ||
| 407 | template <typename T> | 412 | template <typename T> |
| 408 | void RequestParser::PopRaw(T& value) { | 413 | void RequestParser::PopRaw(T& value) { |
| 409 | static_assert(std::is_trivially_copyable_v<T>, | 414 | static_assert(std::is_trivially_copyable_v<T>, |
| @@ -411,6 +416,9 @@ void RequestParser::PopRaw(T& value) { | |||
| 411 | std::memcpy(&value, cmdbuf + index, sizeof(T)); | 416 | std::memcpy(&value, cmdbuf + index, sizeof(T)); |
| 412 | index += (sizeof(T) + 3) / 4; // round up to word length | 417 | index += (sizeof(T) + 3) / 4; // round up to word length |
| 413 | } | 418 | } |
| 419 | #if defined(__GNUC__) | ||
| 420 | #pragma GCC diagnostic pop | ||
| 421 | #endif | ||
| 414 | 422 | ||
| 415 | template <typename T> | 423 | template <typename T> |
| 416 | T RequestParser::PopRaw() { | 424 | T RequestParser::PopRaw() { |
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 6e63e057e..e34ef5a78 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -39,9 +39,9 @@ constexpr ResultCode ERR_FAILED_SAVE_DATA{ErrorModule::Account, 100}; | |||
| 39 | // Thumbnails are hard coded to be at least this size | 39 | // Thumbnails are hard coded to be at least this size |
| 40 | constexpr std::size_t THUMBNAIL_SIZE = 0x24000; | 40 | constexpr std::size_t THUMBNAIL_SIZE = 0x24000; |
| 41 | 41 | ||
| 42 | static std::filesystem::path GetImagePath(Common::UUID uuid) { | 42 | static std::filesystem::path GetImagePath(const Common::UUID& uuid) { |
| 43 | return Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / | 43 | return Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / |
| 44 | fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormatSwitch()); | 44 | fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormattedString()); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | static constexpr u32 SanitizeJPEGSize(std::size_t size) { | 47 | static constexpr u32 SanitizeJPEGSize(std::size_t size) { |
| @@ -290,7 +290,7 @@ public: | |||
| 290 | 290 | ||
| 291 | protected: | 291 | protected: |
| 292 | void Get(Kernel::HLERequestContext& ctx) { | 292 | void Get(Kernel::HLERequestContext& ctx) { |
| 293 | LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.Format()); | 293 | LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); |
| 294 | ProfileBase profile_base{}; | 294 | ProfileBase profile_base{}; |
| 295 | ProfileData data{}; | 295 | ProfileData data{}; |
| 296 | if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) { | 296 | if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) { |
| @@ -300,21 +300,21 @@ protected: | |||
| 300 | rb.PushRaw(profile_base); | 300 | rb.PushRaw(profile_base); |
| 301 | } else { | 301 | } else { |
| 302 | LOG_ERROR(Service_ACC, "Failed to get profile base and data for user=0x{}", | 302 | LOG_ERROR(Service_ACC, "Failed to get profile base and data for user=0x{}", |
| 303 | user_id.Format()); | 303 | user_id.RawString()); |
| 304 | IPC::ResponseBuilder rb{ctx, 2}; | 304 | IPC::ResponseBuilder rb{ctx, 2}; |
| 305 | rb.Push(ResultUnknown); // TODO(ogniK): Get actual error code | 305 | rb.Push(ResultUnknown); // TODO(ogniK): Get actual error code |
| 306 | } | 306 | } |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | void GetBase(Kernel::HLERequestContext& ctx) { | 309 | void GetBase(Kernel::HLERequestContext& ctx) { |
| 310 | LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.Format()); | 310 | LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); |
| 311 | ProfileBase profile_base{}; | 311 | ProfileBase profile_base{}; |
| 312 | if (profile_manager.GetProfileBase(user_id, profile_base)) { | 312 | if (profile_manager.GetProfileBase(user_id, profile_base)) { |
| 313 | IPC::ResponseBuilder rb{ctx, 16}; | 313 | IPC::ResponseBuilder rb{ctx, 16}; |
| 314 | rb.Push(ResultSuccess); | 314 | rb.Push(ResultSuccess); |
| 315 | rb.PushRaw(profile_base); | 315 | rb.PushRaw(profile_base); |
| 316 | } else { | 316 | } else { |
| 317 | LOG_ERROR(Service_ACC, "Failed to get profile base for user=0x{}", user_id.Format()); | 317 | LOG_ERROR(Service_ACC, "Failed to get profile base for user=0x{}", user_id.RawString()); |
| 318 | IPC::ResponseBuilder rb{ctx, 2}; | 318 | IPC::ResponseBuilder rb{ctx, 2}; |
| 319 | rb.Push(ResultUnknown); // TODO(ogniK): Get actual error code | 319 | rb.Push(ResultUnknown); // TODO(ogniK): Get actual error code |
| 320 | } | 320 | } |
| @@ -373,7 +373,7 @@ protected: | |||
| 373 | LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", | 373 | LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", |
| 374 | Common::StringFromFixedZeroTerminatedBuffer( | 374 | Common::StringFromFixedZeroTerminatedBuffer( |
| 375 | reinterpret_cast<const char*>(base.username.data()), base.username.size()), | 375 | reinterpret_cast<const char*>(base.username.data()), base.username.size()), |
| 376 | base.timestamp, base.user_uuid.Format()); | 376 | base.timestamp, base.user_uuid.RawString()); |
| 377 | 377 | ||
| 378 | if (user_data.size() < sizeof(ProfileData)) { | 378 | if (user_data.size() < sizeof(ProfileData)) { |
| 379 | LOG_ERROR(Service_ACC, "ProfileData buffer too small!"); | 379 | LOG_ERROR(Service_ACC, "ProfileData buffer too small!"); |
| @@ -406,7 +406,7 @@ protected: | |||
| 406 | LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", | 406 | LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", |
| 407 | Common::StringFromFixedZeroTerminatedBuffer( | 407 | Common::StringFromFixedZeroTerminatedBuffer( |
| 408 | reinterpret_cast<const char*>(base.username.data()), base.username.size()), | 408 | reinterpret_cast<const char*>(base.username.data()), base.username.size()), |
| 409 | base.timestamp, base.user_uuid.Format()); | 409 | base.timestamp, base.user_uuid.RawString()); |
| 410 | 410 | ||
| 411 | if (user_data.size() < sizeof(ProfileData)) { | 411 | if (user_data.size() < sizeof(ProfileData)) { |
| 412 | LOG_ERROR(Service_ACC, "ProfileData buffer too small!"); | 412 | LOG_ERROR(Service_ACC, "ProfileData buffer too small!"); |
| @@ -435,7 +435,7 @@ protected: | |||
| 435 | } | 435 | } |
| 436 | 436 | ||
| 437 | ProfileManager& profile_manager; | 437 | ProfileManager& profile_manager; |
| 438 | Common::UUID user_id{Common::INVALID_UUID}; ///< The user id this profile refers to. | 438 | Common::UUID user_id{}; ///< The user id this profile refers to. |
| 439 | }; | 439 | }; |
| 440 | 440 | ||
| 441 | class IProfile final : public IProfileCommon { | 441 | class IProfile final : public IProfileCommon { |
| @@ -547,7 +547,7 @@ private: | |||
| 547 | 547 | ||
| 548 | IPC::ResponseBuilder rb{ctx, 4}; | 548 | IPC::ResponseBuilder rb{ctx, 4}; |
| 549 | rb.Push(ResultSuccess); | 549 | rb.Push(ResultSuccess); |
| 550 | rb.PushRaw<u64>(user_id.GetNintendoID()); | 550 | rb.PushRaw<u64>(user_id.Hash()); |
| 551 | } | 551 | } |
| 552 | 552 | ||
| 553 | void EnsureIdTokenCacheAsync(Kernel::HLERequestContext& ctx) { | 553 | void EnsureIdTokenCacheAsync(Kernel::HLERequestContext& ctx) { |
| @@ -577,7 +577,7 @@ private: | |||
| 577 | 577 | ||
| 578 | IPC::ResponseBuilder rb{ctx, 4}; | 578 | IPC::ResponseBuilder rb{ctx, 4}; |
| 579 | rb.Push(ResultSuccess); | 579 | rb.Push(ResultSuccess); |
| 580 | rb.PushRaw<u64>(user_id.GetNintendoID()); | 580 | rb.PushRaw<u64>(user_id.Hash()); |
| 581 | } | 581 | } |
| 582 | 582 | ||
| 583 | void StoreOpenContext(Kernel::HLERequestContext& ctx) { | 583 | void StoreOpenContext(Kernel::HLERequestContext& ctx) { |
| @@ -587,7 +587,7 @@ private: | |||
| 587 | } | 587 | } |
| 588 | 588 | ||
| 589 | std::shared_ptr<EnsureTokenIdCacheAsyncInterface> ensure_token_id{}; | 589 | std::shared_ptr<EnsureTokenIdCacheAsyncInterface> ensure_token_id{}; |
| 590 | Common::UUID user_id{Common::INVALID_UUID}; | 590 | Common::UUID user_id{}; |
| 591 | }; | 591 | }; |
| 592 | 592 | ||
| 593 | // 6.0.0+ | 593 | // 6.0.0+ |
| @@ -687,7 +687,7 @@ void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) { | |||
| 687 | void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { | 687 | void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { |
| 688 | IPC::RequestParser rp{ctx}; | 688 | IPC::RequestParser rp{ctx}; |
| 689 | Common::UUID user_id = rp.PopRaw<Common::UUID>(); | 689 | Common::UUID user_id = rp.PopRaw<Common::UUID>(); |
| 690 | LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.Format()); | 690 | LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); |
| 691 | 691 | ||
| 692 | IPC::ResponseBuilder rb{ctx, 3}; | 692 | IPC::ResponseBuilder rb{ctx, 3}; |
| 693 | rb.Push(ResultSuccess); | 693 | rb.Push(ResultSuccess); |
| @@ -718,7 +718,7 @@ void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) { | |||
| 718 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { | 718 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { |
| 719 | IPC::RequestParser rp{ctx}; | 719 | IPC::RequestParser rp{ctx}; |
| 720 | Common::UUID user_id = rp.PopRaw<Common::UUID>(); | 720 | Common::UUID user_id = rp.PopRaw<Common::UUID>(); |
| 721 | LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.Format()); | 721 | LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); |
| 722 | 722 | ||
| 723 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 723 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 724 | rb.Push(ResultSuccess); | 724 | rb.Push(ResultSuccess); |
| @@ -833,7 +833,7 @@ void Module::Interface::GetProfileEditor(Kernel::HLERequestContext& ctx) { | |||
| 833 | IPC::RequestParser rp{ctx}; | 833 | IPC::RequestParser rp{ctx}; |
| 834 | Common::UUID user_id = rp.PopRaw<Common::UUID>(); | 834 | Common::UUID user_id = rp.PopRaw<Common::UUID>(); |
| 835 | 835 | ||
| 836 | LOG_DEBUG(Service_ACC, "called, user_id=0x{}", user_id.Format()); | 836 | LOG_DEBUG(Service_ACC, "called, user_id=0x{}", user_id.RawString()); |
| 837 | 837 | ||
| 838 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 838 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 839 | rb.Push(ResultSuccess); | 839 | rb.Push(ResultSuccess); |
| @@ -875,7 +875,7 @@ void Module::Interface::StoreSaveDataThumbnailApplication(Kernel::HLERequestCont | |||
| 875 | IPC::RequestParser rp{ctx}; | 875 | IPC::RequestParser rp{ctx}; |
| 876 | const auto uuid = rp.PopRaw<Common::UUID>(); | 876 | const auto uuid = rp.PopRaw<Common::UUID>(); |
| 877 | 877 | ||
| 878 | LOG_WARNING(Service_ACC, "(STUBBED) called, uuid=0x{}", uuid.Format()); | 878 | LOG_WARNING(Service_ACC, "(STUBBED) called, uuid=0x{}", uuid.RawString()); |
| 879 | 879 | ||
| 880 | // TODO(ogniK): Check if application ID is zero on acc initialize. As we don't have a reliable | 880 | // TODO(ogniK): Check if application ID is zero on acc initialize. As we don't have a reliable |
| 881 | // way of confirming things like the TID, we're going to assume a non zero value for the time | 881 | // way of confirming things like the TID, we're going to assume a non zero value for the time |
| @@ -889,7 +889,7 @@ void Module::Interface::StoreSaveDataThumbnailSystem(Kernel::HLERequestContext& | |||
| 889 | const auto uuid = rp.PopRaw<Common::UUID>(); | 889 | const auto uuid = rp.PopRaw<Common::UUID>(); |
| 890 | const auto tid = rp.Pop<u64_le>(); | 890 | const auto tid = rp.Pop<u64_le>(); |
| 891 | 891 | ||
| 892 | LOG_WARNING(Service_ACC, "(STUBBED) called, uuid=0x{}, tid={:016X}", uuid.Format(), tid); | 892 | LOG_WARNING(Service_ACC, "(STUBBED) called, uuid=0x{}, tid={:016X}", uuid.RawString(), tid); |
| 893 | StoreSaveDataThumbnail(ctx, uuid, tid); | 893 | StoreSaveDataThumbnail(ctx, uuid, tid); |
| 894 | } | 894 | } |
| 895 | 895 | ||
| @@ -903,7 +903,7 @@ void Module::Interface::StoreSaveDataThumbnail(Kernel::HLERequestContext& ctx, | |||
| 903 | return; | 903 | return; |
| 904 | } | 904 | } |
| 905 | 905 | ||
| 906 | if (!uuid) { | 906 | if (uuid.IsInvalid()) { |
| 907 | LOG_ERROR(Service_ACC, "User ID is not valid!"); | 907 | LOG_ERROR(Service_ACC, "User ID is not valid!"); |
| 908 | rb.Push(ERR_INVALID_USER_ID); | 908 | rb.Push(ERR_INVALID_USER_ID); |
| 909 | return; | 909 | return; |
| @@ -927,20 +927,20 @@ void Module::Interface::TrySelectUserWithoutInteraction(Kernel::HLERequestContex | |||
| 927 | IPC::ResponseBuilder rb{ctx, 6}; | 927 | IPC::ResponseBuilder rb{ctx, 6}; |
| 928 | if (profile_manager->GetUserCount() != 1) { | 928 | if (profile_manager->GetUserCount() != 1) { |
| 929 | rb.Push(ResultSuccess); | 929 | rb.Push(ResultSuccess); |
| 930 | rb.PushRaw<u128>(Common::INVALID_UUID); | 930 | rb.PushRaw(Common::InvalidUUID); |
| 931 | return; | 931 | return; |
| 932 | } | 932 | } |
| 933 | 933 | ||
| 934 | const auto user_list = profile_manager->GetAllUsers(); | 934 | const auto user_list = profile_manager->GetAllUsers(); |
| 935 | if (std::ranges::all_of(user_list, [](const auto& user) { return user.IsInvalid(); })) { | 935 | if (std::ranges::all_of(user_list, [](const auto& user) { return user.IsInvalid(); })) { |
| 936 | rb.Push(ResultUnknown); // TODO(ogniK): Find the correct error code | 936 | rb.Push(ResultUnknown); // TODO(ogniK): Find the correct error code |
| 937 | rb.PushRaw<u128>(Common::INVALID_UUID); | 937 | rb.PushRaw(Common::InvalidUUID); |
| 938 | return; | 938 | return; |
| 939 | } | 939 | } |
| 940 | 940 | ||
| 941 | // Select the first user we have | 941 | // Select the first user we have |
| 942 | rb.Push(ResultSuccess); | 942 | rb.Push(ResultSuccess); |
| 943 | rb.PushRaw<u128>(profile_manager->GetUser(0)->uuid); | 943 | rb.PushRaw(profile_manager->GetUser(0)->uuid); |
| 944 | } | 944 | } |
| 945 | 945 | ||
| 946 | Module::Interface::Interface(std::shared_ptr<Module> module_, | 946 | Module::Interface::Interface(std::shared_ptr<Module> module_, |
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 568303ced..fba847142 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -19,8 +19,8 @@ namespace FS = Common::FS; | |||
| 19 | using Common::UUID; | 19 | using Common::UUID; |
| 20 | 20 | ||
| 21 | struct UserRaw { | 21 | struct UserRaw { |
| 22 | UUID uuid{Common::INVALID_UUID}; | 22 | UUID uuid{}; |
| 23 | UUID uuid2{Common::INVALID_UUID}; | 23 | UUID uuid2{}; |
| 24 | u64 timestamp{}; | 24 | u64 timestamp{}; |
| 25 | ProfileUsername username{}; | 25 | ProfileUsername username{}; |
| 26 | ProfileData extra_data{}; | 26 | ProfileData extra_data{}; |
| @@ -45,7 +45,7 @@ ProfileManager::ProfileManager() { | |||
| 45 | 45 | ||
| 46 | // Create an user if none are present | 46 | // Create an user if none are present |
| 47 | if (user_count == 0) { | 47 | if (user_count == 0) { |
| 48 | CreateNewUser(UUID::Generate(), "yuzu"); | 48 | CreateNewUser(UUID::MakeRandom(), "yuzu"); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | auto current = | 51 | auto current = |
| @@ -101,7 +101,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& usern | |||
| 101 | if (user_count == MAX_USERS) { | 101 | if (user_count == MAX_USERS) { |
| 102 | return ERROR_TOO_MANY_USERS; | 102 | return ERROR_TOO_MANY_USERS; |
| 103 | } | 103 | } |
| 104 | if (!uuid) { | 104 | if (uuid.IsInvalid()) { |
| 105 | return ERROR_ARGUMENT_IS_NULL; | 105 | return ERROR_ARGUMENT_IS_NULL; |
| 106 | } | 106 | } |
| 107 | if (username[0] == 0x0) { | 107 | if (username[0] == 0x0) { |
| @@ -145,7 +145,7 @@ std::optional<UUID> ProfileManager::GetUser(std::size_t index) const { | |||
| 145 | 145 | ||
| 146 | /// Returns a users profile index based on their user id. | 146 | /// Returns a users profile index based on their user id. |
| 147 | std::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { | 147 | std::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { |
| 148 | if (!uuid) { | 148 | if (uuid.IsInvalid()) { |
| 149 | return std::nullopt; | 149 | return std::nullopt; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| @@ -250,9 +250,10 @@ UserIDArray ProfileManager::GetOpenUsers() const { | |||
| 250 | std::ranges::transform(profiles, output.begin(), [](const ProfileInfo& p) { | 250 | std::ranges::transform(profiles, output.begin(), [](const ProfileInfo& p) { |
| 251 | if (p.is_open) | 251 | if (p.is_open) |
| 252 | return p.user_uuid; | 252 | return p.user_uuid; |
| 253 | return UUID{Common::INVALID_UUID}; | 253 | return Common::InvalidUUID; |
| 254 | }); | 254 | }); |
| 255 | std::stable_partition(output.begin(), output.end(), [](const UUID& uuid) { return uuid; }); | 255 | std::stable_partition(output.begin(), output.end(), |
| 256 | [](const UUID& uuid) { return uuid.IsValid(); }); | ||
| 256 | return output; | 257 | return output; |
| 257 | } | 258 | } |
| 258 | 259 | ||
| @@ -299,7 +300,7 @@ bool ProfileManager::RemoveUser(UUID uuid) { | |||
| 299 | 300 | ||
| 300 | profiles[*index] = ProfileInfo{}; | 301 | profiles[*index] = ProfileInfo{}; |
| 301 | std::stable_partition(profiles.begin(), profiles.end(), | 302 | std::stable_partition(profiles.begin(), profiles.end(), |
| 302 | [](const ProfileInfo& profile) { return profile.user_uuid; }); | 303 | [](const ProfileInfo& profile) { return profile.user_uuid.IsValid(); }); |
| 303 | return true; | 304 | return true; |
| 304 | } | 305 | } |
| 305 | 306 | ||
| @@ -361,7 +362,7 @@ void ProfileManager::ParseUserSaveFile() { | |||
| 361 | } | 362 | } |
| 362 | 363 | ||
| 363 | std::stable_partition(profiles.begin(), profiles.end(), | 364 | std::stable_partition(profiles.begin(), profiles.end(), |
| 364 | [](const ProfileInfo& profile) { return profile.user_uuid; }); | 365 | [](const ProfileInfo& profile) { return profile.user_uuid.IsValid(); }); |
| 365 | } | 366 | } |
| 366 | 367 | ||
| 367 | void ProfileManager::WriteUserSaveFile() { | 368 | void ProfileManager::WriteUserSaveFile() { |
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index 71b9d5518..17347f7ef 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h | |||
| @@ -35,7 +35,7 @@ static_assert(sizeof(ProfileData) == 0x80, "ProfileData structure has incorrect | |||
| 35 | /// This holds general information about a users profile. This is where we store all the information | 35 | /// This holds general information about a users profile. This is where we store all the information |
| 36 | /// based on a specific user | 36 | /// based on a specific user |
| 37 | struct ProfileInfo { | 37 | struct ProfileInfo { |
| 38 | Common::UUID user_uuid{Common::INVALID_UUID}; | 38 | Common::UUID user_uuid{}; |
| 39 | ProfileUsername username{}; | 39 | ProfileUsername username{}; |
| 40 | u64 creation_time{}; | 40 | u64 creation_time{}; |
| 41 | ProfileData data{}; // TODO(ognik): Work out what this is | 41 | ProfileData data{}; // TODO(ognik): Work out what this is |
| @@ -49,7 +49,7 @@ struct ProfileBase { | |||
| 49 | 49 | ||
| 50 | // Zero out all the fields to make the profile slot considered "Empty" | 50 | // Zero out all the fields to make the profile slot considered "Empty" |
| 51 | void Invalidate() { | 51 | void Invalidate() { |
| 52 | user_uuid.Invalidate(); | 52 | user_uuid = {}; |
| 53 | timestamp = 0; | 53 | timestamp = 0; |
| 54 | username.fill(0); | 54 | username.fill(0); |
| 55 | } | 55 | } |
| @@ -103,7 +103,7 @@ private: | |||
| 103 | 103 | ||
| 104 | std::array<ProfileInfo, MAX_USERS> profiles{}; | 104 | std::array<ProfileInfo, MAX_USERS> profiles{}; |
| 105 | std::size_t user_count{}; | 105 | std::size_t user_count{}; |
| 106 | Common::UUID last_opened_user{Common::INVALID_UUID}; | 106 | Common::UUID last_opened_user{}; |
| 107 | }; | 107 | }; |
| 108 | 108 | ||
| 109 | }; // namespace Service::Account | 109 | }; // namespace Service::Account |
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index e60661fe1..773dc9f29 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp | |||
| @@ -55,7 +55,7 @@ constexpr u32 LAUNCH_PARAMETER_ACCOUNT_PRESELECTED_USER_MAGIC = 0xC79497CA; | |||
| 55 | struct LaunchParameterAccountPreselectedUser { | 55 | struct LaunchParameterAccountPreselectedUser { |
| 56 | u32_le magic; | 56 | u32_le magic; |
| 57 | u32_le is_account_selected; | 57 | u32_le is_account_selected; |
| 58 | u128 current_user; | 58 | Common::UUID current_user; |
| 59 | INSERT_PADDING_BYTES(0x70); | 59 | INSERT_PADDING_BYTES(0x70); |
| 60 | }; | 60 | }; |
| 61 | static_assert(sizeof(LaunchParameterAccountPreselectedUser) == 0x88); | 61 | static_assert(sizeof(LaunchParameterAccountPreselectedUser) == 0x88); |
| @@ -1453,8 +1453,8 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { | |||
| 1453 | 1453 | ||
| 1454 | Account::ProfileManager profile_manager{}; | 1454 | Account::ProfileManager profile_manager{}; |
| 1455 | const auto uuid = profile_manager.GetUser(static_cast<s32>(Settings::values.current_user)); | 1455 | const auto uuid = profile_manager.GetUser(static_cast<s32>(Settings::values.current_user)); |
| 1456 | ASSERT(uuid); | 1456 | ASSERT(uuid.has_value() && uuid->IsValid()); |
| 1457 | params.current_user = uuid->uuid; | 1457 | params.current_user = *uuid; |
| 1458 | 1458 | ||
| 1459 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 1459 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 1460 | 1460 | ||
diff --git a/src/core/hle/service/am/applets/applet_profile_select.cpp b/src/core/hle/service/am/applets/applet_profile_select.cpp index a6e891944..82500e121 100644 --- a/src/core/hle/service/am/applets/applet_profile_select.cpp +++ b/src/core/hle/service/am/applets/applet_profile_select.cpp | |||
| @@ -62,11 +62,11 @@ void ProfileSelect::SelectionComplete(std::optional<Common::UUID> uuid) { | |||
| 62 | 62 | ||
| 63 | if (uuid.has_value() && uuid->IsValid()) { | 63 | if (uuid.has_value() && uuid->IsValid()) { |
| 64 | output.result = 0; | 64 | output.result = 0; |
| 65 | output.uuid_selected = uuid->uuid; | 65 | output.uuid_selected = *uuid; |
| 66 | } else { | 66 | } else { |
| 67 | status = ERR_USER_CANCELLED_SELECTION; | 67 | status = ERR_USER_CANCELLED_SELECTION; |
| 68 | output.result = ERR_USER_CANCELLED_SELECTION.raw; | 68 | output.result = ERR_USER_CANCELLED_SELECTION.raw; |
| 69 | output.uuid_selected = Common::INVALID_UUID; | 69 | output.uuid_selected = Common::InvalidUUID; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | final_data = std::vector<u8>(sizeof(UserSelectionOutput)); | 72 | final_data = std::vector<u8>(sizeof(UserSelectionOutput)); |
diff --git a/src/core/hle/service/am/applets/applet_profile_select.h b/src/core/hle/service/am/applets/applet_profile_select.h index 8fb76e6c4..852e1e0c0 100644 --- a/src/core/hle/service/am/applets/applet_profile_select.h +++ b/src/core/hle/service/am/applets/applet_profile_select.h | |||
| @@ -27,7 +27,7 @@ static_assert(sizeof(UserSelectionConfig) == 0xA0, "UserSelectionConfig has inco | |||
| 27 | 27 | ||
| 28 | struct UserSelectionOutput { | 28 | struct UserSelectionOutput { |
| 29 | u64 result; | 29 | u64 result; |
| 30 | u128 uuid_selected; | 30 | Common::UUID uuid_selected; |
| 31 | }; | 31 | }; |
| 32 | static_assert(sizeof(UserSelectionOutput) == 0x18, "UserSelectionOutput has incorrect size."); | 32 | static_assert(sizeof(UserSelectionOutput) == 0x18, "UserSelectionOutput has incorrect size."); |
| 33 | 33 | ||
diff --git a/src/core/hle/service/friend/friend.cpp b/src/core/hle/service/friend/friend.cpp index 9f9cea1e0..79cd3acbb 100644 --- a/src/core/hle/service/friend/friend.cpp +++ b/src/core/hle/service/friend/friend.cpp | |||
| @@ -173,7 +173,7 @@ private: | |||
| 173 | const auto uuid = rp.PopRaw<Common::UUID>(); | 173 | const auto uuid = rp.PopRaw<Common::UUID>(); |
| 174 | 174 | ||
| 175 | LOG_WARNING(Service_Friend, "(STUBBED) called, local_play={}, uuid=0x{}", local_play, | 175 | LOG_WARNING(Service_Friend, "(STUBBED) called, local_play={}, uuid=0x{}", local_play, |
| 176 | uuid.Format()); | 176 | uuid.RawString()); |
| 177 | 177 | ||
| 178 | IPC::ResponseBuilder rb{ctx, 2}; | 178 | IPC::ResponseBuilder rb{ctx, 2}; |
| 179 | rb.Push(ResultSuccess); | 179 | rb.Push(ResultSuccess); |
| @@ -186,7 +186,7 @@ private: | |||
| 186 | [[maybe_unused]] const auto filter = rp.PopRaw<SizedFriendFilter>(); | 186 | [[maybe_unused]] const auto filter = rp.PopRaw<SizedFriendFilter>(); |
| 187 | const auto pid = rp.Pop<u64>(); | 187 | const auto pid = rp.Pop<u64>(); |
| 188 | LOG_WARNING(Service_Friend, "(STUBBED) called, offset={}, uuid=0x{}, pid={}", friend_offset, | 188 | LOG_WARNING(Service_Friend, "(STUBBED) called, offset={}, uuid=0x{}, pid={}", friend_offset, |
| 189 | uuid.Format(), pid); | 189 | uuid.RawString(), pid); |
| 190 | 190 | ||
| 191 | IPC::ResponseBuilder rb{ctx, 3}; | 191 | IPC::ResponseBuilder rb{ctx, 3}; |
| 192 | rb.Push(ResultSuccess); | 192 | rb.Push(ResultSuccess); |
| @@ -312,7 +312,7 @@ void Module::Interface::CreateNotificationService(Kernel::HLERequestContext& ctx | |||
| 312 | IPC::RequestParser rp{ctx}; | 312 | IPC::RequestParser rp{ctx}; |
| 313 | auto uuid = rp.PopRaw<Common::UUID>(); | 313 | auto uuid = rp.PopRaw<Common::UUID>(); |
| 314 | 314 | ||
| 315 | LOG_DEBUG(Service_Friend, "called, uuid=0x{}", uuid.Format()); | 315 | LOG_DEBUG(Service_Friend, "called, uuid=0x{}", uuid.RawString()); |
| 316 | 316 | ||
| 317 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 317 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 318 | rb.Push(ResultSuccess); | 318 | rb.Push(ResultSuccess); |
diff --git a/src/core/hle/service/mii/mii_manager.cpp b/src/core/hle/service/mii/mii_manager.cpp index ca4ed35bb..0a57c3cde 100644 --- a/src/core/hle/service/mii/mii_manager.cpp +++ b/src/core/hle/service/mii/mii_manager.cpp | |||
| @@ -118,16 +118,6 @@ u16 GenerateCrc16(const void* data, std::size_t size) { | |||
| 118 | return Common::swap16(static_cast<u16>(crc)); | 118 | return Common::swap16(static_cast<u16>(crc)); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | Common::UUID GenerateValidUUID() { | ||
| 122 | auto uuid{Common::UUID::Generate()}; | ||
| 123 | |||
| 124 | // Bit 7 must be set, and bit 6 unset for the UUID to be valid | ||
| 125 | uuid.uuid[1] &= 0xFFFFFFFFFFFFFF3FULL; | ||
| 126 | uuid.uuid[1] |= 0x0000000000000080ULL; | ||
| 127 | |||
| 128 | return uuid; | ||
| 129 | } | ||
| 130 | |||
| 131 | template <typename T> | 121 | template <typename T> |
| 132 | T GetRandomValue(T min, T max) { | 122 | T GetRandomValue(T min, T max) { |
| 133 | std::random_device device; | 123 | std::random_device device; |
| @@ -383,7 +373,7 @@ MiiStoreData::MiiStoreData() = default; | |||
| 383 | MiiStoreData::MiiStoreData(const MiiStoreData::Name& name, const MiiStoreBitFields& bit_fields, | 373 | MiiStoreData::MiiStoreData(const MiiStoreData::Name& name, const MiiStoreBitFields& bit_fields, |
| 384 | const Common::UUID& user_id) { | 374 | const Common::UUID& user_id) { |
| 385 | data.name = name; | 375 | data.name = name; |
| 386 | data.uuid = GenerateValidUUID(); | 376 | data.uuid = Common::UUID::MakeRandomRFC4122V4(); |
| 387 | 377 | ||
| 388 | std::memcpy(data.data.data(), &bit_fields, sizeof(MiiStoreBitFields)); | 378 | std::memcpy(data.data.data(), &bit_fields, sizeof(MiiStoreBitFields)); |
| 389 | data_crc = GenerateCrc16(data.data.data(), sizeof(data)); | 379 | data_crc = GenerateCrc16(data.data.data(), sizeof(data)); |
diff --git a/src/core/hle/service/mii/mii_manager.h b/src/core/hle/service/mii/mii_manager.h index 8e048fc56..6999d15b1 100644 --- a/src/core/hle/service/mii/mii_manager.h +++ b/src/core/hle/service/mii/mii_manager.h | |||
| @@ -202,7 +202,7 @@ struct MiiStoreData { | |||
| 202 | static_assert(sizeof(MiiStoreBitFields) == sizeof(data), "data field has incorrect size."); | 202 | static_assert(sizeof(MiiStoreBitFields) == sizeof(data), "data field has incorrect size."); |
| 203 | 203 | ||
| 204 | Name name{}; | 204 | Name name{}; |
| 205 | Common::UUID uuid{Common::INVALID_UUID}; | 205 | Common::UUID uuid{}; |
| 206 | } data; | 206 | } data; |
| 207 | 207 | ||
| 208 | u16 data_crc{}; | 208 | u16 data_crc{}; |
| @@ -326,7 +326,7 @@ public: | |||
| 326 | ResultCode GetIndex(const MiiInfo& info, u32& index); | 326 | ResultCode GetIndex(const MiiInfo& info, u32& index); |
| 327 | 327 | ||
| 328 | private: | 328 | private: |
| 329 | const Common::UUID user_id{Common::INVALID_UUID}; | 329 | const Common::UUID user_id{}; |
| 330 | u64 update_counter{}; | 330 | u64 update_counter{}; |
| 331 | }; | 331 | }; |
| 332 | 332 | ||
diff --git a/src/core/hle/service/ns/pdm_qry.cpp b/src/core/hle/service/ns/pdm_qry.cpp index e2fab5c3f..36ce46353 100644 --- a/src/core/hle/service/ns/pdm_qry.cpp +++ b/src/core/hle/service/ns/pdm_qry.cpp | |||
| @@ -59,7 +59,7 @@ void PDM_QRY::QueryPlayStatisticsByApplicationIdAndUserAccountId(Kernel::HLERequ | |||
| 59 | 59 | ||
| 60 | LOG_WARNING(Service_NS, | 60 | LOG_WARNING(Service_NS, |
| 61 | "(STUBBED) called. unknown={}. application_id=0x{:016X}, user_account_uid=0x{}", | 61 | "(STUBBED) called. unknown={}. application_id=0x{:016X}, user_account_uid=0x{}", |
| 62 | unknown, application_id, user_account_uid.Format()); | 62 | unknown, application_id, user_account_uid.RawString()); |
| 63 | 63 | ||
| 64 | IPC::ResponseBuilder rb{ctx, 12}; | 64 | IPC::ResponseBuilder rb{ctx, 12}; |
| 65 | rb.Push(ResultSuccess); | 65 | rb.Push(ResultSuccess); |
diff --git a/src/core/hle/service/time/clock_types.h b/src/core/hle/service/time/clock_types.h index 392e16863..d0cacb80c 100644 --- a/src/core/hle/service/time/clock_types.h +++ b/src/core/hle/service/time/clock_types.h | |||
| @@ -36,7 +36,7 @@ struct SteadyClockTimePoint { | |||
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | static SteadyClockTimePoint GetRandom() { | 38 | static SteadyClockTimePoint GetRandom() { |
| 39 | return {0, Common::UUID::Generate()}; | 39 | return {0, Common::UUID::MakeRandom()}; |
| 40 | } | 40 | } |
| 41 | }; | 41 | }; |
| 42 | static_assert(sizeof(SteadyClockTimePoint) == 0x18, "SteadyClockTimePoint is incorrect size"); | 42 | static_assert(sizeof(SteadyClockTimePoint) == 0x18, "SteadyClockTimePoint is incorrect size"); |
diff --git a/src/core/hle/service/time/steady_clock_core.h b/src/core/hle/service/time/steady_clock_core.h index d80a2385f..5ee2c0e0a 100644 --- a/src/core/hle/service/time/steady_clock_core.h +++ b/src/core/hle/service/time/steady_clock_core.h | |||
| @@ -49,7 +49,7 @@ public: | |||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | private: | 51 | private: |
| 52 | Common::UUID clock_source_id{Common::UUID::Generate()}; | 52 | Common::UUID clock_source_id{Common::UUID::MakeRandom()}; |
| 53 | bool is_initialized{}; | 53 | bool is_initialized{}; |
| 54 | }; | 54 | }; |
| 55 | 55 | ||
diff --git a/src/core/hle/service/time/time_manager.cpp b/src/core/hle/service/time/time_manager.cpp index c1e4e6cce..00f1ae8cf 100644 --- a/src/core/hle/service/time/time_manager.cpp +++ b/src/core/hle/service/time/time_manager.cpp | |||
| @@ -45,7 +45,7 @@ struct TimeManager::Impl final { | |||
| 45 | time_zone_content_manager{system} { | 45 | time_zone_content_manager{system} { |
| 46 | 46 | ||
| 47 | const auto system_time{Clock::TimeSpanType::FromSeconds(GetExternalRtcValue())}; | 47 | const auto system_time{Clock::TimeSpanType::FromSeconds(GetExternalRtcValue())}; |
| 48 | SetupStandardSteadyClock(system, Common::UUID::Generate(), system_time, {}, {}); | 48 | SetupStandardSteadyClock(system, Common::UUID::MakeRandom(), system_time, {}, {}); |
| 49 | SetupStandardLocalSystemClock(system, {}, system_time.ToSeconds()); | 49 | SetupStandardLocalSystemClock(system, {}, system_time.ToSeconds()); |
| 50 | 50 | ||
| 51 | Clock::SystemClockContext clock_context{}; | 51 | Clock::SystemClockContext clock_context{}; |
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp index 7ab4540a8..155caae42 100644 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp | |||
| @@ -248,7 +248,7 @@ bool GCAdapter::Setup() { | |||
| 248 | std::size_t port = 0; | 248 | std::size_t port = 0; |
| 249 | for (GCController& pad : pads) { | 249 | for (GCController& pad : pads) { |
| 250 | pad.identifier = { | 250 | pad.identifier = { |
| 251 | .guid = Common::UUID{Common::INVALID_UUID}, | 251 | .guid = Common::UUID{}, |
| 252 | .port = port++, | 252 | .port = port++, |
| 253 | .pad = 0, | 253 | .pad = 0, |
| 254 | }; | 254 | }; |
diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp index 4c1e5bbec..59e3d9cc0 100644 --- a/src/input_common/drivers/keyboard.cpp +++ b/src/input_common/drivers/keyboard.cpp | |||
| @@ -9,17 +9,17 @@ | |||
| 9 | namespace InputCommon { | 9 | namespace InputCommon { |
| 10 | 10 | ||
| 11 | constexpr PadIdentifier key_identifier = { | 11 | constexpr PadIdentifier key_identifier = { |
| 12 | .guid = Common::UUID{Common::INVALID_UUID}, | 12 | .guid = Common::UUID{}, |
| 13 | .port = 0, | 13 | .port = 0, |
| 14 | .pad = 0, | 14 | .pad = 0, |
| 15 | }; | 15 | }; |
| 16 | constexpr PadIdentifier keyboard_key_identifier = { | 16 | constexpr PadIdentifier keyboard_key_identifier = { |
| 17 | .guid = Common::UUID{Common::INVALID_UUID}, | 17 | .guid = Common::UUID{}, |
| 18 | .port = 1, | 18 | .port = 1, |
| 19 | .pad = 0, | 19 | .pad = 0, |
| 20 | }; | 20 | }; |
| 21 | constexpr PadIdentifier keyboard_modifier_identifier = { | 21 | constexpr PadIdentifier keyboard_modifier_identifier = { |
| 22 | .guid = Common::UUID{Common::INVALID_UUID}, | 22 | .guid = Common::UUID{}, |
| 23 | .port = 1, | 23 | .port = 1, |
| 24 | .pad = 1, | 24 | .pad = 1, |
| 25 | }; | 25 | }; |
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp index d8ae7f0c1..3c9a4e747 100644 --- a/src/input_common/drivers/mouse.cpp +++ b/src/input_common/drivers/mouse.cpp | |||
| @@ -20,7 +20,7 @@ constexpr int motion_wheel_y = 4; | |||
| 20 | constexpr int touch_axis_x = 10; | 20 | constexpr int touch_axis_x = 10; |
| 21 | constexpr int touch_axis_y = 11; | 21 | constexpr int touch_axis_y = 11; |
| 22 | constexpr PadIdentifier identifier = { | 22 | constexpr PadIdentifier identifier = { |
| 23 | .guid = Common::UUID{Common::INVALID_UUID}, | 23 | .guid = Common::UUID{}, |
| 24 | .port = 0, | 24 | .port = 0, |
| 25 | .pad = 0, | 25 | .pad = 0, |
| 26 | }; | 26 | }; |
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index f54b91f9d..5cf1987ad 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp | |||
| @@ -502,7 +502,7 @@ std::vector<Common::ParamPackage> SDLDriver::GetInputDevices() const { | |||
| 502 | Common::Input::VibrationError SDLDriver::SetRumble( | 502 | Common::Input::VibrationError SDLDriver::SetRumble( |
| 503 | const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) { | 503 | const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) { |
| 504 | const auto joystick = | 504 | const auto joystick = |
| 505 | GetSDLJoystickByGUID(identifier.guid.Format(), static_cast<int>(identifier.port)); | 505 | GetSDLJoystickByGUID(identifier.guid.RawString(), static_cast<int>(identifier.port)); |
| 506 | const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { | 506 | const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { |
| 507 | return (amplitude + std::pow(amplitude, factor)) * 0.5f * 0xFFFF; | 507 | return (amplitude + std::pow(amplitude, factor)) * 0.5f * 0xFFFF; |
| 508 | }; | 508 | }; |
| @@ -599,7 +599,7 @@ Common::ParamPackage SDLDriver::BuildParamPackageForAnalog(PadIdentifier identif | |||
| 599 | Common::ParamPackage params; | 599 | Common::ParamPackage params; |
| 600 | params.Set("engine", GetEngineName()); | 600 | params.Set("engine", GetEngineName()); |
| 601 | params.Set("port", static_cast<int>(identifier.port)); | 601 | params.Set("port", static_cast<int>(identifier.port)); |
| 602 | params.Set("guid", identifier.guid.Format()); | 602 | params.Set("guid", identifier.guid.RawString()); |
| 603 | params.Set("axis_x", axis_x); | 603 | params.Set("axis_x", axis_x); |
| 604 | params.Set("axis_y", axis_y); | 604 | params.Set("axis_y", axis_y); |
| 605 | params.Set("offset_x", offset_x); | 605 | params.Set("offset_x", offset_x); |
diff --git a/src/input_common/drivers/touch_screen.cpp b/src/input_common/drivers/touch_screen.cpp index 880781825..30c727df4 100644 --- a/src/input_common/drivers/touch_screen.cpp +++ b/src/input_common/drivers/touch_screen.cpp | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | namespace InputCommon { | 8 | namespace InputCommon { |
| 9 | 9 | ||
| 10 | constexpr PadIdentifier identifier = { | 10 | constexpr PadIdentifier identifier = { |
| 11 | .guid = Common::UUID{Common::INVALID_UUID}, | 11 | .guid = Common::UUID{}, |
| 12 | .port = 0, | 12 | .port = 0, |
| 13 | .pad = 0, | 13 | .pad = 0, |
| 14 | }; | 14 | }; |
diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index 333173e3d..64162f431 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp | |||
| @@ -353,7 +353,7 @@ PadIdentifier UDPClient::GetPadIdentifier(std::size_t pad_index) const { | |||
| 353 | 353 | ||
| 354 | Common::UUID UDPClient::GetHostUUID(const std::string& host) const { | 354 | Common::UUID UDPClient::GetHostUUID(const std::string& host) const { |
| 355 | const auto ip = boost::asio::ip::make_address_v4(host); | 355 | const auto ip = boost::asio::ip::make_address_v4(host); |
| 356 | const auto hex_host = fmt::format("{:06x}", ip.to_uint()); | 356 | const auto hex_host = fmt::format("00000000-0000-0000-0000-0000{:06x}", ip.to_uint()); |
| 357 | return Common::UUID{hex_host}; | 357 | return Common::UUID{hex_host}; |
| 358 | } | 358 | } |
| 359 | 359 | ||
| @@ -385,7 +385,7 @@ std::vector<Common::ParamPackage> UDPClient::GetInputDevices() const { | |||
| 385 | Common::ParamPackage identifier{}; | 385 | Common::ParamPackage identifier{}; |
| 386 | identifier.Set("engine", GetEngineName()); | 386 | identifier.Set("engine", GetEngineName()); |
| 387 | identifier.Set("display", fmt::format("UDP Controller {}", pad_identifier.pad)); | 387 | identifier.Set("display", fmt::format("UDP Controller {}", pad_identifier.pad)); |
| 388 | identifier.Set("guid", pad_identifier.guid.Format()); | 388 | identifier.Set("guid", pad_identifier.guid.RawString()); |
| 389 | identifier.Set("port", static_cast<int>(pad_identifier.port)); | 389 | identifier.Set("port", static_cast<int>(pad_identifier.port)); |
| 390 | identifier.Set("pad", static_cast<int>(pad_identifier.pad)); | 390 | identifier.Set("pad", static_cast<int>(pad_identifier.pad)); |
| 391 | devices.emplace_back(identifier); | 391 | devices.emplace_back(identifier); |
diff --git a/src/input_common/drivers/udp_client.h b/src/input_common/drivers/udp_client.h index e9c178139..76e32bd04 100644 --- a/src/input_common/drivers/udp_client.h +++ b/src/input_common/drivers/udp_client.h | |||
| @@ -126,7 +126,7 @@ private: | |||
| 126 | struct ClientConnection { | 126 | struct ClientConnection { |
| 127 | ClientConnection(); | 127 | ClientConnection(); |
| 128 | ~ClientConnection(); | 128 | ~ClientConnection(); |
| 129 | Common::UUID uuid{"7F000001"}; | 129 | Common::UUID uuid{"00000000-0000-0000-0000-00007F000001"}; |
| 130 | std::string host{"127.0.0.1"}; | 130 | std::string host{"127.0.0.1"}; |
| 131 | u16 port{26760}; | 131 | u16 port{26760}; |
| 132 | s8 active{-1}; | 132 | s8 active{-1}; |
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 0508b408d..65ae1b848 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp | |||
| @@ -96,7 +96,7 @@ bool InputEngine::GetButton(const PadIdentifier& identifier, int button) const { | |||
| 96 | std::lock_guard lock{mutex}; | 96 | std::lock_guard lock{mutex}; |
| 97 | const auto controller_iter = controller_list.find(identifier); | 97 | const auto controller_iter = controller_list.find(identifier); |
| 98 | if (controller_iter == controller_list.cend()) { | 98 | if (controller_iter == controller_list.cend()) { |
| 99 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 99 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 100 | identifier.pad, identifier.port); | 100 | identifier.pad, identifier.port); |
| 101 | return false; | 101 | return false; |
| 102 | } | 102 | } |
| @@ -113,7 +113,7 @@ bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 d | |||
| 113 | std::lock_guard lock{mutex}; | 113 | std::lock_guard lock{mutex}; |
| 114 | const auto controller_iter = controller_list.find(identifier); | 114 | const auto controller_iter = controller_list.find(identifier); |
| 115 | if (controller_iter == controller_list.cend()) { | 115 | if (controller_iter == controller_list.cend()) { |
| 116 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 116 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 117 | identifier.pad, identifier.port); | 117 | identifier.pad, identifier.port); |
| 118 | return false; | 118 | return false; |
| 119 | } | 119 | } |
| @@ -130,7 +130,7 @@ f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const { | |||
| 130 | std::lock_guard lock{mutex}; | 130 | std::lock_guard lock{mutex}; |
| 131 | const auto controller_iter = controller_list.find(identifier); | 131 | const auto controller_iter = controller_list.find(identifier); |
| 132 | if (controller_iter == controller_list.cend()) { | 132 | if (controller_iter == controller_list.cend()) { |
| 133 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 133 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 134 | identifier.pad, identifier.port); | 134 | identifier.pad, identifier.port); |
| 135 | return 0.0f; | 135 | return 0.0f; |
| 136 | } | 136 | } |
| @@ -147,7 +147,7 @@ BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const { | |||
| 147 | std::lock_guard lock{mutex}; | 147 | std::lock_guard lock{mutex}; |
| 148 | const auto controller_iter = controller_list.find(identifier); | 148 | const auto controller_iter = controller_list.find(identifier); |
| 149 | if (controller_iter == controller_list.cend()) { | 149 | if (controller_iter == controller_list.cend()) { |
| 150 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 150 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 151 | identifier.pad, identifier.port); | 151 | identifier.pad, identifier.port); |
| 152 | return BatteryLevel::Charging; | 152 | return BatteryLevel::Charging; |
| 153 | } | 153 | } |
| @@ -159,7 +159,7 @@ BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) | |||
| 159 | std::lock_guard lock{mutex}; | 159 | std::lock_guard lock{mutex}; |
| 160 | const auto controller_iter = controller_list.find(identifier); | 160 | const auto controller_iter = controller_list.find(identifier); |
| 161 | if (controller_iter == controller_list.cend()) { | 161 | if (controller_iter == controller_list.cend()) { |
| 162 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), | 162 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), |
| 163 | identifier.pad, identifier.port); | 163 | identifier.pad, identifier.port); |
| 164 | return {}; | 164 | return {}; |
| 165 | } | 165 | } |
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index fe2faee5a..c6c027aef 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | // Pad Identifier of data source | 17 | // Pad Identifier of data source |
| 18 | struct PadIdentifier { | 18 | struct PadIdentifier { |
| 19 | Common::UUID guid{Common::INVALID_UUID}; | 19 | Common::UUID guid{}; |
| 20 | std::size_t port{}; | 20 | std::size_t port{}; |
| 21 | std::size_t pad{}; | 21 | std::size_t pad{}; |
| 22 | 22 | ||
| @@ -59,7 +59,7 @@ namespace std { | |||
| 59 | template <> | 59 | template <> |
| 60 | struct hash<PadIdentifier> { | 60 | struct hash<PadIdentifier> { |
| 61 | size_t operator()(const PadIdentifier& pad_id) const noexcept { | 61 | size_t operator()(const PadIdentifier& pad_id) const noexcept { |
| 62 | u64 hash_value = pad_id.guid.uuid[1] ^ pad_id.guid.uuid[0]; | 62 | u64 hash_value = pad_id.guid.Hash(); |
| 63 | hash_value ^= (static_cast<u64>(pad_id.port) << 32); | 63 | hash_value ^= (static_cast<u64>(pad_id.port) << 32); |
| 64 | hash_value ^= static_cast<u64>(pad_id.pad); | 64 | hash_value ^= static_cast<u64>(pad_id.pad); |
| 65 | return static_cast<size_t>(hash_value); | 65 | return static_cast<size_t>(hash_value); |
diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index a7a6ad8c2..fb78093b8 100644 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp | |||
| @@ -57,7 +57,7 @@ void MappingFactory::RegisterButton(const MappingData& data) { | |||
| 57 | Common::ParamPackage new_input; | 57 | Common::ParamPackage new_input; |
| 58 | new_input.Set("engine", data.engine); | 58 | new_input.Set("engine", data.engine); |
| 59 | if (data.pad.guid.IsValid()) { | 59 | if (data.pad.guid.IsValid()) { |
| 60 | new_input.Set("guid", data.pad.guid.Format()); | 60 | new_input.Set("guid", data.pad.guid.RawString()); |
| 61 | } | 61 | } |
| 62 | new_input.Set("port", static_cast<int>(data.pad.port)); | 62 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| 63 | new_input.Set("pad", static_cast<int>(data.pad.pad)); | 63 | new_input.Set("pad", static_cast<int>(data.pad.pad)); |
| @@ -93,7 +93,7 @@ void MappingFactory::RegisterStick(const MappingData& data) { | |||
| 93 | Common::ParamPackage new_input; | 93 | Common::ParamPackage new_input; |
| 94 | new_input.Set("engine", data.engine); | 94 | new_input.Set("engine", data.engine); |
| 95 | if (data.pad.guid.IsValid()) { | 95 | if (data.pad.guid.IsValid()) { |
| 96 | new_input.Set("guid", data.pad.guid.Format()); | 96 | new_input.Set("guid", data.pad.guid.RawString()); |
| 97 | } | 97 | } |
| 98 | new_input.Set("port", static_cast<int>(data.pad.port)); | 98 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| 99 | new_input.Set("pad", static_cast<int>(data.pad.pad)); | 99 | new_input.Set("pad", static_cast<int>(data.pad.pad)); |
| @@ -138,7 +138,7 @@ void MappingFactory::RegisterMotion(const MappingData& data) { | |||
| 138 | Common::ParamPackage new_input; | 138 | Common::ParamPackage new_input; |
| 139 | new_input.Set("engine", data.engine); | 139 | new_input.Set("engine", data.engine); |
| 140 | if (data.pad.guid.IsValid()) { | 140 | if (data.pad.guid.IsValid()) { |
| 141 | new_input.Set("guid", data.pad.guid.Format()); | 141 | new_input.Set("guid", data.pad.guid.RawString()); |
| 142 | } | 142 | } |
| 143 | new_input.Set("port", static_cast<int>(data.pad.port)); | 143 | new_input.Set("port", static_cast<int>(data.pad.port)); |
| 144 | new_input.Set("pad", static_cast<int>(data.pad.pad)); | 144 | new_input.Set("pad", static_cast<int>(data.pad.pad)); |
diff --git a/src/yuzu/applets/qt_profile_select.cpp b/src/yuzu/applets/qt_profile_select.cpp index 5b32da923..4cd8f7784 100644 --- a/src/yuzu/applets/qt_profile_select.cpp +++ b/src/yuzu/applets/qt_profile_select.cpp | |||
| @@ -23,13 +23,13 @@ QString FormatUserEntryText(const QString& username, Common::UUID uuid) { | |||
| 23 | return QtProfileSelectionDialog::tr( | 23 | return QtProfileSelectionDialog::tr( |
| 24 | "%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. " | 24 | "%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. " |
| 25 | "00112233-4455-6677-8899-AABBCCDDEEFF))") | 25 | "00112233-4455-6677-8899-AABBCCDDEEFF))") |
| 26 | .arg(username, QString::fromStdString(uuid.FormatSwitch())); | 26 | .arg(username, QString::fromStdString(uuid.FormattedString())); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | QString GetImagePath(Common::UUID uuid) { | 29 | QString GetImagePath(Common::UUID uuid) { |
| 30 | const auto path = | 30 | const auto path = |
| 31 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / | 31 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / |
| 32 | fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormatSwitch()); | 32 | fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormattedString()); |
| 33 | return QString::fromStdString(Common::FS::PathToUTF8String(path)); | 33 | return QString::fromStdString(Common::FS::PathToUTF8String(path)); |
| 34 | } | 34 | } |
| 35 | 35 | ||
diff --git a/src/yuzu/configuration/configure_profile_manager.cpp b/src/yuzu/configuration/configure_profile_manager.cpp index 78b6374c0..d9f6dee4e 100644 --- a/src/yuzu/configuration/configure_profile_manager.cpp +++ b/src/yuzu/configuration/configure_profile_manager.cpp | |||
| @@ -33,10 +33,10 @@ constexpr std::array<u8, 107> backup_jpeg{ | |||
| 33 | 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | 33 | 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | QString GetImagePath(Common::UUID uuid) { | 36 | QString GetImagePath(const Common::UUID& uuid) { |
| 37 | const auto path = | 37 | const auto path = |
| 38 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / | 38 | Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / |
| 39 | fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormatSwitch()); | 39 | fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormattedString()); |
| 40 | return QString::fromStdString(Common::FS::PathToUTF8String(path)); | 40 | return QString::fromStdString(Common::FS::PathToUTF8String(path)); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| @@ -55,10 +55,10 @@ QString FormatUserEntryText(const QString& username, Common::UUID uuid) { | |||
| 55 | return ConfigureProfileManager::tr("%1\n%2", | 55 | return ConfigureProfileManager::tr("%1\n%2", |
| 56 | "%1 is the profile username, %2 is the formatted UUID (e.g. " | 56 | "%1 is the profile username, %2 is the formatted UUID (e.g. " |
| 57 | "00112233-4455-6677-8899-AABBCCDDEEFF))") | 57 | "00112233-4455-6677-8899-AABBCCDDEEFF))") |
| 58 | .arg(username, QString::fromStdString(uuid.FormatSwitch())); | 58 | .arg(username, QString::fromStdString(uuid.FormattedString())); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | QPixmap GetIcon(Common::UUID uuid) { | 61 | QPixmap GetIcon(const Common::UUID& uuid) { |
| 62 | QPixmap icon{GetImagePath(uuid)}; | 62 | QPixmap icon{GetImagePath(uuid)}; |
| 63 | 63 | ||
| 64 | if (!icon) { | 64 | if (!icon) { |
| @@ -200,7 +200,7 @@ void ConfigureProfileManager::AddUser() { | |||
| 200 | return; | 200 | return; |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | const auto uuid = Common::UUID::Generate(); | 203 | const auto uuid = Common::UUID::MakeRandom(); |
| 204 | profile_manager->CreateNewUser(uuid, username.toStdString()); | 204 | profile_manager->CreateNewUser(uuid, username.toStdString()); |
| 205 | 205 | ||
| 206 | item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); | 206 | item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index cc5a8f65e..3c2d7d080 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -1652,7 +1652,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target | |||
| 1652 | 1652 | ||
| 1653 | const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( | 1653 | const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( |
| 1654 | *system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData, | 1654 | *system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData, |
| 1655 | program_id, user_id->uuid, 0); | 1655 | program_id, user_id->AsU128(), 0); |
| 1656 | 1656 | ||
| 1657 | path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path); | 1657 | path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path); |
| 1658 | } else { | 1658 | } else { |