diff --git a/README.md b/README.md index 1bd6e8ced..45804babc 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 2483. +This is the source code for early-access 2484. ## Legal Notice diff --git a/src/common/uuid.cpp b/src/common/uuid.cpp index d7435a6e9..4aab10e08 100755 --- a/src/common/uuid.cpp +++ b/src/common/uuid.cpp @@ -1,23 +1,25 @@ -// Copyright 2018 yuzu Emulator Project +// Copyright 2022 yuzu Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include +#include #include #include #include "common/assert.h" +#include "common/tiny_mt.h" #include "common/uuid.h" namespace Common { namespace { -bool IsHexDigit(char c) { - return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); -} +constexpr size_t RawStringSize = sizeof(UUID) * 2; +constexpr size_t FormattedStringSize = RawStringSize + 4; -u8 HexCharToByte(char c) { +std::optional HexCharToByte(char c) { if (c >= '0' && c <= '9') { return static_cast(c - '0'); } @@ -28,60 +30,184 @@ u8 HexCharToByte(char c) { return static_cast(c - 'A' + 10); } ASSERT_MSG(false, "{} is not a hexadecimal digit!", c); - return u8{0}; + return std::nullopt; +} + +std::array ConstructFromRawString(std::string_view raw_string) { + std::array uuid; + + for (size_t i = 0; i < RawStringSize; i += 2) { + const auto upper = HexCharToByte(raw_string[i]); + const auto lower = HexCharToByte(raw_string[i + 1]); + if (!upper || !lower) { + return {}; + } + uuid[i / 2] = static_cast((*upper << 4) | *lower); + } + + return uuid; +} + +std::array ConstructFromFormattedString(std::string_view formatted_string) { + std::array uuid; + + size_t i = 0; + + // Process the first 8 characters. + const auto* str = formatted_string.data(); + + for (; i < 4; ++i) { + const auto upper = HexCharToByte(*(str++)); + const auto lower = HexCharToByte(*(str++)); + if (!upper || !lower) { + return {}; + } + uuid[i] = static_cast((*upper << 4) | *lower); + } + + // Process the next 4 characters. + ++str; + + for (; i < 6; ++i) { + const auto upper = HexCharToByte(*(str++)); + const auto lower = HexCharToByte(*(str++)); + if (!upper || !lower) { + return {}; + } + uuid[i] = static_cast((*upper << 4) | *lower); + } + + // Process the next 4 characters. + ++str; + + for (; i < 8; ++i) { + const auto upper = HexCharToByte(*(str++)); + const auto lower = HexCharToByte(*(str++)); + if (!upper || !lower) { + return {}; + } + uuid[i] = static_cast((*upper << 4) | *lower); + } + + // Process the next 4 characters. + ++str; + + for (; i < 10; ++i) { + const auto upper = HexCharToByte(*(str++)); + const auto lower = HexCharToByte(*(str++)); + if (!upper || !lower) { + return {}; + } + uuid[i] = static_cast((*upper << 4) | *lower); + } + + // Process the last 12 characters. + ++str; + + for (; i < 16; ++i) { + const auto upper = HexCharToByte(*(str++)); + const auto lower = HexCharToByte(*(str++)); + if (!upper || !lower) { + return {}; + } + uuid[i] = static_cast((*upper << 4) | *lower); + } + + return uuid; +} + +std::array ConstructUUID(std::string_view uuid_string) { + const auto length = uuid_string.length(); + + if (length == 0) { + return {}; + } + + // Check if the input string contains 32 hexadecimal characters. + if (length == RawStringSize) { + return ConstructFromRawString(uuid_string); + } + + // Check if the input string has the length of a RFC 4122 formatted UUID string. + if (length == FormattedStringSize) { + return ConstructFromFormattedString(uuid_string); + } + + ASSERT_MSG(false, "UUID string has an invalid length of {} characters!", length); + + return {}; } } // Anonymous namespace -u128 HexStringToU128(std::string_view hex_string) { - const size_t length = hex_string.length(); +UUID::UUID(std::string_view uuid_string) : uuid{ConstructUUID(uuid_string)} {} - // Detect "0x" prefix. - const bool has_0x_prefix = length > 2 && hex_string[0] == '0' && hex_string[1] == 'x'; - const size_t offset = has_0x_prefix ? 2 : 0; - - // Check length. - if (length > 32 + offset) { - ASSERT_MSG(false, "hex_string has more than 32 hexadecimal characters!"); - return INVALID_UUID; - } - - u64 lo = 0; - u64 hi = 0; - for (size_t i = 0; i < length - offset; ++i) { - const char c = hex_string[length - 1 - i]; - if (!IsHexDigit(c)) { - ASSERT_MSG(false, "{} is not a hexadecimal digit!", c); - return INVALID_UUID; - } - if (i < 16) { - lo |= u64{HexCharToByte(c)} << (i * 4); - } - if (i >= 16) { - hi |= u64{HexCharToByte(c)} << ((i - 16) * 4); - } - } - return u128{lo, hi}; +std::string UUID::RawString() const { + return fmt::format("{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}" + "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", + uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], + uuid[15]); } -UUID UUID::Generate() { +std::string UUID::FormattedString() const { + return fmt::format("{:02x}{:02x}{:02x}{:02x}" + "-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-" + "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", + uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], + uuid[15]); +} + +size_t UUID::Hash() const noexcept { + u64 hash; + u64 temp; + + std::memcpy(&hash, uuid.data(), sizeof(u64)); + std::memcpy(&temp, uuid.data() + 8, sizeof(u64)); + + return hash ^ std::rotl(temp, 1); +} + +u128 UUID::AsU128() const { + u128 uuid_old; + std::memcpy(&uuid_old, uuid.data(), sizeof(UUID)); + return uuid_old; +} + +UUID UUID::MakeRandom() { std::random_device device; - std::mt19937 gen(device()); - std::uniform_int_distribution distribution(1, std::numeric_limits::max()); - return UUID{distribution(gen), distribution(gen)}; + + return MakeRandomWithSeed(device()); } -std::string UUID::Format() const { - return fmt::format("{:016x}{:016x}", uuid[1], uuid[0]); +UUID UUID::MakeRandomWithSeed(u32 seed) { + // Create and initialize our RNG. + TinyMT rng; + rng.Initialize(seed); + + UUID uuid; + + // Populate the UUID with random bytes. + rng.GenerateRandomBytes(uuid.uuid.data(), sizeof(UUID)); + + return uuid; } -std::string UUID::FormatSwitch() const { - std::array s{}; - std::memcpy(s.data(), uuid.data(), sizeof(u128)); - return fmt::format("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{" - ":02x}{:02x}{:02x}{:02x}{:02x}", - s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], - s[12], s[13], s[14], s[15]); +UUID UUID::MakeRandomRFC4122V4() { + auto uuid = MakeRandom(); + + // According to Proposed Standard RFC 4122 Section 4.4, we must: + + // 1. Set the two most significant bits (bits 6 and 7) of the + // clock_seq_hi_and_reserved to zero and one, respectively. + uuid.uuid[8] = 0x80 | (uuid.uuid[8] & 0x3F); + + // 2. Set the four most significant bits (bits 12 through 15) of the + // time_hi_and_version field to the 4-bit version number from Section 4.1.3. + uuid.uuid[6] = 0x40 | (uuid.uuid[6] & 0xF); + + return uuid; } } // namespace Common diff --git a/src/common/uuid.h b/src/common/uuid.h index 8ea01f8da..fe31e64e6 100755 --- a/src/common/uuid.h +++ b/src/common/uuid.h @@ -1,9 +1,11 @@ -// Copyright 2018 yuzu Emulator Project +// Copyright 2022 yuzu Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. #pragma once +#include +#include #include #include @@ -11,69 +13,119 @@ namespace Common { -constexpr u128 INVALID_UUID{{0, 0}}; - -/** - * Converts a hex string to a 128-bit unsigned integer. - * - * The hex string can be formatted in lowercase or uppercase, with or without the "0x" prefix. - * - * This function will assert and return INVALID_UUID under the following conditions: - * - If the hex string is more than 32 characters long - * - If the hex string contains non-hexadecimal characters - * - * @param hex_string Hexadecimal string - * - * @returns A 128-bit unsigned integer if successfully converted, INVALID_UUID otherwise. - */ -[[nodiscard]] u128 HexStringToU128(std::string_view hex_string); - struct UUID { - // UUIDs which are 0 are considered invalid! - u128 uuid; - UUID() = default; - constexpr explicit UUID(const u128& id) : uuid{id} {} - constexpr explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {} - explicit UUID(std::string_view hex_string) { - uuid = HexStringToU128(hex_string); + std::array uuid{}; + + /// Constructs an invalid UUID. + constexpr UUID() = default; + + /// Constructs a UUID from a reference to a 128 bit array. + constexpr explicit UUID(const std::array& uuid_) : uuid{uuid_} {} + + /** + * Constructs a UUID from either: + * 1. A 32 hexadecimal character string representing the bytes of the UUID + * 2. A RFC 4122 formatted UUID string, in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + * + * The input string may contain uppercase or lowercase characters, but they must: + * 1. Contain valid hexadecimal characters (0-9, a-f, A-F) + * 2. Not contain the "0x" hexadecimal prefix + * + * Should the input string not meet the above requirements, + * an assert will be triggered and an invalid UUID is set instead. + */ + explicit UUID(std::string_view uuid_string); + + ~UUID() = default; + + constexpr UUID(const UUID&) noexcept = default; + constexpr UUID(UUID&&) noexcept = default; + + constexpr UUID& operator=(const UUID&) noexcept = default; + constexpr UUID& operator=(UUID&&) noexcept = default; + + /** + * Returns whether the stored UUID is valid or not. + * + * @returns True if the stored UUID is valid, false otherwise. + */ + constexpr bool IsValid() const { + return uuid != std::array{}; } - [[nodiscard]] constexpr explicit operator bool() const { - return uuid != INVALID_UUID; + /** + * Returns whether the stored UUID is invalid or not. + * + * @returns True if the stored UUID is invalid, false otherwise. + */ + constexpr bool IsInvalid() const { + return !IsValid(); } - [[nodiscard]] constexpr bool operator==(const UUID& rhs) const { - return uuid == rhs.uuid; + /** + * Returns a 32 hexadecimal character string representing the bytes of the UUID. + * + * @returns A 32 hexadecimal character string of the UUID. + */ + std::string RawString() const; + + /** + * Returns a RFC 4122 formatted UUID string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx. + * + * @returns A RFC 4122 formatted UUID string. + */ + std::string FormattedString() const; + + /** + * Returns a 64-bit hash of the UUID for use in hash table data structures. + * + * @returns A 64-bit hash of the UUID. + */ + size_t Hash() const noexcept; + + /// DO NOT USE. Copies the contents of the UUID into a u128. + u128 AsU128() const; + + /** + * Creates a default UUID "yuzu Default UID". + * + * @returns A UUID with its bytes set to the ASCII values of "yuzu Default UID". + */ + static constexpr UUID MakeDefault() { + return UUID{ + {'y', 'u', 'z', 'u', ' ', 'D', 'e', 'f', 'a', 'u', 'l', 't', ' ', 'U', 'I', 'D'}, + }; } - [[nodiscard]] constexpr bool operator!=(const UUID& rhs) const { - return !operator==(rhs); - } + /** + * Creates a random UUID. + * + * @returns A random UUID. + */ + static UUID MakeRandom(); - // TODO(ogniK): Properly generate uuids based on RFC-4122 - [[nodiscard]] static UUID Generate(); + /** + * Creates a random UUID with a seed. + * + * @param seed A seed to initialize the Mersenne-Twister RNG + * + * @returns A random UUID. + */ + static UUID MakeRandomWithSeed(u32 seed); - // Set the UUID to {0,0} to be considered an invalid user - constexpr void Invalidate() { - uuid = INVALID_UUID; - } + /** + * Creates a random UUID. The generated UUID is RFC 4122 Version 4 compliant. + * + * @returns A random UUID that is RFC 4122 Version 4 compliant. + */ + static UUID MakeRandomRFC4122V4(); - [[nodiscard]] constexpr bool IsInvalid() const { - return uuid == INVALID_UUID; - } - [[nodiscard]] constexpr bool IsValid() const { - return !IsInvalid(); - } - - // TODO(ogniK): Properly generate a Nintendo ID - [[nodiscard]] constexpr u64 GetNintendoID() const { - return uuid[0]; - } - - [[nodiscard]] std::string Format() const; - [[nodiscard]] std::string FormatSwitch() const; + friend constexpr bool operator==(const UUID& lhs, const UUID& rhs) = default; }; -static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); +static_assert(sizeof(UUID) == 0x10, "UUID has incorrect size."); + +/// An invalid UUID. This UUID has all its bytes set to 0. +constexpr UUID InvalidUUID = {}; } // namespace Common @@ -82,7 +134,7 @@ namespace std { template <> struct hash { size_t operator()(const Common::UUID& uuid) const noexcept { - return uuid.uuid[1] ^ uuid.uuid[0]; + return uuid.Hash(); } }; diff --git a/src/core/frontend/applets/profile_select.cpp b/src/core/frontend/applets/profile_select.cpp index 3e4f90be2..4c58c310f 100755 --- a/src/core/frontend/applets/profile_select.cpp +++ b/src/core/frontend/applets/profile_select.cpp @@ -13,8 +13,7 @@ ProfileSelectApplet::~ProfileSelectApplet() = default; void DefaultProfileSelectApplet::SelectProfile( std::function)> callback) const { Service::Account::ProfileManager manager; - callback(manager.GetUser(Settings::values.current_user.GetValue()) - .value_or(Common::UUID{Common::INVALID_UUID})); + callback(manager.GetUser(Settings::values.current_user.GetValue()).value_or(Common::UUID{})); LOG_INFO(Service_ACC, "called, selecting current user instead of prompting..."); } diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index a7cdf45e6..2bee173b3 100755 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -269,7 +269,8 @@ void EmulatedController::ReloadInput() { } // Use a common UUID for TAS - const auto tas_uuid = Common::UUID{0x0, 0x7A5}; + static constexpr Common::UUID TAS_UUID = Common::UUID{ + {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7, 0xA5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}}; // Register TAS devices. No need to force update for (std::size_t index = 0; index < tas_button_devices.size(); ++index) { @@ -278,8 +279,8 @@ void EmulatedController::ReloadInput() { } tas_button_devices[index]->SetCallback({ .on_change = - [this, index, tas_uuid](const Common::Input::CallbackStatus& callback) { - SetButton(callback, index, tas_uuid); + [this, index](const Common::Input::CallbackStatus& callback) { + SetButton(callback, index, TAS_UUID); }, }); } @@ -290,8 +291,8 @@ void EmulatedController::ReloadInput() { } tas_stick_devices[index]->SetCallback({ .on_change = - [this, index, tas_uuid](const Common::Input::CallbackStatus& callback) { - SetStick(callback, index, tas_uuid); + [this, index](const Common::Input::CallbackStatus& callback) { + SetStick(callback, index, TAS_UUID); }, }); } diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h index cf204f570..026257115 100755 --- a/src/core/hle/ipc_helpers.h +++ b/src/core/hle/ipc_helpers.h @@ -404,6 +404,11 @@ inline s32 RequestParser::Pop() { return static_cast(Pop()); } +// Ignore the -Wclass-memaccess warning on memcpy for non-trivially default constructible objects. +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wclass-memaccess" +#endif template void RequestParser::PopRaw(T& value) { static_assert(std::is_trivially_copyable_v, @@ -411,6 +416,9 @@ void RequestParser::PopRaw(T& value) { std::memcpy(&value, cmdbuf + index, sizeof(T)); index += (sizeof(T) + 3) / 4; // round up to word length } +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif template T RequestParser::PopRaw() { diff --git a/src/core/hle/kernel/k_code_memory.cpp b/src/core/hle/kernel/k_code_memory.cpp index d69f7ffb7..0b225e8e0 100755 --- a/src/core/hle/kernel/k_code_memory.cpp +++ b/src/core/hle/kernel/k_code_memory.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include "common/alignment.h" #include "common/common_types.h" #include "core/device_memory.h" #include "core/hle/kernel/k_auto_object.h" @@ -28,8 +29,7 @@ ResultCode KCodeMemory::Initialize(Core::DeviceMemory& device_memory, VAddr addr auto& page_table = m_owner->PageTable(); // Construct the page group. - KMemoryInfo kBlockInfo = page_table.QueryInfo(addr); - m_page_group = KPageLinkedList(kBlockInfo.GetAddress(), kBlockInfo.GetNumPages()); + m_page_group = KPageLinkedList(addr, Common::DivideUp(size, PageSize)); // Lock the memory. R_TRY(page_table.LockForCodeMemory(addr, size)) @@ -143,4 +143,4 @@ ResultCode KCodeMemory::UnmapFromOwner(VAddr address, size_t size) { return ResultSuccess; } -} // namespace Kernel \ No newline at end of file +} // namespace Kernel diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 4f7aebf3f..9387373c1 100755 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -396,7 +396,7 @@ static ResultCode GetProcessId(Core::System& system, u64* out_process_id, Handle // Get the process id. *out_process_id = process->GetId(); - return ResultInvalidHandle; + return ResultSuccess; } static ResultCode GetProcessId32(Core::System& system, u32* out_process_id_low, diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 6e63e057e..e34ef5a78 100755 --- 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}; // Thumbnails are hard coded to be at least this size constexpr std::size_t THUMBNAIL_SIZE = 0x24000; -static std::filesystem::path GetImagePath(Common::UUID uuid) { +static std::filesystem::path GetImagePath(const Common::UUID& uuid) { return Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / - fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormatSwitch()); + fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormattedString()); } static constexpr u32 SanitizeJPEGSize(std::size_t size) { @@ -290,7 +290,7 @@ public: protected: void Get(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.Format()); + LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); ProfileBase profile_base{}; ProfileData data{}; if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) { @@ -300,21 +300,21 @@ protected: rb.PushRaw(profile_base); } else { LOG_ERROR(Service_ACC, "Failed to get profile base and data for user=0x{}", - user_id.Format()); + user_id.RawString()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultUnknown); // TODO(ogniK): Get actual error code } } void GetBase(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.Format()); + LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); ProfileBase profile_base{}; if (profile_manager.GetProfileBase(user_id, profile_base)) { IPC::ResponseBuilder rb{ctx, 16}; rb.Push(ResultSuccess); rb.PushRaw(profile_base); } else { - LOG_ERROR(Service_ACC, "Failed to get profile base for user=0x{}", user_id.Format()); + LOG_ERROR(Service_ACC, "Failed to get profile base for user=0x{}", user_id.RawString()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultUnknown); // TODO(ogniK): Get actual error code } @@ -373,7 +373,7 @@ protected: LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(base.username.data()), base.username.size()), - base.timestamp, base.user_uuid.Format()); + base.timestamp, base.user_uuid.RawString()); if (user_data.size() < sizeof(ProfileData)) { LOG_ERROR(Service_ACC, "ProfileData buffer too small!"); @@ -406,7 +406,7 @@ protected: LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid=0x{}", Common::StringFromFixedZeroTerminatedBuffer( reinterpret_cast(base.username.data()), base.username.size()), - base.timestamp, base.user_uuid.Format()); + base.timestamp, base.user_uuid.RawString()); if (user_data.size() < sizeof(ProfileData)) { LOG_ERROR(Service_ACC, "ProfileData buffer too small!"); @@ -435,7 +435,7 @@ protected: } ProfileManager& profile_manager; - Common::UUID user_id{Common::INVALID_UUID}; ///< The user id this profile refers to. + Common::UUID user_id{}; ///< The user id this profile refers to. }; class IProfile final : public IProfileCommon { @@ -547,7 +547,7 @@ private: IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); - rb.PushRaw(user_id.GetNintendoID()); + rb.PushRaw(user_id.Hash()); } void EnsureIdTokenCacheAsync(Kernel::HLERequestContext& ctx) { @@ -577,7 +577,7 @@ private: IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); - rb.PushRaw(user_id.GetNintendoID()); + rb.PushRaw(user_id.Hash()); } void StoreOpenContext(Kernel::HLERequestContext& ctx) { @@ -587,7 +587,7 @@ private: } std::shared_ptr ensure_token_id{}; - Common::UUID user_id{Common::INVALID_UUID}; + Common::UUID user_id{}; }; // 6.0.0+ @@ -687,7 +687,7 @@ void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) { void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; Common::UUID user_id = rp.PopRaw(); - LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.Format()); + LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); @@ -718,7 +718,7 @@ void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) { void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; Common::UUID user_id = rp.PopRaw(); - LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.Format()); + LOG_DEBUG(Service_ACC, "called user_id=0x{}", user_id.RawString()); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -833,7 +833,7 @@ void Module::Interface::GetProfileEditor(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; Common::UUID user_id = rp.PopRaw(); - LOG_DEBUG(Service_ACC, "called, user_id=0x{}", user_id.Format()); + LOG_DEBUG(Service_ACC, "called, user_id=0x{}", user_id.RawString()); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -875,7 +875,7 @@ void Module::Interface::StoreSaveDataThumbnailApplication(Kernel::HLERequestCont IPC::RequestParser rp{ctx}; const auto uuid = rp.PopRaw(); - LOG_WARNING(Service_ACC, "(STUBBED) called, uuid=0x{}", uuid.Format()); + LOG_WARNING(Service_ACC, "(STUBBED) called, uuid=0x{}", uuid.RawString()); // TODO(ogniK): Check if application ID is zero on acc initialize. As we don't have a reliable // 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& const auto uuid = rp.PopRaw(); const auto tid = rp.Pop(); - LOG_WARNING(Service_ACC, "(STUBBED) called, uuid=0x{}, tid={:016X}", uuid.Format(), tid); + LOG_WARNING(Service_ACC, "(STUBBED) called, uuid=0x{}, tid={:016X}", uuid.RawString(), tid); StoreSaveDataThumbnail(ctx, uuid, tid); } @@ -903,7 +903,7 @@ void Module::Interface::StoreSaveDataThumbnail(Kernel::HLERequestContext& ctx, return; } - if (!uuid) { + if (uuid.IsInvalid()) { LOG_ERROR(Service_ACC, "User ID is not valid!"); rb.Push(ERR_INVALID_USER_ID); return; @@ -927,20 +927,20 @@ void Module::Interface::TrySelectUserWithoutInteraction(Kernel::HLERequestContex IPC::ResponseBuilder rb{ctx, 6}; if (profile_manager->GetUserCount() != 1) { rb.Push(ResultSuccess); - rb.PushRaw(Common::INVALID_UUID); + rb.PushRaw(Common::InvalidUUID); return; } const auto user_list = profile_manager->GetAllUsers(); if (std::ranges::all_of(user_list, [](const auto& user) { return user.IsInvalid(); })) { rb.Push(ResultUnknown); // TODO(ogniK): Find the correct error code - rb.PushRaw(Common::INVALID_UUID); + rb.PushRaw(Common::InvalidUUID); return; } // Select the first user we have rb.Push(ResultSuccess); - rb.PushRaw(profile_manager->GetUser(0)->uuid); + rb.PushRaw(profile_manager->GetUser(0)->uuid); } Module::Interface::Interface(std::shared_ptr module_, diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 568303ced..fba847142 100755 --- 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; using Common::UUID; struct UserRaw { - UUID uuid{Common::INVALID_UUID}; - UUID uuid2{Common::INVALID_UUID}; + UUID uuid{}; + UUID uuid2{}; u64 timestamp{}; ProfileUsername username{}; ProfileData extra_data{}; @@ -45,7 +45,7 @@ ProfileManager::ProfileManager() { // Create an user if none are present if (user_count == 0) { - CreateNewUser(UUID::Generate(), "yuzu"); + CreateNewUser(UUID::MakeRandom(), "yuzu"); } auto current = @@ -101,7 +101,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& usern if (user_count == MAX_USERS) { return ERROR_TOO_MANY_USERS; } - if (!uuid) { + if (uuid.IsInvalid()) { return ERROR_ARGUMENT_IS_NULL; } if (username[0] == 0x0) { @@ -145,7 +145,7 @@ std::optional ProfileManager::GetUser(std::size_t index) const { /// Returns a users profile index based on their user id. std::optional ProfileManager::GetUserIndex(const UUID& uuid) const { - if (!uuid) { + if (uuid.IsInvalid()) { return std::nullopt; } @@ -250,9 +250,10 @@ UserIDArray ProfileManager::GetOpenUsers() const { std::ranges::transform(profiles, output.begin(), [](const ProfileInfo& p) { if (p.is_open) return p.user_uuid; - return UUID{Common::INVALID_UUID}; + return Common::InvalidUUID; }); - std::stable_partition(output.begin(), output.end(), [](const UUID& uuid) { return uuid; }); + std::stable_partition(output.begin(), output.end(), + [](const UUID& uuid) { return uuid.IsValid(); }); return output; } @@ -299,7 +300,7 @@ bool ProfileManager::RemoveUser(UUID uuid) { profiles[*index] = ProfileInfo{}; std::stable_partition(profiles.begin(), profiles.end(), - [](const ProfileInfo& profile) { return profile.user_uuid; }); + [](const ProfileInfo& profile) { return profile.user_uuid.IsValid(); }); return true; } @@ -361,7 +362,7 @@ void ProfileManager::ParseUserSaveFile() { } std::stable_partition(profiles.begin(), profiles.end(), - [](const ProfileInfo& profile) { return profile.user_uuid; }); + [](const ProfileInfo& profile) { return profile.user_uuid.IsValid(); }); } 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 100755 --- 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 /// This holds general information about a users profile. This is where we store all the information /// based on a specific user struct ProfileInfo { - Common::UUID user_uuid{Common::INVALID_UUID}; + Common::UUID user_uuid{}; ProfileUsername username{}; u64 creation_time{}; ProfileData data{}; // TODO(ognik): Work out what this is @@ -49,7 +49,7 @@ struct ProfileBase { // Zero out all the fields to make the profile slot considered "Empty" void Invalidate() { - user_uuid.Invalidate(); + user_uuid = {}; timestamp = 0; username.fill(0); } @@ -103,7 +103,7 @@ private: std::array profiles{}; std::size_t user_count{}; - Common::UUID last_opened_user{Common::INVALID_UUID}; + Common::UUID last_opened_user{}; }; }; // namespace Service::Account diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index e60661fe1..773dc9f29 100755 --- 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; struct LaunchParameterAccountPreselectedUser { u32_le magic; u32_le is_account_selected; - u128 current_user; + Common::UUID current_user; INSERT_PADDING_BYTES(0x70); }; static_assert(sizeof(LaunchParameterAccountPreselectedUser) == 0x88); @@ -1453,8 +1453,8 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { Account::ProfileManager profile_manager{}; const auto uuid = profile_manager.GetUser(static_cast(Settings::values.current_user)); - ASSERT(uuid); - params.current_user = uuid->uuid; + ASSERT(uuid.has_value() && uuid->IsValid()); + params.current_user = *uuid; IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 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 100755 --- 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 uuid) { if (uuid.has_value() && uuid->IsValid()) { output.result = 0; - output.uuid_selected = uuid->uuid; + output.uuid_selected = *uuid; } else { status = ERR_USER_CANCELLED_SELECTION; output.result = ERR_USER_CANCELLED_SELECTION.raw; - output.uuid_selected = Common::INVALID_UUID; + output.uuid_selected = Common::InvalidUUID; } final_data = std::vector(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 100755 --- 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 struct UserSelectionOutput { u64 result; - u128 uuid_selected; + Common::UUID uuid_selected; }; static_assert(sizeof(UserSelectionOutput) == 0x18, "UserSelectionOutput has incorrect size."); diff --git a/src/core/hle/service/friend/friend.cpp b/src/core/hle/service/friend/friend.cpp index 9f9cea1e0..79cd3acbb 100755 --- a/src/core/hle/service/friend/friend.cpp +++ b/src/core/hle/service/friend/friend.cpp @@ -173,7 +173,7 @@ private: const auto uuid = rp.PopRaw(); LOG_WARNING(Service_Friend, "(STUBBED) called, local_play={}, uuid=0x{}", local_play, - uuid.Format()); + uuid.RawString()); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -186,7 +186,7 @@ private: [[maybe_unused]] const auto filter = rp.PopRaw(); const auto pid = rp.Pop(); LOG_WARNING(Service_Friend, "(STUBBED) called, offset={}, uuid=0x{}, pid={}", friend_offset, - uuid.Format(), pid); + uuid.RawString(), pid); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); @@ -312,7 +312,7 @@ void Module::Interface::CreateNotificationService(Kernel::HLERequestContext& ctx IPC::RequestParser rp{ctx}; auto uuid = rp.PopRaw(); - LOG_DEBUG(Service_Friend, "called, uuid=0x{}", uuid.Format()); + LOG_DEBUG(Service_Friend, "called, uuid=0x{}", uuid.RawString()); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 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 100755 --- 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) { return Common::swap16(static_cast(crc)); } -Common::UUID GenerateValidUUID() { - auto uuid{Common::UUID::Generate()}; - - // Bit 7 must be set, and bit 6 unset for the UUID to be valid - uuid.uuid[1] &= 0xFFFFFFFFFFFFFF3FULL; - uuid.uuid[1] |= 0x0000000000000080ULL; - - return uuid; -} - template T GetRandomValue(T min, T max) { std::random_device device; @@ -383,7 +373,7 @@ MiiStoreData::MiiStoreData() = default; MiiStoreData::MiiStoreData(const MiiStoreData::Name& name, const MiiStoreBitFields& bit_fields, const Common::UUID& user_id) { data.name = name; - data.uuid = GenerateValidUUID(); + data.uuid = Common::UUID::MakeRandomRFC4122V4(); std::memcpy(data.data.data(), &bit_fields, sizeof(MiiStoreBitFields)); 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 100755 --- a/src/core/hle/service/mii/mii_manager.h +++ b/src/core/hle/service/mii/mii_manager.h @@ -202,7 +202,7 @@ struct MiiStoreData { static_assert(sizeof(MiiStoreBitFields) == sizeof(data), "data field has incorrect size."); Name name{}; - Common::UUID uuid{Common::INVALID_UUID}; + Common::UUID uuid{}; } data; u16 data_crc{}; @@ -326,7 +326,7 @@ public: ResultCode GetIndex(const MiiInfo& info, u32& index); private: - const Common::UUID user_id{Common::INVALID_UUID}; + const Common::UUID user_id{}; u64 update_counter{}; }; diff --git a/src/core/hle/service/ns/pdm_qry.cpp b/src/core/hle/service/ns/pdm_qry.cpp index e2fab5c3f..36ce46353 100755 --- 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 LOG_WARNING(Service_NS, "(STUBBED) called. unknown={}. application_id=0x{:016X}, user_account_uid=0x{}", - unknown, application_id, user_account_uid.Format()); + unknown, application_id, user_account_uid.RawString()); IPC::ResponseBuilder rb{ctx, 12}; rb.Push(ResultSuccess); diff --git a/src/core/hle/service/pm/pm.cpp b/src/core/hle/service/pm/pm.cpp index 277abc17a..057666021 100755 --- a/src/core/hle/service/pm/pm.cpp +++ b/src/core/hle/service/pm/pm.cpp @@ -91,6 +91,8 @@ public: {4, &DebugMonitor::GetApplicationProcessId, "GetApplicationProcessId"}, {5, nullptr, "HookToCreateApplicationProgress"}, {6, nullptr, "ClearHook"}, + {65000, &DebugMonitor::AtmosphereGetProcessInfo, "AtmosphereGetProcessInfo"}, + {65001, nullptr, "AtmosphereGetCurrentLimitInfo"}, }; // clang-format on @@ -125,6 +127,49 @@ private: GetApplicationPidGeneric(ctx, kernel.GetProcessList()); } + void AtmosphereGetProcessInfo(Kernel::HLERequestContext& ctx) { + // https://github.com/Atmosphere-NX/Atmosphere/blob/master/stratosphere/pm/source/impl/pm_process_manager.cpp#L614 + // This implementation is incomplete; only a handle to the process is returned. + IPC::RequestParser rp{ctx}; + const auto pid = rp.PopRaw(); + + LOG_WARNING(Service_PM, "(Partial Implementation) called, pid={:016X}", pid); + + const auto process = SearchProcessList(kernel.GetProcessList(), [pid](const auto& proc) { + return proc->GetProcessID() == pid; + }); + + if (!process.has_value()) { + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultProcessNotFound); + return; + } + + struct ProgramLocation { + u64 program_id; + u8 storage_id; + }; + static_assert(sizeof(ProgramLocation) == 0x10, "ProgramLocation has an invalid size"); + + struct OverrideStatus { + u64 keys_held; + u64 flags; + }; + static_assert(sizeof(OverrideStatus) == 0x10, "OverrideStatus has an invalid size"); + + OverrideStatus override_status{}; + ProgramLocation program_location{ + .program_id = (*process)->GetProgramID(), + .storage_id = 0, + }; + + IPC::ResponseBuilder rb{ctx, 10, 1}; + rb.Push(ResultSuccess); + rb.PushCopyObjects(*process); + rb.PushRaw(program_location); + rb.PushRaw(override_status); + } + const Kernel::KernelCore& kernel; }; diff --git a/src/core/hle/service/time/clock_types.h b/src/core/hle/service/time/clock_types.h index 392e16863..d0cacb80c 100755 --- a/src/core/hle/service/time/clock_types.h +++ b/src/core/hle/service/time/clock_types.h @@ -36,7 +36,7 @@ struct SteadyClockTimePoint { } static SteadyClockTimePoint GetRandom() { - return {0, Common::UUID::Generate()}; + return {0, Common::UUID::MakeRandom()}; } }; 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 100755 --- 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: } private: - Common::UUID clock_source_id{Common::UUID::Generate()}; + Common::UUID clock_source_id{Common::UUID::MakeRandom()}; bool is_initialized{}; }; diff --git a/src/core/hle/service/time/time_manager.cpp b/src/core/hle/service/time/time_manager.cpp index c1e4e6cce..00f1ae8cf 100755 --- 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 { time_zone_content_manager{system} { const auto system_time{Clock::TimeSpanType::FromSeconds(GetExternalRtcValue())}; - SetupStandardSteadyClock(system, Common::UUID::Generate(), system_time, {}, {}); + SetupStandardSteadyClock(system, Common::UUID::MakeRandom(), system_time, {}, {}); SetupStandardLocalSystemClock(system, {}, system_time.ToSeconds()); 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 100755 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp @@ -248,7 +248,7 @@ bool GCAdapter::Setup() { std::size_t port = 0; for (GCController& pad : pads) { pad.identifier = { - .guid = Common::UUID{Common::INVALID_UUID}, + .guid = Common::UUID{}, .port = port++, .pad = 0, }; diff --git a/src/input_common/drivers/keyboard.cpp b/src/input_common/drivers/keyboard.cpp index 4c1e5bbec..59e3d9cc0 100755 --- a/src/input_common/drivers/keyboard.cpp +++ b/src/input_common/drivers/keyboard.cpp @@ -9,17 +9,17 @@ namespace InputCommon { constexpr PadIdentifier key_identifier = { - .guid = Common::UUID{Common::INVALID_UUID}, + .guid = Common::UUID{}, .port = 0, .pad = 0, }; constexpr PadIdentifier keyboard_key_identifier = { - .guid = Common::UUID{Common::INVALID_UUID}, + .guid = Common::UUID{}, .port = 1, .pad = 0, }; constexpr PadIdentifier keyboard_modifier_identifier = { - .guid = Common::UUID{Common::INVALID_UUID}, + .guid = Common::UUID{}, .port = 1, .pad = 1, }; diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp index d8ae7f0c1..3c9a4e747 100755 --- a/src/input_common/drivers/mouse.cpp +++ b/src/input_common/drivers/mouse.cpp @@ -20,7 +20,7 @@ constexpr int motion_wheel_y = 4; constexpr int touch_axis_x = 10; constexpr int touch_axis_y = 11; constexpr PadIdentifier identifier = { - .guid = Common::UUID{Common::INVALID_UUID}, + .guid = Common::UUID{}, .port = 0, .pad = 0, }; diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index b031a8523..655eb5275 100755 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp @@ -502,7 +502,7 @@ std::vector SDLDriver::GetInputDevices() const { Common::Input::VibrationError SDLDriver::SetRumble( const PadIdentifier& identifier, const Common::Input::VibrationStatus& vibration) { const auto joystick = - GetSDLJoystickByGUID(identifier.guid.Format(), static_cast(identifier.port)); + GetSDLJoystickByGUID(identifier.guid.RawString(), static_cast(identifier.port)); const auto process_amplitude_exp = [](f32 amplitude, f32 factor) { return (amplitude + std::pow(amplitude, factor)) * 0.5f * 0xFFFF; }; @@ -599,7 +599,7 @@ Common::ParamPackage SDLDriver::BuildParamPackageForAnalog(PadIdentifier identif Common::ParamPackage params; params.Set("engine", GetEngineName()); params.Set("port", static_cast(identifier.port)); - params.Set("guid", identifier.guid.Format()); + params.Set("guid", identifier.guid.RawString()); params.Set("axis_x", axis_x); params.Set("axis_y", axis_y); 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 100755 --- a/src/input_common/drivers/touch_screen.cpp +++ b/src/input_common/drivers/touch_screen.cpp @@ -8,7 +8,7 @@ namespace InputCommon { constexpr PadIdentifier identifier = { - .guid = Common::UUID{Common::INVALID_UUID}, + .guid = Common::UUID{}, .port = 0, .pad = 0, }; diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index 333173e3d..64162f431 100755 --- 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 { Common::UUID UDPClient::GetHostUUID(const std::string& host) const { const auto ip = boost::asio::ip::make_address_v4(host); - const auto hex_host = fmt::format("{:06x}", ip.to_uint()); + const auto hex_host = fmt::format("00000000-0000-0000-0000-0000{:06x}", ip.to_uint()); return Common::UUID{hex_host}; } @@ -385,7 +385,7 @@ std::vector UDPClient::GetInputDevices() const { Common::ParamPackage identifier{}; identifier.Set("engine", GetEngineName()); identifier.Set("display", fmt::format("UDP Controller {}", pad_identifier.pad)); - identifier.Set("guid", pad_identifier.guid.Format()); + identifier.Set("guid", pad_identifier.guid.RawString()); identifier.Set("port", static_cast(pad_identifier.port)); identifier.Set("pad", static_cast(pad_identifier.pad)); 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 100755 --- a/src/input_common/drivers/udp_client.h +++ b/src/input_common/drivers/udp_client.h @@ -126,7 +126,7 @@ private: struct ClientConnection { ClientConnection(); ~ClientConnection(); - Common::UUID uuid{"7F000001"}; + Common::UUID uuid{"00000000-0000-0000-0000-00007F000001"}; std::string host{"127.0.0.1"}; u16 port{26760}; s8 active{-1}; diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 0508b408d..65ae1b848 100755 --- 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 { std::lock_guard lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { - LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), + LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), identifier.pad, identifier.port); return false; } @@ -113,7 +113,7 @@ bool InputEngine::GetHatButton(const PadIdentifier& identifier, int button, u8 d std::lock_guard lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { - LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), + LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), identifier.pad, identifier.port); return false; } @@ -130,7 +130,7 @@ f32 InputEngine::GetAxis(const PadIdentifier& identifier, int axis) const { std::lock_guard lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { - LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), + LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), identifier.pad, identifier.port); return 0.0f; } @@ -147,7 +147,7 @@ BatteryLevel InputEngine::GetBattery(const PadIdentifier& identifier) const { std::lock_guard lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { - LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), + LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), identifier.pad, identifier.port); return BatteryLevel::Charging; } @@ -159,7 +159,7 @@ BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) std::lock_guard lock{mutex}; const auto controller_iter = controller_list.find(identifier); if (controller_iter == controller_list.cend()) { - LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.Format(), + LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), identifier.pad, identifier.port); return {}; } diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index 4f620b229..a511036b4 100755 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h @@ -16,7 +16,7 @@ // Pad Identifier of data source struct PadIdentifier { - Common::UUID guid{Common::INVALID_UUID}; + Common::UUID guid{}; std::size_t port{}; std::size_t pad{}; @@ -59,7 +59,7 @@ namespace std { template <> struct hash { size_t operator()(const PadIdentifier& pad_id) const noexcept { - u64 hash_value = pad_id.guid.uuid[1] ^ pad_id.guid.uuid[0]; + u64 hash_value = pad_id.guid.Hash(); hash_value ^= (static_cast(pad_id.port) << 32); hash_value ^= static_cast(pad_id.pad); return static_cast(hash_value); diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index a7a6ad8c2..fb78093b8 100755 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp @@ -57,7 +57,7 @@ void MappingFactory::RegisterButton(const MappingData& data) { Common::ParamPackage new_input; new_input.Set("engine", data.engine); if (data.pad.guid.IsValid()) { - new_input.Set("guid", data.pad.guid.Format()); + new_input.Set("guid", data.pad.guid.RawString()); } new_input.Set("port", static_cast(data.pad.port)); new_input.Set("pad", static_cast(data.pad.pad)); @@ -93,7 +93,7 @@ void MappingFactory::RegisterStick(const MappingData& data) { Common::ParamPackage new_input; new_input.Set("engine", data.engine); if (data.pad.guid.IsValid()) { - new_input.Set("guid", data.pad.guid.Format()); + new_input.Set("guid", data.pad.guid.RawString()); } new_input.Set("port", static_cast(data.pad.port)); new_input.Set("pad", static_cast(data.pad.pad)); @@ -138,7 +138,7 @@ void MappingFactory::RegisterMotion(const MappingData& data) { Common::ParamPackage new_input; new_input.Set("engine", data.engine); if (data.pad.guid.IsValid()) { - new_input.Set("guid", data.pad.guid.Format()); + new_input.Set("guid", data.pad.guid.RawString()); } new_input.Set("port", static_cast(data.pad.port)); new_input.Set("pad", static_cast(data.pad.pad)); diff --git a/src/yuzu/applets/qt_profile_select.cpp b/src/yuzu/applets/qt_profile_select.cpp index 5b32da923..4cd8f7784 100755 --- 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) { return QtProfileSelectionDialog::tr( "%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. " "00112233-4455-6677-8899-AABBCCDDEEFF))") - .arg(username, QString::fromStdString(uuid.FormatSwitch())); + .arg(username, QString::fromStdString(uuid.FormattedString())); } QString GetImagePath(Common::UUID uuid) { const auto path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / - fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormatSwitch()); + fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormattedString()); return QString::fromStdString(Common::FS::PathToUTF8String(path)); } diff --git a/src/yuzu/configuration/configure_profile_manager.cpp b/src/yuzu/configuration/configure_profile_manager.cpp index 78b6374c0..d9f6dee4e 100755 --- a/src/yuzu/configuration/configure_profile_manager.cpp +++ b/src/yuzu/configuration/configure_profile_manager.cpp @@ -33,10 +33,10 @@ constexpr std::array backup_jpeg{ 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, }; -QString GetImagePath(Common::UUID uuid) { +QString GetImagePath(const Common::UUID& uuid) { const auto path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / - fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormatSwitch()); + fmt::format("system/save/8000000000000010/su/avators/{}.jpg", uuid.FormattedString()); return QString::fromStdString(Common::FS::PathToUTF8String(path)); } @@ -55,10 +55,10 @@ QString FormatUserEntryText(const QString& username, Common::UUID uuid) { return ConfigureProfileManager::tr("%1\n%2", "%1 is the profile username, %2 is the formatted UUID (e.g. " "00112233-4455-6677-8899-AABBCCDDEEFF))") - .arg(username, QString::fromStdString(uuid.FormatSwitch())); + .arg(username, QString::fromStdString(uuid.FormattedString())); } -QPixmap GetIcon(Common::UUID uuid) { +QPixmap GetIcon(const Common::UUID& uuid) { QPixmap icon{GetImagePath(uuid)}; if (!icon) { @@ -200,7 +200,7 @@ void ConfigureProfileManager::AddUser() { return; } - const auto uuid = Common::UUID::Generate(); + const auto uuid = Common::UUID::MakeRandom(); profile_manager->CreateNewUser(uuid, username.toStdString()); item_model->appendRow(new QStandardItem{GetIcon(uuid), FormatUserEntryText(username, uuid)}); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index c788db12d..00c45962d 100755 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1690,7 +1690,7 @@ void GMainWindow::OnGameListOpenFolder(u64 program_id, GameListOpenTarget target const auto user_save_data_path = FileSys::SaveDataFactory::GetFullPath( *system, FileSys::SaveDataSpaceId::NandUser, FileSys::SaveDataType::SaveData, - program_id, user_id->uuid, 0); + program_id, user_id->AsU128(), 0); path = Common::FS::ConcatPathSafe(nand_dir, user_save_data_path); } else {