Advertisement
Guest User

Untitled

a guest
May 24th, 2020
2,646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. diff --git a/src/core/hle/service/time/time.h b/src/core/hle/service/time/time.h
  2. index 41f3002e9..c8aaf8992 100644
  3. --- a/src/core/hle/service/time/time.h
  4. +++ b/src/core/hle/service/time/time.h
  5. @@ -36,6 +36,10 @@ public:
  6. void CalculateSpanBetween(Kernel::HLERequestContext& ctx);
  7. void GetSharedMemoryNativeHandle(Kernel::HLERequestContext& ctx);
  8.  
  9. + TimeManager& GetTimeManager() {
  10. + return module->GetTimeManager();
  11. + }
  12. +
  13. private:
  14. ResultCode GetClockSnapshotFromSystemClockContextInternal(
  15. Kernel::Thread* thread, Clock::SystemClockContext user_context,
  16. diff --git a/src/core/hle/service/time/time_manager.cpp b/src/core/hle/service/time/time_manager.cpp
  17. index b4dfe45e5..aea08e49c 100644
  18. --- a/src/core/hle/service/time/time_manager.cpp
  19. +++ b/src/core/hle/service/time/time_manager.cpp
  20. @@ -5,12 +5,10 @@
  21. #include <chrono>
  22. #include <ctime>
  23.  
  24. -#include "common/time_zone.h"
  25. #include "core/hle/service/time/ephemeral_network_system_clock_context_writer.h"
  26. #include "core/hle/service/time/local_system_clock_context_writer.h"
  27. #include "core/hle/service/time/network_system_clock_context_writer.h"
  28. #include "core/hle/service/time/time_manager.h"
  29. -#include "core/settings.h"
  30.  
  31. namespace Service::Time {
  32.  
  33. @@ -22,16 +20,8 @@ static std::chrono::seconds GetSecondsSinceEpoch() {
  34. Settings::values.custom_rtc_differential;
  35. }
  36.  
  37. -static s64 GetExternalTimeZoneOffset() {
  38. - // With "auto" timezone setting, we use the external system's timezone offset
  39. - if (Settings::GetTimeZoneString() == "auto") {
  40. - return Common::TimeZone::GetCurrentOffsetSeconds().count();
  41. - }
  42. - return 0;
  43. -}
  44. -
  45. static s64 GetExternalRtcValue() {
  46. - return GetSecondsSinceEpoch().count() + GetExternalTimeZoneOffset();
  47. + return GetSecondsSinceEpoch().count() + TimeManager::GetExternalTimeZoneOffset();
  48. }
  49.  
  50. TimeManager::TimeManager(Core::System& system)
  51. diff --git a/src/core/hle/service/time/time_manager.h b/src/core/hle/service/time/time_manager.h
  52. index 8e65f0d22..f709e8930 100644
  53. --- a/src/core/hle/service/time/time_manager.h
  54. +++ b/src/core/hle/service/time/time_manager.h
  55. @@ -5,6 +5,7 @@
  56. #pragma once
  57.  
  58. #include "common/common_types.h"
  59. +#include "common/time_zone.h"
  60. #include "core/file_sys/vfs_types.h"
  61. #include "core/hle/service/time/clock_types.h"
  62. #include "core/hle/service/time/ephemeral_network_system_clock_core.h"
  63. @@ -15,6 +16,7 @@
  64. #include "core/hle/service/time/tick_based_steady_clock_core.h"
  65. #include "core/hle/service/time/time_sharedmemory.h"
  66. #include "core/hle/service/time/time_zone_content_manager.h"
  67. +#include "core/settings.h"
  68.  
  69. namespace Service::Time {
  70.  
  71. @@ -85,6 +87,14 @@ public:
  72. std::size_t total_location_name_count, u128 time_zone_rule_version,
  73. FileSys::VirtualFile& vfs_file);
  74.  
  75. + static s64 GetExternalTimeZoneOffset() {
  76. + // With "auto" timezone setting, we use the external system's timezone offset
  77. + if (Settings::GetTimeZoneString() == "auto") {
  78. + return Common::TimeZone::GetCurrentOffsetSeconds().count();
  79. + }
  80. + return 0;
  81. + }
  82. +
  83. private:
  84. void SetupStandardSteadyClock(Core::System& system, Common::UUID clock_source_id,
  85. Clock::TimeSpanType setup_value,
  86. diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp
  87. index 10315e7a6..cd6b99016 100644
  88. --- a/src/yuzu/configuration/configure_system.cpp
  89. +++ b/src/yuzu/configuration/configure_system.cpp
  90. @@ -12,10 +12,28 @@
  91. #include "common/assert.h"
  92. #include "common/file_util.h"
  93. #include "core/core.h"
  94. +#include "core/hle/service/sm/sm.h"
  95. +#include "core/hle/service/time/standard_local_system_clock_core.h"
  96. +#include "core/hle/service/time/time.h"
  97. #include "core/settings.h"
  98. #include "ui_configure_system.h"
  99. #include "yuzu/configuration/configure_system.h"
  100.  
  101. +void OnCustomRtcChanged() {
  102. + const s64 new_posix = Settings::values.custom_rtc.value().count() + Service::Time::TimeManager::GetExternalTimeZoneOffset();
  103. + const auto new_system_time{Service::Time::Clock::TimeSpanType::FromSeconds(new_posix)};
  104. + Core::System& system{Core::System::GetInstance()};
  105. + const Service::SM::ServiceManager& sm = system.ServiceManager();
  106. + const auto& tm = sm.GetService<Service::Time::Module::Interface>("time:a")->GetTimeManager();
  107. + auto local_system_clock = tm.GetStandardLocalSystemClockCore();
  108. + auto shared_memory = tm.GetSharedMemory();
  109. +
  110. + if (local_system_clock.SetCurrentTime(system, new_system_time.ToSeconds()) != RESULT_SUCCESS) {
  111. + UNREACHABLE();
  112. + return;
  113. + }
  114. +}
  115. +
  116. ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) {
  117. ui->setupUi(this);
  118. connect(ui->button_regenerate_console_id, &QPushButton::clicked, this,
  119. @@ -79,6 +97,18 @@ void ConfigureSystem::SetConfiguration() {
  120. void ConfigureSystem::ReadSystemSettings() {}
  121.  
  122. void ConfigureSystem::ApplyConfiguration() {
  123. + // Allow setting custom RTC even if system is powered on,
  124. + // to enable time travel in game.
  125. + if (ui->custom_rtc_checkbox->isChecked()) {
  126. + Settings::values.custom_rtc =
  127. + std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch());
  128. + if (Core::System::GetInstance().IsPoweredOn()) {
  129. + OnCustomRtcChanged();
  130. + }
  131. + } else {
  132. + Settings::values.custom_rtc = std::nullopt;
  133. + }
  134. +
  135. if (!enabled) {
  136. return;
  137. }
  138. @@ -94,13 +124,6 @@ void ConfigureSystem::ApplyConfiguration() {
  139. Settings::values.rng_seed = std::nullopt;
  140. }
  141.  
  142. - if (ui->custom_rtc_checkbox->isChecked()) {
  143. - Settings::values.custom_rtc =
  144. - std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch());
  145. - } else {
  146. - Settings::values.custom_rtc = std::nullopt;
  147. - }
  148. -
  149. Settings::Apply();
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement