1
0
Fork 0
mirror of https://gitlab.com/Mr_Goldberg/goldberg_emulator.git synced 2024-11-14 10:50:13 +01:00
goldberg_emulator/overlay_experimental/Base_Hook.cpp

89 lines
1.3 KiB
C++
Raw Normal View History

#include "Base_Hook.h"
2019-08-27 16:29:20 +02:00
#include "Hook_Manager.h"
#include <algorithm>
#ifdef EMU_OVERLAY
2019-08-31 20:49:46 +02:00
#ifdef STEAM_WIN32
2019-08-16 10:28:23 +02:00
2019-08-31 20:49:46 +02:00
#include "../detours/detours.h"
2019-09-01 20:53:16 +02:00
Base_Hook::Base_Hook():
_library(nullptr)
{}
Base_Hook::~Base_Hook()
2019-08-31 20:49:46 +02:00
{
2019-09-01 20:53:16 +02:00
UnhookAll();
2019-08-31 20:49:46 +02:00
}
2019-09-01 20:53:16 +02:00
const char* Base_Hook::get_lib_name() const
{
2019-09-01 20:53:16 +02:00
return "<no_name>";
}
2019-08-31 20:49:46 +02:00
void Base_Hook::BeginHook()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
2019-08-31 20:49:46 +02:00
}
void Base_Hook::EndHook()
{
DetourTransactionCommit();
}
2019-08-01 17:04:49 +02:00
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
{
if( DetourAttach(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) {
DetourDetach(hook.first, hook.second);
2019-08-31 20:49:46 +02:00
});
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