|
ds@1114
|
1 |
/** |
|
ds@1114
|
2 |
* vim: set ts=4 : |
|
ds@1330
|
3 |
* ============================================================================= |
|
ds@1947
|
4 |
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1330
|
5 |
* ============================================================================= |
|
ds@1330
|
6 |
* |
|
ds@1330
|
7 |
* This file is part of the SourceMod/SourcePawn SDK. |
|
ds@1114
|
8 |
* |
|
ds@1330
|
9 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1330
|
10 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1330
|
11 |
* Free Software Foundation. |
|
ds@1330
|
12 |
* |
|
ds@1330
|
13 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1330
|
14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1330
|
15 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1330
|
16 |
* details. |
|
ds@1330
|
17 |
* |
|
ds@1330
|
18 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1330
|
19 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1330
|
20 |
* |
|
ds@1330
|
21 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1330
|
22 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1330
|
23 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1330
|
24 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1330
|
25 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1330
|
26 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1330
|
27 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1330
|
28 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@1114
|
29 |
* |
|
ds@1114
|
30 |
* Version: $Id$ |
|
ds@1114
|
31 |
*/ |
|
ds@1114
|
32 |
|
|
ds@1114
|
33 |
#if defined _sdktools_stringtables_included |
|
ds@1114
|
34 |
#endinput |
|
ds@1114
|
35 |
#endif |
|
ds@1114
|
36 |
#define _sdktools_stringtables_included |
|
ds@1114
|
37 |
|
|
ds@1114
|
38 |
#define INVALID_STRING_TABLE -1 /**< An invalid string table index */ |
|
ds@1114
|
39 |
#define INVALID_STRING_INDEX -1 /**< An invalid string index in a table */ |
|
ds@1114
|
40 |
|
|
ds@1114
|
41 |
/** |
|
ds@1114
|
42 |
* Searches for a string table. |
|
ds@1114
|
43 |
* |
|
ds@1114
|
44 |
* @param name Name of string table to find. |
|
ds@1114
|
45 |
* @return A string table index number if found, INVALID_STRING_TABLE otherwise. |
|
ds@1114
|
46 |
*/ |
|
ds@1114
|
47 |
native FindStringTable(const String:name[]); |
|
ds@1114
|
48 |
|
|
ds@1114
|
49 |
/** |
|
ds@1114
|
50 |
* Returns the number of string tables that currently exist. |
|
ds@1114
|
51 |
* |
|
ds@1114
|
52 |
* @return Number of string tables that currently exist. |
|
ds@1114
|
53 |
*/ |
|
ds@1114
|
54 |
native GetNumStringTables(); |
|
ds@1114
|
55 |
|
|
ds@1114
|
56 |
/** |
|
ds@1114
|
57 |
* Returns the number of strings that currently exist in a given string table. |
|
ds@1114
|
58 |
* |
|
ds@1114
|
59 |
* @param tableidx A string table index. |
|
ds@1114
|
60 |
* @return Number of strings that currently exist. |
|
ds@1114
|
61 |
* @error Invalid string table index. |
|
ds@1114
|
62 |
*/ |
|
ds@1114
|
63 |
native GetStringTableNumStrings(tableidx); |
|
ds@1114
|
64 |
|
|
ds@1114
|
65 |
/** |
|
ds@1114
|
66 |
* Returns the maximum number of strings that are allowed in a given string table. |
|
ds@1114
|
67 |
* |
|
ds@1114
|
68 |
* @param tableidx A string table index. |
|
ds@1114
|
69 |
* @return Maximum number of strings allowed. |
|
ds@1114
|
70 |
* @error Invalid string table index. |
|
ds@1114
|
71 |
*/ |
|
ds@1114
|
72 |
native GetStringTableMaxStrings(tableidx); |
|
ds@1114
|
73 |
|
|
ds@1114
|
74 |
/** |
|
ds@1114
|
75 |
* Retrieves the name of a string table. |
|
ds@1114
|
76 |
* |
|
ds@1114
|
77 |
* @param tableidx A string table index. |
|
ds@1114
|
78 |
* @param name Buffer to store the name of the string table. |
|
ds@1114
|
79 |
* @param maxlength Maximum length of string buffer. |
|
ds@1114
|
80 |
* @return Number of bytes written to the buffer (UTF-8 safe). |
|
ds@1114
|
81 |
* @error Invalid string table index. |
|
ds@1114
|
82 |
*/ |
|
ds@1114
|
83 |
native GetStringTableName(tableidx, String:name[], maxlength); |
|
ds@1114
|
84 |
|
|
ds@1114
|
85 |
/** |
|
ds@1114
|
86 |
* Searches for the index of a given string in a string table. |
|
ds@1114
|
87 |
* |
|
ds@1114
|
88 |
* @param tableidx A string table index. |
|
erik@3967
|
89 |
* @param str String to find. |
|
ds@1114
|
90 |
* @return String index if found, INVALID_STRING_INDEX otherwise. |
|
ds@1114
|
91 |
* @error Invalid string table index. |
|
ds@1114
|
92 |
*/ |
|
ds@1114
|
93 |
native FindStringIndex(tableidx, const String:str[]); |
|
ds@1114
|
94 |
|
|
ds@1114
|
95 |
/** |
|
ds@1114
|
96 |
* Retrieves the string at a given index of a string table. |
|
ds@1114
|
97 |
* |
|
ds@1114
|
98 |
* @param tableidx A string table index. |
|
ds@1114
|
99 |
* @param stringidx A string index. |
|
erik@3967
|
100 |
* @param str Buffer to store the string value. |
|
ds@1114
|
101 |
* @param maxlength Maximum length of string buffer. |
|
ds@1114
|
102 |
* @return Number of bytes written to the buffer (UTF-8 safe). |
|
ds@1114
|
103 |
* @error Invalid string table index or string index. |
|
ds@1114
|
104 |
*/ |
|
erik@3967
|
105 |
native ReadStringTable(tableidx, stringidx, String:str[], maxlength); |
|
ds@1114
|
106 |
|
|
ds@1114
|
107 |
/** |
|
ds@1114
|
108 |
* Returns the length of the user data associated with a given string index. |
|
ds@1114
|
109 |
* |
|
ds@1114
|
110 |
* @param tableidx A string table index. |
|
ds@1114
|
111 |
* @param stringidx A string index. |
|
ds@1114
|
112 |
* @return Length of user data. This will be 0 if there is no user data. |
|
ds@1114
|
113 |
* @error Invalid string table index or string index. |
|
ds@1114
|
114 |
*/ |
|
ds@1114
|
115 |
native GetStringTableDataLength(tableidx, stringidx); |
|
ds@1114
|
116 |
|
|
ds@1114
|
117 |
/** |
|
ds@1114
|
118 |
* Retrieves the user data associated with a given string index. |
|
ds@1114
|
119 |
* |
|
ds@1114
|
120 |
* @param tableidx A string table index. |
|
ds@1114
|
121 |
* @param stringidx A string index. |
|
ds@1114
|
122 |
* @param userdata Buffer to store the user data. This will be set to "" if there is no user data. |
|
ds@1114
|
123 |
* @param maxlength Maximum length of string buffer. |
|
ds@1114
|
124 |
* @return Number of bytes written to the buffer (UTF-8 safe). |
|
ds@1114
|
125 |
* @error Invalid string table index or string index. |
|
ds@1114
|
126 |
*/ |
|
erik@3967
|
127 |
native GetStringTableData(tableidx, stringidx, String:userdata[], maxlength); |
|
ds@1114
|
128 |
|
|
ds@1114
|
129 |
/** |
|
ds@1114
|
130 |
* Sets the user data associated with a given string index. |
|
ds@1114
|
131 |
* |
|
ds@1114
|
132 |
* @param tableidx A string table index. |
|
ds@1114
|
133 |
* @param stringidx A string index. |
|
ds@1114
|
134 |
* @param userdata User data string that will be set. |
|
ds@1114
|
135 |
* @param length Length of user data string. This should include the null terminator. |
|
ds@1114
|
136 |
* @return Number of bytes written to the buffer (UTF-8 safe). |
|
ds@1114
|
137 |
* @error Invalid string table index or string index. |
|
ds@1114
|
138 |
*/ |
|
erik@3967
|
139 |
native SetStringTableData(tableidx, stringidx, const String:userdata[], length); |
|
ds@1114
|
140 |
|
|
ds@1114
|
141 |
/** |
|
ds@1114
|
142 |
* Adds a string to a given string table. |
|
ds@1114
|
143 |
* |
|
ds@1114
|
144 |
* @param tableidx A string table index. |
|
erik@3967
|
145 |
* @param str String to add. |
|
ds@1114
|
146 |
* @param userdata An optional user data string. |
|
ds@1114
|
147 |
* @param length Length of user data string. This should include the null terminator. |
|
ds@1114
|
148 |
* If set to -1, then user data will be not be altered if the specified string |
|
ds@1114
|
149 |
* already exists in the string table. |
|
ds@1114
|
150 |
*/ |
|
ds@1114
|
151 |
native AddToStringTable(tableidx, const String:str[], const String:userdata[]="", length=-1); |
|
ds@1114
|
152 |
|
|
ds@1114
|
153 |
/** |
|
ds@1114
|
154 |
* Locks or unlocks the network string tables. |
|
ds@1114
|
155 |
* |
|
ds@1114
|
156 |
* @param lock Determines whether network string tables should be locked. |
|
ds@1114
|
157 |
* True means the tables should be locked for writing; false means unlocked. |
|
ds@1114
|
158 |
* @return Previous lock state. |
|
ds@1114
|
159 |
*/ |
|
ds@1114
|
160 |
native bool:LockStringTables(bool:lock); |
|
ds@1114
|
161 |
|
|
ds@1114
|
162 |
/** |
|
ds@1114
|
163 |
* Adds a file to the downloadables network string table. |
|
ds@1114
|
164 |
* This forces a client to download the file if they do not already have it. |
|
ds@1114
|
165 |
* |
|
ds@1114
|
166 |
* @param filename File that will be added to downloadables table. |
|
ds@1114
|
167 |
*/ |
|
ds@1115
|
168 |
stock AddFileToDownloadsTable(const String:filename[]) |
|
ds@1114
|
169 |
{ |
|
ds@1114
|
170 |
static table = INVALID_STRING_TABLE; |
|
ds@1114
|
171 |
|
|
ds@1114
|
172 |
if (table == INVALID_STRING_TABLE) |
|
ds@1114
|
173 |
{ |
|
ds@1114
|
174 |
table = FindStringTable("downloadables"); |
|
ds@1114
|
175 |
} |
|
ds@1114
|
176 |
|
|
ds@1114
|
177 |
new bool:save = LockStringTables(false); |
|
ds@1114
|
178 |
AddToStringTable(table, filename); |
|
ds@1114
|
179 |
LockStringTables(save); |
|
ds@1114
|
180 |
} |