diff options
| author | 2018-08-08 21:09:45 +1000 | |
|---|---|---|
| committer | 2018-08-08 21:09:45 +1000 | |
| commit | 5f8d253ce0a940cdb668861c2c96749c7b9ce626 (patch) | |
| tree | d5de1ee30b41330d09f78c2b3c2b1bb23257211a | |
| parent | Merge pull request #972 from lioncash/catch (diff) | |
| download | yuzu-5f8d253ce0a940cdb668861c2c96749c7b9ce626.tar.gz yuzu-5f8d253ce0a940cdb668861c2c96749c7b9ce626.tar.xz yuzu-5f8d253ce0a940cdb668861c2c96749c7b9ce626.zip | |
Switched uuids from u128 to new UUID struct
| -rw-r--r-- | src/core/hle/service/acc/acc.cpp | 22 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc.h | 37 |
2 files changed, 49 insertions, 10 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index e952b0518..1fb3d96f6 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -3,7 +3,10 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include "common/common_types.h" | ||
| 6 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "common/swap.h" | ||
| 9 | #include "core/core_timing.h" | ||
| 7 | #include "core/hle/ipc_helpers.h" | 10 | #include "core/hle/ipc_helpers.h" |
| 8 | #include "core/hle/service/acc/acc.h" | 11 | #include "core/hle/service/acc/acc.h" |
| 9 | #include "core/hle/service/acc/acc_aa.h" | 12 | #include "core/hle/service/acc/acc_aa.h" |
| @@ -13,7 +16,6 @@ | |||
| 13 | #include "core/settings.h" | 16 | #include "core/settings.h" |
| 14 | 17 | ||
| 15 | namespace Service::Account { | 18 | namespace Service::Account { |
| 16 | |||
| 17 | // TODO: RE this structure | 19 | // TODO: RE this structure |
| 18 | struct UserData { | 20 | struct UserData { |
| 19 | INSERT_PADDING_WORDS(1); | 21 | INSERT_PADDING_WORDS(1); |
| @@ -33,11 +35,11 @@ struct ProfileBase { | |||
| 33 | static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase structure has incorrect size"); | 35 | static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase structure has incorrect size"); |
| 34 | 36 | ||
| 35 | // TODO(ogniK): Generate a real user id based on username, md5(username) maybe? | 37 | // TODO(ogniK): Generate a real user id based on username, md5(username) maybe? |
| 36 | static constexpr u128 DEFAULT_USER_ID{1ull, 0ull}; | 38 | static UUID DEFAULT_USER_ID{1ull, 0ull}; |
| 37 | 39 | ||
| 38 | class IProfile final : public ServiceFramework<IProfile> { | 40 | class IProfile final : public ServiceFramework<IProfile> { |
| 39 | public: | 41 | public: |
| 40 | explicit IProfile(u128 user_id) : ServiceFramework("IProfile"), user_id(user_id) { | 42 | explicit IProfile(UUID user_id) : ServiceFramework("IProfile"), user_id(user_id) { |
| 41 | static const FunctionInfo functions[] = { | 43 | static const FunctionInfo functions[] = { |
| 42 | {0, &IProfile::Get, "Get"}, | 44 | {0, &IProfile::Get, "Get"}, |
| 43 | {1, &IProfile::GetBase, "GetBase"}, | 45 | {1, &IProfile::GetBase, "GetBase"}, |
| @@ -51,7 +53,7 @@ private: | |||
| 51 | void Get(Kernel::HLERequestContext& ctx) { | 53 | void Get(Kernel::HLERequestContext& ctx) { |
| 52 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 54 | LOG_WARNING(Service_ACC, "(STUBBED) called"); |
| 53 | ProfileBase profile_base{}; | 55 | ProfileBase profile_base{}; |
| 54 | profile_base.user_id = user_id; | 56 | profile_base.user_id = user_id.uuid; |
| 55 | if (Settings::values.username.size() > profile_base.username.size()) { | 57 | if (Settings::values.username.size() > profile_base.username.size()) { |
| 56 | std::copy_n(Settings::values.username.begin(), profile_base.username.size(), | 58 | std::copy_n(Settings::values.username.begin(), profile_base.username.size(), |
| 57 | profile_base.username.begin()); | 59 | profile_base.username.begin()); |
| @@ -70,7 +72,7 @@ private: | |||
| 70 | 72 | ||
| 71 | // TODO(Subv): Retrieve this information from somewhere. | 73 | // TODO(Subv): Retrieve this information from somewhere. |
| 72 | ProfileBase profile_base{}; | 74 | ProfileBase profile_base{}; |
| 73 | profile_base.user_id = user_id; | 75 | profile_base.user_id = user_id.uuid; |
| 74 | if (Settings::values.username.size() > profile_base.username.size()) { | 76 | if (Settings::values.username.size() > profile_base.username.size()) { |
| 75 | std::copy_n(Settings::values.username.begin(), profile_base.username.size(), | 77 | std::copy_n(Settings::values.username.begin(), profile_base.username.size(), |
| 76 | profile_base.username.begin()); | 78 | profile_base.username.begin()); |
| @@ -83,7 +85,7 @@ private: | |||
| 83 | rb.PushRaw(profile_base); | 85 | rb.PushRaw(profile_base); |
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | u128 user_id; ///< The user id this profile refers to. | 88 | UUID user_id; ///< The user id this profile refers to. |
| 87 | }; | 89 | }; |
| 88 | 90 | ||
| 89 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { | 91 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { |
| @@ -136,7 +138,7 @@ void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { | |||
| 136 | void Module::Interface::ListAllUsers(Kernel::HLERequestContext& ctx) { | 138 | void Module::Interface::ListAllUsers(Kernel::HLERequestContext& ctx) { |
| 137 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 139 | LOG_WARNING(Service_ACC, "(STUBBED) called"); |
| 138 | // TODO(Subv): There is only one user for now. | 140 | // TODO(Subv): There is only one user for now. |
| 139 | const std::vector<u128> user_ids = {DEFAULT_USER_ID}; | 141 | const std::vector<UUID> user_ids = {DEFAULT_USER_ID}; |
| 140 | ctx.WriteBuffer(user_ids); | 142 | ctx.WriteBuffer(user_ids); |
| 141 | IPC::ResponseBuilder rb{ctx, 2}; | 143 | IPC::ResponseBuilder rb{ctx, 2}; |
| 142 | rb.Push(RESULT_SUCCESS); | 144 | rb.Push(RESULT_SUCCESS); |
| @@ -145,7 +147,7 @@ void Module::Interface::ListAllUsers(Kernel::HLERequestContext& ctx) { | |||
| 145 | void Module::Interface::ListOpenUsers(Kernel::HLERequestContext& ctx) { | 147 | void Module::Interface::ListOpenUsers(Kernel::HLERequestContext& ctx) { |
| 146 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 148 | LOG_WARNING(Service_ACC, "(STUBBED) called"); |
| 147 | // TODO(Subv): There is only one user for now. | 149 | // TODO(Subv): There is only one user for now. |
| 148 | const std::vector<u128> user_ids = {DEFAULT_USER_ID}; | 150 | const std::vector<UUID> user_ids = {DEFAULT_USER_ID}; |
| 149 | ctx.WriteBuffer(user_ids); | 151 | ctx.WriteBuffer(user_ids); |
| 150 | IPC::ResponseBuilder rb{ctx, 2}; | 152 | IPC::ResponseBuilder rb{ctx, 2}; |
| 151 | rb.Push(RESULT_SUCCESS); | 153 | rb.Push(RESULT_SUCCESS); |
| @@ -153,11 +155,11 @@ void Module::Interface::ListOpenUsers(Kernel::HLERequestContext& ctx) { | |||
| 153 | 155 | ||
| 154 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { | 156 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { |
| 155 | IPC::RequestParser rp{ctx}; | 157 | IPC::RequestParser rp{ctx}; |
| 156 | u128 user_id = rp.PopRaw<u128>(); | 158 | UUID user_id = rp.PopRaw<UUID>(); |
| 157 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 159 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 158 | rb.Push(RESULT_SUCCESS); | 160 | rb.Push(RESULT_SUCCESS); |
| 159 | rb.PushIpcInterface<IProfile>(user_id); | 161 | rb.PushIpcInterface<IProfile>(user_id); |
| 160 | LOG_DEBUG(Service_ACC, "called user_id=0x{:016X}{:016X}", user_id[1], user_id[0]); | 162 | LOG_DEBUG(Service_ACC, "called user_id={}", user_id.Format()); |
| 161 | } | 163 | } |
| 162 | 164 | ||
| 163 | void Module::Interface::InitializeApplicationInfo(Kernel::HLERequestContext& ctx) { | 165 | void Module::Interface::InitializeApplicationInfo(Kernel::HLERequestContext& ctx) { |
diff --git a/src/core/hle/service/acc/acc.h b/src/core/hle/service/acc/acc.h index 88cabaa01..e392b3557 100644 --- a/src/core/hle/service/acc/acc.h +++ b/src/core/hle/service/acc/acc.h | |||
| @@ -8,6 +8,43 @@ | |||
| 8 | 8 | ||
| 9 | namespace Service::Account { | 9 | namespace Service::Account { |
| 10 | 10 | ||
| 11 | struct UUID { | ||
| 12 | // UUIDs which are 0 are considered invalid! | ||
| 13 | u128 uuid{0, 0}; | ||
| 14 | UUID() = default; | ||
| 15 | explicit UUID(const u128& id) { | ||
| 16 | uuid[0] = id[0]; | ||
| 17 | uuid[1] = id[1]; | ||
| 18 | }; | ||
| 19 | explicit UUID(const u64& lo, const u64& hi) { | ||
| 20 | uuid[0] = lo; | ||
| 21 | uuid[1] = hi; | ||
| 22 | }; | ||
| 23 | operator bool() const { | ||
| 24 | return uuid[0] != 0x0 && uuid[1] != 0x0; | ||
| 25 | } | ||
| 26 | |||
| 27 | bool operator==(const UUID& rhs) { | ||
| 28 | return uuid[0] == rhs.uuid[0] && uuid[1] == rhs.uuid[1]; | ||
| 29 | } | ||
| 30 | |||
| 31 | bool operator!=(const UUID& rhs) { | ||
| 32 | return uuid[0] != rhs.uuid[0] || uuid[1] != rhs.uuid[1]; | ||
| 33 | } | ||
| 34 | |||
| 35 | // TODO(ogniK): Properly generate uuids based on RFC-4122 | ||
| 36 | const UUID& Generate() { | ||
| 37 | uuid[0] = (static_cast<u64>(std::rand()) << 32) | std::rand(); | ||
| 38 | uuid[1] = (static_cast<u64>(std::rand()) << 32) | std::rand(); | ||
| 39 | return *this; | ||
| 40 | } | ||
| 41 | |||
| 42 | std::string Format() { | ||
| 43 | return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]); | ||
| 44 | } | ||
| 45 | }; | ||
| 46 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); | ||
| 47 | |||
| 11 | class Module final { | 48 | class Module final { |
| 12 | public: | 49 | public: |
| 13 | class Interface : public ServiceFramework<Interface> { | 50 | class Interface : public ServiceFramework<Interface> { |