client_runtime_lifecycle.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #include "../../core/logging/log.h"
  2. #include "../content/investment/worker.h"
  3. #include "../hooks/assert_handler/assert_handler_lifecycle.h"
  4. #include "../hooks/banner/banner_hook_lifecycle.h"
  5. #include "../hooks/bitmap/bitmap_hook_lifecycle.h"
  6. #include "../hooks/bootflow/bootflow_hook_lifecycle.h"
  7. #include "../hooks/config_getter/config_getter_lifecycle.h"
  8. #include "../hooks/cursor/runtime.h"
  9. #include "../hooks/graphics/graphics_hook_lifecycle.h"
  10. #include "../hooks/network/runtime.h"
  11. #include "../hooks/noclip/runtime.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. // Detached before the other game hooks because each fix is a plain one-site detour with
  50. // no shared target state to hand back.
  51. hooks::banner::uninstall();
  52. hooks::bitmap::uninstall();
  53. hooks::bootflow::uninstall();
  54. hooks::noclip::uninstall();
  55. hooks::teleport::uninstall();
  56. hooks::queuez::uninstall();
  57. if (!hooks::config_getter::uninstall()) {
  58. ReleaseSRWLockExclusive(&runtime::g_lock);
  59. return false;
  60. }
  61. if (!hooks::assert_handler::uninstall()) {
  62. ReleaseSRWLockExclusive(&runtime::g_lock);
  63. return false;
  64. }
  65. if (!hooks::retail_log::uninstall()) {
  66. core::log::write(core::log::Channel::client,
  67. core::log::Level::error,
  68. "ev=shutdown stage=retail_log result=fail");
  69. ReleaseSRWLockExclusive(&runtime::g_lock);
  70. return false;
  71. }
  72. content::investment::worker::reset();
  73. targets::steam::clear();
  74. if (runtime::g_platformModule != nullptr) {
  75. if (FreeLibrary(runtime::g_platformModule) == FALSE) {
  76. core::log::write(core::log::Channel::client,
  77. core::log::Level::error,
  78. "ev=shutdown stage=steam_module result=fail");
  79. ReleaseSRWLockExclusive(&runtime::g_lock);
  80. return false;
  81. }
  82. runtime::g_platformModule = nullptr;
  83. }
  84. targets::game::retail_log::clear();
  85. targets::game::content::clear();
  86. targets::game::network::clear();
  87. runtime::g_mainStage = runtime::StageState::pending;
  88. runtime::g_graphicsStage = runtime::StageState::pending;
  89. runtime::g_platformStage = runtime::StageState::pending;
  90. ui::runtime::shutdown();
  91. movement::shutdown();
  92. core::log::write(core::log::Channel::client, core::log::Level::info, "ev=shutdown result=ok");
  93. ReleaseSRWLockExclusive(&runtime::g_lock);
  94. return true;
  95. }
  96. } // namespace sunrise::client