Partly addressed amb197 - added network string table natives to SDKTools
authorScott Ehlert <ds@alliedmods.net>
Sun Jul 15 07:44:17 2007 +0000 (2007-07-15)
changeset 11144b4a61f32a96
parent 1113 c09265bc03ce
child 1115 13d96df8ead8
Partly addressed amb197 - added network string table natives to SDKTools
(Wow, I don't like this code)
extensions/sdktools/extension.cpp
extensions/sdktools/extension.h
extensions/sdktools/msvc8/sdktools.vcproj
extensions/sdktools/vsound.cpp
extensions/sdktools/vstringtable.cpp
plugins/include/sdktools.inc
plugins/include/sdktools_stringtables.inc
     1.1 --- a/extensions/sdktools/extension.cpp	Sun Jul 15 03:07:58 2007 +0000
     1.2 +++ b/extensions/sdktools/extension.cpp	Sun Jul 15 07:44:17 2007 +0000
     1.3 @@ -35,10 +35,11 @@
     1.4  SDKTools g_SdkTools;		/**< Global singleton for extension's main interface */
     1.5  IServerGameEnts *gameents = NULL;
     1.6  IEngineTrace *enginetrace = NULL;
     1.7 +IEngineSound *engsound = NULL;
     1.8 +INetworkStringTableContainer *netstringtables = NULL;
     1.9  IBinTools *g_pBinTools = NULL;
    1.10  IGameConfig *g_pGameConf = NULL;
    1.11  IGameHelpers *g_pGameHelpers = NULL;
    1.12 -IEngineSound *engsound = NULL;
    1.13  HandleType_t g_CallHandle = 0;
    1.14  HandleType_t g_TraceHandle = 0;
    1.15  
    1.16 @@ -47,6 +48,7 @@
    1.17  extern sp_nativeinfo_t g_CallNatives[];
    1.18  extern sp_nativeinfo_t g_TENatives[];
    1.19  extern sp_nativeinfo_t g_TRNatives[];
    1.20 +extern sp_nativeinfo_t g_StringTableNatives[];
    1.21  
    1.22  bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late)
    1.23  {
    1.24 @@ -56,6 +58,7 @@
    1.25  	sharesys->AddNatives(myself, g_TENatives);
    1.26  	sharesys->AddNatives(myself, g_SoundNatives);
    1.27  	sharesys->AddNatives(myself, g_TRNatives);
    1.28 +	sharesys->AddNatives(myself, g_StringTableNatives);
    1.29  
    1.30  	SM_GET_IFACE(GAMEHELPERS, g_pGameHelpers);
    1.31  
    1.32 @@ -107,6 +110,7 @@
    1.33  	GET_V_IFACE_ANY(serverFactory, gameents, IServerGameEnts, INTERFACEVERSION_SERVERGAMEENTS);
    1.34  	GET_V_IFACE_ANY(engineFactory, engsound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
    1.35  	GET_V_IFACE_ANY(engineFactory, enginetrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER);
    1.36 +	GET_V_IFACE_ANY(engineFactory, netstringtables, INetworkStringTableContainer, INTERFACENAME_NETWORKSTRINGTABLESERVER);
    1.37  
    1.38  	return true;
    1.39  }
     2.1 --- a/extensions/sdktools/extension.h	Sun Jul 15 03:07:58 2007 +0000
     2.2 +++ b/extensions/sdktools/extension.h	Sun Jul 15 07:44:17 2007 +0000
     2.3 @@ -66,12 +66,16 @@
     2.4  	bool RegisterConCommandBase(ConCommandBase *pVar);
     2.5  };
     2.6  
     2.7 +/* Interfaces from engine or gamedll */
     2.8  extern IServerGameEnts *gameents;
     2.9  extern IEngineTrace *enginetrace;
    2.10 +extern IEngineSound *engsound;
    2.11 +extern INetworkStringTableContainer *netstringtables;
    2.12 +/* Interfaces from SourceMod */
    2.13  extern IBinTools *g_pBinTools;
    2.14  extern IGameConfig *g_pGameConf;
    2.15  extern IGameHelpers *g_pGameHelpers;
    2.16 -extern IEngineSound *engsound;
    2.17 +/* Handle types */
    2.18  extern HandleType_t g_CallHandle;
    2.19  extern HandleType_t g_TraceHandle;
    2.20  
     3.1 --- a/extensions/sdktools/msvc8/sdktools.vcproj	Sun Jul 15 03:07:58 2007 +0000
     3.2 +++ b/extensions/sdktools/msvc8/sdktools.vcproj	Sun Jul 15 07:44:17 2007 +0000
     3.3 @@ -1,7 +1,7 @@
     3.4  <?xml version="1.0" encoding="Windows-1252"?>
     3.5  <VisualStudioProject
     3.6  	ProjectType="Visual C++"
     3.7 -	Version="8,00"
     3.8 +	Version="8.00"
     3.9  	Name="sdktools"
    3.10  	ProjectGUID="{7A740927-C751-4312-BF9D-6367F8C508F8}"
    3.11  	RootNamespace="sdk"
    3.12 @@ -223,6 +223,10 @@
    3.13  				RelativePath="..\vsound.cpp"
    3.14  				>
    3.15  			</File>
    3.16 +			<File
    3.17 +				RelativePath="..\vstringtable.cpp"
    3.18 +				>
    3.19 +			</File>
    3.20  		</Filter>
    3.21  		<Filter
    3.22  			Name="Header Files"
     4.1 --- a/extensions/sdktools/vsound.cpp	Sun Jul 15 03:07:58 2007 +0000
     4.2 +++ b/extensions/sdktools/vsound.cpp	Sun Jul 15 07:44:17 2007 +0000
     4.3 @@ -1,3 +1,26 @@
     4.4 +/**
     4.5 + * vim: set ts=4 :
     4.6 + * ===============================================================
     4.7 + * SourceMod SDK Tools Extension
     4.8 + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
     4.9 + * ===============================================================
    4.10 + *
    4.11 + * This program is free software; you can redistribute it and/or
    4.12 + * modify it under the terms of the GNU General Public License
    4.13 + * as published by the Free Software Foundation; either version 2
    4.14 + * of the License, or (at your option) any later version.
    4.15 + * This program is distributed in the hope that it will be useful,
    4.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.18 + * GNU General Public License for more details.
    4.19 + * 
    4.20 + * You should have received a copy of the GNU General Public License
    4.21 + * along with this program; if not, write to the Free Software
    4.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    4.23 + *
    4.24 + * Version: $Id$
    4.25 + */
    4.26 +
    4.27  #include "extension.h"
    4.28  #include "CellRecipientFilter.h"
    4.29  
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/extensions/sdktools/vstringtable.cpp	Sun Jul 15 07:44:17 2007 +0000
     5.3 @@ -0,0 +1,261 @@
     5.4 +/**
     5.5 + * vim: set ts=4 :
     5.6 + * ===============================================================
     5.7 + * SourceMod SDK Tools Extension
     5.8 + * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
     5.9 + * ===============================================================
    5.10 + *
    5.11 + * This program is free software; you can redistribute it and/or
    5.12 + * modify it under the terms of the GNU General Public License
    5.13 + * as published by the Free Software Foundation; either version 2
    5.14 + * of the License, or (at your option) any later version.
    5.15 + * This program is distributed in the hope that it will be useful,
    5.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.18 + * GNU General Public License for more details.
    5.19 + * 
    5.20 + * You should have received a copy of the GNU General Public License
    5.21 + * along with this program; if not, write to the Free Software
    5.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    5.23 + *
    5.24 + * Version: $Id$
    5.25 + */
    5.26 +
    5.27 +#include "extension.h"
    5.28 +
    5.29 +static cell_t LockStringTables(IPluginContext *pContext, const cell_t *params)
    5.30 +{
    5.31 +	bool lock = params[1] ? true : false;
    5.32 +
    5.33 +	return engine->LockNetworkStringTables(lock) ? 1 : 0;
    5.34 +}
    5.35 +
    5.36 +static cell_t FindStringTable(IPluginContext *pContext, const cell_t *params)
    5.37 +{
    5.38 +	char *name;
    5.39 +	pContext->LocalToString(params[1], &name);
    5.40 +
    5.41 +	INetworkStringTable *pTable = netstringtables->FindTable(name);
    5.42 +
    5.43 +	if (!pTable)
    5.44 +	{
    5.45 +		return INVALID_STRING_TABLE;
    5.46 +	}
    5.47 +
    5.48 +	return pTable->GetTableId();
    5.49 +}
    5.50 +
    5.51 +static cell_t GetNumStringTables(IPluginContext *pContext, const cell_t *params)
    5.52 +{
    5.53 +	return netstringtables->GetNumTables();
    5.54 +}
    5.55 +
    5.56 +static cell_t GetStringTableNumStrings(IPluginContext *pContext, const cell_t *params)
    5.57 +{
    5.58 +	TABLEID idx = static_cast<TABLEID>(params[1]);
    5.59 +	INetworkStringTable *pTable = netstringtables->GetTable(idx);
    5.60 +
    5.61 +	if (!pTable)
    5.62 +	{
    5.63 +		return pContext->ThrowNativeError("Invalid string table index %d", idx);
    5.64 +	}
    5.65 +
    5.66 +	return pTable->GetNumStrings();
    5.67 +}
    5.68 +
    5.69 +static cell_t GetStringTableMaxStrings(IPluginContext *pContext, const cell_t *params)
    5.70 +{
    5.71 +	TABLEID idx = static_cast<TABLEID>(params[1]);
    5.72 +	INetworkStringTable *pTable = netstringtables->GetTable(idx);
    5.73 +
    5.74 +	if (!pTable)
    5.75 +	{
    5.76 +		return pContext->ThrowNativeError("Invalid string table index %d", idx);
    5.77 +	}
    5.78 +
    5.79 +	return pTable->GetMaxStrings();
    5.80 +}
    5.81 +
    5.82 +static cell_t GetStringTableName(IPluginContext *pContext, const cell_t *params)
    5.83 +{
    5.84 +	TABLEID idx = static_cast<TABLEID>(params[1]);
    5.85 +	INetworkStringTable *pTable = netstringtables->GetTable(idx);
    5.86 +	size_t numBytes;
    5.87 +
    5.88 +	if (!pTable)
    5.89 +	{
    5.90 +		return pContext->ThrowNativeError("Invalid string table index %d", idx);
    5.91 +	}
    5.92 +
    5.93 +	pContext->StringToLocalUTF8(params[2], params[3], pTable->GetTableName(), &numBytes);
    5.94 +
    5.95 +	return numBytes;
    5.96 +}
    5.97 +
    5.98 +static cell_t FindStringIndex(IPluginContext *pContext, const cell_t *params)
    5.99 +{
   5.100 +	TABLEID idx = static_cast<TABLEID>(params[1]);
   5.101 +	INetworkStringTable *pTable = netstringtables->GetTable(idx);
   5.102 +	char *str;
   5.103 +
   5.104 +	if (!pTable)
   5.105 +	{
   5.106 +		return pContext->ThrowNativeError("Invalid string table index %d", idx);
   5.107 +	}
   5.108 +
   5.109 +	pContext->LocalToString(params[2], &str);
   5.110 +
   5.111 +	return pTable->FindStringIndex(str);
   5.112 +}
   5.113 +
   5.114 +static cell_t ReadStringTable(IPluginContext *pContext, const cell_t *params)
   5.115 +{
   5.116 +	TABLEID idx = static_cast<TABLEID>(params[1]);
   5.117 +	INetworkStringTable *pTable = netstringtables->GetTable(idx);
   5.118 +	int stringidx;
   5.119 +	const char *value;
   5.120 +	size_t numBytes;
   5.121 +
   5.122 +	if (!pTable)
   5.123 +	{
   5.124 +		return pContext->ThrowNativeError("Invalid string table index %d", idx);
   5.125 +	}
   5.126 +	
   5.127 +	stringidx = params[2];
   5.128 +	value = pTable->GetString(stringidx);
   5.129 +
   5.130 +	if (!value)
   5.131 +	{
   5.132 +		return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName());
   5.133 +	}
   5.134 +
   5.135 +	pContext->StringToLocalUTF8(params[3], params[4], value, &numBytes);
   5.136 +
   5.137 +	return numBytes;
   5.138 +}
   5.139 +
   5.140 +static cell_t GetStringTableDataLength(IPluginContext *pContext, const cell_t *params)
   5.141 +{
   5.142 +	TABLEID idx = static_cast<TABLEID>(params[1]);
   5.143 +	INetworkStringTable *pTable = netstringtables->GetTable(idx);
   5.144 +	int stringidx;
   5.145 +	const void *userdata;
   5.146 +	int datalen;
   5.147 +
   5.148 +	if (!pTable)
   5.149 +	{
   5.150 +		return pContext->ThrowNativeError("Invalid string table index %d", idx);
   5.151 +	}
   5.152 +
   5.153 +	stringidx = params[2];
   5.154 +	if (stringidx < 0 || stringidx >= pTable->GetNumStrings())
   5.155 +	{
   5.156 +		return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName());
   5.157 +	}
   5.158 +
   5.159 +	userdata = pTable->GetStringUserData(stringidx, &datalen);
   5.160 +	if (!userdata)
   5.161 +	{
   5.162 +		datalen = 0;
   5.163 +	}
   5.164 +
   5.165 +	return datalen;
   5.166 +}
   5.167 +
   5.168 +static cell_t GetStringTableData(IPluginContext *pContext, const cell_t *params)
   5.169 +{
   5.170 +	TABLEID idx = static_cast<TABLEID>(params[1]);
   5.171 +	INetworkStringTable *pTable = netstringtables->GetTable(idx);
   5.172 +	int stringidx;
   5.173 +	const char *userdata;
   5.174 +	int datalen;
   5.175 +	size_t numBytes;
   5.176 +
   5.177 +	if (!pTable)
   5.178 +	{
   5.179 +		return pContext->ThrowNativeError("Invalid string table index %d", idx);
   5.180 +	}
   5.181 +
   5.182 +	stringidx = params[2];
   5.183 +	if (stringidx < 0 || stringidx >= pTable->GetNumStrings())
   5.184 +	{
   5.185 +		return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName());
   5.186 +	}
   5.187 +
   5.188 +	userdata = (const char *)pTable->GetStringUserData(stringidx, &datalen);
   5.189 +	if (!userdata)
   5.190 +	{
   5.191 +		userdata = "";
   5.192 +	}
   5.193 +
   5.194 +	pContext->StringToLocalUTF8(params[3], params[4], userdata, &numBytes);
   5.195 +
   5.196 +	return numBytes;
   5.197 +}
   5.198 +
   5.199 +CON_COMMAND(sm_lockstate, "Lock state")
   5.200 +{
   5.201 +	bool save = engine->LockNetworkStringTables(false);
   5.202 +	Msg("save: %d\n", save);
   5.203 +	engine->LockNetworkStringTables(save);
   5.204 +}
   5.205 +
   5.206 +static cell_t SetStringTableData(IPluginContext *pContext, const cell_t *params)
   5.207 +{
   5.208 +	TABLEID idx = static_cast<TABLEID>(params[1]);
   5.209 +	INetworkStringTable *pTable = netstringtables->GetTable(idx);
   5.210 +	int stringidx;
   5.211 +	char *userdata;
   5.212 +
   5.213 +	if (!pTable)
   5.214 +	{
   5.215 +		return pContext->ThrowNativeError("Invalid string table index %d", idx);
   5.216 +	}
   5.217 +
   5.218 +	stringidx = params[2];
   5.219 +	if (stringidx < 0 || stringidx >= pTable->GetNumStrings())
   5.220 +	{
   5.221 +		return pContext->ThrowNativeError("Invalid string index specified for table (index %d) (table \"%s\")", stringidx, pTable->GetTableName());
   5.222 +	}
   5.223 +
   5.224 +	pContext->LocalToString(params[3], &userdata);
   5.225 +	pTable->SetStringUserData(stringidx, params[4], userdata);
   5.226 +
   5.227 +	return 1;
   5.228 +}
   5.229 +
   5.230 +static cell_t AddToStringTable(IPluginContext *pContext, const cell_t *params)
   5.231 +{
   5.232 +	TABLEID idx = static_cast<TABLEID>(params[1]);
   5.233 +	INetworkStringTable *pTable = netstringtables->GetTable(idx);
   5.234 +	char *str, *userdata;
   5.235 +
   5.236 +	if (!pTable)
   5.237 +	{
   5.238 +		return pContext->ThrowNativeError("Invalid string table index %d", idx);
   5.239 +	}
   5.240 +
   5.241 +	pContext->LocalToString(params[2], &str);
   5.242 +	pContext->LocalToString(params[3], &userdata);
   5.243 +
   5.244 +	pTable->AddString(str, params[4], userdata);
   5.245 +
   5.246 +	return 1;
   5.247 +}
   5.248 +
   5.249 +sp_nativeinfo_t g_StringTableNatives[] = 
   5.250 +{
   5.251 +	{"LockStringTables",			LockStringTables},
   5.252 +	{"FindStringTable",				FindStringTable},
   5.253 +	{"GetNumStringTables",			GetNumStringTables},
   5.254 +	{"GetStringTableNumStrings",	GetStringTableNumStrings},
   5.255 +	{"GetStringTableMaxStrings",	GetStringTableMaxStrings},
   5.256 +	{"GetStringTableName",			GetStringTableName},
   5.257 +	{"FindStringIndex",				FindStringIndex},
   5.258 +	{"ReadStringTable",				ReadStringTable},
   5.259 +	{"GetStringTableDataLength",	GetStringTableDataLength},
   5.260 +	{"GetStringTableData",			GetStringTableData},
   5.261 +	{"SetStringTableData",			SetStringTableData},
   5.262 +	{"AddToStringTable",			AddToStringTable},
   5.263 +	{NULL,							NULL},
   5.264 +};
     6.1 --- a/plugins/include/sdktools.inc	Sun Jul 15 03:07:58 2007 +0000
     6.2 +++ b/plugins/include/sdktools.inc	Sun Jul 15 07:44:17 2007 +0000
     6.3 @@ -21,12 +21,13 @@
     6.4  #include <core>
     6.5  #include <sdktools_engine>
     6.6  #include <sdktools_functions>
     6.7 -#include <sdktools_tempents>
     6.8 -#include <sdktools_tempents_stocks>
     6.9  #if !defined SDKTOOLS_DISABLE_SOUNDAPI
    6.10  #include <sdktools_sound>
    6.11  #endif
    6.12 +#include <sdktools_stringtables>
    6.13  #include <sdktools_trace>
    6.14 +#include <sdktools_tempents>
    6.15 +#include <sdktools_tempents_stocks>
    6.16  
    6.17  enum SDKCallType
    6.18  {
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/plugins/include/sdktools_stringtables.inc	Sun Jul 15 07:44:17 2007 +0000
     7.3 @@ -0,0 +1,163 @@
     7.4 +/**
     7.5 + * vim: set ts=4 :
     7.6 + * ===============================================================
     7.7 + * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     7.8 + * ===============================================================
     7.9 + *
    7.10 + *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
    7.11 + * or modified under the Terms and Conditions of its License Agreement, which is found 
    7.12 + * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    7.13 + * may change at any time.  To view the latest information, see:
    7.14 + *   http://www.sourcemod.net/license.php
    7.15 + *
    7.16 + * Version: $Id$
    7.17 + */
    7.18 +
    7.19 +#if defined _sdktools_stringtables_included
    7.20 +  #endinput
    7.21 +#endif
    7.22 +#define _sdktools_stringtables_included
    7.23 +
    7.24 +#define INVALID_STRING_TABLE -1		/**< An invalid string table index */
    7.25 +#define INVALID_STRING_INDEX -1		/**< An invalid string index in a table */
    7.26 +
    7.27 +/**
    7.28 + * Searches for a string table.
    7.29 + *
    7.30 + * @param name			Name of string table to find.
    7.31 + * @return				A string table index number if found, INVALID_STRING_TABLE otherwise.
    7.32 + */
    7.33 +native FindStringTable(const String:name[]);
    7.34 +
    7.35 +/**
    7.36 + * Returns the number of string tables that currently exist.
    7.37 + *
    7.38 + * @return				Number of string tables that currently exist.
    7.39 + */
    7.40 +native GetNumStringTables();
    7.41 +
    7.42 +/**
    7.43 + * Returns the number of strings that currently exist in a given string table.
    7.44 + *
    7.45 + * @param tableidx		A string table index.
    7.46 + * @return				Number of strings that currently exist.
    7.47 + * @error				Invalid string table index.
    7.48 + */
    7.49 +native GetStringTableNumStrings(tableidx);
    7.50 +
    7.51 +/**
    7.52 + * Returns the maximum number of strings that are allowed in a given string table.
    7.53 + *
    7.54 + * @param tableidx		A string table index.
    7.55 + * @return				Maximum number of strings allowed.
    7.56 + * @error				Invalid string table index.
    7.57 + */
    7.58 +native GetStringTableMaxStrings(tableidx);
    7.59 +
    7.60 +/**
    7.61 + * Retrieves the name of a string table.
    7.62 + *
    7.63 + * @param tableidx		A string table index.
    7.64 + * @param name			Buffer to store the name of the string table.
    7.65 + * @param maxlength		Maximum length of string buffer.
    7.66 + * @return				Number of bytes written to the buffer (UTF-8 safe).
    7.67 + * @error				Invalid string table index.
    7.68 + */
    7.69 +native GetStringTableName(tableidx, String:name[], maxlength);
    7.70 +
    7.71 +/**
    7.72 + * Searches for the index of a given string in a string table.
    7.73 + *
    7.74 + * @param tableidx		A string table index.
    7.75 + * @param string		String to find.
    7.76 + * @return				String index if found, INVALID_STRING_INDEX otherwise.
    7.77 + * @error				Invalid string table index.
    7.78 + */
    7.79 +native FindStringIndex(tableidx, const String:str[]);
    7.80 +
    7.81 +/**
    7.82 + * Retrieves the string at a given index of a string table.
    7.83 + *
    7.84 + * @param tableidx		A string table index.
    7.85 + * @param stringidx		A string index.
    7.86 + * @param name			Buffer to store the string value.
    7.87 + * @param maxlength		Maximum length of string buffer.
    7.88 + * @return				Number of bytes written to the buffer (UTF-8 safe).
    7.89 + * @error				Invalid string table index or string index.
    7.90 + */
    7.91 +native ReadStringTable(tableidx, stringIdx, String:str[], maxlength);
    7.92 +
    7.93 +/**
    7.94 + * Returns the length of the user data associated with a given string index.
    7.95 + *
    7.96 + * @param tableidx		A string table index.
    7.97 + * @param stringidx		A string index.
    7.98 + * @return				Length of user data. This will be 0 if there is no user data.
    7.99 + * @error				Invalid string table index or string index.
   7.100 + */
   7.101 +native GetStringTableDataLength(tableidx, stringidx);
   7.102 +
   7.103 +/**
   7.104 + * Retrieves the user data associated with a given string index.
   7.105 + *
   7.106 + * @param tableidx		A string table index.
   7.107 + * @param stringidx		A string index.
   7.108 + * @param userdata		Buffer to store the user data. This will be set to "" if there is no user data.
   7.109 + * @param maxlength		Maximum length of string buffer.
   7.110 + * @return				Number of bytes written to the buffer (UTF-8 safe).
   7.111 + * @error				Invalid string table index or string index.
   7.112 + */
   7.113 +native GetStringTableData(tableidx, stringIdx, String:userdata[], maxlength);
   7.114 +
   7.115 +/**
   7.116 + * Sets the user data associated with a given string index.
   7.117 + *
   7.118 + * @param tableidx		A string table index.
   7.119 + * @param stringidx		A string index.
   7.120 + * @param userdata		User data string that will be set.
   7.121 + * @param length		Length of user data string. This should include the null terminator.
   7.122 + * @return				Number of bytes written to the buffer (UTF-8 safe).
   7.123 + * @error				Invalid string table index or string index.
   7.124 + */
   7.125 +native SetStringTableData(tableidx, stringIdx, const String:userdata[], length);
   7.126 +
   7.127 +/**
   7.128 + * Adds a string to a given string table.
   7.129 + *
   7.130 + * @param tableidx		A string table index.
   7.131 + * @param string		String to add.
   7.132 + * @param userdata		An optional user data string.
   7.133 + * @param length		Length of user data string. This should include the null terminator.
   7.134 + *						If set to -1, then user data will be not be altered if the specified string
   7.135 + *						already exists in the string table.
   7.136 + */
   7.137 +native AddToStringTable(tableidx, const String:str[], const String:userdata[]="", length=-1);
   7.138 +
   7.139 +/**
   7.140 + * Locks or unlocks the network string tables.
   7.141 + *
   7.142 + * @param lock			Determines whether network string tables should be locked.
   7.143 + *						True means the tables should be locked for writing; false means unlocked.
   7.144 + * @return				Previous lock state.
   7.145 + */
   7.146 +native bool:LockStringTables(bool:lock);
   7.147 +
   7.148 +/**
   7.149 + * Adds a file to the downloadables network string table.
   7.150 + * This forces a client to download the file if they do not already have it.
   7.151 + *
   7.152 + * @param filename		File that will be added to downloadables table.
   7.153 + */
   7.154 +stock AddFileToDownloadTable(const String:filename[])
   7.155 +{
   7.156 +	static table = INVALID_STRING_TABLE;
   7.157 +	
   7.158 +	if (table == INVALID_STRING_TABLE)
   7.159 +	{
   7.160 +		table = FindStringTable("downloadables");
   7.161 +	}
   7.162 +	
   7.163 +	new bool:save = LockStringTables(false);
   7.164 +	AddToStringTable(table, filename);
   7.165 +	LockStringTables(save);
   7.166 +}