// native Array:ArrayClone(Array:which); static cell AMX_NATIVE_CALL ArrayClone(AMX* amx, cell* params) { CellArray* vec = HandleToVector(amx, params[1]); if (vec == NULL) { return 0; } CellArray *clonevec = vec->clone(); // Scan through the vector list to see if any are NULL. // NULL means the vector was previously destroyed. for (unsigned int i = 0; i < VectorHolder.length(); ++i) { if (VectorHolder[i] == NULL) { VectorHolder[i] = clonevec; return i + 1; } } VectorHolder.append(clonevec); return VectorHolder.length(); }
// native Array:ArrayClone(Array:which); static cell AMX_NATIVE_CALL ArrayClone(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; } return ArrayHandles.clone(vec->clone()); }
static cell_t CloneArray(IPluginContext *pContext, const cell_t *params) { CellArray *oldArray; HandleError err; HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent); if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&oldArray)) != HandleError_None) { return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err); } CellArray *array = oldArray->clone(); Handle_t hndl = handlesys->CreateHandle(htCellArray, array, pContext->GetIdentity(), g_pCoreIdent, NULL); if (!hndl) { delete array; } return hndl; }
CellArray *UpdateMapList(CellArray *pUseArray, const char *name, int *pSerial, unsigned int flags) { int change_serial; CellArray *pNewArray = NULL; bool success, free_new_array; free_new_array = false; if ((success = GetMapList(&pNewArray, name, &change_serial)) == false) { if ((flags & MAPLIST_FLAG_NO_DEFAULT) != MAPLIST_FLAG_NO_DEFAULT) { /* If this list failed, and it's not the default, try the default. */ if (strcmp(name, "default") != 0) { success = GetMapList(&pNewArray, name, &change_serial); } /* If either of the last two conditions failed, try again if we can. */ if (!success && strcmp(name, "mapcyclefile") != 0) { success = GetMapList(&pNewArray, "mapcyclefile", &change_serial); } } } /* If there was a success, and the serial has not changed, bail out. */ if (success && *pSerial == change_serial) { return NULL; } /** * If there was a success but no map list, we need to look in the maps folder. * If there was a failure and the flag is specified, we need to look in the maps folder. */ if ((success && pNewArray == NULL) || (!success && ((flags & MAPLIST_FLAG_MAPSFOLDER) == MAPLIST_FLAG_MAPSFOLDER))) { pNewArray = new CellArray(64); free_new_array = true; cell_t *blk; FileFindHandle_t findHandle; const char *fileName = bridge->filesystem->FindFirstEx("maps/*.bsp", "GAME", &findHandle); while (fileName) { char buffer[PLATFORM_MAX_PATH]; UTIL_StripExtension(fileName, buffer, sizeof(buffer)); if (!gamehelpers->IsMapValid(buffer)) { fileName = bridge->filesystem->FindNext(findHandle); continue; } if ((blk = pNewArray->push()) == NULL) { fileName = bridge->filesystem->FindNext(findHandle); continue; } strncopy((char *)blk, buffer, 255); fileName = bridge->filesystem->FindNext(findHandle); } bridge->filesystem->FindClose(findHandle); /* Remove the array if there were no items. */ if (pNewArray->size() == 0) { delete pNewArray; pNewArray = NULL; } else { qsort(pNewArray->base(), pNewArray->size(), pNewArray->blocksize() * sizeof(cell_t), sort_maps_in_adt_array); } change_serial = -1; } /* If there is still no array by this point, bail out. */ if (pNewArray == NULL) { *pSerial = -1; return NULL; } *pSerial = change_serial; /* If there is no input array, return something temporary. */ if (pUseArray == NULL) { if (free_new_array) { return pNewArray; } else { return pNewArray->clone(); } } /* Clear the input array if necessary. */ if ((flags & MAPLIST_FLAG_CLEARARRAY) == MAPLIST_FLAG_CLEARARRAY) { pUseArray->clear(); } /* Copy. */ cell_t *blk_dst; cell_t *blk_src; for (size_t i = 0; i < pNewArray->size(); i++) { blk_dst = pUseArray->push(); blk_src = pNewArray->at(i); strncopy((char *)blk_dst, (char *)blk_src, pUseArray->blocksize() * sizeof(cell_t)); } /* Free resources if necessary. */ if (free_new_array) { delete pNewArray; } /* Return the array we were given. */ return pUseArray; }
CellArray *UpdateMapList(CellArray *pUseArray, const char *name, int *pSerial, unsigned int flags) { int change_serial; CellArray *pNewArray = NULL; bool success, free_new_array; free_new_array = false; if ((success = GetMapList(&pNewArray, name, &change_serial)) == false) { if ((flags & MAPLIST_FLAG_NO_DEFAULT) != MAPLIST_FLAG_NO_DEFAULT) { /* If this list failed, and it's not the default, try the default. */ if (strcmp(name, "default") != 0) { success = GetMapList(&pNewArray, name, &change_serial); } /* If either of the last two conditions failed, try again if we can. */ if (!success && strcmp(name, "mapcyclefile") != 0) { success = GetMapList(&pNewArray, "mapcyclefile", &change_serial); } } } /* If there was a success, and the serial has not changed, bail out. */ if (success && *pSerial == change_serial) { return NULL; } /** * If there was a success but no map list, we need to look in the maps folder. * If there was a failure and the flag is specified, we need to look in the maps folder. */ if ((success && pNewArray == NULL) || (!success && ((flags & MAPLIST_FLAG_MAPSFOLDER) == MAPLIST_FLAG_MAPSFOLDER))) { char path[255]; IDirectory *pDir; pNewArray = new CellArray(64); free_new_array = true; g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "maps"); if ((pDir = g_LibSys.OpenDirectory(path)) != NULL) { char *ptr; cell_t *blk; char buffer[PLATFORM_MAX_PATH]; while (pDir->MoreFiles()) { if (!pDir->IsEntryFile() || strcmp(pDir->GetEntryName(), ".") == 0 || strcmp(pDir->GetEntryName(), "..") == 0) { pDir->NextEntry(); continue; } strncopy(buffer, pDir->GetEntryName(), sizeof(buffer)); if ((ptr = strstr(buffer, ".bsp")) == NULL || ptr[4] != '\0') { pDir->NextEntry(); continue; } *ptr = '\0'; if (!engine->IsMapValid(buffer)) { pDir->NextEntry(); continue; } if ((blk = pNewArray->push()) == NULL) { pDir->NextEntry(); continue; } strncopy((char *)blk, buffer, 255); pDir->NextEntry(); } g_LibSys.CloseDirectory(pDir); } /* Remove the array if there were no items. */ if (pNewArray->size() == 0) { delete pNewArray; pNewArray = NULL; } else { qsort(pNewArray->base(), pNewArray->size(), pNewArray->blocksize() * sizeof(cell_t), sort_maps_in_adt_array); } change_serial = -1; } /* If there is still no array by this point, bail out. */ if (pNewArray == NULL) { *pSerial = -1; return NULL; } *pSerial = change_serial; /* If there is no input array, return something temporary. */ if (pUseArray == NULL) { if (free_new_array) { return pNewArray; } else { return pNewArray->clone(); } } /* Clear the input array if necessary. */ if ((flags & MAPLIST_FLAG_CLEARARRAY) == MAPLIST_FLAG_CLEARARRAY) { pUseArray->clear(); } /* Copy. */ cell_t *blk_dst; cell_t *blk_src; for (size_t i = 0; i < pNewArray->size(); i++) { blk_dst = pUseArray->push(); blk_src = pNewArray->at(i); strncopy((char *)blk_dst, (char *)blk_src, pUseArray->blocksize() * sizeof(cell_t)); } /* Free resources if necessary. */ if (free_new_array) { delete pNewArray; } /* Return the array we were given. */ return pUseArray; }