public static string VariableString(string var_name) { cvar_t var; var = Cvar.FindVar(var_name); return(var == null ? "" : var.@string); }
/** * Returns the float value of a variable. */ public static float VariableValue(string var_name) { var var = Cvar.FindVar(var_name); if (var == null) { return(0); } return(Lib.atof(var.@string)); }
/** * @param var_name * @param var_value * @param flags * @return */ public static cvar_t Get(string var_name, string var_value, int flags) { cvar_t var; if ((flags & (Defines.CVAR_USERINFO | Defines.CVAR_SERVERINFO)) != 0) { if (!Cvar.InfoValidate(var_name)) { Com.Printf("invalid info cvar name\n"); return(null); } } var = Cvar.FindVar(var_name); if (var != null) { var.flags |= flags; return(var); } if (var_value == null) { return(null); } if ((flags & (Defines.CVAR_USERINFO | Defines.CVAR_SERVERINFO)) != 0) { if (!Cvar.InfoValidate(var_value)) { Com.Printf("invalid info cvar value\n"); return(null); } } var = new(); var.name = new(var_name); var.@string = new(var_value); var.modified = true; var.value = Lib.atof(var.@string); // link the variable in var.next = Globals.cvar_vars; Globals.cvar_vars = var; var.flags = flags; return(var); }
/** * Handles variable inspection and changing from the console. */ public static bool Command() { cvar_t v; // check variables v = Cvar.FindVar(Cmd.Argv(0)); if (v == null) { return(false); } // perform a variable print or set if (Cmd.Argc() == 1) { Com.Printf("\"" + v.name + "\" is \"" + v.@string + "\"\n"); return(true); } Cvar.Set(v.name, Cmd.Argv(1)); return(true); }
/** * Creates a variable if not found and sets their value, the parsed float value and their flags. */ public static cvar_t FullSet(string var_name, string value, int flags) { cvar_t var; var = Cvar.FindVar(var_name); if (null == var) { // create it return(Cvar.Get(var_name, value, flags)); } var.modified = true; if ((var.flags & Defines.CVAR_USERINFO) != 0) { Globals.userinfo_modified = true; // transmit at next oportunity } var.@string = value; var.value = Lib.atof(var.@string); var.flags = flags; return(var); }
/** * Gereric set function, sets the value of the variable, with forcing its even possible to * override the variables write protection. */ private static cvar_t Set2(string var_name, string value, bool force) { var var = Cvar.FindVar(var_name); if (var == null) { // create it return(Cvar.Get(var_name, value, 0)); } if ((var.flags & (Defines.CVAR_USERINFO | Defines.CVAR_SERVERINFO)) != 0) { if (!Cvar.InfoValidate(value)) { Com.Printf("invalid info cvar value\n"); return(var); } } if (!force) { if ((var.flags & Defines.CVAR_NOSET) != 0) { Com.Printf(var_name + " is write protected.\n"); return(var); } if ((var.flags & Defines.CVAR_LATCH) != 0) { if (var.latched_string != null) { if (value.Equals(var.latched_string)) { return(var); } var.latched_string = null; } else { if (value.Equals(var.@string)) { return(var); } } if (Globals.server_state != 0) { Com.Printf(var_name + " will be changed for next game.\n"); var.latched_string = value; } else { var.@string = value; var.value = Lib.atof(var.@string); if (var.name.Equals("game")) { FS.SetGamedir(var.@string); FS.ExecAutoexec(); } } return(var); } } else { if (var.latched_string != null) { var.latched_string = null; } } if (value.Equals(var.@string)) { return(var); // not changed } var.modified = true; if ((var.flags & Defines.CVAR_USERINFO) != 0) { Globals.userinfo_modified = true; // transmit at next oportunity } var.@string = value; try { var.value = float.Parse(var.@string, CultureInfo.InvariantCulture); } catch (Exception) { var.value = 0.0f; } return(var); }