diff --git a/src/client/component/logfile.cpp b/src/client/component/logfile.cpp index 46fc4ee..200178a 100644 --- a/src/client/component/logfile.cpp +++ b/src/client/component/logfile.cpp @@ -62,79 +62,83 @@ namespace logfile } void scr_player_killed_stub(game::mp::gentity_s* self, const game::mp::gentity_s* inflictor, game::mp::gentity_s* attacker, int damage, - int meansOfDeath, const unsigned int weapon, bool isAlternate, const float* vDir, const unsigned int hitLoc, int psTimeOffset, int deathAnimDuration) + const int meansOfDeath, const unsigned int weapon, const bool isAlternate, const float* vDir, const unsigned int hitLoc, int psTimeOffset, int deathAnimDuration) { - const std::string _hitLoc = reinterpret_cast(0x1409B5400)[hitLoc]; - const auto _mod = convert_mod(meansOfDeath); - - const auto _weapon = get_weapon_name(weapon, isAlternate); - - for (const auto& callback : player_killed_callbacks) { - const auto state = callback.lua_state(); + const std::string _hitLoc = reinterpret_cast(0x1409B5400)[hitLoc]; + const auto _mod = convert_mod(meansOfDeath); - const auto _self = convert_entity(state, self); - const auto _inflictor = convert_entity(state, inflictor); - const auto _attacker = convert_entity(state, attacker); + const auto _weapon = get_weapon_name(weapon, isAlternate); - const auto _vDir = convert_vector(state, vDir); - - const auto result = callback(_self, _inflictor, _attacker, damage, _mod, _weapon, _vDir, _hitLoc, psTimeOffset, deathAnimDuration); - - scripting::lua::handle_error(result); - - if (result.valid() && result.get_type() == sol::type::number) + for (const auto& callback : player_killed_callbacks) { - damage = result.get(); - } - } + const auto state = callback.lua_state(); - if (damage == 0) - { - return; + const auto _self = convert_entity(state, self); + const auto _inflictor = convert_entity(state, inflictor); + const auto _attacker = convert_entity(state, attacker); + + const auto _vDir = convert_vector(state, vDir); + + const auto result = callback(_self, _inflictor, _attacker, damage, _mod, _weapon, _vDir, _hitLoc, psTimeOffset, deathAnimDuration); + + scripting::lua::handle_error(result); + + if (result.valid() && result.get_type() == sol::type::number) + { + damage = result.get(); + } + } + + if (damage == 0) + { + return; + } } scr_player_killed_hook.invoke(self, inflictor, attacker, damage, meansOfDeath, weapon, isAlternate, vDir, hitLoc, psTimeOffset, deathAnimDuration); } void scr_player_damage_stub(game::mp::gentity_s* self, const game::mp::gentity_s* inflictor, game::mp::gentity_s* attacker, int damage, int dflags, - int meansOfDeath, const unsigned int weapon, bool isAlternate, const float* vPoint, const float* vDir, const unsigned int hitLoc, int timeOffset) + const int meansOfDeath, const unsigned int weapon, const bool isAlternate, const float* vPoint, const float* vDir, const unsigned int hitLoc, const int timeOffset) { - const std::string _hitLoc = reinterpret_cast(0x1409B5400)[hitLoc]; - const auto _mod = convert_mod(meansOfDeath); - - const auto _weapon = get_weapon_name(weapon, isAlternate); - - for (const auto& callback : player_damage_callbacks) { - const auto state = callback.lua_state(); + const std::string _hitLoc = reinterpret_cast(0x1409B5400)[hitLoc]; + const auto _mod = convert_mod(meansOfDeath); - const auto _self = convert_entity(state, self); - const auto _inflictor = convert_entity(state, inflictor); - const auto _attacker = convert_entity(state, attacker); + const auto _weapon = get_weapon_name(weapon, isAlternate); - const auto _vPoint = convert_vector(state, vPoint); - const auto _vDir = convert_vector(state, vDir); - - const auto result = callback(_self, _inflictor, _attacker, damage, dflags, _mod, _weapon, _vPoint, _vDir, _hitLoc); - - scripting::lua::handle_error(result); - - if (result.valid() && result.get_type() == sol::type::number) + for (const auto& callback : player_damage_callbacks) { - damage = result.get(); - } - } + const auto state = callback.lua_state(); - if (damage == 0) - { - return; + const auto _self = convert_entity(state, self); + const auto _inflictor = convert_entity(state, inflictor); + const auto _attacker = convert_entity(state, attacker); + + const auto _vPoint = convert_vector(state, vPoint); + const auto _vDir = convert_vector(state, vDir); + + const auto result = callback(_self, _inflictor, _attacker, damage, dflags, _mod, _weapon, _vPoint, _vDir, _hitLoc); + + scripting::lua::handle_error(result); + + if (result.valid() && result.get_type() == sol::type::number) + { + damage = result.get(); + } + } + + if (damage == 0) + { + return; + } } scr_player_damage_hook.invoke(self, inflictor, attacker, damage, dflags, meansOfDeath, weapon, isAlternate, vPoint, vDir, hitLoc, timeOffset); } - void client_command_stub(int clientNum) + void client_command_stub(const int clientNum) { auto self = &game::mp::g_entities[clientNum]; char cmd[1024]{}; @@ -168,10 +172,12 @@ namespace logfile return reinterpret_cast(0x1402E98F0)(clientNum); } - void g_shutdown_game_stub(int freeScripts) + void g_shutdown_game_stub(const int freeScripts) { - const scripting::entity level{*game::levelEntityId}; - scripting::notify(level, "shutdownGame_called", {1}); + { + const scripting::entity level{*game::levelEntityId}; + scripting::notify(level, "shutdownGame_called", {1}); + } // G_ShutdownGame return reinterpret_cast(0x1402F8C10)(freeScripts); diff --git a/src/client/component/scripting.cpp b/src/client/component/scripting.cpp index 5eb3baf..8277251 100644 --- a/src/client/component/scripting.cpp +++ b/src/client/component/scripting.cpp @@ -59,10 +59,7 @@ namespace scripting void g_shutdown_game_stub(const int free_scripts) { - if (!game::VirtualLobby_Loaded()) - { - lua::engine::stop(); - } + lua::engine::stop(); return g_shutdown_game_hook.invoke(free_scripts); } } diff --git a/src/client/game/scripting/lua/engine.cpp b/src/client/game/scripting/lua/engine.cpp index 8e2cbfc..29bcdfd 100644 --- a/src/client/game/scripting/lua/engine.cpp +++ b/src/client/game/scripting/lua/engine.cpp @@ -32,12 +32,18 @@ namespace scripting::lua::engine { if (std::filesystem::is_directory(script) && utils::io::file_exists(script + "/__init__.lua")) { - get_scripts().push_back(std::make_unique(script)); + get_scripts().emplace_back(std::make_unique(script)); } } } } + void stop() + { + logfile::clear_callbacks(); + get_scripts().clear(); + } + void start() { // No SP until there is a concept @@ -46,17 +52,10 @@ namespace scripting::lua::engine return; } - clear_custom_fields(); - get_scripts().clear(); + stop(); load_scripts(); } - void stop() - { - logfile::clear_callbacks(); - get_scripts().clear(); - } - void notify(const event& e) { for (auto& script : get_scripts())