summaryrefslogtreecommitdiffstats
path: root/src/core/hle
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/service/ns/pl_u.cpp164
-rw-r--r--src/core/hle/service/ns/pl_u.h3
-rw-r--r--src/core/hle/service/prepo/prepo.cpp105
-rw-r--r--src/core/hle/service/prepo/prepo.h2
-rw-r--r--src/core/hle/service/service.cpp2
5 files changed, 134 insertions, 142 deletions
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp
index 9d49f36e8..8f0c6bc07 100644
--- a/src/core/hle/service/ns/pl_u.cpp
+++ b/src/core/hle/service/ns/pl_u.cpp
@@ -6,13 +6,6 @@
#include <cstring>
#include <vector>
-#include <FontChineseSimplified.h>
-#include <FontChineseTraditional.h>
-#include <FontExtendedChineseSimplified.h>
-#include <FontKorean.h>
-#include <FontNintendoExtended.h>
-#include <FontStandard.h>
-
#include "common/assert.h"
#include "common/common_paths.h"
#include "common/common_types.h"
@@ -24,6 +17,7 @@
#include "core/file_sys/nca_metadata.h"
#include "core/file_sys/registered_cache.h"
#include "core/file_sys/romfs.h"
+#include "core/file_sys/system_archive/system_archive.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/shared_memory.h"
#include "core/hle/service/filesystem/filesystem.h"
@@ -94,15 +88,16 @@ static void DecryptSharedFont(const std::vector<u32>& input, Kernel::PhysicalMem
offset += transformed_font.size() * sizeof(u32);
}
-static void EncryptSharedFont(const std::vector<u8>& input, Kernel::PhysicalMemory& output,
- std::size_t& offset) {
- ASSERT_MSG(offset + input.size() + 8 < SHARED_FONT_MEM_SIZE, "Shared fonts exceeds 17mb!");
- const u32 KEY = EXPECTED_MAGIC ^ EXPECTED_RESULT;
- std::memcpy(output.data() + offset, &EXPECTED_RESULT, sizeof(u32)); // Magic header
- const u32 ENC_SIZE = static_cast<u32>(input.size()) ^ KEY;
- std::memcpy(output.data() + offset + sizeof(u32), &ENC_SIZE, sizeof(u32));
- std::memcpy(output.data() + offset + (sizeof(u32) * 2), input.data(), input.size());
- offset += input.size() + (sizeof(u32) * 2);
+void EncryptSharedFont(const std::vector<u8>& input, Kernel::PhysicalMemory& output) {
+ ASSERT_MSG(input.size() * sizeof(u32) < SHARED_FONT_MEM_SIZE, "Shared fonts exceeds 17mb!");
+
+ const auto key = Common::swap32(EXPECTED_RESULT ^ EXPECTED_MAGIC);
+ std::vector<u32> transformed_font(input.size() + 2);
+ transformed_font[0] = Common::swap32(EXPECTED_MAGIC);
+ transformed_font[1] = Common::swap32(input.size() * sizeof(u32)) ^ key;
+ std::transform(input.begin(), input.end(), transformed_font.begin() + 2,
+ [key](u32 in) { return in ^ key; });
+ std::memcpy(output.data(), transformed_font.data(), transformed_font.size() * sizeof(u32));
}
// Helper function to make BuildSharedFontsRawRegions a bit nicer
@@ -164,114 +159,49 @@ PL_U::PL_U(FileSystem::FileSystemController& fsc)
// Attempt to load shared font data from disk
const auto* nand = fsc.GetSystemNANDContents();
std::size_t offset = 0;
- // Rebuild shared fonts from data ncas
- if (nand->HasEntry(static_cast<u64>(FontArchives::Standard),
- FileSys::ContentRecordType::Data)) {
- impl->shared_font = std::make_shared<Kernel::PhysicalMemory>(SHARED_FONT_MEM_SIZE);
- for (auto font : SHARED_FONTS) {
- const auto nca =
- nand->GetEntry(static_cast<u64>(font.first), FileSys::ContentRecordType::Data);
- if (!nca) {
- LOG_ERROR(Service_NS, "Failed to find {:016X}! Skipping",
- static_cast<u64>(font.first));
- continue;
- }
- const auto romfs = nca->GetRomFS();
- if (!romfs) {
- LOG_ERROR(Service_NS, "{:016X} has no RomFS! Skipping",
- static_cast<u64>(font.first));
- continue;
- }
- const auto extracted_romfs = FileSys::ExtractRomFS(romfs);
- if (!extracted_romfs) {
- LOG_ERROR(Service_NS, "Failed to extract RomFS for {:016X}! Skipping",
- static_cast<u64>(font.first));
- continue;
- }
- const auto font_fp = extracted_romfs->GetFile(font.second);
- if (!font_fp) {
- LOG_ERROR(Service_NS, "{:016X} has no file \"{}\"! Skipping",
- static_cast<u64>(font.first), font.second);
- continue;
- }
- std::vector<u32> font_data_u32(font_fp->GetSize() / sizeof(u32));
- font_fp->ReadBytes<u32>(font_data_u32.data(), font_fp->GetSize());
- // We need to be BigEndian as u32s for the xor encryption
- std::transform(font_data_u32.begin(), font_data_u32.end(), font_data_u32.begin(),
- Common::swap32);
- FontRegion region{
- static_cast<u32>(offset + 8),
- static_cast<u32>((font_data_u32.size() * sizeof(u32)) -
- 8)}; // Font offset and size do not account for the header
- DecryptSharedFont(font_data_u32, *impl->shared_font, offset);
- impl->shared_font_regions.push_back(region);
+ // Rebuild shared fonts from data ncas or synthesize
+
+ impl->shared_font = std::make_shared<Kernel::PhysicalMemory>(SHARED_FONT_MEM_SIZE);
+ for (auto font : SHARED_FONTS) {
+ FileSys::VirtualFile romfs;
+ const auto nca =
+ nand->GetEntry(static_cast<u64>(font.first), FileSys::ContentRecordType::Data);
+ if (nca) {
+ romfs = nca->GetRomFS();
}
- } else {
- impl->shared_font = std::make_shared<Kernel::PhysicalMemory>(
- SHARED_FONT_MEM_SIZE); // Shared memory needs to always be allocated and a fixed size
-
- const std::string user_path = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir);
- const std::string filepath{user_path + SHARED_FONT};
+ if (!romfs) {
+ romfs = FileSys::SystemArchive::SynthesizeSystemArchive(static_cast<u64>(font.first));
+ }
- // Create path if not already created
- if (!FileUtil::CreateFullPath(filepath)) {
- LOG_ERROR(Service_NS, "Failed to create sharedfonts path \"{}\"!", filepath);
- return;
+ if (!romfs) {
+ LOG_ERROR(Service_NS, "Failed to find or synthesize {:016X}! Skipping",
+ static_cast<u64>(font.first));
+ continue;
}
- bool using_ttf = false;
- for (const char* font_ttf : SHARED_FONTS_TTF) {
- if (FileUtil::Exists(user_path + font_ttf)) {
- using_ttf = true;
- FileUtil::IOFile file(user_path + font_ttf, "rb");
- if (file.IsOpen()) {
- std::vector<u8> ttf_bytes(file.GetSize());
- file.ReadBytes<u8>(ttf_bytes.data(), ttf_bytes.size());
- FontRegion region{
- static_cast<u32>(offset + 8),
- static_cast<u32>(ttf_bytes.size())}; // Font offset and size do not account
- // for the header
- EncryptSharedFont(ttf_bytes, *impl->shared_font, offset);
- impl->shared_font_regions.push_back(region);
- } else {
- LOG_WARNING(Service_NS, "Unable to load font: {}", font_ttf);
- }
- } else if (using_ttf) {
- LOG_WARNING(Service_NS, "Unable to find font: {}", font_ttf);
- }
+ const auto extracted_romfs = FileSys::ExtractRomFS(romfs);
+ if (!extracted_romfs) {
+ LOG_ERROR(Service_NS, "Failed to extract RomFS for {:016X}! Skipping",
+ static_cast<u64>(font.first));
+ continue;
}
- if (using_ttf)
- return;
- FileUtil::IOFile file(filepath, "rb");
-
- if (file.IsOpen()) {
- // Read shared font data
- ASSERT(file.GetSize() == SHARED_FONT_MEM_SIZE);
- file.ReadBytes(impl->shared_font->data(), impl->shared_font->size());
- impl->BuildSharedFontsRawRegions(*impl->shared_font);
- } else {
- LOG_WARNING(Service_NS,
- "Shared Font file missing. Loading open source replacement from memory");
-
- // clang-format off
- const std::vector<std::vector<u8>> open_source_shared_fonts_ttf = {
- {std::begin(FontChineseSimplified), std::end(FontChineseSimplified)},
- {std::begin(FontChineseTraditional), std::end(FontChineseTraditional)},
- {std::begin(FontExtendedChineseSimplified), std::end(FontExtendedChineseSimplified)},
- {std::begin(FontKorean), std::end(FontKorean)},
- {std::begin(FontNintendoExtended), std::end(FontNintendoExtended)},
- {std::begin(FontStandard), std::end(FontStandard)},
- };
- // clang-format on
-
- for (const std::vector<u8>& font_ttf : open_source_shared_fonts_ttf) {
- const FontRegion region{static_cast<u32>(offset + 8),
- static_cast<u32>(font_ttf.size())};
- EncryptSharedFont(font_ttf, *impl->shared_font, offset);
- impl->shared_font_regions.push_back(region);
- }
+ const auto font_fp = extracted_romfs->GetFile(font.second);
+ if (!font_fp) {
+ LOG_ERROR(Service_NS, "{:016X} has no file \"{}\"! Skipping",
+ static_cast<u64>(font.first), font.second);
+ continue;
}
+ std::vector<u32> font_data_u32(font_fp->GetSize() / sizeof(u32));
+ font_fp->ReadBytes<u32>(font_data_u32.data(), font_fp->GetSize());
+ // We need to be BigEndian as u32s for the xor encryption
+ std::transform(font_data_u32.begin(), font_data_u32.end(), font_data_u32.begin(),
+ Common::swap32);
+ // Font offset and size do not account for the header
+ const FontRegion region{static_cast<u32>(offset + 8),
+ static_cast<u32>((font_data_u32.size() * sizeof(u32)) - 8)};
+ DecryptSharedFont(font_data_u32, *impl->shared_font, offset);
+ impl->shared_font_regions.push_back(region);
}
}
diff --git a/src/core/hle/service/ns/pl_u.h b/src/core/hle/service/ns/pl_u.h
index 35ca424d2..7e9fe6220 100644
--- a/src/core/hle/service/ns/pl_u.h
+++ b/src/core/hle/service/ns/pl_u.h
@@ -5,6 +5,7 @@
#pragma once
#include <memory>
+#include "core/hle/kernel/physical_memory.h"
#include "core/hle/service/service.h"
namespace Service {
@@ -15,6 +16,8 @@ class FileSystemController;
namespace NS {
+void EncryptSharedFont(const std::vector<u8>& input, Kernel::PhysicalMemory& output);
+
class PL_U final : public ServiceFramework<PL_U> {
public:
PL_U(FileSystem::FileSystemController& fsc);
diff --git a/src/core/hle/service/prepo/prepo.cpp b/src/core/hle/service/prepo/prepo.cpp
index 7e134f5c1..0f79135ff 100644
--- a/src/core/hle/service/prepo/prepo.cpp
+++ b/src/core/hle/service/prepo/prepo.cpp
@@ -2,34 +2,31 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
-#include <json.hpp>
-#include "common/file_util.h"
#include "common/hex_util.h"
#include "common/logging/log.h"
-#include "common/scm_rev.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/process.h"
#include "core/hle/service/acc/profile_manager.h"
#include "core/hle/service/prepo/prepo.h"
#include "core/hle/service/service.h"
#include "core/reporter.h"
-#include "core/settings.h"
namespace Service::PlayReport {
class PlayReport final : public ServiceFramework<PlayReport> {
public:
- explicit PlayReport(const char* name) : ServiceFramework{name} {
+ explicit PlayReport(Core::System& system, const char* name)
+ : ServiceFramework{name}, system(system) {
// clang-format off
static const FunctionInfo functions[] = {
- {10100, nullptr, "SaveReportOld"},
- {10101, &PlayReport::SaveReportWithUserOld, "SaveReportWithUserOld"},
- {10102, nullptr, "SaveReport"},
- {10103, nullptr, "SaveReportWithUser"},
+ {10100, &PlayReport::SaveReport<Core::Reporter::PlayReportType::Old>, "SaveReportOld"},
+ {10101, &PlayReport::SaveReportWithUser<Core::Reporter::PlayReportType::Old>, "SaveReportWithUserOld"},
+ {10102, &PlayReport::SaveReport<Core::Reporter::PlayReportType::New>, "SaveReport"},
+ {10103, &PlayReport::SaveReportWithUser<Core::Reporter::PlayReportType::New>, "SaveReportWithUser"},
{10200, nullptr, "RequestImmediateTransmission"},
{10300, nullptr, "GetTransmissionStatus"},
- {20100, nullptr, "SaveSystemReport"},
- {20101, nullptr, "SaveSystemReportWithUser"},
+ {20100, &PlayReport::SaveSystemReport, "SaveSystemReport"},
+ {20101, &PlayReport::SaveSystemReportWithUser, "SaveSystemReportWithUser"},
{20200, nullptr, "SetOperationMode"},
{30100, nullptr, "ClearStorage"},
{30200, nullptr, "ClearStatistics"},
@@ -47,7 +44,28 @@ public:
}
private:
- void SaveReportWithUserOld(Kernel::HLERequestContext& ctx) {
+ template <Core::Reporter::PlayReportType Type>
+ void SaveReport(Kernel::HLERequestContext& ctx) {
+ IPC::RequestParser rp{ctx};
+ const auto process_id = rp.PopRaw<u64>();
+
+ const auto data1 = ctx.ReadBuffer(0);
+ const auto data2 = ctx.ReadBuffer(1);
+
+ LOG_DEBUG(Service_PREPO,
+ "called, type={:02X}, process_id={:016X}, data1_size={:016X}, data2_size={:016X}",
+ static_cast<u8>(Type), process_id, data1.size(), data2.size());
+
+ const auto& reporter{system.GetReporter()};
+ reporter.SavePlayReport(Type, system.CurrentProcess()->GetTitleID(), {data1, data2},
+ process_id);
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ template <Core::Reporter::PlayReportType Type>
+ void SaveReportWithUser(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto user_id = rp.PopRaw<u128>();
const auto process_id = rp.PopRaw<u64>();
@@ -57,24 +75,65 @@ private:
LOG_DEBUG(
Service_PREPO,
- "called, user_id={:016X}{:016X}, unk1={:016X}, data1_size={:016X}, data2_size={:016X}",
- user_id[1], user_id[0], process_id, data1.size(), data2.size());
+ "called, type={:02X}, user_id={:016X}{:016X}, process_id={:016X}, data1_size={:016X}, "
+ "data2_size={:016X}",
+ static_cast<u8>(Type), user_id[1], user_id[0], process_id, data1.size(), data2.size());
+
+ const auto& reporter{system.GetReporter()};
+ reporter.SavePlayReport(Type, system.CurrentProcess()->GetTitleID(), {data1, data2},
+ process_id, user_id);
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
+
+ void SaveSystemReport(Kernel::HLERequestContext& ctx) {
+ IPC::RequestParser rp{ctx};
+ const auto title_id = rp.PopRaw<u64>();
+
+ const auto data1 = ctx.ReadBuffer(0);
+ const auto data2 = ctx.ReadBuffer(1);
+
+ LOG_DEBUG(Service_PREPO, "called, title_id={:016X}, data1_size={:016X}, data2_size={:016X}",
+ title_id, data1.size(), data2.size());
+
+ const auto& reporter{system.GetReporter()};
+ reporter.SavePlayReport(Core::Reporter::PlayReportType::System, title_id, {data1, data2});
+
+ IPC::ResponseBuilder rb{ctx, 2};
+ rb.Push(RESULT_SUCCESS);
+ }
- const auto& reporter{Core::System::GetInstance().GetReporter()};
- reporter.SavePlayReport(Core::CurrentProcess()->GetTitleID(), process_id, {data1, data2},
- user_id);
+ void SaveSystemReportWithUser(Kernel::HLERequestContext& ctx) {
+ IPC::RequestParser rp{ctx};
+ const auto user_id = rp.PopRaw<u128>();
+ const auto title_id = rp.PopRaw<u64>();
+
+ const auto data1 = ctx.ReadBuffer(0);
+ const auto data2 = ctx.ReadBuffer(1);
+
+ LOG_DEBUG(Service_PREPO,
+ "called, user_id={:016X}{:016X}, title_id={:016X}, data1_size={:016X}, "
+ "data2_size={:016X}",
+ user_id[1], user_id[0], title_id, data1.size(), data2.size());
+
+ const auto& reporter{system.GetReporter()};
+ reporter.SavePlayReport(Core::Reporter::PlayReportType::System, title_id, {data1, data2},
+ std::nullopt, user_id);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(RESULT_SUCCESS);
}
+
+ Core::System& system;
};
-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);
+void InstallInterfaces(Core::System& system) {
+ std::make_shared<PlayReport>(system, "prepo:a")->InstallAsService(system.ServiceManager());
+ std::make_shared<PlayReport>(system, "prepo:a2")->InstallAsService(system.ServiceManager());
+ std::make_shared<PlayReport>(system, "prepo:m")->InstallAsService(system.ServiceManager());
+ std::make_shared<PlayReport>(system, "prepo:s")->InstallAsService(system.ServiceManager());
+ std::make_shared<PlayReport>(system, "prepo:u")->InstallAsService(system.ServiceManager());
}
} // namespace Service::PlayReport
diff --git a/src/core/hle/service/prepo/prepo.h b/src/core/hle/service/prepo/prepo.h
index 0e7b01331..0ebc3a938 100644
--- a/src/core/hle/service/prepo/prepo.h
+++ b/src/core/hle/service/prepo/prepo.h
@@ -10,6 +10,6 @@ class ServiceManager;
namespace Service::PlayReport {
-void InstallInterfaces(SM::ServiceManager& service_manager);
+void InstallInterfaces(Core::System& system);
} // namespace Service::PlayReport
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index 454387467..906fdc415 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -241,7 +241,7 @@ void Init(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system) {
PCIe::InstallInterfaces(*sm);
PCTL::InstallInterfaces(*sm);
PCV::InstallInterfaces(*sm);
- PlayReport::InstallInterfaces(*sm);
+ PlayReport::InstallInterfaces(system);
PM::InstallInterfaces(system);
PSC::InstallInterfaces(*sm);
PSM::InstallInterfaces(*sm);