7 void RegisterCvars(void(string name, string def, string desc, bool archive, string file) f) { }
9 /** escape the string to make it safe for consoles */
10 string MakeConsoleSafe(string input)
12 input = strreplace("\n", "", input);
13 input = strreplace("\\", "\\\\", input);
14 input = strreplace("$", "$$", input);
15 input = strreplace("\"", "\\\"", input);
19 void RegisterCvars_Set(string name, string def, string desc, bool archive, string file)
21 string val = string_null;
22 if (cvar_type(name) & CVAR_TYPEFLAG_EXISTS) {
23 val = cvar_string(name);
24 // Need to unset first to change the default
25 localcmd(sprintf("\nunset %s\n", name));
27 localcmd(sprintf("\n%s %s \"%s\" \"%s\"\n", (archive ? "seta" : "set"), name, MakeConsoleSafe(def), MakeConsoleSafe(desc)));
29 localcmd(sprintf("\n%s \"%s\"\n", name, MakeConsoleSafe(val)));
34 STATIC_INIT_LATE(Cvars) { RegisterCvars(RegisterCvars_Set); }
37 const noref bool default_bool = false;
38 const noref int default_int = 0;
39 const noref float default_float = 0;
40 const noref string default_string = "";
41 const noref vector default_vector = '0 0 0';
43 #define repr_cvar_bool(x) ((x) ? "1" : "0")
44 #define repr_cvar_int(x) (ftos(x))
45 #define repr_cvar_float(x) (ftos(x))
46 #define repr_cvar_string(x) (x)
47 #define repr_cvar_vector(x) (sprintf("%v", x))
49 #define __AUTOCVAR(file, archive, var, type, desc, default) \
50 [[accumulate]] void RegisterCvars(void(string, string, string, bool, string) f) { f(#var, repr_cvar_##type(default), desc, archive, file); } \
51 type autocvar_##var = default
52 #define AUTOCVAR_5(file, archive, var, type, desc) \
53 __AUTOCVAR(file, archive, var, type, desc, default_##type)
54 #define AUTOCVAR_6(file, archive, var, type, default, desc) \
55 __AUTOCVAR(file, archive, var, type, desc, default)
56 #define _AUTOCVAR(...) EVAL(OVERLOAD(AUTOCVAR, __FILE__, __VA_ARGS__))
57 #define AUTOCVAR_SAVE(...) _AUTOCVAR(true, __VA_ARGS__)
58 #define AUTOCVAR(...) _AUTOCVAR(false, __VA_ARGS__)