From d44a55dc11a99c533b18730665a5a9d7c055c529 Mon Sep 17 00:00:00 2001 From: Federico Cecchetto Date: Sat, 18 Sep 2021 18:29:03 +0200 Subject: [PATCH] Nevermind --- src/client/component/scripting.cpp | 16 +++++----------- src/client/game/scripting/lua/context.cpp | 1 + 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index e9945e3d..ed04e863 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -9,6 +9,7 @@ #include "game/scripting/event.hpp" #include "game/scripting/functions.hpp" +#include "game/scripting/execution.hpp" #include "game/scripting/lua/engine.hpp" #include @@ -22,8 +23,8 @@ namespace scripting { utils::hook::detour vm_notify_hook; - utils::hook::detour scr_load_level_hook; utils::hook::detour g_shutdown_game_hook; + utils::hook::detour player_spawn_hook; utils::hook::detour scr_add_class_field_hook; @@ -53,22 +54,16 @@ namespace scripting vm_notify_hook.invoke(notify_list_owner_id, string_value, top); } - void scr_load_level_stub() + void player_spawn_stub(const game::gentity_s* player) { - scr_load_level_hook.invoke(); command::execute("reloadmenus"); + player_spawn_hook.invoke(player); lua::engine::start(); } void g_shutdown_game_stub(const int free_scripts) { lua::engine::stop(); - - if (!free_scripts) - { - lua::engine::start(); - } - g_shutdown_game_hook.invoke(free_scripts); } @@ -101,7 +96,6 @@ namespace scripting { const auto function_name = scripting::find_token(threadName); script_function_table[current_file][function_name] = codePos; - scr_set_thread_position_hook.invoke(threadName, codePos); } } @@ -113,8 +107,8 @@ namespace scripting { vm_notify_hook.create(game::base_address + 0x5CC450, vm_notify_stub); - scr_load_level_hook.create(game::base_address + 0x4C7EB0, scr_load_level_stub); g_shutdown_game_hook.create(game::base_address + 0x4CBAD0, g_shutdown_game_stub); + player_spawn_hook.create(game::base_address + 0x4B0710, player_spawn_stub); scr_add_class_field_hook.create(game::base_address + 0x5C2C30, scr_add_class_field_stub); scr_set_thread_position_hook.create(game::base_address + 0x5BC7E0, scr_set_thread_position_stub); diff --git a/src/client/game/scripting/lua/context.cpp b/src/client/game/scripting/lua/context.cpp index c3badd6c..88f4c214 100644 --- a/src/client/game/scripting/lua/context.cpp +++ b/src/client/game/scripting/lua/context.cpp @@ -32,6 +32,7 @@ namespace scripting::lua void setup_entity_type(sol::state& state, event_handler& handler, scheduler& scheduler) { state["level"] = entity{*game::levelEntityId}; + state["player"] = call("getentbynum", {0}).as(); state["io"]["fileexists"] = utils::io::file_exists; state["io"]["writefile"] = utils::io::write_file;