// Token: 0x06000CCC RID: 3276 RVA: 0x0003161C File Offset: 0x0002F81C
    public static bool RunCommand(ref global::ConsoleSystem.Arg arg, bool bWantReply = true)
    {
        Type[] array = global::ConsoleSystem.FindTypes(arg.Class);
        if (array.Length == 0)
        {
            if (bWantReply)
            {
                arg.ReplyWith("Console class not found: " + arg.Class);
            }
            return(false);
        }
        if (bWantReply)
        {
            arg.ReplyWith(string.Concat(new string[]
            {
                "command ",
                arg.Class,
                ".",
                arg.Function,
                " was executed"
            }));
        }
        Type[] array2 = array;
        int    i      = 0;

        while (i < array2.Length)
        {
            Type       type   = array2[i];
            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);
                }
                object[] array3 = new global::ConsoleSystem.Arg[]
                {
                    arg
                };
                try
                {
                    method.Invoke(null, array3);
                }
                catch (Exception ex)
                {
                    Debug.LogWarning(string.Concat(new string[]
                    {
                        "Error: ",
                        arg.Class,
                        ".",
                        arg.Function,
                        " - ",
                        ex.Message
                    }));
                    arg.ReplyWith(string.Concat(new string[]
                    {
                        "Error: ",
                        arg.Class,
                        ".",
                        arg.Function,
                        " - ",
                        ex.Message
                    }));
                    return(false);
                }
                arg = (array3[0] as global::ConsoleSystem.Arg);
                return(true);
            }
            else
            {
                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(string.Concat(new string[]
                                {
                                    arg.Class,
                                    ".",
                                    arg.Function,
                                    ": changed ",
                                    Facepunch.Utility.String.QuoteSafe(str),
                                    " to ",
                                    Facepunch.Utility.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(string.Concat(new string[]
                        {
                            arg.Class,
                            ".",
                            arg.Function,
                            ": ",
                            Facepunch.Utility.String.QuoteSafe(field.GetValue(null).ToString()),
                            " (",
                            fieldType.Name,
                            ")"
                        }));
                    }
                    return(true);
                }
                else
                {
                    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(string.Concat(new string[]
                                    {
                                        arg.Class,
                                        ".",
                                        arg.Function,
                                        ": changed ",
                                        Facepunch.Utility.String.QuoteSafe(str2),
                                        " to ",
                                        Facepunch.Utility.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(string.Concat(new string[]
                            {
                                arg.Class,
                                ".",
                                arg.Function,
                                ": ",
                                Facepunch.Utility.String.QuoteSafe(property.GetValue(null, null).ToString()),
                                " (",
                                propertyType.Name,
                                ")"
                            }));
                        }
                        return(true);
                    }
                    else
                    {
                        i++;
                    }
                }
            }
        }
        if (bWantReply)
        {
            arg.ReplyWith("Command not found: " + arg.Class + "." + arg.Function);
        }
        return(false);
    }
예제 #2
0
    public static void find(ref global::ConsoleSystem.Arg arg)
    {
        if (!arg.HasArgs(1))
        {
            return;
        }
        string text  = arg.Args[0];
        string text2 = string.Empty;

        Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
        for (int i = 0; i < assemblies.Length; i++)
        {
            Type[] types = assemblies[i].GetTypes();
            for (int j = 0; j < types.Length; j++)
            {
                if (types[j].IsSubclassOf(typeof(global::ConsoleSystem)))
                {
                    MethodInfo[] methods = types[j].GetMethods();
                    for (int k = 0; k < methods.Length; k++)
                    {
                        if (methods[k].IsStatic)
                        {
                            if (!(text != "*") || types[j].Name.Contains(text) || methods[k].Name.Contains(text))
                            {
                                if (arg.CheckPermissions(methods[k].GetCustomAttributes(true)))
                                {
                                    string text3 = text2;
                                    text2 = string.Concat(new string[]
                                    {
                                        text3,
                                        types[j].Name,
                                        ".",
                                        global::global.BuildMethodString(ref methods[k]),
                                        "\n"
                                    });
                                }
                            }
                        }
                    }
                    FieldInfo[] fields = types[j].GetFields();
                    for (int l = 0; l < fields.Length; l++)
                    {
                        if (fields[l].IsStatic)
                        {
                            if (!(text != "*") || types[j].Name.Contains(text) || fields[l].Name.Contains(text))
                            {
                                if (arg.CheckPermissions(fields[l].GetCustomAttributes(true)))
                                {
                                    string text3 = text2;
                                    text2 = string.Concat(new string[]
                                    {
                                        text3,
                                        types[j].Name,
                                        ".",
                                        global::global.BuildFieldsString(ref fields[l]),
                                        "\n"
                                    });
                                }
                            }
                        }
                    }
                    PropertyInfo[] properties = types[j].GetProperties();
                    for (int m = 0; m < properties.Length; m++)
                    {
                        if (!(text != "*") || types[j].Name.Contains(text) || properties[m].Name.Contains(text))
                        {
                            if (arg.CheckPermissions(properties[m].GetCustomAttributes(true)))
                            {
                                string text3 = text2;
                                text2 = string.Concat(new string[]
                                {
                                    text3,
                                    types[j].Name,
                                    ".",
                                    global::global.BuildPropertyString(ref properties[m]),
                                    "\n"
                                });
                            }
                        }
                    }
                }
            }
        }
        arg.ReplyWith("Finding " + text + ":\n" + text2);
    }