summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/common_funcs.h6
-rw-r--r--src/core/CMakeLists.txt8
-rw-r--r--src/core/hle/service/set/appln_settings.cpp12
-rw-r--r--src/core/hle/service/set/appln_settings.h35
-rw-r--r--src/core/hle/service/set/device_settings.cpp12
-rw-r--r--src/core/hle/service/set/device_settings.h53
-rw-r--r--src/core/hle/service/set/private_settings.cpp12
-rw-r--r--src/core/hle/service/set/private_settings.h72
-rw-r--r--src/core/hle/service/set/set.h24
-rw-r--r--src/core/hle/service/set/set_sys.cpp666
-rw-r--r--src/core/hle/service/set/set_sys.h373
-rw-r--r--src/core/hle/service/set/system_settings.cpp51
-rw-r--r--src/core/hle/service/set/system_settings.h699
13 files changed, 1617 insertions, 406 deletions
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 47d028d48..ba3081efb 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -123,6 +123,12 @@ namespace Common {
123 return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24; 123 return u32(a) | u32(b) << 8 | u32(c) << 16 | u32(d) << 24;
124} 124}
125 125
126[[nodiscard]] constexpr u64 MakeMagic(char a, char b, char c, char d, char e, char f, char g,
127 char h) {
128 return u64(a) << 0 | u64(b) << 8 | u64(c) << 16 | u64(d) << 24 | u64(e) << 32 | u64(f) << 40 |
129 u64(g) << 48 | u64(h) << 56;
130}
131
126// std::size() does not support zero-size C arrays. We're fixing that. 132// std::size() does not support zero-size C arrays. We're fixing that.
127template <class C> 133template <class C>
128constexpr auto Size(const C& c) -> decltype(c.size()) { 134constexpr auto Size(const C& c) -> decltype(c.size()) {
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 7b9ed856f..1ff90bbaf 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -784,6 +784,12 @@ add_library(core STATIC
784 hle/service/service.h 784 hle/service/service.h
785 hle/service/set/set.cpp 785 hle/service/set/set.cpp
786 hle/service/set/set.h 786 hle/service/set/set.h
787 hle/service/set/appln_settings.cpp
788 hle/service/set/appln_settings.h
789 hle/service/set/device_settings.cpp
790 hle/service/set/device_settings.h
791 hle/service/set/private_settings.cpp
792 hle/service/set/private_settings.h
787 hle/service/set/set_cal.cpp 793 hle/service/set/set_cal.cpp
788 hle/service/set/set_cal.h 794 hle/service/set/set_cal.h
789 hle/service/set/set_fd.cpp 795 hle/service/set/set_fd.cpp
@@ -792,6 +798,8 @@ add_library(core STATIC
792 hle/service/set/set_sys.h 798 hle/service/set/set_sys.h
793 hle/service/set/settings.cpp 799 hle/service/set/settings.cpp
794 hle/service/set/settings.h 800 hle/service/set/settings.h
801 hle/service/set/system_settings.cpp
802 hle/service/set/system_settings.h
795 hle/service/sm/sm.cpp 803 hle/service/sm/sm.cpp
796 hle/service/sm/sm.h 804 hle/service/sm/sm.h
797 hle/service/sm/sm_controller.cpp 805 hle/service/sm/sm_controller.cpp
diff --git a/src/core/hle/service/set/appln_settings.cpp b/src/core/hle/service/set/appln_settings.cpp
new file mode 100644
index 000000000..a5d802757
--- /dev/null
+++ b/src/core/hle/service/set/appln_settings.cpp
@@ -0,0 +1,12 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "core/hle/service/set/appln_settings.h"
5
6namespace Service::Set {
7
8ApplnSettings DefaultApplnSettings() {
9 return {};
10}
11
12} // namespace Service::Set
diff --git a/src/core/hle/service/set/appln_settings.h b/src/core/hle/service/set/appln_settings.h
new file mode 100644
index 000000000..b07df0ee7
--- /dev/null
+++ b/src/core/hle/service/set/appln_settings.h
@@ -0,0 +1,35 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <array>
7
8#include "common/common_types.h"
9
10namespace Service::Set {
11struct ApplnSettings {
12 std::array<u8, 0x10> reserved_000;
13
14 // nn::util::Uuid MiiAuthorId, copied from system settings 0x94B0
15 std::array<u8, 0x10> mii_author_id;
16
17 std::array<u8, 0x30> reserved_020;
18
19 // nn::settings::system::ServiceDiscoveryControlSettings
20 std::array<u8, 0x4> service_discovery_control_settings;
21
22 std::array<u8, 0x20> reserved_054;
23
24 bool in_repair_process_enable_flag;
25
26 std::array<u8, 0x3> pad_075;
27};
28static_assert(offsetof(ApplnSettings, mii_author_id) == 0x10);
29static_assert(offsetof(ApplnSettings, service_discovery_control_settings) == 0x50);
30static_assert(offsetof(ApplnSettings, in_repair_process_enable_flag) == 0x74);
31static_assert(sizeof(ApplnSettings) == 0x78, "ApplnSettings has the wrong size!");
32
33ApplnSettings DefaultApplnSettings();
34
35} // namespace Service::Set
diff --git a/src/core/hle/service/set/device_settings.cpp b/src/core/hle/service/set/device_settings.cpp
new file mode 100644
index 000000000..e423ce38a
--- /dev/null
+++ b/src/core/hle/service/set/device_settings.cpp
@@ -0,0 +1,12 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "core/hle/service/set/device_settings.h"
5
6namespace Service::Set {
7
8DeviceSettings DefaultDeviceSettings() {
9 return {};
10}
11
12} // namespace Service::Set
diff --git a/src/core/hle/service/set/device_settings.h b/src/core/hle/service/set/device_settings.h
new file mode 100644
index 000000000..b6cfe04f2
--- /dev/null
+++ b/src/core/hle/service/set/device_settings.h
@@ -0,0 +1,53 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <array>
7
8#include "common/common_types.h"
9
10namespace Service::Set {
11struct DeviceSettings {
12 std::array<u8, 0x10> reserved_000;
13
14 // nn::settings::BatteryLot
15 std::array<u8, 0x18> ptm_battery_lot;
16 // nn::settings::system::PtmFuelGaugeParameter
17 std::array<u8, 0x18> ptm_fuel_gauge_parameter;
18 u8 ptm_battery_version;
19 // nn::settings::system::PtmCycleCountReliability
20 u32 ptm_cycle_count_reliability;
21
22 std::array<u8, 0x48> reserved_048;
23
24 // nn::settings::system::AnalogStickUserCalibration L
25 std::array<u8, 0x10> analog_user_stick_calibration_l;
26 // nn::settings::system::AnalogStickUserCalibration R
27 std::array<u8, 0x10> analog_user_stick_calibration_r;
28
29 std::array<u8, 0x20> reserved_0B0;
30
31 // nn::settings::system::ConsoleSixAxisSensorAccelerationBias
32 std::array<u8, 0xC> console_six_axis_sensor_acceleration_bias;
33 // nn::settings::system::ConsoleSixAxisSensorAngularVelocityBias
34 std::array<u8, 0xC> console_six_axis_sensor_angular_velocity_bias;
35 // nn::settings::system::ConsoleSixAxisSensorAccelerationGain
36 std::array<u8, 0x24> console_six_axis_sensor_acceleration_gain;
37 // nn::settings::system::ConsoleSixAxisSensorAngularVelocityGain
38 std::array<u8, 0x24> console_six_axis_sensor_angular_velocity_gain;
39 // nn::settings::system::ConsoleSixAxisSensorAngularVelocityTimeBias
40 std::array<u8, 0xC> console_six_axis_sensor_angular_velocity_time_bias;
41 // nn::settings::system::ConsoleSixAxisSensorAngularAcceleration
42 std::array<u8, 0x24> console_six_axis_sensor_angular_acceleration;
43};
44static_assert(offsetof(DeviceSettings, ptm_battery_lot) == 0x10);
45static_assert(offsetof(DeviceSettings, ptm_cycle_count_reliability) == 0x44);
46static_assert(offsetof(DeviceSettings, analog_user_stick_calibration_l) == 0x90);
47static_assert(offsetof(DeviceSettings, console_six_axis_sensor_acceleration_bias) == 0xD0);
48static_assert(offsetof(DeviceSettings, console_six_axis_sensor_angular_acceleration) == 0x13C);
49static_assert(sizeof(DeviceSettings) == 0x160, "DeviceSettings has the wrong size!");
50
51DeviceSettings DefaultDeviceSettings();
52
53} // namespace Service::Set
diff --git a/src/core/hle/service/set/private_settings.cpp b/src/core/hle/service/set/private_settings.cpp
new file mode 100644
index 000000000..70bf65727
--- /dev/null
+++ b/src/core/hle/service/set/private_settings.cpp
@@ -0,0 +1,12 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "core/hle/service/set/private_settings.h"
5
6namespace Service::Set {
7
8PrivateSettings DefaultPrivateSettings() {
9 return {};
10}
11
12} // namespace Service::Set
diff --git a/src/core/hle/service/set/private_settings.h b/src/core/hle/service/set/private_settings.h
new file mode 100644
index 000000000..b63eaf45c
--- /dev/null
+++ b/src/core/hle/service/set/private_settings.h
@@ -0,0 +1,72 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <array>
7
8#include "common/bit_field.h"
9#include "common/common_funcs.h"
10#include "common/common_types.h"
11#include "common/uuid.h"
12#include "core/hle/service/time/clock_types.h"
13
14namespace Service::Set {
15
16/// This is nn::settings::system::InitialLaunchFlag
17struct InitialLaunchFlag {
18 union {
19 u32 raw{};
20
21 BitField<0, 1, u32> InitialLaunchCompletionFlag;
22 BitField<8, 1, u32> InitialLaunchUserAdditionFlag;
23 BitField<16, 1, u32> InitialLaunchTimestampFlag;
24 };
25};
26static_assert(sizeof(InitialLaunchFlag) == 4, "InitialLaunchFlag is an invalid size");
27
28/// This is nn::settings::system::InitialLaunchSettings
29struct InitialLaunchSettings {
30 InitialLaunchFlag flags;
31 INSERT_PADDING_BYTES(0x4);
32 Service::Time::Clock::SteadyClockTimePoint timestamp;
33};
34static_assert(sizeof(InitialLaunchSettings) == 0x20, "InitialLaunchSettings is incorrect size");
35
36#pragma pack(push, 4)
37struct InitialLaunchSettingsPacked {
38 InitialLaunchFlag flags;
39 Service::Time::Clock::SteadyClockTimePoint timestamp;
40};
41#pragma pack(pop)
42static_assert(sizeof(InitialLaunchSettingsPacked) == 0x1C,
43 "InitialLaunchSettingsPacked is incorrect size");
44
45struct PrivateSettings {
46 std::array<u8, 0x10> reserved_00;
47
48 // nn::settings::system::InitialLaunchSettings
49 InitialLaunchSettings initial_launch_settings;
50
51 std::array<u8, 0x20> reserved_30;
52
53 Common::UUID external_clock_source_id;
54 s64 shutdown_rtc_value;
55 s64 external_steady_clock_internal_offset;
56
57 std::array<u8, 0x60> reserved_70;
58
59 // nn::settings::system::PlatformRegion
60 std::array<u8, 0x4> platform_region;
61
62 std::array<u8, 0x4> reserved_D4;
63};
64static_assert(offsetof(PrivateSettings, initial_launch_settings) == 0x10);
65static_assert(offsetof(PrivateSettings, external_clock_source_id) == 0x50);
66static_assert(offsetof(PrivateSettings, reserved_70) == 0x70);
67static_assert(offsetof(PrivateSettings, platform_region) == 0xD0);
68static_assert(sizeof(PrivateSettings) == 0xD8, "PrivateSettings has the wrong size!");
69
70PrivateSettings DefaultPrivateSettings();
71
72} // namespace Service::Set
diff --git a/src/core/hle/service/set/set.h b/src/core/hle/service/set/set.h
index b61a3560d..6ef3da410 100644
--- a/src/core/hle/service/set/set.h
+++ b/src/core/hle/service/set/set.h
@@ -4,35 +4,13 @@
4#pragma once 4#pragma once
5 5
6#include "core/hle/service/service.h" 6#include "core/hle/service/service.h"
7#include "core/hle/service/set/system_settings.h"
7 8
8namespace Core { 9namespace Core {
9class System; 10class System;
10} 11}
11 12
12namespace Service::Set { 13namespace Service::Set {
13
14/// This is "nn::settings::LanguageCode", which is a NUL-terminated string stored in a u64.
15enum class LanguageCode : u64 {
16 JA = 0x000000000000616A,
17 EN_US = 0x00000053552D6E65,
18 FR = 0x0000000000007266,
19 DE = 0x0000000000006564,
20 IT = 0x0000000000007469,
21 ES = 0x0000000000007365,
22 ZH_CN = 0x0000004E432D687A,
23 KO = 0x0000000000006F6B,
24 NL = 0x0000000000006C6E,
25 PT = 0x0000000000007470,
26 RU = 0x0000000000007572,
27 ZH_TW = 0x00000057542D687A,
28 EN_GB = 0x00000042472D6E65,
29 FR_CA = 0x00000041432D7266,
30 ES_419 = 0x00003931342D7365,
31 ZH_HANS = 0x00736E61482D687A,
32 ZH_HANT = 0x00746E61482D687A,
33 PT_BR = 0x00000052422D7470,
34};
35
36enum class KeyboardLayout : u64 { 14enum class KeyboardLayout : u64 {
37 Japanese = 0, 15 Japanese = 0,
38 EnglishUs = 1, 16 EnglishUs = 1,
diff --git a/src/core/hle/service/set/set_sys.cpp b/src/core/hle/service/set/set_sys.cpp
index 48304e6d1..0653779d5 100644
--- a/src/core/hle/service/set/set_sys.cpp
+++ b/src/core/hle/service/set/set_sys.cpp
@@ -1,7 +1,12 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2018 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 <fstream>
5
4#include "common/assert.h" 6#include "common/assert.h"
7#include "common/fs/file.h"
8#include "common/fs/fs.h"
9#include "common/fs/path_util.h"
5#include "common/logging/log.h" 10#include "common/logging/log.h"
6#include "common/settings.h" 11#include "common/settings.h"
7#include "common/string_util.h" 12#include "common/string_util.h"
@@ -19,6 +24,16 @@
19 24
20namespace Service::Set { 25namespace Service::Set {
21 26
27namespace {
28constexpr u32 SETTINGS_VERSION{1u};
29constexpr auto SETTINGS_MAGIC = Common::MakeMagic('y', 'u', 'z', 'u', '_', 's', 'e', 't');
30struct SettingsHeader {
31 u64 magic;
32 u32 version;
33 u32 reserved;
34};
35} // Anonymous namespace
36
22Result GetFirmwareVersionImpl(FirmwareVersionFormat& out_firmware, Core::System& system, 37Result GetFirmwareVersionImpl(FirmwareVersionFormat& out_firmware, Core::System& system,
23 GetFirmwareVersionType type) { 38 GetFirmwareVersionType type) {
24 constexpr u64 FirmwareVersionSystemDataId = 0x0100000000000809; 39 constexpr u64 FirmwareVersionSystemDataId = 0x0100000000000809;
@@ -72,11 +87,120 @@ Result GetFirmwareVersionImpl(FirmwareVersionFormat& out_firmware, Core::System&
72 return ResultSuccess; 87 return ResultSuccess;
73} 88}
74 89
90bool SET_SYS::LoadSettingsFile(std::filesystem::path& path, auto&& default_func) {
91 using settings_type = decltype(default_func());
92
93 if (!Common::FS::CreateDirs(path)) {
94 return false;
95 }
96
97 auto settings_file = path / "settings.dat";
98 auto exists = std::filesystem::exists(settings_file);
99 auto file_size_ok = exists && std::filesystem::file_size(settings_file) ==
100 sizeof(SettingsHeader) + sizeof(settings_type);
101
102 auto ResetToDefault = [&]() {
103 auto default_settings{default_func()};
104
105 SettingsHeader hdr{
106 .magic = SETTINGS_MAGIC,
107 .version = SETTINGS_VERSION,
108 .reserved = 0u,
109 };
110
111 std::ofstream out_settings_file(settings_file, std::ios::out | std::ios::binary);
112 out_settings_file.write(reinterpret_cast<const char*>(&hdr), sizeof(hdr));
113 out_settings_file.write(reinterpret_cast<const char*>(&default_settings),
114 sizeof(settings_type));
115 out_settings_file.flush();
116 out_settings_file.close();
117 };
118
119 constexpr auto IsHeaderValid = [](std::ifstream& file) -> bool {
120 if (!file.is_open()) {
121 return false;
122 }
123 SettingsHeader hdr{};
124 file.read(reinterpret_cast<char*>(&hdr), sizeof(hdr));
125 return hdr.magic == SETTINGS_MAGIC && hdr.version == SETTINGS_VERSION;
126 };
127
128 if (!exists || !file_size_ok) {
129 ResetToDefault();
130 }
131
132 std::ifstream file(settings_file, std::ios::binary | std::ios::in);
133 if (!IsHeaderValid(file)) {
134 file.close();
135 ResetToDefault();
136 file = std::ifstream(settings_file, std::ios::binary | std::ios::in);
137 if (!IsHeaderValid(file)) {
138 return false;
139 }
140 }
141
142 if constexpr (std::is_same_v<settings_type, PrivateSettings>) {
143 file.read(reinterpret_cast<char*>(&m_private_settings), sizeof(settings_type));
144 } else if constexpr (std::is_same_v<settings_type, DeviceSettings>) {
145 file.read(reinterpret_cast<char*>(&m_device_settings), sizeof(settings_type));
146 } else if constexpr (std::is_same_v<settings_type, ApplnSettings>) {
147 file.read(reinterpret_cast<char*>(&m_appln_settings), sizeof(settings_type));
148 } else if constexpr (std::is_same_v<settings_type, SystemSettings>) {
149 file.read(reinterpret_cast<char*>(&m_system_settings), sizeof(settings_type));
150 } else {
151 UNREACHABLE();
152 }
153 file.close();
154
155 return true;
156}
157
158bool SET_SYS::StoreSettingsFile(std::filesystem::path& path, auto& settings) {
159 using settings_type = std::decay_t<decltype(settings)>;
160
161 if (!Common::FS::IsDir(path)) {
162 return false;
163 }
164
165 auto settings_base = path / "settings";
166 auto settings_tmp_file = settings_base;
167 settings_tmp_file = settings_tmp_file.replace_extension("tmp");
168 std::ofstream file(settings_tmp_file, std::ios::binary | std::ios::out);
169 if (!file.is_open()) {
170 return false;
171 }
172
173 SettingsHeader hdr{
174 .magic = SETTINGS_MAGIC,
175 .version = SETTINGS_VERSION,
176 .reserved = 0u,
177 };
178 file.write(reinterpret_cast<const char*>(&hdr), sizeof(hdr));
179
180 if constexpr (std::is_same_v<settings_type, PrivateSettings>) {
181 file.write(reinterpret_cast<const char*>(&m_private_settings), sizeof(settings_type));
182 } else if constexpr (std::is_same_v<settings_type, DeviceSettings>) {
183 file.write(reinterpret_cast<const char*>(&m_device_settings), sizeof(settings_type));
184 } else if constexpr (std::is_same_v<settings_type, ApplnSettings>) {
185 file.write(reinterpret_cast<const char*>(&m_appln_settings), sizeof(settings_type));
186 } else if constexpr (std::is_same_v<settings_type, SystemSettings>) {
187 file.write(reinterpret_cast<const char*>(&m_system_settings), sizeof(settings_type));
188 } else {
189 UNREACHABLE();
190 }
191 file.close();
192
193 std::filesystem::rename(settings_tmp_file, settings_base.replace_extension("dat"));
194
195 return true;
196}
197
75void SET_SYS::SetLanguageCode(HLERequestContext& ctx) { 198void SET_SYS::SetLanguageCode(HLERequestContext& ctx) {
76 IPC::RequestParser rp{ctx}; 199 IPC::RequestParser rp{ctx};
77 language_code_setting = rp.PopEnum<LanguageCode>(); 200 m_system_settings.language_code = rp.PopEnum<LanguageCode>();
201 SetSaveNeeded();
78 202
79 LOG_INFO(Service_SET, "called, language_code={}", language_code_setting); 203 LOG_INFO(Service_SET, "called, language_code={}", m_system_settings.language_code);
80 204
81 IPC::ResponseBuilder rb{ctx, 2}; 205 IPC::ResponseBuilder rb{ctx, 2};
82 rb.Push(ResultSuccess); 206 rb.Push(ResultSuccess);
@@ -112,19 +236,68 @@ void SET_SYS::GetFirmwareVersion2(HLERequestContext& ctx) {
112 rb.Push(result); 236 rb.Push(result);
113} 237}
114 238
239void SET_SYS::GetExternalSteadyClockSourceId(HLERequestContext& ctx) {
240 LOG_INFO(Service_SET, "called");
241
242 Common::UUID id{};
243 auto res = GetExternalSteadyClockSourceId(id);
244
245 IPC::ResponseBuilder rb{ctx, 2 + sizeof(Common::UUID) / sizeof(u32)};
246 rb.Push(res);
247 rb.PushRaw(id);
248}
249
250void SET_SYS::SetExternalSteadyClockSourceId(HLERequestContext& ctx) {
251 LOG_INFO(Service_SET, "called");
252
253 IPC::RequestParser rp{ctx};
254 auto id{rp.PopRaw<Common::UUID>()};
255
256 auto res = SetExternalSteadyClockSourceId(id);
257
258 IPC::ResponseBuilder rb{ctx, 2};
259 rb.Push(res);
260}
261
262void SET_SYS::GetUserSystemClockContext(HLERequestContext& ctx) {
263 LOG_INFO(Service_SET, "called");
264
265 Service::Time::Clock::SystemClockContext context{};
266 auto res = GetUserSystemClockContext(context);
267
268 IPC::ResponseBuilder rb{ctx,
269 2 + sizeof(Service::Time::Clock::SystemClockContext) / sizeof(u32)};
270 rb.Push(res);
271 rb.PushRaw(context);
272}
273
274void SET_SYS::SetUserSystemClockContext(HLERequestContext& ctx) {
275 LOG_INFO(Service_SET, "called");
276
277 IPC::RequestParser rp{ctx};
278 auto context{rp.PopRaw<Service::Time::Clock::SystemClockContext>()};
279
280 auto res = SetUserSystemClockContext(context);
281
282 IPC::ResponseBuilder rb{ctx, 2};
283 rb.Push(res);
284}
285
115void SET_SYS::GetAccountSettings(HLERequestContext& ctx) { 286void SET_SYS::GetAccountSettings(HLERequestContext& ctx) {
116 LOG_INFO(Service_SET, "called"); 287 LOG_INFO(Service_SET, "called");
117 288
118 IPC::ResponseBuilder rb{ctx, 3}; 289 IPC::ResponseBuilder rb{ctx, 3};
119 rb.Push(ResultSuccess); 290 rb.Push(ResultSuccess);
120 rb.PushRaw(account_settings); 291 rb.PushRaw(m_system_settings.account_settings);
121} 292}
122 293
123void SET_SYS::SetAccountSettings(HLERequestContext& ctx) { 294void SET_SYS::SetAccountSettings(HLERequestContext& ctx) {
124 IPC::RequestParser rp{ctx}; 295 IPC::RequestParser rp{ctx};
125 account_settings = rp.PopRaw<AccountSettings>(); 296 m_system_settings.account_settings = rp.PopRaw<AccountSettings>();
297 SetSaveNeeded();
126 298
127 LOG_INFO(Service_SET, "called, account_settings_flags={}", account_settings.flags); 299 LOG_INFO(Service_SET, "called, account_settings_flags={}",
300 m_system_settings.account_settings.flags);
128 301
129 IPC::ResponseBuilder rb{ctx, 2}; 302 IPC::ResponseBuilder rb{ctx, 2};
130 rb.Push(ResultSuccess); 303 rb.Push(ResultSuccess);
@@ -133,11 +306,11 @@ void SET_SYS::SetAccountSettings(HLERequestContext& ctx) {
133void SET_SYS::GetEulaVersions(HLERequestContext& ctx) { 306void SET_SYS::GetEulaVersions(HLERequestContext& ctx) {
134 LOG_INFO(Service_SET, "called"); 307 LOG_INFO(Service_SET, "called");
135 308
136 ctx.WriteBuffer(eula_versions); 309 ctx.WriteBuffer(m_system_settings.eula_versions);
137 310
138 IPC::ResponseBuilder rb{ctx, 3}; 311 IPC::ResponseBuilder rb{ctx, 3};
139 rb.Push(ResultSuccess); 312 rb.Push(ResultSuccess);
140 rb.Push(static_cast<u32>(eula_versions.size())); 313 rb.Push(m_system_settings.eula_version_count);
141} 314}
142 315
143void SET_SYS::SetEulaVersions(HLERequestContext& ctx) { 316void SET_SYS::SetEulaVersions(HLERequestContext& ctx) {
@@ -145,13 +318,12 @@ void SET_SYS::SetEulaVersions(HLERequestContext& ctx) {
145 const auto buffer_data = ctx.ReadBuffer(); 318 const auto buffer_data = ctx.ReadBuffer();
146 319
147 LOG_INFO(Service_SET, "called, elements={}", elements); 320 LOG_INFO(Service_SET, "called, elements={}", elements);
321 ASSERT(elements <= m_system_settings.eula_versions.size());
148 322
149 eula_versions.resize(elements); 323 m_system_settings.eula_version_count = static_cast<u32>(elements);
150 for (std::size_t index = 0; index < elements; index++) { 324 std::memcpy(&m_system_settings.eula_versions, buffer_data.data(),
151 const std::size_t start_index = index * sizeof(EulaVersion); 325 sizeof(EulaVersion) * elements);
152 memcpy(eula_versions.data() + start_index, buffer_data.data() + start_index, 326 SetSaveNeeded();
153 sizeof(EulaVersion));
154 }
155 327
156 IPC::ResponseBuilder rb{ctx, 2}; 328 IPC::ResponseBuilder rb{ctx, 2};
157 rb.Push(ResultSuccess); 329 rb.Push(ResultSuccess);
@@ -162,14 +334,15 @@ void SET_SYS::GetColorSetId(HLERequestContext& ctx) {
162 334
163 IPC::ResponseBuilder rb{ctx, 3}; 335 IPC::ResponseBuilder rb{ctx, 3};
164 rb.Push(ResultSuccess); 336 rb.Push(ResultSuccess);
165 rb.PushEnum(color_set); 337 rb.PushEnum(m_system_settings.color_set_id);
166} 338}
167 339
168void SET_SYS::SetColorSetId(HLERequestContext& ctx) { 340void SET_SYS::SetColorSetId(HLERequestContext& ctx) {
169 IPC::RequestParser rp{ctx}; 341 IPC::RequestParser rp{ctx};
170 color_set = rp.PopEnum<ColorSet>(); 342 m_system_settings.color_set_id = rp.PopEnum<ColorSet>();
343 SetSaveNeeded();
171 344
172 LOG_DEBUG(Service_SET, "called, color_set={}", color_set); 345 LOG_DEBUG(Service_SET, "called, color_set={}", m_system_settings.color_set_id);
173 346
174 IPC::ResponseBuilder rb{ctx, 2}; 347 IPC::ResponseBuilder rb{ctx, 2};
175 rb.Push(ResultSuccess); 348 rb.Push(ResultSuccess);
@@ -180,17 +353,21 @@ void SET_SYS::GetNotificationSettings(HLERequestContext& ctx) {
180 353
181 IPC::ResponseBuilder rb{ctx, 8}; 354 IPC::ResponseBuilder rb{ctx, 8};
182 rb.Push(ResultSuccess); 355 rb.Push(ResultSuccess);
183 rb.PushRaw(notification_settings); 356 rb.PushRaw(m_system_settings.notification_settings);
184} 357}
185 358
186void SET_SYS::SetNotificationSettings(HLERequestContext& ctx) { 359void SET_SYS::SetNotificationSettings(HLERequestContext& ctx) {
187 IPC::RequestParser rp{ctx}; 360 IPC::RequestParser rp{ctx};
188 notification_settings = rp.PopRaw<NotificationSettings>(); 361 m_system_settings.notification_settings = rp.PopRaw<NotificationSettings>();
362 SetSaveNeeded();
189 363
190 LOG_INFO(Service_SET, "called, flags={}, volume={}, head_time={}:{}, tailt_time={}:{}", 364 LOG_INFO(Service_SET, "called, flags={}, volume={}, head_time={}:{}, tailt_time={}:{}",
191 notification_settings.flags.raw, notification_settings.volume, 365 m_system_settings.notification_settings.flags.raw,
192 notification_settings.start_time.hour, notification_settings.start_time.minute, 366 m_system_settings.notification_settings.volume,
193 notification_settings.stop_time.hour, notification_settings.stop_time.minute); 367 m_system_settings.notification_settings.start_time.hour,
368 m_system_settings.notification_settings.start_time.minute,
369 m_system_settings.notification_settings.stop_time.hour,
370 m_system_settings.notification_settings.stop_time.minute);
194 371
195 IPC::ResponseBuilder rb{ctx, 2}; 372 IPC::ResponseBuilder rb{ctx, 2};
196 rb.Push(ResultSuccess); 373 rb.Push(ResultSuccess);
@@ -199,11 +376,11 @@ void SET_SYS::SetNotificationSettings(HLERequestContext& ctx) {
199void SET_SYS::GetAccountNotificationSettings(HLERequestContext& ctx) { 376void SET_SYS::GetAccountNotificationSettings(HLERequestContext& ctx) {
200 LOG_INFO(Service_SET, "called"); 377 LOG_INFO(Service_SET, "called");
201 378
202 ctx.WriteBuffer(account_notifications); 379 ctx.WriteBuffer(m_system_settings.account_notification_settings);
203 380
204 IPC::ResponseBuilder rb{ctx, 3}; 381 IPC::ResponseBuilder rb{ctx, 3};
205 rb.Push(ResultSuccess); 382 rb.Push(ResultSuccess);
206 rb.Push(static_cast<u32>(account_notifications.size())); 383 rb.Push(m_system_settings.account_notification_settings_count);
207} 384}
208 385
209void SET_SYS::SetAccountNotificationSettings(HLERequestContext& ctx) { 386void SET_SYS::SetAccountNotificationSettings(HLERequestContext& ctx) {
@@ -212,12 +389,12 @@ void SET_SYS::SetAccountNotificationSettings(HLERequestContext& ctx) {
212 389
213 LOG_INFO(Service_SET, "called, elements={}", elements); 390 LOG_INFO(Service_SET, "called, elements={}", elements);
214 391
215 account_notifications.resize(elements); 392 ASSERT(elements <= m_system_settings.account_notification_settings.size());
216 for (std::size_t index = 0; index < elements; index++) { 393
217 const std::size_t start_index = index * sizeof(AccountNotificationSettings); 394 m_system_settings.account_notification_settings_count = static_cast<u32>(elements);
218 memcpy(account_notifications.data() + start_index, buffer_data.data() + start_index, 395 std::memcpy(&m_system_settings.account_notification_settings, buffer_data.data(),
219 sizeof(AccountNotificationSettings)); 396 elements * sizeof(AccountNotificationSettings));
220 } 397 SetSaveNeeded();
221 398
222 IPC::ResponseBuilder rb{ctx, 2}; 399 IPC::ResponseBuilder rb{ctx, 2};
223 rb.Push(ResultSuccess); 400 rb.Push(ResultSuccess);
@@ -244,6 +421,14 @@ static Settings GetSettings() {
244 ret["hbloader"]["applet_heap_size"] = ToBytes(u64{0x0}); 421 ret["hbloader"]["applet_heap_size"] = ToBytes(u64{0x0});
245 ret["hbloader"]["applet_heap_reservation_size"] = ToBytes(u64{0x8600000}); 422 ret["hbloader"]["applet_heap_reservation_size"] = ToBytes(u64{0x8600000});
246 423
424 // Time
425 ret["time"]["notify_time_to_fs_interval_seconds"] = ToBytes(s32{600});
426 ret["time"]["standard_network_clock_sufficient_accuracy_minutes"] =
427 ToBytes(s32{43200}); // 30 days
428 ret["time"]["standard_steady_clock_rtc_update_interval_minutes"] = ToBytes(s32{5});
429 ret["time"]["standard_steady_clock_test_offset_minutes"] = ToBytes(s32{0});
430 ret["time"]["standard_user_clock_initial_year"] = ToBytes(s32{2023});
431
247 return ret; 432 return ret;
248} 433}
249 434
@@ -273,8 +458,6 @@ void SET_SYS::GetSettingsItemValueSize(HLERequestContext& ctx) {
273} 458}
274 459
275void SET_SYS::GetSettingsItemValue(HLERequestContext& ctx) { 460void SET_SYS::GetSettingsItemValue(HLERequestContext& ctx) {
276 LOG_DEBUG(Service_SET, "called");
277
278 // The category of the setting. This corresponds to the top-level keys of 461 // The category of the setting. This corresponds to the top-level keys of
279 // system_settings.ini. 462 // system_settings.ini.
280 const auto setting_category_buf{ctx.ReadBuffer(0)}; 463 const auto setting_category_buf{ctx.ReadBuffer(0)};
@@ -285,14 +468,13 @@ void SET_SYS::GetSettingsItemValue(HLERequestContext& ctx) {
285 const auto setting_name_buf{ctx.ReadBuffer(1)}; 468 const auto setting_name_buf{ctx.ReadBuffer(1)};
286 const std::string setting_name{setting_name_buf.begin(), setting_name_buf.end()}; 469 const std::string setting_name{setting_name_buf.begin(), setting_name_buf.end()};
287 470
288 auto settings{GetSettings()}; 471 std::vector<u8> value;
289 Result response{ResultUnknown}; 472 auto response = GetSettingsItemValue(value, setting_category, setting_name);
290 473
291 if (settings.contains(setting_category) && settings[setting_category].contains(setting_name)) { 474 LOG_INFO(Service_SET, "called. category={}, name={} -- res=0x{:X}", setting_category,
292 auto setting_value = settings[setting_category][setting_name]; 475 setting_name, response.raw);
293 ctx.WriteBuffer(setting_value.data(), setting_value.size()); 476
294 response = ResultSuccess; 477 ctx.WriteBuffer(value.data(), value.size());
295 }
296 478
297 IPC::ResponseBuilder rb{ctx, 2}; 479 IPC::ResponseBuilder rb{ctx, 2};
298 rb.Push(response); 480 rb.Push(response);
@@ -303,19 +485,23 @@ void SET_SYS::GetTvSettings(HLERequestContext& ctx) {
303 485
304 IPC::ResponseBuilder rb{ctx, 10}; 486 IPC::ResponseBuilder rb{ctx, 10};
305 rb.Push(ResultSuccess); 487 rb.Push(ResultSuccess);
306 rb.PushRaw(tv_settings); 488 rb.PushRaw(m_system_settings.tv_settings);
307} 489}
308 490
309void SET_SYS::SetTvSettings(HLERequestContext& ctx) { 491void SET_SYS::SetTvSettings(HLERequestContext& ctx) {
310 IPC::RequestParser rp{ctx}; 492 IPC::RequestParser rp{ctx};
311 tv_settings = rp.PopRaw<TvSettings>(); 493 m_system_settings.tv_settings = rp.PopRaw<TvSettings>();
494 SetSaveNeeded();
312 495
313 LOG_INFO(Service_SET, 496 LOG_INFO(Service_SET,
314 "called, flags={}, cmu_mode={}, constrast_ratio={}, hdmi_content_type={}, " 497 "called, flags={}, cmu_mode={}, constrast_ratio={}, hdmi_content_type={}, "
315 "rgb_range={}, tv_gama={}, tv_resolution={}, tv_underscan={}", 498 "rgb_range={}, tv_gama={}, tv_resolution={}, tv_underscan={}",
316 tv_settings.flags.raw, tv_settings.cmu_mode, tv_settings.constrast_ratio, 499 m_system_settings.tv_settings.flags.raw, m_system_settings.tv_settings.cmu_mode,
317 tv_settings.hdmi_content_type, tv_settings.rgb_range, tv_settings.tv_gama, 500 m_system_settings.tv_settings.constrast_ratio,
318 tv_settings.tv_resolution, tv_settings.tv_underscan); 501 m_system_settings.tv_settings.hdmi_content_type,
502 m_system_settings.tv_settings.rgb_range, m_system_settings.tv_settings.tv_gama,
503 m_system_settings.tv_settings.tv_resolution,
504 m_system_settings.tv_settings.tv_underscan);
319 505
320 IPC::ResponseBuilder rb{ctx, 2}; 506 IPC::ResponseBuilder rb{ctx, 2};
321 rb.Push(ResultSuccess); 507 rb.Push(ResultSuccess);
@@ -329,16 +515,87 @@ void SET_SYS::GetQuestFlag(HLERequestContext& ctx) {
329 rb.PushEnum(QuestFlag::Retail); 515 rb.PushEnum(QuestFlag::Retail);
330} 516}
331 517
518void SET_SYS::GetDeviceTimeZoneLocationName(HLERequestContext& ctx) {
519 LOG_WARNING(Service_SET, "called");
520
521 Service::Time::TimeZone::LocationName name{};
522 auto res = GetDeviceTimeZoneLocationName(name);
523
524 IPC::ResponseBuilder rb{ctx, 2 + sizeof(Service::Time::TimeZone::LocationName) / sizeof(u32)};
525 rb.Push(res);
526 rb.PushRaw<Service::Time::TimeZone::LocationName>(name);
527}
528
529void SET_SYS::SetDeviceTimeZoneLocationName(HLERequestContext& ctx) {
530 LOG_WARNING(Service_SET, "called");
531
532 IPC::RequestParser rp{ctx};
533 auto name{rp.PopRaw<Service::Time::TimeZone::LocationName>()};
534
535 auto res = SetDeviceTimeZoneLocationName(name);
536
537 IPC::ResponseBuilder rb{ctx, 2};
538 rb.Push(res);
539}
540
332void SET_SYS::SetRegionCode(HLERequestContext& ctx) { 541void SET_SYS::SetRegionCode(HLERequestContext& ctx) {
333 IPC::RequestParser rp{ctx}; 542 IPC::RequestParser rp{ctx};
334 region_code = rp.PopEnum<RegionCode>(); 543 m_system_settings.region_code = rp.PopEnum<RegionCode>();
544 SetSaveNeeded();
335 545
336 LOG_INFO(Service_SET, "called, region_code={}", region_code); 546 LOG_INFO(Service_SET, "called, region_code={}", m_system_settings.region_code);
337 547
338 IPC::ResponseBuilder rb{ctx, 2}; 548 IPC::ResponseBuilder rb{ctx, 2};
339 rb.Push(ResultSuccess); 549 rb.Push(ResultSuccess);
340} 550}
341 551
552void SET_SYS::GetNetworkSystemClockContext(HLERequestContext& ctx) {
553 LOG_INFO(Service_SET, "called");
554
555 Service::Time::Clock::SystemClockContext context{};
556 auto res = GetNetworkSystemClockContext(context);
557
558 IPC::ResponseBuilder rb{ctx,
559 2 + sizeof(Service::Time::Clock::SystemClockContext) / sizeof(u32)};
560 rb.Push(res);
561 rb.PushRaw(context);
562}
563
564void SET_SYS::SetNetworkSystemClockContext(HLERequestContext& ctx) {
565 LOG_INFO(Service_SET, "called");
566
567 IPC::RequestParser rp{ctx};
568 auto context{rp.PopRaw<Service::Time::Clock::SystemClockContext>()};
569
570 auto res = SetNetworkSystemClockContext(context);
571
572 IPC::ResponseBuilder rb{ctx, 2};
573 rb.Push(res);
574}
575
576void SET_SYS::IsUserSystemClockAutomaticCorrectionEnabled(HLERequestContext& ctx) {
577 LOG_INFO(Service_SET, "called");
578
579 bool enabled{};
580 auto res = IsUserSystemClockAutomaticCorrectionEnabled(enabled);
581
582 IPC::ResponseBuilder rb{ctx, 3};
583 rb.Push(res);
584 rb.PushRaw(enabled);
585}
586
587void SET_SYS::SetUserSystemClockAutomaticCorrectionEnabled(HLERequestContext& ctx) {
588 LOG_INFO(Service_SET, "called");
589
590 IPC::RequestParser rp{ctx};
591 auto enabled{rp.Pop<bool>()};
592
593 auto res = SetUserSystemClockAutomaticCorrectionEnabled(enabled);
594
595 IPC::ResponseBuilder rb{ctx, 2};
596 rb.Push(res);
597}
598
342void SET_SYS::GetPrimaryAlbumStorage(HLERequestContext& ctx) { 599void SET_SYS::GetPrimaryAlbumStorage(HLERequestContext& ctx) {
343 LOG_WARNING(Service_SET, "(STUBBED) called"); 600 LOG_WARNING(Service_SET, "(STUBBED) called");
344 601
@@ -352,16 +609,18 @@ void SET_SYS::GetSleepSettings(HLERequestContext& ctx) {
352 609
353 IPC::ResponseBuilder rb{ctx, 5}; 610 IPC::ResponseBuilder rb{ctx, 5};
354 rb.Push(ResultSuccess); 611 rb.Push(ResultSuccess);
355 rb.PushRaw(sleep_settings); 612 rb.PushRaw(m_system_settings.sleep_settings);
356} 613}
357 614
358void SET_SYS::SetSleepSettings(HLERequestContext& ctx) { 615void SET_SYS::SetSleepSettings(HLERequestContext& ctx) {
359 IPC::RequestParser rp{ctx}; 616 IPC::RequestParser rp{ctx};
360 sleep_settings = rp.PopRaw<SleepSettings>(); 617 m_system_settings.sleep_settings = rp.PopRaw<SleepSettings>();
618 SetSaveNeeded();
361 619
362 LOG_INFO(Service_SET, "called, flags={}, handheld_sleep_plan={}, console_sleep_plan={}", 620 LOG_INFO(Service_SET, "called, flags={}, handheld_sleep_plan={}, console_sleep_plan={}",
363 sleep_settings.flags.raw, sleep_settings.handheld_sleep_plan, 621 m_system_settings.sleep_settings.flags.raw,
364 sleep_settings.console_sleep_plan); 622 m_system_settings.sleep_settings.handheld_sleep_plan,
623 m_system_settings.sleep_settings.console_sleep_plan);
365 624
366 IPC::ResponseBuilder rb{ctx, 2}; 625 IPC::ResponseBuilder rb{ctx, 2};
367 rb.Push(ResultSuccess); 626 rb.Push(ResultSuccess);
@@ -371,15 +630,20 @@ void SET_SYS::GetInitialLaunchSettings(HLERequestContext& ctx) {
371 LOG_INFO(Service_SET, "called"); 630 LOG_INFO(Service_SET, "called");
372 IPC::ResponseBuilder rb{ctx, 10}; 631 IPC::ResponseBuilder rb{ctx, 10};
373 rb.Push(ResultSuccess); 632 rb.Push(ResultSuccess);
374 rb.PushRaw(launch_settings); 633 rb.PushRaw(m_system_settings.initial_launch_settings_packed);
375} 634}
376 635
377void SET_SYS::SetInitialLaunchSettings(HLERequestContext& ctx) { 636void SET_SYS::SetInitialLaunchSettings(HLERequestContext& ctx) {
378 IPC::RequestParser rp{ctx}; 637 IPC::RequestParser rp{ctx};
379 launch_settings = rp.PopRaw<InitialLaunchSettings>(); 638 auto inital_launch_settings = rp.PopRaw<InitialLaunchSettings>();
380 639
381 LOG_INFO(Service_SET, "called, flags={}, timestamp={}", launch_settings.flags.raw, 640 m_system_settings.initial_launch_settings_packed.flags = inital_launch_settings.flags;
382 launch_settings.timestamp.time_point); 641 m_system_settings.initial_launch_settings_packed.timestamp = inital_launch_settings.timestamp;
642 SetSaveNeeded();
643
644 LOG_INFO(Service_SET, "called, flags={}, timestamp={}",
645 m_system_settings.initial_launch_settings_packed.flags.raw,
646 m_system_settings.initial_launch_settings_packed.timestamp.time_point);
383 647
384 IPC::ResponseBuilder rb{ctx, 2}; 648 IPC::ResponseBuilder rb{ctx, 2};
385 rb.Push(ResultSuccess); 649 rb.Push(ResultSuccess);
@@ -437,13 +701,37 @@ void SET_SYS::GetAutoUpdateEnableFlag(HLERequestContext& ctx) {
437void SET_SYS::GetBatteryPercentageFlag(HLERequestContext& ctx) { 701void SET_SYS::GetBatteryPercentageFlag(HLERequestContext& ctx) {
438 u8 battery_percentage_flag{1}; 702 u8 battery_percentage_flag{1};
439 703
440 LOG_DEBUG(Service_SET, "(STUBBED) called, battery_percentage_flag={}", battery_percentage_flag); 704 LOG_WARNING(Service_SET, "(STUBBED) called, battery_percentage_flag={}",
705 battery_percentage_flag);
441 706
442 IPC::ResponseBuilder rb{ctx, 3}; 707 IPC::ResponseBuilder rb{ctx, 3};
443 rb.Push(ResultSuccess); 708 rb.Push(ResultSuccess);
444 rb.Push(battery_percentage_flag); 709 rb.Push(battery_percentage_flag);
445} 710}
446 711
712void SET_SYS::SetExternalSteadyClockInternalOffset(HLERequestContext& ctx) {
713 LOG_DEBUG(Service_SET, "called.");
714
715 IPC::RequestParser rp{ctx};
716 auto offset{rp.Pop<s64>()};
717
718 auto res = SetExternalSteadyClockInternalOffset(offset);
719
720 IPC::ResponseBuilder rb{ctx, 2};
721 rb.Push(res);
722}
723
724void SET_SYS::GetExternalSteadyClockInternalOffset(HLERequestContext& ctx) {
725 LOG_DEBUG(Service_SET, "called.");
726
727 s64 offset{};
728 auto res = GetExternalSteadyClockInternalOffset(offset);
729
730 IPC::ResponseBuilder rb{ctx, 4};
731 rb.Push(res);
732 rb.Push(offset);
733}
734
447void SET_SYS::GetErrorReportSharePermission(HLERequestContext& ctx) { 735void SET_SYS::GetErrorReportSharePermission(HLERequestContext& ctx) {
448 LOG_WARNING(Service_SET, "(STUBBED) called"); 736 LOG_WARNING(Service_SET, "(STUBBED) called");
449 737
@@ -453,18 +741,19 @@ void SET_SYS::GetErrorReportSharePermission(HLERequestContext& ctx) {
453} 741}
454 742
455void SET_SYS::GetAppletLaunchFlags(HLERequestContext& ctx) { 743void SET_SYS::GetAppletLaunchFlags(HLERequestContext& ctx) {
456 LOG_INFO(Service_SET, "called, applet_launch_flag={}", applet_launch_flag); 744 LOG_INFO(Service_SET, "called, applet_launch_flag={}", m_system_settings.applet_launch_flag);
457 745
458 IPC::ResponseBuilder rb{ctx, 3}; 746 IPC::ResponseBuilder rb{ctx, 3};
459 rb.Push(ResultSuccess); 747 rb.Push(ResultSuccess);
460 rb.Push(applet_launch_flag); 748 rb.Push(m_system_settings.applet_launch_flag);
461} 749}
462 750
463void SET_SYS::SetAppletLaunchFlags(HLERequestContext& ctx) { 751void SET_SYS::SetAppletLaunchFlags(HLERequestContext& ctx) {
464 IPC::RequestParser rp{ctx}; 752 IPC::RequestParser rp{ctx};
465 applet_launch_flag = rp.Pop<u32>(); 753 m_system_settings.applet_launch_flag = rp.Pop<u32>();
754 SetSaveNeeded();
466 755
467 LOG_INFO(Service_SET, "called, applet_launch_flag={}", applet_launch_flag); 756 LOG_INFO(Service_SET, "called, applet_launch_flag={}", m_system_settings.applet_launch_flag);
468 757
469 IPC::ResponseBuilder rb{ctx, 2}; 758 IPC::ResponseBuilder rb{ctx, 2};
470 rb.Push(ResultSuccess); 759 rb.Push(ResultSuccess);
@@ -489,6 +778,52 @@ void SET_SYS::GetKeyboardLayout(HLERequestContext& ctx) {
489 rb.Push(static_cast<u32>(selected_keyboard_layout)); 778 rb.Push(static_cast<u32>(selected_keyboard_layout));
490} 779}
491 780
781void SET_SYS::GetDeviceTimeZoneLocationUpdatedTime(HLERequestContext& ctx) {
782 LOG_WARNING(Service_SET, "called.");
783
784 Service::Time::Clock::SteadyClockTimePoint time_point{};
785 auto res = GetDeviceTimeZoneLocationUpdatedTime(time_point);
786
787 IPC::ResponseBuilder rb{ctx, 4};
788 rb.Push(res);
789 rb.PushRaw<Service::Time::Clock::SteadyClockTimePoint>(time_point);
790}
791
792void SET_SYS::SetDeviceTimeZoneLocationUpdatedTime(HLERequestContext& ctx) {
793 LOG_WARNING(Service_SET, "called.");
794
795 IPC::RequestParser rp{ctx};
796 auto time_point{rp.PopRaw<Service::Time::Clock::SteadyClockTimePoint>()};
797
798 auto res = SetDeviceTimeZoneLocationUpdatedTime(time_point);
799
800 IPC::ResponseBuilder rb{ctx, 2};
801 rb.Push(res);
802}
803
804void SET_SYS::GetUserSystemClockAutomaticCorrectionUpdatedTime(HLERequestContext& ctx) {
805 LOG_WARNING(Service_SET, "called.");
806
807 Service::Time::Clock::SteadyClockTimePoint time_point{};
808 auto res = GetUserSystemClockAutomaticCorrectionUpdatedTime(time_point);
809
810 IPC::ResponseBuilder rb{ctx, 4};
811 rb.Push(res);
812 rb.PushRaw<Service::Time::Clock::SteadyClockTimePoint>(time_point);
813}
814
815void SET_SYS::SetUserSystemClockAutomaticCorrectionUpdatedTime(HLERequestContext& ctx) {
816 LOG_WARNING(Service_SET, "called.");
817
818 IPC::RequestParser rp{ctx};
819 auto time_point{rp.PopRaw<Service::Time::Clock::SteadyClockTimePoint>()};
820
821 auto res = SetUserSystemClockAutomaticCorrectionUpdatedTime(time_point);
822
823 IPC::ResponseBuilder rb{ctx, 2};
824 rb.Push(res);
825}
826
492void SET_SYS::GetChineseTraditionalInputMethod(HLERequestContext& ctx) { 827void SET_SYS::GetChineseTraditionalInputMethod(HLERequestContext& ctx) {
493 LOG_WARNING(Service_SET, "(STUBBED) called"); 828 LOG_WARNING(Service_SET, "(STUBBED) called");
494 829
@@ -508,7 +843,7 @@ void SET_SYS::GetHomeMenuScheme(HLERequestContext& ctx) {
508 .extra = 0xFF000000, 843 .extra = 0xFF000000,
509 }; 844 };
510 845
511 IPC::ResponseBuilder rb{ctx, 7}; 846 IPC::ResponseBuilder rb{ctx, 2 + sizeof(HomeMenuScheme) / sizeof(u32)};
512 rb.Push(ResultSuccess); 847 rb.Push(ResultSuccess);
513 rb.PushRaw(default_color); 848 rb.PushRaw(default_color);
514} 849}
@@ -520,6 +855,7 @@ void SET_SYS::GetHomeMenuSchemeModel(HLERequestContext& ctx) {
520 rb.Push(ResultSuccess); 855 rb.Push(ResultSuccess);
521 rb.Push(0); 856 rb.Push(0);
522} 857}
858
523void SET_SYS::GetFieldTestingFlag(HLERequestContext& ctx) { 859void SET_SYS::GetFieldTestingFlag(HLERequestContext& ctx) {
524 LOG_WARNING(Service_SET, "(STUBBED) called"); 860 LOG_WARNING(Service_SET, "(STUBBED) called");
525 861
@@ -528,7 +864,7 @@ void SET_SYS::GetFieldTestingFlag(HLERequestContext& ctx) {
528 rb.Push<u8>(false); 864 rb.Push<u8>(false);
529} 865}
530 866
531SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} { 867SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"}, m_system{system} {
532 // clang-format off 868 // clang-format off
533 static const FunctionInfo functions[] = { 869 static const FunctionInfo functions[] = {
534 {0, &SET_SYS::SetLanguageCode, "SetLanguageCode"}, 870 {0, &SET_SYS::SetLanguageCode, "SetLanguageCode"},
@@ -543,10 +879,10 @@ SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} {
543 {10, nullptr, "SetBacklightSettings"}, 879 {10, nullptr, "SetBacklightSettings"},
544 {11, nullptr, "SetBluetoothDevicesSettings"}, 880 {11, nullptr, "SetBluetoothDevicesSettings"},
545 {12, nullptr, "GetBluetoothDevicesSettings"}, 881 {12, nullptr, "GetBluetoothDevicesSettings"},
546 {13, nullptr, "GetExternalSteadyClockSourceId"}, 882 {13, &SET_SYS::GetExternalSteadyClockSourceId, "GetExternalSteadyClockSourceId"},
547 {14, nullptr, "SetExternalSteadyClockSourceId"}, 883 {14, &SET_SYS::SetExternalSteadyClockSourceId, "SetExternalSteadyClockSourceId"},
548 {15, nullptr, "GetUserSystemClockContext"}, 884 {15, &SET_SYS::GetUserSystemClockContext, "GetUserSystemClockContext"},
549 {16, nullptr, "SetUserSystemClockContext"}, 885 {16, &SET_SYS::SetUserSystemClockContext, "SetUserSystemClockContext"},
550 {17, &SET_SYS::GetAccountSettings, "GetAccountSettings"}, 886 {17, &SET_SYS::GetAccountSettings, "GetAccountSettings"},
551 {18, &SET_SYS::SetAccountSettings, "SetAccountSettings"}, 887 {18, &SET_SYS::SetAccountSettings, "SetAccountSettings"},
552 {19, nullptr, "GetAudioVolume"}, 888 {19, nullptr, "GetAudioVolume"},
@@ -581,15 +917,15 @@ SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} {
581 {50, nullptr, "SetDataDeletionSettings"}, 917 {50, nullptr, "SetDataDeletionSettings"},
582 {51, nullptr, "GetInitialSystemAppletProgramId"}, 918 {51, nullptr, "GetInitialSystemAppletProgramId"},
583 {52, nullptr, "GetOverlayDispProgramId"}, 919 {52, nullptr, "GetOverlayDispProgramId"},
584 {53, nullptr, "GetDeviceTimeZoneLocationName"}, 920 {53, &SET_SYS::GetDeviceTimeZoneLocationName, "GetDeviceTimeZoneLocationName"},
585 {54, nullptr, "SetDeviceTimeZoneLocationName"}, 921 {54, &SET_SYS::SetDeviceTimeZoneLocationName, "SetDeviceTimeZoneLocationName"},
586 {55, nullptr, "GetWirelessCertificationFileSize"}, 922 {55, nullptr, "GetWirelessCertificationFileSize"},
587 {56, nullptr, "GetWirelessCertificationFile"}, 923 {56, nullptr, "GetWirelessCertificationFile"},
588 {57, &SET_SYS::SetRegionCode, "SetRegionCode"}, 924 {57, &SET_SYS::SetRegionCode, "SetRegionCode"},
589 {58, nullptr, "GetNetworkSystemClockContext"}, 925 {58, &SET_SYS::GetNetworkSystemClockContext, "GetNetworkSystemClockContext"},
590 {59, nullptr, "SetNetworkSystemClockContext"}, 926 {59, &SET_SYS::SetNetworkSystemClockContext, "SetNetworkSystemClockContext"},
591 {60, nullptr, "IsUserSystemClockAutomaticCorrectionEnabled"}, 927 {60, &SET_SYS::IsUserSystemClockAutomaticCorrectionEnabled, "IsUserSystemClockAutomaticCorrectionEnabled"},
592 {61, nullptr, "SetUserSystemClockAutomaticCorrectionEnabled"}, 928 {61, &SET_SYS::SetUserSystemClockAutomaticCorrectionEnabled, "SetUserSystemClockAutomaticCorrectionEnabled"},
593 {62, nullptr, "GetDebugModeFlag"}, 929 {62, nullptr, "GetDebugModeFlag"},
594 {63, &SET_SYS::GetPrimaryAlbumStorage, "GetPrimaryAlbumStorage"}, 930 {63, &SET_SYS::GetPrimaryAlbumStorage, "GetPrimaryAlbumStorage"},
595 {64, nullptr, "SetPrimaryAlbumStorage"}, 931 {64, nullptr, "SetPrimaryAlbumStorage"},
@@ -633,8 +969,8 @@ SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} {
633 {102, nullptr, "SetExternalRtcResetFlag"}, 969 {102, nullptr, "SetExternalRtcResetFlag"},
634 {103, nullptr, "GetUsbFullKeyEnableFlag"}, 970 {103, nullptr, "GetUsbFullKeyEnableFlag"},
635 {104, nullptr, "SetUsbFullKeyEnableFlag"}, 971 {104, nullptr, "SetUsbFullKeyEnableFlag"},
636 {105, nullptr, "SetExternalSteadyClockInternalOffset"}, 972 {105, &SET_SYS::SetExternalSteadyClockInternalOffset, "SetExternalSteadyClockInternalOffset"},
637 {106, nullptr, "GetExternalSteadyClockInternalOffset"}, 973 {106, &SET_SYS::GetExternalSteadyClockInternalOffset, "GetExternalSteadyClockInternalOffset"},
638 {107, nullptr, "GetBacklightSettingsEx"}, 974 {107, nullptr, "GetBacklightSettingsEx"},
639 {108, nullptr, "SetBacklightSettingsEx"}, 975 {108, nullptr, "SetBacklightSettingsEx"},
640 {109, nullptr, "GetHeadphoneVolumeWarningCount"}, 976 {109, nullptr, "GetHeadphoneVolumeWarningCount"},
@@ -678,10 +1014,10 @@ SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} {
678 {147, nullptr, "GetConsoleSixAxisSensorAngularAcceleration"}, 1014 {147, nullptr, "GetConsoleSixAxisSensorAngularAcceleration"},
679 {148, nullptr, "SetConsoleSixAxisSensorAngularAcceleration"}, 1015 {148, nullptr, "SetConsoleSixAxisSensorAngularAcceleration"},
680 {149, nullptr, "GetRebootlessSystemUpdateVersion"}, 1016 {149, nullptr, "GetRebootlessSystemUpdateVersion"},
681 {150, nullptr, "GetDeviceTimeZoneLocationUpdatedTime"}, 1017 {150, &SET_SYS::GetDeviceTimeZoneLocationUpdatedTime, "GetDeviceTimeZoneLocationUpdatedTime"},
682 {151, nullptr, "SetDeviceTimeZoneLocationUpdatedTime"}, 1018 {151, &SET_SYS::SetDeviceTimeZoneLocationUpdatedTime, "SetDeviceTimeZoneLocationUpdatedTime"},
683 {152, nullptr, "GetUserSystemClockAutomaticCorrectionUpdatedTime"}, 1019 {152, &SET_SYS::GetUserSystemClockAutomaticCorrectionUpdatedTime, "GetUserSystemClockAutomaticCorrectionUpdatedTime"},
684 {153, nullptr, "SetUserSystemClockAutomaticCorrectionUpdatedTime"}, 1020 {153, &SET_SYS::SetUserSystemClockAutomaticCorrectionUpdatedTime, "SetUserSystemClockAutomaticCorrectionUpdatedTime"},
685 {154, nullptr, "GetAccountOnlineStorageSettings"}, 1021 {154, nullptr, "GetAccountOnlineStorageSettings"},
686 {155, nullptr, "SetAccountOnlineStorageSettings"}, 1022 {155, nullptr, "SetAccountOnlineStorageSettings"},
687 {156, nullptr, "GetPctlReadyFlag"}, 1023 {156, nullptr, "GetPctlReadyFlag"},
@@ -743,8 +1079,184 @@ SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} {
743 // clang-format on 1079 // clang-format on
744 1080
745 RegisterHandlers(functions); 1081 RegisterHandlers(functions);
1082
1083 SetupSettings();
1084 m_save_thread =
1085 std::jthread([this](std::stop_token stop_token) { StoreSettingsThreadFunc(stop_token); });
1086}
1087
1088SET_SYS::~SET_SYS() {
1089 SetSaveNeeded();
1090 m_save_thread.request_stop();
1091}
1092
1093void SET_SYS::SetupSettings() {
1094 auto system_dir =
1095 Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "system/save/8000000000000050";
1096 if (!LoadSettingsFile(system_dir, []() { return DefaultSystemSettings(); })) {
1097 ASSERT(false);
1098 }
1099
1100 auto private_dir =
1101 Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "system/save/8000000000000052";
1102 if (!LoadSettingsFile(private_dir, []() { return DefaultPrivateSettings(); })) {
1103 ASSERT(false);
1104 }
1105
1106 auto device_dir =
1107 Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "system/save/8000000000000053";
1108 if (!LoadSettingsFile(device_dir, []() { return DefaultDeviceSettings(); })) {
1109 ASSERT(false);
1110 }
1111
1112 auto appln_dir =
1113 Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "system/save/8000000000000054";
1114 if (!LoadSettingsFile(appln_dir, []() { return DefaultApplnSettings(); })) {
1115 ASSERT(false);
1116 }
1117}
1118
1119void SET_SYS::StoreSettings() {
1120 auto system_dir =
1121 Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "system/save/8000000000000050";
1122 if (!StoreSettingsFile(system_dir, m_system_settings)) {
1123 LOG_ERROR(HW_GPU, "Failed to store System settings");
1124 }
1125
1126 auto private_dir =
1127 Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "system/save/8000000000000052";
1128 if (!StoreSettingsFile(private_dir, m_private_settings)) {
1129 LOG_ERROR(HW_GPU, "Failed to store Private settings");
1130 }
1131
1132 auto device_dir =
1133 Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "system/save/8000000000000053";
1134 if (!StoreSettingsFile(device_dir, m_device_settings)) {
1135 LOG_ERROR(HW_GPU, "Failed to store Device settings");
1136 }
1137
1138 auto appln_dir =
1139 Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir) / "system/save/8000000000000054";
1140 if (!StoreSettingsFile(appln_dir, m_appln_settings)) {
1141 LOG_ERROR(HW_GPU, "Failed to store ApplLn settings");
1142 }
1143}
1144
1145void SET_SYS::StoreSettingsThreadFunc(std::stop_token stop_token) {
1146 while (Common::StoppableTimedWait(stop_token, std::chrono::minutes(1))) {
1147 std::scoped_lock l{m_save_needed_mutex};
1148 if (!std::exchange(m_save_needed, false)) {
1149 continue;
1150 }
1151 StoreSettings();
1152 }
1153}
1154
1155void SET_SYS::SetSaveNeeded() {
1156 std::scoped_lock l{m_save_needed_mutex};
1157 m_save_needed = true;
1158}
1159
1160Result SET_SYS::GetSettingsItemValue(std::vector<u8>& out_value, const std::string& category,
1161 const std::string& name) {
1162 auto settings{GetSettings()};
1163 R_UNLESS(settings.contains(category) && settings[category].contains(name), ResultUnknown);
1164
1165 out_value = settings[category][name];
1166 R_SUCCEED();
1167}
1168
1169Result SET_SYS::GetExternalSteadyClockSourceId(Common::UUID& out_id) {
1170 out_id = m_private_settings.external_clock_source_id;
1171 R_SUCCEED();
1172}
1173
1174Result SET_SYS::SetExternalSteadyClockSourceId(Common::UUID id) {
1175 m_private_settings.external_clock_source_id = id;
1176 SetSaveNeeded();
1177 R_SUCCEED();
1178}
1179
1180Result SET_SYS::GetUserSystemClockContext(Service::Time::Clock::SystemClockContext& out_context) {
1181 out_context = m_system_settings.user_system_clock_context;
1182 R_SUCCEED();
746} 1183}
747 1184
748SET_SYS::~SET_SYS() = default; 1185Result SET_SYS::SetUserSystemClockContext(Service::Time::Clock::SystemClockContext& context) {
1186 m_system_settings.user_system_clock_context = context;
1187 SetSaveNeeded();
1188 R_SUCCEED();
1189}
1190
1191Result SET_SYS::GetDeviceTimeZoneLocationName(Service::Time::TimeZone::LocationName& out_name) {
1192 out_name = m_system_settings.device_time_zone_location_name;
1193 R_SUCCEED();
1194}
1195
1196Result SET_SYS::SetDeviceTimeZoneLocationName(Service::Time::TimeZone::LocationName& name) {
1197 m_system_settings.device_time_zone_location_name = name;
1198 SetSaveNeeded();
1199 R_SUCCEED();
1200}
1201
1202Result SET_SYS::GetNetworkSystemClockContext(
1203 Service::Time::Clock::SystemClockContext& out_context) {
1204 out_context = m_system_settings.network_system_clock_context;
1205 R_SUCCEED();
1206}
1207
1208Result SET_SYS::SetNetworkSystemClockContext(Service::Time::Clock::SystemClockContext& context) {
1209 m_system_settings.network_system_clock_context = context;
1210 SetSaveNeeded();
1211 R_SUCCEED();
1212}
1213
1214Result SET_SYS::IsUserSystemClockAutomaticCorrectionEnabled(bool& out_enabled) {
1215 out_enabled = m_system_settings.user_system_clock_automatic_correction_enabled;
1216 R_SUCCEED();
1217}
1218
1219Result SET_SYS::SetUserSystemClockAutomaticCorrectionEnabled(bool enabled) {
1220 m_system_settings.user_system_clock_automatic_correction_enabled = enabled;
1221 SetSaveNeeded();
1222 R_SUCCEED();
1223}
1224
1225Result SET_SYS::SetExternalSteadyClockInternalOffset(s64 offset) {
1226 m_private_settings.external_steady_clock_internal_offset = offset;
1227 SetSaveNeeded();
1228 R_SUCCEED();
1229}
1230
1231Result SET_SYS::GetExternalSteadyClockInternalOffset(s64& out_offset) {
1232 out_offset = m_private_settings.external_steady_clock_internal_offset;
1233 R_SUCCEED();
1234}
1235
1236Result SET_SYS::GetDeviceTimeZoneLocationUpdatedTime(
1237 Service::Time::Clock::SteadyClockTimePoint& out_time_point) {
1238 out_time_point = m_system_settings.device_time_zone_location_updated_time;
1239 R_SUCCEED();
1240}
1241
1242Result SET_SYS::SetDeviceTimeZoneLocationUpdatedTime(
1243 Service::Time::Clock::SteadyClockTimePoint& time_point) {
1244 m_system_settings.device_time_zone_location_updated_time = time_point;
1245 SetSaveNeeded();
1246 R_SUCCEED();
1247}
1248
1249Result SET_SYS::GetUserSystemClockAutomaticCorrectionUpdatedTime(
1250 Service::Time::Clock::SteadyClockTimePoint& out_time_point) {
1251 out_time_point = m_system_settings.user_system_clock_automatic_correction_updated_time_point;
1252 R_SUCCEED();
1253}
1254
1255Result SET_SYS::SetUserSystemClockAutomaticCorrectionUpdatedTime(
1256 Service::Time::Clock::SteadyClockTimePoint out_time_point) {
1257 m_system_settings.user_system_clock_automatic_correction_updated_time_point = out_time_point;
1258 SetSaveNeeded();
1259 R_SUCCEED();
1260}
749 1261
750} // namespace Service::Set 1262} // namespace Service::Set
diff --git a/src/core/hle/service/set/set_sys.h b/src/core/hle/service/set/set_sys.h
index 5f770fd32..3785d93d8 100644
--- a/src/core/hle/service/set/set_sys.h
+++ b/src/core/hle/service/set/set_sys.h
@@ -3,17 +3,27 @@
3 3
4#pragma once 4#pragma once
5 5
6#include <filesystem>
7#include <mutex>
8#include <string>
9#include <thread>
10
11#include "common/polyfill_thread.h"
6#include "common/uuid.h" 12#include "common/uuid.h"
7#include "core/hle/result.h" 13#include "core/hle/result.h"
8#include "core/hle/service/service.h" 14#include "core/hle/service/service.h"
15#include "core/hle/service/set/appln_settings.h"
16#include "core/hle/service/set/device_settings.h"
17#include "core/hle/service/set/private_settings.h"
18#include "core/hle/service/set/system_settings.h"
9#include "core/hle/service/time/clock_types.h" 19#include "core/hle/service/time/clock_types.h"
20#include "core/hle/service/time/time_zone_types.h"
10 21
11namespace Core { 22namespace Core {
12class System; 23class System;
13} 24}
14 25
15namespace Service::Set { 26namespace Service::Set {
16enum class LanguageCode : u64;
17enum class GetFirmwareVersionType { 27enum class GetFirmwareVersionType {
18 Version1, 28 Version1,
19 Version2, 29 Version2,
@@ -42,270 +52,38 @@ public:
42 explicit SET_SYS(Core::System& system_); 52 explicit SET_SYS(Core::System& system_);
43 ~SET_SYS() override; 53 ~SET_SYS() override;
44 54
45private: 55 Result GetSettingsItemValue(std::vector<u8>& out_value, const std::string& category,
46 /// Indicates the current theme set by the system settings 56 const std::string& name);
47 enum class ColorSet : u32 { 57
48 BasicWhite = 0, 58 Result GetExternalSteadyClockSourceId(Common::UUID& out_id);
49 BasicBlack = 1, 59 Result SetExternalSteadyClockSourceId(Common::UUID id);
50 }; 60 Result GetUserSystemClockContext(Service::Time::Clock::SystemClockContext& out_context);
51 61 Result SetUserSystemClockContext(Service::Time::Clock::SystemClockContext& context);
52 /// Indicates the current console is a retail or kiosk unit 62 Result GetDeviceTimeZoneLocationName(Service::Time::TimeZone::LocationName& out_name);
53 enum class QuestFlag : u8 { 63 Result SetDeviceTimeZoneLocationName(Service::Time::TimeZone::LocationName& name);
54 Retail = 0, 64 Result GetNetworkSystemClockContext(Service::Time::Clock::SystemClockContext& out_context);
55 Kiosk = 1, 65 Result SetNetworkSystemClockContext(Service::Time::Clock::SystemClockContext& context);
56 }; 66 Result IsUserSystemClockAutomaticCorrectionEnabled(bool& out_enabled);
57 67 Result SetUserSystemClockAutomaticCorrectionEnabled(bool enabled);
58 /// This is nn::settings::system::TvResolution 68 Result SetExternalSteadyClockInternalOffset(s64 offset);
59 enum class TvResolution : u32 { 69 Result GetExternalSteadyClockInternalOffset(s64& out_offset);
60 Auto, 70 Result GetDeviceTimeZoneLocationUpdatedTime(
61 Resolution1080p, 71 Service::Time::Clock::SteadyClockTimePoint& out_time_point);
62 Resolution720p, 72 Result SetDeviceTimeZoneLocationUpdatedTime(
63 Resolution480p, 73 Service::Time::Clock::SteadyClockTimePoint& time_point);
64 }; 74 Result GetUserSystemClockAutomaticCorrectionUpdatedTime(
65 75 Service::Time::Clock::SteadyClockTimePoint& out_time_point);
66 /// This is nn::settings::system::HdmiContentType 76 Result SetUserSystemClockAutomaticCorrectionUpdatedTime(
67 enum class HdmiContentType : u32 { 77 Service::Time::Clock::SteadyClockTimePoint time_point);
68 None,
69 Graphics,
70 Cinema,
71 Photo,
72 Game,
73 };
74
75 /// This is nn::settings::system::RgbRange
76 enum class RgbRange : u32 {
77 Auto,
78 Full,
79 Limited,
80 };
81
82 /// This is nn::settings::system::CmuMode
83 enum class CmuMode : u32 {
84 None,
85 ColorInvert,
86 HighContrast,
87 GrayScale,
88 };
89
90 /// This is nn::settings::system::PrimaryAlbumStorage
91 enum class PrimaryAlbumStorage : u32 {
92 Nand,
93 SdCard,
94 };
95
96 /// This is nn::settings::system::NotificationVolume
97 enum class NotificationVolume : u32 {
98 Mute,
99 Low,
100 High,
101 };
102
103 /// This is nn::settings::system::ChineseTraditionalInputMethod
104 enum class ChineseTraditionalInputMethod : u32 {
105 Unknown0 = 0,
106 Unknown1 = 1,
107 Unknown2 = 2,
108 };
109
110 /// This is nn::settings::system::ErrorReportSharePermission
111 enum class ErrorReportSharePermission : u32 {
112 NotConfirmed,
113 Granted,
114 Denied,
115 };
116
117 /// This is nn::settings::system::FriendPresenceOverlayPermission
118 enum class FriendPresenceOverlayPermission : u8 {
119 NotConfirmed,
120 NoDisplay,
121 FavoriteFriends,
122 Friends,
123 };
124
125 /// This is nn::settings::system::HandheldSleepPlan
126 enum class HandheldSleepPlan : u32 {
127 Sleep1Min,
128 Sleep3Min,
129 Sleep5Min,
130 Sleep10Min,
131 Sleep30Min,
132 Never,
133 };
134
135 /// This is nn::settings::system::ConsoleSleepPlan
136 enum class ConsoleSleepPlan : u32 {
137 Sleep1Hour,
138 Sleep2Hour,
139 Sleep3Hour,
140 Sleep6Hour,
141 Sleep12Hour,
142 Never,
143 };
144
145 /// This is nn::settings::system::RegionCode
146 enum class RegionCode : u32 {
147 Japan,
148 Usa,
149 Europe,
150 Australia,
151 HongKongTaiwanKorea,
152 China,
153 };
154
155 /// This is nn::settings::system::EulaVersionClockType
156 enum class EulaVersionClockType : u32 {
157 NetworkSystemClock,
158 SteadyClock,
159 };
160
161 /// This is nn::settings::system::SleepFlag
162 struct SleepFlag {
163 union {
164 u32 raw{};
165
166 BitField<0, 1, u32> SleepsWhilePlayingMedia;
167 BitField<1, 1, u32> WakesAtPowerStateChange;
168 };
169 };
170 static_assert(sizeof(SleepFlag) == 4, "TvFlag is an invalid size");
171
172 /// This is nn::settings::system::TvFlag
173 struct TvFlag {
174 union {
175 u32 raw{};
176
177 BitField<0, 1, u32> Allows4k;
178 BitField<1, 1, u32> Allows3d;
179 BitField<2, 1, u32> AllowsCec;
180 BitField<3, 1, u32> PreventsScreenBurnIn;
181 };
182 };
183 static_assert(sizeof(TvFlag) == 4, "TvFlag is an invalid size");
184
185 /// This is nn::settings::system::InitialLaunchFlag
186 struct InitialLaunchFlag {
187 union {
188 u32 raw{};
189
190 BitField<0, 1, u32> InitialLaunchCompletionFlag;
191 BitField<8, 1, u32> InitialLaunchUserAdditionFlag;
192 BitField<16, 1, u32> InitialLaunchTimestampFlag;
193 };
194 };
195 static_assert(sizeof(InitialLaunchFlag) == 4, "InitialLaunchFlag is an invalid size");
196
197 /// This is nn::settings::system::NotificationFlag
198 struct NotificationFlag {
199 union {
200 u32 raw{};
201
202 BitField<0, 1, u32> RingtoneFlag;
203 BitField<1, 1, u32> DownloadCompletionFlag;
204 BitField<8, 1, u32> EnablesNews;
205 BitField<9, 1, u32> IncomingLampFlag;
206 };
207 };
208 static_assert(sizeof(NotificationFlag) == 4, "NotificationFlag is an invalid size");
209
210 /// This is nn::settings::system::AccountNotificationFlag
211 struct AccountNotificationFlag {
212 union {
213 u32 raw{};
214
215 BitField<0, 1, u32> FriendOnlineFlag;
216 BitField<1, 1, u32> FriendRequestFlag;
217 BitField<8, 1, u32> CoralInvitationFlag;
218 };
219 };
220 static_assert(sizeof(AccountNotificationFlag) == 4,
221 "AccountNotificationFlag is an invalid size");
222
223 /// This is nn::settings::system::TvSettings
224 struct TvSettings {
225 TvFlag flags;
226 TvResolution tv_resolution;
227 HdmiContentType hdmi_content_type;
228 RgbRange rgb_range;
229 CmuMode cmu_mode;
230 u32 tv_underscan;
231 f32 tv_gama;
232 f32 constrast_ratio;
233 };
234 static_assert(sizeof(TvSettings) == 0x20, "TvSettings is an invalid size");
235
236 /// This is nn::settings::system::NotificationTime
237 struct NotificationTime {
238 u32 hour;
239 u32 minute;
240 };
241 static_assert(sizeof(NotificationTime) == 0x8, "NotificationTime is an invalid size");
242
243 /// This is nn::settings::system::NotificationSettings
244 struct NotificationSettings {
245 NotificationFlag flags;
246 NotificationVolume volume;
247 NotificationTime start_time;
248 NotificationTime stop_time;
249 };
250 static_assert(sizeof(NotificationSettings) == 0x18, "NotificationSettings is an invalid size");
251
252 /// This is nn::settings::system::AccountSettings
253 struct AccountSettings {
254 u32 flags;
255 };
256 static_assert(sizeof(AccountSettings) == 0x4, "AccountSettings is an invalid size");
257
258 /// This is nn::settings::system::AccountNotificationSettings
259 struct AccountNotificationSettings {
260 Common::UUID uid;
261 AccountNotificationFlag flags;
262 FriendPresenceOverlayPermission friend_presence_permission;
263 FriendPresenceOverlayPermission friend_invitation_permission;
264 INSERT_PADDING_BYTES(0x2);
265 };
266 static_assert(sizeof(AccountNotificationSettings) == 0x18,
267 "AccountNotificationSettings is an invalid size");
268
269 /// This is nn::settings::system::InitialLaunchSettings
270 struct SleepSettings {
271 SleepFlag flags;
272 HandheldSleepPlan handheld_sleep_plan;
273 ConsoleSleepPlan console_sleep_plan;
274 };
275 static_assert(sizeof(SleepSettings) == 0xc, "SleepSettings is incorrect size");
276
277 /// This is nn::settings::system::InitialLaunchSettings
278 struct InitialLaunchSettings {
279 InitialLaunchFlag flags;
280 INSERT_PADDING_BYTES(0x4);
281 Time::Clock::SteadyClockTimePoint timestamp;
282 };
283 static_assert(sizeof(InitialLaunchSettings) == 0x20, "InitialLaunchSettings is incorrect size");
284
285 /// This is nn::settings::system::InitialLaunchSettings
286 struct EulaVersion {
287 u32 version;
288 RegionCode region_code;
289 EulaVersionClockType clock_type;
290 INSERT_PADDING_BYTES(0x4);
291 s64 posix_time;
292 Time::Clock::SteadyClockTimePoint timestamp;
293 };
294 static_assert(sizeof(EulaVersion) == 0x30, "EulaVersion is incorrect size");
295
296 /// This is nn::settings::system::HomeMenuScheme
297 struct HomeMenuScheme {
298 u32 main;
299 u32 back;
300 u32 sub;
301 u32 bezel;
302 u32 extra;
303 };
304 static_assert(sizeof(HomeMenuScheme) == 0x14, "HomeMenuScheme is incorrect size");
305 78
79private:
306 void SetLanguageCode(HLERequestContext& ctx); 80 void SetLanguageCode(HLERequestContext& ctx);
307 void GetFirmwareVersion(HLERequestContext& ctx); 81 void GetFirmwareVersion(HLERequestContext& ctx);
308 void GetFirmwareVersion2(HLERequestContext& ctx); 82 void GetFirmwareVersion2(HLERequestContext& ctx);
83 void GetExternalSteadyClockSourceId(HLERequestContext& ctx);
84 void SetExternalSteadyClockSourceId(HLERequestContext& ctx);
85 void GetUserSystemClockContext(HLERequestContext& ctx);
86 void SetUserSystemClockContext(HLERequestContext& ctx);
309 void GetAccountSettings(HLERequestContext& ctx); 87 void GetAccountSettings(HLERequestContext& ctx);
310 void SetAccountSettings(HLERequestContext& ctx); 88 void SetAccountSettings(HLERequestContext& ctx);
311 void GetEulaVersions(HLERequestContext& ctx); 89 void GetEulaVersions(HLERequestContext& ctx);
@@ -321,7 +99,13 @@ private:
321 void GetTvSettings(HLERequestContext& ctx); 99 void GetTvSettings(HLERequestContext& ctx);
322 void SetTvSettings(HLERequestContext& ctx); 100 void SetTvSettings(HLERequestContext& ctx);
323 void GetQuestFlag(HLERequestContext& ctx); 101 void GetQuestFlag(HLERequestContext& ctx);
102 void GetDeviceTimeZoneLocationName(HLERequestContext& ctx);
103 void SetDeviceTimeZoneLocationName(HLERequestContext& ctx);
324 void SetRegionCode(HLERequestContext& ctx); 104 void SetRegionCode(HLERequestContext& ctx);
105 void GetNetworkSystemClockContext(HLERequestContext& ctx);
106 void SetNetworkSystemClockContext(HLERequestContext& ctx);
107 void IsUserSystemClockAutomaticCorrectionEnabled(HLERequestContext& ctx);
108 void SetUserSystemClockAutomaticCorrectionEnabled(HLERequestContext& ctx);
325 void GetPrimaryAlbumStorage(HLERequestContext& ctx); 109 void GetPrimaryAlbumStorage(HLERequestContext& ctx);
326 void GetSleepSettings(HLERequestContext& ctx); 110 void GetSleepSettings(HLERequestContext& ctx);
327 void SetSleepSettings(HLERequestContext& ctx); 111 void SetSleepSettings(HLERequestContext& ctx);
@@ -333,59 +117,36 @@ private:
333 void GetMiiAuthorId(HLERequestContext& ctx); 117 void GetMiiAuthorId(HLERequestContext& ctx);
334 void GetAutoUpdateEnableFlag(HLERequestContext& ctx); 118 void GetAutoUpdateEnableFlag(HLERequestContext& ctx);
335 void GetBatteryPercentageFlag(HLERequestContext& ctx); 119 void GetBatteryPercentageFlag(HLERequestContext& ctx);
120 void SetExternalSteadyClockInternalOffset(HLERequestContext& ctx);
121 void GetExternalSteadyClockInternalOffset(HLERequestContext& ctx);
336 void GetErrorReportSharePermission(HLERequestContext& ctx); 122 void GetErrorReportSharePermission(HLERequestContext& ctx);
337 void GetAppletLaunchFlags(HLERequestContext& ctx); 123 void GetAppletLaunchFlags(HLERequestContext& ctx);
338 void SetAppletLaunchFlags(HLERequestContext& ctx); 124 void SetAppletLaunchFlags(HLERequestContext& ctx);
339 void GetKeyboardLayout(HLERequestContext& ctx); 125 void GetKeyboardLayout(HLERequestContext& ctx);
126 void GetDeviceTimeZoneLocationUpdatedTime(HLERequestContext& ctx);
127 void SetDeviceTimeZoneLocationUpdatedTime(HLERequestContext& ctx);
128 void GetUserSystemClockAutomaticCorrectionUpdatedTime(HLERequestContext& ctx);
129 void SetUserSystemClockAutomaticCorrectionUpdatedTime(HLERequestContext& ctx);
340 void GetChineseTraditionalInputMethod(HLERequestContext& ctx); 130 void GetChineseTraditionalInputMethod(HLERequestContext& ctx);
341 void GetFieldTestingFlag(HLERequestContext& ctx);
342 void GetHomeMenuScheme(HLERequestContext& ctx); 131 void GetHomeMenuScheme(HLERequestContext& ctx);
343 void GetHomeMenuSchemeModel(HLERequestContext& ctx); 132 void GetHomeMenuSchemeModel(HLERequestContext& ctx);
133 void GetFieldTestingFlag(HLERequestContext& ctx);
344 134
345 AccountSettings account_settings{ 135 bool LoadSettingsFile(std::filesystem::path& path, auto&& default_func);
346 .flags = {}, 136 bool StoreSettingsFile(std::filesystem::path& path, auto& settings);
347 }; 137 void SetupSettings();
348 138 void StoreSettings();
349 ColorSet color_set = ColorSet::BasicWhite; 139 void StoreSettingsThreadFunc(std::stop_token stop_token);
350 140 void SetSaveNeeded();
351 NotificationSettings notification_settings{ 141
352 .flags = {0x300}, 142 Core::System& m_system;
353 .volume = NotificationVolume::High, 143 SystemSettings m_system_settings{};
354 .start_time = {.hour = 9, .minute = 0}, 144 PrivateSettings m_private_settings{};
355 .stop_time = {.hour = 21, .minute = 0}, 145 DeviceSettings m_device_settings{};
356 }; 146 ApplnSettings m_appln_settings{};
357 147 std::jthread m_save_thread;
358 std::vector<AccountNotificationSettings> account_notifications{}; 148 std::mutex m_save_needed_mutex;
359 149 bool m_save_needed{false};
360 TvSettings tv_settings{
361 .flags = {0xc},
362 .tv_resolution = TvResolution::Auto,
363 .hdmi_content_type = HdmiContentType::Game,
364 .rgb_range = RgbRange::Auto,
365 .cmu_mode = CmuMode::None,
366 .tv_underscan = {},
367 .tv_gama = 1.0f,
368 .constrast_ratio = 0.5f,
369 };
370
371 InitialLaunchSettings launch_settings{
372 .flags = {0x10001},
373 .timestamp = {},
374 };
375
376 SleepSettings sleep_settings{
377 .flags = {0x3},
378 .handheld_sleep_plan = HandheldSleepPlan::Sleep10Min,
379 .console_sleep_plan = ConsoleSleepPlan::Sleep1Hour,
380 };
381
382 u32 applet_launch_flag{};
383
384 std::vector<EulaVersion> eula_versions{};
385
386 RegionCode region_code;
387
388 LanguageCode language_code_setting;
389}; 150};
390 151
391} // namespace Service::Set 152} // namespace Service::Set
diff --git a/src/core/hle/service/set/system_settings.cpp b/src/core/hle/service/set/system_settings.cpp
new file mode 100644
index 000000000..2723417ad
--- /dev/null
+++ b/src/core/hle/service/set/system_settings.cpp
@@ -0,0 +1,51 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include "core/hle/service/set/system_settings.h"
5
6namespace Service::Set {
7
8SystemSettings DefaultSystemSettings() {
9 SystemSettings settings{};
10
11 settings.version = 0x140000;
12 settings.flags = 7;
13
14 settings.color_set_id = ColorSet::BasicWhite;
15
16 settings.notification_settings = {
17 .flags{0x300},
18 .volume = NotificationVolume::High,
19 .start_time = {.hour = 9, .minute = 0},
20 .stop_time = {.hour = 21, .minute = 0},
21 };
22
23 settings.tv_settings = {
24 .flags = {0xC},
25 .tv_resolution = TvResolution::Auto,
26 .hdmi_content_type = HdmiContentType::Game,
27 .rgb_range = RgbRange::Auto,
28 .cmu_mode = CmuMode::None,
29 .tv_underscan = {},
30 .tv_gama = 1.0f,
31 .constrast_ratio = 0.5f,
32 };
33
34 settings.initial_launch_settings_packed = {
35 .flags = {0x10001},
36 .timestamp = {},
37 };
38
39 settings.sleep_settings = {
40 .flags = {0x3},
41 .handheld_sleep_plan = HandheldSleepPlan::Sleep10Min,
42 .console_sleep_plan = ConsoleSleepPlan::Sleep1Hour,
43 };
44
45 settings.device_time_zone_location_name = {"UTC"};
46 settings.user_system_clock_automatic_correction_enabled = false;
47
48 return settings;
49}
50
51} // namespace Service::Set
diff --git a/src/core/hle/service/set/system_settings.h b/src/core/hle/service/set/system_settings.h
new file mode 100644
index 000000000..ded2906ad
--- /dev/null
+++ b/src/core/hle/service/set/system_settings.h
@@ -0,0 +1,699 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <array>
7
8#include "common/bit_field.h"
9#include "common/common_funcs.h"
10#include "common/common_types.h"
11#include "core/hle/service/set/private_settings.h"
12#include "core/hle/service/time/clock_types.h"
13
14namespace Service::Set {
15
16/// This is "nn::settings::LanguageCode", which is a NUL-terminated string stored in a u64.
17enum class LanguageCode : u64 {
18 JA = 0x000000000000616A,
19 EN_US = 0x00000053552D6E65,
20 FR = 0x0000000000007266,
21 DE = 0x0000000000006564,
22 IT = 0x0000000000007469,
23 ES = 0x0000000000007365,
24 ZH_CN = 0x0000004E432D687A,
25 KO = 0x0000000000006F6B,
26 NL = 0x0000000000006C6E,
27 PT = 0x0000000000007470,
28 RU = 0x0000000000007572,
29 ZH_TW = 0x00000057542D687A,
30 EN_GB = 0x00000042472D6E65,
31 FR_CA = 0x00000041432D7266,
32 ES_419 = 0x00003931342D7365,
33 ZH_HANS = 0x00736E61482D687A,
34 ZH_HANT = 0x00746E61482D687A,
35 PT_BR = 0x00000052422D7470,
36};
37
38/// This is nn::settings::system::ErrorReportSharePermission
39enum class ErrorReportSharePermission : u32 {
40 NotConfirmed,
41 Granted,
42 Denied,
43};
44
45/// This is nn::settings::system::ChineseTraditionalInputMethod
46enum class ChineseTraditionalInputMethod : u32 {
47 Unknown0 = 0,
48 Unknown1 = 1,
49 Unknown2 = 2,
50};
51
52/// This is nn::settings::system::HomeMenuScheme
53struct HomeMenuScheme {
54 u32 main;
55 u32 back;
56 u32 sub;
57 u32 bezel;
58 u32 extra;
59};
60static_assert(sizeof(HomeMenuScheme) == 0x14, "HomeMenuScheme is incorrect size");
61
62/// Indicates the current theme set by the system settings
63enum class ColorSet : u32 {
64 BasicWhite = 0,
65 BasicBlack = 1,
66};
67
68/// Indicates the current console is a retail or kiosk unit
69enum class QuestFlag : u8 {
70 Retail = 0,
71 Kiosk = 1,
72};
73
74/// This is nn::settings::system::RegionCode
75enum class RegionCode : u32 {
76 Japan,
77 Usa,
78 Europe,
79 Australia,
80 HongKongTaiwanKorea,
81 China,
82};
83
84/// This is nn::settings::system::AccountSettings
85struct AccountSettings {
86 u32 flags;
87};
88static_assert(sizeof(AccountSettings) == 4, "AccountSettings is an invalid size");
89
90/// This is nn::settings::system::NotificationVolume
91enum class NotificationVolume : u32 {
92 Mute,
93 Low,
94 High,
95};
96
97/// This is nn::settings::system::NotificationFlag
98struct NotificationFlag {
99 union {
100 u32 raw{};
101
102 BitField<0, 1, u32> RingtoneFlag;
103 BitField<1, 1, u32> DownloadCompletionFlag;
104 BitField<8, 1, u32> EnablesNews;
105 BitField<9, 1, u32> IncomingLampFlag;
106 };
107};
108static_assert(sizeof(NotificationFlag) == 4, "NotificationFlag is an invalid size");
109
110/// This is nn::settings::system::NotificationTime
111struct NotificationTime {
112 u32 hour;
113 u32 minute;
114};
115static_assert(sizeof(NotificationTime) == 0x8, "NotificationTime is an invalid size");
116
117/// This is nn::settings::system::NotificationSettings
118struct NotificationSettings {
119 NotificationFlag flags;
120 NotificationVolume volume;
121 NotificationTime start_time;
122 NotificationTime stop_time;
123};
124static_assert(sizeof(NotificationSettings) == 0x18, "NotificationSettings is an invalid size");
125
126/// This is nn::settings::system::AccountNotificationFlag
127struct AccountNotificationFlag {
128 union {
129 u32 raw{};
130
131 BitField<0, 1, u32> FriendOnlineFlag;
132 BitField<1, 1, u32> FriendRequestFlag;
133 BitField<8, 1, u32> CoralInvitationFlag;
134 };
135};
136static_assert(sizeof(AccountNotificationFlag) == 4, "AccountNotificationFlag is an invalid size");
137
138/// This is nn::settings::system::FriendPresenceOverlayPermission
139enum class FriendPresenceOverlayPermission : u8 {
140 NotConfirmed,
141 NoDisplay,
142 FavoriteFriends,
143 Friends,
144};
145
146/// This is nn::settings::system::AccountNotificationSettings
147struct AccountNotificationSettings {
148 Common::UUID uid;
149 AccountNotificationFlag flags;
150 FriendPresenceOverlayPermission friend_presence_permission;
151 FriendPresenceOverlayPermission friend_invitation_permission;
152 INSERT_PADDING_BYTES(0x2);
153};
154static_assert(sizeof(AccountNotificationSettings) == 0x18,
155 "AccountNotificationSettings is an invalid size");
156
157/// This is nn::settings::system::TvFlag
158struct TvFlag {
159 union {
160 u32 raw{};
161
162 BitField<0, 1, u32> Allows4k;
163 BitField<1, 1, u32> Allows3d;
164 BitField<2, 1, u32> AllowsCec;
165 BitField<3, 1, u32> PreventsScreenBurnIn;
166 };
167};
168static_assert(sizeof(TvFlag) == 4, "TvFlag is an invalid size");
169
170/// This is nn::settings::system::TvResolution
171enum class TvResolution : u32 {
172 Auto,
173 Resolution1080p,
174 Resolution720p,
175 Resolution480p,
176};
177
178/// This is nn::settings::system::HdmiContentType
179enum class HdmiContentType : u32 {
180 None,
181 Graphics,
182 Cinema,
183 Photo,
184 Game,
185};
186
187/// This is nn::settings::system::RgbRange
188enum class RgbRange : u32 {
189 Auto,
190 Full,
191 Limited,
192};
193
194/// This is nn::settings::system::CmuMode
195enum class CmuMode : u32 {
196 None,
197 ColorInvert,
198 HighContrast,
199 GrayScale,
200};
201
202/// This is nn::settings::system::TvSettings
203struct TvSettings {
204 TvFlag flags;
205 TvResolution tv_resolution;
206 HdmiContentType hdmi_content_type;
207 RgbRange rgb_range;
208 CmuMode cmu_mode;
209 u32 tv_underscan;
210 f32 tv_gama;
211 f32 constrast_ratio;
212};
213static_assert(sizeof(TvSettings) == 0x20, "TvSettings is an invalid size");
214
215/// This is nn::settings::system::PrimaryAlbumStorage
216enum class PrimaryAlbumStorage : u32 {
217 Nand,
218 SdCard,
219};
220
221/// This is nn::settings::system::HandheldSleepPlan
222enum class HandheldSleepPlan : u32 {
223 Sleep1Min,
224 Sleep3Min,
225 Sleep5Min,
226 Sleep10Min,
227 Sleep30Min,
228 Never,
229};
230
231/// This is nn::settings::system::ConsoleSleepPlan
232enum class ConsoleSleepPlan : u32 {
233 Sleep1Hour,
234 Sleep2Hour,
235 Sleep3Hour,
236 Sleep6Hour,
237 Sleep12Hour,
238 Never,
239};
240
241/// This is nn::settings::system::SleepFlag
242struct SleepFlag {
243 union {
244 u32 raw{};
245
246 BitField<0, 1, u32> SleepsWhilePlayingMedia;
247 BitField<1, 1, u32> WakesAtPowerStateChange;
248 };
249};
250static_assert(sizeof(SleepFlag) == 4, "TvFlag is an invalid size");
251
252/// This is nn::settings::system::SleepSettings
253struct SleepSettings {
254 SleepFlag flags;
255 HandheldSleepPlan handheld_sleep_plan;
256 ConsoleSleepPlan console_sleep_plan;
257};
258static_assert(sizeof(SleepSettings) == 0xc, "SleepSettings is incorrect size");
259
260/// This is nn::settings::system::EulaVersionClockType
261enum class EulaVersionClockType : u32 {
262 NetworkSystemClock,
263 SteadyClock,
264};
265
266/// This is nn::settings::system::EulaVersion
267struct EulaVersion {
268 u32 version;
269 RegionCode region_code;
270 EulaVersionClockType clock_type;
271 INSERT_PADDING_BYTES(0x4);
272 s64 posix_time;
273 Time::Clock::SteadyClockTimePoint timestamp;
274};
275static_assert(sizeof(EulaVersion) == 0x30, "EulaVersion is incorrect size");
276
277struct SystemSettings {
278 // 0/unwritten (1.0.0), 0x20000 (2.0.0), 0x30000 (3.0.0-3.0.1), 0x40001 (4.0.0-4.1.0), 0x50000
279 // (5.0.0-5.1.0), 0x60000 (6.0.0-6.2.0), 0x70000 (7.0.0), 0x80000 (8.0.0-8.1.1), 0x90000
280 // (9.0.0-10.0.4), 0x100100 (10.1.0+), 0x120000 (12.0.0-12.1.0), 0x130000 (13.0.0-13.2.1),
281 // 0x140000 (14.0.0+)
282 u32 version;
283 // 0/unwritten (1.0.0), 1 (6.0.0-8.1.0), 2 (8.1.1), 7 (9.0.0+).
284 // if (flags & 2), defaults are written for AnalogStickUserCalibration
285 u32 flags;
286
287 std::array<u8, 0x8> reserved_00008;
288
289 // nn::settings::LanguageCode
290 LanguageCode language_code;
291
292 std::array<u8, 0x38> reserved_00018;
293
294 // nn::settings::system::NetworkSettings
295 u32 network_setting_count;
296 bool wireless_lan_enable_flag;
297 std::array<u8, 0x3> pad_00055;
298
299 std::array<u8, 0x8> reserved_00058;
300
301 // nn::settings::system::NetworkSettings
302 std::array<std::array<u8, 0x400>, 32> network_settings_1B0;
303
304 // nn::settings::system::BluetoothDevicesSettings
305 std::array<u8, 0x4> bluetooth_device_settings_count;
306 bool bluetooth_enable_flag;
307 std::array<u8, 0x3> pad_08065;
308 bool bluetooth_afh_enable_flag;
309 std::array<u8, 0x3> pad_08069;
310 bool bluetooth_boost_enable_flag;
311 std::array<u8, 0x3> pad_0806D;
312 std::array<std::array<u8, 0x200>, 10> bluetooth_device_settings_first_10;
313
314 s32 ldn_channel;
315
316 std::array<u8, 0x3C> reserved_09474;
317
318 // nn::util::Uuid MiiAuthorId
319 std::array<u8, 0x10> mii_author_id;
320
321 std::array<u8, 0x30> reserved_094C0;
322
323 // nn::settings::system::NxControllerSettings
324 u32 nx_controller_settings_count;
325
326 std::array<u8, 0xC> reserved_094F4;
327
328 // nn::settings::system::NxControllerSettings,
329 // nn::settings::system::NxControllerLegacySettings on 13.0.0+
330 std::array<std::array<u8, 0x40>, 10> nx_controller_legacy_settings;
331
332 std::array<u8, 0x170> reserved_09780;
333
334 bool external_rtc_reset_flag;
335 std::array<u8, 0x3> pad_098F1;
336
337 std::array<u8, 0x3C> reserved_098F4;
338
339 s32 push_notification_activity_mode_on_sleep;
340
341 std::array<u8, 0x3C> reserved_09934;
342
343 // nn::settings::system::ErrorReportSharePermission
344 ErrorReportSharePermission error_report_share_permssion;
345
346 std::array<u8, 0x3C> reserved_09974;
347
348 // nn::settings::KeyboardLayout
349 std::array<u8, 0x4> keyboard_layout;
350
351 std::array<u8, 0x3C> reserved_099B4;
352
353 bool web_inspector_flag;
354 std::array<u8, 0x3> pad_099F1;
355
356 // nn::settings::system::AllowedSslHost
357 u32 allowed_ssl_host_count;
358
359 bool memory_usage_rate_flag;
360 std::array<u8, 0x3> pad_099F9;
361
362 std::array<u8, 0x34> reserved_099FC;
363
364 // nn::settings::system::HostFsMountPoint
365 std::array<u8, 0x100> host_fs_mount_point;
366
367 // nn::settings::system::AllowedSslHost
368 std::array<std::array<u8, 0x100>, 8> allowed_ssl_hosts;
369
370 std::array<u8, 0x6C0> reserved_0A330;
371
372 // nn::settings::system::BlePairingSettings
373 u32 ble_pairing_settings_count;
374 std::array<u8, 0xC> reserved_0A9F4;
375 std::array<std::array<u8, 0x80>, 10> ble_pairing_settings;
376
377 // nn::settings::system::AccountOnlineStorageSettings
378 u32 account_online_storage_settings_count;
379 std::array<u8, 0xC> reserved_0AF04;
380 std::array<std::array<u8, 0x40>, 8> account_online_storage_settings;
381
382 bool pctl_ready_flag;
383 std::array<u8, 0x3> pad_0B111;
384
385 std::array<u8, 0x3C> reserved_0B114;
386
387 // nn::settings::system::ThemeId
388 std::array<u8, 0x80> theme_id_type0;
389 std::array<u8, 0x80> theme_id_type1;
390
391 std::array<u8, 0x100> reserved_0B250;
392
393 // nn::settings::ChineseTraditionalInputMethod
394 ChineseTraditionalInputMethod chinese_traditional_input_method;
395
396 std::array<u8, 0x3C> reserved_0B354;
397
398 bool zoom_flag;
399 std::array<u8, 0x3> pad_0B391;
400
401 std::array<u8, 0x3C> reserved_0B394;
402
403 // nn::settings::system::ButtonConfigRegisteredSettings
404 u32 button_config_registered_settings_count;
405 std::array<u8, 0xC> reserved_0B3D4;
406
407 // nn::settings::system::ButtonConfigSettings
408 u32 button_config_settings_count;
409 std::array<u8, 0x4> reserved_0B3E4;
410 std::array<std::array<u8, 0x5A8>, 5> button_config_settings;
411 std::array<u8, 0x13B0> reserved_0D030;
412 u32 button_config_settings_embedded_count;
413 std::array<u8, 0x4> reserved_0E3E4;
414 std::array<std::array<u8, 0x5A8>, 5> button_config_settings_embedded;
415 std::array<u8, 0x13B0> reserved_10030;
416 u32 button_config_settings_left_count;
417 std::array<u8, 0x4> reserved_113E4;
418 std::array<std::array<u8, 0x5A8>, 5> button_config_settings_left;
419 std::array<u8, 0x13B0> reserved_13030;
420 u32 button_config_settings_right_count;
421 std::array<u8, 0x4> reserved_143E4;
422 std::array<std::array<u8, 0x5A8>, 5> button_config_settings_right;
423 std::array<u8, 0x73B0> reserved_16030;
424 // nn::settings::system::ButtonConfigRegisteredSettings
425 std::array<u8, 0x5C8> button_config_registered_settings_embedded;
426 std::array<std::array<u8, 0x5C8>, 10> button_config_registered_settings;
427
428 std::array<u8, 0x7FF8> reserved_21378;
429
430 // nn::settings::system::ConsoleSixAxisSensorAccelerationBias
431 std::array<u8, 0xC> console_six_axis_sensor_acceleration_bias;
432 // nn::settings::system::ConsoleSixAxisSensorAngularVelocityBias
433 std::array<u8, 0xC> console_six_axis_sensor_angular_velocity_bias;
434 // nn::settings::system::ConsoleSixAxisSensorAccelerationGain
435 std::array<u8, 0x24> console_six_axis_sensor_acceleration_gain;
436 // nn::settings::system::ConsoleSixAxisSensorAngularVelocityGain
437 std::array<u8, 0x24> console_six_axis_sensor_angular_velocity_gain;
438 // nn::settings::system::ConsoleSixAxisSensorAngularVelocityTimeBias
439 std::array<u8, 0xC> console_six_axis_sensor_angular_velocity_time_bias;
440 // nn::settings::system::ConsoleSixAxisSensorAngularAcceleration
441 std::array<u8, 0x24> console_six_axis_sensor_angular_velocity_acceleration;
442
443 std::array<u8, 0x70> reserved_29400;
444
445 bool lock_screen_flag;
446 std::array<u8, 0x3> pad_29471;
447
448 std::array<u8, 0x4> reserved_249274;
449
450 ColorSet color_set_id;
451
452 QuestFlag quest_flag;
453
454 // nn::settings::system::RegionCode
455 RegionCode region_code;
456
457 // Different to nn::settings::system::InitialLaunchSettings?
458 InitialLaunchSettingsPacked initial_launch_settings_packed;
459
460 bool battery_percentage_flag;
461 std::array<u8, 0x3> pad_294A1;
462
463 // BitFlagSet<32, nn::settings::system::AppletLaunchFlag>
464 u32 applet_launch_flag;
465
466 // nn::settings::system::ThemeSettings
467 std::array<u8, 0x8> theme_settings;
468 // nn::fssystem::ArchiveMacKey
469 std::array<u8, 0x10> theme_key;
470
471 bool field_testing_flag;
472 std::array<u8, 0x3> pad_294C1;
473
474 s32 panel_crc_mode;
475
476 std::array<u8, 0x28> reserved_294C8;
477
478 // nn::settings::system::BacklightSettings
479 std::array<u8, 0x2C> backlight_settings_mixed_up;
480
481 std::array<u8, 0x64> reserved_2951C;
482
483 // nn::time::SystemClockContext
484 Service::Time::Clock::SystemClockContext user_system_clock_context;
485 Service::Time::Clock::SystemClockContext network_system_clock_context;
486 bool user_system_clock_automatic_correction_enabled;
487 std::array<u8, 0x3> pad_295C1;
488 std::array<u8, 0x4> reserved_295C4;
489 // nn::time::SteadyClockTimePoint
490 Service::Time::Clock::SteadyClockTimePoint
491 user_system_clock_automatic_correction_updated_time_point;
492
493 std::array<u8, 0x10> reserved_295E0;
494
495 // nn::settings::system::AccountSettings
496 AccountSettings account_settings;
497
498 std::array<u8, 0xFC> reserved_295F4;
499
500 // nn::settings::system::AudioVolume
501 std::array<u8, 0x8> audio_volume_type0;
502 std::array<u8, 0x8> audio_volume_type1;
503 // nn::settings::system::AudioOutputMode
504 s32 audio_output_mode_type0;
505 s32 audio_output_mode_type1;
506 s32 audio_output_mode_type2;
507 bool force_mute_on_headphone_removed;
508 std::array<u8, 0x3> pad_2970D;
509 s32 headphone_volume_warning_count;
510 bool heaphone_volume_update_flag;
511 std::array<u8, 0x3> pad_29715;
512 // nn::settings::system::AudioVolume
513 std::array<u8, 0x8> audio_volume_type2;
514 // nn::settings::system::AudioOutputMode
515 s32 audio_output_mode_type3;
516 s32 audio_output_mode_type4;
517 bool hearing_protection_safeguard_flag;
518 std::array<u8, 0x3> pad_29729;
519 std::array<u8, 0x4> reserved_2972C;
520 s64 hearing_protection_safeguard_remaining_time;
521 std::array<u8, 0x38> reserved_29738;
522
523 bool console_information_upload_flag;
524 std::array<u8, 0x3> pad_29771;
525
526 std::array<u8, 0x3C> reserved_29774;
527
528 bool automatic_application_download_flag;
529 std::array<u8, 0x3> pad_297B1;
530
531 std::array<u8, 0x4> reserved_297B4;
532
533 // nn::settings::system::NotificationSettings
534 NotificationSettings notification_settings;
535
536 std::array<u8, 0x60> reserved_297D0;
537
538 // nn::settings::system::AccountNotificationSettings
539 u32 account_notification_settings_count;
540 std::array<u8, 0xC> reserved_29834;
541 std::array<AccountNotificationSettings, 8> account_notification_settings;
542
543 std::array<u8, 0x140> reserved_29900;
544
545 f32 vibration_master_volume;
546
547 bool usb_full_key_enable_flag;
548 std::array<u8, 0x3> pad_29A45;
549
550 // nn::settings::system::AnalogStickUserCalibration
551 std::array<u8, 0x10> analog_stick_user_calibration_left;
552 std::array<u8, 0x10> analog_stick_user_calibration_right;
553
554 // nn::settings::system::TouchScreenMode
555 s32 touch_screen_mode;
556
557 std::array<u8, 0x14> reserved_29A6C;
558
559 // nn::settings::system::TvSettings
560 TvSettings tv_settings;
561
562 // nn::settings::system::Edid
563 std::array<u8, 0x100> edid;
564
565 std::array<u8, 0x2E0> reserved_29BA0;
566
567 // nn::settings::system::DataDeletionSettings
568 std::array<u8, 0x8> data_deletion_settings;
569
570 std::array<u8, 0x38> reserved_29E88;
571
572 // nn::ncm::ProgramId
573 std::array<u8, 0x8> initial_system_applet_program_id;
574 std::array<u8, 0x8> overlay_disp_program_id;
575
576 std::array<u8, 0x4> reserved_29ED0;
577
578 bool requires_run_repair_time_reviser;
579
580 std::array<u8, 0x6B> reserved_29ED5;
581
582 // nn::time::LocationName
583 Service::Time::TimeZone::LocationName device_time_zone_location_name;
584 std::array<u8, 0x4> reserved_29F64;
585 // nn::time::SteadyClockTimePoint
586 Service::Time::Clock::SteadyClockTimePoint device_time_zone_location_updated_time;
587
588 std::array<u8, 0xC0> reserved_29F80;
589
590 // nn::settings::system::PrimaryAlbumStorage
591 PrimaryAlbumStorage primary_album_storage;
592
593 std::array<u8, 0x3C> reserved_2A044;
594
595 bool usb_30_enable_flag;
596 std::array<u8, 0x3> pad_2A081;
597 bool usb_30_host_enable_flag;
598 std::array<u8, 0x3> pad_2A085;
599 bool usb_30_device_enable_flag;
600 std::array<u8, 0x3> pad_2A089;
601
602 std::array<u8, 0x34> reserved_2A08C;
603
604 bool nfc_enable_flag;
605 std::array<u8, 0x3> pad_2A0C1;
606
607 std::array<u8, 0x3C> reserved_2A0C4;
608
609 // nn::settings::system::SleepSettings
610 SleepSettings sleep_settings;
611
612 std::array<u8, 0x34> reserved_2A10C;
613
614 // nn::settings::system::EulaVersion
615 u32 eula_version_count;
616 std::array<u8, 0xC> reserved_2A144;
617 std::array<EulaVersion, 32> eula_versions;
618
619 std::array<u8, 0x200> reserved_2A750;
620
621 // nn::settings::system::DeviceNickName
622 std::array<u8, 0x80> device_nick_name;
623
624 std::array<u8, 0x80> reserved_2A9D0;
625
626 bool auto_update_enable_flag;
627 std::array<u8, 0x3> pad_2AA51;
628
629 std::array<u8, 0x4C> reserved_2AA54;
630
631 // nn::settings::system::BluetoothDevicesSettings
632 std::array<std::array<u8, 0x200>, 14> bluetooth_device_settings_last_14;
633
634 std::array<u8, 0x2000> reserved_2C6A0;
635
636 // nn::settings::system::NxControllerSettings
637 std::array<std::array<u8, 0x800>, 10> nx_controller_settings_data_from_offset_30;
638};
639
640static_assert(offsetof(SystemSettings, language_code) == 0x10);
641static_assert(offsetof(SystemSettings, network_setting_count) == 0x50);
642static_assert(offsetof(SystemSettings, network_settings_1B0) == 0x60);
643static_assert(offsetof(SystemSettings, bluetooth_device_settings_count) == 0x8060);
644static_assert(offsetof(SystemSettings, bluetooth_enable_flag) == 0x8064);
645static_assert(offsetof(SystemSettings, bluetooth_device_settings_first_10) == 0x8070);
646static_assert(offsetof(SystemSettings, ldn_channel) == 0x9470);
647static_assert(offsetof(SystemSettings, mii_author_id) == 0x94B0);
648static_assert(offsetof(SystemSettings, nx_controller_settings_count) == 0x94F0);
649static_assert(offsetof(SystemSettings, nx_controller_legacy_settings) == 0x9500);
650static_assert(offsetof(SystemSettings, external_rtc_reset_flag) == 0x98F0);
651static_assert(offsetof(SystemSettings, push_notification_activity_mode_on_sleep) == 0x9930);
652static_assert(offsetof(SystemSettings, allowed_ssl_host_count) == 0x99F4);
653static_assert(offsetof(SystemSettings, host_fs_mount_point) == 0x9A30);
654static_assert(offsetof(SystemSettings, allowed_ssl_hosts) == 0x9B30);
655static_assert(offsetof(SystemSettings, ble_pairing_settings_count) == 0xA9F0);
656static_assert(offsetof(SystemSettings, ble_pairing_settings) == 0xAA00);
657static_assert(offsetof(SystemSettings, account_online_storage_settings_count) == 0xAF00);
658static_assert(offsetof(SystemSettings, account_online_storage_settings) == 0xAF10);
659static_assert(offsetof(SystemSettings, pctl_ready_flag) == 0xB110);
660static_assert(offsetof(SystemSettings, theme_id_type0) == 0xB150);
661static_assert(offsetof(SystemSettings, chinese_traditional_input_method) == 0xB350);
662static_assert(offsetof(SystemSettings, button_config_registered_settings_count) == 0xB3D0);
663static_assert(offsetof(SystemSettings, button_config_settings_count) == 0xB3E0);
664static_assert(offsetof(SystemSettings, button_config_settings) == 0xB3E8);
665static_assert(offsetof(SystemSettings, button_config_registered_settings_embedded) == 0x1D3E0);
666static_assert(offsetof(SystemSettings, console_six_axis_sensor_acceleration_bias) == 0x29370);
667static_assert(offsetof(SystemSettings, lock_screen_flag) == 0x29470);
668static_assert(offsetof(SystemSettings, battery_percentage_flag) == 0x294A0);
669static_assert(offsetof(SystemSettings, field_testing_flag) == 0x294C0);
670static_assert(offsetof(SystemSettings, backlight_settings_mixed_up) == 0x294F0);
671static_assert(offsetof(SystemSettings, user_system_clock_context) == 0x29580);
672static_assert(offsetof(SystemSettings, network_system_clock_context) == 0x295A0);
673static_assert(offsetof(SystemSettings, user_system_clock_automatic_correction_enabled) == 0x295C0);
674static_assert(offsetof(SystemSettings, user_system_clock_automatic_correction_updated_time_point) ==
675 0x295C8);
676static_assert(offsetof(SystemSettings, account_settings) == 0x295F0);
677static_assert(offsetof(SystemSettings, audio_volume_type0) == 0x296F0);
678static_assert(offsetof(SystemSettings, hearing_protection_safeguard_remaining_time) == 0x29730);
679static_assert(offsetof(SystemSettings, automatic_application_download_flag) == 0x297B0);
680static_assert(offsetof(SystemSettings, notification_settings) == 0x297B8);
681static_assert(offsetof(SystemSettings, account_notification_settings) == 0x29840);
682static_assert(offsetof(SystemSettings, vibration_master_volume) == 0x29A40);
683static_assert(offsetof(SystemSettings, analog_stick_user_calibration_left) == 0x29A48);
684static_assert(offsetof(SystemSettings, touch_screen_mode) == 0x29A68);
685static_assert(offsetof(SystemSettings, edid) == 0x29AA0);
686static_assert(offsetof(SystemSettings, data_deletion_settings) == 0x29E80);
687static_assert(offsetof(SystemSettings, requires_run_repair_time_reviser) == 0x29ED4);
688static_assert(offsetof(SystemSettings, device_time_zone_location_name) == 0x29F40);
689static_assert(offsetof(SystemSettings, nfc_enable_flag) == 0x2A0C0);
690static_assert(offsetof(SystemSettings, eula_version_count) == 0x2A140);
691static_assert(offsetof(SystemSettings, device_nick_name) == 0x2A950);
692static_assert(offsetof(SystemSettings, bluetooth_device_settings_last_14) == 0x2AAA0);
693static_assert(offsetof(SystemSettings, nx_controller_settings_data_from_offset_30) == 0x2E6A0);
694
695static_assert(sizeof(SystemSettings) == 0x336A0, "SystemSettings has the wrong size!");
696
697SystemSettings DefaultSystemSettings();
698
699} // namespace Service::Set