CBaseEntity *CGlobalEntityList::NextEnt( CBaseEntity *pCurrentEnt ) { if ( !pCurrentEnt ) { const CEntInfo *pInfo = FirstEntInfo(); if ( !pInfo ) return NULL; return (CBaseEntity *)pInfo->m_pEntity; } // Run through the list until we get a CBaseEntity. const CEntInfo *pList = GetEntInfoPtr( pCurrentEnt->GetRefEHandle() ); if ( pList ) pList = NextEntInfo(pList); while ( pList ) { #if 0 if ( pList->m_pEntity ) { IServerUnknown *pUnk = static_cast<IServerUnknown*>(const_cast<IHandleEntity*>(pList->m_pEntity)); CBaseEntity *pRet = pUnk->GetBaseEntity(); if ( pRet ) return pRet; } #else return (CBaseEntity *)pList->m_pEntity; #endif pList = pList->m_pNext; } return NULL; }
/* Taken from Sourcemod Tf2 Extension */ CBaseEntity *UTIL_GetCBaseEntity(int num, bool onlyPlayers) { edict_t *pEdict = PEntityOfEntIndex(num); if (!pEdict || pEdict->IsFree()) { return NULL; } if (num > 0 && num <= playerhelpers->GetMaxClients()) { IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(pEdict); if (!pPlayer || !pPlayer->IsConnected()) { return NULL; } } else if (onlyPlayers) { return NULL; } IServerUnknown *pUnk; if ((pUnk=pEdict->GetUnknown()) == NULL) { return NULL; } return pUnk->GetBaseEntity(); }
void CHookManager::OnClientPutInServer(int client) { if (!PRCH_enabled) return; if (!PRCH_used) return; edict_t *pEdict = PEntityOfEntIndex(client); if (!pEdict) { return; } IServerUnknown *pUnknown = pEdict->GetUnknown(); if (!pUnknown) { return; } CBaseEntity *pEntity = pUnknown->GetBaseEntity(); if (!pEntity) { return; } SH_ADD_MANUALHOOK(PlayerRunCmdHook, pEntity, SH_MEMBER(this, &CHookManager::PlayerRunCmd), false); }
CBaseEntity *GetBaseEntity(int index) { IServerUnknown *pUnknown = LookupEntity(index); if(pUnknown == NULL) return NULL; return pUnknown->GetBaseEntity(); }
CBaseEntity *EdictToBaseEntity( edict_t *pEdict ) { if (pEdict) { IServerUnknown *pUnk = pEdict->GetUnknown(); if (pUnk) { return pUnk->GetBaseEntity(); } } return nullptr; }
//----------------------------------------------------------------------------- // Returns a BaseEntity instance from the given Edict instance. //----------------------------------------------------------------------------- bool BaseEntityFromEdict( edict_t *pEdict, CBaseEntity*& output ) { if (!pEdict || pEdict->IsFree()) return false; IServerUnknown *pServerUnknown = pEdict->GetUnknown(); if (!pServerUnknown) return false; output = pServerUnknown->GetBaseEntity(); return true; }
int ManiReservedSlot::FindPlayerToKick ( ) { // FIRST LOOK FOR BOTS! for ( int i = 1; i <= max_players; i++ ) { #if defined ( GAME_CSGO ) edict_t *pEdict = PEntityOfEntIndex(i); #else edict_t *pEdict = engine->PEntityOfEntIndex(i); #endif IServerUnknown *unknown = pEdict->GetUnknown(); if (!unknown) continue; CBaseEntity *base = unknown->GetBaseEntity(); if (!base) continue; IPlayerInfo *pi_player = playerinfomanager->GetPlayerInfo( pEdict ); if ( !pi_player ) continue; if ( FStrEq(pi_player->GetNetworkIDString(), "BOT") ) return i; } BuildPlayerKickList(); if ( active_player_list_size == 0 ) return 0; int KickMethod = mani_reserve_slots_kick_method.GetInt(); //0 = by ping //1 = by connection time //2 = by kills per minute //3 = kill/death ratio if ( KickMethod == 0 ) { qsort(active_player_list, active_player_list_size, sizeof(active_player_t), sort_active_players_by_ping); } else if ( KickMethod == 1 ) { qsort(active_player_list, active_player_list_size, sizeof(active_player_t), sort_active_players_by_connect_time); } else if ( KickMethod == 2 ) { qsort(active_player_list, active_player_list_size, sizeof(active_player_t), sort_active_players_by_kill_rate); } else if ( KickMethod == 3 ) { qsort(active_player_list, active_player_list_size, sizeof(active_player_t), sort_active_players_by_kd_ratio); } return active_player_list[0].index; }
int CPlayer::GetLifeState() { if (lifestate_offset == -1) { if (!g_pGameConf->GetOffset("m_lifeState", &lifestate_offset)) { lifestate_offset = -2; } } if (lifestate_offset < 0) { IPlayerInfo *info = GetPlayerInfo(); if (info == NULL) { return PLAYER_LIFE_UNKNOWN; } return info->IsDead() ? PLAYER_LIFE_DEAD : PLAYER_LIFE_ALIVE; } if (m_pEdict == NULL) { return PLAYER_LIFE_UNKNOWN; } CBaseEntity *pEntity; IServerUnknown *pUnknown = m_pEdict->GetUnknown(); if (pUnknown == NULL || (pEntity = pUnknown->GetBaseEntity()) == NULL) { return PLAYER_LIFE_UNKNOWN; } if (*((uint8_t *)pEntity + lifestate_offset) == LIFE_ALIVE) { return PLAYER_LIFE_ALIVE; } else { return PLAYER_LIFE_DEAD; } }
CBaseEntity *CHalfLife2::ReferenceToEntity(cell_t entRef) { if ((unsigned)entRef == INVALID_EHANDLE_INDEX) { return NULL; } CEntInfo *pInfo = NULL; if (entRef & (1<<31)) { /* Proper ent reference */ int hndlValue = entRef & ~(1<<31); CBaseHandle hndl(hndlValue); pInfo = LookupEntity(hndl.GetEntryIndex()); if (!pInfo || pInfo->m_SerialNumber != hndl.GetSerialNumber()) { return NULL; } } else { /* Old style index only */ pInfo = LookupEntity(entRef); } if (!pInfo) { return NULL; } IServerUnknown *pUnk = static_cast<IServerUnknown *>(pInfo->m_pEntity); if (pUnk) { return pUnk->GetBaseEntity(); } return NULL; }
const char *CHalfLife2::GetEntityClassname(edict_t * pEdict) { if (pEdict == NULL || pEdict->IsFree()) { return NULL; } IServerUnknown *pUnk = pEdict->GetUnknown(); if (pUnk == NULL) { return NULL; } CBaseEntity * pEntity = pUnk->GetBaseEntity(); if (pEntity == NULL) { return NULL; } return GetEntityClassname(pEntity); }
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 }
DataStatus DecodeValveParam(IPluginContext *pContext, cell_t param, const ValveCall *pCall, const ValvePassInfo *data, void *_buffer) { void *buffer = (unsigned char *)_buffer + data->offset; switch (data->vtype) { case Valve_Vector: { cell_t *addr; int err; err = pContext->LocalToPhysAddr(param, &addr); unsigned char *mem = (unsigned char *)buffer; if (data->type == PassType_Basic) { /* Store the object in the next N bytes, and store * a pointer to that object right beforehand. */ Vector **realPtr = (Vector **)buffer; if (addr == pContext->GetNullRef(SP_NULL_VECTOR)) { if (data->decflags & VDECODE_FLAG_ALLOWNULL) { *realPtr = NULL; return Data_Okay; } else { pContext->ThrowNativeError("NULL not allowed"); return Data_Fail; } } else { mem = (unsigned char *)_buffer + pCall->stackEnd + data->obj_offset; *realPtr = (Vector *)mem; } } if (err != SP_ERROR_NONE) { pContext->ThrowNativeErrorEx(err, "Could not read plugin data"); return Data_Fail; } /* Use placement new to initialize the object cleanly * This has no destructor so we don't need to do * DestroyValveParam() or something :] */ Vector *v = new (mem) Vector( sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2])); return Data_Okay; } case Valve_QAngle: { cell_t *addr; int err; err = pContext->LocalToPhysAddr(param, &addr); unsigned char *mem = (unsigned char *)buffer; if (data->type == PassType_Basic) { /* Store the object in the next N bytes, and store * a pointer to that object right beforehand. */ QAngle **realPtr = (QAngle **)buffer; if (addr == pContext->GetNullRef(SP_NULL_VECTOR)) { if (!(data->decflags & VDECODE_FLAG_ALLOWNULL)) { pContext->ThrowNativeError("NULL not allowed"); return Data_Fail; } else { *realPtr = NULL; return Data_Okay; } } else { mem = (unsigned char *)_buffer + pCall->stackEnd + data->obj_offset; *realPtr = (QAngle *)mem; } } if (err != SP_ERROR_NONE) { pContext->ThrowNativeErrorEx(err, "Could not read plugin data"); return Data_Fail; } /* Use placement new to initialize the object cleanly * This has no destructor so we don't need to do * DestroyValveParam() or something :] */ QAngle *v = new (mem) QAngle( sp_ctof(addr[0]), sp_ctof(addr[1]), sp_ctof(addr[2])); return Data_Okay; } case Valve_CBasePlayer: { edict_t *pEdict; if (data->decflags & VDECODE_FLAG_BYREF) { cell_t *addr; pContext->LocalToPhysAddr(param, &addr); param = *addr; } if (param >= 1 && param <= playerhelpers->GetMaxClients()) { IGamePlayer *player = playerhelpers->GetGamePlayer(param); if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME) && !player->IsConnected()) { pContext->ThrowNativeError("Client %d is not connected", param); return Data_Fail; } else if (!player->IsInGame()) { pContext->ThrowNativeError("Client %d is not in game", param); return Data_Fail; } pEdict = player->GetEdict(); } else if (param == -1) { if (data->decflags & VDECODE_FLAG_ALLOWNULL) { pEdict = NULL; } else { pContext->ThrowNativeError("NULL not allowed"); return Data_Fail; } } else if (param == 0) { if (data->decflags & VDECODE_FLAG_ALLOWWORLD) { pEdict = engine->PEntityOfEntIndex(0); } else { pContext->ThrowNativeError("World not allowed"); return Data_Fail; } } else { pContext->ThrowNativeError("Entity index %d is not a valid client", param); return Data_Fail; } CBaseEntity *pEntity = NULL; if (pEdict) { IServerUnknown *pUnknown = pEdict->GetUnknown(); if (!pUnknown) { pContext->ThrowNativeError("Entity %d is a not an IServerUnknown", param); return Data_Fail; } pEntity = pUnknown->GetBaseEntity(); if (!pEntity) { pContext->ThrowNativeError("Entity %d is not a CBaseEntity", param); return Data_Fail; } } CBaseEntity **ebuf = (CBaseEntity **)buffer; *ebuf = pEntity; return Data_Okay; } case Valve_CBaseEntity: { edict_t *pEdict; if (data->decflags & VDECODE_FLAG_BYREF) { cell_t *addr; pContext->LocalToPhysAddr(param, &addr); param = *addr; } if (param >= 1 && param <= playerhelpers->GetMaxClients()) { IGamePlayer *player = playerhelpers->GetGamePlayer(param); if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME) && !player->IsConnected()) { pContext->ThrowNativeError("Client %d is not connected", param); return Data_Fail; } else if (!player->IsInGame()) { pContext->ThrowNativeError("Client %d is not in game", param); return Data_Fail; } pEdict = player->GetEdict(); } else if (param == -1) { if (data->decflags & VDECODE_FLAG_ALLOWNULL) { pEdict = NULL; } else { pContext->ThrowNativeError("NULL not allowed"); return Data_Fail; } } else if (param == 0) { if (data->decflags & VDECODE_FLAG_ALLOWWORLD) { pEdict = engine->PEntityOfEntIndex(0); } else { pContext->ThrowNativeError("World not allowed"); return Data_Fail; } } else { pEdict = engine->PEntityOfEntIndex(param); if (!pEdict || pEdict->IsFree()) { pContext->ThrowNativeError("Entity %d is not valid or is freed", param); return Data_Fail; } } CBaseEntity *pEntity = NULL; if (pEdict) { IServerUnknown *pUnknown = pEdict->GetUnknown(); if (!pUnknown) { pContext->ThrowNativeError("Entity %d is a not an IServerUnknown", param); return Data_Fail; } pEntity = pUnknown->GetBaseEntity(); if (!pEntity) { pContext->ThrowNativeError("Entity %d is not a CBaseEntity", param); return Data_Fail; } } CBaseEntity **ebuf = (CBaseEntity **)buffer; *ebuf = pEntity; return Data_Okay; } case Valve_Edict: { edict_t *pEdict; if (data->decflags & VDECODE_FLAG_BYREF) { cell_t *addr; pContext->LocalToPhysAddr(param, &addr); param = *addr; } if (param >= 1 && param <= playerhelpers->GetMaxClients()) { IGamePlayer *player = playerhelpers->GetGamePlayer(param); if ((data->decflags & VDECODE_FLAG_ALLOWNOTINGAME) && !player->IsConnected()) { pContext->ThrowNativeError("Client %d is not connected", param); return Data_Fail; } else if (!player->IsInGame()) { pContext->ThrowNativeError("Client %d is not in game", param); return Data_Fail; } pEdict = player->GetEdict(); } else if (param == -1) { if (data->decflags & VDECODE_FLAG_ALLOWNULL) { pEdict = NULL; } else { pContext->ThrowNativeError("NULL not allowed"); return Data_Fail; } } else if (param == 0) { if (data->decflags & VDECODE_FLAG_ALLOWWORLD) { pEdict = engine->PEntityOfEntIndex(0); } else { pContext->ThrowNativeError("World not allowed"); return Data_Fail; } } else { pEdict = engine->PEntityOfEntIndex(param); if (!pEdict || pEdict->IsFree()) { pContext->ThrowNativeError("Entity %d is not valid or is freed", param); return Data_Fail; } } edict_t **ebuf = (edict_t **)buffer; *ebuf = pEdict; return Data_Okay; } case Valve_POD: case Valve_Float: { if (data->decflags & VDECODE_FLAG_BYREF) { cell_t *addr; pContext->LocalToPhysAddr(param, &addr); param = *addr; } if (data->flags & PASSFLAG_ASPOINTER) { *(void **)buffer = (unsigned char *)_buffer + pCall->stackEnd + data->obj_offset; buffer = *(void **)buffer; } *(cell_t *)buffer = param; return Data_Okay; } case Valve_Bool: { if (data->decflags & VDECODE_FLAG_BYREF) { cell_t *addr; pContext->LocalToPhysAddr(param, &addr); param = *addr; } if (data->flags & PASSFLAG_ASPOINTER) { *(bool **)buffer = (bool *)((unsigned char *)_buffer + pCall->stackEnd + data->obj_offset); buffer = *(bool **)buffer; } *(bool *)buffer = param ? true : false; return Data_Okay; } case Valve_String: { char *addr; pContext->LocalToString(param, &addr); *(char **)buffer = addr; return Data_Okay; } } return Data_Fail; }