//========================================================================
// Finds a detour in the list by its target function's address.
//========================================================================
CDetour* CDetourManager::Find_Detour( void *pTarget )
{
	// Sanity check.
	if( !pTarget ) {
		return NULL;
	}

	// Loop through the list, see if we can find it
	for( unsigned int i = 0; i < m_DetourList.size(); i++ )
	{
		// Get the detour
		CDetour* pDetour = m_DetourList[i];

		// Is it valid?
		if( !pDetour )
			continue;

		// Is it the right one?
		if( pDetour->GetFuncObj()->GetAddress() == pTarget )
			return pDetour;
	}

	// If we make it here, we can't find it.
	return NULL;
}
// =======================================================================
// Adds a detour to the list.
// =======================================================================
CDetour* CDetourManager::CreateDetour(void* pTarget, void* pCallBack, 
									  eCallConv conv, char* szParams)
{
	// ------------------------------------
	// Make all given information is
	// valid.
	// ------------------------------------
	if( !pTarget || !pCallBack || !szParams ) {
		return NULL;
	}

	// ------------------------------------
	// We'll use this to either find or
	// create the detour.
	// ------------------------------------
	CDetour* pDetour = NULL;

	// ------------------------------------
	// Try to find the detour in the map.
	// ------------------------------------
	TDetourMap::iterator iterDetour = m_DetourList.find((unsigned int)pTarget);

	// ------------------------------------
	// Make sure it's valid...
	// ------------------------------------
	if( iterDetour == m_DetourList.end() ) {
		
		// ------------------------------------
		// If not, we need to create it.
		// ------------------------------------
		pDetour = new CDetour(pTarget, szParams, conv);

		// ------------------------------------
		// Now add it to the list
		// ------------------------------------
		m_DetourList.insert(TDetourPair((unsigned int)pTarget, pDetour));
	} else {

		// ------------------------------------
		// This means we found the detour.
		// Grab the instance.
		// ------------------------------------
		pDetour = iterDetour->second;
	}

	// ------------------------------------
	// Add the callback to it.
	// ------------------------------------
	pDetour->AddCallback( pCallBack );

	// ------------------------------------
	// Return the detour!
	// ------------------------------------
	return pDetour;
}
CDetour *CDetourManager::CreateDetour( const char *function, void *address_from, void *address_to, void **ret_tramp )
{
	CDetour *detour = new CDetour(function, address_from, address_to, ret_tramp);
	if (detour) {
		if (!detour->Init()) {
			delete detour;
			return NULL;
		}
		return detour;
	}

	return NULL;
}
Exemple #4
0
CDetour *CDetourManager::CreateDetour(void *callbackfunction, void **trampoline, const char *signame)
{
	CDetour *detour = new CDetour(callbackfunction, trampoline, signame);
	if (detour)
	{
		if (!detour->Init(spengine, gameconf))
		{
			delete detour;
			return NULL;
		}

		return detour;
	}

	return NULL;
}