sourcehook/sourcehook.cpp
author David Anderson <dvander@alliedmods.net>
Fri Apr 22 14:29:25 2005 +0000 (2005-04-22)
changeset 34 11e62a912700
parent 10 406d8e5ddfc4
child 41 534eac4c53ef
permissions -rw-r--r--
Cleaned up files for linux
Disabled SH_CCC_Makegate call for linux builds
     1 /* ======== SourceHook ========
     2 * Copyright (C) 2004-2005 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 /**
    12  * @file sourcehook.cpp
    13  * @brief Contains the implementation of the SourceHook API
    14 */
    15 
    16 #include <algorithm>
    17 #include "sourcehook_impl.h"
    18 
    19 #if SH_SYS == SH_SYS_WIN32
    20 # include <windows.h>
    21 #elif SH_SYS == SH_SYS_LINUX
    22 # include <sys/mman.h>
    23 # include <limits.h>
    24 # include <unistd.h>
    25 # ifndef PAGESIZE
    26 #  define PAGESIZE 4096
    27 # endif
    28 #endif
    29 
    30 #if SH_RUNTIME_CODEGEN == 1
    31 # if SH_COMP == SH_COMP_GCC
    32 #  define SH_CCC_CODESIZE 15
    33 	//	 :TODO:
    34 	//void SH_CCC_MakeGate(void *origthisptr, unsigned char* &ptr, void *origvtable, int i)
    35 	//{
    36 	//}
    37 # elif SH_COMP == SH_COMP_MSVC
    38 #  define SH_CCC_CODESIZE 19
    39 	void SH_CCC_MakeGate(void *origthisptr, void *ccthisptr, unsigned char* ptr, void *origfunc)
    40 	{
    41 		// --Subtract old this pointer to get the offset
    42 		// 00417EDF 81 E9 A1 7B 33 01 sub         ecx,1337BA1h 
    43 		*ptr++ = 0x81;
    44 		*ptr++ = 0xE9;
    45 		*reinterpret_cast<void**>(ptr) = ccthisptr;
    46 		ptr += sizeof(void*);
    47 		// --Add it to the new this pointer
    48 		// 00417EE5 81 C1 37 13 37 13 add         ecx,13371337h 
    49 		*ptr++ = 0x81;
    50 		*ptr++ = 0xC1;
    51 		*reinterpret_cast<void**>(ptr) = origthisptr;
    52 		ptr += sizeof(void*);
    53 		// --Prepare address
    54 		// 00417EEB B8 EF BE AD DE   mov         eax,0DEADBEEFh 
    55 		*ptr++ = 0xB8;
    56 		*reinterpret_cast<void**>(ptr) = origfunc;
    57 		ptr += sizeof(void*);
    58 		// -- Do actual jump
    59 		// 00417EF0 FF E0            jmp         eax  
    60 		*ptr++ = 0xFF;
    61 		*ptr++ = 0xE0;
    62 	}
    63 # endif
    64 #endif
    65 
    66 
    67 namespace SourceHook
    68 {
    69 	CSourceHookImpl::CSourceHookImpl()
    70 	{
    71 		// Get page size
    72 #if SH_SYS == SH_SYS_WIN32
    73 		SYSTEM_INFO sysinfo;
    74 		GetSystemInfo(&sysinfo);
    75 		m_PageSize = sysinfo.dwPageSize;
    76 #elif SH_SYS == SH_SYS_LINUX
    77 		m_PageSize = PAGESIZE;
    78 #else
    79 # error Unsupported system
    80 #endif
    81 	}
    82 
    83 	CSourceHookImpl::~CSourceHookImpl()
    84 	{
    85 
    86 	}
    87 
    88 	bool CSourceHookImpl::IsPluginInUse(Plugin plug)
    89 	{
    90 		// Iterate through all hook managers which are in this plugin
    91 		// Iterate through their hooks
    92 		// If a hook from an other plugin is found, return true
    93 		// Return false otherwise
    94 #define TMP_CHECK_LIST(name) \
    95 	for (iter3 = iter2->name.begin(); iter3 != iter2->name.end(); ++iter3) \
    96 		if (iter3->plug == plug) \
    97 			return true;
    98 
    99 		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
   100 		{
   101 			if (iter->plug == plug && !iter->ifaces.empty())
   102 			{
   103 				for (std::list<HookManagerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end(); ++iter2)
   104 				{
   105 					std::list<HookManagerInfo::Iface::Hook>::iterator iter3;
   106 					TMP_CHECK_LIST(hooks_pre);
   107 					TMP_CHECK_LIST(hooks_post);
   108 				}
   109 			}
   110 		}
   111 #undef TMP_CHECK_LIST
   112 		return false;
   113 	}
   114 
   115 	void CSourceHookImpl::UnloadPlugin(Plugin plug)
   116 	{
   117 		// 1) Manually remove all hooks by this plugin
   118 		std::list<RemoveHookInfo> hookstoremove;
   119 
   120 		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
   121 		{
   122 			for (std::list<HookManagerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end();
   123 				++iter2)
   124 			{
   125 				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end(); ++iter3)
   126 					if (iter3->plug == plug)
   127 						hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, false));
   128 
   129 				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end(); ++iter3)
   130 					if (iter3->plug == plug)
   131 						hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, true));
   132 			}
   133 		}
   134 
   135 		for (std::list<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
   136 			RemoveHook(rmiter->plug, rmiter->iface, rmiter->hpf, rmiter->handler, rmiter->post);
   137 
   138 		// 2) Other plugins may use hook managers in this plugin.
   139 		// Get a list of hook managers that are in this plugin and are used by other plugins
   140 		// Delete all hook managers that are in this plugin
   141 
   142 		HookManInfoList tmphookmans;
   143 		bool erase = false;
   144 		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end();
   145 			erase ? iter=m_HookMans.erase(iter) : ++iter)
   146 		{
   147 			if (iter->plug == plug)
   148 			{
   149 				if (!iter->ifaces.empty())
   150 				{
   151 					// All hooks by this plugin are already removed
   152 					// So if there is an iface, it has to be used by an other plugin
   153 					tmphookmans.push_back(*iter);
   154 				}
   155 				erase = true;
   156 			}
   157 			else
   158 				erase = false;
   159 		}
   160 		
   161 		// For each hook manager:
   162 		for (HookManInfoList::iterator iter = tmphookmans.begin(); iter != tmphookmans.end(); ++iter)
   163 		{
   164 			// Find a suitable hook manager in an other plugin
   165 			HookManInfoList::iterator newHookMan = FindHookMan(m_HookMans.begin(), m_HookMans.end(),
   166 				iter->proto, iter->vtbl_offs, iter->vtbl_idx, iter->thisptr_offs);
   167 			if (newHookMan == m_HookMans.end())
   168 			{
   169 				// This should _never_ happen.
   170 				// If there is a hook from an other plugin, the plugin must have provided a hook manager as well.
   171 				SH_ASSERT(0);
   172 			}
   173 
   174 			// AddHook should make sure that every plugin only has _one_ hook manager for _one_ proto/vi/vo/thisptroffs
   175 			SH_ASSERT(newHookMan->plug != plug);
   176 
   177 			// The first hooker should be always used - so the new hook manager has to be empty
   178 			SH_ASSERT(newHookMan->ifaces.empty());
   179 
   180 			// Move the ifaces from the old hook manager to the new one
   181 			newHookMan->ifaces = iter->ifaces;
   182 
   183 			// Unregister the old one, register the new one
   184 			iter->func(HA_Unregister, NULL);
   185 			newHookMan->func(HA_Register, &(*newHookMan));
   186 		}
   187 	}
   188 
   189 	void CSourceHookImpl::CompleteShutdown()
   190 	{
   191 		std::list<RemoveHookInfo> hookstoremove;
   192 
   193 		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
   194 		{
   195 			for (std::list<HookManagerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end();
   196 				++iter2)
   197 			{
   198 				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end(); ++iter3)
   199 					hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, false));
   200 				
   201 				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end(); ++iter3)
   202 					hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, true));
   203 			}
   204 		}
   205 
   206 		for (std::list<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
   207 			RemoveHook(rmiter->plug, rmiter->iface, rmiter->hpf, rmiter->handler, rmiter->post);
   208 
   209 		m_HookMans.clear();
   210 	}
   211 
   212 	bool CSourceHookImpl::AddHook(Plugin plug, void *iface, int ifacesize, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post)
   213 	{
   214 		// 1) Get info about the hook manager
   215 		HookManagerInfo tmp;
   216 		if (myHookMan(HA_GetInfo, &tmp) != 0)
   217 			return false;
   218 
   219 		// Add the proposed hook manager to the _end_ of the list if the plugin doesn't have a hook manager with this proto/vo/vi registered
   220 		HookManInfoList::iterator hookmaniter;
   221 		for (hookmaniter = m_HookMans.begin(); hookmaniter != m_HookMans.end(); ++hookmaniter)
   222 		{
   223 			if (hookmaniter->plug == plug && strcmp(hookmaniter->proto, tmp.proto) == 0 &&
   224 				hookmaniter->vtbl_offs == tmp.vtbl_offs && hookmaniter->vtbl_idx == tmp.vtbl_idx &&
   225 				hookmaniter->thisptr_offs == tmp.thisptr_offs)
   226 				break;
   227 		}
   228 		if (hookmaniter == m_HookMans.end())
   229 		{
   230 			// No such hook manager from this plugin yet, add it!
   231 			tmp.func = myHookMan;
   232 			tmp.plug = plug;
   233 			m_HookMans.push_back(tmp);
   234 		}
   235 
   236 		// Then, search for a suitable hook manager (from the beginning)
   237 		HookManInfoList::iterator hookman = FindHookMan(m_HookMans.begin(), m_HookMans.end(), tmp.proto, tmp.vtbl_offs, tmp.vtbl_idx, tmp.thisptr_offs);
   238 		SH_ASSERT(hookman != m_HookMans.end());
   239 
   240 		// Tell it to store the pointer if it's not already active
   241 		if (hookman->ifaces.empty())
   242 			hookman->func(HA_Register, &(*hookman));
   243 
   244 		std::list<HookManagerInfo::Iface>::iterator ifsiter = std::find(hookman->ifaces.begin(), hookman->ifaces.end(), iface);
   245 
   246 		if (ifsiter == hookman->ifaces.end())
   247 		{
   248 			HookManagerInfo::Iface ifs;
   249 			ifs.ptr = iface;
   250 			ifs.callclass = GetCallClass(iface, ifacesize);
   251 			void *vtableptr = *reinterpret_cast<void**>(reinterpret_cast<char*>(iface) + hookman->vtbl_offs);
   252 			SetMemAccess(vtableptr, sizeof(void*) * hookman->vtbl_idx, SH_MEM_READ | SH_MEM_WRITE);
   253 			ifs.orig_entry = (*reinterpret_cast<void***>(reinterpret_cast<char*>(iface) + hookman->vtbl_offs))[hookman->vtbl_idx];
   254 			(*reinterpret_cast<void***>(reinterpret_cast<char*>(iface) + hookman->vtbl_offs))[hookman->vtbl_idx] =
   255 				(*reinterpret_cast<void***>(reinterpret_cast<char*>(hookman->hookfunc_inst) + hookman->hookfunc_vtbl_offs))[hookman->hookfunc_vtbl_idx];
   256 			hookman->ifaces.push_back(ifs);
   257 			ifsiter = hookman->ifaces.end();
   258 			--ifsiter;
   259 		}
   260 		HookManagerInfo::Iface::Hook hookinfo;
   261 		hookinfo.handler = handler;
   262 		hookinfo.plug = plug;
   263 		hookinfo.paused = false;
   264 		if (post)
   265    			ifsiter->hooks_post.push_back(hookinfo);
   266 		else
   267 			ifsiter->hooks_pre.push_back(hookinfo);
   268 
   269 
   270 		// Now that it is done, check whether we have to update any callclasses
   271 		for (Impl_CallClassList::iterator cciter = m_CallClasses.begin(); cciter != m_CallClasses.end(); ++cciter)
   272 		{
   273 			if (cciter->iface == iface)
   274 			{
   275 				ApplyCallClassPatch(*cciter, tmp.vtbl_offs, tmp.vtbl_idx, ifsiter->orig_entry);
   276 
   277 				// We can assume that there is no more callclass with the same iface
   278 				break;
   279 			}
   280 		}
   281 
   282 		return true;
   283 	}
   284 
   285 	bool CSourceHookImpl::RemoveHook(Plugin plug, void *iface, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post)
   286 	{
   287 		HookManagerInfo tmp;
   288 		if (myHookMan(HA_GetInfo, &tmp) != 0)
   289 			return false;
   290 
   291 		// Find the hook manager and the hook
   292 		HookManInfoList::iterator hookman = FindHookMan(m_HookMans.begin(), m_HookMans.end(), 
   293 			tmp.proto, tmp.vtbl_offs, tmp.vtbl_idx, tmp.thisptr_offs);
   294 		if (hookman == m_HookMans.end())
   295 			return false;
   296 
   297 		for (std::list<HookManagerInfo::Iface>::iterator ifaceiter = hookman->ifaces.begin(); ifaceiter != hookman->ifaces.end(); ++ifaceiter)
   298 		{
   299 			if (ifaceiter->ptr == iface)
   300 			{
   301 				std::list<HookManagerInfo::Iface::Hook> &hooks = post ? ifaceiter->hooks_post : ifaceiter->hooks_pre;
   302 				bool erase;
   303 				for (std::list<HookManagerInfo::Iface::Hook>::iterator hookiter = hooks.begin();
   304 					hookiter != hooks.end(); erase ? hookiter = hooks.erase(hookiter) : ++hookiter)
   305 				{
   306 					erase = hookiter->plug == plug && hookiter->handler->IsEqual(handler);
   307 					if (erase)
   308 						hookiter->handler->DeleteThis();			// Make the _plugin_ delete the handler object
   309 				}
   310 				if (ifaceiter->hooks_post.empty() && ifaceiter->hooks_pre.empty())
   311 				{
   312 					// Deactivate the hook
   313 					(*reinterpret_cast<void***>(reinterpret_cast<char*>(ifaceiter->ptr) +
   314 						hookman->vtbl_offs))[hookman->vtbl_idx]= ifaceiter->orig_entry;
   315 
   316 					// Release the callclass
   317 					ReleaseCallClass(ifaceiter->callclass);
   318 
   319 					// Remove the iface info
   320 					hookman->ifaces.erase(ifaceiter);
   321 
   322 					if (hookman->ifaces.empty())
   323 						hookman->func(HA_Unregister, NULL);
   324 				}
   325 				// :TODO: Better return value? Or none?
   326 				return true;
   327 			}
   328 		}
   329 		return false;
   330 	}
   331 
   332 	void *CSourceHookImpl::GetCallClass(void *iface, size_t size)
   333 	{
   334 		for (Impl_CallClassList::iterator cciter = m_CallClasses.begin(); cciter != m_CallClasses.end(); ++cciter)
   335 		{
   336 			if (cciter->iface == iface)
   337 			{
   338 				++cciter->refcounter;
   339 				return cciter->ptr;
   340 			}
   341 		}
   342 
   343 		// The layout of callclasses is:
   344 		//  Copy of the class; vtable entries pointing to gates
   345 		//  Pointer to the corresponding CallClass object
   346 		//  Copy of the class; vtable entries pointing to original functions
   347 
   348 		CallClass tmp;
   349 		char *ptr = new char[size * 2 + sizeof(void*)];
   350 		tmp.ptr = reinterpret_cast<void*>(ptr);
   351 		memcpy(reinterpret_cast<void*>(ptr), iface, size);
   352 		memcpy(reinterpret_cast<void*>(ptr + size + sizeof(void*)), iface, size);
   353 		tmp.iface = iface;
   354 		tmp.size = size;
   355 		tmp.refcounter = 1;
   356 
   357 		// Go through _all_ hooks and apply any needed patches
   358 		for (HookManInfoList::iterator hookman = m_HookMans.begin(); hookman != m_HookMans.end(); ++hookman)
   359 		{
   360 			for (std::list<HookManagerInfo::Iface>::iterator ifaceiter = hookman->ifaces.begin(); ifaceiter != hookman->ifaces.end(); ++ifaceiter)
   361 			{
   362 				if (ifaceiter->ptr == iface)
   363 				{
   364 					if (!ApplyCallClassPatch(tmp, hookman->vtbl_offs, hookman->vtbl_idx, ifaceiter->orig_entry))
   365 					{
   366 						FreeCallClass(tmp);
   367 						return NULL;
   368 					}
   369 				}
   370 			}
   371 		}
   372 		m_CallClasses.push_back(tmp);
   373 		// The object has to be followed by the pointer to the vtable info object
   374 		*reinterpret_cast<void**>(ptr + size) = &m_CallClasses.back();
   375 		return tmp.ptr;
   376 	}
   377 
   378 	void CSourceHookImpl::ReleaseCallClass(void *ptr)
   379 	{
   380 		Impl_CallClassList::iterator iter = std::find(m_CallClasses.begin(), m_CallClasses.end(), ptr);
   381 		if (iter == m_CallClasses.end())
   382 			return;
   383 		--iter->refcounter;
   384 		if (iter->refcounter < 1)
   385 		{
   386 			FreeCallClass(*iter);
   387 			m_CallClasses.erase(iter);
   388 		}
   389 	}
   390 
   391 	void CSourceHookImpl::FreeCallClass(CallClass &cc)
   392 	{
   393 		for (CallClass::VTableList::iterator vtbliter = cc.vtables.begin(); vtbliter != cc.vtables.end(); ++vtbliter)
   394 		{
   395 #if SH_RUNTIME_CODEGEN == 1
   396 			// Delete generated callgates
   397 			for (std::list<int>::iterator cgiter = vtbliter->patches.begin(); cgiter != vtbliter->patches.end(); ++cgiter)
   398 			{
   399 				char *cgptr = reinterpret_cast<char**>(vtbliter->ptr)[*cgiter];
   400 				delete [] cgptr;
   401 			}
   402 #endif
   403 			delete [] reinterpret_cast<char*>(vtbliter->ptr);
   404 		}
   405 		delete [] reinterpret_cast<char*>(cc.ptr);
   406 	}
   407 
   408 	bool CSourceHookImpl::ApplyCallClassPatch(CallClass &cc, int vtbl_offs, int vtbl_idx, void *orig_entry)
   409 	{
   410 		char *ptr = reinterpret_cast<char*>(cc.ptr);
   411 		void *vtable = *reinterpret_cast<void**>(ptr + vtbl_offs);
   412 
   413 		// Check whether we already know that vtable
   414 		CallClass::VTableList::iterator vtbliter = std::find(cc.vtables.begin(),
   415 			cc.vtables.end(), reinterpret_cast<void*>(vtable));
   416 		int actvtablesize=MAX_VTABLE_LEN;
   417 		if (vtbliter == cc.vtables.end())
   418 		{
   419 			CallClass::VTable newvtableinfo;
   420 			int pagesnum = (MAX_VTABLE_LEN % m_PageSize == 0) ? MAX_VTABLE_LEN / m_PageSize : MAX_VTABLE_LEN / m_PageSize + 1;
   421 			// Set all pages in the range to readwrite
   422 			// :TODO: Fix this!
   423 			char *pagebegin = reinterpret_cast<char*>(vtable) - (reinterpret_cast<int>(vtable) % m_PageSize);
   424 			for (int ipage = 0; ipage < pagesnum; ++ipage)
   425 			{
   426 				if (!SetMemAccess(reinterpret_cast<void*>(pagebegin + ipage * m_PageSize), 1,
   427 					SH_MEM_READ | SH_MEM_WRITE))
   428 				{
   429 					// We can't go here anymore
   430 					actvtablesize = static_cast<int>((pagebegin + ipage * m_PageSize) - reinterpret_cast<char*>(vtable));
   431 					break;
   432 				}
   433 			}
   434 			if (actvtablesize < 1)
   435 			{
   436 				// We can't access the vtable -> Quit
   437 				return false;
   438 			}
   439 			// Create a new vtable
   440 			newvtableinfo.ptr = reinterpret_cast<void*>(new char[actvtablesize]);
   441 			// Fill it with the information from the old vtable
   442 			memcpy(newvtableinfo.ptr, vtable, actvtablesize);
   443 			newvtableinfo.actsize = actvtablesize;
   444 			// Set the pointer in the object and add it to the list of already known vtables
   445 			*reinterpret_cast<void**>(ptr + vtbl_offs) = newvtableinfo.ptr;
   446 			cc.vtables.push_back(newvtableinfo);
   447 
   448 			vtbliter = cc.vtables.end();
   449 			--vtbliter;
   450 			// :TODO: When not codegen, patch the other vtable?
   451 		}
   452 
   453 		// Check whether we already have this patch
   454 		if (std::find(vtbliter->patches.begin(), vtbliter->patches.end(), vtbl_idx) == vtbliter->patches.end())
   455 		{
   456 			// No -> apply it
   457 
   458 			// Get a call gate
   459 			void *callgate = NULL;
   460 #if SH_RUNTIME_CODEGEN == 1
   461 			unsigned char *cggen = new unsigned char[SH_CCC_CODESIZE];
   462 			//SH_CCC_MakeGate(cc.iface, cc.ptr, cggen, orig_entry);
   463 			callgate = (void*)cggen;
   464 			SetMemAccess(callgate, SH_CCC_CODESIZE, SH_MEM_READ | SH_MEM_WRITE | SH_MEM_EXEC);
   465 #else
   466 			// :TODO:
   467 #error Not supported yet!
   468 #endif
   469 			vtbliter->patches.push_back(vtbl_idx);
   470 			reinterpret_cast<void**>(vtbliter->ptr)[vtbl_idx] = callgate;
   471 		}
   472 		return true;
   473 	}
   474 
   475 
   476 	CSourceHookImpl::HookManInfoList::iterator CSourceHookImpl::FindHookMan(HookManInfoList::iterator begin,
   477 		HookManInfoList::iterator end, const char *proto, int vtblofs, int vtblidx, int thisptrofs)
   478 	{
   479 		for (HookManInfoList::iterator hookmaniter = m_HookMans.begin(); hookmaniter != m_HookMans.end(); ++hookmaniter)
   480 		{
   481 			if (strcmp(hookmaniter->proto, proto) == 0 && hookmaniter->vtbl_offs == vtblofs && hookmaniter->vtbl_idx == vtblidx &&
   482 				hookmaniter->thisptr_offs == thisptrofs)
   483 				break;
   484 		}
   485 		return hookmaniter;
   486 	}
   487 
   488 	void CSourceHookImpl::PausePlugin(Plugin plug)
   489 	{
   490 		// Go through all hook managers, all interfaces, and set the status of all hooks of this plugin to paused
   491 		for (HookManInfoList::iterator hookmaniter = m_HookMans.begin(); hookmaniter != m_HookMans.end(); ++hookmaniter)
   492 			for (std::list<HookManagerInfo::Iface>::iterator ifaceiter = hookmaniter->ifaces.begin();
   493 				ifaceiter != hookmaniter->ifaces.end(); ++ifaceiter)
   494 			{
   495 				for (std::list<HookManagerInfo::Iface::Hook>::iterator hookiter = ifaceiter->hooks_pre.begin();
   496 					hookiter != ifaceiter->hooks_pre.end(); ++hookiter)
   497 					if (plug == hookiter->plug)
   498 						hookiter->paused = true;
   499 
   500 				for (std::list<HookManagerInfo::Iface::Hook>::iterator hookiter = ifaceiter->hooks_post.begin();
   501 					hookiter != ifaceiter->hooks_post.end(); ++hookiter)
   502 					if (plug == hookiter->plug)
   503 						hookiter->paused = true;
   504 			}
   505 	}
   506 
   507 	void CSourceHookImpl::UnpausePlugin(Plugin plug)
   508 	{
   509 		// Go through all hook managers, all interfaces, and set the status of all hooks of this plugin to normal
   510 		for (HookManInfoList::iterator hookmaniter = m_HookMans.begin(); hookmaniter != m_HookMans.end(); ++hookmaniter)
   511 			for (std::list<HookManagerInfo::Iface>::iterator ifaceiter = hookmaniter->ifaces.begin();
   512 				ifaceiter != hookmaniter->ifaces.end(); ++ifaceiter)
   513 			{
   514 				for (std::list<HookManagerInfo::Iface::Hook>::iterator hookiter = ifaceiter->hooks_pre.begin();
   515 					hookiter != ifaceiter->hooks_pre.end(); ++hookiter)
   516 					if (plug == hookiter->plug)
   517 						hookiter->paused = false;
   518 
   519 				for (std::list<HookManagerInfo::Iface::Hook>::iterator hookiter = ifaceiter->hooks_post.begin();
   520 					hookiter != ifaceiter->hooks_post.end(); ++hookiter)
   521 					if (plug == hookiter->plug)
   522 						hookiter->paused = false;
   523 			}
   524 	}
   525 
   526 	void CSourceHookImpl::SetRes(META_RES res)
   527 	{
   528 		m_CurRes = res;
   529 	}
   530 
   531 	META_RES CSourceHookImpl::GetPrevRes()
   532 	{
   533 		return m_PrevRes;
   534 	}
   535 
   536 	META_RES CSourceHookImpl::GetStatus()
   537 	{
   538 		return m_Status;
   539 	}
   540 
   541 	const void *CSourceHookImpl::GetOrigRet()
   542 	{
   543 		return m_OrigRet;
   544 	}
   545 
   546 	const void *CSourceHookImpl::GetOverrideRet()
   547 	{
   548 		return m_OverrideRet;
   549 	}
   550 
   551 	META_RES &CSourceHookImpl::GetCurResRef()
   552 	{
   553 		return m_CurRes;
   554 	}
   555 
   556 	META_RES &CSourceHookImpl::GetPrevResRef()
   557 	{
   558 		return m_PrevRes;
   559 	}
   560 
   561 	META_RES &CSourceHookImpl::GetStatusRef()
   562 	{
   563 		return m_Status;
   564 	}
   565 
   566 	void CSourceHookImpl::SetOrigRet(const void *ptr)
   567 	{
   568 		m_OrigRet = ptr;
   569 	}
   570 
   571 	void CSourceHookImpl::SetOverrideRet(const void *ptr)
   572 	{
   573 		m_OverrideRet = ptr;
   574 	}
   575 
   576 	void CSourceHookImpl::SetIfacePtr(void *ptr)
   577 	{
   578 		m_IfacePtr = ptr;
   579 	}
   580 	void *CSourceHookImpl::GetIfacePtr()
   581 	{
   582 		return m_IfacePtr;
   583 	}
   584 }