From c6016856d878c8f68bc5518f3ef0270ea018bc3d Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 28 Dec 2018 18:35:55 -0500 Subject: settings: Add custom RTC settings Stored as signed seconds since epoch. --- src/core/settings.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/core') diff --git a/src/core/settings.h b/src/core/settings.h index de01b05c0..5b211a716 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -350,6 +350,9 @@ struct Values { bool use_docked_mode; bool enable_nfc; std::optional rng_seed; + std::optional custom_rtc; // Measured in seconds since epoch + s64 custom_rtc_differential; // Set on game boot, reset on stop. Seconds difference between + // current time and `custom_rtc` s32 current_user; s32 language_index; -- cgit v1.2.3 From 21f1b2889d2d8dc52f406957175d1d10a673128a Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 28 Dec 2018 18:36:37 -0500 Subject: core: Set custom RTC differential on game boot --- src/core/core.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/core') diff --git a/src/core/core.cpp b/src/core/core.cpp index fd10199ec..7459c0851 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -30,6 +30,7 @@ #include "core/hle/service/sm/sm.h" #include "core/loader/loader.h" #include "core/perf_stats.h" +#include "core/settings.h" #include "core/telemetry_session.h" #include "frontend/applets/software_keyboard.h" #include "video_core/debug_utils/debug_utils.h" @@ -94,6 +95,12 @@ struct System::Impl { CoreTiming::Init(); kernel.Initialize(); + const auto current_time = std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count(); + Settings::values.custom_rtc_differential = + Settings::values.custom_rtc.value_or(current_time) - current_time; + // Create a default fs if one doesn't already exist. if (virtual_filesystem == nullptr) virtual_filesystem = std::make_shared(); -- cgit v1.2.3 From dbb1eb9c29e072e77b66efa28ea21e814100d6ee Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 28 Dec 2018 19:09:57 -0500 Subject: time: Use custom RTC settings if applicable for game --- src/core/hle/service/time/time.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/core') diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index 16564de24..ef8c9f2b7 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -12,9 +12,17 @@ #include "core/hle/kernel/client_session.h" #include "core/hle/service/time/interface.h" #include "core/hle/service/time/time.h" +#include "core/settings.h" namespace Service::Time { +static s64 GetSecondsSinceEpoch() { + return std::chrono::duration_cast( + std::chrono::system_clock::now().time_since_epoch()) + .count() + + Settings::values.custom_rtc_differential; +} + static void PosixToCalendar(u64 posix_time, CalendarTime& calendar_time, CalendarAdditionalInfo& additional_info, [[maybe_unused]] const TimeZoneRule& /*rule*/) { @@ -68,9 +76,7 @@ public: private: void GetCurrentTime(Kernel::HLERequestContext& ctx) { - const s64 time_since_epoch{std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count()}; + const s64 time_since_epoch{GetSecondsSinceEpoch()}; LOG_DEBUG(Service_Time, "called"); IPC::ResponseBuilder rb{ctx, 4}; @@ -266,9 +272,7 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto initial_type = rp.PopRaw(); - const s64 time_since_epoch{std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count()}; + const s64 time_since_epoch{GetSecondsSinceEpoch()}; const std::time_t time(time_since_epoch); const std::tm* tm = std::localtime(&time); -- cgit v1.2.3 From 05dbb47af51fb00826912155da85469cb74022db Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 28 Dec 2018 20:24:24 -0500 Subject: settings: Use std::chrono::seconds instead of s64 for RTC --- src/core/core.cpp | 3 +-- src/core/hle/service/time/time.cpp | 10 ++++------ src/core/settings.h | 8 +++++--- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/core') diff --git a/src/core/core.cpp b/src/core/core.cpp index 7459c0851..123b11409 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -96,8 +96,7 @@ struct System::Impl { kernel.Initialize(); const auto current_time = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count(); + std::chrono::system_clock::now().time_since_epoch()); Settings::values.custom_rtc_differential = Settings::values.custom_rtc.value_or(current_time) - current_time; diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index ef8c9f2b7..c13640ad8 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -16,10 +16,9 @@ namespace Service::Time { -static s64 GetSecondsSinceEpoch() { +static std::chrono::seconds GetSecondsSinceEpoch() { return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count() + + std::chrono::system_clock::now().time_since_epoch()) + Settings::values.custom_rtc_differential; } @@ -76,7 +75,7 @@ public: private: void GetCurrentTime(Kernel::HLERequestContext& ctx) { - const s64 time_since_epoch{GetSecondsSinceEpoch()}; + const s64 time_since_epoch{GetSecondsSinceEpoch().count()}; LOG_DEBUG(Service_Time, "called"); IPC::ResponseBuilder rb{ctx, 4}; @@ -272,8 +271,7 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto initial_type = rp.PopRaw(); - const s64 time_since_epoch{GetSecondsSinceEpoch()}; - + const s64 time_since_epoch{GetSecondsSinceEpoch().count()}; const std::time_t time(time_since_epoch); const std::tm* tm = std::localtime(&time); if (tm == nullptr) { diff --git a/src/core/settings.h b/src/core/settings.h index 5b211a716..bb5aafa0c 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -350,9 +351,10 @@ struct Values { bool use_docked_mode; bool enable_nfc; std::optional rng_seed; - std::optional custom_rtc; // Measured in seconds since epoch - s64 custom_rtc_differential; // Set on game boot, reset on stop. Seconds difference between - // current time and `custom_rtc` + std::optional custom_rtc; // Measured in seconds since epoch + std::chrono::seconds + custom_rtc_differential; // Set on game boot, reset on stop. Seconds difference between + // current time and `custom_rtc` s32 current_user; s32 language_index; -- cgit v1.2.3 From ac7d8983ebc75b1b5e150ea7e03ff54267faf670 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Mon, 7 Jan 2019 19:40:23 -0500 Subject: settings: Fix comment structure --- src/core/settings.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/settings.h b/src/core/settings.h index bb5aafa0c..29ce98983 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -351,10 +351,11 @@ struct Values { bool use_docked_mode; bool enable_nfc; std::optional rng_seed; - std::optional custom_rtc; // Measured in seconds since epoch - std::chrono::seconds - custom_rtc_differential; // Set on game boot, reset on stop. Seconds difference between - // current time and `custom_rtc` + // Measured in seconds since epoch + std::optional custom_rtc; + // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` + std::chrono::seconds custom_rtc_differential; + s32 current_user; s32 language_index; -- cgit v1.2.3