2019-07-25 23:21:03 +02:00
|
|
|
#include "Base_Hook.h"
|
2019-08-27 16:29:20 +02:00
|
|
|
#include "Hook_Manager.h"
|
2019-07-25 23:21:03 +02:00
|
|
|
|
|
|
|
#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"
|
2019-07-25 23:21:03 +02:00
|
|
|
|
2019-09-01 20:53:16 +02:00
|
|
|
#define DETOUR_HOOKBEGIN DetourTransactionBegin
|
|
|
|
#define DETOUR_UPDATETHREAD() DetourUpdateThread(GetCurrentThread())
|
|
|
|
#define DETOUR_ENDHOOK DetourTransactionCommit
|
|
|
|
#define DETOUR_HOOK DetourAttach
|
|
|
|
#define DETOUR_UNHOOK DetourDetach
|
2019-07-25 23:21:03 +02:00
|
|
|
|
2019-09-01 20:53:16 +02:00
|
|
|
#elif defined(__LINUX__)
|
|
|
|
#include "linux/Linux_Detour.h"
|
2019-07-25 23:21:03 +02:00
|
|
|
|
2019-09-01 20:53:16 +02:00
|
|
|
#define DETOUR_HOOKBEGIN Linux_Detour::transaction_begin
|
|
|
|
#define DETOUR_UPDATETHREAD() Linux_Detour::update_thread(pthread_self())
|
|
|
|
#define DETOUR_ENDHOOK Linux_Detour::transaction_commit
|
|
|
|
#define DETOUR_HOOK Linux_Detour::hook_func
|
|
|
|
#define DETOUR_UNHOOK Linux_Detour::unhook_func
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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-07-25 23:21:03 +02:00
|
|
|
{
|
2019-09-01 20:53:16 +02:00
|
|
|
return "<no_name>";
|
2019-07-25 23:21:03 +02:00
|
|
|
}
|
|
|
|
|
2019-08-31 20:49:46 +02:00
|
|
|
void Base_Hook::BeginHook()
|
2019-08-26 16:38:01 +02:00
|
|
|
{
|
2019-09-01 20:53:16 +02:00
|
|
|
DETOUR_HOOKBEGIN();
|
|
|
|
DETOUR_UPDATETHREAD();
|
2019-08-31 20:49:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Base_Hook::EndHook()
|
|
|
|
{
|
2019-09-01 20:53:16 +02:00
|
|
|
DETOUR_ENDHOOK();
|
2019-08-26 16:38:01 +02:00
|
|
|
}
|
|
|
|
|
2019-08-01 17:04:49 +02:00
|
|
|
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
|
2019-07-25 23:21:03 +02:00
|
|
|
{
|
2019-09-01 20:53:16 +02:00
|
|
|
if( DETOUR_HOOK(hook.first, hook.second) == 0 )
|
2019-07-31 22:20:27 +02:00
|
|
|
_hooked_funcs.emplace_back(hook);
|
2019-08-14 15:09:57 +02:00
|
|
|
}
|
|
|
|
|
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) {
|
2019-09-01 20:53:16 +02:00
|
|
|
DETOUR_UNHOOK(hook.first, hook.second);
|
2019-08-31 20:49:46 +02:00
|
|
|
});
|
|
|
|
EndHook();
|
|
|
|
_hooked_funcs.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif//NO_OVERLAY
|