plugins/include/console.inc
author Scott Ehlert <ds@alliedmods.net>
Thu Feb 08 21:41:28 2007 +0000 (2007-02-08)
changeset 457 9b8a85bf4175
child 465 8856d2e7018d
permissions -rw-r--r--
Initial import of convar stuff
1) Natives to create, find, set, and get convars
2) "cvars" option added to sm menu
3) Some internal additions to CPlugin to store a convar list
Still some things left to do...
ds@457
     1
/**
ds@457
     2
 * ===============================================================
ds@457
     3
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
ds@457
     4
 * ===============================================================
ds@457
     5
 *
ds@457
     6
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
ds@457
     7
 * or modified under the Terms and Conditions of its License Agreement, which is found 
ds@457
     8
 * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
ds@457
     9
 * may change at any time.  To view the latest information, see:
ds@457
    10
 *   http://www.sourcemod.net/license.php
ds@457
    11
 *
ds@457
    12
 * Version: $Id$
ds@457
    13
 */
ds@457
    14
 
ds@457
    15
#if defined _console_included
ds@457
    16
 #endinput
ds@457
    17
#endif
ds@457
    18
#define _console_included
ds@457
    19
ds@457
    20
/**
ds@457
    21
 * Flags for console commands and console variables
ds@457
    22
 * @note The descriptions for each constant come directly from the Source SDK.
ds@457
    23
 */
ds@457
    24
#define FCVAR_NONE              0       /**< The default, no flags at all */
ds@457
    25
#define FCVAR_UNREGISTERED      (1<<0)  /**< If this is set, don't add to linked list, etc. */
ds@457
    26
#define FCVAR_LAUNCHER          (1<<1)  /**< Defined by launcher. */
ds@457
    27
#define FCVAR_GAMEDLL           (1<<2)  /**< Defined by the game DLL. */
ds@457
    28
#define FCVAR_CLIENTDLL         (1<<3)  /**< Defined by the client DLL. */
ds@457
    29
#define FCVAR_MATERIAL_SYSTEM   (1<<4)  /**< Defined by the material system. */
ds@457
    30
#define FCVAR_PROTECTED         (1<<5)  /**< It's a server cvar, but we don't send the data since it's a password, etc. Sends 1 if it's not bland/zero, 0 otherwise as value. */
ds@457
    31
#define FCVAR_SPONLY            (1<<6)  /**< This cvar cannot be changed by clients connected to a multiplayer server. */
ds@457
    32
#define	FCVAR_ARCHIVE           (1<<7)  /**< Set to cause it to be saved to vars.rc */
ds@457
    33
#define	FCVAR_NOTIFY            (1<<8)  /**< Notifies players when changed. */
ds@457
    34
#define	FCVAR_USERINFO          (1<<9)  /**< Changes the client's info string. */
ds@457
    35
#define FCVAR_PRINTABLEONLY     (1<<10) /**< This cvar's string cannot contain unprintable characters (e.g., used for player name, etc.) */
ds@457
    36
#define FCVAR_UNLOGGED          (1<<11) /**< If this is a FCVAR_SERVER, don't log changes to the log file / console if we are creating a log */
ds@457
    37
#define FCVAR_NEVER_AS_STRING   (1<<12) /**< Never try to print that cvar. */
ds@457
    38
#define FCVAR_REPLICATED        (1<<13) /**< Server setting enforced on clients. */
ds@457
    39
#define FCVAR_CHEAT             (1<<14) /**< Only useable in singleplayer / debug / multiplayer & sv_cheats */
ds@457
    40
#define FCVAR_STUDIORENDER      (1<<15) /**< Defined by the studiorender system. */
ds@457
    41
#define FCVAR_DEMO              (1<<16) /**< Record this cvar when starting a demo file. */
ds@457
    42
#define FCVAR_DONTRECORD        (1<<17) /**< Don't record these command in demo files. */
ds@457
    43
#define FCVAR_PLUGIN            (1<<18) /**< Defined by a 3rd party plugin. */
ds@457
    44
#define FCVAR_DATACACHE         (1<<19) /**< Defined by the datacache system. */
ds@457
    45
#define FCVAR_TOOLSYSTEM        (1<<20) /**< Defined by an IToolSystem library */
ds@457
    46
#define FCVAR_FILESYSTEM        (1<<21) /**< Defined by the file system. */
ds@457
    47
#define FCVAR_NOT_CONNECTED     (1<<22) /**< Cvar cannot be changed by a client that is connected to a server. */
ds@457
    48
#define FCVAR_SOUNDSYSTEM       (1<<23) /**< Defined by the soundsystem library. */
ds@457
    49
#define FCVAR_ARCHIVE_XBOX      (1<<24) /**< Cvar written to config.cfg on the Xbox. */
ds@457
    50
#define FCVAR_INPUTSYSTEM       (1<<25) /**< Defined by the inputsystem DLL. */
ds@457
    51
#define FCVAR_NETWORKSYSTEM     (1<<26) /**< Defined by the network system. */
ds@457
    52
#define FCVAR_VPHYSICS          (1<<27) /**< Defined by vphysics. */
ds@457
    53
ds@457
    54
/**
ds@457
    55
 * Creates a new console variable.
ds@457
    56
 *
ds@457
    57
 * @param name          Name of new convar.
ds@457
    58
 * @param defaultValue  String containing the default value of new convar.
ds@457
    59
 * @param helpText      Optional description of the convar.
ds@457
    60
 * @param flags         Optional bitstream of flags determining how the convar should be handled. (See FCVAR_* constants for more details)
ds@457
    61
 * @param hasMin        Optional boolean that determines if the convar has a minimum value.
ds@457
    62
 * @param min           Minimum floating point value that the convar can have if hasMin is true.
ds@457
    63
 * @param hasMax        Optional boolean that determines if the convar has a maximum value.
ds@457
    64
 * @param max           Maximum floating point value that the convar can have if hasMax is true.
ds@457
    65
 * @return				A handle to the newly created convar. If the convar already exists, INVALID_HANDLE is returned.
ds@457
    66
 */
ds@457
    67
native Handle:CreateConVar(const String:name[], const String:defaultValue[], const String:helpText[]="", flags=0, bool:hasMin=false, Float:min=0.0, bool:hasMax=false, Float:max=0.0);
ds@457
    68
ds@457
    69
/**
ds@457
    70
 * Searches for a console variable.
ds@457
    71
 *
ds@457
    72
 * @param name          Name of convar to find.
ds@457
    73
 * @return              A handle to the convar if it is found. INVALID_HANDLE otherwise.
ds@457
    74
 */
ds@457
    75
native Handle:FindConVar(const String:name[]);
ds@457
    76
ds@457
    77
/**
ds@457
    78
 * Returns the boolean value of a console variable.
ds@457
    79
 *
ds@457
    80
 * @param convar        Handle to the convar.
ds@457
    81
 * @return              The boolean value of the convar.
ds@457
    82
 * @error               Invalid or corrupt Handle.
ds@457
    83
 */
ds@457
    84
native bool:GetConVarBool(Handle:convar);
ds@457
    85
ds@457
    86
/**
ds@457
    87
 * Sets the boolean value of a console variable.
ds@457
    88
 *
ds@457
    89
 * @param convar        Handle to the convar.
ds@457
    90
 * @param value         New boolean value.
ds@457
    91
 * @noreturn
ds@457
    92
 * @error               Invalid or corrupt Handle.
ds@457
    93
 */
ds@457
    94
native SetConVarBool(Handle:convar, bool:value);
ds@457
    95
ds@457
    96
/**
ds@457
    97
 * Returns the integer value of a console variable.
ds@457
    98
 *
ds@457
    99
 * @param convar        Handle to the convar.
ds@457
   100
 * @return              The integer value of the convar.
ds@457
   101
 * @error               Invalid or corrupt Handle.
ds@457
   102
 */
ds@457
   103
native GetConVarInt(Handle:convar);
ds@457
   104
ds@457
   105
/**
ds@457
   106
 * Sets the integer value of a console variable.
ds@457
   107
 *
ds@457
   108
 * @param convar        Handle to the convar.
ds@457
   109
 * @param value         New integer value.
ds@457
   110
 * @noreturn
ds@457
   111
 * @error               Invalid or corrupt Handle.
ds@457
   112
 */
ds@457
   113
native SetConVarInt(Handle:convar, value);
ds@457
   114
ds@457
   115
/**
ds@457
   116
 * Returns the floating point value of a console variable.
ds@457
   117
 *
ds@457
   118
 * @param convar        Handle to the convar.
ds@457
   119
 * @return              The floating point value of the convar.
ds@457
   120
 * @error               Invalid or corrupt Handle.
ds@457
   121
 */
ds@457
   122
native Float:GetConVarFloat(Handle:convar);
ds@457
   123
ds@457
   124
/**
ds@457
   125
 * Sets the floating point value of a console variable.
ds@457
   126
 *
ds@457
   127
 * @param convar        Handle to the convar.
ds@457
   128
 * @param value         New floating point value.
ds@457
   129
 * @noreturn
ds@457
   130
 * @error               Invalid or corrupt Handle.
ds@457
   131
 */
ds@457
   132
native SetConVarFloat(Handle:convar, Float:value);
ds@457
   133
ds@457
   134
/**
ds@457
   135
 * Retrieves the string value of a console variable.
ds@457
   136
 *
ds@457
   137
 * @param convar        Handle to the convar.
ds@457
   138
 * @param value         Buffer to store the value of the convar.
ds@457
   139
 * @param maxlen        Maximum length of string buffer.
ds@457
   140
 * @noreturn
ds@457
   141
 * @error               Invalid or corrupt Handle.     
ds@457
   142
 */
ds@457
   143
native GetConVarString(Handle:convar, String:value[], maxlen);
ds@457
   144
ds@457
   145
/**
ds@457
   146
 * Sets the string value of a console variable.
ds@457
   147
 *
ds@457
   148
 * @param convar        Handle to the convar.
ds@457
   149
 * @param value         New string value.
ds@457
   150
 * @noreturn
ds@457
   151
 * @error               Invalid or corrupt Handle.
ds@457
   152
 */
ds@457
   153
native SetConVarString(Handle:convar, const String:value[]);
ds@457
   154
ds@457
   155
/**
ds@457
   156
 * Returns the bitstring of flags on a console variable.
ds@457
   157
 *
ds@457
   158
 * @param convar        Handle to the convar.
ds@457
   159
 * @return              A bitstring containing the FCVAR_* flags that are enabled.
ds@457
   160
 * @error               Invalid or corrupt Handle.
ds@457
   161
 */
ds@457
   162
native GetConVarFlags(Handle:convar);
ds@457
   163
ds@457
   164
/**
ds@457
   165
 * Sets the bitstring of flags on a console variable.
ds@457
   166
 *
ds@457
   167
 * @param convar        Handle to the convar.
ds@457
   168
 * @param flags         A bitstring containing the FCVAR_* flags to enable.
ds@457
   169
 * @noreturn
ds@457
   170
 * @error               Invalid or corrupt Handle.
ds@457
   171
 */
ds@457
   172
native SetConVarFlags(Handle:convar, flags);
ds@457
   173
ds@457
   174
/**
ds@457
   175
 * Retrieves the minimum floating point value that a console variable can contain.
ds@457
   176
 *
ds@457
   177
 * @param convar        Handle to the convar.
ds@457
   178
 * @param min           By-reference cell to store the minimum floating point value.
ds@457
   179
 * @return              True if the convar has a minimum value set, false otherwise.
ds@457
   180
 * @error               Invalid or corrupt Handle.
ds@457
   181
 */
ds@457
   182
native bool:GetConVarMin(Handle:convar, &Float:min);
ds@457
   183
ds@457
   184
/**
ds@457
   185
 * Retrieves the maximum floating point value that a console variable can contain.
ds@457
   186
 *
ds@457
   187
 * @param convar        Handle to the convar.
ds@457
   188
 * @param min           By-reference cell to store the maximum floating point value.
ds@457
   189
 * @return              True if the convar has a maximum value set, false otherwise.
ds@457
   190
 * @error               Invalid or corrupt Handle.
ds@457
   191
 */
ds@457
   192
native bool:GetConVarMax(Handle:convar, &Float:max);
ds@457
   193
ds@457
   194
/**
ds@457
   195
 * Resets the console variable to its default value.
ds@457
   196
 *
ds@457
   197
 * @param convar        Handle to the convar.
ds@457
   198
 * @noreturn
ds@457
   199
 * @error               Invalid or corrupt Handle.
ds@457
   200
 */
ds@457
   201
native ResetConVar(Handle:convar);