This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/vtable_hook.cpp
maybegreat48 5eead0436f
Huge protection improvements and other stuff (#1963)
* feat(protections): add a fuzzer
* feat(protections): improve protections
* feat(spoofing): add warning
* feat(world): force object cleanup
* fix(weapons): fix custom weapon code
* fix(weapons): fix for #1983
2023-08-19 13:01:08 +02:00

40 lines
889 B
C++

#include "vtable_hook.hpp"
namespace big
{
vtable_hook::vtable_hook(void** vft, std::size_t num_funcs) :
m_num_funcs(num_funcs),
m_table(vft),
m_backup_table(std::make_unique<void*[]>(m_num_funcs)),
m_hook_table(std::make_unique<void*[]>(m_num_funcs))
{
std::memcpy(m_backup_table.get(), m_table, m_num_funcs * sizeof(void*));
std::memcpy(m_hook_table.get(), m_table, m_num_funcs * sizeof(void*));
}
vtable_hook::~vtable_hook()
{
disable();
}
void vtable_hook::hook(std::size_t index, void* func)
{
m_hook_table[index] = func;
}
void vtable_hook::unhook(std::size_t index)
{
m_hook_table[index] = m_backup_table[index];
}
void vtable_hook::enable()
{
std::memcpy(m_table, m_hook_table.get(), m_num_funcs * sizeof(void*));
}
void vtable_hook::disable()
{
std::memcpy(m_table, m_backup_table.get(), m_num_funcs * sizeof(void*));
}
}