forked from nukkonyan/Tklib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvars.inc
533 lines (485 loc) · 24.2 KB
/
convars.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/**
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#if defined _convars_included
#endinput
#endif
#define _convars_included
/**
* Console variable bound values used with Get/SetConVarBounds()
*/
enum ConVarBounds
{
ConVarBound_Upper = 0,
ConVarBound_Lower
};
/**
* Console variable query result values.
*/
enum ConVarQueryResult
{
ConVarQuery_Cancelled = -1, //< Client disconnected during query */
ConVarQuery_Okay = 0, //< Retrieval of client convar value was successful. */
ConVarQuery_NotFound, //< Client convar was not found. */
ConVarQuery_NotValid, //< A console command with the same name was found, but there is no convar. */
ConVarQuery_Protected //< Client convar was found, but it is protected. The server cannot retrieve its value. */
};
/**
* Called when a console variable's value is changed.
*
* @param convar Handle to the convar that was changed.
* @param oldValue String containing the value of the convar before it was changed.
* @param newValue String containing the new value of the convar.
*/
typedef ConVarChanged = function void (ConVar convar, const char[] oldValue, const char[] newValue);
/**
* Creates a new console variable.
*
* @param name Name of new convar.
* @param defaultValue String containing the default value of new convar.
* @param description Optional description of the convar.
* @param flags Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details.
* @param hasMin Optional boolean that determines if the convar has a minimum value.
* @param min Minimum floating point value that the convar can have if hasMin is true.
* @param hasMax Optional boolean that determines if the convar has a maximum value.
* @param max Maximum floating point value that the convar can have if hasMax is true.
* @return A handle to the newly created convar. If the convar already exists, a handle to it will still be returned.
* @error Convar name is blank or is the same as an existing console command.
*/
native ConVar CreateConVar(
const char[] name,
const char[] defaultValue,
const char[] description="",
int flags=0,
bool hasMin=false, float min=0.0,
bool hasMax=false, float max=0.0);
/**
* Searches for a console variable.
*
* @param name Name of convar to find.
* @return A ConVar object if found; null otherwise.
*/
native ConVar FindConVar(const char[] name);
// A ConVar is a configurable, named setting in the srcds console.
methodmap ConVar < Handle
{
// Retrieves or sets a boolean value for the convar.
property bool BoolValue {
public native get();
public native set(bool b);
}
// Retrieves or sets an integer value for the convar.
property int IntValue {
public native get();
public native set(int value);
}
// Retrieves or sets a float value for the convar.
property float FloatValue {
public native get();
public native set(float value);
}
// Gets or sets the flag bits (FCVAR_*) on the convar.
property int Flags {
public native get();
public native set(int flags);
}
// Retrieves the plugin handle of the convar's creator
property Handle Plugin {
public native get();
}
//Creates a new console variable.
//
// @param name Name of new convar.
// @param defaultValue String containing the default value of new convar.
// @param description Optional description of the convar.
// @param flags Optional bitstring of flags determining how the convar should be handled. See FCVAR_* constants for more details.
// @param hasMin Optional boolean that determines if the convar has a minimum value.
// @param min Minimum floating point value that the convar can have if hasMin is true.
// @param hasMax Optional boolean that determines if the convar has a maximum value.
// @param max Maximum floating point value that the convar can have if hasMax is true.
// @return A handle to the newly created convar. If the convar already exists, a handle to it will still be returned.
// @error Convar name is blank or is the same as an existing console command.
public ConVar(const char[] name, const char[] defaultValue, const char[] description="", int flags=0, bool hasMin=false, float min=0.0, bool hasMax=false, float max=0.0)
{
return CreateConVar(name, defaultValue, description, flags, hasMin, min, hasMax, max);
}
// Sets the boolean value of a console variable.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param value New boolean value.
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void SetBool(bool value, bool replicate=false, bool notify=false);
// Sets the integer value of a console variable.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param value New integer value.
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void SetInt(int value, bool replicate=false, bool notify=false);
// Sets the floating point value of a console variable.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param value New floating point value.
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void SetFloat(float value, bool replicate=false, bool notify=false);
// Retrieves the string value of a console variable.
//
// @param convar Handle to the convar.
// @param value Buffer to store the value of the convar.
// @param maxlength Maximum length of string buffer.
public native void GetString(char[] value, int maxlength);
// Sets the string value of a console variable.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param value New string value.
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void SetString(const char[] value, bool replicate=false, bool notify=false);
// Resets the console variable to its default value.
//
// Note: The replicate and notify params are only relevant for the
// original, Dark Messiah, and Episode 1 engines. Newer engines
// automatically do these things when the convar value is changed.
//
// @param replicate If set to true, the new convar value will be set on all clients.
// This will only work if the convar has the FCVAR_REPLICATED flag
// and actually exists on clients.
// @param notify If set to true, clients will be notified that the convar has changed.
// This will only work if the convar has the FCVAR_NOTIFY flag.
public native void RestoreDefault(bool replicate=false, bool notify=false);
// Retrieves the default string value of a console variable.
//
// @param value Buffer to store the default value of the convar.
// @param maxlength Maximum length of string buffer.
// @return Number of bytes written to the buffer (UTF-8 safe).
public native int GetDefault(char[] value, int maxlength);
// Retrieves the specified bound of a console variable.
//
// @param type Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
// @param value By-reference cell to store the specified floating point bound value.
// @return True if the convar has the specified bound set, false otherwise.
public native bool GetBounds(ConVarBounds type, float &value);
// Sets the specified bound of a console variable.
//
// @param type Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
// @param set If set to true, convar will use specified bound. If false, bound will be removed.
// @param value Floating point value to use as the specified bound.
public native void SetBounds(ConVarBounds type, bool set, float value=0.0);
// Retrieves the name of a console variable.
//
// @param name Buffer to store the name of the convar.
// @param maxlength Maximum length of string buffer.
public native void GetName(char[] name, int maxlength);
// Retrieves the description of a console variable.
//
// @param buffer Buffer to store the description of the convar.
// @param maxlength Maximum length of string buffer.
public native void GetDescription(char[] buffer, int maxlength);
// Replicates a convar value to a specific client. This does not change the actual convar value.
//
// @param client Client index
// @param value String value to send
// @return True on success, false on failure
// @error Invalid client index, client not in game, or client is fake
public native bool ReplicateToClient(int client, const char[] value);
// Creates a hook for when a console variable's value is changed.
//
// @param callback An OnConVarChanged function pointer.
public native void AddChangeHook(ConVarChanged callback);
// Removes a hook for when a console variable's value is changed.
//
// @param convar Handle to the convar.
// @param callback An OnConVarChanged function pointer.
// @error No active hook on convar.
public native void RemoveChangeHook(ConVarChanged callback);
}
/**
* Creates a hook for when a console variable's value is changed.
*
* @param convar Handle to the convar.
* @param callback An OnConVarChanged function pointer.
* @error Invalid or corrupt Handle or invalid callback function.
*/
native void HookConVarChange(Handle convar, ConVarChanged callback);
/**
* Removes a hook for when a console variable's value is changed.
*
* @param convar Handle to the convar.
* @param callback An OnConVarChanged function pointer.
* @error Invalid or corrupt Handle, invalid callback function, or no active hook on convar.
*/
native void UnhookConVarChange(Handle convar, ConVarChanged callback);
/**
* Returns the boolean value of a console variable.
*
* @param convar Handle to the convar.
* @return The boolean value of the convar.
* @error Invalid or corrupt Handle.
*/
native bool GetConVarBool(Handle convar);
/**
* Sets the boolean value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New boolean value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void SetConVarBool(Handle convar, bool value, bool replicate=false, bool notify=false);
/**
* Returns the integer value of a console variable.
*
* @param convar Handle to the convar.
* @return The integer value of the convar.
* @error Invalid or corrupt Handle.
*/
native int GetConVarInt(Handle convar);
/**
* Sets the integer value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New integer value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void SetConVarInt(Handle convar, int value, bool replicate=false, bool notify=false);
/**
* Returns the floating point value of a console variable.
*
* @param convar Handle to the convar.
* @return The floating point value of the convar.
* @error Invalid or corrupt Handle.
*/
native float GetConVarFloat(Handle convar);
/**
* Sets the floating point value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New floating point value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void SetConVarFloat(Handle convar, float value, bool replicate=false, bool notify=false);
/**
* Retrieves the string value of a console variable.
*
* @param convar Handle to the convar.
* @param value Buffer to store the value of the convar.
* @param maxlength Maximum length of string buffer.
* @error Invalid or corrupt Handle.
*/
native void GetConVarString(Handle convar, char[] value, int maxlength);
/**
* Sets the string value of a console variable.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param value New string value.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void SetConVarString(Handle convar, const char[] value, bool replicate=false, bool notify=false);
/**
* Resets the console variable to its default value.
*
* Note: The replicate and notify params are only relevant for the original, Dark Messiah, and
* Episode 1 engines. Newer engines automatically do these things when the convar value is changed.
*
* @param convar Handle to the convar.
* @param replicate If set to true, the new convar value will be set on all clients.
* This will only work if the convar has the FCVAR_REPLICATED flag
* and actually exists on clients.
* @param notify If set to true, clients will be notified that the convar has changed.
* This will only work if the convar has the FCVAR_NOTIFY flag.
* @error Invalid or corrupt Handle.
*/
native void ResetConVar(Handle convar, bool replicate=false, bool notify=false);
/**
* Retrieves the default string value of a console variable.
*
* @param convar Handle to the convar.
* @param value Buffer to store the default value of the convar.
* @param maxlength Maximum length of string buffer.
* @return Number of bytes written to the buffer (UTF-8 safe).
* @error Invalid or corrupt Handle.
*/
native int GetConVarDefault(Handle convar, char[] value, int maxlength);
/**
* Returns the bitstring of flags on a console variable.
*
* @param convar Handle to the convar.
* @return A bitstring containing the FCVAR_* flags that are enabled.
* @error Invalid or corrupt Handle.
*/
native int GetConVarFlags(Handle convar);
/**
* Sets the bitstring of flags on a console variable.
*
* @param convar Handle to the convar.
* @param flags A bitstring containing the FCVAR_* flags to enable.
* @error Invalid or corrupt Handle.
*/
native void SetConVarFlags(Handle convar, int flags);
/**
* Retrieves the specified bound of a console variable.
*
* @param convar Handle to the convar.
* @param type Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
* @param value By-reference cell to store the specified floating point bound value.
* @return True if the convar has the specified bound set, false otherwise.
* @error Invalid or corrupt Handle.
*/
native bool GetConVarBounds(Handle convar, ConVarBounds type, float &value);
/**
* Sets the specified bound of a console variable.
*
* @param convar Handle to the convar.
* @param type Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
* @param set If set to true, convar will use specified bound. If false, bound will be removed.
* @param value Floating point value to use as the specified bound.
* @error Invalid or corrupt Handle.
*/
native void SetConVarBounds(Handle convar, ConVarBounds type, bool set, float value=0.0);
/**
* Retrieves the name of a console variable.
*
* @param convar Handle to the convar.
* @param name Buffer to store the name of the convar.
* @param maxlength Maximum length of string buffer.
* @error Invalid or corrupt Handle.
*/
native void GetConVarName(Handle convar, char[] name, int maxlength);
/**
* Replicates a convar value to a specific client. This does not change the actual convar value.
*
* @param client Client index
* @param convar ConVar handle
* @param value String value to send
* @return True on success, false on failure
* @error Invalid client index, client not in game, or client is fake
*/
native bool SendConVarValue(int client, Handle convar, const char[] value);
typeset ConVarQueryFinished
{
// Called when a query to retrieve a client's console variable has finished.
//
// @param cookie Unique identifier of query.
// @param client Player index.
// @param result Result of query that tells one whether or not query was successful.
// See ConVarQueryResult enum for more details.
// @param convarName Name of client convar that was queried.
// @param convarValue Value of client convar that was queried if successful. This will be "" if it was not.
// @param value Value that was passed when query was started.
function void (QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue, any value);
// Called when a query to retrieve a client's console variable has finished.
//
// @param cookie Unique identifier of query.
// @param client Player index.
// @param result Result of query that tells one whether or not query was successful.
// See ConVarQueryResult enum for more details.
// @param convarName Name of client convar that was queried.
// @param convarValue Value of client convar that was queried if successful. This will be "" if it was not.
function void (QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue);
};
/**
* Starts a query to retrieve the value of a client's console variable.
*
* @param client Player index.
* @param cvarName Name of client convar to query.
* @param callback A function to use as a callback when the query has finished.
* @param value Optional value to pass to the callback function.
* @return A cookie that uniquely identifies the query.
* Returns QUERYCOOKIE_FAILED on failure, such as when used on a bot.
*/
native QueryCookie QueryClientConVar(int client, const char[] cvarName, ConVarQueryFinished callback, any value=0);
/**
* Returns true if the supplied character is valid in a ConVar name.
*
* @param c Character to validate.
* @return True is valid for ConVars, false otherwise
*/
stock bool IsValidConVarChar(int c)
{
return (c == '_' || IsCharAlpha(c) || IsCharNumeric(c));
}