diff options
Diffstat (limited to 'src/core/hle')
| -rw-r--r-- | src/core/hle/service/mii/mii.cpp | 257 |
1 files changed, 242 insertions, 15 deletions
diff --git a/src/core/hle/service/mii/mii.cpp b/src/core/hle/service/mii/mii.cpp index a6197124a..c2263569d 100644 --- a/src/core/hle/service/mii/mii.cpp +++ b/src/core/hle/service/mii/mii.cpp | |||
| @@ -5,9 +5,11 @@ | |||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | 6 | ||
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "common/string_util.h" | ||
| 8 | #include "core/hle/ipc_helpers.h" | 9 | #include "core/hle/ipc_helpers.h" |
| 9 | #include "core/hle/kernel/hle_ipc.h" | 10 | #include "core/hle/kernel/hle_ipc.h" |
| 10 | #include "core/hle/service/mii/mii.h" | 11 | #include "core/hle/service/mii/mii.h" |
| 12 | #include "core/hle/service/mii/mii_manager.h" | ||
| 11 | #include "core/hle/service/service.h" | 13 | #include "core/hle/service/service.h" |
| 12 | #include "core/hle/service/sm/sm.h" | 14 | #include "core/hle/service/sm/sm.h" |
| 13 | 15 | ||
| @@ -18,28 +20,28 @@ public: | |||
| 18 | explicit IDatabaseService() : ServiceFramework{"IDatabaseService"} { | 20 | explicit IDatabaseService() : ServiceFramework{"IDatabaseService"} { |
| 19 | // clang-format off | 21 | // clang-format off |
| 20 | static const FunctionInfo functions[] = { | 22 | static const FunctionInfo functions[] = { |
| 21 | {0, nullptr, "IsUpdated"}, | 23 | {0, &IDatabaseService::IsUpdated, "IsUpdated"}, |
| 22 | {1, nullptr, "IsFullDatabase"}, | 24 | {1, &IDatabaseService::IsFullDatabase, "IsFullDatabase"}, |
| 23 | {2, nullptr, "GetCount"}, | 25 | {2, &IDatabaseService::GetCount, "GetCount"}, |
| 24 | {3, nullptr, "Get"}, | 26 | {3, &IDatabaseService::Get, "Get"}, |
| 25 | {4, nullptr, "Get1"}, | 27 | {4, &IDatabaseService::Get1, "Get1"}, |
| 26 | {5, nullptr, "UpdateLatest"}, | 28 | {5, nullptr, "UpdateLatest"}, |
| 27 | {6, nullptr, "BuildRandom"}, | 29 | {6, &IDatabaseService::BuildRandom, "BuildRandom"}, |
| 28 | {7, nullptr, "BuildDefault"}, | 30 | {7, &IDatabaseService::BuildDefault, "BuildDefault"}, |
| 29 | {8, nullptr, "Get2"}, | 31 | {8, &IDatabaseService::Get2, "Get2"}, |
| 30 | {9, nullptr, "Get3"}, | 32 | {9, &IDatabaseService::Get3, "Get3"}, |
| 31 | {10, nullptr, "UpdateLatest1"}, | 33 | {10, nullptr, "UpdateLatest1"}, |
| 32 | {11, nullptr, "FindIndex"}, | 34 | {11, &IDatabaseService::FindIndex, "FindIndex"}, |
| 33 | {12, nullptr, "Move"}, | 35 | {12, &IDatabaseService::Move, "Move"}, |
| 34 | {13, nullptr, "AddOrReplace"}, | 36 | {13, &IDatabaseService::AddOrReplace, "AddOrReplace"}, |
| 35 | {14, nullptr, "Delete"}, | 37 | {14, &IDatabaseService::Delete, "Delete"}, |
| 36 | {15, nullptr, "DestroyFile"}, | 38 | {15, nullptr, "DestroyFile"}, |
| 37 | {16, nullptr, "DeleteFile"}, | 39 | {16, nullptr, "DeleteFile"}, |
| 38 | {17, nullptr, "Format"}, | 40 | {17, &IDatabaseService::Format, "Format"}, |
| 39 | {18, nullptr, "Import"}, | 41 | {18, nullptr, "Import"}, |
| 40 | {19, nullptr, "Export"}, | 42 | {19, nullptr, "Export"}, |
| 41 | {20, nullptr, "IsBrokenDatabaseWithClearFlag"}, | 43 | {20, nullptr, "IsBrokenDatabaseWithClearFlag"}, |
| 42 | {21, nullptr, "GetIndex"}, | 44 | {21, &IDatabaseService::GetIndex, "GetIndex"}, |
| 43 | {22, nullptr, "SetInterfaceVersion"}, | 45 | {22, nullptr, "SetInterfaceVersion"}, |
| 44 | {23, nullptr, "Convert"}, | 46 | {23, nullptr, "Convert"}, |
| 45 | }; | 47 | }; |
| @@ -47,6 +49,231 @@ public: | |||
| 47 | 49 | ||
| 48 | RegisterHandlers(functions); | 50 | RegisterHandlers(functions); |
| 49 | } | 51 | } |
| 52 | |||
| 53 | private: | ||
| 54 | template <typename OutType> | ||
| 55 | std::vector<u8> SerializeArray(OutType (MiiManager::*getter)(u32) const, u32 offset, | ||
| 56 | u32 requested_size, u32& read_size) { | ||
| 57 | read_size = std::min(requested_size, db.Size() - offset); | ||
| 58 | |||
| 59 | std::vector<u8> out(read_size * sizeof(OutType)); | ||
| 60 | |||
| 61 | for (u32 i = 0; i < read_size; ++i) { | ||
| 62 | const auto obj = (db.*getter)(offset + i); | ||
| 63 | std::memcpy(out.data() + i * sizeof(OutType), &obj, sizeof(OutType)); | ||
| 64 | } | ||
| 65 | |||
| 66 | return out; | ||
| 67 | } | ||
| 68 | |||
| 69 | void IsUpdated(Kernel::HLERequestContext& ctx) { | ||
| 70 | IPC::RequestParser rp{ctx}; | ||
| 71 | const auto unknown{rp.PopRaw<u32>()}; | ||
| 72 | |||
| 73 | LOG_WARNING(Service_Mii, "(STUBBED) called with unknown={:08X}", unknown); | ||
| 74 | |||
| 75 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 76 | rb.Push(RESULT_SUCCESS); | ||
| 77 | rb.Push(false); | ||
| 78 | } | ||
| 79 | |||
| 80 | void IsFullDatabase(Kernel::HLERequestContext& ctx) { | ||
| 81 | LOG_DEBUG(Service_Mii, "called"); | ||
| 82 | |||
| 83 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 84 | rb.Push(RESULT_SUCCESS); | ||
| 85 | rb.Push(db.Full()); | ||
| 86 | } | ||
| 87 | |||
| 88 | void GetCount(Kernel::HLERequestContext& ctx) { | ||
| 89 | IPC::RequestParser rp{ctx}; | ||
| 90 | const auto unknown{rp.PopRaw<u32>()}; | ||
| 91 | |||
| 92 | LOG_DEBUG(Service_Mii, "called with unknown={:08X}", unknown); | ||
| 93 | |||
| 94 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 95 | rb.Push(RESULT_SUCCESS); | ||
| 96 | rb.Push<u32>(db.Size()); | ||
| 97 | } | ||
| 98 | |||
| 99 | // Gets Miis from database at offset and index in format MiiInfoElement | ||
| 100 | void Get(Kernel::HLERequestContext& ctx) { | ||
| 101 | IPC::RequestParser rp{ctx}; | ||
| 102 | const auto size{rp.PopRaw<u32>()}; | ||
| 103 | |||
| 104 | LOG_DEBUG(Service_Mii, "called with size={:08X}, offset={:08X}", size, offsets[0]); | ||
| 105 | |||
| 106 | u32 read_size{}; | ||
| 107 | ctx.WriteBuffer(SerializeArray(&MiiManager::GetInfoElement, offsets[0], size, read_size)); | ||
| 108 | offsets[0] += read_size; | ||
| 109 | |||
| 110 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 111 | rb.Push(RESULT_SUCCESS); | ||
| 112 | rb.Push<u32>(read_size); | ||
| 113 | } | ||
| 114 | |||
| 115 | // Gets Miis from database at offset and index in format MiiInfo | ||
| 116 | void Get1(Kernel::HLERequestContext& ctx) { | ||
| 117 | IPC::RequestParser rp{ctx}; | ||
| 118 | const auto size{rp.PopRaw<u32>()}; | ||
| 119 | |||
| 120 | LOG_DEBUG(Service_Mii, "called with size={:08X}, offset={:08X}", size, offsets[1]); | ||
| 121 | |||
| 122 | u32 read_size{}; | ||
| 123 | ctx.WriteBuffer(SerializeArray(&MiiManager::GetInfo, offsets[1], size, read_size)); | ||
| 124 | offsets[1] += read_size; | ||
| 125 | |||
| 126 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 127 | rb.Push(RESULT_SUCCESS); | ||
| 128 | rb.Push<u32>(read_size); | ||
| 129 | } | ||
| 130 | |||
| 131 | void BuildRandom(Kernel::HLERequestContext& ctx) { | ||
| 132 | IPC::RequestParser rp{ctx}; | ||
| 133 | const auto random_params{rp.PopRaw<RandomParameters>()}; | ||
| 134 | |||
| 135 | LOG_DEBUG(Service_Mii, "called with param_1={:08X}, param_2={:08X}, param_3={:08X}", | ||
| 136 | random_params.unknown_1, random_params.unknown_2, random_params.unknown_3); | ||
| 137 | |||
| 138 | const auto info = db.CreateRandom(random_params); | ||
| 139 | IPC::ResponseBuilder rb{ctx, 2 + sizeof(MiiInfo) / sizeof(u32)}; | ||
| 140 | rb.Push(RESULT_SUCCESS); | ||
| 141 | rb.PushRaw<MiiInfo>(info); | ||
| 142 | } | ||
| 143 | |||
| 144 | void BuildDefault(Kernel::HLERequestContext& ctx) { | ||
| 145 | IPC::RequestParser rp{ctx}; | ||
| 146 | const auto index{rp.PopRaw<u32>()}; | ||
| 147 | |||
| 148 | LOG_DEBUG(Service_Mii, "called with index={:08X}", index); | ||
| 149 | |||
| 150 | const auto info = db.CreateDefault(index); | ||
| 151 | IPC::ResponseBuilder rb{ctx, 2 + sizeof(MiiInfo) / sizeof(u32)}; | ||
| 152 | rb.Push(RESULT_SUCCESS); | ||
| 153 | rb.PushRaw<MiiInfo>(info); | ||
| 154 | } | ||
| 155 | |||
| 156 | // Gets Miis from database at offset and index in format MiiStoreDataElement | ||
| 157 | void Get2(Kernel::HLERequestContext& ctx) { | ||
| 158 | IPC::RequestParser rp{ctx}; | ||
| 159 | const auto size{rp.PopRaw<u32>()}; | ||
| 160 | |||
| 161 | LOG_DEBUG(Service_Mii, "called with size={:08X}, offset={:08X}", size, offsets[2]); | ||
| 162 | |||
| 163 | u32 read_size{}; | ||
| 164 | ctx.WriteBuffer( | ||
| 165 | SerializeArray(&MiiManager::GetStoreDataElement, offsets[2], size, read_size)); | ||
| 166 | offsets[2] += read_size; | ||
| 167 | |||
| 168 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 169 | rb.Push(RESULT_SUCCESS); | ||
| 170 | rb.Push<u32>(read_size); | ||
| 171 | } | ||
| 172 | |||
| 173 | // Gets Miis from database at offset and index in format MiiStoreData | ||
| 174 | void Get3(Kernel::HLERequestContext& ctx) { | ||
| 175 | IPC::RequestParser rp{ctx}; | ||
| 176 | const auto size{rp.PopRaw<u32>()}; | ||
| 177 | |||
| 178 | LOG_DEBUG(Service_Mii, "called with size={:08X}, offset={:08X}", size, offsets[3]); | ||
| 179 | |||
| 180 | u32 read_size{}; | ||
| 181 | ctx.WriteBuffer(SerializeArray(&MiiManager::GetStoreData, offsets[3], size, read_size)); | ||
| 182 | offsets[3] += read_size; | ||
| 183 | |||
| 184 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 185 | rb.Push(RESULT_SUCCESS); | ||
| 186 | rb.Push<u32>(read_size); | ||
| 187 | } | ||
| 188 | |||
| 189 | void FindIndex(Kernel::HLERequestContext& ctx) { | ||
| 190 | IPC::RequestParser rp{ctx}; | ||
| 191 | const auto uuid{rp.PopRaw<Common::UUID>()}; | ||
| 192 | const auto unknown{rp.PopRaw<bool>()}; | ||
| 193 | |||
| 194 | LOG_DEBUG(Service_Mii, "called with uuid={}, unknown={}", uuid.FormatSwitch(), unknown); | ||
| 195 | |||
| 196 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 197 | |||
| 198 | const auto index = db.IndexOf(uuid); | ||
| 199 | if (index > MAX_MIIS) { | ||
| 200 | // TODO(DarkLordZach): Find a better error code | ||
| 201 | rb.Push(ResultCode(-1)); | ||
| 202 | rb.Push(index); | ||
| 203 | } else { | ||
| 204 | rb.Push(RESULT_SUCCESS); | ||
| 205 | rb.Push(index); | ||
| 206 | } | ||
| 207 | } | ||
| 208 | |||
| 209 | void Move(Kernel::HLERequestContext& ctx) { | ||
| 210 | IPC::RequestParser rp{ctx}; | ||
| 211 | const auto uuid{rp.PopRaw<Common::UUID>()}; | ||
| 212 | const auto index{rp.PopRaw<u32>()}; | ||
| 213 | |||
| 214 | LOG_DEBUG(Service_Mii, "called with uuid={}, index={:08X}", uuid.FormatSwitch(), index); | ||
| 215 | |||
| 216 | const auto success = db.Move(uuid, index); | ||
| 217 | |||
| 218 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 219 | // TODO(DarkLordZach): Find a better error code | ||
| 220 | rb.Push(success ? RESULT_SUCCESS : ResultCode(-1)); | ||
| 221 | } | ||
| 222 | |||
| 223 | void AddOrReplace(Kernel::HLERequestContext& ctx) { | ||
| 224 | IPC::RequestParser rp{ctx}; | ||
| 225 | const auto data{rp.PopRaw<MiiStoreData>()}; | ||
| 226 | |||
| 227 | LOG_DEBUG(Service_Mii, "called with Mii data uuid={}, name={}", data.uuid.FormatSwitch(), | ||
| 228 | Common::UTF16ToUTF8(data.Name())); | ||
| 229 | |||
| 230 | const auto success = db.AddOrReplace(data); | ||
| 231 | |||
| 232 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 233 | // TODO(DarkLordZach): Find a better error code | ||
| 234 | rb.Push(success ? RESULT_SUCCESS : ResultCode(-1)); | ||
| 235 | } | ||
| 236 | |||
| 237 | void Delete(Kernel::HLERequestContext& ctx) { | ||
| 238 | IPC::RequestParser rp{ctx}; | ||
| 239 | const auto uuid{rp.PopRaw<Common::UUID>()}; | ||
| 240 | |||
| 241 | LOG_DEBUG(Service_Mii, "called with uuid={}", uuid.FormatSwitch()); | ||
| 242 | |||
| 243 | const auto success = db.Remove(uuid); | ||
| 244 | |||
| 245 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 246 | // TODO(DarkLordZach): Find a better error code | ||
| 247 | rb.Push(success ? RESULT_SUCCESS : ResultCode(-1)); | ||
| 248 | } | ||
| 249 | |||
| 250 | void Format(Kernel::HLERequestContext& ctx) { | ||
| 251 | LOG_DEBUG(Service_Mii, "called"); | ||
| 252 | |||
| 253 | db.Clear(); | ||
| 254 | |||
| 255 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 256 | rb.Push(RESULT_SUCCESS); | ||
| 257 | } | ||
| 258 | |||
| 259 | void GetIndex(Kernel::HLERequestContext& ctx) { | ||
| 260 | IPC::RequestParser rp{ctx}; | ||
| 261 | const auto info{rp.PopRaw<MiiInfo>()}; | ||
| 262 | |||
| 263 | LOG_DEBUG(Service_Mii, "called with Mii info uuid={}, name={}", info.uuid.FormatSwitch(), | ||
| 264 | Common::UTF16ToUTF8(info.Name())); | ||
| 265 | |||
| 266 | const auto index = db.IndexOf(info); | ||
| 267 | |||
| 268 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 269 | rb.Push(RESULT_SUCCESS); | ||
| 270 | rb.Push(index); | ||
| 271 | } | ||
| 272 | |||
| 273 | MiiManager db; | ||
| 274 | |||
| 275 | // Last read offsets of Get functions | ||
| 276 | std::array<u32, 4> offsets{}; | ||
| 50 | }; | 277 | }; |
| 51 | 278 | ||
| 52 | class MiiDBModule final : public ServiceFramework<MiiDBModule> { | 279 | class MiiDBModule final : public ServiceFramework<MiiDBModule> { |