static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params) { int client = params[1]; IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); } else if (!pPlayer->IsInGame()) { return pContext->ThrowNativeError("Client %d is not in game", client); } IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); if (!pInfo) { return pContext->ThrowNativeError("IPlayerInfo not supported by game"); } cell_t *pVec; pContext->LocalToPhysAddr(params[2], &pVec); float x, y, z; bridge->playerInfo->GetPlayerMaxs(pInfo, &x, &y, &z); pVec[0] = sp_ftoc(x); pVec[1] = sp_ftoc(y); pVec[2] = sp_ftoc(z); return 1; }
void ConsoleVariableType::SendValueToClient(int clientIndex, std::string value) { if(clientIndex < 1 || clientIndex > g_Interfaces.GlobalVarsInstance->maxClients) { throw ClientIndexOutOfRangeExceptionType(clientIndex, g_Interfaces.GlobalVarsInstance->maxClients); } char data[256]; bf_write buffer(data, sizeof(data)); buffer.WriteUBitLong(NET_SETCONVAR, NETMSG_BITS); buffer.WriteByte(1); buffer.WriteString(ConVarInstance->GetName()); buffer.WriteString(value.c_str()); IGamePlayer *gamePlayer = playerhelpers->GetGamePlayer(clientIndex); if(!gamePlayer->IsConnected()) { throw ClientNotConnectedExceptionType(clientIndex); } if(gamePlayer->IsFakeClient()) { throw ClientIsFakeExceptionType(clientIndex); } INetChannel *netchan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(clientIndex)); if (netchan == NULL) { throw ClientDataNotAvailableExceptionType(clientIndex, "net_chan"); } netchan->SendData(buffer); }
bool InitialiseConditionChecks() { sm_sendprop_info_t prop; if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCond", &prop)) { g_pSM->LogError(myself, "Failed to find m_nPlayerCond prop offset"); return false; } playerCondOffset = prop.actual_offset; if (!gamehelpers->FindSendPropInfo("CTFPlayer", "_condition_bits", &prop)) { g_pSM->LogError(myself, "Failed to find _condition_bits prop offset"); return false; } conditionBitsOffset = prop.actual_offset; if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCondEx", &prop)) { g_pSM->LogError(myself, "Failed to find m_nPlayerCondEx prop offset"); return false; } playerCondExOffset = prop.actual_offset; if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCondEx2", &prop)) { g_pSM->LogError(myself, "Failed to find m_nPlayerCondEx2 prop offset"); return false; } playerCondEx2Offset = prop.actual_offset; if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCondEx3", &prop)) { g_pSM->LogError(myself, "Failed to find m_nPlayerCondEx3 prop offset"); return false; } playerCondEx3Offset = prop.actual_offset; if (playerCondOffset == -1 || playerCondExOffset == -1 || conditionBitsOffset == -1 || playerCondEx2Offset == -1 || playerCondEx3Offset == -1) return false; int maxClients = gpGlobals->maxClients; for (int i = 1; i <= maxClients; i++) { IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i); if (!pPlayer || !pPlayer->IsInGame()) continue; GetPlayerConds(gamehelpers->ReferenceToEntity(i), &g_PlayerActiveConds[i]); } g_pSM->AddGameFrameHook(Conditions_OnGameFrame); return true; }
static cell_t DisplayTopMenu(IPluginContext *pContext, const cell_t *params) { HandleError err; ITopMenu *pMenu; HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity()); if ((err = handlesys->ReadHandle(params[1], hTopMenuType, &sec, (void **)&pMenu)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); } int client = params[2]; IGamePlayer *player = playerhelpers->GetGamePlayer(client); if (!player) { return pContext->ThrowNativeError("Invalid client index %d", client); } else if (!player->IsInGame()) { return pContext->ThrowNativeError("Client %d is not in game", client); } return pMenu->DisplayMenu(client, 0, (TopMenuPosition)params[3]); }
static cell_t GetClientEyePosition(IPluginContext *pContext, const cell_t *params) { IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); if (player == NULL) { return pContext->ThrowNativeError("Invalid client index %d", params[1]); } if (!player->IsInGame()) { return pContext->ThrowNativeError("Client %d is not in game", params[1]); } Vector pos; #if SOURCE_ENGINE == SE_DOTA serverClients->ClientEarPosition(params[1], &pos); #else serverClients->ClientEarPosition(player->GetEdict(), &pos); #endif cell_t *addr; pContext->LocalToPhysAddr(params[2], &addr); addr[0] = sp_ftoc(pos.x); addr[1] = sp_ftoc(pos.y); addr[2] = sp_ftoc(pos.z); return 1; }
bool PlayerConditionsMgr::Init() { memset(m_BackupProxyFns, 0, sizeof(m_BackupProxyFns)); bool bFoundProps = SetupProp<m_nPlayerCond>("m_nPlayerCond") && SetupProp<_condition_bits>("_condition_bits") && SetupProp<m_nPlayerCondEx>("m_nPlayerCondEx") && SetupProp<m_nPlayerCondEx2>("m_nPlayerCondEx2") && SetupProp<m_nPlayerCondEx3>("m_nPlayerCondEx3") && SetupProp<m_nPlayerCondEx4>("m_nPlayerCondEx4"); if (!bFoundProps) return false; playerhelpers->AddClientListener(this); int maxClients = gpGlobals->maxClients; for (int i = 1; i <= maxClients; i++) { IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i); if (!pPlayer || !pPlayer->IsInGame()) continue; CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i); for (size_t j = 0; j < CondVar_Count; ++j) { m_OldConds[i][j] = *(int *)((intp) pEntity + GetPropOffs((CondVar)j)); } } return true; }
static cell_t SetClientViewEntity(IPluginContext *pContext, const cell_t *params) { IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); if (player == NULL) { return pContext->ThrowNativeError("Invalid client index %d", params[1]); } if (!player->IsInGame()) { return pContext->ThrowNativeError("Client %d is not in game", params[1]); } edict_t *pEdict = PEntityOfEntIndex(gamehelpers->ReferenceToIndex(params[2])); if (!pEdict || pEdict->IsFree()) { return pContext->ThrowNativeError("Entity %d is not valid", params[2]); } #if SOURCE_ENGINE == SE_DOTA engine->SetView(params[1], params[2]); #else engine->SetView(player->GetEdict(), pEdict); #endif return 1; }
static cell_t GetPlayerDecalFile(IPluginContext *pContext, const cell_t *params) { IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); if (player == NULL) { return pContext->ThrowNativeError("Invalid client index %d", params[1]); } if (!player->IsInGame()) { return pContext->ThrowNativeError("Client %d is not in game", params[1]); } player_info_t info; char *buffer; if (!GetPlayerInfo(params[1], &info) || !info.customFiles[0]) { return 0; } pContext->LocalToString(params[2], &buffer); Q_binarytohex((byte *)&info.customFiles[0], sizeof(info.customFiles[0]), buffer, params[3]); return 1; }
bool BaseBuiltinVoteStyle::DoClientVote(int clients[], unsigned int num_clients, IBaseBuiltinVote *vote, IBuiltinVoteHandler *bvh) { unsigned int totalPlayers = 0; int realClients[256+1]; for (unsigned int i=0; i<num_clients;i++) { IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(clients[i]); CBaseBuiltinVotePlayer *player = GetVotePlayer(clients[i]); vote_states_t &states = player->states; if (!pPlayer || pPlayer->IsFakeClient() || !pPlayer->IsInGame()) { states.vote = NULL; states.bvh = NULL; continue; } states.vote = vote; states.bvh = bvh; states.apiVers = SMINTERFACE_BUILTINVOTES_VERSION; realClients[totalPlayers++] = clients[i]; } if (totalPlayers > 0) { vote->Display(realClients, totalPlayers); //SendDisplay(realClients, totalPlayers, vote); return true; } else { return false; } }
static cell_t sm_GetStatFloat(IPluginContext *pContext, const cell_t *params) { ISteamGameServerStats *pStats = GetServerStatsPointer(); if (pStats == NULL) { return 0; } int client = gamehelpers->ReferenceToIndex(params[1]); IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); /* Man, including GameHelpers and PlayerHelpers for this native :(. */ if (pPlayer == NULL || pPlayer->IsConnected() == false) { return pContext->ThrowNativeError("Client index %d is invalid", params[1]); } char *pName; pContext->LocalToString(params[2], &pName); cell_t *pValue; pContext->LocalToPhysAddr(params[3], &pValue); CSteamID checkid = CreateCommonCSteamID(pPlayer, params, 4, 5); float fValue; bool bResult = pStats->GetUserStat(checkid, pName, &fValue); *pValue = sp_ftoc(fValue); return bResult ? 1 : 0; }
static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params) { int client = params[1]; IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); } if (!pPlayer->IsConnected()) { return pContext->ThrowNativeError("Client %d is not connected", client); } char *key; pContext->LocalToString(params[2], &key); const char *val = engine->GetClientConVarValue(client, key); if (!val) { return false; } pContext->StringToLocalUTF8(params[3], params[4], val, NULL); return 1; }
static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params) { int index = params[1]; if (index == 0) { static ConVar *hostname = NULL; if (!hostname) { hostname = bridge->FindConVar("hostname"); if (!hostname) { return pCtx->ThrowNativeError("Could not find \"hostname\" cvar"); } } pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), bridge->GetCvarString(hostname), NULL); return 1; } if ((index < 1) || (index > playerhelpers->GetMaxClients())) { return pCtx->ThrowNativeError("Client index %d is invalid", index); } IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); if (!pPlayer->IsConnected()) { return pCtx->ThrowNativeError("Client %d is not connected", index); } pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->GetName(), NULL); return 1; }
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) { int index = params[1]; if ((index < 1) || (index > playerhelpers->GetMaxClients())) { return pCtx->ThrowNativeError("Client index %d is invalid", index); } IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); if (!pPlayer->IsConnected()) { return pCtx->ThrowNativeError("Client %d is not connected", index); } char buf[64], *ptr; strcpy(buf, pPlayer->GetIPAddress()); if (params[4] && (ptr = strchr(buf, ':'))) { *ptr = '\0'; } pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf); return 1; }
/* 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(); }
static cell_t KickClientEx(IPluginContext *pContext, const cell_t *params) { int client = params[1]; IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); } else if (!pPlayer->IsConnected()) { return pContext->ThrowNativeError("Client %d is not connected", client); } g_pSM->SetGlobalTarget(client); char buffer[256]; { DetectExceptions eh(pContext); g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2); if (eh.HasException()) return 0; } pPlayer->Kick(buffer); return 1; }
static cell_t FadeClientVolume(IPluginContext *pContext, const cell_t *params) { int client = params[1]; if (client < 1 || client > playerhelpers->GetMaxClients()) { return pContext->ThrowNativeError("Client index %d is not valid", client); } IGamePlayer *player = playerhelpers->GetGamePlayer(client); if (!player->IsInGame()) { return pContext->ThrowNativeError("Client index %d is not in game", client); } engine->FadeClientVolume( #if SOURCE_ENGINE == SE_DOTA player->GetIndex(), #else player->GetEdict(), #endif sp_ctof(params[2]), sp_ctof(params[3]), sp_ctof(params[4]), sp_ctof(params[5])); return 1; }
static cell_t GetClientEyeAngles(IPluginContext *pContext, const cell_t *params) { IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]); if (!pPlayer) { return pContext->ThrowNativeError("Invalid client index %d", params[1]); } else if (!pPlayer->IsInGame()) { return pContext->ThrowNativeError("Client %d is not in game", params[1]); } edict_t *pEdict = pPlayer->GetEdict(); CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL; /* We always set the angles for backwards compatibility -- * The original function had no return value. */ QAngle angles; bool got_angles = false; if (pEntity != NULL) { got_angles = GetEyeAngles(pEntity, &angles); } cell_t *addr; pContext->LocalToPhysAddr(params[2], &addr); addr[0] = sp_ftoc(angles.x); addr[1] = sp_ftoc(angles.y); addr[2] = sp_ftoc(angles.z); return got_angles ? 1 : 0; }
static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params) { int client = params[1]; IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); } if (!pPlayer->IsConnected()) { return pContext->ThrowNativeError("Client %d is not connected", client); } AdminId id; if ((id = pPlayer->GetAdminId()) == INVALID_ADMIN_ID) { return 0; } cell_t *addr; for (int i = 2; i <= params[0]; i++) { pContext->LocalToPhysAddr(params[i], &addr); adminsys->SetAdminFlag(id, (AdminFlag) *addr, false); } return 1; }
bool ProcessCommandTarget(cmd_target_info_t *info) { List<SimpleMultiTargetFilter *>::iterator iter; for (iter = simpleMultis.begin(); iter != simpleMultis.end(); iter++) { SimpleMultiTargetFilter *smtf = (*iter); if (strcmp(smtf->pattern.c_str(), info->pattern) == 0) { CellArray *array = new CellArray(1); HandleSecurity sec(g_pCoreIdent, g_pCoreIdent); Handle_t hndl = handlesys->CreateHandleEx(htCellArray, array, &sec, NULL, NULL); AutoHandleCloner ahc(hndl, sec); if (ahc.getClone() == BAD_HANDLE) { smcore.LogError("[SM] Could not allocate a handle (%s, %d)", __FILE__, __LINE__); delete array; return false; } smtf->fun->PushString(info->pattern); smtf->fun->PushCell(ahc.getClone()); cell_t result = 0; if (smtf->fun->Execute(&result) != SP_ERROR_NONE || !result) return false; IGamePlayer *pAdmin = info->admin ? playerhelpers->GetGamePlayer(info->admin) : NULL; info->num_targets = 0; for (size_t i = 0; i < array->size(); i++) { cell_t client = *array->at(i); IGamePlayer *pClient = playerhelpers->GetGamePlayer(client); if (pClient == NULL || !pClient->IsConnected()) continue; if (playerhelpers->FilterCommandTarget(pAdmin, pClient, info->flags) == COMMAND_TARGET_VALID) { info->targets[info->num_targets++] = client; if (info->num_targets >= unsigned(info->max_targets)) break; } } info->reason = info->num_targets > 0 ? COMMAND_TARGET_VALID : COMMAND_TARGET_EMPTY_FILTER; if (info->num_targets) { smcore.strncopy(info->target_name, smtf->phrase.c_str(), info->target_name_maxlength); info->target_name_style = smtf->phraseIsML ? COMMAND_TARGETNAME_ML : COMMAND_TARGETNAME_RAW; } return true; } } return false; }
int GetClientAimTarget(edict_t *pEdict, bool only_players) { CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL; if (pEntity == NULL) { return -1; } Vector eye_position; QAngle eye_angles; /* Get the private information we need */ #if SOURCE_ENGINE == SE_DOTA serverClients->ClientEarPosition(IndexOfEdict(pEdict), &eye_position); #else serverClients->ClientEarPosition(pEdict, &eye_position); #endif if (!GetEyeAngles(pEntity, &eye_angles)) { return -2; } Vector aim_dir; AngleVectors(eye_angles, &aim_dir); VectorNormalize(aim_dir); Vector vec_end = eye_position + aim_dir * 8000; Ray_t ray; ray.Init(eye_position, vec_end); trace_t tr; CTraceFilterSimple simple(pEdict->GetIServerEntity()); enginetrace->TraceRay(ray, MASK_SOLID|CONTENTS_DEBRIS|CONTENTS_HITBOX, &simple, &tr); if (tr.fraction == 1.0f || tr.m_pEnt == NULL) { return -1; } int ent_ref = gamehelpers->EntityToBCompatRef(tr.m_pEnt); int ent_index = gamehelpers->ReferenceToIndex(ent_ref); IGamePlayer *pTargetPlayer = playerhelpers->GetGamePlayer(ent_index); if (pTargetPlayer != NULL && !pTargetPlayer->IsInGame()) { return -1; } else if (only_players && pTargetPlayer == NULL) { return -1; } return ent_ref; }
bool TopMenu::DisplayMenu(int client, unsigned int hold_time, TopMenuPosition position) { if (m_clients == NULL) { return false; } IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); if (!pPlayer->IsInGame()) { return false; } UpdateClientRoot(client, pPlayer); /* This is unfortunate but it's the best solution. */ for (size_t i = 0; i < m_Categories.size(); i++) { UpdateClientCategory(client, i, true); } topmenu_player_t *pClient = &m_clients[client]; if (pClient->root == NULL) { return false; } if (!m_bCacheTitles) { char renderbuf[128]; m_pTitle->OnTopMenuDisplayTitle(this, client, 0, renderbuf, sizeof(renderbuf)); pClient->root->SetDefaultTitle(renderbuf); } bool return_value = false; if (position == TopMenuPosition_LastCategory && pClient->last_category < m_Categories.size()) { return_value = DisplayCategory(client, pClient->last_category, hold_time, true); if (!return_value) { return_value = pClient->root->DisplayAtItem(client, hold_time, pClient->last_root_pos); } } else if (position == TopMenuPosition_LastRoot) { pClient->root->DisplayAtItem(client, hold_time, pClient->last_root_pos); } else if (position == TopMenuPosition_Start) { pClient->last_position = 0; pClient->last_category = 0; return_value = pClient->root->Display(client, hold_time); } return return_value; }
/** * @brief Called when a client is authorized. * * @param client Index of the client. * @param authstring His SteamID. */ void Left4Downtown::OnClientAuthorized(int client, const char *authstring) { /* Credits to Scott "DS" Ehlert from the SourceMod Dev Team for providing me with this super-easy method of selective event broadcasting. If it wasn't for him, I'd be stuck with a bunch of nasty code -- i.e. my initial idea of a NET_SendPacket vcall(bitbuffers, serializing events, casting IPs to netadr_t etc.) /blog */ if (!g_AddonsEclipse.GetBool()) { L4D_DEBUG_LOG("l4d2_addons_eclipse set to 0, skipping function"); return; } IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); if (pPlayer->IsFakeClient()) { L4D_DEBUG_LOG("Fake client %d connected, ignoring...", client); return; } cell_t result = Pl_Continue; if (g_pFwdOnAddonsEclipseUpdate) { g_pFwdOnAddonsEclipseUpdate->PushCell(client); g_pFwdOnAddonsEclipseUpdate->Execute(&result); if(result == Pl_Handled) { L4D_DEBUG_LOG("L4D2_OnAddonsEclipseUpdate(%d) will be skipped", client); return; } L4D_DEBUG_LOG("L4D2_OnAddonsEclipseUpdate(%d) has been sent out...", client); } // Getting the client event listener INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(client)); IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler()); unsigned char *pBaseClient = reinterpret_cast<unsigned char *>(pClient) - 4; IGameEventListener2 *pClientListener = reinterpret_cast<IGameEventListener2 *>(pBaseClient); // Firing our event; it will tell the client to unload his addons IGameEvent *pEvent = gameeventmanager->CreateEvent("server_spawn"); if (pEvent) { pEvent->SetString("address", "159.253.143.194:0"); pEvent->SetString("mapname", STRING(gpGlobals->mapname)); pClientListener->FireGameEvent(pEvent); L4D_DEBUG_LOG("Fired event for client %d", client); } // When done with event, must destroy it manually gameeventmanager->FreeEvent(pEvent); }
void CookieManager::OnClientDisconnecting(int client) { connected[client] = false; statsLoaded[client] = false; SourceHook::List<CookieData *>::iterator _iter; CookieData *current; _iter = clientData[client].begin(); while (_iter != clientData[client].end()) { current = (CookieData *)*_iter; if (!current->changed) { current->parent->data[client] = NULL; delete current; _iter = clientData[client].erase(_iter); continue; } /* Save this cookie to the database */ IGamePlayer *player = playerhelpers->GetGamePlayer(client); if (player == NULL) { /* panic! */ return; } int dbId = current->parent->dbid; if (dbId == -1) { /* Insert/Find Query must be still running or failed. */ return; } TQueryOp *op = new TQueryOp(Query_InsertData, client); strcpy(op->m_params.steamId, player->GetAuthString()); op->m_params.cookieId = dbId; op->m_params.data = current; g_ClientPrefs.AddQueryToQueue(op); current->parent->data[client] = NULL; /* We don't delete here, it will be removed when the query is completed */ _iter = clientData[client].erase(_iter); } }
static cell_t sm_GetClientLanguage(IPluginContext *pContext, const cell_t *params) { IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); if (!player || !player->IsConnected()) { return pContext->ThrowNativeError("Invalid client index %d", params[1]); } return g_Translator.GetClientLanguage(params[1]); }
static cell_t sm_GetClientSerial(IPluginContext *pContext, const cell_t *params) { int client = params[1]; IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); } return pPlayer->GetSerial(); }
static cell_t SetClientName(IPluginContext *pContext, const cell_t *params) { if (iserver == NULL) { return pContext->ThrowNativeError("IServer interface not supported, file a bug report."); } IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); IClient *pClient = iserver->GetClient(params[1] - 1); if (player == NULL || pClient == NULL) { return pContext->ThrowNativeError("Invalid client index %d", params[1]); } if (!player->IsConnected()) { return pContext->ThrowNativeError("Client %d is not connected", params[1]); } static ValveCall *pCall = NULL; if (!pCall) { ValvePassInfo params[1]; InitPass(params[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL); if (!CreateBaseCall("SetClientName", ValveCall_Entity, NULL, params, 1, &pCall)) { return pContext->ThrowNativeError("\"SetClientName\" not supported by this mod"); } else if (!pCall) { return pContext->ThrowNativeError("\"SetClientName\" wrapper failed to initialize"); } } // The IClient vtable is +4 from the CBaseClient vtable due to multiple inheritance. void *pGameClient = (void *)((intptr_t)pClient - 4); // Change the name in the engine. START_CALL(); void **ebuf = (void **)vptr; *ebuf = pGameClient; DECODE_VALVE_PARAM(2, vparams, 0); FINISH_CALL_SIMPLE(NULL); // Notify the server of the change. serverClients->ClientSettingsChanged(player->GetEdict()); return 1; }
static cell_t sm_GetClientAimTarget(IPluginContext *pContext, const cell_t *params) { IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]); if (!pPlayer) { return pContext->ThrowNativeError("Invalid client index %d", params[1]); } else if (!pPlayer->IsInGame()) { return pContext->ThrowNativeError("Client %d is not in game", params[1]); } return GetClientAimTarget(pPlayer->GetEdict(), params[2] ? true : false); }
DETOUR_DECL_MEMBER1(GetEventChangeAttributes, int, char const*, attribute) { int index = gamehelpers->EntityToBCompatRef(reinterpret_cast<CBaseEntity *>(this)); if (index > 0 && index <= playerhelpers->GetMaxClients()) { IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); if (pPlayer->IsConnected() && pPlayer->IsInGame() && !pPlayer->IsFakeClient()) { return 0; } } return DETOUR_MEMBER_CALL(GetEventChangeAttributes)(attribute); }
static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params) { int client = params[1]; IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); if (!pPlayer) { return pContext->ThrowNativeError("Client index %d is invalid", client); } if (!pPlayer->IsConnected()) { return pContext->ThrowNativeError("Client %d is not connected", client); } return pPlayer->GetUserId(); }
static cell_t sm_IsClientReplay(IPluginContext *pCtx, const cell_t *params) { int index = params[1]; if ((index < 1) || (index > playerhelpers->GetMaxClients())) { return pCtx->ThrowNativeError("Client index %d is invalid", index); } IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); if (!pPlayer->IsConnected()) { return pCtx->ThrowNativeError("Client %d is not connected", index); } return (pPlayer->IsReplay()) ? 1 : 0; }