-
Notifications
You must be signed in to change notification settings - Fork 12
/
convars.inc
50 lines (43 loc) · 1.44 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
#if defined __stocksoup_convars_included
#endinput
#endif
#define __stocksoup_convars_included
/**
* Creates a standard "version" ConVar for plugins to advertise their current version.
*/
stock ConVar CreateVersionConVar(const char[] name, const char[] description = "") {
ConVar convar;
char version[16];
if (GetPluginInfo(INVALID_HANDLE, PlInfo_Version, version, sizeof(version))) {
// FCVAR_NOTIFY posts the ConVar to A2S_RULES
// FCVAR_DONTRECORD prevents the ConVar from being added to AutoExecConfig
convar = CreateConVar(name, "", description, FCVAR_NOTIFY | FCVAR_DONTRECORD);
convar.AddChangeHook(__stocksoup_LockVersionConVar);
convar.SetString(version);
}
return convar;
}
stock void LockConVar(ConVar convar) {
convar.RestoreDefault();
convar.AddChangeHook(__stocksoup_LockConVar);
}
static stock void __stocksoup_LockConVar(ConVar convar, const char[] oldValue,
const char[] newValue) {
char defaultValue[64];
convar.GetDefault(defaultValue, sizeof(defaultValue));
if (!StrEqual(newValue, defaultValue)) {
convar.RestoreDefault();
}
}
/**
* Default value may be stale from a previous plugin load; always pull the data from plugin
* info.
*/
static stock void __stocksoup_LockVersionConVar(ConVar convar, const char[] oldValue,
const char[] newValue) {
char version[16];
GetPluginInfo(INVALID_HANDLE, PlInfo_Version, version, sizeof(version));
if (!StrEqual(newValue, version)) {
convar.SetString(version);
}
}