Beispiel #1
0
        // Run method without counting on being connected to the game (startup/shutdown).
        private void RunNoProcessMethod(ASLMethod method, LiveSplitState state, bool is_startup = false)
        {
            var refresh_rate = RefreshRate;
            var version      = GameVersion;

            method.Call(state, Vars, ref version, ref refresh_rate,
                        is_startup ? _settings.Builder : (object)_settings.Reader);
            RefreshRate = refresh_rate;
        }
Beispiel #2
0
        private dynamic RunMethod(ASLMethod method, LiveSplitState state, ref string version)
        {
            var refresh_rate = RefreshRate;
            var result       = method.Call(state, Vars, ref version, ref refresh_rate, _settings.Reader,
                                           OldState?.Data, State?.Data, _game);

            RefreshRate = refresh_rate;
            return(result);
        }
Beispiel #3
0
        public static ASLScript Parse(String code)
        {
            var grammar = new ASLGrammar();
            var parser  = new Parser(grammar);
            var tree    = parser.Parse(code);

            var rootChilds  = tree.Root.ChildNodes;
            var stateNode   = rootChilds.Where(x => x.Term.Name == "stateDef").First();
            var methodsNode = rootChilds.Where(x => x.Term.Name == "methodList").First();

            var processName          = (String)stateNode.ChildNodes[2].Token.Value;
            var valueDefinitionNodes = stateNode.ChildNodes[5].ChildNodes;

            var state = new ASLState();

            foreach (var valueDefinitionNode in valueDefinitionNodes.Where(x => x.ChildNodes.Count > 0))
            {
                var childNodes      = valueDefinitionNode.ChildNodes;
                var type            = (String)childNodes[0].Token.Value;
                var identifier      = (String)childNodes[1].Token.Value;
                var module          = (String)childNodes[3].Token.Value;
                var moduleBase      = childNodes[5].ChildNodes.Select(x => (int)x.Token.Value).First();
                var offsets         = childNodes[5].ChildNodes.Skip(1).Select(x => (int)x.Token.Value).ToArray();
                var valueDefinition = new ASLValueDefinition()
                {
                    Identifier = identifier,
                    Type       = type,
                    Pointer    = new DeepPointer(module, moduleBase, offsets)
                };
                state.ValueDefinitions.Add(valueDefinition);
            }

            ASLMethod start = null, split = null, isLoading = null, gameTime = null, reset = null;

            foreach (var method in methodsNode.ChildNodes[0].ChildNodes)
            {
                var script     = new ASLMethod((String)method.ChildNodes[2].Token.Value);
                var methodName = (String)method.ChildNodes[0].Token.Value;
                switch (methodName)
                {
                case "start": start = script; break;

                case "split": split = script; break;

                case "isLoading": isLoading = script; break;

                case "gameTime": gameTime = script; break;

                case "reset": reset = script; break;
                }
            }

            return(new ASLScript(processName, state, start, split, reset, isLoading, gameTime));
        }
 public ASLScript(
     String processName, ASLState state, 
     ASLMethod start, ASLMethod split, 
     ASLMethod reset, 
     ASLMethod isLoading, ASLMethod gameTime)
 {
     ProcessName = processName;
     State = state;
     Start = start ?? new ASLMethod("");
     Split = split ?? new ASLMethod("");
     Reset = reset ?? new ASLMethod("");
     IsLoading = isLoading ?? new ASLMethod("");
     GameTime = gameTime ?? new ASLMethod("");
 }
 public ASLScript(
     String processName, ASLState state,
     ASLMethod start, ASLMethod split,
     ASLMethod reset,
     ASLMethod isLoading, ASLMethod gameTime)
 {
     ProcessName = processName;
     State       = state;
     Start       = start ?? new ASLMethod("");
     Split       = split ?? new ASLMethod("");
     Reset       = reset ?? new ASLMethod("");
     IsLoading   = isLoading ?? new ASLMethod("");
     GameTime    = gameTime ?? new ASLMethod("");
 }
        public static ASLScript Parse(String code)
        {
            var grammar = new ASLGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(code);

            var rootChilds = tree.Root.ChildNodes;
            var stateNode = rootChilds.Where(x => x.Term.Name == "stateDef").First();
            var methodsNode = rootChilds.Where(x => x.Term.Name == "methodList").First();

            var processName = (String)stateNode.ChildNodes[2].Token.Value;
            var valueDefinitionNodes = stateNode.ChildNodes[5].ChildNodes;

            var state = new ASLState();

            foreach (var valueDefinitionNode in valueDefinitionNodes.Where(x => x.ChildNodes.Count > 0))
            {
                var childNodes = valueDefinitionNode.ChildNodes;
                var type = (String)childNodes[0].Token.Value;
                var identifier = (String)childNodes[1].Token.Value;
                var module = (String)childNodes[3].Token.Value;
                var moduleBase = childNodes[5].ChildNodes.Select(x => (int)x.Token.Value).First();
                var offsets = childNodes[5].ChildNodes.Skip(1).Select(x => (int)x.Token.Value).ToArray();
                var valueDefinition = new ASLValueDefinition() 
                { 
                    Identifier = identifier,
                    Type = type,
                    Pointer = new DeepPointer(module, moduleBase, offsets)
                };
                state.ValueDefinitions.Add(valueDefinition);
            }

            ASLMethod start = null, split = null, isLoading = null, gameTime = null, reset = null;
            foreach (var method in methodsNode.ChildNodes[0].ChildNodes)
            {
                var script = new ASLMethod((String)method.ChildNodes[2].Token.Value);
                var methodName = (String)method.ChildNodes[0].Token.Value;
                switch (methodName)
                {
                    case "start": start = script; break;
                    case "split": split = script; break;
                    case "isLoading": isLoading = script; break;
                    case "gameTime": gameTime = script; break;
                    case "reset": reset = script; break; 
                }
            }

            return new ASLScript(processName, state, start, split, reset, isLoading, gameTime);
        }
Beispiel #7
0
        static string GetMessage(ASLMethod method, Exception inner_exception)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            if (inner_exception == null)
            {
                throw new ArgumentNullException(nameof(inner_exception));
            }

            var stack_trace    = new StackTrace(inner_exception, true);
            var stack_trace_sb = new StringBuilder();

            foreach (var frame in stack_trace.GetFrames())
            {
                var frame_method = frame.GetMethod();
                var frame_module = frame_method.Module;

                var frame_asl_method = method;
                if (method.ScriptMethods != null)
                {
                    frame_asl_method = method.ScriptMethods.FirstOrDefault(m => frame_module == m.Module);
                    if (frame_asl_method == null)
                    {
                        continue;
                    }
                }
                else if (frame_module != method.Module)
                {
                    continue;
                }

                var frame_line = frame.GetFileLineNumber();
                if (frame_line > 0)
                {
                    var line = frame_line + frame_asl_method.LineOffset;
                    stack_trace_sb.Append($"\n   at ASL line {line} in '{frame_asl_method.Name}'");
                }
            }

            var exception_name    = inner_exception.GetType().FullName;
            var method_name       = method.Name ?? "(no name)";
            var exception_message = inner_exception.Message;

            return($"Exception thrown: '{exception_name}' in '{method_name}' method:\n{exception_message}\n{stack_trace_sb.ToString()}");
        }
 public ASLScript(
     Dictionary<string, List<ASLState>> states,
     ASLMethod init, ASLMethod update,
     ASLMethod start, ASLMethod split,
     ASLMethod reset, 
     ASLMethod isLoading, ASLMethod gameTime)
 {
     States = states;
     Vars = new ExpandoObject();
     Init = init ?? new ASLMethod("");
     Update = update ?? new ASLMethod("");
     Start = start ?? new ASLMethod("");
     Split = split ?? new ASLMethod("");
     Reset = reset ?? new ASLMethod("");
     IsLoading = isLoading ?? new ASLMethod("");
     GameTime = gameTime ?? new ASLMethod("");
     UsesGameTime = !IsLoading.IsEmpty || !GameTime.IsEmpty;
     Version = string.Empty;
 }
Beispiel #9
0
        static string GetMessage(ASLMethod method, CompilerErrorCollection errors)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }
            if (errors == null)
            {
                throw new ArgumentNullException(nameof(errors));
            }

            var sb = new StringBuilder($"'{method.Name ?? "(no name)"}' method compilation errors:");

            foreach (CompilerError error in errors)
            {
                error.Line = error.Line + method.LineOffset;
                sb.Append($"\nLine {error.Line}, Col {error.Column}: {(error.IsWarning ? "warning" : "error")} {error.ErrorNumber}: {error.ErrorText}");
            }
            return(sb.ToString());
        }
 private dynamic runMethod(ASLMethod methodToRun, LiveSplitState lsState, ref string ver)
 {
     var refreshRate = RefreshRate;
     var result = methodToRun.Run(lsState, OldState, State, Vars, Game, ref ver, ref refreshRate);
     RefreshRate = refreshRate;
     return result;
 }
 // Run method without counting on being connected to the game (startup/shutdown).
 private void RunNoProcessMethod(ASLMethod method, LiveSplitState state, bool is_startup = false)
 {
     var refresh_rate = RefreshRate;
     var version = GameVersion;
     method.Call(state, _vars, ref version, ref refresh_rate,
         is_startup ? _settings.Builder : (object)_settings.Reader);
     RefreshRate = refresh_rate;
 }
 private dynamic RunMethod(ASLMethod method, LiveSplitState state)
 {
     var version = GameVersion;
     return RunMethod(method, state, ref version);
 }
 private dynamic RunMethod(ASLMethod method, LiveSplitState state, ref string version)
 {
     var refresh_rate = RefreshRate;
     var result = method.Call(state, _vars, ref version, ref refresh_rate, _settings.Reader,
         _old_state.Data, _state.Data, _game);
     RefreshRate = refresh_rate;
     return result;
 }
        public static ASLScript Parse(string code)
        {
            var grammar = new ASLGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(code);

            if (tree.HasErrors())
                throw new Exception("ASL parse error(s): " + string.Join("\n", tree.ParserMessages));

            var root_childs = tree.Root.ChildNodes;
            var methods_node = root_childs.First(x => x.Term.Name == "methodList");
            var states_node = root_childs.First(x => x.Term.Name == "stateList");

            var states = new Dictionary<string, List<ASLState>>();

            foreach (var state_node in states_node.ChildNodes)
            {
                var process_name = (string)state_node.ChildNodes[2].Token.Value;
                var version =
                    state_node.ChildNodes[3].ChildNodes.Skip(1).Select(x => (string) x.Token.Value).FirstOrDefault() ??
                    string.Empty;
                var value_definition_nodes = state_node.ChildNodes[6].ChildNodes;

                var state = new ASLState();

                foreach (var value_definition_node in value_definition_nodes.Where(x => x.ChildNodes.Count > 0))
                {
                    var child_nodes = value_definition_node.ChildNodes;
                    var type = (string)child_nodes[0].Token.Value;
                    var identifier = (string)child_nodes[1].Token.Value;
                    var module =
                        child_nodes[3].ChildNodes.Take(1).Select(x => (string) x.Token.Value).FirstOrDefault() ??
                        string.Empty;
                    var module_base = child_nodes[4].ChildNodes.Select(x => (int)x.Token.Value).First();
                    var offsets = child_nodes[4].ChildNodes.Skip(1).Select(x => (int)x.Token.Value).ToArray();
                    var value_definition = new ASLValueDefinition()
                    {
                        Identifier = identifier,
                        Type = type,
                        Pointer = new DeepPointer(module, module_base, offsets)
                    };
                    state.ValueDefinitions.Add(value_definition);
                }

                state.GameVersion = version;
                if (!states.ContainsKey(process_name))
                    states.Add(process_name, new List<ASLState>());
                states[process_name].Add(state);
            }

            var methods = new ASLScript.Methods();

            foreach (var method in methods_node.ChildNodes[0].ChildNodes)
            {
                var method_name = (string)method.ChildNodes[0].Token.Value;
                var script = new ASLMethod((string)method.ChildNodes[2].Token.Value);
                switch (method_name)
                {
                    case "init": methods.init = script; break;
                    case "exit": methods.exit = script; break;
                    case "update": methods.update = script; break;
                    case "start": methods.start = script; break;
                    case "split": methods.split = script; break;
                    case "isLoading": methods.isLoading = script; break;
                    case "gameTime": methods.gameTime = script; break;
                    case "reset": methods.reset = script; break;
                    case "startup": methods.startup = script; break;
                    case "shutdown": methods.shutdown = script; break;
                }
            }

            return new ASLScript(methods, states);
        }
Beispiel #15
0
        public static ASLScript Parse(string code)
        {
            var grammar = new ASLGrammar();
            var parser  = new Parser(grammar);
            var tree    = parser.Parse(code);

            if (tree.HasErrors())
            {
                var error_msg = new StringBuilder("ASL parse error(s):");
                foreach (var msg in parser.Context.CurrentParseTree.ParserMessages)
                {
                    var loc = msg.Location;
                    error_msg.Append($"\nat Line {loc.Line + 1}, Col {loc.Column + 1}: {msg.Message}");
                }

                throw new Exception(error_msg.ToString());
            }

            var root_childs  = tree.Root.ChildNodes;
            var methods_node = root_childs.First(x => x.Term.Name == "methodList");
            var states_node  = root_childs.First(x => x.Term.Name == "stateList");

            var states = new Dictionary <string, List <ASLState> >();

            foreach (var state_node in states_node.ChildNodes)
            {
                var process_name = (string)state_node.ChildNodes[2].Token.Value;
                var version      =
                    state_node.ChildNodes[3].ChildNodes.Skip(1).Select(x => (string)x.Token.Value).FirstOrDefault() ??
                    string.Empty;
                var value_definition_nodes = state_node.ChildNodes[6].ChildNodes;

                var state = new ASLState();

                foreach (var value_definition_node in value_definition_nodes.Where(x => x.ChildNodes.Count > 0))
                {
                    var child_nodes = value_definition_node.ChildNodes;
                    var type        = (string)child_nodes[0].Token.Value;
                    var identifier  = (string)child_nodes[1].Token.Value;
                    var module      =
                        child_nodes[3].ChildNodes.Take(1).Select(x => (string)x.Token.Value).FirstOrDefault() ??
                        string.Empty;
                    var module_base      = child_nodes[4].ChildNodes.Select(x => (long)x.Token.Value).First();
                    var offsets          = child_nodes[4].ChildNodes.Skip(1).Select(x => (long)x.Token.Value).ToArray();
                    var value_definition = new ASLValueDefinition()
                    {
                        Identifier = identifier,
                        Type       = type,
                        Pointer    = new DeepPointer(module, module_base, offsets)
                    };
                    state.ValueDefinitions.Add(value_definition);
                }

                state.GameVersion = version;
                if (!states.ContainsKey(process_name))
                {
                    states.Add(process_name, new List <ASLState>());
                }
                states[process_name].Add(state);
            }

            var methods = new ASLScript.Methods();

            foreach (var method in methods_node.ChildNodes[0].ChildNodes)
            {
                var body        = (string)method.ChildNodes[2].Token.Value;
                var method_name = (string)method.ChildNodes[0].Token.Value;
                var line        = method.ChildNodes[2].Token.Location.Line + 1;
                var script      = new ASLMethod(body, method_name, line)
                {
                    ScriptMethods = methods
                };
                switch (method_name)
                {
                case "init": methods.init = script; break;

                case "exit": methods.exit = script; break;

                case "update": methods.update = script; break;

                case "start": methods.start = script; break;

                case "split": methods.split = script; break;

                case "isLoading": methods.isLoading = script; break;

                case "gameTime": methods.gameTime = script; break;

                case "reset": methods.reset = script; break;

                case "startup": methods.startup = script; break;

                case "shutdown": methods.shutdown = script; break;
                }
            }

            return(new ASLScript(methods, states));
        }
Beispiel #16
0
        private dynamic RunMethod(ASLMethod method, LiveSplitState state)
        {
            var version = GameVersion;

            return(RunMethod(method, state, ref version));
        }
Beispiel #17
0
 public ASLRuntimeException(ASLMethod method, Exception inner_exception)
     : base(GetMessage(method, inner_exception), inner_exception)
 {
 }
Beispiel #18
0
 public ASLCompilerException(ASLMethod method, CompilerErrorCollection errors)
     : base(GetMessage(method, errors))
 {
     Method         = method;
     CompilerErrors = errors;
 }