コード例 #1
0
 public dynamic Run(LiveSplitState timer, ASLState old, ASLState current, ExpandoObject vars, Process game, ref string version, ref double refreshRate)
 {
     // dynamic args can't be ref or out, this is a workaround
     CompiledCode.version = version;
     CompiledCode.refreshRate = refreshRate;
     var ret = CompiledCode.Execute(timer, old.Data, current.Data, vars, game);
     version = CompiledCode.version;
     refreshRate = CompiledCode.refreshRate;
     return ret;
 }
コード例 #2
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));
        }
コード例 #3
0
 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("");
 }
コード例 #4
0
 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("");
 }
コード例 #5
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);
        }
コード例 #6
0
        // This is executed repeatedly as long as the game is connected and initialized.
        private void DoUpdate(LiveSplitState state)
        {
            _old_state = _state.RefreshValues(_game);

            if (!(RunMethod(_methods.update, state) ?? true))
            {
                // If Update explicitly returns false, don't run anything else
                return;
            }

            if (state.CurrentPhase == TimerPhase.Running || state.CurrentPhase == TimerPhase.Paused)
            {
                if (_uses_game_time && !state.IsGameTimeInitialized)
                    _timer.InitializeGameTime();

                var is_paused = RunMethod(_methods.isLoading, state);
                if (is_paused != null)
                    state.IsGameTimePaused = is_paused;

                var game_time = RunMethod(_methods.gameTime, state);
                if (game_time != null)
                    state.SetGameTime(game_time);

                if (RunMethod(_methods.reset, state) ?? false)
                {
                    if (_settings.GetBasicSettingValue("reset"))
                        _timer.Reset();
                }
                else if (RunMethod(_methods.split, state) ?? false)
                {
                    if (_settings.GetBasicSettingValue("split"))
                        _timer.Split();
                }
            }

            if (state.CurrentPhase == TimerPhase.NotRunning)
            {
                if (RunMethod(_methods.start, state) ?? false)
                {
                    if (_settings.GetBasicSettingValue("start"))
                        _timer.Start();
                }
            }
        }
コード例 #7
0
        // This is executed each time after connecting to the game (usually just once,
        // unless an error occurs before the method finishes).
        private void DoInit(LiveSplitState state)
        {
            Debug("Initializing");

            _state.RefreshValues(_game);
            _old_state = _state;
            GameVersion = string.Empty;

            // Fetch version from init-method
            var ver = string.Empty;
            RunMethod(_methods.init, state, ref ver);

            if (ver != GameVersion)
            {
                GameVersion = ver;

                var version_state = _states.Where(kv => kv.Key.ToLower() == _game.ProcessName.ToLower())
                    .Select(kv => kv.Value)
                    .First() // states
                    .FirstOrDefault(s => s.GameVersion == ver);

                if (version_state != null)
                {
                    // This state descriptor may already be selected
                    if (version_state != _state)
                    {
                        _state = version_state;
                        _state.RefreshValues(_game);
                        _old_state = _state;
                        Debug($"Switched to state descriptor for version '{GameVersion}'");
                    }
                }
                else
                {
                    Debug($"No state descriptor for version '{GameVersion}' (will keep using default one)");
                }
            }

            _init_completed = true;
            Debug("Init completed, running main methods");
        }
コード例 #8
0
        private void TryConnect(LiveSplitState state)
        {
            _game = null;

            var state_process = _states.Keys.Select(proccessName => new
            {
                // default to the state with no version specified, if it exists
                State = _states[proccessName].FirstOrDefault(s => s.GameVersion == "") ?? _states[proccessName].First(),
                Process = Process.GetProcessesByName(proccessName).FirstOrDefault(x => !x.HasExited)
            }).FirstOrDefault(x => x.Process != null);

            if (state_process == null)
                return;

            _init_completed = false;
            _game = state_process.Process;
            _state = state_process.State;

            if (_state.GameVersion == "")
            {
                Debug("Connected to game: {0} (using default state descriptor)", _game.ProcessName);
            }
            else
            {
                Debug("Connected to game: {0} (state descriptor for version '{1}' chosen as default)",
                    _game.ProcessName,
                    _state.GameVersion);
            }

            DoInit(state);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
 public dynamic Run(LiveSplitState timer, ASLState old, ASLState current)
 {
     return(CompiledCode.Execute(timer, old.Data, current.Data));
 }
コード例 #11
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));
        }
コード例 #12
0
 public dynamic Run(LiveSplitState timer, ASLState old, ASLState current)
 {
     return CompiledCode.Execute(timer, old.Data, current.Data);
 }
コード例 #13
0
 public OcarinaOfTimeScript()
 {
     State = new ASLState();
 }
コード例 #14
0
 public PokemonRedBlueScript()
 {
     State = new ASLState();
 }