client_runtime_lifecycle.cpp 4.1 KB

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