Пример #1
0
// native sqlite_get_field(SQLiteResult:result, field, fieldvalue[], maxlength = sizeof fieldvalue );
static cell AMX_NATIVE_CALL n_get_field(AMX* amx, cell* params)
{
	SQLiteResult *result;
	int field;
	
	result = (SQLiteResult *)params[1];

	if (!result)
	{
		//logprintf(NATIVE_PREFIX "get_field() - Warning: Invalid result set\n");
		return 0;
	}

	field = (int) params[2];
	if (field < 0 || field >= result->nColumns)
	{
		// exceeds the number of columns
		set_amxstring(amx, params[3], "", params[4]);
		return 0;
	}

	set_amxstring(amx, params[3], result->pResults[result->nColumns * (result->nCurrentRow+1) + field], params[4]);

	return 1;
}
Пример #2
0
//added by BAILOPAN for jtp10181
//takes a string and breaks it into a 1st param and rest params
//different from strbreak because it's more crafted for control
static cell AMX_NATIVE_CALL amx_strtok(AMX *amx, cell *params)
{
	int left_pos = 0;
	int right_pos = 0;
	unsigned int i = 0;
	bool done_flag = false;
	int len = 0;

	//string[]
	char *string = get_amxstring(amx, params[1], 0, len);
	//left[]
	char *left = new char[len + 1];
	//right[]
	char *right = new char[len + 1];
	int leftMax = params[3];
	int rightMax = params[5];
	//token
	char token = static_cast<char>(params[6]);
	//trim
	int trim = params[7];
	
	for (i = 0; i < (unsigned int)len; i++)
	{
		if (trim && !done_flag)
		{
			if (isspace(string[i]))
			{
				while (isspace(string[++i]));
				done_flag = true;
			}
		}

		if (!done_flag && string[i] == token)
		{
			done_flag = true;
			i++;
		}

		if (done_flag)
		{
			right[right_pos++] = string[i];
		} else {
			left[left_pos++] = string[i];
		}
	}

	right[right_pos] = 0;
	left[left_pos] = 0;
	set_amxstring(amx, params[2], left, leftMax);
	set_amxstring(amx, params[4], right, rightMax);
	delete [] left;
	delete [] right;
	
	return 1;
}
Пример #3
0
static cell AMX_NATIVE_CALL replace_stringex(AMX *amx, cell *params)
{
	int len;
	size_t maxlength = (size_t)params[2];

	char *text = get_amxstring(amx, params[1], 0, len);
	const char *search = get_amxstring(amx, params[3], 1, len);
	const char *replace = get_amxstring(amx, params[4], 2, len);

	size_t searchLen = (params[5] == -1) ? strlen(search) : (size_t)params[5];
	size_t replaceLen = (params[6] == -1) ? strlen(replace) : (size_t)params[6];

	bool caseSensitive = params[7] ? true : false;

	if (searchLen == 0)
	{
		LogError(amx, AMX_ERR_NATIVE, "Cannot replace searches of empty strings.");
		return -1;
	}

	char *ptr = UTIL_ReplaceEx(text, maxlength + 1, search, searchLen, replace, replaceLen, caseSensitive); // + EOS

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

	set_amxstring(amx, params[1], ptr, maxlength);

	return ptr - text;
}
Пример #4
0
static cell AMX_NATIVE_CALL numtostr(AMX *amx, cell *params) /* 3 param */
{
	char szTemp[32];
	sprintf(szTemp, "%d", (int)params[1]);

	return set_amxstring(amx, params[2], szTemp, params[3]);
}
Пример #5
0
static cell AMX_NATIVE_CALL float_to_str(AMX *amx, cell *params)
{
	char szTemp[32];
	sprintf(szTemp, "%f", amx_ctof(params[1]));
	
	return set_amxstring(amx, params[2], szTemp, params[3]);
}
Пример #6
0
static cell AMX_NATIVE_CALL get_vaultdata(AMX *amx, cell *params)
{
	int iLen;
	const char* key = get_amxstring(amx, params[1], 0, iLen);

	if (params[3])
		return set_amxstring(amx, params[2], g_vault.get(key), params[3]);

	return g_vault.get_number(key);
}
Пример #7
0
// native bool:SMC_GetErrorString(SMCError:error, buffer[], buf_max);
static cell AMX_NATIVE_CALL SMC_GetErrorString(AMX *amx, cell *params)
{
	const char *str = textparsers->GetSMCErrorString((SMCError)params[1]);

	if (!str)
	{
		return 0;
	}

	return set_amxstring(amx, params[2], str, params[3]);
}
Пример #8
0
static cell AMX_NATIVE_CALL dbg_fmt_error(AMX *amx, cell *params)
{
    Handler *pHandler = (Handler *)amx->userdata[UD_HANDLER];

    if (!pHandler)
        return 0;

    const char *str = pHandler->GetFmtCache();

    set_amxstring(amx, params[1], str, params[2]);

    return 1;
}
Пример #9
0
static cell AMX_NATIVE_CALL get_msg_arg_string(AMX *amx, cell *params)
{
	size_t argn = static_cast<size_t>(params[1]);

	if (!inhook || argn > Msg.Params())
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid message argument %d", argn);
		return 0;
	}

	const char *szVal = Msg.GetParamString(argn);

	return set_amxstring(amx, params[2], szVal, params[3]);
}
Пример #10
0
// native sqlite_get_field_assoc(SQLiteResult:result, const field[], fieldvalue[], maxlength = sizeof fieldvalue );
static cell AMX_NATIVE_CALL n_get_field_assoc(AMX* amx, cell* params)
{
	SQLiteResult *result;
	int field, i;
	char *szFieldName;
	
	result = (SQLiteResult *)params[1];

	if (!result)
	{
		//logprintf(NATIVE_PREFIX "get_field_assoc() - Warning: Invalid result set\n");
		return 0;
	}

	// Figure out the field index
	amx_StrParam(amx, params[2], szFieldName);

	field = -1;
	for(i = 0; i<result->nColumns; i++)
	{
		if (strcmp(szFieldName, result->pResults[i]) == 0)
		{
			field = i;
			break;
		}
	}

	if (field < 0 || field >= result->nColumns)
	{
		set_amxstring(amx, params[3], "", params[4]);
		return 0;
	}

	set_amxstring(amx, params[3], result->pResults[result->nColumns * (result->nCurrentRow+1) + field], params[4]);

	return 1;
}
Пример #11
0
//Gets info about a menu option
//native menu_item_getinfo(menu, item, &access, command[], cmdlen, name[]="", namelen=0, &callback);
static cell AMX_NATIVE_CALL menu_item_getinfo(AMX *amx, cell *params)
{
	GETMENU(params[1]);

	menuitem *pItem = pMenu->GetMenuItem(static_cast<item_t>(params[2]));

	if (!pItem)
		return 0;

	cell *addr = get_amxaddr(amx, params[3]);
	addr[0] = pItem->access;

	set_amxstring(amx, params[4], pItem->cmd.chars(), params[5]);
	set_amxstring(amx, params[6], pItem->name.chars(), params[7]);

	if (params[8])
	{
		addr = get_amxaddr(amx, params[8]);
		if (addr)
			addr[0] = pItem->handler;
	}

	return 1;
}
Пример #12
0
static cell AMX_NATIVE_CALL format_args(AMX *amx, cell *params)
{
	int len;
	int pos = params[3];
	
	if (pos < 0)
	{
		LogError(amx, AMX_ERR_NATIVE, "Pos has to be a positive number");
		return 0;
	}

	char* string = format_arguments(amx, pos, len); // indexed from 0
	
	return set_amxstring(amx, params[1], string, params[2]);
}
Пример #13
0
static cell AMX_NATIVE_CALL amx_trim(AMX *amx, cell *params)
{
	int len, newlen;
	char *str = get_amxstring(amx, params[1], 0, len);

	UTIL_TrimLeft(str);
	UTIL_TrimRight(str);

	newlen = strlen(str);
	len -= newlen;

	set_amxstring(amx, params[1], str, newlen);

	return len;
}
Пример #14
0
static cell AMX_NATIVE_CALL dbg_trace_info(AMX *amx, cell *params)
{
    Debugger *pDebugger = (Debugger *)amx->userdata[UD_DEBUGGER];

    if (!pDebugger)
        return 0;

    trace_info_t *pTrace = (trace_info_t *)(params[1]);

    if (!pTrace)
        return 0;

    cell *line_addr = get_amxaddr(amx, params[2]);
    long lLine=-1;
    const char *function=NULL, *file=NULL;

    pDebugger->GetTraceInfo(pTrace, lLine, function, file);

    set_amxstring(amx, params[3], function ? function : "", params[4]);
    set_amxstring(amx, params[5], file ? file : "", params[5]);
    *line_addr = (cell)lLine + 1;

    return 1;
}
Пример #15
0
static cell AMX_NATIVE_CALL amx_trim(AMX *amx, cell *params)
{
	int len;
	char *str = get_amxstring(amx, params[1], 0, len);

	String toTrim;

	toTrim.assign(str);
	toTrim.trim();

	len -= toTrim.size();

	set_amxstring(amx, params[1], toTrim.c_str(), toTrim.size());

	return len;
}
Пример #16
0
//get_string(param, dest[], len)
static cell AMX_NATIVE_CALL get_string(AMX *amx, cell *params)
{
	if (!g_pCurNative || (g_pCurNative->amx != amx))
	{
		LogError(amx, AMX_ERR_NATIVE, "Not currently in a dynamic native");
		return 0;
	}
	if (g_pCurNative->style)
	{
		LogError(amx, AMX_ERR_NATIVE, "Wrong style of dynamic native");
		return 0;
	}
	int p = params[1];

	int len;
	char *str = get_amxstring(g_pCaller, g_Params[p], 0, len);
	return set_amxstring(amx, params[2], str, params[3]);
}
Пример #17
0
static cell AMX_NATIVE_CALL replace_string(AMX *amx, cell *params)
{
	int len;
	size_t maxlength = (size_t)params[2];

	char *text = get_amxstring(amx, params[1], 0, len);
	const char *search = get_amxstring(amx, params[3], 1, len);
	const char *replace = get_amxstring(amx, params[4], 2, len);

	bool caseSensitive = params[5] ? true : false;

	if (search[0] == '\0')
	{
		LogError(amx, AMX_ERR_NATIVE, "Cannot replace searches of empty strings.");
		return -1;
	}

	int count = UTIL_ReplaceAll(text, maxlength + 1, search, replace, caseSensitive); // + EOS

	set_amxstring(amx, params[1], text, maxlength);

	return count;
}
Пример #18
0
int CPluginMngr::loadPluginsFromFile(const char* filename, bool warn)
{
	char file[PLATFORM_MAX_PATH];
	FILE *fp = fopen(build_pathname_r(file, sizeof(file), "%s", filename), "rt");

	if (!fp)
	{
		if (warn)
		{
			AMXXLOG_Error("[AMXX] Plugins list not found (file \"%s\")", filename);
		}
		return 1;
	}

	// Find now folder
	char pluginName[256], error[256], debug[256];
	int debugFlag = 0;
	const char *pluginsDir = get_localinfo("amxx_pluginsdir", "addons/amxmodx/plugins");

	char line[512];

	List<ke::AString *>::iterator block_iter;

	while (!feof(fp))
	{
		pluginName[0] = '\0';

		debug[0] = '\0';
		debugFlag = 0;

		line[0] = '\0';
		fgets(line, sizeof(line), fp);

		/** quick hack */
		char *ptr = line;
		while (*ptr)
		{
			if (*ptr == ';')
			{
				*ptr = '\0';
			} else {
				ptr++;
			}
		}
		sscanf(line, "%s %s", pluginName, debug);

		if (!isalnum(*pluginName))
		{
			continue;
		}

		if (isalnum(*debug) && !strcmp(debug, "debug"))
		{
			debugFlag = 1;
		}

		bool skip = false;
		for (block_iter = m_BlockList.begin();
			 block_iter != m_BlockList.end();
			 block_iter++)
		{
			if ((*block_iter)->compare(pluginName) == 0)
			{
				skip = true;
				break;
			}
		}

		if (skip || !strcmp(debug, "disabled"))
		{
			continue;
		}

		if (findPlugin(pluginName) != NULL)
		{
			continue;
		}

		CPlugin* plugin = loadPlugin(pluginsDir, pluginName, error, sizeof(error), debugFlag);

		if (plugin->getStatusCode() == ps_bad_load)
		{
			char errorMsg[255];
			sprintf(errorMsg, "%s (plugin \"%s\")", error, pluginName);
			plugin->setError(errorMsg);
			AMXXLOG_Error("[AMXX] %s", plugin->getError());
		}
		else
		{
			cell addr;
			if (amx_FindPubVar(plugin->getAMX(), "MaxClients", &addr) != AMX_ERR_NOTFOUND)
			{
				*get_amxaddr(plugin->getAMX(), addr) = gpGlobals->maxClients;
			}

			if (amx_FindPubVar(plugin->getAMX(), "MapName", &addr) != AMX_ERR_NOTFOUND)
			{
				set_amxstring(plugin->getAMX(), addr, STRING(gpGlobals->mapname), MAX_MAPNAME_LENGTH - 1);
			}

			if (amx_FindPubVar(plugin->getAMX(), "NULL_STRING", &addr) != AMX_ERR_NOTFOUND)
			{
				plugin->m_pNullStringOfs = get_amxaddr(plugin->getAMX(), addr);
			}

			if (amx_FindPubVar(plugin->getAMX(), "NULL_VECTOR", &addr) != AMX_ERR_NOTFOUND)
			{
				plugin->m_pNullVectorOfs = get_amxaddr(plugin->getAMX(), addr);
			}
		}
	}

	fclose(fp);

	return pCounter;
}
Пример #19
0
// Same as amx_strtok but fixes and expands trim, returns token pos if token was found, -1 otherwise
static cell AMX_NATIVE_CALL amx_strtok2(AMX *amx, cell *params)
{
	int left_pos = 0, right_pos = 0, len, pos = -1;
	unsigned int i = 0;

	char *string = get_amxstring(amx, params[1], 0, len);
	char *left = new char[len + 1], *right = new char[len + 1];
	int left_max = params[3], right_max = params[5];
	char token = static_cast<char>(params[6]);
	
	/*	Trim flags:
			1 - ltrim left
			2 - rtrim left
			4 - ltrim right
			8 - rtrim right
	*/
	int trim = params[7];

	// ltrim left
	if (trim & 1 && isspace(string[i]))
	{
		while (isspace(string[++i]));
	}

	for (; i < (unsigned int) len; ++i)
	{
		if (string[i] == token)
		{
			pos = i;
			++i;
			break;
		}

		left[left_pos++] = string[i];
	}

	// rtrim left
	if (trim & 2 && left_pos && isspace(left[left_pos - 1]))
	{
		while (--left_pos >= 0 && isspace(left[left_pos]));
		
		++left_pos;
	}

	// ltrim right
	if (trim & 4 && isspace(string[i]))
	{
		while (isspace(string[++i]));
	}

	for (; i < (unsigned int) len; ++i)
	{
		right[right_pos++] = string[i];	
	}

	// rtrim right
	if (trim & 8 && right_pos && isspace(right[right_pos - 1]))
	{
		while (--right_pos >= 0 && isspace(right[right_pos]));

		++right_pos;
	}

	right[right_pos] = 0;
	left[left_pos] = 0;
	set_amxstring(amx, params[2], left, left_max);
	set_amxstring(amx, params[4], right, right_max);

	delete [] left;
	delete [] right;

	return pos;
}
Пример #20
0
//added by BAILOPAN
//Takes a string and breaks it into a 1st param and rest params
//strbreak(String[], First[], FirstLen, Rest[], RestLen)
static cell AMX_NATIVE_CALL strbreak(AMX *amx, cell *params)	/* 5 param */
{

	int _len;
	bool in_quote = false;
	bool had_quotes = false;
	size_t i = 0;
	size_t beg = 0;

	char *string = get_amxstring(amx, params[1], 0, _len);
	cell *left = get_amxaddr(amx, params[2]);
	cell *right = get_amxaddr(amx, params[4]);
	int LeftMax = params[3];
	int RightMax = params[5];

	size_t len = (size_t)_len;

    while (isspace(string[i]) && i<len)
		i++;
    beg = i;
	for (; i<len; i++)
	{
		if (string[i] == '"' && !in_quote)
		{
			in_quote = (had_quotes = true);
		} else if (string[i] == '"' && in_quote) {
			in_quote = false;
			if (i == len-1)
				goto do_copy;
		} else {
			if (isspace(string[i]) && !in_quote)
			{
do_copy:
				size_t pos = i;
				while (isspace(string[i]))
					i++;
				const char *start = had_quotes ? &(string[beg+1]) : &(string[beg]);
				size_t _end = had_quotes ? (i==len-1 ? 1 : 2) : 0;
				size_t end = (pos - _end > (size_t)LeftMax) ? (size_t)LeftMax : pos - _end;
				size_t to_go = end-beg;
				if (end && to_go)
				{
					while (to_go--)
						*left++ = (cell)*start++;
				}
				*left = '\0';
				end = (len-i+1 > (size_t)RightMax) ? (size_t)RightMax : len-i+1;
                if (end)
				{
					start = &(string[i]);
					while (end--)
						*right++ = (cell)*start++;
				}
				*right = '\0';
				return 1;
			}
		}
	}

	//if we got here, there was nothing to break
	set_amxstring(amx, params[2], &(string[beg]), LeftMax);
	if (RightMax)
		*right = '\0';

	return 1;
}
Пример #21
0
// GetMTAMapName(mapid, name[], len = sizeof(name));
cell AMX_NATIVE_CALL n_GetMTAMapName(AMX* amx, cell* params)
{	
	std::string strMapName = *pConverter->GetMTAMapName(static_cast<int>(params[1]));
	return set_amxstring(amx, params[2], strMapName.c_str(), params[3]);
}