2018-07-27 15:39:30 -04:00
|
|
|
// Copyright 2018 yuzu emulator team
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "core/hle/ipc_helpers.h"
|
|
|
|
#include "core/hle/kernel/hle_ipc.h"
|
2020-07-10 22:52:07 -04:00
|
|
|
#include "core/hle/service/mii/manager.h"
|
2018-07-27 15:39:30 -04:00
|
|
|
#include "core/hle/service/mii/mii.h"
|
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
#include "core/hle/service/sm/sm.h"
|
|
|
|
|
|
|
|
namespace Service::Mii {
|
|
|
|
|
2018-12-27 20:54:44 -05:00
|
|
|
constexpr ResultCode ERROR_INVALID_ARGUMENT{ErrorModule::Mii, 1};
|
|
|
|
|
2018-07-27 15:39:30 -04:00
|
|
|
class IDatabaseService final : public ServiceFramework<IDatabaseService> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit IDatabaseService(Core::System& system_)
|
|
|
|
: ServiceFramework{system_, "IDatabaseService"} {
|
2018-07-27 15:39:30 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2018-12-18 09:09:52 -05:00
|
|
|
{0, &IDatabaseService::IsUpdated, "IsUpdated"},
|
|
|
|
{1, &IDatabaseService::IsFullDatabase, "IsFullDatabase"},
|
|
|
|
{2, &IDatabaseService::GetCount, "GetCount"},
|
|
|
|
{3, &IDatabaseService::Get, "Get"},
|
|
|
|
{4, &IDatabaseService::Get1, "Get1"},
|
2020-07-10 22:52:07 -04:00
|
|
|
{5, &IDatabaseService::UpdateLatest, "UpdateLatest"},
|
2018-12-18 09:09:52 -05:00
|
|
|
{6, &IDatabaseService::BuildRandom, "BuildRandom"},
|
|
|
|
{7, &IDatabaseService::BuildDefault, "BuildDefault"},
|
2020-07-10 22:52:07 -04:00
|
|
|
{8, nullptr, "Get2"},
|
|
|
|
{9, nullptr, "Get3"},
|
2018-07-27 15:39:30 -04:00
|
|
|
{10, nullptr, "UpdateLatest1"},
|
2020-07-10 22:52:07 -04: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 15:39:30 -04:00
|
|
|
{18, nullptr, "Import"},
|
|
|
|
{19, nullptr, "Export"},
|
|
|
|
{20, nullptr, "IsBrokenDatabaseWithClearFlag"},
|
2018-12-18 09:09:52 -05:00
|
|
|
{21, &IDatabaseService::GetIndex, "GetIndex"},
|
2019-07-06 21:39:04 -04:00
|
|
|
{22, &IDatabaseService::SetInterfaceVersion, "SetInterfaceVersion"},
|
2018-07-27 15:39:30 -04:00
|
|
|
{23, nullptr, "Convert"},
|
2019-11-12 08:54:58 -05:00
|
|
|
{24, nullptr, "ConvertCoreDataToCharInfo"},
|
|
|
|
{25, nullptr, "ConvertCharInfoToCoreData"},
|
2020-10-27 21:19:44 -04:00
|
|
|
{26, nullptr, "Append"},
|
2018-07-27 15:39:30 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-12-18 09:09:52 -05:00
|
|
|
|
|
|
|
private:
|
2020-07-10 22:52:07 -04:00
|
|
|
template <typename T>
|
|
|
|
std::vector<u8> SerializeArray(const std::vector<T>& values) {
|
|
|
|
std::vector<u8> out(values.size() * sizeof(T));
|
|
|
|
std::size_t offset{};
|
|
|
|
for (const auto& value : values) {
|
|
|
|
std::memcpy(out.data() + offset, &value, sizeof(T));
|
|
|
|
offset += sizeof(T);
|
2018-12-18 09:09:52 -05:00
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IsUpdated(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-10 22:52:07 -04:00
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}", source_flag);
|
2018-12-18 09:09:52 -05:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.Push(manager.CheckAndResetUpdateCounter(source_flag, current_update_counter));
|
2018-12-18 09:09:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void IsFullDatabase(Kernel::HLERequestContext& ctx) {
|
|
|
|
LOG_DEBUG(Service_Mii, "called");
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.Push(manager.IsFullDatabase());
|
2018-12-18 09:09:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetCount(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-10 22:52:07 -04:00
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}", source_flag);
|
2018-12-18 09:09:52 -05:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.Push<u32>(manager.GetCount(source_flag));
|
2018-12-18 09:09:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void Get(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-10 22:52:07 -04:00
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}", source_flag);
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
const auto result{manager.GetDefault(source_flag)};
|
|
|
|
if (result.Failed()) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(result.Code());
|
|
|
|
return;
|
|
|
|
}
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
if (result->size() > 0) {
|
|
|
|
ctx.WriteBuffer(SerializeArray(*result));
|
|
|
|
}
|
2018-12-18 09:09:52 -05:00
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.Push<u32>(static_cast<u32>(result->size()));
|
2018-12-18 09:09:52 -05:00
|
|
|
}
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
void Get1(Kernel::HLERequestContext& ctx) {
|
2018-12-18 09:09:52 -05:00
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-10 22:52:07 -04:00
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2018-12-27 20:54:44 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}", source_flag);
|
2018-12-27 20:54:44 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
const auto result{manager.GetDefault(source_flag)};
|
|
|
|
if (result.Failed()) {
|
2018-12-27 20:54:44 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.Push(result.Code());
|
2018-12-27 20:54:44 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
std::vector<MiiInfo> values;
|
|
|
|
for (const auto& element : *result) {
|
|
|
|
values.emplace_back(element.info);
|
2018-12-27 20:54:44 -05:00
|
|
|
}
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
ctx.WriteBuffer(SerializeArray(values));
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.Push<u32>(static_cast<u32>(result->size()));
|
2018-12-18 09:09:52 -05:00
|
|
|
}
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
void UpdateLatest(Kernel::HLERequestContext& ctx) {
|
2018-12-18 09:09:52 -05:00
|
|
|
IPC::RequestParser rp{ctx};
|
2020-07-10 22:52:07 -04:00
|
|
|
const auto info{rp.PopRaw<MiiInfo>()};
|
|
|
|
const auto source_flag{rp.PopRaw<SourceFlag>()};
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
LOG_DEBUG(Service_Mii, "called with source_flag={}", source_flag);
|
|
|
|
|
|
|
|
const auto result{manager.UpdateLatest(info, source_flag)};
|
|
|
|
if (result.Failed()) {
|
2018-12-27 20:54:44 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.Push(result.Code());
|
2018-12-27 20:54:44 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-18 09:09:52 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2 + sizeof(MiiInfo) / sizeof(u32)};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.PushRaw<MiiInfo>(*result);
|
2018-12-18 09:09:52 -05:00
|
|
|
}
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
void BuildRandom(Kernel::HLERequestContext& ctx) {
|
2018-12-18 09:09:52 -05:00
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
const auto age{rp.PopRaw<Age>()};
|
|
|
|
const auto gender{rp.PopRaw<Gender>()};
|
|
|
|
const auto race{rp.PopRaw<Race>()};
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
LOG_DEBUG(Service_Mii, "called with age={}, gender={}, race={}", age, gender, race);
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
if (age > Age::All) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERROR_INVALID_ARGUMENT);
|
|
|
|
LOG_ERROR(Service_Mii, "invalid age={}", age);
|
|
|
|
return;
|
2018-12-18 09:09:52 -05:00
|
|
|
}
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
if (gender > Gender::All) {
|
2018-12-27 20:54:44 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
|
|
|
rb.Push(ERROR_INVALID_ARGUMENT);
|
2020-07-10 22:52:07 -04:00
|
|
|
LOG_ERROR(Service_Mii, "invalid gender={}", gender);
|
2018-12-27 20:54:44 -05:00
|
|
|
return;
|
|
|
|
}
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
if (race > Race::All) {
|
2018-12-27 20:54:44 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.Push(ERROR_INVALID_ARGUMENT);
|
|
|
|
LOG_ERROR(Service_Mii, "invalid race={}", race);
|
2018-12-27 20:54:44 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2 + sizeof(MiiInfo) / sizeof(u32)};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.PushRaw<MiiInfo>(manager.BuildRandom(age, gender, race));
|
2018-12-27 20:54:44 -05:00
|
|
|
}
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
void BuildDefault(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto index{rp.Pop<u32>()};
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_Mii, "called with index={}", index);
|
2018-12-27 20:54:44 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
if (index > 5) {
|
|
|
|
LOG_ERROR(Service_Mii, "invalid argument, index cannot be greater than 5 but is {:08X}",
|
|
|
|
index);
|
2018-12-27 20:54:44 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.Push(ERROR_INVALID_ARGUMENT);
|
2018-12-27 20:54:44 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2 + sizeof(MiiInfo) / sizeof(u32)};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-07-10 22:52:07 -04:00
|
|
|
rb.PushRaw<MiiInfo>(manager.BuildDefault(index));
|
2018-12-18 09:09:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void GetIndex(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
const auto info{rp.PopRaw<MiiInfo>()};
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
LOG_DEBUG(Service_Mii, "called");
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
u32 index{};
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3};
|
|
|
|
rb.Push(manager.GetIndex(info, index));
|
2018-12-18 09:09:52 -05:00
|
|
|
rb.Push(index);
|
|
|
|
}
|
|
|
|
|
2019-07-06 21:39:04 -04:00
|
|
|
void SetInterfaceVersion(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp{ctx};
|
|
|
|
current_interface_version = rp.PopRaw<u32>();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_Mii, "called, interface_version={:08X}", current_interface_version);
|
|
|
|
|
|
|
|
UNIMPLEMENTED_IF(current_interface_version != 1);
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-07-06 21:39:04 -04:00
|
|
|
}
|
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
constexpr bool IsInterfaceVersionSupported(u32 interface_version) const {
|
|
|
|
return current_interface_version >= interface_version;
|
|
|
|
}
|
2018-12-18 09:09:52 -05:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
MiiManager manager;
|
2019-07-06 21:39:04 -04:00
|
|
|
|
2020-07-10 22:52:07 -04:00
|
|
|
u32 current_interface_version{};
|
|
|
|
u64 current_update_counter{};
|
2018-07-27 15:39:30 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class MiiDBModule final : public ServiceFramework<MiiDBModule> {
|
|
|
|
public:
|
2021-05-16 01:46:30 -04:00
|
|
|
explicit MiiDBModule(Core::System& system_, const char* name_)
|
|
|
|
: ServiceFramework{system_, name_} {
|
2018-07-27 15:39:30 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
|
|
|
{0, &MiiDBModule::GetDatabaseService, "GetDatabaseService"},
|
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void GetDatabaseService(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 15:19:08 -05:00
|
|
|
rb.PushIpcInterface<IDatabaseService>(system);
|
2018-07-27 15:39:30 -04:00
|
|
|
|
|
|
|
LOG_DEBUG(Service_Mii, "called");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MiiImg final : public ServiceFramework<MiiImg> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit MiiImg(Core::System& system_) : ServiceFramework{system_, "miiimg"} {
|
2018-07-27 15:39:30 -04: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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-26 15:19:08 -05:00
|
|
|
void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
|
|
|
|
std::make_shared<MiiDBModule>(system, "mii:e")->InstallAsService(sm);
|
|
|
|
std::make_shared<MiiDBModule>(system, "mii:u")->InstallAsService(sm);
|
2018-07-27 15:39:30 -04:00
|
|
|
|
2020-11-26 15:19:08 -05:00
|
|
|
std::make_shared<MiiImg>(system)->InstallAsService(sm);
|
2018-07-27 15:39:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::Mii
|