client_runtime_lifecycle.cpp 3.8 KB

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