static cell_t SetArrayArray(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()); } cell_t *blk = array->at(idx); size_t indexes = array->blocksize(); if (params[4] != -1 && (size_t)params[4] <= array->blocksize()) { indexes = params[4]; } cell_t *addr; pContext->LocalToPhysAddr(params[3], &addr); memcpy(blk, addr, sizeof(cell_t) * indexes); return indexes; }
// native ArrayGetArray(Array:which, item, any:output[], size = -1); static cell AMX_NATIVE_CALL ArrayGetArray(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; } cell *blk = vec->at(idx); size_t indexes = vec->blocksize(); if (*params / sizeof(cell) == 4) { if (params[4] != -1 && (size_t)params[4] <= vec->blocksize()) { indexes = params[4]; } } cell *addr = get_amxaddr(amx, params[3]); memcpy(addr, blk, sizeof(cell) * indexes); return indexes; }
// native PushStackArray(Stack:handle, const any:values[], size= -1); static cell AMX_NATIVE_CALL PushStackArray(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; } cell *blk = vec->push(); if (!blk) { LogError(amx, AMX_ERR_NATIVE, "Failed to grow stack"); return 0; } cell *addr = get_amxaddr(amx, params[2]); size_t indexes = vec->blocksize(); if (params[3] != -1 && (size_t)params[3] <= vec->blocksize()) { indexes = params[3]; } memcpy(blk, addr, indexes * sizeof(cell)); 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 PushStackArray(Stack:handle, const any:values[], size= -1); static cell AMX_NATIVE_CALL PushStackArray(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return 0; } cell *blk = vec->push(); if (!blk) { LogError(amx, AMX_ERR_NATIVE, "Failed to grow stack"); return 0; } cell *addr = get_amxaddr(amx, params[2]); size_t indexes = vec->blocksize(); if (params[3] != -1 && (size_t)params[3] <= vec->blocksize()) { indexes = params[3]; } memcpy(blk, addr, indexes * sizeof(cell)); return 1; }
static cell_t FindValueInArray(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); } // the blocknumber is not guaranteed to always be passed size_t blocknumber = 0; if (params[0] >= 3) { blocknumber = (size_t) params[3]; } if (blocknumber >= array->blocksize()) { return pContext->ThrowNativeError("Invalid block %d (blocksize: %d)", blocknumber, array->blocksize()); } for (unsigned int i = 0; i < array->size(); i++) { cell_t *blk = array->at(i); if (params[2] == blk[blocknumber]) { return (cell_t) i; } } return -1; }
// native ArrayPushArray(Array:which, const any:input[], size = -1); static cell AMX_NATIVE_CALL ArrayPushArray(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; } cell *blk = vec->push(); if (!blk) { LogError(amx, AMX_ERR_NATIVE, "Failed to grow array"); return 0; } cell *addr = get_amxaddr(amx, params[2]); size_t indexes = vec->blocksize(); if (*params / sizeof(cell) == 3) { if (params[3] != -1 && (size_t)params[3] <= vec->blocksize()) { indexes = params[3]; } } memcpy(blk, addr, sizeof(cell) * indexes); return static_cast<cell>((vec->size() - 1)); }
static cell_t PushArrayArray(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); } cell_t *blk = array->push(); if (!blk) { return pContext->ThrowNativeError("Failed to grow array"); } cell_t *addr; pContext->LocalToPhysAddr(params[2], &addr); size_t indexes = array->blocksize(); if (params[3] != -1 && (size_t)params[3] <= array->blocksize()) { indexes = params[3]; } memcpy(blk, addr, sizeof(cell_t) * indexes); return (cell_t)(array->size() - 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 ArraySetArray(Array:which, item, const any:input[], size =-1); static cell AMX_NATIVE_CALL ArraySetArray(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; } cell *blk = vec->at(idx); size_t indexes = vec->blocksize(); if (*params / sizeof(cell) == 4) { if (params[4] != -1 && (size_t)params[4] <= vec->blocksize()) { indexes = params[4]; } } cell *addr = get_amxaddr(amx, params[3]); memcpy(blk, addr, sizeof(cell) * indexes); return indexes; }
// native any:ArrayGetCell(Array:which, item, block = 0, bool:asChar = false); static cell AMX_NATIVE_CALL ArrayGetCell(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; } cell *blk = vec->at(idx); if (*params / sizeof(cell) <= 2) { return *blk; } idx = (size_t)params[3]; if (!params[4]) { if (idx >= vec->blocksize()) { LogError(amx, AMX_ERR_NATIVE, "Invalid block %d (blocksize: %d)", idx, vec->blocksize()); return 0; } return 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; } return (cell)*((char *)blk + idx); } return 0; }
// native ArrayFindString(Array:which, const item[]); static cell AMX_NATIVE_CALL ArrayFindString(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return -1; } cell *b, *a = get_amxaddr(amx, params[2]); size_t cellcount = vec->blocksize(); size_t a_len = ke::Max(1, amxstring_len(a)); size_t len = a_len > cellcount ? cellcount : a_len; for (size_t i = 0; i < vec->size(); i++) { b = vec->at(i); if (fastcellcmp(a, b, len)) { return static_cast<cell>(i); } } return -1; }
static cell_t PushArrayString(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); } cell_t *blk = array->push(); if (!blk) { return pContext->ThrowNativeError("Failed to grow array"); } char *str; pContext->LocalToString(params[2], &str); smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); return (cell_t)(array->size() - 1); }
static cell_t SetArrayString(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()); } cell_t *blk = array->at(idx); char *str; pContext->LocalToString(params[3], &str); return smcore.strncopy((char *)blk, str, array->blocksize() * sizeof(cell_t)); }
// native ArraySetString(Array:which, item, const input[]); static cell AMX_NATIVE_CALL ArraySetString(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; } cell *blk = vec->at(idx); int len; char *str = get_amxstring(amx, params[3], 0, len); return strncopy(blk, str, ke::Min((size_t)len + 1, vec->blocksize())); }
// native PushStackString(Stack:handle, const value[]); static cell AMX_NATIVE_CALL PushStackString(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; } cell *blk = vec->push(); if (!blk) { LogError(amx, AMX_ERR_NATIVE, "Failed to grow stack"); return 0; } int len; const char *value = get_amxstring(amx, params[2], 0, len); strncopy(blk, value, vec->blocksize()); return 1; }
// native ArrayFindString(Array:which, const item[]); static cell AMX_NATIVE_CALL ArrayFindString(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 -1; } cell *b, *a = get_amxaddr(amx, params[2]); size_t cellcount = vec->blocksize(); size_t a_len = ke::Max(1, amxstring_len(a)); size_t len = a_len > cellcount ? cellcount : a_len; for (size_t i = 0; i < vec->size(); i++) { b = vec->at(i); if (fastcellcmp(a, b, len)) { return static_cast<cell>(i); } } return -1; }
// native ArraySetCell(Array:which, item, any:input, block = 0, bool:asChar = false); static cell AMX_NATIVE_CALL ArraySetCell(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; } cell *blk = vec->at(idx); idx = (size_t)params[4]; if (*params / sizeof(cell) <= 3) { *blk = params[3]; return 1; } if (params[5] == 0) { if (idx >= vec->blocksize()) { LogError(amx, AMX_ERR_NATIVE, "Invalid block %d (blocksize: %d)", idx, vec->blocksize()); return 0; } blk[idx] = params[3]; } else { if (idx >= vec->blocksize() * 4) { LogError(amx, AMX_ERR_NATIVE, "Invalid byte %d (blocksize: %d bytes)", idx, vec->blocksize() * 4); return 0; } *((char *)blk + idx) = (char)params[3]; } 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; }
static cell_t SetArrayCell(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()); } cell_t *blk = array->at(idx); idx = (size_t)params[4]; if (params[5] == 0) { if (idx >= array->blocksize()) { return pContext->ThrowNativeError("Invalid block %d (blocksize: %d)", idx, array->blocksize()); } blk[idx] = params[3]; } else { if (idx >= array->blocksize() * 4) { return pContext->ThrowNativeError("Invalid byte %d (blocksize: %d bytes)", idx, array->blocksize() * 4); } *((char *)blk + idx) = (char)params[3]; } 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; }
// native ArraySort(Array:array, const comparefunc[], data[]="", data_size=0); static cell AMX_NATIVE_CALL ArraySort(AMX* amx, cell* params) { cell handle = params[1]; CellArray* vec = ArrayHandles.lookup(handle); if (!vec) { LogError(amx, AMX_ERR_NATIVE, "Invalid array handle provided (%d)", handle); return 0; } int len; char* funcName = get_amxstring(amx, params[2], 0, len); // MySortFunc(Array:array, item1, item2, const data[], data_size) int func = registerSPForwardByName(amx, funcName, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE); if (func < 0) { LogError(amx, AMX_ERR_NATIVE, "The public function \"%s\" was not found.", funcName); return 0; } size_t arraysize = vec->size(); size_t blocksize = vec->blocksize(); cell *array = vec->base(); ArraySort_s oldinfo = SortInfo; SortInfo.func = func; SortInfo.array_base = array; SortInfo.array_bsize = static_cast<cell>(blocksize); SortInfo.array_hndl = handle; SortInfo.data = params[3]; SortInfo.size = params[4]; qsort(array, arraysize, blocksize * sizeof(cell), SortArrayList); SortInfo = oldinfo; unregisterSPForward(func); return 1; }
// native ArrayPushString(Array:which, const input[]); static cell AMX_NATIVE_CALL ArrayPushString(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return 0; } cell *blk = vec->push(); if (!blk) { LogError(amx, AMX_ERR_NATIVE, "Failed to grow array"); return 0; } strncopy(blk, get_amxaddr(amx, params[2]), vec->blocksize()); return static_cast<cell>((vec->size() - 1)); }
// native ArrayPushString(Array:which, const input[]); static cell AMX_NATIVE_CALL ArrayPushString(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; } cell *blk = vec->push(); if (!blk) { LogError(amx, AMX_ERR_NATIVE, "Failed to grow array"); return 0; } strncopy(blk, get_amxaddr(amx, params[2]), vec->blocksize()); return static_cast<cell>((vec->size() - 1)); }
// native ArrayInsertStringBefore(Array:which, item, const input[]); static cell AMX_NATIVE_CALL ArrayInsertStringBefore(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return 0; } size_t idx = params[2]; if (idx >= vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid item specified in ArrayInsertStringBefore (%d:%d)", idx, vec->size()); return 0; } int len; const char *str = get_amxstring(amx, params[3], 0, len); return strncopy(vec->insert_at(idx), str, ke::Min((size_t)len + 1, vec->blocksize())); }
// native ArrayInsertArrayBefore(Array:which, item, const any:input[]); static cell AMX_NATIVE_CALL ArrayInsertArrayBefore(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return 0; } size_t idx = params[2]; if (idx >= vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid item specified in ArrayInsertArrayBefore (%d:%d)", idx, vec->size()); return 0; } cell *addr = get_amxaddr(amx, params[3]); memcpy(vec->insert_at(idx), addr, vec->blocksize() * sizeof(cell)); return 1; }
// native ArrayInsertStringAfter(Array:which, item, const input[]); static cell AMX_NATIVE_CALL ArrayInsertStringAfter(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 = params[2] + 1; if (idx > vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid item specified in ArrayInsertStringAfter (%d:%d)", idx, vec->size()); return 0; } int len; const char *str = get_amxstring(amx, params[3], 0, len); return strncopy(vec->insert_at(idx), str, ke::Min((size_t)len + 1, vec->blocksize())); }
// native ArrayInsertArrayAfter(Array:which, item, const any:input[]); static cell AMX_NATIVE_CALL ArrayInsertArrayAfter(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 = params[2] + 1; if (idx > vec->size()) { LogError(amx, AMX_ERR_NATIVE, "Invalid item specified in ArrayInsertArrayAfter (%d:%d)", idx, vec->size()); return 0; } cell *addr = get_amxaddr(amx, params[3]); memcpy(vec->insert_at(idx), addr, sizeof(cell) * vec->blocksize()); return 1; }
static cell_t sm_SortADTArrayCustom(IPluginContext *pContext, const cell_t *params) { CellArray *cArray; HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); if ((err = g_HandleSys.ReadHandle(params[1], htCellArray, &sec, (void **)&cArray)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); } IPluginFunction *pFunction = pContext->GetFunctionById(params[2]); if (!pFunction) { return pContext->ThrowNativeError("Function %x is not a valid function", params[2]); } size_t arraysize = cArray->size(); size_t blocksize = cArray->blocksize(); cell_t *array = cArray->base(); sort_infoADT oldinfo = g_SortInfoADT; g_SortInfoADT.pFunc = pFunction; g_SortInfoADT.array_base = array; g_SortInfoADT.array_bsize = (cell_t) blocksize; g_SortInfoADT.array_hndl = params[1]; g_SortInfoADT.hndl = params[3]; qsort(array, arraysize, blocksize * sizeof(cell_t), sort_adtarray_custom); g_SortInfoADT = oldinfo; return 1; }