client_runtime_lifecycle.cpp 4.5 KB

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