1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/sourcehook/sourcehook_impl_chookmaninfo.cpp Sat Oct 16 23:21:58 2010 -0700
1.3 @@ -0,0 +1,84 @@
1.4 +/* ======== SourceHook ========
1.5 +* Copyright (C) 2004-2010 Metamod:Source Development Team
1.6 +* No warranties of any kind
1.7 +*
1.8 +* License: zlib/libpng
1.9 +*
1.10 +* Author(s): Pavol "PM OnoTo" Marko
1.11 +* Contributors: Scott "Damaged Soul" Ehlert
1.12 +* ============================
1.13 +*/
1.14 +
1.15 +#include "sourcehook_impl.h"
1.16 +
1.17 +namespace SourceHook
1.18 +{
1.19 + namespace Impl
1.20 + {
1.21 + CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
1.22 + : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
1.23 + {
1.24 + // Query pubfunc
1.25 + // -> Should call SetInfo and set all the other variables!
1.26 + if (m_PubFunc(false, this) != 0)
1.27 + {
1.28 + // Error!
1.29 + m_Version = -1;
1.30 + }
1.31 + }
1.32 +
1.33 + void CHookManager::SetInfo(int hookman_version, int vtbloffs, int vtblidx,
1.34 + ProtoInfo *proto, void *hookfunc_vfnptr)
1.35 + {
1.36 + m_Version = hookman_version;
1.37 + m_VtblOffs = vtbloffs;
1.38 + m_VtblIdx = vtblidx;
1.39 + m_Proto = proto;
1.40 + m_HookfuncVfnptr = hookfunc_vfnptr;
1.41 + }
1.42 +
1.43 + void CHookManager::Register()
1.44 + {
1.45 + m_PubFunc(true, this);
1.46 + }
1.47 +
1.48 + void CHookManager::Unregister()
1.49 + {
1.50 + m_PubFunc(true, NULL);
1.51 + }
1.52 +
1.53 + void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
1.54 + {
1.55 + m_VfnPtrs.push_back(pVfnPtr);
1.56 + if (m_VfnPtrs.size() == 1)
1.57 + Register();
1.58 + }
1.59 +
1.60 + void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
1.61 + {
1.62 + m_VfnPtrs.remove(pVfnPtr);
1.63 + if (m_VfnPtrs.empty())
1.64 + Unregister();
1.65 + }
1.66 +
1.67 + CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
1.68 + {
1.69 + CHookManager hm(plug, pubFunc);
1.70 + return GetHookMan(hm);
1.71 + }
1.72 +
1.73 + CHookManager *CHookManList::GetHookMan(CHookManager &hm)
1.74 + {
1.75 + iterator iter = find(hm);
1.76 + if (iter == end())
1.77 + {
1.78 + push_back(hm);
1.79 + return &(back());
1.80 + }
1.81 + else
1.82 + {
1.83 + return &(*iter);
1.84 + }
1.85 + }
1.86 + }
1.87 +}