Changed a few natives/stocks that should have used IsClientInGame() rather than IsClientConnected()
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #include "sm_globals.h"
16 #include "HandleSys.h"
17 #include "CDataPack.h"
19 HandleType_t g_DataPackType;
21 class DataPackNatives :
23 public IHandleTypeDispatch
26 void OnSourceModAllInitialized()
28 g_DataPackType = g_HandleSys.CreateType("DataPack", this, 0, NULL, NULL, g_pCoreIdent, NULL);
30 void OnSourceModShutdown()
32 g_HandleSys.RemoveType(g_DataPackType, g_pCoreIdent);
35 void OnHandleDestroy(HandleType_t type, void *object)
37 g_SourceMod.FreeDataPack(reinterpret_cast<IDataPack *>(object));
41 static cell_t smn_CreateDataPack(IPluginContext *pContext, const cell_t *params)
43 IDataPack *pDataPack = g_SourceMod.CreateDataPack();
50 return g_HandleSys.CreateHandle(g_DataPackType, pDataPack, pContext->GetIdentity(), g_pCoreIdent, NULL);
53 static cell_t smn_WritePackCell(IPluginContext *pContext, const cell_t *params)
55 Handle_t hndl = static_cast<Handle_t>(params[1]);
61 sec.pIdentity = g_pCoreIdent;
63 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
66 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
69 pDataPack->PackCell(params[2]);
74 static cell_t smn_WritePackFloat(IPluginContext *pContext, const cell_t *params)
76 Handle_t hndl = static_cast<Handle_t>(params[1]);
82 sec.pIdentity = g_pCoreIdent;
84 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
87 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
90 pDataPack->PackFloat(sp_ctof(params[2]));
95 static cell_t smn_WritePackString(IPluginContext *pContext, const cell_t *params)
97 Handle_t hndl = static_cast<Handle_t>(params[1]);
100 IDataPack *pDataPack;
104 sec.pIdentity = g_pCoreIdent;
106 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
109 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
113 if ((err=pContext->LocalToString(params[2], &str)) != SP_ERROR_NONE)
115 pContext->ThrowNativeErrorEx(err, NULL);
119 pDataPack->PackString(str);
124 static cell_t smn_ReadPackCell(IPluginContext *pContext, const cell_t *params)
126 Handle_t hndl = static_cast<Handle_t>(params[1]);
129 IDataPack *pDataPack;
132 sec.pIdentity = g_pCoreIdent;
134 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
137 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
140 if (!pDataPack->IsReadable(sizeof(size_t) + sizeof(cell_t)))
142 return pContext->ThrowNativeError("DataPack operation is out of bounds.");
145 return pDataPack->ReadCell();
148 static cell_t smn_ReadPackFloat(IPluginContext *pContext, const cell_t *params)
150 Handle_t hndl = static_cast<Handle_t>(params[1]);
153 IDataPack *pDataPack;
156 sec.pIdentity = g_pCoreIdent;
158 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
161 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
164 if (!pDataPack->IsReadable(sizeof(size_t) + sizeof(float)))
166 return pContext->ThrowNativeError("DataPack operation is out of bounds.");
169 return sp_ftoc(pDataPack->ReadFloat());
172 static cell_t smn_ReadPackString(IPluginContext *pContext, const cell_t *params)
174 Handle_t hndl = static_cast<Handle_t>(params[1]);
177 IDataPack *pDataPack;
180 sec.pIdentity = g_pCoreIdent;
182 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
185 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
189 if (!(str=pDataPack->ReadString(NULL)))
191 return pContext->ThrowNativeError("DataPack operation is out of bounds.");
194 pContext->StringToLocal(params[2], params[3], str);
199 static cell_t smn_ResetPack(IPluginContext *pContext, const cell_t *params)
201 Handle_t hndl = static_cast<Handle_t>(params[1]);
204 IDataPack *pDataPack;
207 sec.pIdentity = g_pCoreIdent;
209 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
212 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
218 pDataPack->ResetSize();
224 static cell_t smn_GetPackPosition(IPluginContext *pContext, const cell_t *params)
226 Handle_t hndl = static_cast<Handle_t>(params[1]);
229 IDataPack *pDataPack;
232 sec.pIdentity = g_pCoreIdent;
234 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
237 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
240 return static_cast<cell_t>(pDataPack->GetPosition());
243 static cell_t smn_SetPackPosition(IPluginContext *pContext, const cell_t *params)
245 Handle_t hndl = static_cast<Handle_t>(params[1]);
248 IDataPack *pDataPack;
251 sec.pIdentity = g_pCoreIdent;
253 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
256 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
259 if (!pDataPack->SetPosition(params[2]))
261 return pContext->ThrowNativeError("Invalid DataPack position, %d is out of bounds", params[2]);
267 static cell_t smn_IsPackReadable(IPluginContext *pContext, const cell_t *params)
269 Handle_t hndl = static_cast<Handle_t>(params[1]);
272 IDataPack *pDataPack;
275 sec.pIdentity = g_pCoreIdent;
277 if ((herr=g_HandleSys.ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
280 return pContext->ThrowNativeError("Invalid data pack handle %x (error %d)", hndl, herr);
283 return pDataPack->IsReadable(params[2]) ? 1 : 0;
286 static DataPackNatives s_DataPackNatives;
288 REGISTER_NATIVES(datapacknatives)
290 {"CreateDataPack", smn_CreateDataPack},
291 {"WritePackCell", smn_WritePackCell},
292 {"WritePackFloat", smn_WritePackFloat},
293 {"WritePackString", smn_WritePackString},
294 {"ReadPackCell", smn_ReadPackCell},
295 {"ReadPackFloat", smn_ReadPackFloat},
296 {"ReadPackString", smn_ReadPackString},
297 {"ResetPack", smn_ResetPack},
298 {"GetPackPosition", smn_GetPackPosition},
299 {"SetPackPosition", smn_SetPackPosition},
300 {"IsPackReadable", smn_IsPackReadable},