public static bool TryExecuteCommand(InputController state, string line, int studioLine) { try { if (char.IsLetter(line[0])) { string[] args = Split(line); string commandType = args[0] + "Command"; MethodInfo method = typeof(InputCommands).GetMethod(commandType, BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase); if (method == null) { return(false); } string[] commandArgs = TrimArray(args, 1); TASCommandAttribute attribute = (TASCommandAttribute)method.GetCustomAttribute(typeof(TASCommandAttribute)); if (!(Manager.enforceLegal && attribute.illegalInMaingame)) { if (attribute.executeAtStart) { method.Invoke(null, new object[] { state, commandArgs, studioLine }); //the play command needs to stop reading the current file when it's done to prevent recursion return(commandType.ToLower() == "playcommand"); } Action commandCall = () => method.Invoke(null, new object[] { commandArgs }); state.inputs.Add(new InputRecord(commandCall)); } } return(false); } catch { return(false); } }
public static bool TryExecuteCommand(InputController state, string line, int studioLine) { try { if (char.IsLetter(line[0])) { string[] args = Split(line); string commandType = args[0] + "Command"; MethodInfo method = typeof(InputCommands).GetMethod(commandType, BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase); if (method == null) { return(false); } string[] commandArgs = new string[args.Length - 1]; for (int i = 1; i < args.Length; i++) { commandArgs[i - 1] = args[i]; } TASCommandAttribute attribute = (TASCommandAttribute)method.GetCustomAttribute(typeof(TASCommandAttribute)); if (!(Manager.enforceLegal && attribute.illegalInMaingame)) { if (attribute.executeAtStart) { return((bool)method.Invoke(null, new object[] { state, commandArgs, studioLine })); } else { Action commandCall = () => method.Invoke(null, new object[] { commandArgs }); state.inputs.Add(new InputRecord(commandCall)); } } } return(false); } catch { return(false); } }