Exemplo n.º 1
0
        private static VariableModel ToVariableModel(Variable v, int i)
        {
            var set = v as VariableSet;
            var children = set == null
                ? new ObservableCollection<VariableModel>()
                : new ObservableCollection<VariableModel>(set.Variables.Select(ToVariableModel));

            var typed = v as TypedVariable;
            var type = typed == null
                ? "None"
                : typed.Type;

            var value = typed == null || typed.Value == null
                ? ""
                : typed.Value.ToString();

            return new VariableModel
            {
                Index = i,
                Name = v == null ? "" : v.Name,
                Type = type,
                Value = value,
                DebugString = v == null ? "" : v.ToString(),
                Children = children
            };
        }
Exemplo n.º 2
0
        private void ReadVariables(BinaryReader reader, IReadSavegameProgress progress)
        {
            var parser = new VariableParser(VariableNames);

            // TODO: Use while loops in each of the recursive parsers
            var parsers = new List<VariableParserBase>
            {
                new ManuVariableParser(),
                new OpVariableParser(),
                new VlVariableParser(),
                new AvalVariableParser(),
                new PorpVariableParser(),
                new SxapVariableParser(),
                new SsVariableParser(parser),
                new BsVariableParser(parser),
                new BlckVariableParser(parser)
            };
            parser.RegisterParsers(parsers);

            Variable[] variables = new Variable[VariableTableEntries.Length];
            for (int i = 0; i < VariableTableEntries.Length; i++)
            {
                // Calculate the size of the next token
                var size = VariableTableEntries[i].Size;
                int tokenSize;

                // There is a hidden variable before the last one
                if (i < VariableTableEntries.Length - 2)
                {
                    tokenSize = VariableTableEntries[i + 1].Offset - VariableTableEntries[i].Offset;
                }
                else
                {
                    tokenSize = VariableTableEntries[i].Size;
                }

                reader.BaseStream.Position = VariableTableEntries[i].Offset;
                try
                {
                    // Tokenizing
                    var readTokenSize = tokenSize;
                    var variable = parser.Parse(reader, ref readTokenSize);
                    variable.Size = size;
                    variable.TokenSize = tokenSize;
                    variables[i] = variable;
                }
                catch (ParseVariableException e)
                {
                    Debug.WriteLine(e.Message);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }

                if (i % 250 == 0 && progress != null) progress.Report(true, false, i, VariableTableEntries.Length);
            }

            // Parsing
            var valueParser = new VariableValueParser();
            var stack = new Stack<Variable>(variables.Reverse());
            var root = valueParser.Parse<SavegameRoot>(stack);
            Variables = variables;
        }