diff --git a/sdk b/sdk index fec44c3e..bcfffa73 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit fec44c3e820c8a4c428faaf5bf1698e7b8727888 +Subproject commit bcfffa737a1b5dc649a502bf56c98a631bc00c5f diff --git a/src/adminsystem.cpp b/src/adminsystem.cpp index b67e6114..02e8eb4a 100644 --- a/src/adminsystem.cpp +++ b/src/adminsystem.cpp @@ -125,8 +125,7 @@ CON_COMMAND_CHAT_FLAGS(ban, "ban a player", ADMFLAG_BAN) ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX"Invalid duration."); return; } - - CBasePlayerController* pTarget = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[0] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[0]); if (!pTarget) return; @@ -199,7 +198,7 @@ CON_COMMAND_CHAT_FLAGS(mute, "mutes a player", ADMFLAG_CHAT) for (int i = 0; i < iNumClients; i++) { - CBasePlayerController* pTarget = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); if (!pTarget) continue; @@ -252,7 +251,7 @@ CON_COMMAND_CHAT_FLAGS(unmute, "unmutes a player", ADMFLAG_CHAT) for (int i = 0; i < iNumClients; i++) { - CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); if (!pTarget) continue; @@ -318,7 +317,7 @@ CON_COMMAND_CHAT_FLAGS(gag, "gag a player", ADMFLAG_CHAT) for (int i = 0; i < iNumClients; i++) { - CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); if (!pTarget) continue; @@ -373,7 +372,7 @@ CON_COMMAND_CHAT_FLAGS(ungag, "ungags a player", ADMFLAG_CHAT) for (int i = 0; i < iNumClients; i++) { - CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); if (!pTarget) continue; @@ -422,7 +421,7 @@ CON_COMMAND_CHAT_FLAGS(kick, "kick a player", ADMFLAG_KICK) for (int i = 0; i < iNumClients; i++) { - CBasePlayerController* pTarget = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlot[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlot[i]); if (!pTarget) continue; @@ -459,7 +458,7 @@ CON_COMMAND_CHAT_FLAGS(slay, "slay a player", ADMFLAG_SLAY) for (int i = 0; i < iNumClients; i++) { - CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); if (!pTarget) continue; @@ -505,7 +504,7 @@ CON_COMMAND_CHAT_FLAGS(goto, "teleport to a player", ADMFLAG_SLAY) for (int i = 0; i < iNumClients; i++) { - CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); if (!pTarget) continue; @@ -545,7 +544,7 @@ CON_COMMAND_CHAT_FLAGS(bring, "bring a player", ADMFLAG_SLAY) for (int i = 0; i < iNumClients; i++) { - CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); if (!pTarget) continue; @@ -598,7 +597,7 @@ CON_COMMAND_CHAT_FLAGS(setteam, "set a player's team", ADMFLAG_SLAY) for (int i = 0; i < iNumClients; i++) { - CCSPlayerController *pTarget = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); if (!pTarget) continue; diff --git a/src/commands.cpp b/src/commands.cpp index 7d34cf62..4cf15c85 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -369,16 +369,16 @@ CON_COMMAND_CHAT(message, "message someone") // Note that the engine will treat this as a player slot number, not an entity index int uid = atoi(args[1]); - CBasePlayerController *target = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(uid + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(uid); - if (!target) + if (!pTarget) return; // skipping the id and space, it's dumb but w/e const char *pMessage = args.ArgS() + V_strlen(args[1]) + 1; char buf[256]; - V_snprintf(buf, sizeof(buf), CHAT_PREFIX"Private message from %s to %s: \5%s", player->GetPlayerName(), target->GetPlayerName(), pMessage); + V_snprintf(buf, sizeof(buf), CHAT_PREFIX"Private message from %s to %s: \5%s", player->GetPlayerName(), pTarget->GetPlayerName(), pMessage); CSingleRecipientFilter filter(uid); @@ -428,7 +428,7 @@ CON_COMMAND_CHAT(test_target, "test string targetting") for (int i = 0; i < iNumClients; i++) { - CBasePlayerController* pTarget = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); if (!pTarget) continue; @@ -501,7 +501,7 @@ CON_COMMAND_CHAT(setcollisiongroup, "set a player's collision group") for (int i = 0; i < iNumClients; i++) { - CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); if (!pTarget) continue; @@ -526,7 +526,7 @@ CON_COMMAND_CHAT(setsolidtype, "set a player's solid type") for (int i = 0; i < iNumClients; i++) { - CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); if (!pTarget) continue; @@ -550,7 +550,7 @@ CON_COMMAND_CHAT(setinteraction, "set a player's interaction flags") for (int i = 0; i < iNumClients; i++) { - CBasePlayerController *pTarget = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(pSlots[i] + 1)); + CCSPlayerController* pTarget = CCSPlayerController::FromSlot(pSlots[i]); if (!pTarget) continue; diff --git a/src/cs2_sdk/entity/ccsplayercontroller.h b/src/cs2_sdk/entity/ccsplayercontroller.h index 4a68142c..c314be96 100644 --- a/src/cs2_sdk/entity/ccsplayercontroller.h +++ b/src/cs2_sdk/entity/ccsplayercontroller.h @@ -21,6 +21,9 @@ #include "cbaseplayercontroller.h" #include "services.h" +#include "../playermanager.h" + +extern CEntitySystem* g_pEntitySystem; class CCSPlayerController : public CBasePlayerController { @@ -31,7 +34,19 @@ class CCSPlayerController : public CBasePlayerController SCHEMA_FIELD(CCSPlayerController_ActionTrackingServices*, m_pActionTrackingServices) SCHEMA_FIELD(bool, m_bPawnIsAlive); - static CCSPlayerController* FromPawn(CCSPlayerPawn* pawn) { return (CCSPlayerController*)pawn->m_hController().Get(); } + static CCSPlayerController* FromPawn(CCSPlayerPawn* pawn) { + return (CCSPlayerController*)pawn->m_hController().Get(); + } + + static CCSPlayerController* FromSlot(CPlayerSlot slot) + { + return (CCSPlayerController*)g_pEntitySystem->GetBaseEntity(CEntityIndex(slot.Get() + 1)); + } + + ZEPlayer* GetZEPlayer() + { + return g_playerManager->GetPlayer(GetPlayerSlot()); + } void ChangeTeam(int iTeam) { diff --git a/src/cs2fixes.cpp b/src/cs2fixes.cpp index c0b90c79..b445514d 100644 --- a/src/cs2fixes.cpp +++ b/src/cs2fixes.cpp @@ -468,7 +468,7 @@ void CS2Fixes::Hook_CheckTransmit(CCheckTransmitInfo **ppInfoList, int infoCount // though this is probably part of the client class that contains the CCheckTransmitInfo int iPlayerSlot = (int)*((uint8 *)pInfo + 560); - auto pSelfController = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(iPlayerSlot + 1)); + CCSPlayerController* pSelfController = CCSPlayerController::FromSlot(iPlayerSlot); if (!pSelfController || !pSelfController->IsConnected() || !pSelfController->m_bPawnIsAlive) continue; @@ -483,12 +483,12 @@ void CS2Fixes::Hook_CheckTransmit(CCheckTransmitInfo **ppInfoList, int infoCount if (!pSelfZEPlayer) continue; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 0; i < gpGlobals->maxClients; i++) { - if (!pSelfZEPlayer->ShouldBlockTransmit(i - 1)) + if (!pSelfZEPlayer->ShouldBlockTransmit(i)) continue; - auto pController = (CBasePlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)i); + CCSPlayerController* pController = CCSPlayerController::FromSlot(i); if (!pController) continue; diff --git a/src/detours.cpp b/src/detours.cpp index b839c54e..ca3cec5c 100644 --- a/src/detours.cpp +++ b/src/detours.cpp @@ -170,8 +170,8 @@ void FASTCALL Detour_UTIL_SayText2Filter( const char *param4) { #ifdef _DEBUG - int entindex = filter.GetRecipientIndex(0).Get() + 1; - CCSPlayerController *target = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)entindex); + CPlayerSlot slot = filter.GetRecipientIndex(0); + CCSPlayerController* target = CCSPlayerController::FromSlot(slot); if (target) Message("Chat from %s to %s: %s\n", param1, target->GetPlayerName(), param2); @@ -182,7 +182,7 @@ void FASTCALL Detour_UTIL_SayText2Filter( void FASTCALL Detour_Host_Say(CCSPlayerController *pController, CCommand &args, bool teamonly, int unk1, const char *unk2) { - bool bGagged = pController && g_playerManager->GetPlayer(pController->GetPlayerSlot())->IsGagged(); + bool bGagged = pController && pController->GetZEPlayer()->IsGagged(); if (!bGagged && *args[1] != '/') { diff --git a/src/events.cpp b/src/events.cpp index ccc09581..cb303124 100644 --- a/src/events.cpp +++ b/src/events.cpp @@ -78,9 +78,9 @@ GAME_EVENT_F(round_prestart) if (!g_bForceCT) return; - for (int i = 1; i <= gpGlobals->maxClients; i++) + for (int i = 0; i < gpGlobals->maxClients; i++) { - CCSPlayerController *pController = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity(CEntityIndex(i)); + CCSPlayerController* pController = CCSPlayerController::FromSlot(i); // Only do this for Ts, ignore CTs and specs if (!pController || pController->m_iTeamNum() != CS_TEAM_T) @@ -140,14 +140,14 @@ GAME_EVENT_F(player_spawn) GAME_EVENT_F(player_hurt) { - CBasePlayerController *pAttacker = (CBasePlayerController*)pEvent->GetPlayerController("attacker"); - CBasePlayerController *pVictim = (CBasePlayerController*)pEvent->GetPlayerController("userid"); + CCSPlayerController *pAttacker = (CCSPlayerController*)pEvent->GetPlayerController("attacker"); + CCSPlayerController *pVictim = (CCSPlayerController*)pEvent->GetPlayerController("userid"); // Ignore Ts/zombies and CTs hurting themselves if (!pAttacker || pAttacker->m_iTeamNum() != CS_TEAM_CT || pAttacker == pVictim) return; - ZEPlayer *pPlayer = g_playerManager->GetPlayer(pAttacker->GetPlayerSlot()); + ZEPlayer* pPlayer = pAttacker->GetZEPlayer(); if (!pPlayer) return; @@ -179,7 +179,7 @@ GAME_EVENT_F(round_end) if (!pPlayer || pPlayer->GetTotalDamage() == 0) continue; - CCSPlayerController* pController = (CCSPlayerController*)g_pEntitySystem->GetBaseEntity(CEntityIndex(pPlayer->GetPlayerSlot().Get() + 1)); + CCSPlayerController* pController = CCSPlayerController::FromSlot(pPlayer->GetPlayerSlot()); if(!pController) continue; @@ -202,7 +202,7 @@ GAME_EVENT_F(round_end) for (int i = 0; i < MIN(sortedPlayers.Count(), 5); i++) { ZEPlayer* pPlayer = sortedPlayers[i]; - CCSPlayerController* pController = (CCSPlayerController*)g_pEntitySystem->GetBaseEntity(CEntityIndex(pPlayer->GetPlayerSlot().Get() + 1)); + CCSPlayerController* pController = CCSPlayerController::FromSlot(pPlayer->GetPlayerSlot()); ClientPrintAll(HUD_PRINTTALK, " %c%i. %s \x01- \x07%i DMG", colorMap[MIN(i, 3)], i + 1, pController->GetPlayerName(), pPlayer->GetTotalDamage()); pPlayer->SetTotalDamage(0); diff --git a/src/playermanager.cpp b/src/playermanager.cpp index 6c16df42..590736da 100644 --- a/src/playermanager.cpp +++ b/src/playermanager.cpp @@ -109,7 +109,7 @@ void CPlayerManager::OnLateLoad() { for (int i = 0; i < gpGlobals->maxClients; i++) { - CCSPlayerController *pController = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity(CEntityIndex(i + 1)); + CCSPlayerController* pController = CCSPlayerController::FromSlot(i); if (!pController || !pController->IsController() || !pController->IsConnected()) continue; @@ -171,7 +171,7 @@ void CPlayerManager::CheckHideDistances() if (!hideDistance) continue; - auto pController = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(i + 1)); + CCSPlayerController* pController = CCSPlayerController::FromSlot(i); if (!pController) continue; @@ -189,7 +189,7 @@ void CPlayerManager::CheckHideDistances() if (j == i) continue; - auto pTargetController = (CCSPlayerController *)g_pEntitySystem->GetBaseEntity((CEntityIndex)(j + 1)); + CCSPlayerController* pTargetController = CCSPlayerController::FromSlot(j); if (pTargetController) { @@ -245,7 +245,7 @@ ETargetType CPlayerManager::TargetPlayerString(int iCommandClient, const char* t if (m_vecPlayers[i] == nullptr) continue; - CBasePlayerController* player = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(i + 1)); + CCSPlayerController* player = CCSPlayerController::FromSlot(i); if (!player || !player->IsController()) continue; @@ -270,7 +270,7 @@ ETargetType CPlayerManager::TargetPlayerString(int iCommandClient, const char* t if (m_vecPlayers[slot] == nullptr) continue; - CBasePlayerController* player = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(slot + 1)); + CCSPlayerController* player = CCSPlayerController::FromSlot(slot); if (!player) continue; @@ -298,7 +298,7 @@ ETargetType CPlayerManager::TargetPlayerString(int iCommandClient, const char* t if (m_vecPlayers[i] == nullptr) continue; - CBasePlayerController* player = (CBasePlayerController*)g_pEntitySystem->GetBaseEntity((CEntityIndex)(i + 1)); + CCSPlayerController* player = CCSPlayerController::FromSlot(i); if (!player || !player->IsController()) continue;