client_runtime_lifecycle.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include "../../core/logging/log.h"
  2. #include "../../core/settings/settings.h"
  3. #include "../content/activity/activity_sdk_generation_worker.h"
  4. #include "../content/activity/scriptable_catalog_worker.h"
  5. #include "../content/investment/worker.h"
  6. #include "../hooks/assert_handler/assert_handler_lifecycle.h"
  7. #include "../hooks/async_io/async_io_lifetime_guard.h"
  8. #include "../hooks/bitmap/bitmap_hook_lifecycle.h"
  9. #include "../hooks/bootflow/bootflow_hook_lifecycle.h"
  10. #include "../hooks/config_getter/config_getter_lifecycle.h"
  11. #include "../hooks/cursor/runtime.h"
  12. #include "../hooks/graphics/graphics_hook_lifecycle.h"
  13. #include "../hooks/inactivity/inactivity_override.h"
  14. #include "../hooks/infinite_ammo/infinite_ammo.h"
  15. #include "../hooks/network/runtime.h"
  16. #include "../hooks/noclip/runtime.h"
  17. #include "../hooks/package_trust/package_trust_bypass.h"
  18. #include "../hooks/polled_input/runtime.h"
  19. #include "../hooks/queuez/queuez_hook_lifecycle.h"
  20. #include "../hooks/retail_log/retail_log_lifecycle.h"
  21. #include "../hooks/teleport/runtime.h"
  22. #include "../hooks/world_objects/world_object_registry.h"
  23. #include "../inactivity/inactivity_settings_store.h"
  24. #include "../movement/movement_settings_store.h"
  25. #include "../player/player_settings_store.h"
  26. #include "../targets/game.h"
  27. #include "../targets/steam_targets.h"
  28. #include "../ui/activity/authored_placement_marker.h"
  29. #include "../ui/runtime/client_ui_module_runtime.h"
  30. #include "internal.h"
  31. #include "runtime.h"
  32. namespace sunrise::client {
  33. /** Initializes Client-owned process state without installing hooks. */
  34. bool initialize(void* module) noexcept {
  35. const core::settings::ActivitySdkGenerationSettings& generation =
  36. core::settings::get().activitySdkGeneration;
  37. content::activity::sdk_generation::initialize(module,
  38. {generation.enabled, generation.luaDeclarations});
  39. // Loaded before the pages register, so each page draws saved values on its first frame.
  40. movement::initialize(module);
  41. player::initialize(module);
  42. inactivity::initialize(module);
  43. ui::activity::authored_placement_marker::initialize(module);
  44. return ui::runtime::initialize();
  45. }
  46. /** Detaches Client hooks before clearing their resolved target entries. */
  47. bool shutdown() noexcept {
  48. AcquireSRWLockExclusive(&runtime::g_lock);
  49. if (!hooks::graphics::uninstall()) {
  50. core::log::write(core::log::Channel::client,
  51. core::log::Level::error,
  52. "ev=shutdown stage=graphics_hooks result=fail");
  53. ReleaseSRWLockExclusive(&runtime::g_lock);
  54. return false;
  55. }
  56. // Detached after presentation, so no later frame can apply the cursor policy.
  57. hooks::cursor::uninstall();
  58. hooks::polled_input::uninstall();
  59. if (!hooks::world_objects::uninstall()) {
  60. core::log::write(core::log::Channel::client,
  61. core::log::Level::error,
  62. "ev=shutdown stage=world_objects result=fail");
  63. ReleaseSRWLockExclusive(&runtime::g_lock);
  64. return false;
  65. }
  66. if (!hooks::network::uninstall()) {
  67. core::log::write(core::log::Channel::client,
  68. core::log::Level::error,
  69. "ev=shutdown stage=network_hooks result=fail");
  70. ReleaseSRWLockExclusive(&runtime::g_lock);
  71. return false;
  72. }
  73. if (!hooks::package_trust::uninstall()) {
  74. core::log::write(core::log::Channel::client,
  75. core::log::Level::error,
  76. "ev=shutdown stage=package_trust result=fail");
  77. ReleaseSRWLockExclusive(&runtime::g_lock);
  78. return false;
  79. }
  80. hooks::bitmap::uninstall();
  81. hooks::bootflow::uninstall();
  82. hooks::infinite_ammo::uninstall();
  83. hooks::inactivity::uninstall();
  84. hooks::noclip::uninstall();
  85. hooks::teleport::uninstall();
  86. hooks::queuez::uninstall();
  87. if (!hooks::config_getter::uninstall()) {
  88. ReleaseSRWLockExclusive(&runtime::g_lock);
  89. return false;
  90. }
  91. if (!hooks::assert_handler::uninstall()) {
  92. ReleaseSRWLockExclusive(&runtime::g_lock);
  93. return false;
  94. }
  95. if (!hooks::retail_log::uninstall()) {
  96. core::log::write(core::log::Channel::client,
  97. core::log::Level::error,
  98. "ev=shutdown stage=retail_log result=fail");
  99. ReleaseSRWLockExclusive(&runtime::g_lock);
  100. return false;
  101. }
  102. content::activity::sdk_generation::reset();
  103. content::activity::scriptables::reset();
  104. content::investment::worker::reset();
  105. (void)hooks::async_io::uninstall();
  106. targets::steam::clear();
  107. if (runtime::g_platformModule != nullptr) {
  108. if (FreeLibrary(runtime::g_platformModule) == FALSE) {
  109. core::log::write(core::log::Channel::client,
  110. core::log::Level::error,
  111. "ev=shutdown stage=steam_module result=fail");
  112. ReleaseSRWLockExclusive(&runtime::g_lock);
  113. return false;
  114. }
  115. runtime::g_platformModule = nullptr;
  116. }
  117. targets::game::retail_log::clear();
  118. targets::game::content::clear();
  119. targets::game::network::clear();
  120. runtime::g_mainStage = runtime::StageState::pending;
  121. runtime::g_graphicsStage = runtime::StageState::pending;
  122. runtime::g_platformStage = runtime::StageState::pending;
  123. ui::runtime::shutdown();
  124. // The reverse of the order the stores initialize in.
  125. ui::activity::authored_placement_marker::shutdown();
  126. inactivity::shutdown();
  127. player::shutdown();
  128. movement::shutdown();
  129. core::log::write(core::log::Channel::client, core::log::Level::info, "ev=shutdown result=ok");
  130. ReleaseSRWLockExclusive(&runtime::g_lock);
  131. return true;
  132. }
  133. } // namespace sunrise::client