2022-11-12 18:35:28 +00:00
|
|
|
#include "hooking.hpp"
|
|
|
|
#include <script/scrProgram.hpp>
|
|
|
|
|
|
|
|
#include "services/script_patcher/script_patcher_service.hpp"
|
|
|
|
|
2023-02-13 20:38:30 +00:00
|
|
|
#include "pointers.hpp"
|
|
|
|
#include "core/scr_globals.hpp"
|
|
|
|
#include <script/globals/GlobalPlayerBD.hpp>
|
|
|
|
|
|
|
|
static int old_cayo_flags;
|
|
|
|
static int old_shop_index;
|
|
|
|
|
2022-11-12 18:35:28 +00:00
|
|
|
namespace big
|
|
|
|
{
|
2022-11-24 21:49:05 +00:00
|
|
|
class script_vm_guard
|
2022-11-12 18:35:28 +00:00
|
|
|
{
|
2022-11-24 21:49:05 +00:00
|
|
|
rage::scrProgram* m_program;
|
|
|
|
uint8_t** m_orig_bytecode;
|
|
|
|
|
|
|
|
public:
|
|
|
|
script_vm_guard(rage::scrProgram* program)
|
|
|
|
: m_program(program)
|
|
|
|
{
|
|
|
|
m_orig_bytecode = program->m_code_blocks;
|
2022-11-12 18:35:28 +00:00
|
|
|
|
2022-11-24 21:49:05 +00:00
|
|
|
if (auto bytecode = g_script_patcher_service->get_script_bytecode(program->m_name_hash))
|
|
|
|
program->m_code_blocks = bytecode;
|
2023-02-13 20:38:30 +00:00
|
|
|
|
|
|
|
if (g_pointers->m_script_globals[0xA])
|
|
|
|
{
|
|
|
|
scr_globals::globalplayer_bd.as<GlobalPlayerBD*>()->Entries[self::id].CurrentShopIndex = old_shop_index;
|
|
|
|
scr_globals::globalplayer_bd.as<GlobalPlayerBD*>()->Entries[self::id].CayoPericoFlags = old_cayo_flags;
|
|
|
|
}
|
2022-11-24 21:49:05 +00:00
|
|
|
}
|
2022-11-12 18:35:28 +00:00
|
|
|
|
2022-11-24 21:49:05 +00:00
|
|
|
~script_vm_guard()
|
|
|
|
{
|
|
|
|
m_program->m_code_blocks = m_orig_bytecode;
|
2023-02-13 20:38:30 +00:00
|
|
|
|
|
|
|
if (g_pointers->m_script_globals[0xA])
|
|
|
|
{
|
|
|
|
old_shop_index = scr_globals::globalplayer_bd.as<GlobalPlayerBD*>()->Entries[self::id].CurrentShopIndex;
|
|
|
|
old_cayo_flags = scr_globals::globalplayer_bd.as<GlobalPlayerBD*>()->Entries[self::id].CayoPericoFlags;
|
|
|
|
|
|
|
|
if (g.spoofing.hide_from_player_list)
|
|
|
|
{
|
|
|
|
scr_globals::globalplayer_bd.as<GlobalPlayerBD*>()->Entries[self::id].CurrentShopIndex = -1;
|
|
|
|
scr_globals::globalplayer_bd.as<GlobalPlayerBD*>()->Entries[self::id].CayoPericoFlags = 1;
|
|
|
|
}
|
|
|
|
}
|
2022-11-24 21:49:05 +00:00
|
|
|
}
|
|
|
|
};
|
2022-11-12 18:35:28 +00:00
|
|
|
|
2022-11-24 21:49:05 +00:00
|
|
|
rage::eThreadState hooks::script_vm(uint64_t* start_stack, uint64_t** scr_globals, rage::scrProgram* program, rage::scrThreadContext* ctx)
|
|
|
|
{
|
|
|
|
script_vm_guard guard(program);
|
|
|
|
return g_hooking->get_original<hooks::script_vm>()(start_stack, scr_globals, program, ctx);
|
2022-11-12 18:35:28 +00:00
|
|
|
}
|
|
|
|
}
|