91 lines
1.7 KiB
C++
Raw Normal View History

#include "Base_Hook.h"
2019-08-27 16:29:20 +02:00
#include "Hook_Manager.h"
#include <algorithm>
2019-08-31 20:49:46 +02:00
#ifndef NO_OVERLAY
#ifdef STEAM_WIN32
2019-08-16 10:28:23 +02:00
2019-08-31 20:49:46 +02:00
#include "../detours/detours.h"
void Base_Hook::BeginHook()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
}
void Base_Hook::EndHook()
{
DetourTransactionCommit();
}
2019-08-31 20:49:46 +02:00
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
{
if( DetourAttach(hook.first, hook.second) == 0 )
_hooked_funcs.emplace_back(hook);
}
void Base_Hook::UnhookAll()
{
if (_hooked_funcs.size())
{
BeginHook();
std::for_each(_hooked_funcs.begin(), _hooked_funcs.end(), [](std::pair<void**, void*>& hook) {
DetourDetach(hook.first, hook.second);
});
EndHook();
_hooked_funcs.clear();
}
}
2019-08-31 20:49:46 +02:00
#else
#include "Linux_Detour.h"
void Base_Hook::BeginHook()
{
2019-08-31 20:49:46 +02:00
Linux_Detour::transaction_begin();
Linux_Detour::update_thread(pthread_self());
}
void Base_Hook::EndHook()
{
Linux_Detour::transaction_commit();
}
2019-08-01 17:04:49 +02:00
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
{
2019-08-31 20:49:46 +02:00
if( Linux_Detour::hook_func(hook.first, hook.second) == 0 )
2019-07-31 22:20:27 +02:00
_hooked_funcs.emplace_back(hook);
}
2019-08-31 20:49:46 +02:00
void Base_Hook::UnhookAll()
{
if (_hooked_funcs.size())
{
BeginHook();
std::for_each(_hooked_funcs.begin(), _hooked_funcs.end(), [](std::pair<void**, void*>& hook) {
Linux_Detour::unhook_func(hook.first, hook.second);
});
EndHook();
_hooked_funcs.clear();
}
}
#endif
Base_Hook::Base_Hook():
_library(nullptr)
{}
Base_Hook::~Base_Hook()
{
UnhookAll();
}
const char* Base_Hook::get_lib_name() const
{
return "<no_name>";
}
#endif//NO_OVERLAY