summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/file_sys/system_archive/system_version.cpp4
-rw-r--r--src/core/hle/service/caps/caps.cpp7
-rw-r--r--src/core/hle/service/caps/caps_manager.cpp87
-rw-r--r--src/core/hle/service/caps/caps_manager.h11
-rw-r--r--src/core/hle/service/caps/caps_ss.cpp75
-rw-r--r--src/core/hle/service/caps/caps_ss.h8
-rw-r--r--src/core/hle/service/caps/caps_su.cpp69
-rw-r--r--src/core/hle/service/caps/caps_su.h8
-rw-r--r--src/core/hle/service/caps/caps_types.h2
-rw-r--r--src/core/hle/service/hle_ipc.cpp6
-rw-r--r--src/core/hle/service/ptm/ts.cpp40
-rw-r--r--src/core/hle/service/ptm/ts.h6
-rw-r--r--src/core/hle/service/set/set_sys.cpp49
-rw-r--r--src/core/memory/cheat_engine.cpp23
14 files changed, 348 insertions, 47 deletions
diff --git a/src/core/file_sys/system_archive/system_version.cpp b/src/core/file_sys/system_archive/system_version.cpp
index bd493ecca..e4751c2b4 100644
--- a/src/core/file_sys/system_archive/system_version.cpp
+++ b/src/core/file_sys/system_archive/system_version.cpp
@@ -1,6 +1,7 @@
1// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "common/logging/log.h"
4#include "core/file_sys/system_archive/system_version.h" 5#include "core/file_sys/system_archive/system_version.h"
5#include "core/file_sys/vfs_vector.h" 6#include "core/file_sys/vfs_vector.h"
6#include "core/hle/api_version.h" 7#include "core/hle/api_version.h"
@@ -12,6 +13,9 @@ std::string GetLongDisplayVersion() {
12} 13}
13 14
14VirtualDir SystemVersion() { 15VirtualDir SystemVersion() {
16 LOG_WARNING(Common_Filesystem, "called - Using hardcoded firmware version '{}'",
17 GetLongDisplayVersion());
18
15 VirtualFile file = std::make_shared<VectorVfsFile>(std::vector<u8>(0x100), "file"); 19 VirtualFile file = std::make_shared<VectorVfsFile>(std::vector<u8>(0x100), "file");
16 file->WriteObject(HLE::ApiVersion::HOS_VERSION_MAJOR, 0); 20 file->WriteObject(HLE::ApiVersion::HOS_VERSION_MAJOR, 0);
17 file->WriteObject(HLE::ApiVersion::HOS_VERSION_MINOR, 1); 21 file->WriteObject(HLE::ApiVersion::HOS_VERSION_MINOR, 1);
diff --git a/src/core/hle/service/caps/caps.cpp b/src/core/hle/service/caps/caps.cpp
index 31dd98140..cd1dfe993 100644
--- a/src/core/hle/service/caps/caps.cpp
+++ b/src/core/hle/service/caps/caps.cpp
@@ -25,11 +25,12 @@ void LoopProcess(Core::System& system) {
25 server_manager->RegisterNamedService( 25 server_manager->RegisterNamedService(
26 "caps:u", std::make_shared<IAlbumApplicationService>(system, album_manager)); 26 "caps:u", std::make_shared<IAlbumApplicationService>(system, album_manager));
27 27
28 server_manager->RegisterNamedService("caps:ss", std::make_shared<IScreenShotService>(system)); 28 server_manager->RegisterNamedService(
29 "caps:ss", std::make_shared<IScreenShotService>(system, album_manager));
29 server_manager->RegisterNamedService("caps:sc", 30 server_manager->RegisterNamedService("caps:sc",
30 std::make_shared<IScreenShotControlService>(system)); 31 std::make_shared<IScreenShotControlService>(system));
31 server_manager->RegisterNamedService("caps:su", 32 server_manager->RegisterNamedService(
32 std::make_shared<IScreenShotApplicationService>(system)); 33 "caps:su", std::make_shared<IScreenShotApplicationService>(system, album_manager));
33 34
34 ServerManager::RunServer(std::move(server_manager)); 35 ServerManager::RunServer(std::move(server_manager));
35} 36}
diff --git a/src/core/hle/service/caps/caps_manager.cpp b/src/core/hle/service/caps/caps_manager.cpp
index 2b4e3f076..7d733eb54 100644
--- a/src/core/hle/service/caps/caps_manager.cpp
+++ b/src/core/hle/service/caps/caps_manager.cpp
@@ -2,12 +2,11 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include <sstream> 4#include <sstream>
5#include <stb_image.h>
6#include <stb_image_resize.h>
7 5
8#include "common/fs/file.h" 6#include "common/fs/file.h"
9#include "common/fs/path_util.h" 7#include "common/fs/path_util.h"
10#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "common/stb.h"
11#include "core/core.h" 10#include "core/core.h"
12#include "core/hle/service/caps/caps_manager.h" 11#include "core/hle/service/caps/caps_manager.h"
13#include "core/hle/service/caps/caps_result.h" 12#include "core/hle/service/caps/caps_result.h"
@@ -227,6 +226,49 @@ Result AlbumManager::LoadAlbumScreenShotThumbnail(
227 +static_cast<int>(out_image_output.height), decoder_options.flags); 226 +static_cast<int>(out_image_output.height), decoder_options.flags);
228} 227}
229 228
229Result AlbumManager::SaveScreenShot(ApplicationAlbumEntry& out_entry,
230 const ScreenShotAttribute& attribute,
231 std::span<const u8> image_data, u64 aruid) {
232 return SaveScreenShot(out_entry, attribute, {}, image_data, aruid);
233}
234
235Result AlbumManager::SaveScreenShot(ApplicationAlbumEntry& out_entry,
236 const ScreenShotAttribute& attribute,
237 const ApplicationData& app_data, std::span<const u8> image_data,
238 u64 aruid) {
239 const u64 title_id = system.GetApplicationProcessProgramID();
240 const auto& user_clock = system.GetTimeManager().GetStandardUserSystemClockCore();
241
242 s64 posix_time{};
243 Result result = user_clock.GetCurrentTime(system, posix_time);
244
245 if (result.IsError()) {
246 return result;
247 }
248
249 const auto date = ConvertToAlbumDateTime(posix_time);
250
251 return SaveImage(out_entry, image_data, title_id, date);
252}
253
254Result AlbumManager::SaveEditedScreenShot(ApplicationAlbumEntry& out_entry,
255 const ScreenShotAttribute& attribute,
256 const AlbumFileId& file_id,
257 std::span<const u8> image_data) {
258 const auto& user_clock = system.GetTimeManager().GetStandardUserSystemClockCore();
259
260 s64 posix_time{};
261 Result result = user_clock.GetCurrentTime(system, posix_time);
262
263 if (result.IsError()) {
264 return result;
265 }
266
267 const auto date = ConvertToAlbumDateTime(posix_time);
268
269 return SaveImage(out_entry, image_data, file_id.application_id, date);
270}
271
230Result AlbumManager::GetFile(std::filesystem::path& out_path, const AlbumFileId& file_id) const { 272Result AlbumManager::GetFile(std::filesystem::path& out_path, const AlbumFileId& file_id) const {
231 const auto file = album_files.find(file_id); 273 const auto file = album_files.find(file_id);
232 274
@@ -365,6 +407,47 @@ Result AlbumManager::LoadImage(std::span<u8> out_image, const std::filesystem::p
365 return ResultSuccess; 407 return ResultSuccess;
366} 408}
367 409
410static void PNGToMemory(void* context, void* png, int len) {
411 std::vector<u8>* png_image = static_cast<std::vector<u8>*>(context);
412 png_image->reserve(len);
413 std::memcpy(png_image->data(), png, len);
414}
415
416Result AlbumManager::SaveImage(ApplicationAlbumEntry& out_entry, std::span<const u8> image,
417 u64 title_id, const AlbumFileDateTime& date) const {
418 const auto screenshot_path =
419 Common::FS::GetYuzuPathString(Common::FS::YuzuPath::ScreenshotsDir);
420 const std::string formatted_date =
421 fmt::format("{:04}-{:02}-{:02}_{:02}-{:02}-{:02}-{:03}", date.year, date.month, date.day,
422 date.hour, date.minute, date.second, 0);
423 const std::string file_path =
424 fmt::format("{}/{:016x}_{}.png", screenshot_path, title_id, formatted_date);
425
426 const Common::FS::IOFile db_file{file_path, Common::FS::FileAccessMode::Write,
427 Common::FS::FileType::BinaryFile};
428
429 std::vector<u8> png_image;
430 if (!stbi_write_png_to_func(PNGToMemory, &png_image, 1280, 720, STBI_rgb_alpha, image.data(),
431 0)) {
432 return ResultFileCountLimit;
433 }
434
435 if (db_file.Write(png_image) != png_image.size()) {
436 return ResultFileCountLimit;
437 }
438
439 out_entry = {
440 .size = png_image.size(),
441 .hash = {},
442 .datetime = date,
443 .storage = AlbumStorage::Sd,
444 .content = ContentType::Screenshot,
445 .unknown = 1,
446 };
447
448 return ResultSuccess;
449}
450
368AlbumFileDateTime AlbumManager::ConvertToAlbumDateTime(u64 posix_time) const { 451AlbumFileDateTime AlbumManager::ConvertToAlbumDateTime(u64 posix_time) const {
369 Time::TimeZone::CalendarInfo calendar_date{}; 452 Time::TimeZone::CalendarInfo calendar_date{};
370 const auto& time_zone_manager = 453 const auto& time_zone_manager =
diff --git a/src/core/hle/service/caps/caps_manager.h b/src/core/hle/service/caps/caps_manager.h
index f65eb12c1..44d85117f 100644
--- a/src/core/hle/service/caps/caps_manager.h
+++ b/src/core/hle/service/caps/caps_manager.h
@@ -58,6 +58,15 @@ public:
58 std::vector<u8>& out_image, const AlbumFileId& file_id, 58 std::vector<u8>& out_image, const AlbumFileId& file_id,
59 const ScreenShotDecodeOption& decoder_options) const; 59 const ScreenShotDecodeOption& decoder_options) const;
60 60
61 Result SaveScreenShot(ApplicationAlbumEntry& out_entry, const ScreenShotAttribute& attribute,
62 std::span<const u8> image_data, u64 aruid);
63 Result SaveScreenShot(ApplicationAlbumEntry& out_entry, const ScreenShotAttribute& attribute,
64 const ApplicationData& app_data, std::span<const u8> image_data,
65 u64 aruid);
66 Result SaveEditedScreenShot(ApplicationAlbumEntry& out_entry,
67 const ScreenShotAttribute& attribute, const AlbumFileId& file_id,
68 std::span<const u8> image_data);
69
61private: 70private:
62 static constexpr std::size_t NandAlbumFileLimit = 1000; 71 static constexpr std::size_t NandAlbumFileLimit = 1000;
63 static constexpr std::size_t SdAlbumFileLimit = 10000; 72 static constexpr std::size_t SdAlbumFileLimit = 10000;
@@ -67,6 +76,8 @@ private:
67 Result GetAlbumEntry(AlbumEntry& out_entry, const std::filesystem::path& path) const; 76 Result GetAlbumEntry(AlbumEntry& out_entry, const std::filesystem::path& path) const;
68 Result LoadImage(std::span<u8> out_image, const std::filesystem::path& path, int width, 77 Result LoadImage(std::span<u8> out_image, const std::filesystem::path& path, int width,
69 int height, ScreenShotDecoderFlag flag) const; 78 int height, ScreenShotDecoderFlag flag) const;
79 Result SaveImage(ApplicationAlbumEntry& out_entry, std::span<const u8> image, u64 title_id,
80 const AlbumFileDateTime& date) const;
70 81
71 AlbumFileDateTime ConvertToAlbumDateTime(u64 posix_time) const; 82 AlbumFileDateTime ConvertToAlbumDateTime(u64 posix_time) const;
72 83
diff --git a/src/core/hle/service/caps/caps_ss.cpp b/src/core/hle/service/caps/caps_ss.cpp
index d0d1b5425..1ba2b7972 100644
--- a/src/core/hle/service/caps/caps_ss.cpp
+++ b/src/core/hle/service/caps/caps_ss.cpp
@@ -1,19 +1,25 @@
1// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "common/logging/log.h"
5#include "core/hle/service/caps/caps_manager.h"
6#include "core/hle/service/caps/caps_types.h"
7#include "core/hle/service/ipc_helpers.h"
8
4#include "core/hle/service/caps/caps_ss.h" 9#include "core/hle/service/caps/caps_ss.h"
5 10
6namespace Service::Capture { 11namespace Service::Capture {
7 12
8IScreenShotService::IScreenShotService(Core::System& system_) 13IScreenShotService::IScreenShotService(Core::System& system_,
9 : ServiceFramework{system_, "caps:ss"} { 14 std::shared_ptr<AlbumManager> album_manager)
15 : ServiceFramework{system_, "caps:ss"}, manager{album_manager} {
10 // clang-format off 16 // clang-format off
11 static const FunctionInfo functions[] = { 17 static const FunctionInfo functions[] = {
12 {201, nullptr, "SaveScreenShot"}, 18 {201, nullptr, "SaveScreenShot"},
13 {202, nullptr, "SaveEditedScreenShot"}, 19 {202, nullptr, "SaveEditedScreenShot"},
14 {203, nullptr, "SaveScreenShotEx0"}, 20 {203, &IScreenShotService::SaveScreenShotEx0, "SaveScreenShotEx0"},
15 {204, nullptr, "SaveEditedScreenShotEx0"}, 21 {204, nullptr, "SaveEditedScreenShotEx0"},
16 {206, nullptr, "Unknown206"}, 22 {206, &IScreenShotService::SaveEditedScreenShotEx1, "SaveEditedScreenShotEx1"},
17 {208, nullptr, "SaveScreenShotOfMovieEx1"}, 23 {208, nullptr, "SaveScreenShotOfMovieEx1"},
18 {1000, nullptr, "Unknown1000"}, 24 {1000, nullptr, "Unknown1000"},
19 }; 25 };
@@ -24,4 +30,65 @@ IScreenShotService::IScreenShotService(Core::System& system_)
24 30
25IScreenShotService::~IScreenShotService() = default; 31IScreenShotService::~IScreenShotService() = default;
26 32
33void IScreenShotService::SaveScreenShotEx0(HLERequestContext& ctx) {
34 IPC::RequestParser rp{ctx};
35 struct Parameters {
36 ScreenShotAttribute attribute{};
37 u32 report_option{};
38 INSERT_PADDING_BYTES(0x4);
39 u64 applet_resource_user_id{};
40 };
41 static_assert(sizeof(Parameters) == 0x50, "Parameters has incorrect size.");
42
43 const auto parameters{rp.PopRaw<Parameters>()};
44 const auto image_data_buffer = ctx.ReadBuffer();
45
46 LOG_INFO(Service_Capture,
47 "called, report_option={}, image_data_buffer_size={}, applet_resource_user_id={}",
48 parameters.report_option, image_data_buffer.size(),
49 parameters.applet_resource_user_id);
50
51 ApplicationAlbumEntry entry{};
52 const auto result = manager->SaveScreenShot(entry, parameters.attribute, image_data_buffer,
53 parameters.applet_resource_user_id);
54
55 IPC::ResponseBuilder rb{ctx, 10};
56 rb.Push(result);
57 rb.PushRaw(entry);
58}
59void IScreenShotService::SaveEditedScreenShotEx1(HLERequestContext& ctx) {
60 IPC::RequestParser rp{ctx};
61 struct Parameters {
62 ScreenShotAttribute attribute;
63 u64 width;
64 u64 height;
65 u64 thumbnail_width;
66 u64 thumbnail_height;
67 AlbumFileId file_id;
68 };
69 static_assert(sizeof(Parameters) == 0x78, "Parameters has incorrect size.");
70
71 const auto parameters{rp.PopRaw<Parameters>()};
72 const auto application_data_buffer = ctx.ReadBuffer(0);
73 const auto image_data_buffer = ctx.ReadBuffer(1);
74 const auto thumbnail_image_data_buffer = ctx.ReadBuffer(2);
75
76 LOG_INFO(Service_Capture,
77 "called, width={}, height={}, thumbnail_width={}, thumbnail_height={}, "
78 "application_id={:016x}, storage={}, type={}, app_data_buffer_size={}, "
79 "image_data_buffer_size={}, thumbnail_image_buffer_size={}",
80 parameters.width, parameters.height, parameters.thumbnail_width,
81 parameters.thumbnail_height, parameters.file_id.application_id,
82 parameters.file_id.storage, parameters.file_id.type, application_data_buffer.size(),
83 image_data_buffer.size(), thumbnail_image_data_buffer.size());
84
85 ApplicationAlbumEntry entry{};
86 const auto result = manager->SaveEditedScreenShot(entry, parameters.attribute,
87 parameters.file_id, image_data_buffer);
88
89 IPC::ResponseBuilder rb{ctx, 10};
90 rb.Push(result);
91 rb.PushRaw(entry);
92}
93
27} // namespace Service::Capture 94} // namespace Service::Capture
diff --git a/src/core/hle/service/caps/caps_ss.h b/src/core/hle/service/caps/caps_ss.h
index 381e44fd4..a7e9972ab 100644
--- a/src/core/hle/service/caps/caps_ss.h
+++ b/src/core/hle/service/caps/caps_ss.h
@@ -13,8 +13,14 @@ namespace Service::Capture {
13 13
14class IScreenShotService final : public ServiceFramework<IScreenShotService> { 14class IScreenShotService final : public ServiceFramework<IScreenShotService> {
15public: 15public:
16 explicit IScreenShotService(Core::System& system_); 16 explicit IScreenShotService(Core::System& system_, std::shared_ptr<AlbumManager> album_manager);
17 ~IScreenShotService() override; 17 ~IScreenShotService() override;
18
19private:
20 void SaveScreenShotEx0(HLERequestContext& ctx);
21 void SaveEditedScreenShotEx1(HLERequestContext& ctx);
22
23 std::shared_ptr<AlbumManager> manager;
18}; 24};
19 25
20} // namespace Service::Capture 26} // namespace Service::Capture
diff --git a/src/core/hle/service/caps/caps_su.cpp b/src/core/hle/service/caps/caps_su.cpp
index cad173dc7..e85625ee4 100644
--- a/src/core/hle/service/caps/caps_su.cpp
+++ b/src/core/hle/service/caps/caps_su.cpp
@@ -2,19 +2,22 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "common/logging/log.h" 4#include "common/logging/log.h"
5#include "core/hle/service/caps/caps_manager.h"
5#include "core/hle/service/caps/caps_su.h" 6#include "core/hle/service/caps/caps_su.h"
7#include "core/hle/service/caps/caps_types.h"
6#include "core/hle/service/ipc_helpers.h" 8#include "core/hle/service/ipc_helpers.h"
7 9
8namespace Service::Capture { 10namespace Service::Capture {
9 11
10IScreenShotApplicationService::IScreenShotApplicationService(Core::System& system_) 12IScreenShotApplicationService::IScreenShotApplicationService(
11 : ServiceFramework{system_, "caps:su"} { 13 Core::System& system_, std::shared_ptr<AlbumManager> album_manager)
14 : ServiceFramework{system_, "caps:su"}, manager{album_manager} {
12 // clang-format off 15 // clang-format off
13 static const FunctionInfo functions[] = { 16 static const FunctionInfo functions[] = {
14 {32, &IScreenShotApplicationService::SetShimLibraryVersion, "SetShimLibraryVersion"}, 17 {32, &IScreenShotApplicationService::SetShimLibraryVersion, "SetShimLibraryVersion"},
15 {201, nullptr, "SaveScreenShot"}, 18 {201, nullptr, "SaveScreenShot"},
16 {203, nullptr, "SaveScreenShotEx0"}, 19 {203, &IScreenShotApplicationService::SaveScreenShotEx0, "SaveScreenShotEx0"},
17 {205, nullptr, "SaveScreenShotEx1"}, 20 {205, &IScreenShotApplicationService::SaveScreenShotEx1, "SaveScreenShotEx1"},
18 {210, nullptr, "SaveScreenShotEx2"}, 21 {210, nullptr, "SaveScreenShotEx2"},
19 }; 22 };
20 // clang-format on 23 // clang-format on
@@ -36,4 +39,62 @@ void IScreenShotApplicationService::SetShimLibraryVersion(HLERequestContext& ctx
36 rb.Push(ResultSuccess); 39 rb.Push(ResultSuccess);
37} 40}
38 41
42void IScreenShotApplicationService::SaveScreenShotEx0(HLERequestContext& ctx) {
43 IPC::RequestParser rp{ctx};
44 struct Parameters {
45 ScreenShotAttribute attribute{};
46 AlbumReportOption report_option{};
47 INSERT_PADDING_BYTES(0x4);
48 u64 applet_resource_user_id{};
49 };
50 static_assert(sizeof(Parameters) == 0x50, "Parameters has incorrect size.");
51
52 const auto parameters{rp.PopRaw<Parameters>()};
53 const auto image_data_buffer = ctx.ReadBuffer();
54
55 LOG_INFO(Service_Capture,
56 "called, report_option={}, image_data_buffer_size={}, applet_resource_user_id={}",
57 parameters.report_option, image_data_buffer.size(),
58 parameters.applet_resource_user_id);
59
60 ApplicationAlbumEntry entry{};
61 const auto result = manager->SaveScreenShot(entry, parameters.attribute, image_data_buffer,
62 parameters.applet_resource_user_id);
63
64 IPC::ResponseBuilder rb{ctx, 10};
65 rb.Push(result);
66 rb.PushRaw(entry);
67}
68
69void IScreenShotApplicationService::SaveScreenShotEx1(HLERequestContext& ctx) {
70 IPC::RequestParser rp{ctx};
71 struct Parameters {
72 ScreenShotAttribute attribute{};
73 AlbumReportOption report_option{};
74 INSERT_PADDING_BYTES(0x4);
75 u64 applet_resource_user_id{};
76 };
77 static_assert(sizeof(Parameters) == 0x50, "Parameters has incorrect size.");
78
79 const auto parameters{rp.PopRaw<Parameters>()};
80 const auto app_data_buffer = ctx.ReadBuffer(0);
81 const auto image_data_buffer = ctx.ReadBuffer(1);
82
83 LOG_INFO(Service_Capture,
84 "called, report_option={}, image_data_buffer_size={}, applet_resource_user_id={}",
85 parameters.report_option, image_data_buffer.size(),
86 parameters.applet_resource_user_id);
87
88 ApplicationAlbumEntry entry{};
89 ApplicationData app_data{};
90 std::memcpy(&app_data, app_data_buffer.data(), sizeof(ApplicationData));
91 const auto result =
92 manager->SaveScreenShot(entry, parameters.attribute, app_data, image_data_buffer,
93 parameters.applet_resource_user_id);
94
95 IPC::ResponseBuilder rb{ctx, 10};
96 rb.Push(result);
97 rb.PushRaw(entry);
98}
99
39} // namespace Service::Capture 100} // namespace Service::Capture
diff --git a/src/core/hle/service/caps/caps_su.h b/src/core/hle/service/caps/caps_su.h
index 647e3059d..89e71f506 100644
--- a/src/core/hle/service/caps/caps_su.h
+++ b/src/core/hle/service/caps/caps_su.h
@@ -10,14 +10,20 @@ class System;
10} 10}
11 11
12namespace Service::Capture { 12namespace Service::Capture {
13class AlbumManager;
13 14
14class IScreenShotApplicationService final : public ServiceFramework<IScreenShotApplicationService> { 15class IScreenShotApplicationService final : public ServiceFramework<IScreenShotApplicationService> {
15public: 16public:
16 explicit IScreenShotApplicationService(Core::System& system_); 17 explicit IScreenShotApplicationService(Core::System& system_,
18 std::shared_ptr<AlbumManager> album_manager);
17 ~IScreenShotApplicationService() override; 19 ~IScreenShotApplicationService() override;
18 20
19private: 21private:
20 void SetShimLibraryVersion(HLERequestContext& ctx); 22 void SetShimLibraryVersion(HLERequestContext& ctx);
23 void SaveScreenShotEx0(HLERequestContext& ctx);
24 void SaveScreenShotEx1(HLERequestContext& ctx);
25
26 std::shared_ptr<AlbumManager> manager;
21}; 27};
22 28
23} // namespace Service::Capture 29} // namespace Service::Capture
diff --git a/src/core/hle/service/caps/caps_types.h b/src/core/hle/service/caps/caps_types.h
index 7fd357954..589ac28d3 100644
--- a/src/core/hle/service/caps/caps_types.h
+++ b/src/core/hle/service/caps/caps_types.h
@@ -20,6 +20,8 @@ enum class AlbumImageOrientation {
20enum class AlbumReportOption : s32 { 20enum class AlbumReportOption : s32 {
21 Disable, 21 Disable,
22 Enable, 22 Enable,
23 Unknown2,
24 Unknown3,
23}; 25};
24 26
25enum class ContentType : u8 { 27enum class ContentType : u8 {
diff --git a/src/core/hle/service/hle_ipc.cpp b/src/core/hle/service/hle_ipc.cpp
index 6f3ae3cc4..ff374ae39 100644
--- a/src/core/hle/service/hle_ipc.cpp
+++ b/src/core/hle/service/hle_ipc.cpp
@@ -27,10 +27,12 @@ namespace {
27static thread_local std::array read_buffer_data_a{ 27static thread_local std::array read_buffer_data_a{
28 Common::ScratchBuffer<u8>(), 28 Common::ScratchBuffer<u8>(),
29 Common::ScratchBuffer<u8>(), 29 Common::ScratchBuffer<u8>(),
30 Common::ScratchBuffer<u8>(),
30}; 31};
31static thread_local std::array read_buffer_data_x{ 32static thread_local std::array read_buffer_data_x{
32 Common::ScratchBuffer<u8>(), 33 Common::ScratchBuffer<u8>(),
33 Common::ScratchBuffer<u8>(), 34 Common::ScratchBuffer<u8>(),
35 Common::ScratchBuffer<u8>(),
34}; 36};
35} // Anonymous namespace 37} // Anonymous namespace
36 38
@@ -343,6 +345,7 @@ std::span<const u8> HLERequestContext::ReadBufferA(std::size_t buffer_index) con
343 static thread_local std::array read_buffer_a{ 345 static thread_local std::array read_buffer_a{
344 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0), 346 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
345 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0), 347 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
348 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
346 }; 349 };
347 350
348 ASSERT_OR_EXECUTE_MSG( 351 ASSERT_OR_EXECUTE_MSG(
@@ -358,6 +361,7 @@ std::span<const u8> HLERequestContext::ReadBufferX(std::size_t buffer_index) con
358 static thread_local std::array read_buffer_x{ 361 static thread_local std::array read_buffer_x{
359 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0), 362 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
360 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0), 363 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
364 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
361 }; 365 };
362 366
363 ASSERT_OR_EXECUTE_MSG( 367 ASSERT_OR_EXECUTE_MSG(
@@ -373,10 +377,12 @@ std::span<const u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) cons
373 static thread_local std::array read_buffer_a{ 377 static thread_local std::array read_buffer_a{
374 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0), 378 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
375 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0), 379 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
380 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
376 }; 381 };
377 static thread_local std::array read_buffer_x{ 382 static thread_local std::array read_buffer_x{
378 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0), 383 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
379 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0), 384 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
385 Core::Memory::CpuGuestMemory<u8, Core::Memory::GuestMemoryFlags::SafeRead>(memory, 0, 0),
380 }; 386 };
381 387
382 const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && 388 const bool is_buffer_a{BufferDescriptorA().size() > buffer_index &&
diff --git a/src/core/hle/service/ptm/ts.cpp b/src/core/hle/service/ptm/ts.cpp
index ca064dd90..652f38b97 100644
--- a/src/core/hle/service/ptm/ts.cpp
+++ b/src/core/hle/service/ptm/ts.cpp
@@ -9,6 +9,35 @@
9 9
10namespace Service::PTM { 10namespace Service::PTM {
11 11
12enum class Location : u8 {
13 Internal,
14 External,
15};
16
17class ISession : public ServiceFramework<ISession> {
18public:
19 explicit ISession(Core::System& system_) : ServiceFramework{system_, "ISession"} {
20 // clang-format off
21 static const FunctionInfo functions[] = {
22 {0, nullptr, "GetTemperatureRange"},
23 {2, nullptr, "SetMeasurementMode"},
24 {4, &ISession::GetTemperature, "GetTemperature"},
25 };
26 // clang-format on
27
28 RegisterHandlers(functions);
29 }
30
31private:
32 void GetTemperature(HLERequestContext& ctx) {
33 constexpr f32 temperature = 35;
34
35 IPC::ResponseBuilder rb{ctx, 3};
36 rb.Push(ResultSuccess);
37 rb.Push(temperature);
38 }
39};
40
12TS::TS(Core::System& system_) : ServiceFramework{system_, "ts"} { 41TS::TS(Core::System& system_) : ServiceFramework{system_, "ts"} {
13 // clang-format off 42 // clang-format off
14 static const FunctionInfo functions[] = { 43 static const FunctionInfo functions[] = {
@@ -16,7 +45,7 @@ TS::TS(Core::System& system_) : ServiceFramework{system_, "ts"} {
16 {1, &TS::GetTemperature, "GetTemperature"}, 45 {1, &TS::GetTemperature, "GetTemperature"},
17 {2, nullptr, "SetMeasurementMode"}, 46 {2, nullptr, "SetMeasurementMode"},
18 {3, &TS::GetTemperatureMilliC, "GetTemperatureMilliC"}, 47 {3, &TS::GetTemperatureMilliC, "GetTemperatureMilliC"},
19 {4, nullptr, "OpenSession"}, 48 {4, &TS::OpenSession, "OpenSession"},
20 }; 49 };
21 // clang-format on 50 // clang-format on
22 51
@@ -47,4 +76,13 @@ void TS::GetTemperatureMilliC(HLERequestContext& ctx) {
47 rb.Push(temperature); 76 rb.Push(temperature);
48} 77}
49 78
79void TS::OpenSession(HLERequestContext& ctx) {
80 IPC::RequestParser rp{ctx};
81 [[maybe_unused]] const u32 device_code = rp.Pop<u32>();
82
83 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
84 rb.Push(ResultSuccess);
85 rb.PushIpcInterface<ISession>(system);
86}
87
50} // namespace Service::PTM 88} // namespace Service::PTM
diff --git a/src/core/hle/service/ptm/ts.h b/src/core/hle/service/ptm/ts.h
index c3f43d5a3..a10a91a64 100644
--- a/src/core/hle/service/ptm/ts.h
+++ b/src/core/hle/service/ptm/ts.h
@@ -14,13 +14,9 @@ public:
14 ~TS() override; 14 ~TS() override;
15 15
16private: 16private:
17 enum class Location : u8 {
18 Internal,
19 External,
20 };
21
22 void GetTemperature(HLERequestContext& ctx); 17 void GetTemperature(HLERequestContext& ctx);
23 void GetTemperatureMilliC(HLERequestContext& ctx); 18 void GetTemperatureMilliC(HLERequestContext& ctx);
19 void OpenSession(HLERequestContext& ctx);
24}; 20};
25 21
26} // namespace Service::PTM 22} // namespace Service::PTM
diff --git a/src/core/hle/service/set/set_sys.cpp b/src/core/hle/service/set/set_sys.cpp
index 165b97dad..ec3af80af 100644
--- a/src/core/hle/service/set/set_sys.cpp
+++ b/src/core/hle/service/set/set_sys.cpp
@@ -5,8 +5,13 @@
5#include "common/logging/log.h" 5#include "common/logging/log.h"
6#include "common/settings.h" 6#include "common/settings.h"
7#include "common/string_util.h" 7#include "common/string_util.h"
8#include "core/core.h"
9#include "core/file_sys/content_archive.h"
8#include "core/file_sys/errors.h" 10#include "core/file_sys/errors.h"
9#include "core/file_sys/system_archive/system_version.h" 11#include "core/file_sys/nca_metadata.h"
12#include "core/file_sys/registered_cache.h"
13#include "core/file_sys/romfs.h"
14#include "core/file_sys/system_archive/system_archive.h"
10#include "core/hle/service/filesystem/filesystem.h" 15#include "core/hle/service/filesystem/filesystem.h"
11#include "core/hle/service/ipc_helpers.h" 16#include "core/hle/service/ipc_helpers.h"
12#include "core/hle/service/set/set.h" 17#include "core/hle/service/set/set.h"
@@ -22,18 +27,30 @@ enum class GetFirmwareVersionType {
22 Version2, 27 Version2,
23}; 28};
24 29
25void GetFirmwareVersionImpl(HLERequestContext& ctx, GetFirmwareVersionType type) { 30void GetFirmwareVersionImpl(Core::System& system, HLERequestContext& ctx,
26 LOG_WARNING(Service_SET, "called - Using hardcoded firmware version '{}'", 31 GetFirmwareVersionType type) {
27 FileSys::SystemArchive::GetLongDisplayVersion());
28
29 ASSERT_MSG(ctx.GetWriteBufferSize() == 0x100, 32 ASSERT_MSG(ctx.GetWriteBufferSize() == 0x100,
30 "FirmwareVersion output buffer must be 0x100 bytes in size!"); 33 "FirmwareVersion output buffer must be 0x100 bytes in size!");
31 34
32 // Instead of using the normal procedure of checking for the real system archive and if it 35 constexpr u64 FirmwareVersionSystemDataId = 0x0100000000000809;
33 // doesn't exist, synthesizing one, I feel that that would lead to strange bugs because a 36 auto& fsc = system.GetFileSystemController();
34 // used is using a really old or really new SystemVersion title. The synthesized one ensures 37
35 // consistence (currently reports as 5.1.0-0.0) 38 // Attempt to load version data from disk
36 const auto archive = FileSys::SystemArchive::SystemVersion(); 39 const FileSys::RegisteredCache* bis_system{};
40 std::unique_ptr<FileSys::NCA> nca{};
41 FileSys::VirtualDir romfs{};
42
43 bis_system = fsc.GetSystemNANDContents();
44 if (bis_system) {
45 nca = bis_system->GetEntry(FirmwareVersionSystemDataId, FileSys::ContentRecordType::Data);
46 }
47 if (nca) {
48 romfs = FileSys::ExtractRomFS(nca->GetRomFS());
49 }
50 if (!romfs) {
51 romfs = FileSys::ExtractRomFS(
52 FileSys::SystemArchive::SynthesizeSystemArchive(FirmwareVersionSystemDataId));
53 }
37 54
38 const auto early_exit_failure = [&ctx](std::string_view desc, Result code) { 55 const auto early_exit_failure = [&ctx](std::string_view desc, Result code) {
39 LOG_ERROR(Service_SET, "General failure while attempting to resolve firmware version ({}).", 56 LOG_ERROR(Service_SET, "General failure while attempting to resolve firmware version ({}).",
@@ -42,13 +59,7 @@ void GetFirmwareVersionImpl(HLERequestContext& ctx, GetFirmwareVersionType type)
42 rb.Push(code); 59 rb.Push(code);
43 }; 60 };
44 61
45 if (archive == nullptr) { 62 const auto ver_file = romfs->GetFile("file");
46 early_exit_failure("The system version archive couldn't be synthesized.",
47 FileSys::ERROR_FAILED_MOUNT_ARCHIVE);
48 return;
49 }
50
51 const auto ver_file = archive->GetFile("file");
52 if (ver_file == nullptr) { 63 if (ver_file == nullptr) {
53 early_exit_failure("The system version archive didn't contain the file 'file'.", 64 early_exit_failure("The system version archive didn't contain the file 'file'.",
54 FileSys::ERROR_INVALID_ARGUMENT); 65 FileSys::ERROR_INVALID_ARGUMENT);
@@ -87,12 +98,12 @@ void SET_SYS::SetLanguageCode(HLERequestContext& ctx) {
87 98
88void SET_SYS::GetFirmwareVersion(HLERequestContext& ctx) { 99void SET_SYS::GetFirmwareVersion(HLERequestContext& ctx) {
89 LOG_DEBUG(Service_SET, "called"); 100 LOG_DEBUG(Service_SET, "called");
90 GetFirmwareVersionImpl(ctx, GetFirmwareVersionType::Version1); 101 GetFirmwareVersionImpl(system, ctx, GetFirmwareVersionType::Version1);
91} 102}
92 103
93void SET_SYS::GetFirmwareVersion2(HLERequestContext& ctx) { 104void SET_SYS::GetFirmwareVersion2(HLERequestContext& ctx) {
94 LOG_DEBUG(Service_SET, "called"); 105 LOG_DEBUG(Service_SET, "called");
95 GetFirmwareVersionImpl(ctx, GetFirmwareVersionType::Version2); 106 GetFirmwareVersionImpl(system, ctx, GetFirmwareVersionType::Version2);
96} 107}
97 108
98void SET_SYS::GetAccountSettings(HLERequestContext& ctx) { 109void SET_SYS::GetAccountSettings(HLERequestContext& ctx) {
diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp
index a06e99166..53a89cc8f 100644
--- a/src/core/memory/cheat_engine.cpp
+++ b/src/core/memory/cheat_engine.cpp
@@ -19,16 +19,23 @@ namespace Core::Memory {
19namespace { 19namespace {
20constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12}; 20constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12};
21 21
22std::string_view ExtractName(std::string_view data, std::size_t start_index, char match) { 22std::string_view ExtractName(std::size_t& out_name_size, std::string_view data,
23 std::size_t start_index, char match) {
23 auto end_index = start_index; 24 auto end_index = start_index;
24 while (data[end_index] != match) { 25 while (data[end_index] != match) {
25 ++end_index; 26 ++end_index;
26 if (end_index > data.size() || 27 if (end_index > data.size()) {
27 (end_index - start_index - 1) > sizeof(CheatDefinition::readable_name)) {
28 return {}; 28 return {};
29 } 29 }
30 } 30 }
31 31
32 out_name_size = end_index - start_index;
33
34 // Clamp name if it's too big
35 if (out_name_size > sizeof(CheatDefinition::readable_name)) {
36 end_index = start_index + sizeof(CheatDefinition::readable_name);
37 }
38
32 return data.substr(start_index, end_index - start_index); 39 return data.substr(start_index, end_index - start_index);
33} 40}
34} // Anonymous namespace 41} // Anonymous namespace
@@ -113,7 +120,8 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
113 return {}; 120 return {};
114 } 121 }
115 122
116 const auto name = ExtractName(data, i + 1, '}'); 123 std::size_t name_size{};
124 const auto name = ExtractName(name_size, data, i + 1, '}');
117 if (name.empty()) { 125 if (name.empty()) {
118 return {}; 126 return {};
119 } 127 }
@@ -125,12 +133,13 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
125 .definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] = 133 .definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] =
126 '\0'; 134 '\0';
127 135
128 i += name.length() + 1; 136 i += name_size + 1;
129 } else if (data[i] == '[') { 137 } else if (data[i] == '[') {
130 current_entry = out.size(); 138 current_entry = out.size();
131 out.emplace_back(); 139 out.emplace_back();
132 140
133 const auto name = ExtractName(data, i + 1, ']'); 141 std::size_t name_size{};
142 const auto name = ExtractName(name_size, data, i + 1, ']');
134 if (name.empty()) { 143 if (name.empty()) {
135 return {}; 144 return {};
136 } 145 }
@@ -142,7 +151,7 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const {
142 .definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] = 151 .definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] =
143 '\0'; 152 '\0';
144 153
145 i += name.length() + 1; 154 i += name_size + 1;
146 } else if (::isxdigit(data[i])) { 155 } else if (::isxdigit(data[i])) {
147 if (!current_entry || out[*current_entry].definition.num_opcodes >= 156 if (!current_entry || out[*current_entry].definition.num_opcodes >=
148 out[*current_entry].definition.opcodes.size()) { 157 out[*current_entry].definition.opcodes.size()) {