diff options
| author | 2019-07-03 07:57:03 -0500 | |
|---|---|---|
| committer | 2019-07-03 07:57:03 -0500 | |
| commit | 812fb308216387309cec0ce11f912e5001412dda (patch) | |
| tree | edbf9db5c2c005c459d5d885db7c1c7e247b8085 /src | |
| parent | profile_manager: Add setter for ProfileBase and ProfileData (diff) | |
| download | yuzu-812fb308216387309cec0ce11f912e5001412dda.tar.gz yuzu-812fb308216387309cec0ce11f912e5001412dda.tar.xz yuzu-812fb308216387309cec0ce11f912e5001412dda.zip | |
acc: Implement IProfileEditor-specific commands 'Store' and 'StoreWithImage'
Verified with IDA
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/acc/acc.cpp | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index fe4b0e7c3..0b9d1df1c 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -26,6 +26,9 @@ | |||
| 26 | 26 | ||
| 27 | namespace Service::Account { | 27 | namespace Service::Account { |
| 28 | 28 | ||
| 29 | constexpr ResultCode ERR_INVALID_BUFFER_SIZE{ErrorModule::Account, 30}; | ||
| 30 | constexpr ResultCode ERR_FAILED_SAVE_DATA{ErrorModule::Account, 100}; | ||
| 31 | |||
| 29 | static std::string GetImagePath(Common::UUID uuid) { | 32 | static std::string GetImagePath(Common::UUID uuid) { |
| 30 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + | 33 | return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + |
| 31 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; | 34 | "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg"; |
| @@ -133,7 +136,76 @@ protected: | |||
| 133 | } | 136 | } |
| 134 | } | 137 | } |
| 135 | 138 | ||
| 136 | const ProfileManager& profile_manager; | 139 | void Store(Kernel::HLERequestContext& ctx) { |
| 140 | IPC::RequestParser rp{ctx}; | ||
| 141 | const auto base = rp.PopRaw<ProfileBase>(); | ||
| 142 | |||
| 143 | const auto user_data = ctx.ReadBuffer(); | ||
| 144 | |||
| 145 | LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid={}", | ||
| 146 | Common::StringFromFixedZeroTerminatedBuffer( | ||
| 147 | reinterpret_cast<const char*>(base.username.data()), base.username.size()), | ||
| 148 | base.timestamp, base.user_uuid.Format()); | ||
| 149 | |||
| 150 | if (user_data.size() < sizeof(ProfileData)) { | ||
| 151 | LOG_ERROR(Service_ACC, "ProfileData buffer too small!"); | ||
| 152 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 153 | rb.Push(ERR_INVALID_BUFFER_SIZE); | ||
| 154 | return; | ||
| 155 | } | ||
| 156 | |||
| 157 | ProfileData data; | ||
| 158 | std::memcpy(&data, user_data.data(), sizeof(ProfileData)); | ||
| 159 | |||
| 160 | if (!profile_manager.SetProfileBaseAndData(user_id, base, data)) { | ||
| 161 | LOG_ERROR(Service_ACC, "Failed to update profile data and base!"); | ||
| 162 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 163 | rb.Push(ERR_FAILED_SAVE_DATA); | ||
| 164 | return; | ||
| 165 | } | ||
| 166 | |||
| 167 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 168 | rb.Push(RESULT_SUCCESS); | ||
| 169 | } | ||
| 170 | |||
| 171 | void StoreWithImage(Kernel::HLERequestContext& ctx) { | ||
| 172 | IPC::RequestParser rp{ctx}; | ||
| 173 | const auto base = rp.PopRaw<ProfileBase>(); | ||
| 174 | |||
| 175 | const auto user_data = ctx.ReadBuffer(); | ||
| 176 | const auto image_data = ctx.ReadBuffer(1); | ||
| 177 | |||
| 178 | LOG_DEBUG(Service_ACC, "called, username='{}', timestamp={:016X}, uuid={}", | ||
| 179 | Common::StringFromFixedZeroTerminatedBuffer( | ||
| 180 | reinterpret_cast<const char*>(base.username.data()), base.username.size()), | ||
| 181 | base.timestamp, base.user_uuid.Format()); | ||
| 182 | |||
| 183 | if (user_data.size() < sizeof(ProfileData)) { | ||
| 184 | LOG_ERROR(Service_ACC, "ProfileData buffer too small!"); | ||
| 185 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 186 | rb.Push(ERR_INVALID_BUFFER_SIZE); | ||
| 187 | return; | ||
| 188 | } | ||
| 189 | |||
| 190 | ProfileData data; | ||
| 191 | std::memcpy(&data, user_data.data(), sizeof(ProfileData)); | ||
| 192 | |||
| 193 | FileUtil::IOFile image(GetImagePath(user_id), "wb"); | ||
| 194 | |||
| 195 | if (!image.IsOpen() || !image.Resize(image_data.size()) || | ||
| 196 | image.WriteBytes(image_data.data(), image_data.size()) != image_data.size() || | ||
| 197 | !profile_manager.SetProfileBaseAndData(user_id, base, data)) { | ||
| 198 | LOG_ERROR(Service_ACC, "Failed to update profile data, base, and image!"); | ||
| 199 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 200 | rb.Push(ERR_FAILED_SAVE_DATA); | ||
| 201 | return; | ||
| 202 | } | ||
| 203 | |||
| 204 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 205 | rb.Push(RESULT_SUCCESS); | ||
| 206 | } | ||
| 207 | |||
| 208 | ProfileManager& profile_manager; | ||
| 137 | Common::UUID user_id; ///< The user id this profile refers to. | 209 | Common::UUID user_id; ///< The user id this profile refers to. |
| 138 | }; | 210 | }; |
| 139 | 211 | ||