summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt6
-rw-r--r--src/core/crypto/key_manager.cpp1
-rw-r--r--src/core/file_sys/patch_manager.cpp5
-rw-r--r--src/core/file_sys/registered_cache.cpp15
-rw-r--r--src/core/file_sys/registered_cache.h8
-rw-r--r--src/core/file_sys/vfs.cpp8
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp25
-rw-r--r--src/core/hle/kernel/hle_ipc.h13
-rw-r--r--src/core/hle/kernel/kernel.cpp10
-rw-r--r--src/core/hle/kernel/kernel.h6
-rw-r--r--src/core/hle/kernel/process.h14
-rw-r--r--src/core/hle/kernel/server_session.cpp3
-rw-r--r--src/core/hle/kernel/svc.cpp178
-rw-r--r--src/core/hle/kernel/thread.cpp2
-rw-r--r--src/core/hle/service/acc/acc.cpp54
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp204
-rw-r--r--src/core/hle/service/acc/profile_manager.h35
-rw-r--r--src/core/hle/service/am/am.cpp97
-rw-r--r--src/core/hle/service/am/applet_ae.cpp4
-rw-r--r--src/core/hle/service/am/applet_oe.cpp3
-rw-r--r--src/core/hle/service/am/idle.cpp6
-rw-r--r--src/core/hle/service/am/tcap.cpp23
-rw-r--r--src/core/hle/service/am/tcap.h17
-rw-r--r--src/core/hle/service/aoc/aoc_u.cpp6
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp6
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp5
-rw-r--r--src/core/hle/service/hid/hid.cpp1
-rw-r--r--src/core/hle/service/lbl/lbl.cpp56
-rw-r--r--src/core/hle/service/nfc/nfc.cpp53
-rw-r--r--src/core/hle/service/nfp/nfp.cpp268
-rw-r--r--src/core/hle/service/nfp/nfp.h23
-rw-r--r--src/core/hle/service/npns/npns.cpp88
-rw-r--r--src/core/hle/service/npns/npns.h15
-rw-r--r--src/core/hle/service/prepo/prepo.cpp21
-rw-r--r--src/core/hle/service/ptm/psm.cpp71
-rw-r--r--src/core/hle/service/ptm/psm.h15
-rw-r--r--src/core/hle/service/service.cpp8
-rw-r--r--src/core/perf_stats.cpp4
-rw-r--r--src/core/settings.h3
39 files changed, 1093 insertions, 287 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 4755ec822..64fdf38cd 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -156,6 +156,8 @@ add_library(core STATIC
hle/service/am/omm.h
hle/service/am/spsm.cpp
hle/service/am/spsm.h
+ hle/service/am/tcap.cpp
+ hle/service/am/tcap.h
hle/service/aoc/aoc_u.cpp
hle/service/aoc/aoc_u.h
hle/service/apm/apm.cpp
@@ -280,6 +282,8 @@ add_library(core STATIC
hle/service/nifm/nifm.h
hle/service/nim/nim.cpp
hle/service/nim/nim.h
+ hle/service/npns/npns.cpp
+ hle/service/npns/npns.h
hle/service/ns/ns.cpp
hle/service/ns/ns.h
hle/service/ns/pl_u.cpp
@@ -327,6 +331,8 @@ add_library(core STATIC
hle/service/prepo/prepo.h
hle/service/psc/psc.cpp
hle/service/psc/psc.h
+ hle/service/ptm/psm.cpp
+ hle/service/ptm/psm.h
hle/service/service.cpp
hle/service/service.h
hle/service/set/set.cpp
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index fd0786068..fefc3c747 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -713,7 +713,6 @@ void KeyManager::DeriveBase() {
const auto sbk = GetKey(S128KeyType::SecureBoot);
const auto tsec = GetKey(S128KeyType::TSEC);
- const auto master_source = GetKey(S128KeyType::Source, static_cast<u64>(SourceKeyType::Master));
for (size_t i = 0; i < revisions.size(); ++i) {
if (!revisions[i])
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp
index 0117cb0bf..1f4928562 100644
--- a/src/core/file_sys/patch_manager.cpp
+++ b/src/core/file_sys/patch_manager.cpp
@@ -168,7 +168,8 @@ bool PatchManager::HasNSOPatch(const std::array<u8, 32>& build_id_) const {
static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType type) {
const auto load_dir = Service::FileSystem::GetModificationLoadRoot(title_id);
- if (type != ContentRecordType::Program || load_dir == nullptr || load_dir->GetSize() <= 0) {
+ if ((type != ContentRecordType::Program && type != ContentRecordType::Data) ||
+ load_dir == nullptr || load_dir->GetSize() <= 0) {
return;
}
@@ -218,7 +219,7 @@ VirtualFile PatchManager::PatchRomFS(VirtualFile romfs, u64 ivfc_offset, Content
title_id, static_cast<u8>(type))
.c_str();
- if (type == ContentRecordType::Program)
+ if (type == ContentRecordType::Program || type == ContentRecordType::Data)
LOG_INFO(Loader, log_string);
else
LOG_DEBUG(Loader, log_string);
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index 1febb398e..29b100414 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <algorithm>
#include <regex>
#include <mbedtls/sha256.h>
#include "common/assert.h"
@@ -30,6 +31,14 @@ bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs)
return (lhs.title_id < rhs.title_id) || (lhs.title_id == rhs.title_id && lhs.type < rhs.type);
}
+bool operator==(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) {
+ return std::tie(lhs.title_id, lhs.type) == std::tie(rhs.title_id, rhs.type);
+}
+
+bool operator!=(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs) {
+ return !operator==(lhs, rhs);
+}
+
static bool FollowsTwoDigitDirFormat(std::string_view name) {
static const std::regex two_digit_regex("000000[0-9A-F]{2}", std::regex_constants::ECMAScript |
std::regex_constants::icase);
@@ -593,6 +602,9 @@ std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntries() const {
},
[](const CNMT& c, const ContentRecord& r) { return true; });
}
+
+ std::sort(out.begin(), out.end());
+ out.erase(std::unique(out.begin(), out.end()), out.end());
return out;
}
@@ -616,6 +628,9 @@ std::vector<RegisteredCacheEntry> RegisteredCacheUnion::ListEntriesFilter(
return true;
});
}
+
+ std::sort(out.begin(), out.end());
+ out.erase(std::unique(out.begin(), out.end()), out.end());
return out;
}
} // namespace FileSys
diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h
index 5ddacba47..5beceffb3 100644
--- a/src/core/file_sys/registered_cache.h
+++ b/src/core/file_sys/registered_cache.h
@@ -50,6 +50,10 @@ constexpr u64 GetUpdateTitleID(u64 base_title_id) {
// boost flat_map requires operator< for O(log(n)) lookups.
bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs);
+// std unique requires operator== to identify duplicates.
+bool operator==(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs);
+bool operator!=(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs);
+
/*
* A class that catalogues NCAs in the registered directory structure.
* Nintendo's registered format follows this structure:
@@ -60,8 +64,8 @@ bool operator<(const RegisteredCacheEntry& lhs, const RegisteredCacheEntry& rhs)
* | 00
* | 01 <- Actual content split along 4GB boundaries. (optional)
*
- * (This impl also supports substituting the nca dir for an nca file, as that's more convenient when
- * 4GB splitting can be ignored.)
+ * (This impl also supports substituting the nca dir for an nca file, as that's more convenient
+ * when 4GB splitting can be ignored.)
*/
class RegisteredCache {
friend class RegisteredCacheUnion;
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp
index bfe50da73..3824c74e0 100644
--- a/src/core/file_sys/vfs.cpp
+++ b/src/core/file_sys/vfs.cpp
@@ -472,10 +472,14 @@ bool VfsRawCopy(const VirtualFile& src, const VirtualFile& dest, std::size_t blo
std::vector<u8> temp(std::min(block_size, src->GetSize()));
for (std::size_t i = 0; i < src->GetSize(); i += block_size) {
const auto read = std::min(block_size, src->GetSize() - i);
- const auto block = src->Read(temp.data(), read, i);
- if (dest->Write(temp.data(), read, i) != read)
+ if (src->Read(temp.data(), read, i) != read) {
return false;
+ }
+
+ if (dest->Write(temp.data(), read, i) != read) {
+ return false;
+ }
}
return true;
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index edad5f1b1..68d5376cb 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -77,7 +77,8 @@ HLERequestContext::HLERequestContext(SharedPtr<Kernel::ServerSession> server_ses
HLERequestContext::~HLERequestContext() = default;
-void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) {
+void HLERequestContext::ParseCommandBuffer(const HandleTable& handle_table, u32_le* src_cmdbuf,
+ bool incoming) {
IPC::RequestParser rp(src_cmdbuf);
command_header = std::make_shared<IPC::CommandHeader>(rp.PopRaw<IPC::CommandHeader>());
@@ -94,8 +95,6 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) {
rp.Skip(2, false);
}
if (incoming) {
- auto& handle_table = Core::System::GetInstance().Kernel().HandleTable();
-
// Populate the object lists with the data in the IPC request.
for (u32 handle = 0; handle < handle_descriptor_header->num_handles_to_copy; ++handle) {
copy_objects.push_back(handle_table.GetGeneric(rp.Pop<Handle>()));
@@ -189,10 +188,9 @@ void HLERequestContext::ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming) {
rp.Skip(1, false); // The command is actually an u64, but we don't use the high part.
}
-ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdbuf,
- Process& src_process,
- HandleTable& src_table) {
- ParseCommandBuffer(src_cmdbuf, true);
+ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const HandleTable& handle_table,
+ u32_le* src_cmdbuf) {
+ ParseCommandBuffer(handle_table, src_cmdbuf, true);
if (command_header->type == IPC::CommandType::Close) {
// Close does not populate the rest of the IPC header
return RESULT_SUCCESS;
@@ -207,14 +205,17 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdb
return RESULT_SUCCESS;
}
-ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread) {
+ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) {
+ auto& owner_process = *thread.GetOwnerProcess();
+ auto& handle_table = owner_process.GetHandleTable();
+
std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf;
- Memory::ReadBlock(*thread.GetOwnerProcess(), thread.GetTLSAddress(), dst_cmdbuf.data(),
+ Memory::ReadBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(),
dst_cmdbuf.size() * sizeof(u32));
// The header was already built in the internal command buffer. Attempt to parse it to verify
// the integrity and then copy it over to the target command buffer.
- ParseCommandBuffer(cmd_buf.data(), false);
+ ParseCommandBuffer(handle_table, cmd_buf.data(), false);
// The data_size already includes the payload header, the padding and the domain header.
std::size_t size = data_payload_offset + command_header->data_size -
@@ -236,8 +237,6 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread)
ASSERT(copy_objects.size() == handle_descriptor_header->num_handles_to_copy);
ASSERT(move_objects.size() == handle_descriptor_header->num_handles_to_move);
- auto& handle_table = Core::System::GetInstance().Kernel().HandleTable();
-
// We don't make a distinction between copy and move handles when translating since HLE
// services don't deal with handles directly. However, the guest applications might check
// for specific values in each of these descriptors.
@@ -268,7 +267,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread)
}
// Copy the translated command buffer back into the thread's command buffer area.
- Memory::WriteBlock(*thread.GetOwnerProcess(), thread.GetTLSAddress(), dst_cmdbuf.data(),
+ Memory::WriteBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(),
dst_cmdbuf.size() * sizeof(u32));
return RESULT_SUCCESS;
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index 894479ee0..f01491daa 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -24,10 +24,10 @@ class ServiceFrameworkBase;
namespace Kernel {
class Domain;
+class Event;
class HandleTable;
class HLERequestContext;
class Process;
-class Event;
/**
* Interface implemented by HLE Session handlers.
@@ -126,13 +126,12 @@ public:
u64 timeout, WakeupCallback&& callback,
Kernel::SharedPtr<Kernel::Event> event = nullptr);
- void ParseCommandBuffer(u32_le* src_cmdbuf, bool incoming);
-
/// Populates this context with data from the requesting process/thread.
- ResultCode PopulateFromIncomingCommandBuffer(u32_le* src_cmdbuf, Process& src_process,
- HandleTable& src_table);
+ ResultCode PopulateFromIncomingCommandBuffer(const HandleTable& handle_table,
+ u32_le* src_cmdbuf);
+
/// Writes data from this context back to the requesting process/thread.
- ResultCode WriteToOutgoingCommandBuffer(const Thread& thread);
+ ResultCode WriteToOutgoingCommandBuffer(Thread& thread);
u32_le GetCommand() const {
return command;
@@ -255,6 +254,8 @@ public:
std::string Description() const;
private:
+ void ParseCommandBuffer(const HandleTable& handle_table, u32_le* src_cmdbuf, bool incoming);
+
std::array<u32, IPC::COMMAND_BUFFER_LENGTH> cmd_buf;
SharedPtr<Kernel::ServerSession> server_session;
// TODO(yuriks): Check common usage of this and optimize size accordingly
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index bd680adfe..4b6b32dd5 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -118,7 +118,6 @@ struct KernelCore::Impl {
process_list.clear();
current_process = nullptr;
- handle_table.Clear();
resource_limits.fill(nullptr);
thread_wakeup_callback_handle_table.Clear();
@@ -209,7 +208,6 @@ struct KernelCore::Impl {
std::vector<SharedPtr<Process>> process_list;
Process* current_process = nullptr;
- Kernel::HandleTable handle_table;
std::array<SharedPtr<ResourceLimit>, 4> resource_limits;
/// The event type of the generic timer callback event
@@ -241,14 +239,6 @@ void KernelCore::Shutdown() {
impl->Shutdown();
}
-Kernel::HandleTable& KernelCore::HandleTable() {
- return impl->handle_table;
-}
-
-const Kernel::HandleTable& KernelCore::HandleTable() const {
- return impl->handle_table;
-}
-
SharedPtr<ResourceLimit> KernelCore::ResourceLimitForCategory(
ResourceLimitCategory category) const {
return impl->resource_limits.at(static_cast<std::size_t>(category));
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 41554821f..7f822d524 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -47,12 +47,6 @@ public:
/// Clears all resources in use by the kernel instance.
void Shutdown();
- /// Provides a reference to the handle table.
- Kernel::HandleTable& HandleTable();
-
- /// Provides a const reference to the handle table.
- const Kernel::HandleTable& HandleTable() const;
-
/// Retrieves a shared pointer to a ResourceLimit identified by the given category.
SharedPtr<ResourceLimit> ResourceLimitForCategory(ResourceLimitCategory category) const;
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index f2816943a..148478488 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -13,6 +13,7 @@
#include <boost/container/static_vector.hpp>
#include "common/bit_field.h"
#include "common/common_types.h"
+#include "core/hle/kernel/handle_table.h"
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/thread.h"
#include "core/hle/kernel/vm_manager.h"
@@ -142,6 +143,16 @@ public:
return vm_manager;
}
+ /// Gets a reference to the process' handle table.
+ HandleTable& GetHandleTable() {
+ return handle_table;
+ }
+
+ /// Gets a const reference to the process' handle table.
+ const HandleTable& GetHandleTable() const {
+ return handle_table;
+ }
+
/// Gets the current status of the process
ProcessStatus GetStatus() const {
return status;
@@ -294,6 +305,9 @@ private:
/// specified by metadata provided to the process during loading.
bool is_64bit_process = true;
+ /// Per-process handle table for storing created object handles in.
+ HandleTable handle_table;
+
std::string name;
};
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp
index 1ece691c7..5fc320403 100644
--- a/src/core/hle/kernel/server_session.cpp
+++ b/src/core/hle/kernel/server_session.cpp
@@ -107,8 +107,7 @@ ResultCode ServerSession::HandleSyncRequest(SharedPtr<Thread> thread) {
// similar.
Kernel::HLERequestContext context(this);
u32* cmd_buf = (u32*)Memory::GetPointer(thread->GetTLSAddress());
- context.PopulateFromIncomingCommandBuffer(cmd_buf, *Core::CurrentProcess(),
- kernel.HandleTable());
+ context.PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf);
ResultCode result = RESULT_SUCCESS;
// If the session has been converted to a domain, handle the domain request
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 3b8a2e230..9a783d524 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -189,14 +189,15 @@ static ResultCode ConnectToNamedPort(Handle* out_handle, VAddr port_name_address
CASCADE_RESULT(client_session, client_port->Connect());
// Return the client session
- CASCADE_RESULT(*out_handle, kernel.HandleTable().Create(client_session));
+ auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ CASCADE_RESULT(*out_handle, handle_table.Create(client_session));
return RESULT_SUCCESS;
}
/// Makes a blocking IPC call to an OS service.
static ResultCode SendSyncRequest(Handle handle) {
- auto& kernel = Core::System::GetInstance().Kernel();
- SharedPtr<ClientSession> session = kernel.HandleTable().Get<ClientSession>(handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ SharedPtr<ClientSession> session = handle_table.Get<ClientSession>(handle);
if (!session) {
LOG_ERROR(Kernel_SVC, "called with invalid handle=0x{:08X}", handle);
return ERR_INVALID_HANDLE;
@@ -215,8 +216,8 @@ static ResultCode SendSyncRequest(Handle handle) {
static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) {
LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle);
- auto& kernel = Core::System::GetInstance().Kernel();
- const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle);
if (!thread) {
return ERR_INVALID_HANDLE;
}
@@ -229,8 +230,8 @@ static ResultCode GetThreadId(u32* thread_id, Handle thread_handle) {
static ResultCode GetProcessId(u32* process_id, Handle process_handle) {
LOG_TRACE(Kernel_SVC, "called process=0x{:08X}", process_handle);
- auto& kernel = Core::System::GetInstance().Kernel();
- const SharedPtr<Process> process = kernel.HandleTable().Get<Process>(process_handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ const SharedPtr<Process> process = handle_table.Get<Process>(process_handle);
if (!process) {
return ERR_INVALID_HANDLE;
}
@@ -273,11 +274,11 @@ static ResultCode WaitSynchronization(Handle* index, VAddr handles_address, u64
using ObjectPtr = Thread::ThreadWaitObjects::value_type;
Thread::ThreadWaitObjects objects(handle_count);
- auto& kernel = Core::System::GetInstance().Kernel();
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
for (u64 i = 0; i < handle_count; ++i) {
const Handle handle = Memory::Read32(handles_address + i * sizeof(Handle));
- const auto object = kernel.HandleTable().Get<WaitObject>(handle);
+ const auto object = handle_table.Get<WaitObject>(handle);
if (object == nullptr) {
return ERR_INVALID_HANDLE;
@@ -325,8 +326,8 @@ static ResultCode WaitSynchronization(Handle* index, VAddr handles_address, u64
static ResultCode CancelSynchronization(Handle thread_handle) {
LOG_TRACE(Kernel_SVC, "called thread=0x{:X}", thread_handle);
- auto& kernel = Core::System::GetInstance().Kernel();
- const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle);
if (!thread) {
return ERR_INVALID_HANDLE;
}
@@ -354,7 +355,7 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr,
return ERR_INVALID_ADDRESS;
}
- auto& handle_table = Core::System::GetInstance().Kernel().HandleTable();
+ auto& handle_table = Core::CurrentProcess()->GetHandleTable();
return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle,
requesting_thread_handle);
}
@@ -374,9 +375,19 @@ static ResultCode ArbitrateUnlock(VAddr mutex_addr) {
return Mutex::Release(mutex_addr);
}
+enum class BreakType : u32 {
+ Panic = 0,
+ AssertionFailed = 1,
+ PreNROLoad = 3,
+ PostNROLoad = 4,
+ PreNROUnload = 5,
+ PostNROUnload = 6,
+};
+
struct BreakReason {
union {
u32 raw;
+ BitField<0, 30, BreakType> break_type;
BitField<31, 1, u32> signal_debugger;
};
};
@@ -384,12 +395,48 @@ struct BreakReason {
/// Break program execution
static void Break(u32 reason, u64 info1, u64 info2) {
BreakReason break_reason{reason};
- if (break_reason.signal_debugger) {
- LOG_ERROR(
+
+ switch (break_reason.break_type) {
+ case BreakType::Panic:
+ LOG_CRITICAL(Debug_Emulated, "Signalling debugger, PANIC! info1=0x{:016X}, info2=0x{:016X}",
+ info1, info2);
+ break;
+ case BreakType::AssertionFailed:
+ LOG_CRITICAL(Debug_Emulated,
+ "Signalling debugger, Assertion failed! info1=0x{:016X}, info2=0x{:016X}",
+ info1, info2);
+ break;
+ case BreakType::PreNROLoad:
+ LOG_WARNING(
Debug_Emulated,
- "Emulated program broke execution! reason=0x{:016X}, info1=0x{:016X}, info2=0x{:016X}",
- reason, info1, info2);
- } else {
+ "Signalling debugger, Attempting to load an NRO at 0x{:016X} with size 0x{:016X}",
+ info1, info2);
+ break;
+ case BreakType::PostNROLoad:
+ LOG_WARNING(Debug_Emulated,
+ "Signalling debugger, Loaded an NRO at 0x{:016X} with size 0x{:016X}", info1,
+ info2);
+ break;
+ case BreakType::PreNROUnload:
+ LOG_WARNING(
+ Debug_Emulated,
+ "Signalling debugger, Attempting to unload an NRO at 0x{:016X} with size 0x{:016X}",
+ info1, info2);
+ break;
+ case BreakType::PostNROUnload:
+ LOG_WARNING(Debug_Emulated,
+ "Signalling debugger, Unloaded an NRO at 0x{:016X} with size 0x{:016X}", info1,
+ info2);
+ break;
+ default:
+ LOG_WARNING(
+ Debug_Emulated,
+ "Signalling debugger, Unknown break reason {}, info1=0x{:016X}, info2=0x{:016X}",
+ static_cast<u32>(break_reason.break_type.Value()), info1, info2);
+ break;
+ }
+
+ if (!break_reason.signal_debugger) {
LOG_CRITICAL(
Debug_Emulated,
"Emulated program broke execution! reason=0x{:016X}, info1=0x{:016X}, info2=0x{:016X}",
@@ -499,13 +546,12 @@ static ResultCode SetThreadActivity(Handle handle, u32 unknown) {
static ResultCode GetThreadContext(VAddr thread_context, Handle handle) {
LOG_DEBUG(Kernel_SVC, "called, context=0x{:08X}, thread=0x{:X}", thread_context, handle);
- auto& kernel = Core::System::GetInstance().Kernel();
- const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(handle);
+ const auto* current_process = Core::CurrentProcess();
+ const SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle);
if (!thread) {
return ERR_INVALID_HANDLE;
}
- const auto* current_process = Core::CurrentProcess();
if (thread->GetOwnerProcess() != current_process) {
return ERR_INVALID_HANDLE;
}
@@ -531,10 +577,11 @@ static ResultCode GetThreadContext(VAddr thread_context, Handle handle) {
/// Gets the priority for the specified thread
static ResultCode GetThreadPriority(u32* priority, Handle handle) {
- auto& kernel = Core::System::GetInstance().Kernel();
- const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(handle);
- if (!thread)
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ const SharedPtr<Thread> thread = handle_table.Get<Thread>(handle);
+ if (!thread) {
return ERR_INVALID_HANDLE;
+ }
*priority = thread->GetPriority();
return RESULT_SUCCESS;
@@ -546,14 +593,15 @@ static ResultCode SetThreadPriority(Handle handle, u32 priority) {
return ERR_INVALID_THREAD_PRIORITY;
}
- auto& kernel = Core::System::GetInstance().Kernel();
- SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(handle);
- if (!thread)
+ const auto* const current_process = Core::CurrentProcess();
+ SharedPtr<Thread> thread = current_process->GetHandleTable().Get<Thread>(handle);
+ if (!thread) {
return ERR_INVALID_HANDLE;
+ }
// Note: The kernel uses the current process's resource limit instead of
// the one from the thread owner's resource limit.
- const ResourceLimit& resource_limit = Core::CurrentProcess()->GetResourceLimit();
+ const ResourceLimit& resource_limit = current_process->GetResourceLimit();
if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) {
return ERR_NOT_AUTHORIZED;
}
@@ -595,15 +643,13 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s
return ERR_INVALID_MEMORY_PERMISSIONS;
}
- auto& kernel = Core::System::GetInstance().Kernel();
- auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle);
+ auto* const current_process = Core::CurrentProcess();
+ auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle);
if (!shared_memory) {
return ERR_INVALID_HANDLE;
}
- auto* const current_process = Core::CurrentProcess();
const auto& vm_manager = current_process->VMManager();
-
if (!vm_manager.IsWithinASLRRegion(addr, size)) {
return ERR_INVALID_MEMORY_RANGE;
}
@@ -627,15 +673,13 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64
return ERR_INVALID_ADDRESS_STATE;
}
- auto& kernel = Core::System::GetInstance().Kernel();
- auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle);
+ auto* const current_process = Core::CurrentProcess();
+ auto shared_memory = current_process->GetHandleTable().Get<SharedMemory>(shared_memory_handle);
if (!shared_memory) {
return ERR_INVALID_HANDLE;
}
- auto* const current_process = Core::CurrentProcess();
const auto& vm_manager = current_process->VMManager();
-
if (!vm_manager.IsWithinASLRRegion(addr, size)) {
return ERR_INVALID_MEMORY_RANGE;
}
@@ -646,15 +690,14 @@ static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64
/// Query process memory
static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* /*page_info*/,
Handle process_handle, u64 addr) {
-
- auto& kernel = Core::System::GetInstance().Kernel();
- SharedPtr<Process> process = kernel.HandleTable().Get<Process>(process_handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ SharedPtr<Process> process = handle_table.Get<Process>(process_handle);
if (!process) {
return ERR_INVALID_HANDLE;
}
auto vma = process->VMManager().FindVMA(addr);
memory_info->attributes = 0;
- if (vma == Core::CurrentProcess()->VMManager().vma_map.end()) {
+ if (vma == process->VMManager().vma_map.end()) {
memory_info->base_address = 0;
memory_info->permission = static_cast<u32>(VMAPermission::None);
memory_info->size = 0;
@@ -695,20 +738,19 @@ static void ExitProcess() {
/// Creates a new thread
static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top,
u32 priority, s32 processor_id) {
- std::string name = fmt::format("thread-{:X}", entry_point);
-
if (priority > THREADPRIO_LOWEST) {
return ERR_INVALID_THREAD_PRIORITY;
}
- const ResourceLimit& resource_limit = Core::CurrentProcess()->GetResourceLimit();
+ auto* const current_process = Core::CurrentProcess();
+ const ResourceLimit& resource_limit = current_process->GetResourceLimit();
if (resource_limit.GetMaxResourceValue(ResourceType::Priority) > priority) {
return ERR_NOT_AUTHORIZED;
}
if (processor_id == THREADPROCESSORID_DEFAULT) {
// Set the target CPU to the one specified in the process' exheader.
- processor_id = Core::CurrentProcess()->GetDefaultProcessorID();
+ processor_id = current_process->GetDefaultProcessorID();
ASSERT(processor_id != THREADPROCESSORID_DEFAULT);
}
@@ -723,11 +765,13 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V
return ERR_INVALID_PROCESSOR_ID;
}
+ const std::string name = fmt::format("thread-{:X}", entry_point);
auto& kernel = Core::System::GetInstance().Kernel();
CASCADE_RESULT(SharedPtr<Thread> thread,
Thread::Create(kernel, name, entry_point, priority, arg, processor_id, stack_top,
- *Core::CurrentProcess()));
- const auto new_guest_handle = kernel.HandleTable().Create(thread);
+ *current_process));
+
+ const auto new_guest_handle = current_process->GetHandleTable().Create(thread);
if (new_guest_handle.Failed()) {
return new_guest_handle.Code();
}
@@ -748,8 +792,8 @@ static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, V
static ResultCode StartThread(Handle thread_handle) {
LOG_TRACE(Kernel_SVC, "called thread=0x{:08X}", thread_handle);
- auto& kernel = Core::System::GetInstance().Kernel();
- const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle);
if (!thread) {
return ERR_INVALID_HANDLE;
}
@@ -796,8 +840,8 @@ static ResultCode WaitProcessWideKeyAtomic(VAddr mutex_addr, VAddr condition_var
"called mutex_addr={:X}, condition_variable_addr={:X}, thread_handle=0x{:08X}, timeout={}",
mutex_addr, condition_variable_addr, thread_handle, nano_seconds);
- auto& kernel = Core::System::GetInstance().Kernel();
- SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle);
ASSERT(thread);
CASCADE_CODE(Mutex::Release(mutex_addr));
@@ -908,9 +952,9 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
mutex_val | Mutex::MutexHasWaitersFlag));
// The mutex is already owned by some other thread, make this thread wait on it.
- auto& kernel = Core::System::GetInstance().Kernel();
- Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask);
- auto owner = kernel.HandleTable().Get<Thread>(owner_handle);
+ const Handle owner_handle = static_cast<Handle>(mutex_val & Mutex::MutexOwnerMask);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ auto owner = handle_table.Get<Thread>(owner_handle);
ASSERT(owner);
ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex);
thread->InvalidateWakeupCallback();
@@ -989,16 +1033,16 @@ static u64 GetSystemTick() {
static ResultCode CloseHandle(Handle handle) {
LOG_TRACE(Kernel_SVC, "Closing handle 0x{:08X}", handle);
- auto& kernel = Core::System::GetInstance().Kernel();
- return kernel.HandleTable().Close(handle);
+ auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ return handle_table.Close(handle);
}
/// Reset an event
static ResultCode ResetSignal(Handle handle) {
LOG_WARNING(Kernel_SVC, "(STUBBED) called handle 0x{:08X}", handle);
- auto& kernel = Core::System::GetInstance().Kernel();
- auto event = kernel.HandleTable().Get<Event>(handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ auto event = handle_table.Get<Event>(handle);
ASSERT(event != nullptr);
@@ -1017,8 +1061,8 @@ static ResultCode CreateTransferMemory(Handle* handle, VAddr addr, u64 size, u32
static ResultCode GetThreadCoreMask(Handle thread_handle, u32* core, u64* mask) {
LOG_TRACE(Kernel_SVC, "called, handle=0x{:08X}", thread_handle);
- auto& kernel = Core::System::GetInstance().Kernel();
- const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle);
if (!thread) {
return ERR_INVALID_HANDLE;
}
@@ -1033,8 +1077,8 @@ static ResultCode SetThreadCoreMask(Handle thread_handle, u32 core, u64 mask) {
LOG_DEBUG(Kernel_SVC, "called, handle=0x{:08X}, mask=0x{:16X}, core=0x{:X}", thread_handle,
mask, core);
- auto& kernel = Core::System::GetInstance().Kernel();
- const SharedPtr<Thread> thread = kernel.HandleTable().Get<Thread>(thread_handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ const SharedPtr<Thread> thread = handle_table.Get<Thread>(thread_handle);
if (!thread) {
return ERR_INVALID_HANDLE;
}
@@ -1095,7 +1139,7 @@ static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permiss
}
auto& kernel = Core::System::GetInstance().Kernel();
- auto& handle_table = kernel.HandleTable();
+ auto& handle_table = Core::CurrentProcess()->GetHandleTable();
auto shared_mem_handle =
SharedMemory::Create(kernel, handle_table.Get<Process>(KernelHandle::CurrentProcess), size,
local_perms, remote_perms);
@@ -1107,10 +1151,12 @@ static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permiss
static ResultCode ClearEvent(Handle handle) {
LOG_TRACE(Kernel_SVC, "called, event=0x{:08X}", handle);
- auto& kernel = Core::System::GetInstance().Kernel();
- SharedPtr<Event> evt = kernel.HandleTable().Get<Event>(handle);
- if (evt == nullptr)
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ SharedPtr<Event> evt = handle_table.Get<Event>(handle);
+ if (evt == nullptr) {
return ERR_INVALID_HANDLE;
+ }
+
evt->Clear();
return RESULT_SUCCESS;
}
@@ -1123,8 +1169,8 @@ static ResultCode GetProcessInfo(u64* out, Handle process_handle, u32 type) {
Status,
};
- const auto& kernel = Core::System::GetInstance().Kernel();
- const auto process = kernel.HandleTable().Get<Process>(process_handle);
+ const auto& handle_table = Core::CurrentProcess()->GetHandleTable();
+ const auto process = handle_table.Get<Process>(process_handle);
if (!process) {
return ERR_INVALID_HANDLE;
}
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 35ec98c1a..59bc9e0af 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -266,7 +266,7 @@ SharedPtr<Thread> SetupMainThread(KernelCore& kernel, VAddr entry_point, u32 pri
SharedPtr<Thread> thread = std::move(thread_res).Unwrap();
// Register 1 must be a handle to the main thread
- const Handle guest_handle = kernel.HandleTable().Create(thread).Unwrap();
+ const Handle guest_handle = owner_process.GetHandleTable().Create(thread).Unwrap();
thread->SetGuestHandle(guest_handle);
thread->GetContext().cpu_registers[1] = guest_handle;
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp
index e61748ca3..cf065c2e0 100644
--- a/src/core/hle/service/acc/acc.cpp
+++ b/src/core/hle/service/acc/acc.cpp
@@ -2,9 +2,13 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <algorithm>
#include <array>
+#include "common/common_paths.h"
#include "common/common_types.h"
+#include "common/file_util.h"
#include "common/logging/log.h"
+#include "common/string_util.h"
#include "common/swap.h"
#include "core/core_timing.h"
#include "core/hle/ipc_helpers.h"
@@ -16,6 +20,9 @@
#include "core/hle/service/acc/profile_manager.h"
namespace Service::Account {
+
+constexpr u32 MAX_JPEG_IMAGE_SIZE = 0x20000;
+
// TODO: RE this structure
struct UserData {
INSERT_PADDING_WORDS(1);
@@ -27,6 +34,11 @@ struct UserData {
};
static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size");
+static std::string GetImagePath(UUID uuid) {
+ return FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
+ "/system/save/8000000000000010/su/avators/" + uuid.FormatSwitch() + ".jpg";
+}
+
class IProfile final : public ServiceFramework<IProfile> {
public:
explicit IProfile(UUID user_id, ProfileManager& profile_manager)
@@ -73,11 +85,11 @@ private:
}
void LoadImage(Kernel::HLERequestContext& ctx) {
- LOG_WARNING(Service_ACC, "(STUBBED) called");
+ LOG_DEBUG(Service_ACC, "called");
// smallest jpeg https://github.com/mathiasbynens/small/blob/master/jpeg.jpg
- // TODO(mailwl): load actual profile image from disk, width 256px, max size 0x20000
- constexpr u32 jpeg_size = 107;
- static constexpr std::array<u8, jpeg_size> jpeg{
+ // used as a backup should the one on disk not exist
+ constexpr u32 backup_jpeg_size = 107;
+ static constexpr std::array<u8, backup_jpeg_size> backup_jpeg{
0xff, 0xd8, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03,
0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x04, 0x06, 0x04, 0x04, 0x04, 0x04, 0x04,
0x08, 0x06, 0x06, 0x05, 0x06, 0x09, 0x08, 0x0a, 0x0a, 0x09, 0x08, 0x09, 0x09, 0x0a,
@@ -87,18 +99,42 @@ private:
0xff, 0xcc, 0x00, 0x06, 0x00, 0x10, 0x10, 0x05, 0xff, 0xda, 0x00, 0x08, 0x01, 0x01,
0x00, 0x00, 0x3f, 0x00, 0xd2, 0xcf, 0x20, 0xff, 0xd9,
};
- ctx.WriteBuffer(jpeg);
+
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
- rb.Push<u32>(jpeg_size);
+
+ const FileUtil::IOFile image(GetImagePath(user_id), "rb");
+
+ if (!image.IsOpen()) {
+ LOG_WARNING(Service_ACC,
+ "Failed to load user provided image! Falling back to built-in backup...");
+ ctx.WriteBuffer(backup_jpeg);
+ rb.Push<u32>(backup_jpeg_size);
+ } else {
+ const auto size = std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE);
+ std::vector<u8> buffer(size);
+ image.ReadBytes(buffer.data(), buffer.size());
+
+ ctx.WriteBuffer(buffer.data(), buffer.size());
+ rb.Push<u32>(buffer.size());
+ }
}
void GetImageSize(Kernel::HLERequestContext& ctx) {
- LOG_WARNING(Service_ACC, "(STUBBED) called");
- constexpr u32 jpeg_size = 107;
+ LOG_DEBUG(Service_ACC, "called");
+ constexpr u32 backup_jpeg_size = 107;
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
- rb.Push<u32>(jpeg_size);
+
+ const FileUtil::IOFile image(GetImagePath(user_id), "rb");
+
+ if (!image.IsOpen()) {
+ LOG_WARNING(Service_ACC,
+ "Failed to load user provided image! Falling back to built-in backup...");
+ rb.Push<u32>(backup_jpeg_size);
+ } else {
+ rb.Push<u32>(std::min<u32>(image.GetSize(), MAX_JPEG_IMAGE_SIZE));
+ }
}
const ProfileManager& profile_manager;
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index bcb3475db..3cac1b4ff 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -3,41 +3,66 @@
// Refer to the license.txt file included.
#include <random>
-#include <boost/optional.hpp>
+
+#include "common/file_util.h"
#include "core/hle/service/acc/profile_manager.h"
#include "core/settings.h"
namespace Service::Account {
+
+struct UserRaw {
+ UUID uuid;
+ UUID uuid2;
+ u64 timestamp;
+ ProfileUsername username;
+ INSERT_PADDING_BYTES(0x80);
+};
+static_assert(sizeof(UserRaw) == 0xC8, "UserRaw has incorrect size.");
+
+struct ProfileDataRaw {
+ INSERT_PADDING_BYTES(0x10);
+ std::array<UserRaw, MAX_USERS> users;
+};
+static_assert(sizeof(ProfileDataRaw) == 0x650, "ProfileDataRaw has incorrect size.");
+
// TODO(ogniK): Get actual error codes
constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1);
constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2);
constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20);
-const UUID& UUID::Generate() {
+constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/";
+
+UUID UUID::Generate() {
std::random_device device;
std::mt19937 gen(device());
std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
- uuid[0] = distribution(gen);
- uuid[1] = distribution(gen);
- return *this;
+ return UUID{distribution(gen), distribution(gen)};
}
ProfileManager::ProfileManager() {
- // TODO(ogniK): Create the default user we have for now until loading/saving users is added
- auto user_uuid = UUID{1, 0};
- ASSERT(CreateNewUser(user_uuid, Settings::values.username).IsSuccess());
- OpenUser(user_uuid);
+ ParseUserSaveFile();
+
+ if (user_count == 0)
+ CreateNewUser(UUID::Generate(), "yuzu");
+
+ auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1);
+ if (UserExistsIndex(current))
+ current = 0;
+
+ OpenUser(*GetUser(current));
}
-ProfileManager::~ProfileManager() = default;
+ProfileManager::~ProfileManager() {
+ WriteUserSaveFile();
+}
/// After a users creation it needs to be "registered" to the system. AddToProfiles handles the
/// internal management of the users profiles
-boost::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) {
+std::optional<std::size_t> ProfileManager::AddToProfiles(const ProfileInfo& profile) {
if (user_count >= MAX_USERS) {
- return boost::none;
+ return {};
}
- profiles[user_count] = user;
+ profiles[user_count] = profile;
return user_count++;
}
@@ -56,7 +81,7 @@ bool ProfileManager::RemoveProfileAtIndex(std::size_t index) {
/// Helper function to register a user to the system
ResultCode ProfileManager::AddUser(const ProfileInfo& user) {
- if (AddToProfiles(user) == boost::none) {
+ if (!AddToProfiles(user)) {
return ERROR_TOO_MANY_USERS;
}
return RESULT_SUCCESS;
@@ -101,31 +126,40 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username)
return CreateNewUser(uuid, username_output);
}
+std::optional<UUID> ProfileManager::GetUser(std::size_t index) const {
+ if (index >= MAX_USERS) {
+ return {};
+ }
+
+ return profiles[index].user_uuid;
+}
+
/// Returns a users profile index based on their user id.
-boost::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
+std::optional<std::size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
if (!uuid) {
- return boost::none;
+ return {};
}
- auto iter = std::find_if(profiles.begin(), profiles.end(),
- [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; });
+
+ const auto iter = std::find_if(profiles.begin(), profiles.end(),
+ [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; });
if (iter == profiles.end()) {
- return boost::none;
+ return {};
}
+
return static_cast<std::size_t>(std::distance(profiles.begin(), iter));
}
/// Returns a users profile index based on their profile
-boost::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) const {
+std::optional<std::size_t> ProfileManager::GetUserIndex(const ProfileInfo& user) const {
return GetUserIndex(user.user_uuid);
}
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
-bool ProfileManager::GetProfileBase(boost::optional<std::size_t> index,
- ProfileBase& profile) const {
- if (index == boost::none || index >= MAX_USERS) {
+bool ProfileManager::GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const {
+ if (!index || index >= MAX_USERS) {
return false;
}
- const auto& prof_info = profiles[index.get()];
+ const auto& prof_info = profiles[*index];
profile.user_uuid = prof_info.user_uuid;
profile.username = prof_info.username;
profile.timestamp = prof_info.creation_time;
@@ -134,7 +168,7 @@ bool ProfileManager::GetProfileBase(boost::optional<std::size_t> index,
/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const {
- auto idx = GetUserIndex(uuid);
+ const auto idx = GetUserIndex(uuid);
return GetProfileBase(idx, profile);
}
@@ -161,26 +195,34 @@ std::size_t ProfileManager::GetOpenUserCount() const {
/// Checks if a user id exists in our profile manager
bool ProfileManager::UserExists(UUID uuid) const {
- return (GetUserIndex(uuid) != boost::none);
+ return GetUserIndex(uuid) != std::nullopt;
+}
+
+bool ProfileManager::UserExistsIndex(std::size_t index) const {
+ if (index >= MAX_USERS)
+ return false;
+ return profiles[index].user_uuid.uuid != INVALID_UUID;
}
/// Opens a specific user
void ProfileManager::OpenUser(UUID uuid) {
- auto idx = GetUserIndex(uuid);
- if (idx == boost::none) {
+ const auto idx = GetUserIndex(uuid);
+ if (!idx) {
return;
}
- profiles[idx.get()].is_open = true;
+
+ profiles[*idx].is_open = true;
last_opened_user = uuid;
}
/// Closes a specific user
void ProfileManager::CloseUser(UUID uuid) {
- auto idx = GetUserIndex(uuid);
- if (idx == boost::none) {
+ const auto idx = GetUserIndex(uuid);
+ if (!idx) {
return;
}
- profiles[idx.get()].is_open = false;
+
+ profiles[*idx].is_open = false;
}
/// Gets all valid user ids on the system
@@ -210,10 +252,10 @@ UUID ProfileManager::GetLastOpenedUser() const {
}
/// Return the users profile base and the unknown arbitary data.
-bool ProfileManager::GetProfileBaseAndData(boost::optional<std::size_t> index, ProfileBase& profile,
+bool ProfileManager::GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile,
ProfileData& data) const {
if (GetProfileBase(index, profile)) {
- data = profiles[index.get()].data;
+ data = profiles[*index].data;
return true;
}
return false;
@@ -222,7 +264,7 @@ bool ProfileManager::GetProfileBaseAndData(boost::optional<std::size_t> index, P
/// Return the users profile base and the unknown arbitary data.
bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile,
ProfileData& data) const {
- auto idx = GetUserIndex(uuid);
+ const auto idx = GetUserIndex(uuid);
return GetProfileBaseAndData(idx, profile, data);
}
@@ -239,4 +281,96 @@ bool ProfileManager::CanSystemRegisterUser() const {
// emulate qlaunch. Update this to dynamically change.
}
+bool ProfileManager::RemoveUser(UUID uuid) {
+ const auto index = GetUserIndex(uuid);
+ if (!index) {
+ return false;
+ }
+
+ profiles[*index] = ProfileInfo{};
+ std::stable_partition(profiles.begin(), profiles.end(),
+ [](const ProfileInfo& profile) { return profile.user_uuid; });
+ return true;
+}
+
+bool ProfileManager::SetProfileBase(UUID uuid, const ProfileBase& profile_new) {
+ const auto index = GetUserIndex(uuid);
+ if (!index || profile_new.user_uuid == UUID(INVALID_UUID)) {
+ return false;
+ }
+
+ auto& profile = profiles[*index];
+ profile.user_uuid = profile_new.user_uuid;
+ profile.username = profile_new.username;
+ profile.creation_time = profile_new.timestamp;
+
+ return true;
+}
+
+void ProfileManager::ParseUserSaveFile() {
+ FileUtil::IOFile save(FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
+ ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat",
+ "rb");
+
+ if (!save.IsOpen()) {
+ LOG_WARNING(Service_ACC, "Failed to load profile data from save data... Generating new "
+ "user 'yuzu' with random UUID.");
+ return;
+ }
+
+ ProfileDataRaw data;
+ if (save.ReadBytes(&data, sizeof(ProfileDataRaw)) != sizeof(ProfileDataRaw)) {
+ LOG_WARNING(Service_ACC, "profiles.dat is smaller than expected... Generating new user "
+ "'yuzu' with random UUID.");
+ return;
+ }
+
+ for (std::size_t i = 0; i < MAX_USERS; ++i) {
+ const auto& user = data.users[i];
+
+ if (user.uuid != UUID(INVALID_UUID))
+ AddUser({user.uuid, user.username, user.timestamp, {}, false});
+ }
+
+ std::stable_partition(profiles.begin(), profiles.end(),
+ [](const ProfileInfo& profile) { return profile.user_uuid; });
+}
+
+void ProfileManager::WriteUserSaveFile() {
+ ProfileDataRaw raw{};
+
+ for (std::size_t i = 0; i < MAX_USERS; ++i) {
+ raw.users[i].username = profiles[i].username;
+ raw.users[i].uuid2 = profiles[i].user_uuid;
+ raw.users[i].uuid = profiles[i].user_uuid;
+ raw.users[i].timestamp = profiles[i].creation_time;
+ }
+
+ const auto raw_path =
+ FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) + "/system/save/8000000000000010";
+ if (FileUtil::Exists(raw_path) && !FileUtil::IsDirectory(raw_path))
+ FileUtil::Delete(raw_path);
+
+ const auto path = FileUtil::GetUserPath(FileUtil::UserPath::NANDDir) +
+ ACC_SAVE_AVATORS_BASE_PATH + "profiles.dat";
+
+ if (!FileUtil::CreateFullPath(path)) {
+ LOG_WARNING(Service_ACC, "Failed to create full path of profiles.dat. Create the directory "
+ "nand/system/save/8000000000000010/su/avators to mitigate this "
+ "issue.");
+ return;
+ }
+
+ FileUtil::IOFile save(path, "wb");
+
+ if (!save.IsOpen()) {
+ LOG_WARNING(Service_ACC, "Failed to write save data to file... No changes to user data "
+ "made in current session will be saved.");
+ return;
+ }
+
+ save.Resize(sizeof(ProfileDataRaw));
+ save.WriteBytes(&raw, sizeof(ProfileDataRaw));
+}
+
}; // namespace Service::Account
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h
index bffd4cf4d..1cd2e51b2 100644
--- a/src/core/hle/service/acc/profile_manager.h
+++ b/src/core/hle/service/acc/profile_manager.h
@@ -5,8 +5,8 @@
#pragma once
#include <array>
+#include <optional>
-#include "boost/optional.hpp"
#include "common/common_types.h"
#include "common/swap.h"
#include "core/hle/result.h"
@@ -36,7 +36,7 @@ struct UUID {
}
// TODO(ogniK): Properly generate uuids based on RFC-4122
- const UUID& Generate();
+ static UUID Generate();
// Set the UUID to {0,0} to be considered an invalid user
void Invalidate() {
@@ -45,6 +45,15 @@ struct UUID {
std::string Format() const {
return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
}
+
+ std::string FormatSwitch() const {
+ std::array<u8, 16> s{};
+ std::memcpy(s.data(), uuid.data(), sizeof(u128));
+ return fmt::format("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{"
+ ":02x}{:02x}{:02x}{:02x}{:02x}",
+ s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11],
+ s[12], s[13], s[14], s[15]);
+ }
};
static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
@@ -81,18 +90,19 @@ static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase is an invalid size");
/// objects
class ProfileManager {
public:
- ProfileManager(); // TODO(ogniK): Load from system save
+ ProfileManager();
~ProfileManager();
ResultCode AddUser(const ProfileInfo& user);
ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username);
ResultCode CreateNewUser(UUID uuid, const std::string& username);
- boost::optional<std::size_t> GetUserIndex(const UUID& uuid) const;
- boost::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const;
- bool GetProfileBase(boost::optional<std::size_t> index, ProfileBase& profile) const;
+ std::optional<UUID> GetUser(std::size_t index) const;
+ std::optional<std::size_t> GetUserIndex(const UUID& uuid) const;
+ std::optional<std::size_t> GetUserIndex(const ProfileInfo& user) const;
+ bool GetProfileBase(std::optional<std::size_t> index, ProfileBase& profile) const;
bool GetProfileBase(UUID uuid, ProfileBase& profile) const;
bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;
- bool GetProfileBaseAndData(boost::optional<std::size_t> index, ProfileBase& profile,
+ bool GetProfileBaseAndData(std::optional<std::size_t> index, ProfileBase& profile,
ProfileData& data) const;
bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const;
bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
@@ -100,6 +110,7 @@ public:
std::size_t GetUserCount() const;
std::size_t GetOpenUserCount() const;
bool UserExists(UUID uuid) const;
+ bool UserExistsIndex(std::size_t index) const;
void OpenUser(UUID uuid);
void CloseUser(UUID uuid);
UserIDArray GetOpenUsers() const;
@@ -108,11 +119,17 @@ public:
bool CanSystemRegisterUser() const;
+ bool RemoveUser(UUID uuid);
+ bool SetProfileBase(UUID uuid, const ProfileBase& profile_new);
+
private:
+ void ParseUserSaveFile();
+ void WriteUserSaveFile();
+ std::optional<std::size_t> AddToProfiles(const ProfileInfo& profile);
+ bool RemoveProfileAtIndex(std::size_t index);
+
std::array<ProfileInfo, MAX_USERS> profiles{};
std::size_t user_count = 0;
- boost::optional<std::size_t> AddToProfiles(const ProfileInfo& profile);
- bool RemoveProfileAtIndex(std::size_t index);
UUID last_opened_user{INVALID_UUID};
};
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 4d1f83170..59aafd616 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -4,17 +4,20 @@
#include <array>
#include <cinttypes>
+#include <cstring>
#include <stack>
#include "core/core.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/process.h"
+#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/am/am.h"
#include "core/hle/service/am/applet_ae.h"
#include "core/hle/service/am/applet_oe.h"
#include "core/hle/service/am/idle.h"
#include "core/hle/service/am/omm.h"
#include "core/hle/service/am/spsm.h"
+#include "core/hle/service/am/tcap.h"
#include "core/hle/service/apm/apm.h"
#include "core/hle/service/filesystem/filesystem.h"
#include "core/hle/service/nvflinger/nvflinger.h"
@@ -25,14 +28,29 @@
namespace Service::AM {
+constexpr u32 POP_LAUNCH_PARAMETER_MAGIC = 0xC79497CA;
+
+struct LaunchParameters {
+ u32_le magic;
+ u32_le is_account_selected;
+ u128 current_user;
+ INSERT_PADDING_BYTES(0x70);
+};
+static_assert(sizeof(LaunchParameters) == 0x88);
+
IWindowController::IWindowController() : ServiceFramework("IWindowController") {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "CreateWindow"},
{1, &IWindowController::GetAppletResourceUserId, "GetAppletResourceUserId"},
{10, &IWindowController::AcquireForegroundRights, "AcquireForegroundRights"},
{11, nullptr, "ReleaseForegroundRights"},
{12, nullptr, "RejectToChangeIntoBackground"},
+ {20, nullptr, "SetAppletWindowVisibility"},
+ {21, nullptr, "SetAppletGpuTimeSlice"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
@@ -87,6 +105,7 @@ void IAudioController::GetLibraryAppletExpectedMasterVolume(Kernel::HLERequestCo
}
IDisplayController::IDisplayController() : ServiceFramework("IDisplayController") {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "GetLastForegroundCaptureImage"},
{1, nullptr, "UpdateLastForegroundCaptureImage"},
@@ -117,7 +136,11 @@ IDisplayController::IDisplayController() : ServiceFramework("IDisplayController"
{25, nullptr, "ReleaseLastForegroundCaptureSharedBuffer"},
{26, nullptr, "AcquireCallerAppletCaptureSharedBuffer"},
{27, nullptr, "ReleaseCallerAppletCaptureSharedBuffer"},
+ // 6.0.0+
+ {28, nullptr, "TakeScreenShotOfOwnLayerEx"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
@@ -128,6 +151,7 @@ IDebugFunctions::~IDebugFunctions() = default;
ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger)
: ServiceFramework("ISelfController"), nvflinger(std::move(nvflinger)) {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "Exit"},
{1, &ISelfController::LockExit, "LockExit"},
@@ -136,10 +160,8 @@ ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger
{4, nullptr, "LeaveFatalSection"},
{9, &ISelfController::GetLibraryAppletLaunchableEvent, "GetLibraryAppletLaunchableEvent"},
{10, &ISelfController::SetScreenShotPermission, "SetScreenShotPermission"},
- {11, &ISelfController::SetOperationModeChangedNotification,
- "SetOperationModeChangedNotification"},
- {12, &ISelfController::SetPerformanceModeChangedNotification,
- "SetPerformanceModeChangedNotification"},
+ {11, &ISelfController::SetOperationModeChangedNotification, "SetOperationModeChangedNotification"},
+ {12, &ISelfController::SetPerformanceModeChangedNotification, "SetPerformanceModeChangedNotification"},
{13, &ISelfController::SetFocusHandlingMode, "SetFocusHandlingMode"},
{14, &ISelfController::SetRestartMessageEnabled, "SetRestartMessageEnabled"},
{15, nullptr, "SetScreenShotAppletIdentityInfo"},
@@ -165,7 +187,12 @@ ISelfController::ISelfController(std::shared_ptr<NVFlinger::NVFlinger> nvflinger
{69, nullptr, "IsAutoSleepDisabled"},
{70, nullptr, "ReportMultimediaError"},
{80, nullptr, "SetWirelessPriorityMode"},
+ {90, nullptr, "GetAccumulatedSuspendedTickValue"},
+ {91, nullptr, "GetAccumulatedSuspendedTickChangedEvent"},
+ {1000, nullptr, "GetDebugStorageChannel"},
};
+ // clang-format on
+
RegisterHandlers(functions);
auto& kernel = Core::System::GetInstance().Kernel();
@@ -312,6 +339,7 @@ void ISelfController::GetIdleTimeDetectionExtension(Kernel::HLERequestContext& c
}
ICommonStateGetter::ICommonStateGetter() : ServiceFramework("ICommonStateGetter") {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, &ICommonStateGetter::GetEventHandle, "GetEventHandle"},
{1, &ICommonStateGetter::ReceiveMessage, "ReceiveMessage"},
@@ -336,11 +364,12 @@ ICommonStateGetter::ICommonStateGetter() : ServiceFramework("ICommonStateGetter"
{52, nullptr, "SwitchLcdBacklight"},
{55, nullptr, "IsInControllerFirmwareUpdateSection"},
{60, &ICommonStateGetter::GetDefaultDisplayResolution, "GetDefaultDisplayResolution"},
- {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent,
- "GetDefaultDisplayResolutionChangeEvent"},
+ {61, &ICommonStateGetter::GetDefaultDisplayResolutionChangeEvent, "GetDefaultDisplayResolutionChangeEvent"},
{62, nullptr, "GetHdcpAuthenticationState"},
{63, nullptr, "GetHdcpAuthenticationStateChangeEvent"},
};
+ // clang-format on
+
RegisterHandlers(functions);
auto& kernel = Core::System::GetInstance().Kernel();
@@ -432,11 +461,14 @@ class IStorageAccessor final : public ServiceFramework<IStorageAccessor> {
public:
explicit IStorageAccessor(std::vector<u8> buffer)
: ServiceFramework("IStorageAccessor"), buffer(std::move(buffer)) {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, &IStorageAccessor::GetSize, "GetSize"},
{10, &IStorageAccessor::Write, "Write"},
{11, &IStorageAccessor::Read, "Read"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
@@ -489,10 +521,13 @@ class IStorage final : public ServiceFramework<IStorage> {
public:
explicit IStorage(std::vector<u8> buffer)
: ServiceFramework("IStorage"), buffer(std::move(buffer)) {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, &IStorage::Open, "Open"},
{1, nullptr, "OpenTransferStorage"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
@@ -512,6 +547,7 @@ private:
class ILibraryAppletAccessor final : public ServiceFramework<ILibraryAppletAccessor> {
public:
explicit ILibraryAppletAccessor() : ServiceFramework("ILibraryAppletAccessor") {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, &ILibraryAppletAccessor::GetAppletStateChangedEvent, "GetAppletStateChangedEvent"},
{1, nullptr, "IsCompleted"},
@@ -532,6 +568,8 @@ public:
{150, nullptr, "RequestForAppletToGetForeground"},
{160, nullptr, "GetIndirectLayerConsumerHandle"},
};
+ // clang-format on
+
RegisterHandlers(functions);
auto& kernel = Core::System::GetInstance().Kernel();
@@ -624,13 +662,13 @@ void ILibraryAppletCreator::CreateStorage(Kernel::HLERequestContext& ctx) {
}
IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationFunctions") {
+ // clang-format off
static const FunctionInfo functions[] = {
{1, &IApplicationFunctions::PopLaunchParameter, "PopLaunchParameter"},
{10, nullptr, "CreateApplicationAndPushAndRequestToStart"},
{11, nullptr, "CreateApplicationAndPushAndRequestToStartForQuest"},
{12, nullptr, "CreateApplicationAndRequestToStart"},
- {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest,
- "CreateApplicationAndRequestToStartForQuest"},
+ {13, &IApplicationFunctions::CreateApplicationAndRequestToStartForQuest, "CreateApplicationAndRequestToStartForQuest"},
{20, &IApplicationFunctions::EnsureSaveData, "EnsureSaveData"},
{21, &IApplicationFunctions::GetDesiredLanguage, "GetDesiredLanguage"},
{22, &IApplicationFunctions::SetTerminateResult, "SetTerminateResult"},
@@ -638,10 +676,8 @@ IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationF
{24, nullptr, "GetLaunchStorageInfoForDebug"},
{25, nullptr, "ExtendSaveData"},
{26, nullptr, "GetSaveDataSize"},
- {30, &IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed,
- "BeginBlockingHomeButtonShortAndLongPressed"},
- {31, &IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed,
- "EndBlockingHomeButtonShortAndLongPressed"},
+ {30, &IApplicationFunctions::BeginBlockingHomeButtonShortAndLongPressed, "BeginBlockingHomeButtonShortAndLongPressed"},
+ {31, &IApplicationFunctions::EndBlockingHomeButtonShortAndLongPressed, "EndBlockingHomeButtonShortAndLongPressed"},
{32, &IApplicationFunctions::BeginBlockingHomeButton, "BeginBlockingHomeButton"},
{33, &IApplicationFunctions::EndBlockingHomeButton, "EndBlockingHomeButton"},
{40, &IApplicationFunctions::NotifyRunning, "NotifyRunning"},
@@ -666,6 +702,8 @@ IApplicationFunctions::IApplicationFunctions() : ServiceFramework("IApplicationF
{1000, nullptr, "CreateMovieMaker"},
{1001, nullptr, "PrepareForJit"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
@@ -698,20 +736,23 @@ void IApplicationFunctions::EndBlockingHomeButton(Kernel::HLERequestContext& ctx
}
void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
- constexpr std::array<u8, 0x88> data{{
- 0xca, 0x97, 0x94, 0xc7, // Magic
- 1, 0, 0, 0, // IsAccountSelected (bool)
- 1, 0, 0, 0, // User Id (word 0)
- 0, 0, 0, 0, // User Id (word 1)
- 0, 0, 0, 0, // User Id (word 2)
- 0, 0, 0, 0 // User Id (word 3)
- }};
+ LaunchParameters params{};
+
+ params.magic = POP_LAUNCH_PARAMETER_MAGIC;
+ params.is_account_selected = 1;
- std::vector<u8> buffer(data.begin(), data.end());
+ Account::ProfileManager profile_manager{};
+ const auto uuid = profile_manager.GetUser(Settings::values.current_user);
+ ASSERT(uuid != std::nullopt);
+ params.current_user = uuid->uuid;
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(RESULT_SUCCESS);
+
+ std::vector<u8> buffer(sizeof(LaunchParameters));
+ std::memcpy(buffer.data(), &params, buffer.size());
+
rb.PushIpcInterface<AM::IStorage>(buffer);
LOG_DEBUG(Service_AM, "called");
@@ -804,9 +845,11 @@ void InstallInterfaces(SM::ServiceManager& service_manager,
std::make_shared<IdleSys>()->InstallAsService(service_manager);
std::make_shared<OMM>()->InstallAsService(service_manager);
std::make_shared<SPSM>()->InstallAsService(service_manager);
+ std::make_shared<TCAP>()->InstallAsService(service_manager);
}
IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions") {
+ // clang-format off
static const FunctionInfo functions[] = {
{10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
{11, nullptr, "LockForeground"},
@@ -815,7 +858,10 @@ IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions"
{21, nullptr, "GetPopFromGeneralChannelEvent"},
{30, nullptr, "GetHomeButtonWriterLockAccessor"},
{31, nullptr, "GetWriterLockAccessorEx"},
+ {100, nullptr, "PopRequestLaunchApplicationForDebug"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
@@ -828,6 +874,7 @@ void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx)
}
IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStateController") {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "RequestToEnterSleep"},
{1, nullptr, "EnterSleep"},
@@ -841,18 +888,23 @@ IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStat
{14, nullptr, "ShouldSleepOnBoot"},
{15, nullptr, "GetHdcpAuthenticationFailedEvent"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
IGlobalStateController::~IGlobalStateController() = default;
IApplicationCreator::IApplicationCreator() : ServiceFramework("IApplicationCreator") {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "CreateApplication"},
{1, nullptr, "PopLaunchRequestedApplication"},
{10, nullptr, "CreateSystemApplication"},
{100, nullptr, "PopFloatingApplicationForDevelopment"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
@@ -860,6 +912,7 @@ IApplicationCreator::~IApplicationCreator() = default;
IProcessWindingController::IProcessWindingController()
: ServiceFramework("IProcessWindingController") {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "GetLaunchReason"},
{11, nullptr, "OpenCallingLibraryApplet"},
@@ -870,6 +923,8 @@ IProcessWindingController::IProcessWindingController()
{40, nullptr, "ReserveToStartAndWaitAndUnwindThis"},
{41, nullptr, "ReserveToStartAndWait"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
diff --git a/src/core/hle/service/am/applet_ae.cpp b/src/core/hle/service/am/applet_ae.cpp
index 4296c255e..68ea778e8 100644
--- a/src/core/hle/service/am/applet_ae.cpp
+++ b/src/core/hle/service/am/applet_ae.cpp
@@ -211,6 +211,7 @@ void AppletAE::OpenLibraryAppletProxyOld(Kernel::HLERequestContext& ctx) {
AppletAE::AppletAE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger)
: ServiceFramework("appletAE"), nvflinger(std::move(nvflinger)) {
+ // clang-format off
static const FunctionInfo functions[] = {
{100, &AppletAE::OpenSystemAppletProxy, "OpenSystemAppletProxy"},
{200, &AppletAE::OpenLibraryAppletProxyOld, "OpenLibraryAppletProxyOld"},
@@ -218,7 +219,10 @@ AppletAE::AppletAE(std::shared_ptr<NVFlinger::NVFlinger> nvflinger)
{300, nullptr, "OpenOverlayAppletProxy"},
{350, nullptr, "OpenSystemApplicationProxy"},
{400, nullptr, "CreateSelfLibraryAppletCreatorForDevelop"},
+ {401, nullptr, "GetSystemAppletControllerForDebug"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
diff --git a/src/core/hle/service/am/applet_oe.cpp b/src/core/hle/service/am/applet_oe.cpp
index e45cf6e20..60717afd9 100644
--- a/src/core/hle/service/am/applet_oe.cpp
+++ b/src/core/hle/service/am/applet_oe.cpp
@@ -14,6 +14,7 @@ class IApplicationProxy final : public ServiceFramework<IApplicationProxy> {
public:
explicit IApplicationProxy(std::shared_ptr<NVFlinger::NVFlinger> nvflinger)
: ServiceFramework("IApplicationProxy"), nvflinger(std::move(nvflinger)) {
+ // clang-format off
static const FunctionInfo functions[] = {
{0, &IApplicationProxy::GetCommonStateGetter, "GetCommonStateGetter"},
{1, &IApplicationProxy::GetSelfController, "GetSelfController"},
@@ -25,6 +26,8 @@ public:
{20, &IApplicationProxy::GetApplicationFunctions, "GetApplicationFunctions"},
{1000, &IApplicationProxy::GetDebugFunctions, "GetDebugFunctions"},
};
+ // clang-format on
+
RegisterHandlers(functions);
}
diff --git a/src/core/hle/service/am/idle.cpp b/src/core/hle/service/am/idle.cpp
index 0e3088bc8..f814fe2c0 100644
--- a/src/core/hle/service/am/idle.cpp
+++ b/src/core/hle/service/am/idle.cpp
@@ -12,9 +12,9 @@ IdleSys::IdleSys() : ServiceFramework{"idle:sys"} {
{0, nullptr, "GetAutoPowerDownEvent"},
{1, nullptr, "Unknown1"},
{2, nullptr, "Unknown2"},
- {3, nullptr, "Unknown3"},
- {4, nullptr, "Unknown4"},
- {5, nullptr, "Unknown5"},
+ {3, nullptr, "SetHandlingContext"},
+ {4, nullptr, "LoadAndApplySettings"},
+ {5, nullptr, "ReportUserIsActive"},
};
// clang-format on
diff --git a/src/core/hle/service/am/tcap.cpp b/src/core/hle/service/am/tcap.cpp
new file mode 100644
index 000000000..a75cbdda8
--- /dev/null
+++ b/src/core/hle/service/am/tcap.cpp
@@ -0,0 +1,23 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include "core/hle/service/am/tcap.h"
+
+namespace Service::AM {
+
+TCAP::TCAP() : ServiceFramework{"tcap"} {
+ // clang-format off
+ static const FunctionInfo functions[] = {
+ {0, nullptr, "GetContinuousHighSkinTemperatureEvent"},
+ {1, nullptr, "SetOperationMode"},
+ {2, nullptr, "LoadAndApplySettings"},
+ };
+ // clang-format on
+
+ RegisterHandlers(functions);
+}
+
+TCAP::~TCAP() = default;
+
+} // namespace Service::AM
diff --git a/src/core/hle/service/am/tcap.h b/src/core/hle/service/am/tcap.h
new file mode 100644
index 000000000..2021b55d1
--- /dev/null
+++ b/src/core/hle/service/am/tcap.h
@@ -0,0 +1,17 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include "core/hle/service/service.h"
+
+namespace Service::AM {
+
+class TCAP final : public ServiceFramework<TCAP> {
+public:
+ explicit TCAP();
+ ~TCAP() override;
+};
+
+} // namespace Service::AM
diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp
index 428069df2..54305cf05 100644
--- a/src/core/hle/service/aoc/aoc_u.cpp
+++ b/src/core/hle/service/aoc/aoc_u.cpp
@@ -24,8 +24,8 @@ namespace Service::AOC {
constexpr u64 DLC_BASE_TITLE_ID_MASK = 0xFFFFFFFFFFFFE000;
constexpr u64 DLC_BASE_TO_AOC_ID = 0x1000;
-static bool CheckAOCTitleIDMatchesBase(u64 base, u64 aoc) {
- return (aoc & DLC_BASE_TITLE_ID_MASK) == base;
+static bool CheckAOCTitleIDMatchesBase(u64 title_id, u64 base) {
+ return (title_id & DLC_BASE_TITLE_ID_MASK) == base;
}
static std::vector<u64> AccumulateAOCTitleIDs() {
@@ -74,7 +74,7 @@ void AOC_U::CountAddOnContent(Kernel::HLERequestContext& ctx) {
const auto current = Core::System::GetInstance().CurrentProcess()->GetTitleID();
rb.Push<u32>(static_cast<u32>(
std::count_if(add_on_content.begin(), add_on_content.end(),
- [&current](u64 tid) { return (tid & DLC_BASE_TITLE_ID_MASK) == current; })));
+ [current](u64 tid) { return CheckAOCTitleIDMatchesBase(tid, current); })));
}
void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index d5dced429..c87721c39 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -17,6 +17,7 @@
#include "core/file_sys/errors.h"
#include "core/file_sys/mode.h"
#include "core/file_sys/nca_metadata.h"
+#include "core/file_sys/patch_manager.h"
#include "core/file_sys/savedata_factory.h"
#include "core/file_sys/vfs.h"
#include "core/hle/ipc_helpers.h"
@@ -630,6 +631,7 @@ void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) {
static_cast<u8>(storage_id), unknown, title_id);
auto data = OpenRomFS(title_id, storage_id, FileSys::ContentRecordType::Data);
+
if (data.Failed()) {
// TODO(DarkLordZach): Find the right error code to use here
LOG_ERROR(Service_FS,
@@ -640,7 +642,9 @@ void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) {
return;
}
- IStorage storage(std::move(data.Unwrap()));
+ FileSys::PatchManager pm{title_id};
+
+ IStorage storage(pm.PatchRomFS(std::move(data.Unwrap()), 0, FileSys::ContentRecordType::Data));
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(RESULT_SUCCESS);
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index b06e65a77..4b4d1324f 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -108,9 +108,10 @@ void Controller_NPad::OnInit() {
styleset_changed_event =
Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "npad:NpadStyleSetChanged");
- if (!IsControllerActivated())
+ if (!IsControllerActivated()) {
return;
- std::size_t controller{};
+ }
+
if (style.raw == 0) {
// We want to support all controllers
style.handheld.Assign(1);
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index beb89218a..a9aa9ec78 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -827,6 +827,7 @@ public:
{11, nullptr, "EnableJoyPollingReceiveMode"},
{12, nullptr, "DisableJoyPollingReceiveMode"},
{13, nullptr, "GetPollingData"},
+ {14, nullptr, "SetStatusManagerType"},
};
// clang-format on
diff --git a/src/core/hle/service/lbl/lbl.cpp b/src/core/hle/service/lbl/lbl.cpp
index 7321584e1..164c57e18 100644
--- a/src/core/hle/service/lbl/lbl.cpp
+++ b/src/core/hle/service/lbl/lbl.cpp
@@ -18,35 +18,35 @@ public:
explicit LBL() : ServiceFramework{"lbl"} {
// clang-format off
static const FunctionInfo functions[] = {
- {0, nullptr, "Unknown1"},
- {1, nullptr, "Unknown2"},
- {2, nullptr, "Unknown3"},
- {3, nullptr, "GetCurrentBacklightLevel"},
- {4, nullptr, "Unknown4"},
- {5, nullptr, "GetAlsComputedBacklightLevel"},
- {6, nullptr, "TurnOffBacklight"},
- {7, nullptr, "TurnOnBacklight"},
- {8, nullptr, "GetBacklightStatus"},
- {9, nullptr, "Unknown5"},
- {10, nullptr, "Unknown6"},
- {11, nullptr, "Unknown7"},
- {12, nullptr, "Unknown8"},
- {13, nullptr, "Unknown9"},
- {14, nullptr, "Unknown10"},
- {15, nullptr, "GetAutoBrightnessSetting"},
- {16, nullptr, "ReadRawLightSensor"},
- {17, nullptr, "Unknown11"},
- {18, nullptr, "Unknown12"},
- {19, nullptr, "Unknown13"},
- {20, nullptr, "Unknown14"},
- {21, nullptr, "Unknown15"},
- {22, nullptr, "Unknown16"},
- {23, nullptr, "Unknown17"},
- {24, nullptr, "Unknown18"},
- {25, nullptr, "Unknown19"},
+ {0, nullptr, "SaveCurrentSetting"},
+ {1, nullptr, "LoadCurrentSetting"},
+ {2, nullptr, "SetCurrentBrightnessSetting"},
+ {3, nullptr, "GetCurrentBrightnessSetting"},
+ {4, nullptr, "ApplyCurrentBrightnessSettingToBacklight"},
+ {5, nullptr, "GetBrightnessSettingAppliedToBacklight"},
+ {6, nullptr, "SwitchBacklightOn"},
+ {7, nullptr, "SwitchBacklightOff"},
+ {8, nullptr, "GetBacklightSwitchStatus"},
+ {9, nullptr, "EnableDimming"},
+ {10, nullptr, "DisableDimming"},
+ {11, nullptr, "IsDimmingEnabled"},
+ {12, nullptr, "EnableAutoBrightnessControl"},
+ {13, nullptr, "DisableAutoBrightnessControl"},
+ {14, nullptr, "IsAutoBrightnessControlEnabled"},
+ {15, nullptr, "SetAmbientLightSensorValue"},
+ {16, nullptr, "GetAmbientLightSensorValue"},
+ {17, nullptr, "SetBrightnessReflectionDelayLevel"},
+ {18, nullptr, "GetBrightnessReflectionDelayLevel"},
+ {19, nullptr, "SetCurrentBrightnessMapping"},
+ {20, nullptr, "GetCurrentBrightnessMapping"},
+ {21, nullptr, "SetCurrentAmbientLightSensorMapping"},
+ {22, nullptr, "GetCurrentAmbientLightSensorMapping"},
+ {23, nullptr, "IsAmbientLightSensorAvailable"},
+ {24, nullptr, "SetCurrentBrightnessSettingForVrMode"},
+ {25, nullptr, "GetCurrentBrightnessSettingForVrMode"},
{26, &LBL::EnableVrMode, "EnableVrMode"},
{27, &LBL::DisableVrMode, "DisableVrMode"},
- {28, &LBL::GetVrMode, "GetVrMode"},
+ {28, &LBL::IsVrModeEnabled, "IsVrModeEnabled"},
};
// clang-format on
@@ -72,7 +72,7 @@ private:
LOG_DEBUG(Service_LBL, "called");
}
- void GetVrMode(Kernel::HLERequestContext& ctx) {
+ void IsVrModeEnabled(Kernel::HLERequestContext& ctx) {
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
rb.Push(vr_mode_enabled);
diff --git a/src/core/hle/service/nfc/nfc.cpp b/src/core/hle/service/nfc/nfc.cpp
index 8fec97db8..30e542542 100644
--- a/src/core/hle/service/nfc/nfc.cpp
+++ b/src/core/hle/service/nfc/nfc.cpp
@@ -10,12 +10,13 @@
#include "core/hle/service/nfc/nfc.h"
#include "core/hle/service/service.h"
#include "core/hle/service/sm/sm.h"
+#include "core/settings.h"
namespace Service::NFC {
class IAm final : public ServiceFramework<IAm> {
public:
- explicit IAm() : ServiceFramework{"IAm"} {
+ explicit IAm() : ServiceFramework{"NFC::IAm"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "Initialize"},
@@ -52,7 +53,7 @@ private:
class MFIUser final : public ServiceFramework<MFIUser> {
public:
- explicit MFIUser() : ServiceFramework{"IUser"} {
+ explicit MFIUser() : ServiceFramework{"NFC::MFIUser"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, nullptr, "Initialize"},
@@ -100,13 +101,13 @@ private:
class IUser final : public ServiceFramework<IUser> {
public:
- explicit IUser() : ServiceFramework{"IUser"} {
+ explicit IUser() : ServiceFramework{"NFC::IUser"} {
// clang-format off
static const FunctionInfo functions[] = {
- {0, nullptr, "Initialize"},
- {1, nullptr, "Finalize"},
- {2, nullptr, "GetState"},
- {3, nullptr, "IsNfcEnabled"},
+ {0, &IUser::InitializeOld, "InitializeOld"},
+ {1, &IUser::FinalizeOld, "FinalizeOld"},
+ {2, &IUser::GetStateOld, "GetStateOld"},
+ {3, &IUser::IsNfcEnabledOld, "IsNfcEnabledOld"},
{400, nullptr, "Initialize"},
{401, nullptr, "Finalize"},
{402, nullptr, "GetState"},
@@ -130,11 +131,47 @@ public:
RegisterHandlers(functions);
}
+
+private:
+ enum class NfcStates : u32 {
+ Finalized = 6,
+ };
+
+ void InitializeOld(Kernel::HLERequestContext& ctx) {
+ IPC::ResponseBuilder rb{ctx, 2, 0};
+ rb.Push(RESULT_SUCCESS);
+
+ // We don't deal with hardware initialization so we can just stub this.
+ LOG_DEBUG(Service_NFC, "called");
+ }
+
+ void IsNfcEnabledOld(Kernel::HLERequestContext& ctx) {
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(RESULT_SUCCESS);
+ rb.PushRaw<u8>(Settings::values.enable_nfc);
+
+ LOG_DEBUG(Service_NFC, "IsNfcEnabledOld");
+ }
+
+ void GetStateOld(Kernel::HLERequestContext& ctx) {
+ LOG_WARNING(Service_NFC, "(STUBBED) called");
+
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(RESULT_SUCCESS);
+ rb.PushEnum(NfcStates::Finalized); // TODO(ogniK): Figure out if this matches nfp
+ }
+
+ void FinalizeOld(Kernel::HLERequestContext& ctx) {
+ LOG_WARNING(Service_NFC, "(STUBBED) called");
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
};
class NFC_U final : public ServiceFramework<NFC_U> {
public:
- explicit NFC_U() : ServiceFramework{"nfc:u"} {
+ explicit NFC_U() : ServiceFramework{"nfc:user"} {
// clang-format off
static const FunctionInfo functions[] = {
{0, &NFC_U::CreateUserInterface, "CreateUserInterface"},
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp
index 39c0c1e63..9a4eb9301 100644
--- a/src/core/hle/service/nfp/nfp.cpp
+++ b/src/core/hle/service/nfp/nfp.cpp
@@ -2,56 +2,67 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
+#include <atomic>
+
#include "common/logging/log.h"
#include "core/core.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/event.h"
+#include "core/hle/lock.h"
#include "core/hle/service/hid/hid.h"
#include "core/hle/service/nfp/nfp.h"
#include "core/hle/service/nfp/nfp_user.h"
namespace Service::NFP {
+namespace ErrCodes {
+constexpr ResultCode ERR_TAG_FAILED(ErrorModule::NFP,
+ -1); // TODO(ogniK): Find the actual error code
+}
+
Module::Interface::Interface(std::shared_ptr<Module> module, const char* name)
- : ServiceFramework(name), module(std::move(module)) {}
+ : ServiceFramework(name), module(std::move(module)) {
+ auto& kernel = Core::System::GetInstance().Kernel();
+ nfc_tag_load =
+ Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:NFCTagDetected");
+}
Module::Interface::~Interface() = default;
class IUser final : public ServiceFramework<IUser> {
public:
- IUser() : ServiceFramework("IUser") {
+ IUser(Module::Interface& nfp_interface)
+ : ServiceFramework("NFP::IUser"), nfp_interface(nfp_interface) {
static const FunctionInfo functions[] = {
{0, &IUser::Initialize, "Initialize"},
- {1, nullptr, "Finalize"},
+ {1, &IUser::Finalize, "Finalize"},
{2, &IUser::ListDevices, "ListDevices"},
- {3, nullptr, "StartDetection"},
- {4, nullptr, "StopDetection"},
- {5, nullptr, "Mount"},
- {6, nullptr, "Unmount"},
- {7, nullptr, "OpenApplicationArea"},
- {8, nullptr, "GetApplicationArea"},
+ {3, &IUser::StartDetection, "StartDetection"},
+ {4, &IUser::StopDetection, "StopDetection"},
+ {5, &IUser::Mount, "Mount"},
+ {6, &IUser::Unmount, "Unmount"},
+ {7, &IUser::OpenApplicationArea, "OpenApplicationArea"},
+ {8, &IUser::GetApplicationArea, "GetApplicationArea"},
{9, nullptr, "SetApplicationArea"},
{10, nullptr, "Flush"},
{11, nullptr, "Restore"},
{12, nullptr, "CreateApplicationArea"},
- {13, nullptr, "GetTagInfo"},
- {14, nullptr, "GetRegisterInfo"},
- {15, nullptr, "GetCommonInfo"},
- {16, nullptr, "GetModelInfo"},
+ {13, &IUser::GetTagInfo, "GetTagInfo"},
+ {14, &IUser::GetRegisterInfo, "GetRegisterInfo"},
+ {15, &IUser::GetCommonInfo, "GetCommonInfo"},
+ {16, &IUser::GetModelInfo, "GetModelInfo"},
{17, &IUser::AttachActivateEvent, "AttachActivateEvent"},
{18, &IUser::AttachDeactivateEvent, "AttachDeactivateEvent"},
{19, &IUser::GetState, "GetState"},
{20, &IUser::GetDeviceState, "GetDeviceState"},
{21, &IUser::GetNpadId, "GetNpadId"},
- {22, nullptr, "GetApplicationArea2"},
+ {22, &IUser::GetApplicationAreaSize, "GetApplicationAreaSize"},
{23, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"},
{24, nullptr, "RecreateApplicationArea"},
};
RegisterHandlers(functions);
auto& kernel = Core::System::GetInstance().Kernel();
- activate_event =
- Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:ActivateEvent");
deactivate_event =
Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:DeactivateEvent");
availability_change_event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot,
@@ -59,6 +70,17 @@ public:
}
private:
+ struct TagInfo {
+ std::array<u8, 10> uuid;
+ u8 uuid_length; // TODO(ogniK): Figure out if this is actual the uuid length or does it
+ // mean something else
+ INSERT_PADDING_BYTES(0x15);
+ u32_le protocol;
+ u32_le tag_type;
+ INSERT_PADDING_BYTES(0x2c);
+ };
+ static_assert(sizeof(TagInfo) == 0x54, "TagInfo is an invalid size");
+
enum class State : u32 {
NonInitialized = 0,
Initialized = 1,
@@ -66,15 +88,40 @@ private:
enum class DeviceState : u32 {
Initialized = 0,
+ SearchingForTag = 1,
+ TagFound = 2,
+ TagRemoved = 3,
+ TagNearby = 4,
+ Unknown5 = 5,
+ Finalized = 6
};
+ struct CommonInfo {
+ u16_be last_write_year;
+ u8 last_write_month;
+ u8 last_write_day;
+ u16_be write_counter;
+ u16_be version;
+ u32_be application_area_size;
+ INSERT_PADDING_BYTES(0x34);
+ };
+ static_assert(sizeof(CommonInfo) == 0x40, "CommonInfo is an invalid size");
+
void Initialize(Kernel::HLERequestContext& ctx) {
- LOG_WARNING(Service_NFP, "(STUBBED) called");
+ IPC::ResponseBuilder rb{ctx, 2, 0};
+ rb.Push(RESULT_SUCCESS);
state = State::Initialized;
- IPC::ResponseBuilder rb{ctx, 2};
+ LOG_DEBUG(Service_NFC, "called");
+ }
+
+ void GetState(Kernel::HLERequestContext& ctx) {
+ IPC::ResponseBuilder rb{ctx, 3, 0};
rb.Push(RESULT_SUCCESS);
+ rb.PushRaw<u32>(static_cast<u32>(state));
+
+ LOG_DEBUG(Service_NFC, "called");
}
void ListDevices(Kernel::HLERequestContext& ctx) {
@@ -83,80 +130,217 @@ private:
ctx.WriteBuffer(&device_handle, sizeof(device_handle));
- LOG_WARNING(Service_NFP, "(STUBBED) called, array_size={}", array_size);
+ LOG_DEBUG(Service_NFP, "called, array_size={}", array_size);
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
- rb.Push<u32>(0);
+ rb.Push<u32>(1);
}
- void AttachActivateEvent(Kernel::HLERequestContext& ctx) {
+ void GetNpadId(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const u64 dev_handle = rp.Pop<u64>();
- LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle);
+ LOG_DEBUG(Service_NFP, "called, dev_handle=0x{:X}", dev_handle);
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(RESULT_SUCCESS);
+ rb.Push<u32>(npad_id);
+ }
+ void AttachActivateEvent(Kernel::HLERequestContext& ctx) {
+ IPC::RequestParser rp{ctx};
+ const u64 dev_handle = rp.Pop<u64>();
+ LOG_DEBUG(Service_NFP, "called, dev_handle=0x{:X}", dev_handle);
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
- rb.PushCopyObjects(activate_event);
+ rb.PushCopyObjects(nfp_interface.GetNFCEvent());
+ has_attached_handle = true;
}
void AttachDeactivateEvent(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const u64 dev_handle = rp.Pop<u64>();
- LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle);
+ LOG_DEBUG(Service_NFP, "called, dev_handle=0x{:X}", dev_handle);
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(deactivate_event);
}
- void GetState(Kernel::HLERequestContext& ctx) {
- LOG_WARNING(Service_NFP, "(STUBBED) called");
- IPC::ResponseBuilder rb{ctx, 3};
+ void StopDetection(Kernel::HLERequestContext& ctx) {
+ LOG_DEBUG(Service_NFP, "called");
+ switch (device_state) {
+ case DeviceState::TagFound:
+ case DeviceState::TagNearby:
+ deactivate_event->Signal();
+ device_state = DeviceState::Initialized;
+ break;
+ case DeviceState::SearchingForTag:
+ case DeviceState::TagRemoved:
+ device_state = DeviceState::Initialized;
+ break;
+ }
+ IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
- rb.Push<u32>(static_cast<u32>(state));
}
void GetDeviceState(Kernel::HLERequestContext& ctx) {
- LOG_WARNING(Service_NFP, "(STUBBED) called");
+ LOG_DEBUG(Service_NFP, "called");
+ auto nfc_event = nfp_interface.GetNFCEvent();
+ if (!nfc_event->ShouldWait(Kernel::GetCurrentThread()) && !has_attached_handle) {
+ device_state = DeviceState::TagFound;
+ nfc_event->Clear();
+ }
+
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(RESULT_SUCCESS);
rb.Push<u32>(static_cast<u32>(device_state));
}
- void GetNpadId(Kernel::HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const u64 dev_handle = rp.Pop<u64>();
- LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle);
- IPC::ResponseBuilder rb{ctx, 3};
+ void StartDetection(Kernel::HLERequestContext& ctx) {
+ LOG_DEBUG(Service_NFP, "called");
+
+ if (device_state == DeviceState::Initialized || device_state == DeviceState::TagRemoved) {
+ device_state = DeviceState::SearchingForTag;
+ }
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ void GetTagInfo(Kernel::HLERequestContext& ctx) {
+ LOG_DEBUG(Service_NFP, "called");
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ auto amiibo = nfp_interface.GetAmiiboBuffer();
+ TagInfo tag_info{};
+ std::memcpy(tag_info.uuid.data(), amiibo.uuid.data(), sizeof(tag_info.uuid.size()));
+ tag_info.uuid_length = static_cast<u8>(tag_info.uuid.size());
+
+ tag_info.protocol = 1; // TODO(ogniK): Figure out actual values
+ tag_info.tag_type = 2;
+ ctx.WriteBuffer(&tag_info, sizeof(TagInfo));
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ void Mount(Kernel::HLERequestContext& ctx) {
+ LOG_DEBUG(Service_NFP, "called");
+
+ device_state = DeviceState::TagNearby;
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ void GetModelInfo(Kernel::HLERequestContext& ctx) {
+ LOG_DEBUG(Service_NFP, "called");
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ auto amiibo = nfp_interface.GetAmiiboBuffer();
+ ctx.WriteBuffer(&amiibo.model_info, sizeof(amiibo.model_info));
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ void Unmount(Kernel::HLERequestContext& ctx) {
+ LOG_DEBUG(Service_NFP, "called");
+
+ device_state = DeviceState::TagFound;
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ void Finalize(Kernel::HLERequestContext& ctx) {
+ LOG_DEBUG(Service_NFP, "called");
+
+ device_state = DeviceState::Finalized;
+
+ IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
- rb.Push<u32>(npad_id);
}
void AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) {
- IPC::RequestParser rp{ctx};
- const u64 dev_handle = rp.Pop<u64>();
- LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle);
+ LOG_WARNING(Service_NFP, "(STUBBED) called");
IPC::ResponseBuilder rb{ctx, 2, 1};
rb.Push(RESULT_SUCCESS);
rb.PushCopyObjects(availability_change_event);
}
- const u64 device_handle{0xDEAD};
- const u32 npad_id{0}; // This is the first player controller id
+ void GetRegisterInfo(Kernel::HLERequestContext& ctx) {
+ LOG_WARNING(Service_NFP, "(STUBBED) called");
+
+ // TODO(ogniK): Pull Mii and owner data from amiibo
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ void GetCommonInfo(Kernel::HLERequestContext& ctx) {
+ LOG_WARNING(Service_NFP, "(STUBBED) called");
+
+ // TODO(ogniK): Pull common information from amiibo
+
+ CommonInfo common_info{};
+ common_info.application_area_size = 0;
+ ctx.WriteBuffer(&common_info, sizeof(CommonInfo));
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ void OpenApplicationArea(Kernel::HLERequestContext& ctx) {
+ LOG_DEBUG(Service_NFP, "called");
+ // We don't need to worry about this since we can just open the file
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ void GetApplicationAreaSize(Kernel::HLERequestContext& ctx) {
+ LOG_WARNING(Service_NFP, "(STUBBED) called");
+ // We don't need to worry about this since we can just open the file
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(RESULT_SUCCESS);
+ rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub
+ }
+
+ void GetApplicationArea(Kernel::HLERequestContext& ctx) {
+ LOG_WARNING(Service_NFP, "(STUBBED) called");
+
+ // TODO(ogniK): Pull application area from amiibo
+
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(RESULT_SUCCESS);
+ rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub
+ }
+
+ bool has_attached_handle{};
+ const u64 device_handle{Common::MakeMagic('Y', 'U', 'Z', 'U')};
+ const u32 npad_id{0}; // Player 1 controller
State state{State::NonInitialized};
DeviceState device_state{DeviceState::Initialized};
- Kernel::SharedPtr<Kernel::Event> activate_event;
Kernel::SharedPtr<Kernel::Event> deactivate_event;
Kernel::SharedPtr<Kernel::Event> availability_change_event;
+ const Module::Interface& nfp_interface;
};
void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) {
LOG_DEBUG(Service_NFP, "called");
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
rb.Push(RESULT_SUCCESS);
- rb.PushIpcInterface<IUser>();
+ rb.PushIpcInterface<IUser>(*this);
+}
+
+void Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) {
+ std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock);
+ if (buffer.size() < sizeof(AmiiboFile)) {
+ return; // Failed to load file
+ }
+ std::memcpy(&amiibo, buffer.data(), sizeof(amiibo));
+ nfc_tag_load->Signal();
+}
+const Kernel::SharedPtr<Kernel::Event>& Module::Interface::GetNFCEvent() const {
+ return nfc_tag_load;
+}
+const Module::Interface::AmiiboFile& Module::Interface::GetAmiiboBuffer() const {
+ return amiibo;
}
void InstallInterfaces(SM::ServiceManager& service_manager) {
diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h
index 77df343c4..46370dedd 100644
--- a/src/core/hle/service/nfp/nfp.h
+++ b/src/core/hle/service/nfp/nfp.h
@@ -4,6 +4,9 @@
#pragma once
+#include <array>
+#include <vector>
+#include "core/hle/kernel/event.h"
#include "core/hle/service/service.h"
namespace Service::NFP {
@@ -15,7 +18,27 @@ public:
explicit Interface(std::shared_ptr<Module> module, const char* name);
~Interface() override;
+ struct ModelInfo {
+ std::array<u8, 0x8> amiibo_identification_block;
+ INSERT_PADDING_BYTES(0x38);
+ };
+ static_assert(sizeof(ModelInfo) == 0x40, "ModelInfo is an invalid size");
+
+ struct AmiiboFile {
+ std::array<u8, 10> uuid;
+ INSERT_PADDING_BYTES(0x4a);
+ ModelInfo model_info;
+ };
+ static_assert(sizeof(AmiiboFile) == 0x94, "AmiiboFile is an invalid size");
+
void CreateUserInterface(Kernel::HLERequestContext& ctx);
+ void LoadAmiibo(const std::vector<u8>& buffer);
+ const Kernel::SharedPtr<Kernel::Event>& GetNFCEvent() const;
+ const AmiiboFile& GetAmiiboBuffer() const;
+
+ private:
+ Kernel::SharedPtr<Kernel::Event> nfc_tag_load{};
+ AmiiboFile amiibo{};
protected:
std::shared_ptr<Module> module;
diff --git a/src/core/hle/service/npns/npns.cpp b/src/core/hle/service/npns/npns.cpp
new file mode 100644
index 000000000..ccb6f9da9
--- /dev/null
+++ b/src/core/hle/service/npns/npns.cpp
@@ -0,0 +1,88 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#include <memory>
+
+#include "core/hle/service/npns/npns.h"
+#include "core/hle/service/service.h"
+#include "core/hle/service/sm/sm.h"
+
+namespace Service::NPNS {
+
+class NPNS_S final : public ServiceFramework<NPNS_S> {
+public:
+ explicit NPNS_S() : ServiceFramework{"npns:s"} {
+ // clang-format off
+ static const FunctionInfo functions[] = {
+ {1, nullptr, "ListenAll"},
+ {2, nullptr, "ListenTo"},
+ {3, nullptr, "Receive"},
+ {4, nullptr, "ReceiveRaw"},
+ {5, nullptr, "GetReceiveEvent"},
+ {6, nullptr, "ListenUndelivered"},
+ {7, nullptr, "GetStateChangeEVent"},
+ {11, nullptr, "SubscribeTopic"},
+ {12, nullptr, "UnsubscribeTopic"},
+ {13, nullptr, "QueryIsTopicExist"},
+ {21, nullptr, "CreateToken"},
+ {22, nullptr, "CreateTokenWithApplicationId"},
+ {23, nullptr, "DestroyToken"},
+ {24, nullptr, "DestroyTokenWithApplicationId"},
+ {25, nullptr, "QueryIsTokenValid"},
+ {31, nullptr, "UploadTokenToBaaS"},
+ {32, nullptr, "DestroyTokenForBaaS"},
+ {33, nullptr, "CreateTokenForBaaS"},
+ {34, nullptr, "SetBaaSDeviceAccountIdList"},
+ {101, nullptr, "Suspend"},
+ {102, nullptr, "Resume"},
+ {103, nullptr, "GetState"},
+ {104, nullptr, "GetStatistics"},
+ {105, nullptr, "GetPlayReportRequestEvent"},
+ {111, nullptr, "GetJid"},
+ {112, nullptr, "CreateJid"},
+ {113, nullptr, "DestroyJid"},
+ {114, nullptr, "AttachJid"},
+ {115, nullptr, "DetachJid"},
+ {201, nullptr, "RequestChangeStateForceTimed"},
+ {102, nullptr, "RequestChangeStateForceAsync"},
+ };
+ // clang-format on
+
+ RegisterHandlers(functions);
+ }
+};
+
+class NPNS_U final : public ServiceFramework<NPNS_U> {
+public:
+ explicit NPNS_U() : ServiceFramework{"npns:u"} {
+ // clang-format off
+ static const FunctionInfo functions[] = {
+ {1, nullptr, "ListenAll"},
+ {2, nullptr, "ListenTo"},
+ {3, nullptr, "Receive"},
+ {4, nullptr, "ReceiveRaw"},
+ {5, nullptr, "GetReceiveEvent"},
+ {7, nullptr, "GetStateChangeEVent"},
+ {21, nullptr, "CreateToken"},
+ {23, nullptr, "DestroyToken"},
+ {25, nullptr, "QueryIsTokenValid"},
+ {26, nullptr, "ListenToMyApplicationId"},
+ {101, nullptr, "Suspend"},
+ {102, nullptr, "Resume"},
+ {103, nullptr, "GetState"},
+ {104, nullptr, "GetStatistics"},
+ {111, nullptr, "GetJid"},
+ };
+ // clang-format on
+
+ RegisterHandlers(functions);
+ }
+};
+
+void InstallInterfaces(SM::ServiceManager& sm) {
+ std::make_shared<NPNS_S>()->InstallAsService(sm);
+ std::make_shared<NPNS_U>()->InstallAsService(sm);
+}
+
+} // namespace Service::NPNS
diff --git a/src/core/hle/service/npns/npns.h b/src/core/hle/service/npns/npns.h
new file mode 100644
index 000000000..861cd3e48
--- /dev/null
+++ b/src/core/hle/service/npns/npns.h
@@ -0,0 +1,15 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+namespace Service::SM {
+class ServiceManager;
+}
+
+namespace Service::NPNS {
+
+void InstallInterfaces(SM::ServiceManager& sm);
+
+} // namespace Service::NPNS
diff --git a/src/core/hle/service/prepo/prepo.cpp b/src/core/hle/service/prepo/prepo.cpp
index 6a9eccfb5..e4fcee9f8 100644
--- a/src/core/hle/service/prepo/prepo.cpp
+++ b/src/core/hle/service/prepo/prepo.cpp
@@ -14,20 +14,24 @@ public:
explicit PlayReport(const char* name) : ServiceFramework{name} {
// clang-format off
static const FunctionInfo functions[] = {
- {10100, nullptr, "SaveReport"},
- {10101, &PlayReport::SaveReportWithUser, "SaveReportWithUser"},
+ {10100, nullptr, "SaveReportOld"},
+ {10101, &PlayReport::SaveReportWithUserOld, "SaveReportWithUserOld"},
+ {10102, nullptr, "SaveReport"},
+ {10103, nullptr, "SaveReportWithUser"},
{10200, nullptr, "RequestImmediateTransmission"},
{10300, nullptr, "GetTransmissionStatus"},
{20100, nullptr, "SaveSystemReport"},
- {20200, nullptr, "SetOperationMode"},
{20101, nullptr, "SaveSystemReportWithUser"},
+ {20200, nullptr, "SetOperationMode"},
{30100, nullptr, "ClearStorage"},
+ {30200, nullptr, "ClearStatistics"},
+ {30300, nullptr, "GetStorageUsage"},
+ {30400, nullptr, "GetStatistics"},
+ {30401, nullptr, "GetThroughputHistory"},
+ {30500, nullptr, "GetLastUploadError"},
{40100, nullptr, "IsUserAgreementCheckEnabled"},
{40101, nullptr, "SetUserAgreementCheckEnabled"},
- {90100, nullptr, "GetStorageUsage"},
- {90200, nullptr, "GetStatistics"},
- {90201, nullptr, "GetThroughputHistory"},
- {90300, nullptr, "GetLastUploadError"},
+ {90100, nullptr, "ReadAllReportFiles"},
};
// clang-format on
@@ -35,7 +39,7 @@ public:
}
private:
- void SaveReportWithUser(Kernel::HLERequestContext& ctx) {
+ void SaveReportWithUserOld(Kernel::HLERequestContext& ctx) {
// TODO(ogniK): Do we want to add play report?
LOG_WARNING(Service_PREPO, "(STUBBED) called");
@@ -46,6 +50,7 @@ private:
void InstallInterfaces(SM::ServiceManager& service_manager) {
std::make_shared<PlayReport>("prepo:a")->InstallAsService(service_manager);
+ std::make_shared<PlayReport>("prepo:a2")->InstallAsService(service_manager);
std::make_shared<PlayReport>("prepo:m")->InstallAsService(service_manager);
std::make_shared<PlayReport>("prepo:s")->InstallAsService(service_manager);
std::make_shared<PlayReport>("prepo:u")->InstallAsService(service_manager);
diff --git a/src/core/hle/service/ptm/psm.cpp b/src/core/hle/service/ptm/psm.cpp
new file mode 100644
index 000000000..c2d5fda94
--- /dev/null
+++ b/src/core/hle/service/ptm/psm.cpp
@@ -0,0 +1,71 @@
+// 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/service/ptm/psm.h"
+#include "core/hle/service/service.h"
+#include "core/hle/service/sm/sm.h"
+
+namespace Service::PSM {
+
+constexpr u32 BATTERY_FULLY_CHARGED = 100; // 100% Full
+constexpr u32 BATTERY_CURRENTLY_CHARGING = 1; // Plugged into an official dock
+
+class PSM final : public ServiceFramework<PSM> {
+public:
+ explicit PSM() : ServiceFramework{"psm"} {
+ // clang-format off
+ static const FunctionInfo functions[] = {
+ {0, &PSM::GetBatteryChargePercentage, "GetBatteryChargePercentage"},
+ {1, &PSM::GetChargerType, "GetChargerType"},
+ {2, nullptr, "EnableBatteryCharging"},
+ {3, nullptr, "DisableBatteryCharging"},
+ {4, nullptr, "IsBatteryChargingEnabled"},
+ {5, nullptr, "AcquireControllerPowerSupply"},
+ {6, nullptr, "ReleaseControllerPowerSupply"},
+ {7, nullptr, "OpenSession"},
+ {8, nullptr, "EnableEnoughPowerChargeEmulation"},
+ {9, nullptr, "DisableEnoughPowerChargeEmulation"},
+ {10, nullptr, "EnableFastBatteryCharging"},
+ {11, nullptr, "DisableFastBatteryCharging"},
+ {12, nullptr, "GetBatteryVoltageState"},
+ {13, nullptr, "GetRawBatteryChargePercentage"},
+ {14, nullptr, "IsEnoughPowerSupplied"},
+ {15, nullptr, "GetBatteryAgePercentage"},
+ {16, nullptr, "GetBatteryChargeInfoEvent"},
+ {17, nullptr, "GetBatteryChargeInfoFields"},
+ };
+ // clang-format on
+
+ RegisterHandlers(functions);
+ }
+
+ ~PSM() override = default;
+
+private:
+ void GetBatteryChargePercentage(Kernel::HLERequestContext& ctx) {
+ LOG_WARNING(Service_PSM, "(STUBBED) called");
+
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(RESULT_SUCCESS);
+ rb.Push<u32>(BATTERY_FULLY_CHARGED);
+ }
+
+ void GetChargerType(Kernel::HLERequestContext& ctx) {
+ LOG_WARNING(Service_PSM, "(STUBBED) called");
+
+ IPC::ResponseBuilder rb{ctx, 3};
+ rb.Push(RESULT_SUCCESS);
+ rb.Push<u32>(BATTERY_CURRENTLY_CHARGING);
+ }
+};
+
+void InstallInterfaces(SM::ServiceManager& sm) {
+ std::make_shared<PSM>()->InstallAsService(sm);
+}
+
+} // namespace Service::PSM
diff --git a/src/core/hle/service/ptm/psm.h b/src/core/hle/service/ptm/psm.h
new file mode 100644
index 000000000..a286793ae
--- /dev/null
+++ b/src/core/hle/service/ptm/psm.h
@@ -0,0 +1,15 @@
+// Copyright 2018 yuzu emulator team
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+namespace Service::SM {
+class ServiceManager;
+}
+
+namespace Service::PSM {
+
+void InstallInterfaces(SM::ServiceManager& sm);
+
+} // namespace Service::PSM
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index a225cb4cb..a4cf45267 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -22,7 +22,7 @@
#include "core/hle/service/apm/apm.h"
#include "core/hle/service/arp/arp.h"
#include "core/hle/service/audio/audio.h"
-#include "core/hle/service/bcat/bcat.h"
+#include "core/hle/service/bcat/module.h"
#include "core/hle/service/bpc/bpc.h"
#include "core/hle/service/btdrv/btdrv.h"
#include "core/hle/service/btm/btm.h"
@@ -48,15 +48,17 @@
#include "core/hle/service/nfp/nfp.h"
#include "core/hle/service/nifm/nifm.h"
#include "core/hle/service/nim/nim.h"
+#include "core/hle/service/npns/npns.h"
#include "core/hle/service/ns/ns.h"
#include "core/hle/service/nvdrv/nvdrv.h"
#include "core/hle/service/nvflinger/nvflinger.h"
#include "core/hle/service/pcie/pcie.h"
-#include "core/hle/service/pctl/pctl.h"
+#include "core/hle/service/pctl/module.h"
#include "core/hle/service/pcv/pcv.h"
#include "core/hle/service/pm/pm.h"
#include "core/hle/service/prepo/prepo.h"
#include "core/hle/service/psc/psc.h"
+#include "core/hle/service/ptm/psm.h"
#include "core/hle/service/service.h"
#include "core/hle/service/set/settings.h"
#include "core/hle/service/sm/sm.h"
@@ -236,6 +238,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, FileSys::VfsFilesystem& vfs)
NFP::InstallInterfaces(*sm);
NIFM::InstallInterfaces(*sm);
NIM::InstallInterfaces(*sm);
+ NPNS::InstallInterfaces(*sm);
NS::InstallInterfaces(*sm);
Nvidia::InstallInterfaces(*sm, *nv_flinger);
PCIe::InstallInterfaces(*sm);
@@ -244,6 +247,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, FileSys::VfsFilesystem& vfs)
PlayReport::InstallInterfaces(*sm);
PM::InstallInterfaces(*sm);
PSC::InstallInterfaces(*sm);
+ PSM::InstallInterfaces(*sm);
Set::InstallInterfaces(*sm);
Sockets::InstallInterfaces(*sm);
SPL::InstallInterfaces(*sm);
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp
index 7d95816fe..c716a462b 100644
--- a/src/core/perf_stats.cpp
+++ b/src/core/perf_stats.cpp
@@ -74,10 +74,6 @@ double PerfStats::GetLastFrameTimeScale() {
}
void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) {
- // Max lag caused by slow frames. Can be adjusted to compensate for too many slow frames. Higher
- // values increase the time needed to recover and limit framerate again after spikes.
- constexpr microseconds MAX_LAG_TIME_US = 25000us;
-
if (!Settings::values.use_frame_limit) {
return;
}
diff --git a/src/core/settings.h b/src/core/settings.h
index 8f2da01c8..b5aeff29b 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -113,7 +113,8 @@ static const std::array<const char*, NumAnalogs> mapping = {{
struct Values {
// System
bool use_docked_mode;
- std::string username;
+ bool enable_nfc;
+ int current_user;
int language_index;
// Controls