Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add templated handler for manual hooks #150

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions core/sourcehook/sourcehook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ namespace SourceHook

int CSourceHookImpl::AddHook(Plugin plug, AddHookMode mode, void *iface, int thisptr_offs, HookManagerPubFunc myHookMan,
ISHDelegate *handler, bool post)
{
HookManagerPubFuncHandler pubFunc(myHookMan);
SHDelegateHandler shDelegate(handler);
return AddHook(plug, mode, iface, thisptr_offs, pubFunc, shDelegate, post);
}

int CSourceHookImpl::AddHook(Plugin plug, AddHookMode mode, void *iface, int thisptr_offs, const HookManagerPubFuncHandler &myHookMan,
const SHDelegateHandler &handler, bool post)
{
if (mode != Hook_Normal && mode != Hook_VP && mode != Hook_DVP)
return 0;
Expand Down Expand Up @@ -174,7 +182,7 @@ namespace SourceHook
ISHDelegate *handler, bool post)
{
// Get info about hook manager and compute adjustediface
CHookManager tmpHookMan(plug, myHookMan);
CHookManager tmpHookMan(plug, HookManagerPubFuncHandler(myHookMan));

void *adjustediface = reinterpret_cast<void*>(reinterpret_cast<char*>(iface)+thisptr_offs);

Expand Down Expand Up @@ -224,8 +232,6 @@ namespace SourceHook
if (hook_iter == hooks.end())
return false;

hook_iter->GetHandler()->DeleteThis();

// Iterator movage!
List<CHook>::iterator oldhookiter = hook_iter;
hook_iter = hooks.erase(hook_iter);
Expand Down Expand Up @@ -417,6 +423,12 @@ namespace SourceHook
}

void CSourceHookImpl::RemoveHookManager(Plugin plug, HookManagerPubFunc pubFunc)
{
// Find the hook manager
RemoveHookManager(plug, HookManagerPubFuncHandler(pubFunc));
}

void CSourceHookImpl::RemoveHookManager(Plugin plug, const HookManagerPubFuncHandler &pubFunc)
{
// Find the hook manager
CHookManList::iterator hookman_iter = m_HookManList.find(CHookManager::Descriptor(plug, pubFunc));
Expand Down
Loading
Loading