gbe_fork/overlay_experimental/Base_Hook.cpp
Nemirtingas 44d583ee7d Added class Renderer_Detector.
Hook_Manager now only manages hooks.
Renderer_Detector is used to detect the game's renderer. There will be 2 version of it. 1 for windows and 1 for Linux.
2019-08-27 15:38:07 +02:00

58 lines
1.0 KiB
C++

#include "Base_Hook.h"
#ifndef NO_OVERLAY
#include <algorithm>
#include "Hook_Manager.h"
#include "../detours/detours.h"
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN
#include <Windows.h>
Base_Hook::Base_Hook():
_library(nullptr)
{}
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();
}
}
const char* Base_Hook::get_lib_name() const
{
return "<no_name>";
}
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
{
if( DetourAttach(hook.first, hook.second) == 0 )
_hooked_funcs.emplace_back(hook);
}
#endif//NO_OVERLAY