Esempio n. 1
0
const char *CClassInterface::FindEntityNetClass(int start, const char *classname)
{
	edict_t *current;

	for (register short int i = 0; i < MAX_ENTITIES; i++)
	{
		current = INDEXENT(i);
		if (current == NULL)
		{
			continue;
		}

		IServerNetworkable *network = current->GetNetworkable();

		if (network == NULL)
		{
			continue;
		}

		if (strcmp(current->GetClassName(), classname) == 0)
		{
			ServerClass *sClass = network->GetServerClass();

			return sClass->GetName();

		}
	}

	return NULL;
}
Esempio n. 2
0
// http://svn.alliedmods.net/viewvc.cgi/trunk/extensions/tf2/extension.cpp?revision=2183&root=sourcemod&pathrev=2183
edict_t *CClassInterface::FindEntityByNetClass(int start, const char *classname)
{
	edict_t *current;

	for (int i = ((start != -1) ? start : 0); i < gpGlobals->maxEntities; i++)
	{
		current = engine->PEntityOfEntIndex(i);
		if (current == NULL)
		{
			continue;
		}

		IServerNetworkable *network = current->GetNetworkable();

		if (network == NULL)
		{
			continue;
		}

		ServerClass *sClass = network->GetServerClass();
		const char *name = sClass->GetName();
		

		if (strcmp(name, classname) == 0)
		{
			return current;
		}
	}

	return NULL;
}
Esempio n. 3
0
// http://svn.alliedmods.net/viewvc.cgi/trunk/extensions/tf2/extension.cpp?revision=2183&root=sourcemod&pathrev=2183
edict_t *CClassInterface::FindEntityByNetClass(int start, const char *classname)
{
	edict_t *current;

	for (register short int i = 0; i < MAX_ENTITIES; i++)
	{
		current = engine->PEntityOfEntIndex(i);
		if (current == NULL)
		{
			continue;
		}

		IServerNetworkable *network = current->GetNetworkable();

		if (network == NULL)
		{
			continue;
		}

		ServerClass *sClass = network->GetServerClass();
		const char *name = sClass->GetName();


		if (strcmp(name, classname) == 0)
		{
			return current;
		}
	}

	return NULL;
}
Esempio n. 4
0
void UTIL_FindServerClassnamePrint(const char *name_cmd)
{
	edict_t *current;

	for (int i = 0; i < gpGlobals->maxEntities; i++)
	{
		current = engine->PEntityOfEntIndex(i);
		if (current == NULL)
		{
			continue;
		}

		IServerNetworkable *network = current->GetNetworkable();

		if (network == NULL)
		{
			continue;
		}

		ServerClass *sClass = network->GetServerClass();
		const char *name = sClass->GetName();
		

		if (strcmp(name, name_cmd) == 0)
		{
			CBotGlobals::botMessage(NULL,0,"%s",current->GetClassName());
			return;
		}
	}

	CBotGlobals::botMessage(NULL,0,"Not found");
}
Esempio n. 5
0
	IterationRetval_t EnumElement( IHandleEntity *pHandleEntity )
	{
		// skip static props, the game DLL doesn't care about them
		if ( StaticPropMgr()->IsStaticProp( pHandleEntity ) )
			return ITERATION_CONTINUE;

		IServerNetworkable *pNetworkable = static_cast< IServerNetworkable* >( pHandleEntity );
		Assert( pNetworkable );

		// Convert the user ID to and edict_t*...
		edict_t* pTouch = pNetworkable->GetEdict();

		// Can't ever touch itself because it's in the other list
		if ( pTouch == m_pTriggerEntity )
			return ITERATION_CONTINUE;

		IServerEntity *serverEntity = pTouch->GetIServerEntity();
		if ( !serverEntity )
			return ITERATION_CONTINUE;

		if ( m_headnode >= 0 )
		{
			Vector vecMins, vecMaxs;
			CM_WorldAlignBounds( serverEntity->GetCollideable(), &vecMins, &vecMaxs );
			int contents = CM_TransformedBoxContents( serverEntity->GetAbsOrigin(), 
					vecMins, vecMaxs, m_headnode, m_origin, m_angles );
			if ( !(contents & MASK_SOLID) )
				return ITERATION_CONTINUE;
		}

		m_TouchedEntities.AddToTail( pTouch );

		return ITERATION_CONTINUE;
	}
Esempio n. 6
0
void UTIL_FindServerClassnamePrint(const char *name_cmd)
{
	edict_t *current;

	register short int maxEnts = (short int)MAX_ENTITIES;
	for (register short int i = 0; i < maxEnts; i++)
	{
		current = INDEXENT(i);
		if (current == NULL)
		{
			continue;
		}

		IServerNetworkable *network = current->GetNetworkable();

		if (network == NULL)
		{
			continue;
		}

		ServerClass *sClass = network->GetServerClass();
		const char *name = sClass->GetName();


		if (strcmp(name, name_cmd) == 0)
		{
			CBotGlobals::BotMessage(NULL, 0, "%s", current->GetClassName());
			return;
		}
	}

	CBotGlobals::BotMessage(NULL, 0, "Not found");
}
Esempio n. 7
0
inline edict_t *BaseEntityToEdict(CBaseEntity *pEntity) {
	IServerUnknown *pUnk = (IServerUnknown *)pEntity;
	IServerNetworkable *pNet = pUnk->GetNetworkable();

	if(!pNet)
		return NULL;

	return pNet->GetEdict();
}
Esempio n. 8
0
CBaseNetworkable *CreateNetworkableByName( const char *className )
{
	IServerNetworkable *pNetwork = EntityFactoryDictionary()->Create( className );
	if ( !pNetwork )
		return NULL;

	CBaseNetworkable *pNetworkable = pNetwork->GetBaseNetworkable();
	Assert( pNetworkable );
	return pNetworkable;
}
ICollideable *CEngineTraceServer::GetCollideable( IHandleEntity *pEntity )
{
	Assert( pEntity );

	ICollideable *pProp = StaticPropMgr()->GetStaticProp( pEntity );
	if ( pProp )
		return pProp;

	IServerNetworkable *pNetEntity = (IServerNetworkable*)pEntity;
	return pNetEntity->GetEdict()->GetCollideable();
}
Esempio n. 10
0
	IterationRetval_t EnumElement( IHandleEntity *pHandleEntity )
	{
		// Static props should never be in the trigger list 
		Assert( !StaticPropMgr()->IsStaticProp( pHandleEntity ) );

		IServerNetworkable *pNetworkable = static_cast<IServerNetworkable*>( pHandleEntity );
		Assert( pNetworkable );

		// Convert the IHandleEntity to an edict_t*...
		// Context is the thing we're testing everything against		
		edict_t* pTouch = pNetworkable->GetEdict();

		// Can't bump against itself
		if ( pTouch == m_pEnt )
			return ITERATION_CONTINUE;

		IServerEntity *serverEntity = pTouch->GetIServerEntity();
		if ( !serverEntity )
			return ITERATION_CONTINUE;

		// Hmmm.. everything in this list should be a trigger....
		ICollideable *pCollideable = serverEntity->GetCollideable();
		Assert(pCollideable->GetSolidFlags() & FSOLID_TRIGGER );
		if ( (pCollideable->GetSolidFlags() & FSOLID_TRIGGER) == 0 )
			return ITERATION_CONTINUE;

		model_t* pModel = sv.GetModel( pCollideable->GetCollisionModelIndex() );
		if ( pModel && pModel->type == mod_brush )
		{
			int headnode = SV_HullForEntity( pTouch );

			int contents;
			if (!m_Ray.m_IsSwept)
			{
				contents = CM_TransformedBoxContents( m_Ray.m_Start, m_mins, m_maxs,
					headnode, serverEntity->GetAbsOrigin(), serverEntity->GetAbsAngles() );
			}
			else
			{
				trace_t trace;
				CM_TransformedBoxTrace( m_Ray, headnode, MASK_ALL, serverEntity->GetAbsOrigin(), 
					serverEntity->GetAbsAngles(), trace );
				contents = trace.contents;
			}

			if ( !(contents & MASK_SOLID) )
				return ITERATION_CONTINUE;
		}

		m_TouchedEntities.AddToTail( pTouch );

		return ITERATION_CONTINUE;
	}
Esempio n. 11
0
//-----------------------------------------------------------------------------
// Returns an index from the given BaseEntity instance.
//-----------------------------------------------------------------------------
bool IndexFromBaseEntity( CBaseEntity *pBaseEntity, unsigned int& output )
{
    if (!pBaseEntity)
        return false;

    IServerNetworkable *pServerNetworkable = pBaseEntity->GetNetworkable();
    if (!pServerNetworkable)
        return false;

    edict_t* pEdict = pServerNetworkable->GetEdict();
    if (!pEdict || pEdict->IsFree())
        return false;

    return IndexFromEdict(pEdict, output);
}
Esempio n. 12
0
//-----------------------------------------------------------------------------
// Returns an Edict instance from the given BaseEntity instance.
//-----------------------------------------------------------------------------
bool EdictFromBaseEntity( CBaseEntity *pBaseEntity, edict_t*& output )
{
	if (!pBaseEntity)
		return false;
	
	IServerNetworkable *pServerNetworkable = pBaseEntity->GetNetworkable();
	if (!pServerNetworkable)
		return false;

	edict_t* pEdict = pServerNetworkable->GetEdict();
	if (!pEdict || pEdict->IsFree())
		return false;

	output = pEdict;
	return true;
}
Esempio n. 13
0
// creates an entity by string name, but does not spawn it
CBaseEntity *CreateEntityByName( const char *className, int iForceEdictIndex )
{
	if ( iForceEdictIndex != -1 )
	{
		g_pForceAttachEdict = engine->CreateEdict( iForceEdictIndex );
		if ( !g_pForceAttachEdict )
			Error( "CreateEntityByName( %s, %d ) - CreateEdict failed.", className, iForceEdictIndex );
	}

	IServerNetworkable *pNetwork = EntityFactoryDictionary()->Create( className );
	g_pForceAttachEdict = NULL;

	if ( !pNetwork )
		return NULL;

	CBaseEntity *pEntity = pNetwork->GetBaseEntity();
	Assert( pEntity );
	return pEntity;
}
Esempio n. 14
0
edict_t *CClassInterface::FindEntityByNetClassNearest(Vector vstart, const char *classname)
{
	edict_t *current;
	edict_t *pfound = NULL;
	float fMindist = 8192.0f;
	float fDist;

	for (short int i = 0; i < gpGlobals->maxEntities; i++)
	{
		current = engine->PEntityOfEntIndex(i);
		if (current == NULL)
		{
			continue;
		}
		if ( current->IsFree() )
			continue;
		if ( current->GetUnknown() == NULL )
			continue;
		
		IServerNetworkable *network = current->GetNetworkable();

		if (network == NULL)
		{
			continue;
		}

		ServerClass *sClass = network->GetServerClass();
		const char *name = sClass->GetName();
		
		if (strcmp(name, classname) == 0)
		{
			fDist = (vstart - CBotGlobals::entityOrigin(current)).Length();

			if ( !pfound  || (fDist < fMindist))
			{
				fMindist = fDist;
				pfound = current;
			}
		}
	}

	return pfound;
}
Esempio n. 15
0
static CBaseEntity *FindEntityByNetClass(int start, const char *classname)
{
	int maxEntities = gpGlobals->maxEntities;
	for (int i = start; i < maxEntities; i++)
	{
		edict_t *current = gamehelpers->EdictOfIndex(i);
		if (current == NULL || current->IsFree())
			continue;

		IServerNetworkable *network = current->GetNetworkable();
		if (network == NULL)
			continue;

		ServerClass *sClass = network->GetServerClass();
		const char *name = sClass->GetName();

		if (!strcmp(name, classname))
			return gamehelpers->ReferenceToEntity(gamehelpers->IndexOfEdict(current));		
	}

	return NULL;
}
Esempio n. 16
0
//-----------------------------------------------------------------------------
// Converts a user id to a collideable + username
//-----------------------------------------------------------------------------
void CEngineTraceServer::HandleEntityToCollideable( IHandleEntity *pHandleEntity, ICollideable **ppCollide, const char **ppDebugName )
{
	*ppCollide = StaticPropMgr()->GetStaticProp( pHandleEntity );
	if ( *ppCollide	)
	{
		*ppDebugName = "static prop";
		return;
	}

	IServerNetworkable *pServerNetworkable = static_cast<IServerNetworkable*>(pHandleEntity);
	if ( !pServerNetworkable )
	{
		*ppCollide = NULL;
		*ppDebugName = "<null>";
		return;
	}

	edict_t *pEdict = pServerNetworkable->GetEdict();
	Assert( pEdict );
	*ppCollide = pEdict->GetCollideable();
	*ppDebugName = pServerNetworkable->GetServerClass()->GetName();
}
Esempio n. 17
0
void SMJS_Entity::SetEntity(CBaseEntity *ent){
	if(this->ent != NULL){
		if(this->ent != ent){
			throw "Cannot set entity twice";
		}

		return;
	}

	this->valid = false;
	if(ent == NULL) return;

	this->ent = ent;

	IServerUnknown *pUnk = (IServerUnknown *)ent;
	IServerNetworkable *pNet = pUnk->GetNetworkable();
	if(pNet){
		edict = pNet->GetEdict();
		entIndex = gamehelpers->IndexOfEdict(edict);
	}

	this->valid = true;
}
edict_t *CSizzPluginContext::GetEntityByClassName( const char *name, int start_ent /*= 0*/ )
{
	if (name)
	{
		int max_ents = m_pGlobals->maxEntities;
		for (int i = start_ent; i < max_ents; ++i)
		{
			edict_t *pEdict = EdictFromEntIndex(i);
			if (pEdict && !pEdict->IsFree())
			{
				IServerNetworkable *pNetworkable = pEdict->GetNetworkable();
				if (pNetworkable)
				{
					ServerClass *pServerClass = pNetworkable->GetServerClass();
					if (pServerClass && SCHelpers::FStrEq(pServerClass->GetName(), name))
					{
						return pEdict;
					}
				}
			}
		}
	}
	return nullptr;
}
IServerEntity *CServerTools::GetIServerEntity( IClientEntity *pClientEntity )
{
	if ( pClientEntity == NULL )
		return NULL;

	CBaseHandle ehandle = pClientEntity->GetRefEHandle();
	if ( ehandle.GetEntryIndex() >= MAX_EDICTS )
		return NULL; // the first MAX_EDICTS entities are networked, the rest are client or server only

#if 0
	// this fails, since the server entities have extra bits in their serial numbers,
	// since 20 bits are reserved for serial numbers, except for networked entities, which are restricted to 10

	// Brian believes that everything should just restrict itself to 10 to make things simpler,
	// so if/when he changes NUM_SERIAL_NUM_BITS to 10, we can switch back to this simpler code

	IServerNetworkable *pNet = gEntList.GetServerNetworkable( ehandle );
	if ( pNet == NULL )
		return NULL;

	CBaseEntity *pServerEnt = pNet->GetBaseEntity();
	return pServerEnt;
#else
	IHandleEntity *pEnt = gEntList.LookupEntityByNetworkIndex( ehandle.GetEntryIndex() );
	if ( pEnt == NULL )
		return NULL;

	CBaseHandle h = gEntList.GetNetworkableHandle( ehandle.GetEntryIndex() );
	const int mask = ( 1 << NUM_NETWORKED_EHANDLE_SERIAL_NUMBER_BITS ) - 1;
	if ( !h.IsValid() || ( ( h.GetSerialNumber() & mask ) != ( ehandle.GetSerialNumber() & mask ) ) )
		return NULL;

	IServerUnknown *pUnk = static_cast< IServerUnknown* >( pEnt );
	return pUnk->GetBaseEntity();
#endif
}
CEntity *CEntityManager::CBaseEntityPostConstructor(CBaseEntity *pEntity, const char * szClassname )
{
	IServerNetworkable *pNetworkable = pEntity->GetNetworkable();
	Assert(pNetworkable);

	edict_t *pEdict = pNetworkable->GetEdict();

	if(strcmp(szClassname,"player") == 0 && engine->IndexOfEdict(pEdict) == 0)
	{
		return NULL;
	}

	IEntityFactory_CE **value = NULL;
	bool m_bShouldAddToCache = false;
	value = pCacheTrie.retrieve(szClassname);

	if(!value)
	{
		m_bShouldAddToCache = true;
		value = pFactoryTrie.retrieve(szClassname);
	}

	if (!value)
	{
		/* Attempt to do an RTTI lookup for C++ class links */
		IType *pType = GetType(pEntity);
		IBaseType *pBase = pType->GetBaseType();

		do 
		{
			const char *classname = GetTypeName(pBase->GetTypeInfo());
			value = pFactoryTrie.retrieve(classname);

			if (value)
			{
				break;
			}

		} while (pBase->GetNumBaseClasses() && (pBase = pBase->GetBaseClass(0)));

		pType->Destroy();
	}

	if (!value)
	{
		/* No specific handler for this entity */
		value = pFactoryTrie.retrieve("baseentity");
		assert(value);
	}

	IEntityFactory_CE *pFactory = *value;
	assert(pFactory);

	if(m_bShouldAddToCache)
	{
		pCacheTrie.insert(szClassname, pFactory);
	}

	CEntity *cent = pFactory->Create(pEdict, pEntity);

	char vtable[20];
	_snprintf(vtable, sizeof(vtable), "%x", (unsigned int) *(void **)pEntity);

	cent->ClearAllFlags();
	cent->InitProps();
	
	if (!pHookedTrie.retrieve(vtable))
	{
		cent->InitHooks();
		pHookedTrie.insert(vtable, true);
	}
	
	cent->InitDataMap();

	return cent;
}