Esempio n. 1
0
        private void RunCmd(string concommandName, List <string> userArgs)
        {
            Console.ConCommand conCommand = null;
            BaseConVar         baseConVar = null;
            ConVarFlags        flags;

            if (this.concommandCatalog.TryGetValue(concommandName, out conCommand))
            {
                flags = conCommand.flags;
            }
            else
            {
                baseConVar = this.FindConVar(concommandName);
                if (baseConVar == null)
                {
                    Debug.LogFormat("\"{0}\" is not a recognized ConCommand or ConVar.", new object[]
                    {
                        concommandName
                    });
                    return;
                }
                flags = baseConVar.flags;
            }
            if (conCommand != null)
            {
                try
                {
                    conCommand.action(new ConCommandArgs
                    {
                        commandName = concommandName,
                        userArgs    = userArgs
                    });
                }
                catch (ConCommandException ex)
                {
                    Debug.LogFormat("Command \"{0}\" failed: {1}", new object[]
                    {
                        concommandName,
                        ex.Message
                    });
                }
                return;
            }
            if (baseConVar == null)
            {
                return;
            }
            if (userArgs.Count > 0)
            {
                baseConVar.AttemptSetString(userArgs[0]);
                return;
            }
            Debug.LogFormat("\"{0}\" = \"{1}\"\n{2}", new object[]
            {
                concommandName,
                baseConVar.GetString(),
                baseConVar.helpText
            });
        }
Esempio n. 2
0
 private void InitConVars()
 {
     this.allConVars     = new Dictionary <string, BaseConVar>();
     this.archiveConVars = new List <BaseConVar>();
     foreach (Type type in typeof(BaseConVar).Assembly.GetTypes())
     {
         foreach (FieldInfo fieldInfo in type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
         {
             if (fieldInfo.FieldType.IsSubclassOf(typeof(BaseConVar)))
             {
                 if (fieldInfo.IsStatic)
                 {
                     BaseConVar conVar = (BaseConVar)fieldInfo.GetValue(null);
                     this.RegisterConVarInternal(conVar);
                 }
                 else if (type.GetCustomAttribute <CompilerGeneratedAttribute>() == null)
                 {
                     Debug.LogErrorFormat("ConVar defined as {0}.{1} could not be registered. ConVars must be static fields.", new object[]
                     {
                         type.Name,
                         fieldInfo.Name
                     });
                 }
             }
         }
         foreach (MethodInfo methodInfo in type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
         {
             if (methodInfo.GetCustomAttribute <ConVarProviderAttribute>() != null)
             {
                 if (methodInfo.ReturnType != typeof(IEnumerable <BaseConVar>) || methodInfo.GetParameters().Length != 0)
                 {
                     Debug.LogErrorFormat("ConVar provider {0}.{1} does not match the signature \"static IEnumerable<ConVar.BaseConVar>()\".", new object[]
                     {
                         type.Name,
                         methodInfo.Name
                     });
                 }
                 else if (!methodInfo.IsStatic)
                 {
                     Debug.LogErrorFormat("ConVar provider {0}.{1} could not be invoked. Methods marked with the ConVarProvider attribute must be static.", new object[]
                     {
                         type.Name,
                         methodInfo.Name
                     });
                 }
                 else
                 {
                     foreach (BaseConVar conVar2 in ((IEnumerable <BaseConVar>)methodInfo.Invoke(null, Array.Empty <object>())))
                     {
                         this.RegisterConVarInternal(conVar2);
                     }
                 }
             }
         }
     }
     foreach (KeyValuePair <string, BaseConVar> keyValuePair in this.allConVars)
     {
         BaseConVar value = keyValuePair.Value;
         if ((value.flags & ConVarFlags.Engine) != ConVarFlags.None)
         {
             value.defaultValue = value.GetString();
         }
         else if (value.defaultValue != null)
         {
             value.AttemptSetString(value.defaultValue);
         }
     }
 }