summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-10-13 13:02:33 -0400
committerGravatar Zach Hilman2018-10-23 19:31:28 -0400
commit45f2a2fe29373f261144c097d169dad8b65fe012 (patch)
tree610b04ce839b40eaab1fe297c625b34eaf76e9cd /src/core
parentconfigure_system: Clear selection after user delete (diff)
downloadyuzu-45f2a2fe29373f261144c097d169dad8b65fe012.tar.gz
yuzu-45f2a2fe29373f261144c097d169dad8b65fe012.tar.xz
yuzu-45f2a2fe29373f261144c097d169dad8b65fe012.zip
acc: Fix account UUID duplication error
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/service/acc/acc.cpp9
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp24
-rw-r--r--src/core/hle/service/acc/profile_manager.h2
-rw-r--r--src/core/hle/service/am/am.cpp29
4 files changed, 47 insertions, 17 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp
index cee309cb1..cf065c2e0 100644
--- a/src/core/hle/service/acc/acc.cpp
+++ b/src/core/hle/service/acc/acc.cpp
@@ -106,6 +106,8 @@ private:
106 const FileUtil::IOFile image(GetImagePath(user_id), "rb"); 106 const FileUtil::IOFile image(GetImagePath(user_id), "rb");
107 107
108 if (!image.IsOpen()) { 108 if (!image.IsOpen()) {
109 LOG_WARNING(Service_ACC,
110 "Failed to load user provided image! Falling back to built-in backup...");
109 ctx.WriteBuffer(backup_jpeg); 111 ctx.WriteBuffer(backup_jpeg);
110 rb.Push<u32>(backup_jpeg_size); 112 rb.Push<u32>(backup_jpeg_size);
111 } else { 113 } else {
@@ -126,10 +128,13 @@ private:
126 128
127 const FileUtil::IOFile image(GetImagePath(user_id), "rb"); 129 const FileUtil::IOFile image(GetImagePath(user_id), "rb");
128 130
129 if (!image.IsOpen()) 131 if (!image.IsOpen()) {
132 LOG_WARNING(Service_ACC,
133 "Failed to load user provided image! Falling back to built-in backup...");
130 rb.Push<u32>(backup_jpeg_size); 134 rb.Push<u32>(backup_jpeg_size);
131 else 135 } else {
132 rb.Push<u32>(std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE)); 136 rb.Push<u32>(std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE));
137 }
133 } 138 }
134 139
135 const ProfileManager& profile_manager; 140 const ProfileManager& profile_manager;
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 43743d39e..e6f1a0ae8 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -30,6 +30,8 @@ constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1);
30constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); 30constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2);
31constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); 31constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20);
32 32
33constexpr const char* ACC_SAVE_AVATORS_BASE_PATH = "/system/save/8000000000000010/su/avators/";
34
33const UUID& UUID::Generate() { 35const UUID& UUID::Generate() {
34 std::random_device device; 36 std::random_device device;
35 std::mt19937 gen(device()); 37 std::mt19937 gen(device());
@@ -45,11 +47,11 @@ ProfileManager::ProfileManager() {
45 if (user_count == 0) 47 if (user_count == 0)
46 CreateNewUser(UUID{}.Generate(), "yuzu"); 48 CreateNewUser(UUID{}.Generate(), "yuzu");
47 49
48 auto current = Settings::values.current_user; 50 auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1);
49 if (!GetAllUsers()[current]) 51 if (UserExistsIndex(current))
50 current = 0; 52 current = 0;
51 53
52 OpenUser(GetAllUsers()[current]); 54 OpenUser(*GetUser(current));
53} 55}
54 56
55ProfileManager::~ProfileManager() { 57ProfileManager::~ProfileManager() {
@@ -126,6 +128,12 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username)
126 return CreateNewUser(uuid, username_output); 128 return CreateNewUser(uuid, username_output);
127} 129}
128 130
131boost::optional<UUID> ProfileManager::GetUser(std::size_t index) const {
132 if (index >= MAX_USERS)
133 return boost::none;
134 return profiles[index].user_uuid;
135}
136
129/// Returns a users profile index based on their user id. 137/// Returns a users profile index based on their user id.
130boost::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { 138boost::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
131 if (!uuid) { 139 if (!uuid) {
@@ -189,6 +197,12 @@ bool ProfileManager::UserExists(UUID uuid) const {
189 return (GetUserIndex(uuid) != boost::none); 197 return (GetUserIndex(uuid) != boost::none);
190} 198}
191 199
200bool ProfileManager::UserExistsIndex(std::size_t index) const {
201 if (index >= MAX_USERS)
202 return false;
203 return profiles[index].user_uuid.uuid != INVALID_UUID;
204}
205
192/// Opens a specific user 206/// Opens a specific user
193void ProfileManager::OpenUser(UUID uuid) { 207void ProfileManager::OpenUser(UUID uuid) {
194 auto idx = GetUserIndex(uuid); 208 auto idx = GetUserIndex(uuid);
@@ -292,7 +306,7 @@ bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) {
292 306
293void ProfileManager::ParseUserSaveFile() { 307void ProfileManager::ParseUserSaveFile() {
294 FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + 308 FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
295 "/system/save/8000000000000010/su/avators/profiles.dat", 309 ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat",
296 "rb"); 310 "rb");
297 311
298 ProfileDataRaw data; 312 ProfileDataRaw data;
@@ -322,7 +336,7 @@ void ProfileManager::WriteUserSaveFile() {
322 } 336 }
323 337
324 FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + 338 FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
325 "/system/save/8000000000000010/su/avators/profiles.dat", 339 ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat",
326 "wb"); 340 "wb");
327 341
328 save.Resize(sizeof(ProfileDataRaw)); 342 save.Resize(sizeof(ProfileDataRaw));
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h
index 1e5c2460e..482c1d8a9 100644
--- a/src/core/hle/service/acc/profile_manager.h
+++ b/src/core/hle/service/acc/profile_manager.h
@@ -96,6 +96,7 @@ public:
96 ResultCode AddUser(const ProfileInfo& user); 96 ResultCode AddUser(const ProfileInfo& user);
97 ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); 97 ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username);
98 ResultCode CreateNewUser(UUID uuid, const std::string& username); 98 ResultCode CreateNewUser(UUID uuid, const std::string& username);
99 boost::optional<UUID> GetUser(std::size_t index) const;
99 boost::optional<std::size_t> GetUserIndex(const UUID& uuid) const; 100 boost::optional<std::size_t> GetUserIndex(const UUID& uuid) const;
100 boost::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const; 101 boost::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const;
101 bool GetProfileBase(boost::optional<std::size_t> index, ProfileBase& profile) const; 102 bool GetProfileBase(boost::optional<std::size_t> index, ProfileBase& profile) const;
@@ -109,6 +110,7 @@ public:
109 std::size_t GetUserCount() const; 110 std::size_t GetUserCount() const;
110 std::size_t GetOpenUserCount() const; 111 std::size_t GetOpenUserCount() const;
111 bool UserExists(UUID uuid) const; 112 bool UserExists(UUID uuid) const;
113 bool UserExistsIndex(std::size_t index) const;
112 void OpenUser(UUID uuid); 114 void OpenUser(UUID uuid);
113 void CloseUser(UUID uuid); 115 void CloseUser(UUID uuid);
114 UserIDArray GetOpenUsers() const; 116 UserIDArray GetOpenUsers() const;
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 9dfcec59b..4ed66d817 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -28,7 +28,15 @@
28 28
29namespace Service::AM { 29namespace Service::AM {
30 30
31constexpr std::size_t POP_LAUNCH_PARAMETER_BUFFER_SIZE = 0x88; 31constexpr u32 POP_LAUNCH_PARAMETER_MAGIC = 0xC79497CA;
32
33struct LaunchParameters {
34 u32_le magic;
35 u32_le is_account_selected;
36 u128 current_user;
37 INSERT_PADDING_BYTES(0x70);
38};
39static_assert(sizeof(LaunchParameters) == 0x88);
32 40
33IWindowController::IWindowController() : ServiceFramework("IWindowController") { 41IWindowController::IWindowController() : ServiceFramework("IWindowController") {
34 // clang-format off 42 // clang-format off
@@ -728,22 +736,23 @@ void IApplicationFunctions::EndBlockingHomeButton(Kernel::HLERequestContext& ctx
728} 736}
729 737
730void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) { 738void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
731 constexpr std::array<u8, 0x8> header_data{ 739 LaunchParameters params{};
732 0xca, 0x97, 0x94, 0xc7, // Magic
733 1, 0, 0, 0, // IsAccountSelected (bool)
734 };
735 740
736 std::vector<u8> buffer(POP_LAUNCH_PARAMETER_BUFFER_SIZE); 741 params.magic = POP_LAUNCH_PARAMETER_MAGIC;
737 742 params.is_account_selected = 1;
738 std::memcpy(buffer.data(), header_data.data(), header_data.size());
739 743
740 Account::ProfileManager profile_manager{}; 744 Account::ProfileManager profile_manager{};
741 const auto uuid = profile_manager.GetAllUsers()[Settings::values.current_user].uuid; 745 const auto uuid = profile_manager.GetUser(Settings::values.current_user);
742 std::memcpy(buffer.data() + header_data.size(), uuid.data(), sizeof(u128)); 746 ASSERT(uuid != boost::none);
747 params.current_user = uuid->uuid;
743 748
744 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 749 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
745 750
746 rb.Push(RESULT_SUCCESS); 751 rb.Push(RESULT_SUCCESS);
752
753 std::vector<u8> buffer(sizeof(LaunchParameters));
754 std::memcpy(buffer.data(), &params, buffer.size());
755
747 rb.PushIpcInterface<AM::IStorage>(buffer); 756 rb.PushIpcInterface<AM::IStorage>(buffer);
748 757
749 LOG_DEBUG(Service_AM, "called"); 758 LOG_DEBUG(Service_AM, "called");