client_runtime_lifecycle.cpp 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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/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 "../targets/game.h"
  16. #include "../targets/steam_targets.h"
  17. #include "../teleport/teleport_settings_store.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 teleport page draws saved values on its first frame.
  25. teleport::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. // Detached before the other game hooks because each fix is a plain one-site detour with
  49. // no shared target state to hand back.
  50. hooks::banner::uninstall();
  51. hooks::bitmap::uninstall();
  52. hooks::bootflow::uninstall();
  53. hooks::teleport::uninstall();
  54. hooks::queuez::uninstall();
  55. if (!hooks::config_getter::uninstall()) {
  56. ReleaseSRWLockExclusive(&runtime::g_lock);
  57. return false;
  58. }
  59. if (!hooks::assert_handler::uninstall()) {
  60. ReleaseSRWLockExclusive(&runtime::g_lock);
  61. return false;
  62. }
  63. if (!hooks::retail_log::uninstall()) {
  64. core::log::write(core::log::Channel::client,
  65. core::log::Level::error,
  66. "ev=shutdown stage=retail_log result=fail");
  67. ReleaseSRWLockExclusive(&runtime::g_lock);
  68. return false;
  69. }
  70. content::investment::worker::reset();
  71. targets::steam::clear();
  72. if (runtime::g_platformModule != nullptr) {
  73. if (FreeLibrary(runtime::g_platformModule) == FALSE) {
  74. core::log::write(core::log::Channel::client,
  75. core::log::Level::error,
  76. "ev=shutdown stage=steam_module result=fail");
  77. ReleaseSRWLockExclusive(&runtime::g_lock);
  78. return false;
  79. }
  80. runtime::g_platformModule = nullptr;
  81. }
  82. targets::game::retail_log::clear();
  83. targets::game::content::clear();
  84. targets::game::network::clear();
  85. runtime::g_mainStage = runtime::StageState::pending;
  86. runtime::g_graphicsStage = runtime::StageState::pending;
  87. runtime::g_platformStage = runtime::StageState::pending;
  88. ui::runtime::shutdown();
  89. teleport::shutdown();
  90. core::log::write(core::log::Channel::client, core::log::Level::info, "ev=shutdown result=ok");
  91. ReleaseSRWLockExclusive(&runtime::g_lock);
  92. return true;
  93. }
  94. } // namespace sunrise::client