#include #include "scripting.hpp" utils::hook scripting::start_hook_; utils::hook scripting::stop_hook_; std::mutex scripting::mutex_; std::vector> scripting::start_callbacks_; std::vector> scripting::stop_callbacks_; scripting::variable::variable(game::native::VariableValue value) : value_(value) { game::native::AddRefToValue(&value); } scripting::variable::~variable() { game::native::RemoveRefToValue(this->value_.type, this->value_.u); } scripting::variable::operator game::native::VariableValue() const { return this->value_; } void scripting::post_load() { start_hook_.initialize(SELECT_VALUE(0x50C575, 0x50D4F2, 0x48A026), []() { start_execution(); static_cast(start_hook_.get_original())(); }, HOOK_CALL)->install()->quick(); stop_hook_.initialize(SELECT_VALUE(0x528B04, 0x569E46, 0x4F03FA), []() { stop_execution(); static_cast(stop_hook_.get_original())(); }, HOOK_CALL)->install()->quick(); on_start([this]() { this->chai_ = std::make_unique(); }); on_stop([this]() { this->chai_ = {}; }); } void scripting::pre_destroy() { this->chai_ = {}; start_callbacks_.clear(); stop_callbacks_.clear(); } void scripting::on_start(const std::function& callback) { std::lock_guard _(mutex_); start_callbacks_.push_back(callback); } void scripting::on_stop(const std::function& callback) { std::lock_guard _(mutex_); stop_callbacks_.push_back(callback); } void scripting::start_execution() { std::vector> copy; { std::lock_guard _(mutex_); copy = start_callbacks_; } for (const auto& callback : copy) { callback(); } } void scripting::stop_execution() { std::vector> copy; { std::lock_guard _(mutex_); copy = stop_callbacks_; } for (const auto& callback : copy) { callback(); } } REGISTER_MODULE(scripting)