bootflow_hook_lifecycle.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "bootflow_hook_lifecycle.h"
  2. #include <atomic>
  3. #include "internal.h"
  4. #include "spawn/slice_set_sample.h"
  5. namespace sunrise::client::hooks::bootflow {
  6. namespace {
  7. std::atomic_bool g_installed{false};
  8. } // namespace
  9. /**
  10. * Finds the boot-step accessor and the slice-set sample targets, and attaches the lifetime probe.
  11. * @return True when all three are ready.
  12. */
  13. bool install() noexcept {
  14. const bool worldStep = install_world_step();
  15. const bool sliceSet = spawn::install_targets();
  16. const bool probe = install_lifetime_gate_probe();
  17. const bool characterSelectHold = install_character_select_hold();
  18. g_installed.store(worldStep || sliceSet || probe || characterSelectHold,
  19. std::memory_order_release);
  20. return worldStep && sliceSet && probe && characterSelectHold;
  21. }
  22. /** Detaches the probe and clears both accessors, in the reverse order of install. */
  23. void uninstall() noexcept {
  24. uninstall_character_select_hold();
  25. uninstall_lifetime_gate_probe();
  26. spawn::uninstall_targets();
  27. uninstall_world_step();
  28. g_installed.store(false, std::memory_order_release);
  29. }
  30. /** @return True while at least one accessor or the probe is installed. */
  31. bool is_installed() noexcept {
  32. return g_installed.load(std::memory_order_acquire);
  33. }
  34. } // namespace sunrise::client::hooks::bootflow