Пример #1
0
        private static void CallMethod(MethodInfo member, ConCommand.ArgCollection collection, object instance = null)
        {
            List <object> invokeParams = new List <object>();

            foreach (var o in collection.ParsedArgs)
            {
                invokeParams.Add(o.Value);
            }
            member.Invoke(instance, invokeParams.ToArray());
        }
Пример #2
0
        public void ConsoleUserInput(string input)
        {
            if (this.History.Count == 0 || input != this.History[this.History.Count - 1])
            {
                this.History.Add(input);
            }
            while (this.History.Count > MaxHistory)
            {
                this.History.RemoveAt(0);
            }

            ConsoleParser.ParseResult parsed = ConsoleParser.Parse(input);
            Log(">" + input);
            if (parsed.ParsedResult.Length == 0 || !IsConVarOrCmd(parsed.ParsedResult[0].Value))
            {
                Log("Incorrect input");
                return;
            }
            string ConObject = parsed.ParsedResult[0].Value;

            if (IsConCommand(ConObject))
            {
                int NumArgs = parsed.ParsedResult.Length - 1;
                var command = GetConCommand(ConObject);
                if (NumArgs >= command.NumRequiredArgs && NumArgs <= command.NumArgs)
                {
                    var parsedArgs = command.ParseArguments(parsed.ParsedResult);
                    if (parsedArgs == null)
                    {
                        Log("ERROR: Bad arguments");
                        PrintConCommandDescription(command);
                    }
                    else
                    {
                        var collection = new ConCommand.ArgCollection()
                        {
                            ParsedArgs = parsedArgs
                        };
                        command.OnCalled.Value(collection);
                    }
                }
                else
                {
                    Log("ERROR: Wrong number of arguments.");
                    PrintConCommandDescription(command);
                }
            }
            else if (IsConVar(ConObject))
            {
                if (parsed.ParsedResult.Length == 1)
                {
                    var convar = GetConVar(parsed.ParsedResult[0].Value);
                    Log(convar.Name + ": " + convar.Description + " (Value: " + convar.GetCastedValue() + " " +
                        convar.OutCastConstraint.ToString().Replace("System.", "") + ")");
                }
                else
                {
                    var argument = parsed.ParsedResult[1].Value;
                    SetConVarValue(parsed.ParsedResult[0].Value, argument);
                }
            }
        }