2019-03-21 20:18:31 +01:00
|
|
|
#include "vmt_hook.hpp"
|
|
|
|
|
2023-03-01 21:27:15 +00:00
|
|
|
#include "common.hpp"
|
|
|
|
|
2019-03-21 20:18:31 +01:00
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
vmt_hook::vmt_hook(void* obj, std::size_t num_funcs) :
|
2023-03-01 21:27:15 +00:00
|
|
|
m_object(static_cast<void***>(obj)),
|
|
|
|
m_num_funcs(num_funcs),
|
|
|
|
m_original_table(*m_object),
|
|
|
|
m_new_table(std::make_unique<void*[]>(m_num_funcs))
|
2019-03-21 20:18:31 +01:00
|
|
|
{
|
2022-11-24 21:49:05 +00:00
|
|
|
std::copy_n(m_original_table, m_num_funcs, m_new_table.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
vmt_hook::~vmt_hook()
|
|
|
|
{
|
|
|
|
disable();
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void vmt_hook::hook(std::size_t index, void* func)
|
|
|
|
{
|
2022-11-24 21:49:05 +00:00
|
|
|
m_new_table[index] = func;
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void vmt_hook::unhook(std::size_t index)
|
|
|
|
{
|
2022-11-24 21:49:05 +00:00
|
|
|
m_new_table[index] = m_original_table[index];
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void vmt_hook::enable()
|
|
|
|
{
|
2022-11-24 21:49:05 +00:00
|
|
|
*m_object = m_new_table.get();
|
2019-03-21 20:18:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void vmt_hook::disable()
|
|
|
|
{
|
|
|
|
*m_object = m_original_table;
|
|
|
|
}
|
|
|
|
}
|