// SPDX-License-Identifier: GPL-3.0-only #pragma once #include "app/session.hpp" namespace bmh::app::detail { template bool apply_window(CareerSession& session, uint64_t& revision, Checkpoint before, Restore restore_checkpoint, const std::function& action) { const auto game = session.game(); const auto rand = session.rand(); const auto old_revision = revision; const auto restore = [&] { session.game() = game; session.rand() = rand; // Some owners reconstruct their saved RNG identity during restore. restore_checkpoint(std::move(before)); revision = old_revision; }; try { if (action()) return true; } catch (...) { restore(); throw; } restore(); return false; } inline bool apply_native(CareerSession& session, uint64_t& revision, const std::function& action) { return apply_window(session, revision, session.state(), // the whole session state (the Modern one carries more than GameState) [&](SessionState before) { session.state() = std::move(before); }, action); } } // namespace bmh::app::detail