Clear gsc hooks when scripts are freed + fixes

This commit is contained in:
fed 2022-09-19 18:33:51 +02:00
parent 2166df1e8f
commit ac9340fe3e
3 changed files with 26 additions and 4 deletions

View File

@ -92,7 +92,7 @@ namespace loadscreen
void draw_loadscreen_title()
{
auto x = -20.f;
auto y = 290.f;
auto y = 288.f;
auto h = 24.f;
auto w = 0.f;

View File

@ -7,6 +7,7 @@
#include "game/scripting/lua/value_conversion.hpp"
#include "game/scripting/lua/error.hpp"
#include "notifies.hpp"
#include "scripting.hpp"
#include <utils/hook.hpp>
@ -199,7 +200,18 @@ namespace notifies
void clear_callbacks()
{
vm_execute_hooks.clear();
for (auto i = vm_execute_hooks.begin(); i != vm_execute_hooks.end();)
{
if (i->second.is_lua_hook)
{
i = vm_execute_hooks.erase(i);
}
else
{
++i;
}
}
entity_damage_callbacks.clear();
}
@ -237,6 +249,14 @@ namespace notifies
utils::hook::jump(0x1405C90A5, utils::hook::assemble(vm_execute_stub), true);
scr_entity_damage_hook.create(0x1404BD2E0, scr_entity_damage_stub);
scripting::on_shutdown([](bool free_scripts)
{
if (free_scripts)
{
vm_execute_hooks.clear();
}
});
}
};
}

View File

@ -197,7 +197,8 @@ namespace scripting
template <>
bool script_value::is<const char*>() const
{
return this->get_raw().type == game::SCRIPT_STRING;
const auto type = this->get_raw().type;
return type == game::SCRIPT_STRING || type == game::SCRIPT_ISTRING;
}
template <>
@ -215,7 +216,8 @@ namespace scripting
template <>
std::string script_value::get() const
{
return this->get<const char*>();
const auto localized = this->get_raw().type == game::SCRIPT_ISTRING;
return (localized ? "&"s : ""s) + this->get<const char*>();
}
/***************************************************************