Fixed a race condition with scr_patch's destructor. (#3639)

* Fixed a race condition caused by disabling and enabling a Lua script with scr_patch more than once.

* Fixed patch not being enabled if data is already created

---------

Co-authored-by: Arthur <121949966+ShinyWasabi@users.noreply.github.com>
This commit is contained in:
gir489 2024-09-02 01:52:34 -04:00 committed by GitHub
parent 707f2004ff
commit 706e6f7fc0
3 changed files with 11 additions and 7 deletions

View File

@ -27,7 +27,6 @@ namespace lua::scr_patch
scr_patch::~scr_patch()
{
disable();
big::g_script_patcher_service->remove_patch(m_patch_name);
}
@ -36,7 +35,7 @@ namespace lua::scr_patch
if (!m_enable)
{
m_enable = true;
big::g_script_patcher_service->update_all_patches_for_script(m_script);
big::g_script_patcher_service->update();
}
}
@ -45,7 +44,7 @@ namespace lua::scr_patch
if (m_enable)
{
m_enable = false;
big::g_script_patcher_service->update_all_patches_for_script(m_script);
big::g_script_patcher_service->update();
}
}

View File

@ -54,7 +54,10 @@ namespace big
{
auto result = get_code_location_by_pattern(data, m_pattern);
if (!result.has_value())
{
LOG(FATAL) << "Failed to find pattern: " << m_name;
return;
}
m_ip = result.value() + m_offset;

View File

@ -87,11 +87,13 @@ namespace big
void script_patcher_service::on_script_load(rage::scrProgram* program)
{
if (get_data_for_script(program->m_name_hash) == nullptr && does_script_have_patches(program->m_name_hash))
{
if (!does_script_have_patches(program->m_name_hash))
return;
if (get_data_for_script(program->m_name_hash) == nullptr)
create_data_for_script(program);
update_all_patches_for_script(program->m_name_hash);
}
update_all_patches_for_script(program->m_name_hash);
}
uint8_t** script_patcher_service::get_script_bytecode(rage::joaat_t script)