2023-12-27 15:21:59 +08:00
|
|
|
#include "overlay/Base_Hook.h"
|
2019-07-26 05:21:03 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2020-01-20 01:55:14 +08:00
|
|
|
#ifdef EMU_OVERLAY
|
2019-09-01 02:49:46 +08:00
|
|
|
#ifdef STEAM_WIN32
|
2019-08-16 16:28:23 +08:00
|
|
|
|
2023-12-27 15:21:59 +08:00
|
|
|
#include "detours/detours.h"
|
2019-07-26 05:21:03 +08:00
|
|
|
|
2019-09-02 02:53:16 +08:00
|
|
|
Base_Hook::Base_Hook():
|
|
|
|
_library(nullptr)
|
|
|
|
{}
|
|
|
|
|
|
|
|
Base_Hook::~Base_Hook()
|
2019-09-01 02:49:46 +08:00
|
|
|
{
|
2019-09-02 02:53:16 +08:00
|
|
|
UnhookAll();
|
2019-09-01 02:49:46 +08:00
|
|
|
}
|
|
|
|
|
2019-09-02 02:53:16 +08:00
|
|
|
const char* Base_Hook::get_lib_name() const
|
2019-07-26 05:21:03 +08:00
|
|
|
{
|
2019-09-02 02:53:16 +08:00
|
|
|
return "<no_name>";
|
2019-07-26 05:21:03 +08:00
|
|
|
}
|
|
|
|
|
2019-09-01 02:49:46 +08:00
|
|
|
void Base_Hook::BeginHook()
|
2019-08-26 22:38:01 +08:00
|
|
|
{
|
2019-10-15 23:32:47 +08:00
|
|
|
DetourTransactionBegin();
|
|
|
|
DetourUpdateThread(GetCurrentThread());
|
2019-09-01 02:49:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Base_Hook::EndHook()
|
|
|
|
{
|
2019-10-15 23:32:47 +08:00
|
|
|
DetourTransactionCommit();
|
2019-08-26 22:38:01 +08:00
|
|
|
}
|
|
|
|
|
2019-08-01 23:04:49 +08:00
|
|
|
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
|
2019-07-26 05:21:03 +08:00
|
|
|
{
|
2019-10-15 23:32:47 +08:00
|
|
|
if( DetourAttach(hook.first, hook.second) == 0 )
|
2019-08-01 04:20:27 +08:00
|
|
|
_hooked_funcs.emplace_back(hook);
|
2019-08-14 21:09:57 +08:00
|
|
|
}
|
|
|
|
|
2019-09-01 02:49:46 +08: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-10-15 23:32:47 +08:00
|
|
|
DetourDetach(hook.first, hook.second);
|
2019-09-01 02:49:46 +08:00
|
|
|
});
|
|
|
|
EndHook();
|
|
|
|
_hooked_funcs.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 23:32:47 +08:00
|
|
|
#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
|
|
|
|
|
2020-01-20 01:55:14 +08:00
|
|
|
#endif//EMU_OVERLAY
|