sourcehook/sourcehook_impl_chookidman.h
author Pavol Marko <pavolmarko@gmail.com>
Sun Nov 04 16:03:39 2007 +0000 (2007-11-04)
branchhookman_autogen
changeset 445 4c2924c393ed
parent 418 109309ff6350
child 523 6f1630519b81
permissions -rw-r--r--
Moved CPageAlloc from sh_memory into sh_pagealloc.h
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2007 Metamod:Source Development Team
     3 * No warranties of any kind
     4 *
     5 * License: zlib/libpng
     6 *
     7 * Author(s): Pavol "PM OnoTo" Marko
     8 * ============================
     9 */
    10 
    11 #ifndef __SOURCEHOOK_IMPL_CHOOKIDMAN_H__
    12 #define __SOURCEHOOK_IMPL_CHOOKIDMAN_H__
    13 
    14 #include "sh_vector.h"
    15 
    16 namespace SourceHook
    17 {
    18 	namespace Impl
    19 	{
    20 		// Associates hook ids with info about the hooks
    21 		// Also used to keep track of used hook ids
    22 		class CHookIDManager
    23 		{
    24 		public:
    25 			struct Entry
    26 			{
    27 				bool isfree;
    28 
    29 				// hookman info
    30 				CProto proto;
    31 				int vtbl_offs;
    32 				int vtbl_idx;
    33 
    34 				// vfnptr
    35 				void *vfnptr;
    36 
    37 				// iface
    38 				void* adjustediface;
    39 
    40 				// hook
    41 				Plugin plug;
    42 				int thisptr_offs;
    43 				ISHDelegate *handler;
    44 				bool post;
    45 
    46 				Entry(const CProto &pprt, int pvo, int pvi, void *pvp, void *pai, Plugin pplug, int pto,
    47 					ISHDelegate *ph, bool ppost)
    48 					: isfree(false), proto(pprt), vtbl_offs(pvo), vtbl_idx(pvi), vfnptr(pvp), 
    49 					adjustediface(pai), plug(pplug), thisptr_offs(pto), handler(ph), post(ppost)
    50 				{
    51 				}
    52 				Entry()
    53 				{
    54 				}
    55 			};
    56 		private:
    57 			// Internally, hookid 1 is stored as m_Entries[0]
    58 
    59 			CVector<Entry> m_Entries;
    60 		public:
    61 			CHookIDManager();
    62 			int New(const CProto &proto, int vtbl_offs, int vtbl_idx, void *vfnptr, void *adjustediface,
    63 				Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post);
    64 			bool Remove(int hookid);
    65 			const Entry * QueryHook(int hookid);
    66 
    67 			// Finds all hooks with the given info, and fills the hookids into output.
    68 			void FindAllHooks(CVector<int> &output, const CProto &proto, int vtbl_offs, int vtbl_idx,
    69 				void *adjustediface, Plugin plug, int thisptr_offs, ISHDelegate *handler, bool post);
    70 
    71 			// Removes all hooks with a specified vfnptr
    72 			void RemoveAll(void *vfnptr);
    73 
    74 			void FindAllHooks(CVector<int> &output);
    75 			void FindAllHooks(CVector<int> &output, Plugin plug);
    76 		};
    77 	}
    78 }
    79 
    80 #endif
    81