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>.
32 #include "extension.h"
35 void **g_pGameRules = NULL;
36 void *g_EntList = NULL;
37 CBaseHandle g_ResourceEntity;
40 void InitializeValveGlobals()
42 g_EntList = gamehelpers->GetGlobalEntityList();
47 * First try to lookup pointer directly for platforms with symbols.
48 * If symbols aren't present (Windows or stripped Linux/Mac),
49 * attempt find via CreateGameRulesObject + offset
53 if (g_pGameConf->GetMemSig("g_pGameRules", (void **)&addr) && addr)
55 g_pGameRules = reinterpret_cast<void **>(addr);
57 else if (g_pGameConf->GetMemSig("CreateGameRulesObject", (void **)&addr) && addr)
60 if (!g_pGameConf->GetOffset("g_pGameRules", &offset) || !offset)
64 g_pGameRules = *reinterpret_cast<void ***>(addr + offset);
68 size_t UTIL_StringToSignature(const char *str, char buffer[], size_t maxlength)
70 size_t real_bytes = 0;
71 size_t length = strlen(str);
73 for (size_t i=0; i<length; i++)
75 if (real_bytes >= maxlength)
79 buffer[real_bytes++] = (unsigned char)str[i];
87 /* Get the hex part */
93 /* Read it as an integer */
94 sscanf(s_byte, "%x", &r_byte);
96 buffer[real_bytes-1] = (unsigned char)r_byte;
105 bool UTIL_VerifySignature(const void *addr, const char *sig, size_t len)
107 unsigned char *addr1 = (unsigned char *) addr;
108 unsigned char *addr2 = (unsigned char *) sig;
110 for (size_t i = 0; i < len; i++)
114 if (addr1[i] != addr2[i])
121 #if defined PLATFORM_WINDOWS
122 #define FAKECLIENT_KEY "CreateFakeClient_Windows"
123 #elif defined PLATFORM_LINUX
124 #define FAKECLIENT_KEY "CreateFakeClient_Linux"
125 #elif defined PLATFORM_APPLE
126 #define FAKECLIENT_KEY "CreateFakeClient_Mac"
128 #error "Unsupported platform"
140 /* Use the symbol if it exists */
141 if (g_pGameConf->GetMemSig("sv", &addr) && addr)
143 iserver = reinterpret_cast<IServer *>(addr);
147 #if defined METAMOD_PLAPI_VERSION || PLAPI_VERSION >= 11
148 /* Get the CreateFakeClient function pointer */
149 if (!(vfunc=SH_GET_ORIG_VFNPTR_ENTRY(engine, &IVEngineServer::CreateFakeClient)))
154 /* Get the interface manually */
155 SourceHook::MemFuncInfo info = {true, -1, 0, 0};
156 SourceHook::GetFuncInfo(&IVEngineServer::CreateFakeClient, info);
158 vfunc = enginePatch->GetOrigFunc(info.vtbloffs, info.vtblindex);
161 void **vtable = *reinterpret_cast<void ***>(enginePatch->GetThisPtr() + info.thisptroffs + info.vtbloffs);
162 vfunc = vtable[info.vtblindex];
166 /* Get signature string for IVEngineServer::CreateFakeClient() */
167 sigstr = g_pGameConf->GetKeyValue(FAKECLIENT_KEY);
174 /* Convert signature string to signature bytes */
175 siglen = UTIL_StringToSignature(sigstr, sig, sizeof(sig));
177 /* Check if we're on the expected function */
178 if (!UTIL_VerifySignature(vfunc, sig, siglen))
183 /* Get the offset into CreateFakeClient */
184 if (!g_pGameConf->GetOffset("sv", &offset))
189 /* Finally we have the interface we were looking for */
190 iserver = *reinterpret_cast<IServer **>(reinterpret_cast<unsigned char *>(vfunc) + offset);
193 void GetResourceEntity()
195 g_ResourceEntity.Term();
197 #if SOURCE_ENGINE >= SE_ORANGEBOX
198 const char *classname = g_pGameConf->GetKeyValue("ResourceEntityClassname");
199 if (classname != NULL)
201 for (CBaseEntity *pEntity = (CBaseEntity *)servertools->FirstEntity(); pEntity; pEntity = (CBaseEntity *)servertools->NextEntity(pEntity))
203 if (!strcmp(gamehelpers->GetEntityClassname(pEntity), classname))
205 g_ResourceEntity = ((IHandleEntity *)pEntity)->GetRefEHandle();
213 int edictCount = gpGlobals->maxEntities;
215 for (int i=0; i<edictCount; i++)
217 edict_t *pEdict = PEntityOfEntIndex(i);
218 if (!pEdict || pEdict->IsFree())
222 if (!pEdict->GetNetworkable())
227 IHandleEntity *pHandleEnt = pEdict->GetNetworkable()->GetEntityHandle();
233 ServerClass *pClass = pEdict->GetNetworkable()->GetServerClass();
234 if (FindNestedDataTable(pClass->m_pTable, "DT_PlayerResource"))
236 g_ResourceEntity = pHandleEnt->GetRefEHandle();
243 const char *GetDTTypeName(int type)
271 #if SOURCE_ENGINE >= SE_ALIENSWARM