Пример #1
0
 public static string GetString(string strName, string strDefault)
 {
     ConsoleSystem.Arg arg = new ConsoleSystem.Arg(strName);
     if (arg.Invalid)
     {
         return(strDefault);
     }
     Type[] typeArray = ConsoleSystem.FindTypes(arg.Class);
     if ((int)typeArray.Length == 0)
     {
         return(strDefault);
     }
     Type[] typeArray1 = typeArray;
     for (int i = 0; i < (int)typeArray1.Length; i++)
     {
         Type      type  = typeArray1[i];
         FieldInfo field = type.GetField(arg.Function);
         if (field != null && field.IsStatic)
         {
             return(field.GetValue(null).ToString());
         }
         PropertyInfo property = type.GetProperty(arg.Function);
         if (property != null && property.GetGetMethod().IsStatic)
         {
             return(property.GetValue(null, null).ToString());
         }
     }
     return(strDefault);
 }
Пример #2
0
 public static string GetString(string strName, string strDefault)
 {
     ConsoleSystem.Arg arg = new ConsoleSystem.Arg(strName);
     if (!arg.Invalid)
     {
         Type[] typeArray = ConsoleSystem.FindTypes(arg.Class);
         if (typeArray.Length == 0)
         {
             return(strDefault);
         }
         foreach (Type type in typeArray)
         {
             FieldInfo field = type.GetField(arg.Function);
             if ((field != null) && field.IsStatic)
             {
                 return(field.GetValue(null).ToString());
             }
             PropertyInfo property = type.GetProperty(arg.Function);
             if ((property != null) && property.GetGetMethod().IsStatic)
             {
                 return(property.GetValue(null, null).ToString());
             }
         }
     }
     return(strDefault);
 }
Пример #3
0
    public static bool RunCommand(ref ConsoleSystem.Arg arg, bool bWantReply = true)
    {
        bool flag;

        Type[] typeArray = ConsoleSystem.FindTypes(arg.Class);
        if ((int)typeArray.Length == 0)
        {
            if (bWantReply)
            {
                arg.ReplyWith(string.Concat("Console class not found: ", arg.Class));
            }
            return(false);
        }
        if (bWantReply)
        {
            arg.ReplyWith(string.Concat(new string[] { "command ", arg.Class, ".", arg.Function, " was executed" }));
        }
        Type[] typeArray1 = typeArray;
        for (int i = 0; i < (int)typeArray1.Length; i++)
        {
            Type       type   = typeArray1[i];
            MethodInfo method = type.GetMethod(arg.Function);
            if (method != null && method.IsStatic)
            {
                if (!arg.CheckPermissions(method.GetCustomAttributes(true)))
                {
                    if (bWantReply)
                    {
                        arg.ReplyWith(string.Concat("No permission: ", arg.Class, ".", arg.Function));
                    }
                    return(false);
                }
                object[] objArray = new ConsoleSystem.Arg[] { arg };
                try
                {
                    method.Invoke(null, objArray);
                    arg = objArray[0] as ConsoleSystem.Arg;
                    return(true);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    Debug.LogWarning(string.Concat(new string[] { "Error: ", arg.Class, ".", arg.Function, " - ", exception.Message }));
                    arg.ReplyWith(string.Concat(new string[] { "Error: ", arg.Class, ".", arg.Function, " - ", exception.Message }));
                    flag = false;
                }
                return(flag);
            }
            FieldInfo field = type.GetField(arg.Function);
            if (field != null && field.IsStatic)
            {
                if (!arg.CheckPermissions(field.GetCustomAttributes(true)))
                {
                    if (bWantReply)
                    {
                        arg.ReplyWith(string.Concat("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 exception2)
                    {
                        if (bWantReply)
                        {
                            arg.ReplyWith(string.Concat("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);
            }
            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(string.Concat("No permission: ", arg.Class, ".", arg.Function));
                    }
                    return(false);
                }
                Type propertyType = property.PropertyType;
                if (arg.HasArgs(1))
                {
                    try
                    {
                        string str1 = 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(str1), " to ", Facepunch.Utility.String.QuoteSafe(property.GetValue(null, null).ToString()), " (", propertyType.Name, ")" }));
                        }
                    }
                    catch (Exception exception3)
                    {
                        if (bWantReply)
                        {
                            arg.ReplyWith(string.Concat("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);
            }
        }
        if (bWantReply)
        {
            arg.ReplyWith(string.Concat("Command not found: ", arg.Class, ".", arg.Function));
        }
        return(false);
    }