mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-11-30 14:25:36 +08:00
f096a2d8a2
LoadLibrary increase the reference count to the library. So we make sure this library is still loaded when we shut down the hook.
53 lines
948 B
C++
53 lines
948 B
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():
|
|
_hooked(false)
|
|
{}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
void Base_Hook::HookFunc(std::pair<void**, void*> hook)
|
|
{
|
|
if( DetourAttach(hook.first, hook.second) == 0 )
|
|
_hooked_funcs.emplace_back(hook);
|
|
}
|
|
|
|
#endif//NO_OVERLAY
|