core/sourcehook/sourcehook_impl_chookmaninfo.cpp
author David Anderson <dvander@alliedmods.net>
Sat Mar 12 20:18:10 2011 -0800 (2011-03-12)
changeset 742 f38fc2289fa5
parent 733 2365240861a2
permissions -rw-r--r--
Updated symstore logic.
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2010 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): Pavol "PM OnoTo" Marko
     8 * Contributors: Scott "Damaged Soul" Ehlert
     9 * ============================
    10 */
    11 
    12 #include "sourcehook_impl.h"
    13 
    14 namespace SourceHook
    15 {
    16 	namespace Impl
    17 	{
    18 		CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
    19 			: m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
    20 		{
    21 			// Query pubfunc
    22 			//  -> Should call SetInfo and set all the other variables!
    23 			if (m_PubFunc(false, this) != 0)
    24 			{
    25 				// Error!
    26 				m_Version = -1;
    27 			}
    28 		}
    29 
    30 		void CHookManager::SetInfo(int hookman_version, int vtbloffs, int vtblidx,
    31 			ProtoInfo *proto, void *hookfunc_vfnptr)
    32 		{
    33 			m_Version = hookman_version;
    34 			m_VtblOffs = vtbloffs;
    35 			m_VtblIdx = vtblidx;
    36 			m_Proto = proto;
    37 			m_HookfuncVfnptr = hookfunc_vfnptr;
    38 		}
    39 
    40 		void CHookManager::Register()
    41 		{
    42 			m_PubFunc(true, this);
    43 		}
    44 
    45 		void CHookManager::Unregister()
    46 		{
    47 			m_PubFunc(true, NULL);
    48 		}
    49 
    50 		void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
    51 		{
    52 			m_VfnPtrs.push_back(pVfnPtr);
    53 			if (m_VfnPtrs.size() == 1)
    54 				Register();
    55 		}
    56 
    57 		void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
    58 		{
    59 			m_VfnPtrs.remove(pVfnPtr);
    60 			if (m_VfnPtrs.empty())
    61 				Unregister();
    62 		}
    63 
    64 		CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
    65 		{
    66 			CHookManager hm(plug, pubFunc);
    67 			return GetHookMan(hm);
    68 		}
    69 
    70 		CHookManager *CHookManList::GetHookMan(CHookManager &hm)
    71 		{
    72 			iterator iter = find(hm);
    73 			if (iter == end())
    74 			{
    75 				push_back(hm);
    76 				return &(back());
    77 			}
    78 			else
    79 			{
    80 				return &(*iter);
    81 			}
    82 		}
    83 	}
    84 }