public static bool RunCommand(ref Arg arg, bool bWantReply = true) { Type[] typeArray = FindTypes(arg.Class); if (typeArray.Length == 0) { if (bWantReply) { arg.ReplyWith("Console class not found: " + arg.Class); } return(false); } if (bWantReply) { arg.ReplyWith("command " + arg.Class + "." + arg.Function + " was executed"); } foreach (Type type in typeArray) { MethodInfo method = type.GetMethod(arg.Function); if ((method != null) && method.IsStatic) { if (!arg.CheckPermissions(method.GetCustomAttributes(true))) { if (bWantReply) { arg.ReplyWith("No permission: " + arg.Class + "." + arg.Function); } return(false); } Arg[] argArray1 = new Arg[] { arg }; object[] parameters = argArray1; try { method.Invoke(null, parameters); } catch (Exception exception) { Debug.LogWarning("Error: " + arg.Class + "." + arg.Function + " - " + exception.Message); arg.ReplyWith("Error: " + arg.Class + "." + arg.Function + " - " + exception.Message); return(false); } arg = parameters[0] as Arg; return(true); } FieldInfo field = type.GetField(arg.Function); if ((field != null) && field.IsStatic) { if (!arg.CheckPermissions(field.GetCustomAttributes(true))) { if (bWantReply) { arg.ReplyWith("No permission: " + arg.Class + "." + arg.Function); } return(false); } Type fieldType = field.FieldType; if (arg.HasArgs(1)) { try { string str = field.GetValue(null).ToString(); if (fieldType == typeof(float)) { field.SetValue(null, float.Parse(arg.Args[0])); } if (fieldType == typeof(int)) { field.SetValue(null, int.Parse(arg.Args[0])); } if (fieldType == typeof(string)) { field.SetValue(null, arg.Args[0]); } if (fieldType == typeof(bool)) { field.SetValue(null, bool.Parse(arg.Args[0])); } if (bWantReply) { arg.ReplyWith(arg.Class + "." + arg.Function + ": changed " + String.QuoteSafe(str) + " to " + String.QuoteSafe(field.GetValue(null).ToString()) + " (" + fieldType.Name + ")"); } } catch (Exception) { if (bWantReply) { arg.ReplyWith("error setting value: " + arg.Class + "." + arg.Function); } } } else if (bWantReply) { arg.ReplyWith(arg.Class + "." + arg.Function + ": " + String.QuoteSafe(field.GetValue(null).ToString()) + " (" + fieldType.Name + ")"); } return(true); } PropertyInfo property = type.GetProperty(arg.Function); if (((property != null) && property.GetGetMethod().IsStatic) && property.GetSetMethod().IsStatic) { if (!arg.CheckPermissions(property.GetCustomAttributes(true))) { if (bWantReply) { arg.ReplyWith("No permission: " + arg.Class + "." + arg.Function); } return(false); } Type propertyType = property.PropertyType; if (arg.HasArgs(1)) { try { string str2 = property.GetValue(null, null).ToString(); if (propertyType == typeof(float)) { property.SetValue(null, float.Parse(arg.Args[0]), null); } if (propertyType == typeof(int)) { property.SetValue(null, int.Parse(arg.Args[0]), null); } if (propertyType == typeof(string)) { property.SetValue(null, arg.Args[0], null); } if (propertyType == typeof(bool)) { property.SetValue(null, bool.Parse(arg.Args[0]), null); } if (bWantReply) { arg.ReplyWith(arg.Class + "." + arg.Function + ": changed " + String.QuoteSafe(str2) + " to " + String.QuoteSafe(property.GetValue(null, null).ToString()) + " (" + propertyType.Name + ")"); } } catch (Exception) { if (bWantReply) { arg.ReplyWith("error setting value: " + arg.Class + "." + arg.Function); } } } else if (bWantReply) { arg.ReplyWith(arg.Class + "." + arg.Function + ": " + String.QuoteSafe(property.GetValue(null, null).ToString()) + " (" + propertyType.Name + ")"); } return(true); } } if (bWantReply) { arg.ReplyWith("Command not found: " + arg.Class + "." + arg.Function); } return(false); }