gbe_fork/overlay_experimental/Base_Hook.cpp
Mr_Goldberg db2a803cf7
A few improvements to the overlay merge request.
NO_OVERLAY define becomes EMU_OVERLAY which enables the overlay instead of disabling it.

disable_overlay.txt moved to steam_settings.
2020-01-19 12:55:14 -05:00

89 lines
1.3 KiB
C++

#include "Base_Hook.h"
#include "Hook_Manager.h"
#include <algorithm>
#ifdef EMU_OVERLAY
#ifdef STEAM_WIN32
#include "../detours/detours.h"
Base_Hook::Base_Hook():
_library(nullptr)
{}
Base_Hook::~Base_Hook()
{
UnhookAll();
}
const char* Base_Hook::get_lib_name() const
{
return "<no_name>";
}
void Base_Hook::BeginHook()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
}
void Base_Hook::EndHook()
{
DetourTransactionCommit();
}
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();
}
}
#else
Base_Hook::Base_Hook():
_library(nullptr)
{}
Base_Hook::~Base_Hook()
{
}
const char* Base_Hook::get_lib_name() const
{
return "<no_name>";
}
void Base_Hook::BeginHook()
{
}
void Base_Hook::EndHook()
{
}
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
{
}
void Base_Hook::UnhookAll()
{
}
#endif
#endif//EMU_OVERLAY