Cleanup scripting

This commit is contained in:
Maurice Heumann 2021-05-01 14:58:34 +02:00
parent 0476eb9269
commit 56c522274c
3 changed files with 68 additions and 66 deletions

View File

@ -62,7 +62,8 @@ 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 std::string _hitLoc = reinterpret_cast<const char**>(0x1409B5400)[hitLoc];
const auto _mod = convert_mod(meansOfDeath); const auto _mod = convert_mod(meansOfDeath);
@ -93,12 +94,14 @@ namespace logfile
{ {
return; 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 std::string _hitLoc = reinterpret_cast<const char**>(0x1409B5400)[hitLoc];
const auto _mod = convert_mod(meansOfDeath); const auto _mod = convert_mod(meansOfDeath);
@ -130,11 +133,12 @@ namespace logfile
{ {
return; 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}; const scripting::entity level{*game::levelEntityId};
scripting::notify(level, "shutdownGame_called", {1}); scripting::notify(level, "shutdownGame_called", {1});
}
// G_ShutdownGame // G_ShutdownGame
return reinterpret_cast<void(*)(int)>(0x1402F8C10)(freeScripts); return reinterpret_cast<void(*)(int)>(0x1402F8C10)(freeScripts);

View File

@ -58,11 +58,8 @@ 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);
} }
} }

View File

@ -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())