From dd0f60ed489639691732d8f4dc9a10e6ae350064 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Tue, 21 Jun 2022 03:30:41 +0200 Subject: [PATCH] Add scr_autoRespawn --- src/client/component/scripting.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index cd384525..8ffcd5c8 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -2,6 +2,7 @@ #include "loader/component_loader.hpp" #include "game/game.hpp" +#include "game/dvars.hpp" #include "command.hpp" #include "scheduler.hpp" @@ -35,6 +36,10 @@ namespace scripting utils::hook::detour sl_get_canonical_string_hook; + utils::hook::detour respawn_hook; + + game::dvar_t* scr_auto_respawn = nullptr; + std::string current_file; unsigned int current_file_id{}; @@ -62,6 +67,7 @@ namespace scripting void client_spawn_stub(const game::gentity_s* client) { client_spawn_hook.invoke(client); + scr_auto_respawn->current.enabled = true; lua::engine::start(); } @@ -132,6 +138,7 @@ namespace scripting const auto result = sv_check_load_level_hook.invoke(save_game); if (save_game != nullptr) { + scr_auto_respawn->current.enabled = true; lua::engine::start(); } return result; @@ -143,6 +150,16 @@ namespace scripting scripting::token_map[str] = result; return result; } + + void respawn_stub() + { + if (!scr_auto_respawn->current.enabled) + { + return; + } + + respawn_hook.invoke(); + } } class component final : public component_interface @@ -161,6 +178,9 @@ namespace scripting process_script_hook.create(0x1405C6160, process_script_stub); sl_get_canonical_string_hook.create(game::SL_GetCanonicalString, sl_get_canonical_string_stub); + scr_auto_respawn = dvars::register_bool("scr_autoRespawn", true, 0, "Automatically respawn player on death"); + respawn_hook.create(0x1404B1E00, respawn_stub); + scheduler::loop([]() { lua::engine::run_frame();