Fix script patches crashing game on unload (#590)
This commit is contained in:
parent
ade733e4a0
commit
ddc70a76e0
@ -5,14 +5,14 @@ namespace big
|
|||||||
{
|
{
|
||||||
void register_script_patches()
|
void register_script_patches()
|
||||||
{
|
{
|
||||||
g_script_patcher_service.add_patch({ RAGE_JOAAT("freemode"), "2D 01 08 00 ? 38 00 5D ? ? ? 2A 06", 5, {0x6E, 0x2E, 0x01, 0x01}, &g->session.decloak_players });
|
g_script_patcher_service->add_patch({ RAGE_JOAAT("freemode"), "2D 01 08 00 ? 38 00 5D ? ? ? 2A 06", 5, {0x6E, 0x2E, 0x01, 0x01}, &g->session.decloak_players });
|
||||||
g_script_patcher_service.add_patch({ RAGE_JOAAT("freemode"), "2D 01 04 00 ? 2C ? ? ? 5D ? ? ? 6E 57 ? ? 2C", 5, { 0x2E, 0x01, 0x00 }, &g->protections.script_host_kick });
|
g_script_patcher_service->add_patch({ RAGE_JOAAT("freemode"), "2D 01 04 00 ? 2C ? ? ? 5D ? ? ? 6E 57 ? ? 2C", 5, { 0x2E, 0x01, 0x00 }, &g->protections.script_host_kick });
|
||||||
g_script_patcher_service.add_patch({ RAGE_JOAAT("freemode"), "2D 01 09 00 00 5D ? ? ? 56 ? ? 2E", 5, { 0x2E, 0x01, 0x00 }, nullptr }); // disable death when undermap/spectating
|
g_script_patcher_service->add_patch({ RAGE_JOAAT("freemode"), "2D 01 09 00 00 5D ? ? ? 56 ? ? 2E", 5, { 0x2E, 0x01, 0x00 }, nullptr }); // disable death when undermap/spectating
|
||||||
|
|
||||||
for (auto& entry : *g_pointers->m_script_program_table)
|
for (auto& entry : *g_pointers->m_script_program_table)
|
||||||
{
|
{
|
||||||
if (entry.m_program)
|
if (entry.m_program)
|
||||||
g_script_patcher_service.on_script_load(entry.m_program);
|
g_script_patcher_service->on_script_load(entry.m_program);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ namespace big
|
|||||||
{
|
{
|
||||||
g_fiber_pool->queue_job([]
|
g_fiber_pool->queue_job([]
|
||||||
{
|
{
|
||||||
g_script_patcher_service.update();
|
g_script_patcher_service->update();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ namespace big
|
|||||||
bool hooks::init_native_tables(rage::scrProgram* program)
|
bool hooks::init_native_tables(rage::scrProgram* program)
|
||||||
{
|
{
|
||||||
bool ret = g_hooking->get_original<hooks::init_native_tables>()(program);
|
bool ret = g_hooking->get_original<hooks::init_native_tables>()(program);
|
||||||
g_script_patcher_service.on_script_load(program);
|
g_script_patcher_service->on_script_load(program);
|
||||||
g_native_hooks->hook_program(program);
|
g_native_hooks->hook_program(program);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -9,7 +9,7 @@ namespace big
|
|||||||
{
|
{
|
||||||
uint8_t** orig_bytecode = program->m_code_blocks;
|
uint8_t** orig_bytecode = program->m_code_blocks;
|
||||||
|
|
||||||
if (auto bytecode = g_script_patcher_service.get_script_bytecode(program->m_name_hash))
|
if (auto bytecode = g_script_patcher_service->get_script_bytecode(program->m_name_hash); bytecode && g_running)
|
||||||
program->m_code_blocks = bytecode;
|
program->m_code_blocks = bytecode;
|
||||||
|
|
||||||
auto ret = g_hooking->get_original<hooks::script_vm>()(start_stack, scr_globals, program, ctx);
|
auto ret = g_hooking->get_original<hooks::script_vm>()(start_stack, scr_globals, program, ctx);
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "services/notifications/notification_service.hpp"
|
#include "services/notifications/notification_service.hpp"
|
||||||
#include "services/model_preview/model_preview_service.hpp"
|
#include "services/model_preview/model_preview_service.hpp"
|
||||||
#include "services/vehicle/handling_service.hpp"
|
#include "services/vehicle/handling_service.hpp"
|
||||||
|
#include "services/script_patcher/script_patcher_service.hpp"
|
||||||
|
|
||||||
BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
||||||
{
|
{
|
||||||
@ -84,6 +85,7 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
|||||||
auto model_preview_service_instance = std::make_unique<model_preview_service>();
|
auto model_preview_service_instance = std::make_unique<model_preview_service>();
|
||||||
auto handling_service_instance = std::make_unique<handling_service>();
|
auto handling_service_instance = std::make_unique<handling_service>();
|
||||||
auto gui_service_instance = std::make_unique<gui_service>();
|
auto gui_service_instance = std::make_unique<gui_service>();
|
||||||
|
auto script_patcher_service_instance = std::make_unique<script_patcher_service>();
|
||||||
LOG(INFO) << "Registered service instances...";
|
LOG(INFO) << "Registered service instances...";
|
||||||
|
|
||||||
g_script_mgr.add_script(std::make_unique<script>(&gui::script_func, "GUI", false));
|
g_script_mgr.add_script(std::make_unique<script>(&gui::script_func, "GUI", false));
|
||||||
@ -131,6 +133,8 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
|
|||||||
thread_pool_instance.reset();
|
thread_pool_instance.reset();
|
||||||
LOG(INFO) << "Thread pool uninitialized.";
|
LOG(INFO) << "Thread pool uninitialized.";
|
||||||
|
|
||||||
|
script_patcher_service_instance.reset();
|
||||||
|
LOG(INFO) << "Script patcher service reset.";
|
||||||
gui_service_instance.reset();
|
gui_service_instance.reset();
|
||||||
LOG(INFO) << "Gui Service reset.";
|
LOG(INFO) << "Gui Service reset.";
|
||||||
gta_data_service_instance.reset();
|
gta_data_service_instance.reset();
|
||||||
|
@ -34,6 +34,7 @@ namespace big
|
|||||||
|
|
||||||
native_hooks::~native_hooks()
|
native_hooks::~native_hooks()
|
||||||
{
|
{
|
||||||
|
m_script_hooks.clear();
|
||||||
g_native_hooks = nullptr;
|
g_native_hooks = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,16 @@ namespace big
|
|||||||
p.update(data);
|
p.update(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
script_patcher_service::script_patcher_service()
|
||||||
|
{
|
||||||
|
g_script_patcher_service = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
script_patcher_service::~script_patcher_service()
|
||||||
|
{
|
||||||
|
g_script_patcher_service = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void script_patcher_service::add_patch(script_patch&& patch)
|
void script_patcher_service::add_patch(script_patch&& patch)
|
||||||
{
|
{
|
||||||
m_script_patches.push_back(std::move(patch));
|
m_script_patches.push_back(std::move(patch));
|
||||||
|
@ -16,11 +16,14 @@ namespace big
|
|||||||
void update_all_patches_for_script(rage::joaat_t script);
|
void update_all_patches_for_script(rage::joaat_t script);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
script_patcher_service();
|
||||||
|
~script_patcher_service();
|
||||||
|
|
||||||
void add_patch(script_patch&& patch);
|
void add_patch(script_patch&& patch);
|
||||||
void on_script_load(rage::scrProgram* program);
|
void on_script_load(rage::scrProgram* program);
|
||||||
std::uint8_t** get_script_bytecode(rage::joaat_t script);
|
std::uint8_t** get_script_bytecode(rage::joaat_t script);
|
||||||
void update();
|
void update();
|
||||||
};
|
};
|
||||||
|
|
||||||
inline script_patcher_service g_script_patcher_service;
|
inline script_patcher_service* g_script_patcher_service;
|
||||||
}
|
}
|
Reference in New Issue
Block a user