static cell_t PopStackString(IPluginContext *pContext, const cell_t *params) { HandleError err; CellArray *array; size_t idx, numWritten; cell_t *blk, *pWritten; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); } if (array->size() == 0) { return 0; } idx = array->size() - 1; blk = array->at(idx); pContext->StringToLocalUTF8(params[2], params[3], (char *)blk, &numWritten); pContext->LocalToPhysAddr(params[4], &pWritten); *pWritten = (cell_t)numWritten; array->remove(idx); return 1; }
// native bool:PopStackArray(Stack:handle, any:buffer[], size=-1); static cell AMX_NATIVE_CALL PopStackArray(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return 0; } if (vec->size() == 0) { return 0; } size_t idx = vec->size() - 1; cell *blk = vec->at(idx); size_t indexes = vec->blocksize(); if (params[3] != -1 && (size_t)params[3] <= vec->blocksize()) { indexes = params[3]; } cell *addr = get_amxaddr(amx, params[2]); memcpy(addr, blk, indexes * sizeof(cell)); vec->remove(idx); return 1; }
// native bool:PopStackArray(Stack:handle, any:buffer[], size=-1); static cell AMX_NATIVE_CALL PopStackArray(AMX* amx, cell* params) { CellArray* vec = ArrayHandles.lookup(params[1]); if (!vec) { LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]); return 0; } if (vec->size() == 0) { return 0; } size_t idx = vec->size() - 1; cell *blk = vec->at(idx); size_t indexes = vec->blocksize(); if (params[3] != -1 && (size_t)params[3] <= vec->blocksize()) { indexes = params[3]; } cell *addr = get_amxaddr(amx, params[2]); memcpy(addr, blk, indexes * sizeof(cell)); vec->remove(idx); return 1; }
// native bool:PopStackString(Stack:handle, buffer[], maxlength, &written = 0); static cell AMX_NATIVE_CALL PopStackString(AMX* amx, cell* params) { CellArray* vec = ArrayHandles.lookup(params[1]); if (!vec) { LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]); return 0; } if (vec->size() == 0) { return 0; } size_t idx = vec->size() - 1; cell *blk = vec->at(idx); int numWritten = set_amxstring_utf8(amx, params[2], blk, amxstring_len(blk), params[3]); *get_amxaddr(amx, params[4]) = numWritten; vec->remove(idx); return 1; }
// native bool:PopStackCell(Stack:handle, &any:value, block = 0, bool:asChar = false); static cell AMX_NATIVE_CALL PopStackCell(AMX* amx, cell* params) { CellArray* vec = ArrayHandles.lookup(params[1]); if (!vec) { LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]); return 0; } if (vec->size() == 0) { return 0; } cell *buffer = get_amxaddr(amx, params[2]); size_t index = params[3]; cell *blk = vec->at(vec->size() - 1); size_t idx = (size_t)params[3]; if (params[4] == 0) { if (idx >= vec->blocksize()) { LogError(amx, AMX_ERR_NATIVE, "Invalid block %d (blocksize: %d)", idx, vec->blocksize()); return 0; } *buffer = blk[idx]; } else { if (idx >= vec->blocksize() * 4) { LogError(amx, AMX_ERR_NATIVE, "Invalid byte %d (blocksize: %d bytes)", idx, vec->blocksize() * 4); return 0; } *buffer = (cell)*((char *)blk + idx); } vec->remove(vec->size() - 1); return 1; }
static cell_t PopStackCell(IPluginContext *pContext, const cell_t *params) { size_t idx; HandleError err; CellArray *array; cell_t *blk, *buffer; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); } if (array->size() == 0) { return 0; } pContext->LocalToPhysAddr(params[2], &buffer); blk = array->at(array->size() - 1); idx = (size_t)params[3]; if (params[4] == 0) { if (idx >= array->blocksize()) { return pContext->ThrowNativeError("Invalid block %d (blocksize: %d)", idx, array->blocksize()); } *buffer = blk[idx]; } else { if (idx >= array->blocksize() * 4) { return pContext->ThrowNativeError("Invalid byte %d (blocksize: %d bytes)", idx, array->blocksize() * 4); } *buffer = (cell_t)*((char *)blk + idx); } array->remove(array->size() - 1); return 1; }
// native ArrayDeleteItem(Array:which, item); static cell AMX_NATIVE_CALL ArrayDeleteItem(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return 0; } size_t idx = (size_t)params[2]; if (idx >= vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size()); return 0; } vec->remove(idx); return 1; }
static cell_t RemoveFromArray(IPluginContext *pContext, const cell_t *params) { CellArray *array; HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); } size_t idx = (size_t)params[2]; if (idx >= array->size()) { return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, array->size()); } array->remove(idx); return 1; }
// native ArrayDeleteItem(Array:which, item); static cell AMX_NATIVE_CALL ArrayDeleteItem(AMX* amx, cell* params) { CellArray* vec = ArrayHandles.lookup(params[1]); if (!vec) { LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", params[1]); return 0; } size_t idx = (size_t)params[2]; if (idx >= vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid index %d (count: %d)", idx, vec->size()); return 0; } vec->remove(idx); return 1; }
// native bool:PopStackString(Stack:handle, buffer[], maxlength, &written = 0); static cell AMX_NATIVE_CALL PopStackString(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return 0; } if (vec->size() == 0) { return 0; } size_t idx = vec->size() - 1; cell *blk = vec->at(idx); int numWritten = set_amxstring_utf8(amx, params[2], blk, amxstring_len(blk), params[3] + 1); *get_amxaddr(amx, params[4]) = numWritten; vec->remove(idx); return 1; }
static cell_t PopStackArray(IPluginContext *pContext, const cell_t *params) { size_t idx; cell_t *blk; cell_t *addr; size_t indexes; HandleError err; CellArray *array; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); if ((err = g_HandleSys.ReadHandle(params[1], htCellStack, &sec, (void **)&array)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); } if (array->size() == 0) { return 0; } idx = array->size() - 1; blk = array->at(idx); indexes = array->blocksize(); if (params[3] != -1 && (size_t)params[3] <= array->blocksize()) { indexes = params[3]; } pContext->LocalToPhysAddr(params[2], &addr); memcpy(addr, blk, sizeof(cell_t) * indexes); array->remove(idx); return indexes; }