Update CS:GO team score gamedata.
3 * =============================================================================
4 * SourceMod SDKTools Extension
5 * Copyright (C) 2004-2008 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>.
33 #include "extension.h"
35 #include "basehandle.h"
37 #include "utlvector.h"
38 #include <shareddefs.h>
41 #define FEATURECAP_PLAYERRUNCMD_11PARAMS "SDKTools PlayerRunCmd 11Params"
44 static bool PRCH_enabled = false;
45 static bool PRCH_used = false;
47 SH_DECL_MANUALHOOK2_void(PlayerRunCmdHook, 0, 0, 0, CUserCmd *, IMoveHelper *);
49 CHookManager::CHookManager()
54 void CHookManager::Initialize()
57 if (g_pGameConf->GetOffset("PlayerRunCmd", &offset))
59 SH_MANUALHOOK_RECONFIGURE(PlayerRunCmdHook, offset, 0, 0);
64 g_pSM->LogError(myself, "Failed to find PlayerRunCmd offset - OnPlayerRunCmd forward disabled.");
68 plsys->AddPluginsListener(this);
69 sharesys->AddCapabilityProvider(myself, this, FEATURECAP_PLAYERRUNCMD_11PARAMS);
71 m_usercmdsFwd = forwards->CreateForward("OnPlayerRunCmd", ET_Event, 11, NULL,
73 Param_CellByRef, // buttons
74 Param_CellByRef, // impulse
75 Param_Array, // Float:vel[3]
76 Param_Array, // Float:angles[3]
77 Param_CellByRef, // weapon
78 Param_CellByRef, // subtype
79 Param_CellByRef, // cmdnum
80 Param_CellByRef, // tickcount
81 Param_CellByRef, // seed
82 Param_Array); // mouse[2]
85 void CHookManager::Shutdown()
87 forwards->ReleaseForward(m_usercmdsFwd);
89 plsys->RemovePluginsListener(this);
90 sharesys->DropCapabilityProvider(myself, this, FEATURECAP_PLAYERRUNCMD_11PARAMS);
93 void CHookManager::OnClientPutInServer(int client)
101 edict_t *pEdict = PEntityOfEntIndex(client);
107 IServerUnknown *pUnknown = pEdict->GetUnknown();
113 CBaseEntity *pEntity = pUnknown->GetBaseEntity();
119 CVTableHook hook(pEntity);
120 for (size_t i = 0; i < m_runUserCmdHooks.length(); ++i)
122 if (hook == m_runUserCmdHooks[i])
128 int hookid = SH_ADD_MANUALVPHOOK(PlayerRunCmdHook, pEntity, SH_MEMBER(this, &CHookManager::PlayerRunCmd), false);
129 hook.SetHookID(hookid);
130 m_runUserCmdHooks.append(new CVTableHook(hook));
133 void CHookManager::PlayerRunCmd(CUserCmd *ucmd, IMoveHelper *moveHelper)
135 if (m_usercmdsFwd->GetFunctionCount() == 0)
137 RETURN_META(MRES_IGNORED);
140 CBaseEntity *pEntity = META_IFACEPTR(CBaseEntity);
144 RETURN_META(MRES_IGNORED);
147 edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
151 RETURN_META(MRES_IGNORED);
154 int client = IndexOfEdict(pEdict);
158 /* Impulse is a byte so we copy it back manually */
159 cell_t impulse = ucmd->impulse;
160 cell_t vel[3] = {sp_ftoc(ucmd->forwardmove), sp_ftoc(ucmd->sidemove), sp_ftoc(ucmd->upmove)};
161 cell_t angles[3] = {sp_ftoc(ucmd->viewangles.x), sp_ftoc(ucmd->viewangles.y), sp_ftoc(ucmd->viewangles.z)};
162 cell_t mouse[2] = {ucmd->mousedx, ucmd->mousedy};
164 m_usercmdsFwd->PushCell(client);
165 m_usercmdsFwd->PushCellByRef(&ucmd->buttons);
166 m_usercmdsFwd->PushCellByRef(&impulse);
167 m_usercmdsFwd->PushArray(vel, 3, SM_PARAM_COPYBACK);
168 m_usercmdsFwd->PushArray(angles, 3, SM_PARAM_COPYBACK);
169 m_usercmdsFwd->PushCellByRef(&ucmd->weaponselect);
170 m_usercmdsFwd->PushCellByRef(&ucmd->weaponsubtype);
171 m_usercmdsFwd->PushCellByRef(&ucmd->command_number);
172 m_usercmdsFwd->PushCellByRef(&ucmd->tick_count);
173 m_usercmdsFwd->PushCellByRef(&ucmd->random_seed);
174 m_usercmdsFwd->PushArray(mouse, 2, SM_PARAM_COPYBACK);
175 m_usercmdsFwd->Execute(&result);
177 ucmd->impulse = impulse;
178 ucmd->forwardmove = sp_ctof(vel[0]);
179 ucmd->sidemove = sp_ctof(vel[1]);
180 ucmd->upmove = sp_ctof(vel[2]);
181 ucmd->viewangles.x = sp_ctof(angles[0]);
182 ucmd->viewangles.y = sp_ctof(angles[1]);
183 ucmd->viewangles.z = sp_ctof(angles[2]);
184 ucmd->mousedx = mouse[0];
185 ucmd->mousedy = mouse[1];
188 if (result == Pl_Handled)
190 RETURN_META(MRES_SUPERCEDE);
193 RETURN_META(MRES_IGNORED);
196 void CHookManager::OnPluginLoaded(IPlugin *plugin)
204 if (!m_usercmdsFwd->GetFunctionCount())
209 int MaxClients = playerhelpers->GetMaxClients();
210 for (int i = 1; i <= MaxClients; i++)
212 if (playerhelpers->GetGamePlayer(i)->IsInGame())
214 OnClientPutInServer(i);
219 void CHookManager::OnPluginUnloaded(IPlugin *plugin)
227 if (m_usercmdsFwd->GetFunctionCount())
230 for (size_t i = 0; i < m_runUserCmdHooks.length(); ++i)
232 delete m_runUserCmdHooks[i];
235 m_runUserCmdHooks.clear();
239 FeatureStatus CHookManager::GetFeatureStatus(FeatureType type, const char *name)
241 return FeatureStatus_Available;