Updated for latest hl2sdk-dota changes.
3 * =============================================================================
4 * SourceMod Team Fortress 2 Extension
5 * Copyright (C) 2004-2011 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "extension.h"
33 #include "conditions.h"
36 #include <iplayerinfo.h>
38 typedef uint64_t condflags_t;
40 condflags_t g_PlayerConds[MAXPLAYERS+1];
42 IForward *g_addCondForward = NULL;
43 IForward *g_removeCondForward = NULL;
45 int playerCondOffset = -1;
46 int playerCondExOffset = -1;
47 int conditionBitsOffset = -1;
51 #define MAX_CONDS (sizeof(uint64_t) * 8)
53 inline condflags_t GetPlayerConds(CBaseEntity *pPlayer)
55 uint32_t playerCond = *(uint32_t *)((intptr_t)pPlayer + playerCondOffset);
56 uint32_t condBits = *(uint32_t *)((intptr_t)pPlayer + conditionBitsOffset);
57 uint32_t playerCondEx = *(uint32_t *)((intptr_t)pPlayer + playerCondExOffset);
59 uint64_t playerCondExAdj = playerCondEx;
60 playerCondExAdj <<= 32;
62 return playerCond|condBits|playerCondExAdj;
65 void Conditions_OnGameFrame(bool simulating)
73 condflags_t addedconds;
74 condflags_t removedconds;
76 int maxClients = gpGlobals->maxClients;
77 for (int i = 1; i <= maxClients; i++)
79 IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i);
80 if (!pPlayer || !pPlayer->IsInGame())
83 IPlayerInfo *info = pPlayer->GetPlayerInfo();
84 if (info->IsHLTV() || info->IsReplay())
87 CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(i);
88 oldconds = g_PlayerConds[i];
89 newconds = GetPlayerConds(pEntity);
91 if (oldconds == newconds)
94 addedconds = newconds &~ oldconds;
95 removedconds = oldconds &~ newconds;
100 for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= addedconds; j++)
102 if ((addedconds & bit) == bit)
104 g_addCondForward->PushCell(i);
105 g_addCondForward->PushCell(j & 0xFFFFFFFF);
106 g_addCondForward->Execute(NULL, NULL);
110 for (j = 0; j < MAX_CONDS && (bit = ((condflags_t)1 << j)) <= removedconds; j++)
112 if ((removedconds & bit) == bit)
114 g_removeCondForward->PushCell(i);
115 g_removeCondForward->PushCell(j & 0xFFFFFFFF);
116 g_removeCondForward->Execute(NULL, NULL);
120 g_PlayerConds[i] = newconds;
124 bool InitialiseConditionChecks()
126 sm_sendprop_info_t prop;
127 if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCond", &prop))
129 g_pSM->LogError(myself, "Failed to find m_nPlayerCond prop offset");
133 playerCondOffset = prop.actual_offset;
135 if (!gamehelpers->FindSendPropInfo("CTFPlayer", "_condition_bits", &prop))
137 g_pSM->LogError(myself, "Failed to find _condition_bits prop offset");
141 conditionBitsOffset = prop.actual_offset;
143 if (!gamehelpers->FindSendPropInfo("CTFPlayer", "m_nPlayerCondEx", &prop))
145 g_pSM->LogError(myself, "Failed to find m_nPlayerCondEx prop offset");
149 playerCondExOffset = prop.actual_offset;
151 if (playerCondOffset == -1 || playerCondExOffset == -1 || conditionBitsOffset == -1)
154 int maxClients = gpGlobals->maxClients;
155 for (int i = 1; i <= maxClients; i++)
157 IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i);
158 if (!pPlayer || !pPlayer->IsInGame())
161 g_PlayerConds[i] = GetPlayerConds(gamehelpers->ReferenceToEntity(i));
164 g_pSM->AddGameFrameHook(Conditions_OnGameFrame);
169 void Conditions_OnClientPutInServer(int client)
171 g_PlayerConds[client] = 0;
174 void RemoveConditionChecks()
176 g_pSM->RemoveGameFrameHook(Conditions_OnGameFrame);