2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-07-27 19:39:30 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "common/logging/log.h"
|
2023-02-19 19:42:12 +00:00
|
|
|
#include "core/hle/service/ipc_helpers.h"
|
2018-07-27 19:39:30 +00:00
|
|
|
#include "core/hle/service/mii/mii.h"
|
2021-07-14 04:52:17 +00:00
|
|
|
#include "core/hle/service/mii/mii_manager.h"
|
2023-09-11 02:43:26 +00:00
|
|
|
#include "core/hle/service/mii/mii_result.h"
|
2023-02-18 21:26:48 +00:00
|
|
|
#include "core/hle/service/server_manager.h"
|
2018-07-27 19:39:30 +00:00
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
|
|
|
namespace Service::Mii {
|
|
|
|
|
|
|
|
class IDatabaseService final : public ServiceFramework<IDatabaseService> {
|
|
|
|
public:
|
2023-09-11 06:58:46 +00:00
|
|
|
explicit IDatabaseService(Core::System& system_, bool is_system_)
|
|
|
|
: ServiceFramework{system_, "IDatabaseService"}, is_system{is_system_} {
|
2018-07-27 19:39:30 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-12-18 14:09:52 +00:00
|
|
|
{0, &IDatabaseService::IsUpdated, "IsUpdated"},
|
|
|
|
{1, &IDatabaseService::IsFullDatabase, "IsFullDatabase"},
|
|
|
|
{2, &IDatabaseService::GetCount, "GetCount"},
|
|
|
|
{3, &IDatabaseService::Get, "Get"},
|
|
|
|
{4, &IDatabaseService::Get1, "Get1"},
|
2020-07-11 02:52:07 +00:00
|
|
|
{5, &IDatabaseService::UpdateLatest, "UpdateLatest"},
|
2018-12-18 14:09:52 +00:00
|
|
|
{6, &IDatabaseService::BuildRandom, "BuildRandom"},
|
|
|
|
{7, &IDatabaseService::BuildDefault, "BuildDefault"},
|
2020-07-11 02:52:07 +00:00
|
|
|
{8, nullptr, "Get2"},
|
|
|
|
{9, nullptr, "Get3"},
|
2018-07-27 19:39:30 +00:00
|
|
|
{10, nullptr, "UpdateLatest1"},
|
2020-07-11 02:52:07 +00:00
|
|
|
{11, nullptr, "FindIndex"},
|
|
|
|
{12, nullptr, "Move"},
|
|
|
|
{13, nullptr, "AddOrReplace"},
|
|
|
|
{14, nullptr, "Delete"},
|
|
|
|
{15, nullptr, "DestroyFile"},
|
|
|
|
{16, nullptr, "DeleteFile"},
|
|
|
|
{17, nullptr, "Format"},
|
2018-07-27 19:39:30 +00:00
|
|
|
{18, nullptr, "Import"},
|
|
|
|
{19, nullptr, "Export"},
|
|
|
|
{20, nullptr, "IsBrokenDatabaseWithClearFlag"},
|
2018-12-18 14:09:52 +00:00
|
|
|
{21, &IDatabaseService::GetIndex, "GetIndex"},
|
2019-07-07 01:39:04 +00:00
|
|
|
{22, &IDatabaseService::SetInterfaceVersion, "SetInterfaceVersion"},
|
2022-08-30 05:33:47 +00:00
|
|
|
{23, &IDatabaseService::Convert, "Convert"},
|
2019-11-12 13:54:58 +00:00
|
|
|
{24, nullptr, "ConvertCoreDataToCharInfo"},
|
|
|
|
{25, nullptr, "ConvertCharInfoToCoreData"},
|
2020-10-28 01:19:44 +00:00
|
|
|
{26, nullptr, "Append"},
|
2018-07-27 19:39:30 +00:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-12-18 14:09:52 +00:00
|
|
|
|
|
|
|
private:
|
2023-02-19 19:42:12 +00:00
|
|
|
void IsUpdated(HLERequestContext& ctx) {
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-11 02:52:07 +00:00
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}", source_flag);
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
const bool is_updated = manager.IsUpdated(metadata, source_flag);
|
|
|
|
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.Push<u8>(is_updated);
|
2018-12-18 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void IsFullDatabase(HLERequestContext& ctx) {
|
2018-12-18 14:09:52 +00:00
|
|
|
LOG_DEBUG(Service_Mii, "called");
|
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
const bool is_full_database = manager.IsFullDatabase();
|
|
|
|
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.Push<u8>(is_full_database);
|
2018-12-18 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void GetCount(HLERequestContext& ctx) {
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-11 02:52:07 +00:00
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}", source_flag);
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
const u32 mii_count = manager.GetCount(metadata, source_flag);
|
|
|
|
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.Push(mii_count);
|
2018-12-18 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void Get(HLERequestContext& ctx) {
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-11 02:52:07 +00:00
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2023-09-11 06:58:46 +00:00
|
|
|
const auto output_size{ctx.GetWriteBufferNumElements<CharInfoElement>()};
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}, out_size={}", source_flag, output_size);
|
|
|
|
|
|
|
|
u32 mii_count{};
|
|
|
|
std::vector<CharInfoElement> char_info_elements(output_size);
|
|
|
|
Result result = manager.Get(metadata, char_info_elements, mii_count, source_flag);
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
if (mii_count != 0) {
|
|
|
|
ctx.WriteBuffer(char_info_elements);
|
2020-07-11 02:52:07 +00:00
|
|
|
}
|
2018-12-18 14:09:52 +00:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.Push(result);
|
|
|
|
rb.Push(mii_count);
|
2018-12-18 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void Get1(HLERequestContext& ctx) {
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-11 02:52:07 +00:00
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2023-09-11 06:58:46 +00:00
|
|
|
const auto output_size{ctx.GetWriteBufferNumElements<CharInfo>()};
|
2018-12-28 01:54:44 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}, out_size={}", source_flag, output_size);
|
2018-12-28 01:54:44 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
u32 mii_count{};
|
|
|
|
std::vector<CharInfo> char_info(output_size);
|
|
|
|
Result result = manager.Get(metadata, char_info, mii_count, source_flag);
|
2018-12-28 01:54:44 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
if (mii_count != 0) {
|
|
|
|
ctx.WriteBuffer(char_info);
|
2018-12-28 01:54:44 +00:00
|
|
|
}
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.Push(result);
|
|
|
|
rb.Push(mii_count);
|
2018-12-18 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void UpdateLatest(HLERequestContext& ctx) {
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
2023-09-11 06:58:46 +00:00
|
|
|
const auto char_info{rp.PopRaw<CharInfo>()};
|
2020-07-11 02:52:07 +00:00
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}", source_flag);
|
|
|
|
|
2023-07-15 00:16:39 +00:00
|
|
|
CharInfo new_char_info{};
|
2023-09-11 06:58:46 +00:00
|
|
|
const auto result = manager.UpdateLatest(metadata, new_char_info, char_info, source_flag);
|
|
|
|
if (result.IsFailure()) {
|
2018-12-28 01:54:44 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2023-07-15 00:16:39 +00:00
|
|
|
rb.Push(result);
|
2018-12-28 01:54:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-30 05:33:47 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2 + sizeof(CharInfo) / sizeof(u32)};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2023-07-15 00:16:39 +00:00
|
|
|
rb.PushRaw<CharInfo>(new_char_info);
|
2018-12-18 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void BuildRandom(HLERequestContext& ctx) {
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-11 02:52:07 +00:00
|
|
|
const auto age{rp.PopRaw<Age>()};
|
|
|
|
const auto gender{rp.PopRaw<Gender>()};
|
|
|
|
const auto race{rp.PopRaw<Race>()};
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
LOG_DEBUG(Service_Mii, "called with age={}, gender={}, race={}", age, gender, race);
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
if (age > Age::All) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2023-09-11 02:43:26 +00:00
|
|
|
rb.Push(ResultInvalidArgument);
|
2020-07-11 02:52:07 +00:00
|
|
|
return;
|
2018-12-18 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
if (gender > Gender::All) {
|
2018-12-28 01:54:44 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2023-09-11 02:43:26 +00:00
|
|
|
rb.Push(ResultInvalidArgument);
|
2018-12-28 01:54:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
if (race > Race::All) {
|
2018-12-28 01:54:44 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2023-09-11 02:43:26 +00:00
|
|
|
rb.Push(ResultInvalidArgument);
|
2018-12-28 01:54:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
CharInfo char_info{};
|
|
|
|
manager.BuildRandom(char_info, age, gender, race);
|
|
|
|
|
2022-08-30 05:33:47 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2 + sizeof(CharInfo) / sizeof(u32)};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.PushRaw<CharInfo>(char_info);
|
2018-12-28 01:54:44 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void BuildDefault(HLERequestContext& ctx) {
|
2020-07-11 02:52:07 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto index{rp.Pop<u32>()};
|
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
LOG_INFO(Service_Mii, "called with index={}", index);
|
2018-12-28 01:54:44 +00:00
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
if (index > 5) {
|
2018-12-28 01:54:44 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2023-09-11 02:43:26 +00:00
|
|
|
rb.Push(ResultInvalidArgument);
|
2018-12-28 01:54:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
CharInfo char_info{};
|
|
|
|
manager.BuildDefault(char_info, index);
|
|
|
|
|
2022-08-30 05:33:47 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2 + sizeof(CharInfo) / sizeof(u32)};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.PushRaw<CharInfo>(char_info);
|
2018-12-18 14:09:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void GetIndex(HLERequestContext& ctx) {
|
2018-12-18 14:09:52 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
2022-08-30 05:33:47 +00:00
|
|
|
const auto info{rp.PopRaw<CharInfo>()};
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
LOG_DEBUG(Service_Mii, "called");
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
s32 index{};
|
|
|
|
const Result result = manager.GetIndex(metadata, info, index);
|
|
|
|
|
2020-07-11 02:52:07 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.Push(result);
|
2018-12-18 14:09:52 +00:00
|
|
|
rb.Push(index);
|
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void SetInterfaceVersion(HLERequestContext& ctx) {
|
2019-07-07 01:39:04 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
2023-09-11 06:58:46 +00:00
|
|
|
const auto interface_version{rp.PopRaw<u32>()};
|
2019-07-07 01:39:04 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
LOG_INFO(Service_Mii, "called, interface_version={:08X}", interface_version);
|
2019-07-07 01:39:04 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
manager.SetInterfaceVersion(metadata, interface_version);
|
2019-07-07 01:39:04 +00:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2019-07-07 01:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-02-19 19:42:12 +00:00
|
|
|
void Convert(HLERequestContext& ctx) {
|
2022-08-30 05:33:47 +00:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto mii_v3{rp.PopRaw<Ver3StoreData>()};
|
|
|
|
|
|
|
|
LOG_INFO(Service_Mii, "called");
|
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
CharInfo char_info{};
|
|
|
|
manager.ConvertV3ToCharInfo(char_info, mii_v3);
|
|
|
|
|
2022-08-30 05:33:47 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2 + sizeof(CharInfo) / sizeof(u32)};
|
|
|
|
rb.Push(ResultSuccess);
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.PushRaw<CharInfo>(char_info);
|
2020-07-11 02:52:07 +00:00
|
|
|
}
|
2018-12-18 14:09:52 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
MiiManager manager{};
|
|
|
|
DatabaseSessionMetadata metadata{};
|
|
|
|
bool is_system{};
|
2018-07-27 19:39:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MiiDBModule final : public ServiceFramework<MiiDBModule> {
|
|
|
|
public:
|
2023-09-11 06:58:46 +00:00
|
|
|
explicit MiiDBModule(Core::System& system_, const char* name_, bool is_system_)
|
|
|
|
: ServiceFramework{system_, name_}, is_system{is_system_} {
|
2018-07-27 19:39:30 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &MiiDBModule::GetDatabaseService, "GetDatabaseService"},
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-02-19 19:42:12 +00:00
|
|
|
void GetDatabaseService(HLERequestContext& ctx) {
|
2018-07-27 19:39:30 +00:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 05:05:04 +00:00
|
|
|
rb.Push(ResultSuccess);
|
2023-09-11 06:58:46 +00:00
|
|
|
rb.PushIpcInterface<IDatabaseService>(system, is_system);
|
2018-07-27 19:39:30 +00:00
|
|
|
|
|
|
|
LOG_DEBUG(Service_Mii, "called");
|
|
|
|
}
|
2023-09-11 06:58:46 +00:00
|
|
|
|
|
|
|
bool is_system{};
|
2018-07-27 19:39:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MiiImg final : public ServiceFramework<MiiImg> {
|
|
|
|
public:
|
2020-11-26 20:19:08 +00:00
|
|
|
explicit MiiImg(Core::System& system_) : ServiceFramework{system_, "miiimg"} {
|
2018-07-27 19:39:30 +00:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, nullptr, "Initialize"},
|
|
|
|
{10, nullptr, "Reload"},
|
|
|
|
{11, nullptr, "GetCount"},
|
|
|
|
{12, nullptr, "IsEmpty"},
|
|
|
|
{13, nullptr, "IsFull"},
|
|
|
|
{14, nullptr, "GetAttribute"},
|
|
|
|
{15, nullptr, "LoadImage"},
|
|
|
|
{16, nullptr, "AddOrUpdateImage"},
|
|
|
|
{17, nullptr, "DeleteImages"},
|
|
|
|
{100, nullptr, "DeleteFile"},
|
|
|
|
{101, nullptr, "DestroyFile"},
|
|
|
|
{102, nullptr, "ImportFile"},
|
|
|
|
{103, nullptr, "ExportFile"},
|
|
|
|
{104, nullptr, "ForceInitialize"},
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-02-18 21:26:48 +00:00
|
|
|
void LoopProcess(Core::System& system) {
|
|
|
|
auto server_manager = std::make_unique<ServerManager>(system);
|
2018-07-27 19:39:30 +00:00
|
|
|
|
2023-09-11 06:58:46 +00:00
|
|
|
server_manager->RegisterNamedService("mii:e",
|
|
|
|
std::make_shared<MiiDBModule>(system, "mii:e", true));
|
|
|
|
server_manager->RegisterNamedService("mii:u",
|
|
|
|
std::make_shared<MiiDBModule>(system, "mii:u", false));
|
2023-02-18 21:26:48 +00:00
|
|
|
server_manager->RegisterNamedService("miiimg", std::make_shared<MiiImg>(system));
|
|
|
|
ServerManager::RunServer(std::move(server_manager));
|
2018-07-27 19:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::Mii
|