2019-07-25 21:21:03 +00:00
|
|
|
#include "Base_Hook.h"
|
|
|
|
|
2019-08-14 13:09:57 +00:00
|
|
|
#ifndef NO_OVERLAY
|
|
|
|
|
2019-07-25 21:21:03 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include "Hook_Manager.h"
|
|
|
|
|
|
|
|
#include "../detours/detours.h"
|
|
|
|
|
2019-08-18 14:19:28 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#define VC_EXTRALEAN
|
|
|
|
#include <Windows.h>
|
|
|
|
|
2019-08-16 08:28:23 +00:00
|
|
|
Base_Hook::Base_Hook():
|
2019-08-27 13:38:07 +00:00
|
|
|
_library(nullptr)
|
2019-08-16 08:28:23 +00:00
|
|
|
{}
|
|
|
|
|
2019-07-25 21:21:03 +00:00
|
|
|
Base_Hook::~Base_Hook()
|
|
|
|
{
|
|
|
|
UnhookAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Base_Hook::BeginHook()
|
|
|
|
{
|
|
|
|
DetourTransactionBegin();
|
|
|
|
DetourUpdateThread(GetCurrentThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Base_Hook::EndHook()
|
|
|
|
{
|
|
|
|
DetourTransactionCommit();
|
|
|
|
}
|
|
|
|
|
|
|
|
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-26 14:38:01 +00:00
|
|
|
const char* Base_Hook::get_lib_name() const
|
|
|
|
{
|
|
|
|
return "<no_name>";
|
|
|
|
}
|
|
|
|
|
2019-08-01 15:04:49 +00:00
|
|
|
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
|
2019-07-25 21:21:03 +00:00
|
|
|
{
|
2019-07-31 20:20:27 +00:00
|
|
|
if( DetourAttach(hook.first, hook.second) == 0 )
|
|
|
|
_hooked_funcs.emplace_back(hook);
|
2019-08-14 13:09:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif//NO_OVERLAY
|