From ba4fc58d1481fb53ae997ea2f0e32e66081e9e5a Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Sun, 18 Dec 2022 04:15:25 +0100 Subject: [PATCH] Scripting fix --- src/client/component/scripting.cpp | 15 +++++++++++++++ src/client/game/scripting/execution.cpp | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index 9b8c8d62..03a1a214 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -47,6 +47,8 @@ namespace scripting utils::hook::detour scr_run_current_threads_hook; + utils::hook::detour scr_delete_hook; + game::dvar_t* scr_auto_respawn = nullptr; std::string current_scriptfile; @@ -291,6 +293,17 @@ namespace scripting } return spawn_point; } + + void scr_delete_stub(game::scr_entref_t ref) + { + if (ref.entnum == 0 && ref.classnum == 0) + { + console::warn("Script tried to delete entity 0\n"); + return; + } + + scr_delete_hook.invoke(ref); + } } std::string get_token_single(unsigned int id) @@ -341,6 +354,8 @@ namespace scripting scr_get_dvar_int_hook.create(0x1404F0730, scr_get_dvar_int_stub); + scr_delete_hook.create(0x1404F0460, scr_delete_stub); + utils::hook::call(0x1404B07D2, get_spawn_point_stub); scheduler::loop([]() diff --git a/src/client/game/scripting/execution.cpp b/src/client/game/scripting/execution.cpp index aa4dff60..1093c774 100644 --- a/src/client/game/scripting/execution.cpp +++ b/src/client/game/scripting/execution.cpp @@ -80,6 +80,12 @@ namespace scripting const std::vector& arguments) { const auto entref = entity.get_entity_reference(); + const auto ent_id = entity.get_entity_id(); + + if (!is_entity_variable(entref, ent_id)) + { + return {}; + } const auto is_method_call = *reinterpret_cast(&entref) != -1; const auto function = find_function(name, !is_method_call);