MCPcopy Create free account
hub / github.com/alliedmodders/sourcemod / smn_ReadPackCellArray

Function smn_ReadPackCellArray

core/logic/smn_datapacks.cpp:388–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386}
387
388static cell_t smn_ReadPackCellArray(IPluginContext *pContext, const cell_t *params)
389{
390 HandleError herr;
391 HandleSecurity sec;
392 sec.pOwner = pContext->GetIdentity();
393 sec.pIdentity = g_pCoreIdent;
394
395 Handle_t hndl = static_cast<Handle_t>(params[1]);
396 CDataPack *pDataPack = nullptr;
397 if ((herr = handlesys->ReadHandle(hndl, g_DataPackType, &sec, (void **)&pDataPack))
398 != HandleError_None)
399 {
400 pContext->ReportError("Invalid data pack handle %x (error %d).", hndl, herr);
401 return 0;
402 }
403
404 if (!pDataPack->IsReadable())
405 {
406 pContext->ReportError("Data pack operation is out of bounds.");
407 return 0;
408 }
409
410 if (pDataPack->GetCurrentType() != CDataPackType::CellArray)
411 {
412 pContext->ReportError("Invalid data pack type (got %d / expected %d).", pDataPack->GetCurrentType(), CDataPackType::CellArray);
413 return 0;
414 }
415
416 cell_t packCount = 0;
417 cell_t *pData = pDataPack->ReadCellArray(&packCount);
418 if(pData == nullptr || packCount == 0)
419 {
420 pContext->ReportError("Invalid data pack operation: current position isn't an array!");
421 return 0;
422 }
423
424 cell_t count = params[3];
425 if(packCount > count)
426 {
427 pContext->ReportError("Input buffer too small (needed %d, got %d).", packCount, count);
428 return 0;
429 }
430
431 cell_t *pArray;
432 pContext->LocalToPhysAddr(params[2], &pArray);
433
434 memcpy(pArray, pData, sizeof(cell_t) * count);
435
436 return 1;
437}
438
439static cell_t smn_ReadPackFloatArray(IPluginContext *pContext, const cell_t *params)
440{

Callers

nothing calls this directly

Calls 6

ReportErrorMethod · 0.80
IsReadableMethod · 0.80
GetCurrentTypeMethod · 0.80
ReadCellArrayMethod · 0.80
GetIdentityMethod · 0.45
ReadHandleMethod · 0.45

Tested by

no test coverage detected