mirror of
https://github.com/XLabsProject/s1x-client.git
synced 2023-08-02 15:02:12 +02:00
Cleanup scripting
This commit is contained in:
parent
0476eb9269
commit
56c522274c
@ -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,
|
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<const char**>(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<const char**>(0x1409B5400)[hitLoc];
|
||||||
|
const auto _mod = convert_mod(meansOfDeath);
|
||||||
|
|
||||||
const auto _self = convert_entity(state, self);
|
const auto _weapon = get_weapon_name(weapon, isAlternate);
|
||||||
const auto _inflictor = convert_entity(state, inflictor);
|
|
||||||
const auto _attacker = convert_entity(state, attacker);
|
|
||||||
|
|
||||||
const auto _vDir = convert_vector(state, vDir);
|
for (const auto& callback : player_killed_callbacks)
|
||||||
|
|
||||||
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<int>();
|
const auto state = callback.lua_state();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (damage == 0)
|
const auto _self = convert_entity(state, self);
|
||||||
{
|
const auto _inflictor = convert_entity(state, inflictor);
|
||||||
return;
|
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<int>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (damage == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scr_player_killed_hook.invoke<void>(self, inflictor, attacker, damage, meansOfDeath, weapon, isAlternate, vDir, hitLoc, psTimeOffset, deathAnimDuration);
|
scr_player_killed_hook.invoke<void>(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,
|
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<const char**>(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<const char**>(0x1409B5400)[hitLoc];
|
||||||
|
const auto _mod = convert_mod(meansOfDeath);
|
||||||
|
|
||||||
const auto _self = convert_entity(state, self);
|
const auto _weapon = get_weapon_name(weapon, isAlternate);
|
||||||
const auto _inflictor = convert_entity(state, inflictor);
|
|
||||||
const auto _attacker = convert_entity(state, attacker);
|
|
||||||
|
|
||||||
const auto _vPoint = convert_vector(state, vPoint);
|
for (const auto& callback : player_damage_callbacks)
|
||||||
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<int>();
|
const auto state = callback.lua_state();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (damage == 0)
|
const auto _self = convert_entity(state, self);
|
||||||
{
|
const auto _inflictor = convert_entity(state, inflictor);
|
||||||
return;
|
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<int>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (damage == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scr_player_damage_hook.invoke<void>(self, inflictor, attacker, damage, dflags, meansOfDeath, weapon, isAlternate, vPoint, vDir, hitLoc, timeOffset);
|
scr_player_damage_hook.invoke<void>(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];
|
auto self = &game::mp::g_entities[clientNum];
|
||||||
char cmd[1024]{};
|
char cmd[1024]{};
|
||||||
@ -168,10 +172,12 @@ namespace logfile
|
|||||||
return reinterpret_cast<void(*)(int)>(0x1402E98F0)(clientNum);
|
return reinterpret_cast<void(*)(int)>(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
|
// G_ShutdownGame
|
||||||
return reinterpret_cast<void(*)(int)>(0x1402F8C10)(freeScripts);
|
return reinterpret_cast<void(*)(int)>(0x1402F8C10)(freeScripts);
|
||||||
|
@ -59,10 +59,7 @@ namespace scripting
|
|||||||
|
|
||||||
void g_shutdown_game_stub(const int free_scripts)
|
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<void>(free_scripts);
|
return g_shutdown_game_hook.invoke<void>(free_scripts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,12 +32,18 @@ namespace scripting::lua::engine
|
|||||||
{
|
{
|
||||||
if (std::filesystem::is_directory(script) && utils::io::file_exists(script + "/__init__.lua"))
|
if (std::filesystem::is_directory(script) && utils::io::file_exists(script + "/__init__.lua"))
|
||||||
{
|
{
|
||||||
get_scripts().push_back(std::make_unique<context>(script));
|
get_scripts().emplace_back(std::make_unique<context>(script));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stop()
|
||||||
|
{
|
||||||
|
logfile::clear_callbacks();
|
||||||
|
get_scripts().clear();
|
||||||
|
}
|
||||||
|
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
// No SP until there is a concept
|
// No SP until there is a concept
|
||||||
@ -46,17 +52,10 @@ namespace scripting::lua::engine
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_custom_fields();
|
stop();
|
||||||
get_scripts().clear();
|
|
||||||
load_scripts();
|
load_scripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop()
|
|
||||||
{
|
|
||||||
logfile::clear_callbacks();
|
|
||||||
get_scripts().clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void notify(const event& e)
|
void notify(const event& e)
|
||||||
{
|
{
|
||||||
for (auto& script : get_scripts())
|
for (auto& script : get_scripts())
|
||||||
|
Loading…
Reference in New Issue
Block a user