diff options
Diffstat (limited to 'src/core/hle')
| -rw-r--r-- | src/core/hle/service/acc/acc.cpp | 18 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 22 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 66 |
3 files changed, 28 insertions, 78 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index ba7d7acbd..86bf53d08 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -34,7 +34,7 @@ constexpr std::array<u8, backup_jpeg_size> backup_jpeg{{ | |||
| 34 | 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, | 34 | 0x01, 0x01, 0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9, |
| 35 | }}; | 35 | }}; |
| 36 | 36 | ||
| 37 | static std::string GetImagePath(UUID uuid) { | 37 | static std::string GetImagePath(Common::UUID uuid) { |
| 38 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | 38 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + |
| 39 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; | 39 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; |
| 40 | } | 40 | } |
| @@ -46,7 +46,7 @@ static constexpr u32 SanitizeJPEGSize(std::size_t size) { | |||
| 46 | 46 | ||
| 47 | class IProfile final : public ServiceFramework<IProfile> { | 47 | class IProfile final : public ServiceFramework<IProfile> { |
| 48 | public: | 48 | public: |
| 49 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) | 49 | explicit IProfile(Common::UUID user_id, ProfileManager& profile_manager) |
| 50 | : ServiceFramework("IProfile"), profile_manager(profile_manager), user_id(user_id) { | 50 | : ServiceFramework("IProfile"), profile_manager(profile_manager), user_id(user_id) { |
| 51 | static const FunctionInfo functions[] = { | 51 | static const FunctionInfo functions[] = { |
| 52 | {0, &IProfile::Get, "Get"}, | 52 | {0, &IProfile::Get, "Get"}, |
| @@ -131,7 +131,7 @@ private: | |||
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | const ProfileManager& profile_manager; | 133 | const ProfileManager& profile_manager; |
| 134 | UUID user_id; ///< The user id this profile refers to. | 134 | Common::UUID user_id; ///< The user id this profile refers to. |
| 135 | }; | 135 | }; |
| 136 | 136 | ||
| 137 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { | 137 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { |
| @@ -179,7 +179,7 @@ void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) { | |||
| 179 | 179 | ||
| 180 | void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { | 180 | void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { |
| 181 | IPC::RequestParser rp{ctx}; | 181 | IPC::RequestParser rp{ctx}; |
| 182 | UUID user_id = rp.PopRaw<UUID>(); | 182 | Common::UUID user_id = rp.PopRaw<Common::UUID>(); |
| 183 | LOG_INFO(Service_ACC, "called user_id={}", user_id.Format()); | 183 | LOG_INFO(Service_ACC, "called user_id={}", user_id.Format()); |
| 184 | 184 | ||
| 185 | IPC::ResponseBuilder rb{ctx, 3}; | 185 | IPC::ResponseBuilder rb{ctx, 3}; |
| @@ -205,12 +205,12 @@ void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) { | |||
| 205 | LOG_INFO(Service_ACC, "called"); | 205 | LOG_INFO(Service_ACC, "called"); |
| 206 | IPC::ResponseBuilder rb{ctx, 6}; | 206 | IPC::ResponseBuilder rb{ctx, 6}; |
| 207 | rb.Push(RESULT_SUCCESS); | 207 | rb.Push(RESULT_SUCCESS); |
| 208 | rb.PushRaw<UUID>(profile_manager->GetLastOpenedUser()); | 208 | rb.PushRaw<Common::UUID>(profile_manager->GetLastOpenedUser()); |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { | 211 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { |
| 212 | IPC::RequestParser rp{ctx}; | 212 | IPC::RequestParser rp{ctx}; |
| 213 | UUID user_id = rp.PopRaw<UUID>(); | 213 | Common::UUID user_id = rp.PopRaw<Common::UUID>(); |
| 214 | LOG_DEBUG(Service_ACC, "called user_id={}", user_id.Format()); | 214 | LOG_DEBUG(Service_ACC, "called user_id={}", user_id.Format()); |
| 215 | 215 | ||
| 216 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 216 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| @@ -245,15 +245,15 @@ void Module::Interface::TrySelectUserWithoutInteraction(Kernel::HLERequestContex | |||
| 245 | IPC::ResponseBuilder rb{ctx, 6}; | 245 | IPC::ResponseBuilder rb{ctx, 6}; |
| 246 | if (profile_manager->GetUserCount() != 1) { | 246 | if (profile_manager->GetUserCount() != 1) { |
| 247 | rb.Push(RESULT_SUCCESS); | 247 | rb.Push(RESULT_SUCCESS); |
| 248 | rb.PushRaw<u128>(INVALID_UUID); | 248 | rb.PushRaw<u128>(Common::INVALID_UUID); |
| 249 | return; | 249 | return; |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | const auto user_list = profile_manager->GetAllUsers(); | 252 | const auto user_list = profile_manager->GetAllUsers(); |
| 253 | if (std::all_of(user_list.begin(), user_list.end(), | 253 | if (std::all_of(user_list.begin(), user_list.end(), |
| 254 | [](const auto& user) { return user.uuid == INVALID_UUID; })) { | 254 | [](const auto& user) { return user.uuid == Common::INVALID_UUID; })) { |
| 255 | rb.Push(ResultCode(-1)); // TODO(ogniK): Find the correct error code | 255 | rb.Push(ResultCode(-1)); // TODO(ogniK): Find the correct error code |
| 256 | rb.PushRaw<u128>(INVALID_UUID); | 256 | rb.PushRaw<u128>(Common::INVALID_UUID); |
| 257 | return; | 257 | return; |
| 258 | } | 258 | } |
| 259 | 259 | ||
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 1316d0b07..767523dbc 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -13,6 +13,8 @@ | |||
| 13 | 13 | ||
| 14 | namespace Service::Account { | 14 | namespace Service::Account { |
| 15 | 15 | ||
| 16 | using namespace Common; | ||
| 17 | |||
| 16 | struct UserRaw { | 18 | struct UserRaw { |
| 17 | UUID uuid; | 19 | UUID uuid; |
| 18 | UUID uuid2; | 20 | UUID uuid2; |
| @@ -35,26 +37,6 @@ constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); | |||
| 35 | 37 | ||
| 36 | constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/"; | 38 | constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/"; |
| 37 | 39 | ||
| 38 | UUID UUID::Generate() { | ||
| 39 | std::random_device device; | ||
| 40 | std::mt19937 gen(device()); | ||
| 41 | std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); | ||
| 42 | return UUID{distribution(gen), distribution(gen)}; | ||
| 43 | } | ||
| 44 | |||
| 45 | std::string UUID::Format() const { | ||
| 46 | return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]); | ||
| 47 | } | ||
| 48 | |||
| 49 | std::string UUID::FormatSwitch() const { | ||
| 50 | std::array<u8, 16> s{}; | ||
| 51 | std::memcpy(s.data(), uuid.data(), sizeof(u128)); | ||
| 52 | return fmt::format("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{" | ||
| 53 | ":02x}{:02x}{:02x}{:02x}{:02x}", | ||
| 54 | s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], | ||
| 55 | s[12], s[13], s[14], s[15]); | ||
| 56 | } | ||
| 57 | |||
| 58 | ProfileManager::ProfileManager() { | 40 | ProfileManager::ProfileManager() { |
| 59 | ParseUserSaveFile(); | 41 | ParseUserSaveFile(); |
| 60 | 42 | ||
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index c4ce2e0b3..fd7abb541 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h | |||
| @@ -9,47 +9,15 @@ | |||
| 9 | 9 | ||
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/swap.h" | 11 | #include "common/swap.h" |
| 12 | #include "common/uuid.h" | ||
| 12 | #include "core/hle/result.h" | 13 | #include "core/hle/result.h" |
| 13 | 14 | ||
| 14 | namespace Service::Account { | 15 | namespace Service::Account { |
| 15 | constexpr std::size_t MAX_USERS = 8; | 16 | constexpr std::size_t MAX_USERS = 8; |
| 16 | constexpr u128 INVALID_UUID{{0, 0}}; | ||
| 17 | |||
| 18 | struct UUID { | ||
| 19 | // UUIDs which are 0 are considered invalid! | ||
| 20 | u128 uuid = INVALID_UUID; | ||
| 21 | UUID() = default; | ||
| 22 | explicit UUID(const u128& id) : uuid{id} {} | ||
| 23 | explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {} | ||
| 24 | |||
| 25 | explicit operator bool() const { | ||
| 26 | return uuid != INVALID_UUID; | ||
| 27 | } | ||
| 28 | |||
| 29 | bool operator==(const UUID& rhs) const { | ||
| 30 | return uuid == rhs.uuid; | ||
| 31 | } | ||
| 32 | |||
| 33 | bool operator!=(const UUID& rhs) const { | ||
| 34 | return !operator==(rhs); | ||
| 35 | } | ||
| 36 | |||
| 37 | // TODO(ogniK): Properly generate uuids based on RFC-4122 | ||
| 38 | static UUID Generate(); | ||
| 39 | |||
| 40 | // Set the UUID to {0,0} to be considered an invalid user | ||
| 41 | void Invalidate() { | ||
| 42 | uuid = INVALID_UUID; | ||
| 43 | } | ||
| 44 | |||
| 45 | std::string Format() const; | ||
| 46 | std::string FormatSwitch() const; | ||
| 47 | }; | ||
| 48 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); | ||
| 49 | 17 | ||
| 50 | constexpr std::size_t profile_username_size = 32; | 18 | constexpr std::size_t profile_username_size = 32; |
| 51 | using ProfileUsername = std::array<u8, profile_username_size>; | 19 | using ProfileUsername = std::array<u8, profile_username_size>; |
| 52 | using UserIDArray = std::array<UUID, MAX_USERS>; | 20 | using UserIDArray = std::array<Common::UUID, MAX_USERS>; |
| 53 | 21 | ||
| 54 | /// Contains extra data related to a user. | 22 | /// Contains extra data related to a user. |
| 55 | /// TODO: RE this structure | 23 | /// TODO: RE this structure |
| @@ -66,7 +34,7 @@ static_assert(sizeof(ProfileData) == 0x80, "ProfileData structure has incorrect | |||
| 66 | /// This holds general information about a users profile. This is where we store all the information | 34 | /// This holds general information about a users profile. This is where we store all the information |
| 67 | /// based on a specific user | 35 | /// based on a specific user |
| 68 | struct ProfileInfo { | 36 | struct ProfileInfo { |
| 69 | UUID user_uuid; | 37 | Common::UUID user_uuid; |
| 70 | ProfileUsername username; | 38 | ProfileUsername username; |
| 71 | u64 creation_time; | 39 | u64 creation_time; |
| 72 | ProfileData data; // TODO(ognik): Work out what this is | 40 | ProfileData data; // TODO(ognik): Work out what this is |
| @@ -74,7 +42,7 @@ struct ProfileInfo { | |||
| 74 | }; | 42 | }; |
| 75 | 43 | ||
| 76 | struct ProfileBase { | 44 | struct ProfileBase { |
| 77 | UUID user_uuid; | 45 | Common::UUID user_uuid; |
| 78 | u64_le timestamp; | 46 | u64_le timestamp; |
| 79 | ProfileUsername username; | 47 | ProfileUsername username; |
| 80 | 48 | ||
| @@ -96,33 +64,33 @@ public: | |||
| 96 | ~ProfileManager(); | 64 | ~ProfileManager(); |
| 97 | 65 | ||
| 98 | ResultCode AddUser(const ProfileInfo& user); | 66 | ResultCode AddUser(const ProfileInfo& user); |
| 99 | ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); | 67 | ResultCode CreateNewUser(Common::UUID uuid, const ProfileUsername& username); |
| 100 | ResultCode CreateNewUser(UUID uuid, const std::string& username); | 68 | ResultCode CreateNewUser(Common::UUID uuid, const std::string& username); |
| 101 | std::optional<UUID> GetUser(std::size_t index) const; | 69 | std::optional<Common::UUID> GetUser(std::size_t index) const; |
| 102 | std::optional<std::size_t> GetUserIndex(const UUID& uuid) const; | 70 | std::optional<std::size_t> GetUserIndex(const Common::UUID& uuid) const; |
| 103 | std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; | 71 | std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; |
| 104 | bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const; | 72 | bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const; |
| 105 | bool GetProfileBase(UUID uuid, ProfileBase& profile) const; | 73 | bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const; |
| 106 | bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; | 74 | bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; |
| 107 | bool GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile, | 75 | bool GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile, |
| 108 | ProfileData& data) const; | 76 | ProfileData& data) const; |
| 109 | bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const; | 77 | bool GetProfileBaseAndData(Common::UUID uuid, ProfileBase& profile, ProfileData& data) const; |
| 110 | bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, | 78 | bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, |
| 111 | ProfileData& data) const; | 79 | ProfileData& data) const; |
| 112 | std::size_t GetUserCount() const; | 80 | std::size_t GetUserCount() const; |
| 113 | std::size_t GetOpenUserCount() const; | 81 | std::size_t GetOpenUserCount() const; |
| 114 | bool UserExists(UUID uuid) const; | 82 | bool UserExists(Common::UUID uuid) const; |
| 115 | bool UserExistsIndex(std::size_t index) const; | 83 | bool UserExistsIndex(std::size_t index) const; |
| 116 | void OpenUser(UUID uuid); | 84 | void OpenUser(Common::UUID uuid); |
| 117 | void CloseUser(UUID uuid); | 85 | void CloseUser(Common::UUID uuid); |
| 118 | UserIDArray GetOpenUsers() const; | 86 | UserIDArray GetOpenUsers() const; |
| 119 | UserIDArray GetAllUsers() const; | 87 | UserIDArray GetAllUsers() const; |
| 120 | UUID GetLastOpenedUser() const; | 88 | Common::UUID GetLastOpenedUser() const; |
| 121 | 89 | ||
| 122 | bool CanSystemRegisterUser() const; | 90 | bool CanSystemRegisterUser() const; |
| 123 | 91 | ||
| 124 | bool RemoveUser(UUID uuid); | 92 | bool RemoveUser(Common::UUID uuid); |
| 125 | bool SetProfileBase(UUID uuid, const ProfileBase& profile_new); | 93 | bool SetProfileBase(Common::UUID uuid, const ProfileBase& profile_new); |
| 126 | 94 | ||
| 127 | private: | 95 | private: |
| 128 | void ParseUserSaveFile(); | 96 | void ParseUserSaveFile(); |
| @@ -132,7 +100,7 @@ private: | |||
| 132 | 100 | ||
| 133 | std::array<ProfileInfo, MAX_USERS> profiles{}; | 101 | std::array<ProfileInfo, MAX_USERS> profiles{}; |
| 134 | std::size_t user_count = 0; | 102 | std::size_t user_count = 0; |
| 135 | UUID last_opened_user{INVALID_UUID}; | 103 | Common::UUID last_opened_user{Common::INVALID_UUID}; |
| 136 | }; | 104 | }; |
| 137 | 105 | ||
| 138 | }; // namespace Service::Account | 106 | }; // namespace Service::Account |