core/sourcehook/sourcehook_impl_chookidman.h
author Scott Ehlert <ds@alliedmods.net>
Thu Dec 10 00:59:50 2009 -0600 (2009-12-10)
changeset 689 4065ba5e9155
parent 539 db914129ae01
child 733 2365240861a2
permissions -rw-r--r--
Rewrote user message caching code to always use IServerGameDLL::GetUserMessageInfo (bug 4117, r=dvander).

Games where the above function can crash are handled by detouring tier0's Error() function and jumping back to our own code. So in theory this should work on all games now.
     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