Disables script patches from the Lua layer on eject. (#3628)

This commit is contained in:
gir489 2024-08-28 17:38:13 -04:00 committed by GitHub
parent 2519de72f6
commit a63279dde9
6 changed files with 164 additions and 135 deletions

View File

@ -25,6 +25,12 @@ namespace lua::scr_patch
module->m_registered_script_patches.push_back(std::make_unique<scr_patch>(*this));
}
scr_patch::~scr_patch()
{
disable();
big::g_script_patcher_service->remove_patch(m_patch_name);
}
void scr_patch::enable()
{
if (!m_enable)

View File

@ -2,7 +2,7 @@
namespace lua::scr_patch
{
struct scr_patch
class scr_patch
{
rage::joaat_t m_script;
std::string m_patch_name;
@ -21,6 +21,7 @@ namespace lua::scr_patch
// Param: patch_: table: The bytes to be written into the script's bytecode.
// Adds a patch for the specified script.
explicit scr_patch(const std::string& script_name, const std::string& patch_name, const std::string& pattern, const int offset, sol::table patch_, sol::this_state state);
~scr_patch();
// Lua API: Function
// Class: scr_patch

View File

@ -126,6 +126,7 @@ namespace big
{
std::lock_guard guard(m_registered_scripts_mutex);
m_registered_scripts.clear();
m_registered_script_patches.clear();
}
for (const auto owned_tab : m_owned_tabs)

View File

@ -28,6 +28,11 @@ namespace big
return m_script;
}
inline std::string get_name()
{
return m_name;
}
script_patch(rage::joaat_t script, std::string name, const memory::pattern pattern, int32_t offset, std::vector<uint8_t> patch, bool* enable_bool);
void update(script_data* data);
};

View File

@ -70,6 +70,21 @@ namespace big
m_script_patches.push_back(std::move(patch));
}
void script_patcher_service::remove_patch(std::string_view patch_name)
{
for (auto it = m_script_patches.begin(); it != m_script_patches.end();)
{
if (it->get_name() == patch_name)
{
it = m_script_patches.erase(it);
}
else
{
++it;
}
}
}
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))

View File

@ -9,7 +9,7 @@ namespace big
{
class script_patcher_service
{
std::vector<script_patch> m_script_patches;
std::list<script_patch> m_script_patches;
std::unordered_map<rage::joaat_t, std::unique_ptr<script_data>> m_script_data;
script_data* get_data_for_script(rage::joaat_t script);
bool does_script_have_patches(rage::joaat_t script);
@ -20,6 +20,7 @@ namespace big
~script_patcher_service();
void add_patch(script_patch&& patch);
void remove_patch(std::string_view patch_name);
void on_script_load(rage::scrProgram* program);
uint8_t** get_script_bytecode(rage::joaat_t script);
void update_all_patches_for_script(rage::joaat_t script);