2020-04-19 23:04:05 +02:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
2020-03-27 20:36:02 +01:00
|
|
|
// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/)
|
|
|
|
|
2021-05-27 23:25:19 +02:00
|
|
|
#include <common/uuid.h>
|
|
|
|
#include <mbedtls/sha1.h>
|
|
|
|
#include <loader/loader.h>
|
2020-08-09 15:51:57 +02:00
|
|
|
#include <kernel/types/KProcess.h>
|
2020-07-07 13:36:17 +02:00
|
|
|
#include <services/account/IAccountServiceForApplication.h>
|
|
|
|
#include <services/am/storage/IStorage.h>
|
2020-02-19 21:35:54 +01:00
|
|
|
#include "IApplicationFunctions.h"
|
|
|
|
|
|
|
|
namespace skyline::service::am {
|
2021-01-11 20:17:06 +01:00
|
|
|
IApplicationFunctions::IApplicationFunctions(const DeviceState &state, ServiceManager &manager) : gpuErrorEvent(std::make_shared<type::KEvent>(state, false)), BaseService(state, manager) {}
|
2020-02-19 21:35:54 +01:00
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IApplicationFunctions::PopLaunchParameter(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
2020-09-28 12:05:17 +02:00
|
|
|
constexpr u32 LaunchParameterMagic{0xC79497CA}; //!< The magic of the application launch parameters
|
|
|
|
constexpr size_t LaunchParameterSize{0x88}; //!< The size of the launch parameter IStorage
|
2020-07-07 13:36:17 +02:00
|
|
|
|
2020-09-26 07:17:57 +02:00
|
|
|
auto storageService{std::make_shared<IStorage>(state, manager, LaunchParameterSize)};
|
2020-07-07 13:36:17 +02:00
|
|
|
|
|
|
|
storageService->Push<u32>(LaunchParameterMagic);
|
|
|
|
storageService->Push<u32>(1);
|
|
|
|
storageService->Push(constant::DefaultUserId);
|
|
|
|
|
|
|
|
manager.RegisterService(storageService, session, response);
|
2020-09-03 20:43:52 +02:00
|
|
|
return {};
|
2020-07-07 13:36:17 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IApplicationFunctions::EnsureSaveData(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
2020-07-09 15:42:10 +02:00
|
|
|
response.Push<u8>(0);
|
2020-09-03 20:43:52 +02:00
|
|
|
return {};
|
2020-07-09 15:42:10 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IApplicationFunctions::GetDesiredLanguage(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
2020-07-07 13:36:17 +02:00
|
|
|
response.Push(util::MakeMagic<u64>("en-US"));
|
2020-09-03 20:43:52 +02:00
|
|
|
return {};
|
2020-07-07 13:36:17 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IApplicationFunctions::NotifyRunning(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
2020-02-19 21:35:54 +01:00
|
|
|
response.Push<u8>(1);
|
2020-09-03 20:43:52 +02:00
|
|
|
return {};
|
2020-02-19 21:35:54 +01:00
|
|
|
}
|
2020-07-09 15:42:10 +02:00
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IApplicationFunctions::GetPseudoDeviceId(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
2021-05-27 23:25:19 +02:00
|
|
|
auto seedForPseudoDeviceId{state.loader->nacp->nacpContents.seedForPseudoDeviceId};
|
|
|
|
std::array<u8, 20> hashBuf{};
|
|
|
|
|
2021-06-18 18:24:31 +02:00
|
|
|
// On HOS the seed from control.ncap is hashed together with the device specific device ID seed
|
|
|
|
// for us it's enough to just hash the seed from control.nacp as it provides the same guarantees
|
2021-07-11 20:17:59 +02:00
|
|
|
if (int err{mbedtls_sha1(seedForPseudoDeviceId.data(), seedForPseudoDeviceId.size(), hashBuf.data())}; err < 0)
|
2021-05-27 23:25:19 +02:00
|
|
|
throw exception("Failed to hash device ID, err: {}", err);
|
|
|
|
|
|
|
|
response.Push<UUID>(UUID::GenerateUuidV5(hashBuf));
|
2020-09-03 20:43:52 +02:00
|
|
|
return {};
|
2020-08-09 15:51:57 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IApplicationFunctions::InitializeGamePlayRecording(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
|
|
return {};
|
|
|
|
}
|
2020-07-09 15:42:10 +02:00
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IApplicationFunctions::SetGamePlayRecordingState(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
|
|
return {};
|
|
|
|
}
|
2020-08-09 15:51:57 +02:00
|
|
|
|
2021-05-27 23:26:46 +02:00
|
|
|
Result IApplicationFunctions::InitializeApplicationCopyrightFrameBuffer(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
|
|
i32 width{request.Pop<i32>()};
|
|
|
|
i32 height{request.Pop<i32>()};
|
|
|
|
u64 transferMemorySize{request.Pop<u64>()};
|
|
|
|
|
|
|
|
constexpr i32 MaximumFbWidth{1280};
|
|
|
|
constexpr i32 MaximumFbHeight{720};
|
|
|
|
constexpr u64 RequiredFbAlignment{0x40000};
|
|
|
|
|
|
|
|
if (width > MaximumFbWidth || height > MaximumFbHeight || !util::IsAligned(transferMemorySize, RequiredFbAlignment))
|
|
|
|
return result::InvalidParameters;
|
|
|
|
|
|
|
|
state.logger->Debug("Dimensions: ({}, {}) Transfer Memory Size: {}", width, height, transferMemorySize);
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result IApplicationFunctions::SetApplicationCopyrightImage(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
|
|
i32 x{request.Pop<i32>()};
|
|
|
|
i32 y{request.Pop<i32>()};
|
|
|
|
i32 width{request.Pop<i32>()};
|
|
|
|
i32 height{request.Pop<i32>()};
|
|
|
|
|
|
|
|
enum class WindowOriginMode : i32 {
|
|
|
|
LowerLeft,
|
|
|
|
UpperLeft
|
|
|
|
} originMode = request.Pop<WindowOriginMode>();
|
|
|
|
|
|
|
|
if (y < 0 || x < 0 || width < 1 || height < 1)
|
|
|
|
return result::InvalidParameters;
|
|
|
|
|
|
|
|
state.logger->Debug("Position: ({}, {}) Dimensions: ({}, {}) Origin mode: {}", x, y, width, height, static_cast<i32>(originMode));
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Result IApplicationFunctions::SetApplicationCopyrightVisibility(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
|
|
|
u8 visiblity{request.Pop<u8>()};
|
|
|
|
state.logger->Debug("Visiblity: {}", visiblity);
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-09-03 20:43:52 +02:00
|
|
|
Result IApplicationFunctions::GetGpuErrorDetectedSystemEvent(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) {
|
2020-09-26 07:17:57 +02:00
|
|
|
auto handle{state.process->InsertItem(gpuErrorEvent)};
|
2020-08-09 15:51:57 +02:00
|
|
|
state.logger->Debug("GPU Error Event Handle: 0x{:X}", handle);
|
|
|
|
response.copyHandles.push_back(handle);
|
2020-09-03 20:43:52 +02:00
|
|
|
return {};
|
2020-08-09 15:51:57 +02:00
|
|
|
}
|
2020-02-19 21:35:54 +01:00
|
|
|
}
|