public static object ExecuteConvar(ConVar convar, object arg) { if (arg == null) { if (convar.PropertyInfo != null) { return(convar.PropertyInfo.GetMethod.Invoke(null, null)); } else { return(convar.FieldInfo.GetValue(null)); } } else { //if user has inputted multiple arguments into the console input string, we just use the first one object singleArg = null; if (arg is object[]) { if (((object[])arg).Length > 0) { singleArg = ((object[])arg)[0]; } } else { singleArg = arg; } try { if (convar.PropertyInfo != null) { convar.PropertyInfo.SetValue(null, singleArg); } else { convar.FieldInfo.SetValue(null, singleArg); } } catch (Exception e) { if (ShowFullErrorStack) { error(e); } else { error($"{e.GetType().Name}: {e.Message}"); } } } return(null); }
public static ConObject GetConObjectByName(string name) { ConCommand command = GetConCommandByName(name); if (command != null) { return(command); } ConVar convar = GetConVarByName(name); if (convar != null) { return(convar); } return(null); }