Update CS:GO team score gamedata.
2 * vim: set ts=4 sw=4 tw=99 noet :
3 * =============================================================================
5 * Copyright (C) 2004-2010 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 "common_logic.h"
33 #include <IHandleSys.h>
34 #include <IDataPack.h>
35 #include <ISourceMod.h>
37 HandleType_t g_DataPackType;
39 class DataPackNatives :
41 public IHandleTypeDispatch
44 void OnSourceModAllInitialized()
49 handlesys->InitAccessDefaults(&tacc, &hacc);
50 tacc.access[HTypeAccess_Create] = true;
51 tacc.access[HTypeAccess_Inherit] = true;
52 tacc.ident = g_pCoreIdent;
53 hacc.access[HandleAccess_Read] = HANDLE_RESTRICT_OWNER;
55 g_DataPackType = handlesys->CreateType("DataPack", this, 0, &tacc, &hacc, g_pCoreIdent, NULL);
57 void OnSourceModShutdown()
59 handlesys->RemoveType(g_DataPackType, g_pCoreIdent);
62 void OnHandleDestroy(HandleType_t type, void *object)
64 g_pSM->FreeDataPack(reinterpret_cast<IDataPack *>(object));
68 static cell_t smn_CreateDataPack(IPluginContext *pContext, const cell_t *params)
70 IDataPack *pDataPack = g_pSM->CreateDataPack();
77 return handlesys->CreateHandle(g_DataPackType, pDataPack, pContext->GetIdentity(), g_pCoreIdent, NULL);
80 static cell_t smn_WritePackCell(IPluginContext *pContext, const cell_t *params)
82 Handle_t hndl = static_cast<Handle_t>(params[1]);
87 sec.pOwner = pContext->GetIdentity();
88 sec.pIdentity = g_pCoreIdent;
90 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
93 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
96 pDataPack->PackCell(params[2]);
101 static cell_t smn_WritePackFloat(IPluginContext *pContext, const cell_t *params)
103 Handle_t hndl = static_cast<Handle_t>(params[1]);
106 IDataPack *pDataPack;
108 sec.pOwner = pContext->GetIdentity();
109 sec.pIdentity = g_pCoreIdent;
111 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
114 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
117 pDataPack->PackFloat(sp_ctof(params[2]));
122 static cell_t smn_WritePackString(IPluginContext *pContext, const cell_t *params)
124 Handle_t hndl = static_cast<Handle_t>(params[1]);
127 IDataPack *pDataPack;
130 sec.pOwner = pContext->GetIdentity();
131 sec.pIdentity = g_pCoreIdent;
133 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
136 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
140 if ((err=pContext->LocalToString(params[2], &str)) != SP_ERROR_NONE)
142 pContext->ThrowNativeErrorEx(err, NULL);
146 pDataPack->PackString(str);
151 static cell_t smn_ReadPackCell(IPluginContext *pContext, const cell_t *params)
153 Handle_t hndl = static_cast<Handle_t>(params[1]);
156 IDataPack *pDataPack;
158 sec.pOwner = pContext->GetIdentity();
159 sec.pIdentity = g_pCoreIdent;
161 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
164 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
167 if (!pDataPack->IsReadable(sizeof(size_t) + sizeof(cell_t)))
169 return pContext->ThrowNativeError("DataPack operation is out of bounds.");
172 return pDataPack->ReadCell();
175 static cell_t smn_ReadPackFloat(IPluginContext *pContext, const cell_t *params)
177 Handle_t hndl = static_cast<Handle_t>(params[1]);
180 IDataPack *pDataPack;
182 sec.pOwner = pContext->GetIdentity();
183 sec.pIdentity = g_pCoreIdent;
185 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
188 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
191 if (!pDataPack->IsReadable(sizeof(size_t) + sizeof(float)))
193 return pContext->ThrowNativeError("DataPack operation is out of bounds.");
196 return sp_ftoc(pDataPack->ReadFloat());
199 static cell_t smn_ReadPackString(IPluginContext *pContext, const cell_t *params)
201 Handle_t hndl = static_cast<Handle_t>(params[1]);
204 IDataPack *pDataPack;
206 sec.pOwner = pContext->GetIdentity();
207 sec.pIdentity = g_pCoreIdent;
209 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
212 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
216 if (!(str=pDataPack->ReadString(NULL)))
218 return pContext->ThrowNativeError("DataPack operation is out of bounds.");
221 pContext->StringToLocal(params[2], params[3], str);
226 static cell_t smn_ResetPack(IPluginContext *pContext, const cell_t *params)
228 Handle_t hndl = static_cast<Handle_t>(params[1]);
231 IDataPack *pDataPack;
233 sec.pOwner = pContext->GetIdentity();
234 sec.pIdentity = g_pCoreIdent;
236 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
239 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
245 pDataPack->ResetSize();
251 static cell_t smn_GetPackPosition(IPluginContext *pContext, const cell_t *params)
253 Handle_t hndl = static_cast<Handle_t>(params[1]);
256 IDataPack *pDataPack;
258 sec.pOwner = pContext->GetIdentity();
259 sec.pIdentity = g_pCoreIdent;
261 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
264 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
267 return static_cast<cell_t>(pDataPack->GetPosition());
270 static cell_t smn_SetPackPosition(IPluginContext *pContext, const cell_t *params)
272 Handle_t hndl = static_cast<Handle_t>(params[1]);
275 IDataPack *pDataPack;
277 sec.pOwner = pContext->GetIdentity();
278 sec.pIdentity = g_pCoreIdent;
280 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
283 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
286 if (!pDataPack->SetPosition(params[2]))
288 return pContext->ThrowNativeError("Invalid DataPack position, %d is out of bounds", params[2]);
294 static cell_t smn_IsPackReadable(IPluginContext *pContext, const cell_t *params)
296 Handle_t hndl = static_cast<Handle_t>(params[1]);
299 IDataPack *pDataPack;
301 sec.pOwner = pContext->GetIdentity();
302 sec.pIdentity = g_pCoreIdent;
304 if ((herr=handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
307 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
310 return pDataPack->IsReadable(params[2]) ? 1 : 0;
313 static DataPackNatives s_DataPackNatives;
315 REGISTER_NATIVES(datapacknatives)
317 {"CreateDataPack", smn_CreateDataPack},
318 {"WritePackCell", smn_WritePackCell},
319 {"WritePackFloat", smn_WritePackFloat},
320 {"WritePackString", smn_WritePackString},
321 {"ReadPackCell", smn_ReadPackCell},
322 {"ReadPackFloat", smn_ReadPackFloat},
323 {"ReadPackString", smn_ReadPackString},
324 {"ResetPack", smn_ResetPack},
325 {"GetPackPosition", smn_GetPackPosition},
326 {"SetPackPosition", smn_SetPackPosition},
327 {"IsPackReadable", smn_IsPackReadable},