Exemplo n.º 1
0
// 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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
// native DoNotUse : ArrayGetStringHandle(Array : which, item);
static cell AMX_NATIVE_CALL ArrayGetStringHandle(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* ptr = vec->at(idx);

	if (ptr == NULL)
	{
		return 0;
	}

	return reinterpret_cast<cell>(ptr);
}
Exemplo n.º 4
0
// 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()));
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
// 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;
}
Exemplo n.º 7
0
// 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;
}
Exemplo n.º 8
0
static cell_t GetArrayString(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 numWritten = 0;

	pContext->StringToLocalUTF8(params[3], params[4], (char *)blk, &numWritten);

	return numWritten;
}
Exemplo n.º 9
0
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));
}
Exemplo n.º 10
0
// 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;
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
0
static cell_t FindStringInArray(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);
	}

	char *str;
	pContext->LocalToString(params[2], &str);

	for (unsigned int i = 0; i < array->size(); i++)
	{
		const char *array_str = (const char *)array->at(i);
		if (strcmp(str, array_str) == 0)
		{
			return (cell_t) i;
		}
	}

	return -1;
}
Exemplo n.º 14
0
// 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;
}
Exemplo n.º 15
0
// 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;
}
Exemplo n.º 16
0
	bool ProcessCommandTarget(cmd_target_info_t *info)
	{
		List<SimpleMultiTargetFilter *>::iterator iter;

		for (iter = simpleMultis.begin(); iter != simpleMultis.end(); iter++) {
			SimpleMultiTargetFilter *smtf = (*iter);
			if (strcmp(smtf->pattern.c_str(), info->pattern) == 0) {
				CellArray *array = new CellArray(1);
				HandleSecurity sec(g_pCoreIdent, g_pCoreIdent);
				Handle_t hndl = handlesys->CreateHandleEx(htCellArray, array, &sec, NULL, NULL);
				AutoHandleCloner ahc(hndl, sec);
				if (ahc.getClone() == BAD_HANDLE) {
					smcore.LogError("[SM] Could not allocate a handle (%s, %d)", __FILE__, __LINE__);
					delete array;
					return false;
				}

				smtf->fun->PushString(info->pattern);
				smtf->fun->PushCell(ahc.getClone());
				cell_t result = 0;
				if (smtf->fun->Execute(&result) != SP_ERROR_NONE || !result)
					return false;

				IGamePlayer *pAdmin = info->admin
				                      ? playerhelpers->GetGamePlayer(info->admin)
				                      : NULL;

				info->num_targets = 0;
				for (size_t i = 0; i < array->size(); i++) {
					cell_t client = *array->at(i);
					IGamePlayer *pClient = playerhelpers->GetGamePlayer(client);
					if (pClient == NULL || !pClient->IsConnected())
						continue;
					if (playerhelpers->FilterCommandTarget(pAdmin, pClient, info->flags) ==
					    COMMAND_TARGET_VALID)
					{
						info->targets[info->num_targets++] = client;
						if (info->num_targets >= unsigned(info->max_targets))
							break;
					}
				}

				info->reason = info->num_targets > 0
				               ? COMMAND_TARGET_VALID
				               : COMMAND_TARGET_EMPTY_FILTER;
				if (info->num_targets) {
					smcore.strncopy(info->target_name, smtf->phrase.c_str(), info->target_name_maxlength);
					info->target_name_style = smtf->phraseIsML
					                          ? COMMAND_TARGETNAME_ML
					                          : COMMAND_TARGETNAME_RAW;
				}

				return true;
			}
		}

		return false;
	}
Exemplo n.º 17
0
// 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;
}
Exemplo n.º 18
0
// 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;
}
Exemplo n.º 19
0
// 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;
}
Exemplo n.º 20
0
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;
}
Exemplo n.º 21
0
// native ArrayFindValue(Array:which, any:item); 
static cell AMX_NATIVE_CALL ArrayFindValue(AMX* amx, cell* params)
{
	CellArray* vec = HandleToVector(amx, params[1]);

	if (vec == NULL)
	{
		return -1;
	}

	for (size_t i = 0; i < vec->size(); i++)
	{
		if (params[2] == *vec->at(i))
		{
			return static_cast<cell>(i);
		}
	}

	return -1;
}
Exemplo n.º 22
0
// native ArrayFindValue(Array:which, any:item); 
static cell AMX_NATIVE_CALL ArrayFindValue(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;
	}

	for (size_t i = 0; i < vec->size(); i++)
	{
		if (params[2] == *vec->at(i))
		{
			return static_cast<cell>(i);
		}
	}

	return -1;
}
Exemplo n.º 23
0
// native ArrayGetString(Array:which, item, output[], size);
static cell AMX_NATIVE_CALL ArrayGetString(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);
	return set_amxstring_utf8(amx, params[3], blk, amxstring_len(blk), params[4] + 1); // + EOS.
}
Exemplo n.º 24
0
// native ArrayGetString(Array:which, item, output[], size);
static cell AMX_NATIVE_CALL ArrayGetString(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);
	return set_amxstring_utf8(amx, params[3], blk, amxstring_len(blk), params[4]);
}
Exemplo n.º 25
0
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);
	}

	for (unsigned int i = 0; i < array->size(); i++)
	{
		if (params[2] == *array->at(i))
		{
			return (cell_t) i;
		}
	}

	return -1;
}
Exemplo n.º 26
0
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;
}
Exemplo n.º 27
0
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;
}
Exemplo n.º 28
0
// 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;
}
Exemplo n.º 29
0
	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;
	}
Exemplo n.º 30
0
	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;
	}