core/sourcehook/sourcehook_impl_chookidman.h
author Scott Ehlert <ds@alliedmods.net>
Thu Jul 01 02:43:22 2010 -0500 (2010-07-01)
changeset 722 78f730f91439
parent 539 db914129ae01
child 733 2365240861a2
permissions -rw-r--r--
Fixed problem on OBV where alternately loaded plugins (CreateInterface_MMS) could be incorrectly told they were on the OB engine (bug 4491, r=dvander).

This only happened when there was more than one plugin that loaded this way. And the first plugin to load had to fail on OBV first so that OB could be tried. It was being permanently set to OB for future plugin loads and this caused problems.
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2008 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