public void ApplyChanges()
        {
            var tmp = Lines.ToList();

            tmp.RemoveAll(x => string.IsNullOrEmpty(x));
            Script.Clear();
            for (int i = 0; i < Lines.Count; i++)
            {
                string lineText = tmp[i].Trim();
                if (lineText.StartsWith("//"))
                {
                    continue;
                }

                ACMDCommand cmd   = ParseCMD(tmp[i]);
                uint        ident = cmd.CRC;


                int amt = 0;
                if ((amt = SerializeCommands(i, ident)) > 0)
                {
                    i += amt;
                    continue;
                }
                else
                {
                    Script.Add(cmd);
                }
            }
        }
        public void Serialize(List <string> lines)
        {
            lines.RemoveAll(x => string.IsNullOrEmpty(x));
            Script.Clear();
            for (int i = 0; i < lines.Count; i++)
            {
                string lineText = lines[i].Trim();
                if (lineText.Contains("//"))
                {
                    lineText = lineText.Substring(0, lineText.IndexOf("//"));
                }
                if (lineText.Length == 0)
                {
                    continue;
                }

                ACMDCommand cmd   = ParseCMD(lines[i]);
                uint        ident = cmd.CRC;

                int amt = 0;
                if ((amt = SerializeCommands(i, ident)) > 0)
                {
                    i += amt;
                    continue;
                }
                else
                {
                    Script.Add(cmd);
                }
            }
        }
Example #3
0
        public void ApplyChanges()
        {
            Lines.RemoveAll(x => x.Empty);
            CommandList.Clear();
            for (int i = 0; i < Lines.Count; i++)
            {
                string lineText = Lines[i].Text.Trim();
                if (lineText.StartsWith("//"))
                {
                    continue;
                }

                ACMDCommand cmd   = Lines[i].Parse();
                uint        ident = cmd._commandInfo.Identifier;


                int amt = 0;
                if ((amt = ParseCommands(i, ident)) > 0)
                {
                    i += amt;
                    continue;
                }
                else
                {
                    CommandList.Add(cmd);
                }
            }
        }
        private ACMDCommand ParseCMD(string line)
        {
            string s = line.TrimStart();

            s = s.Substring(0, s.IndexOf(')'));
            var name       = s.Substring(0, s.IndexOf('('));
            var parameters =
                s.Substring(s.IndexOf('(')).TrimEnd(')').Split(',').Select(x =>
                                                                           x.Remove(0, x.IndexOf('=') + 1)).ToArray();

            var         crc = ACMD_INFO.CMD_NAMES.Single(x => x.Value == name).Key;
            ACMDCommand cmd = new ACMDCommand(crc);

            for (int i = 0; i < cmd.ParamSpecifiers.Length; i++)
            {
                switch (cmd.ParamSpecifiers[i])
                {
                case 0:
                    cmd.Parameters.Add(int.Parse(parameters[i].Substring(2), System.Globalization.NumberStyles.HexNumber));
                    break;

                case 1:
                    cmd.Parameters.Add(float.Parse(parameters[i]));
                    break;

                case 2:
                    cmd.Parameters.Add(decimal.Parse(parameters[i]));
                    break;
                }
            }
            return(cmd);
        }
Example #5
0
        public ACMDCommand Parse()
        {
            var cmd        = new ACMDCommand(GetInfo());
            var parameters = _tokens.Where(x => x.TokType != TokenType.Syntax &&
                                           x.TokType != TokenType.String &&
                                           x.TokType != TokenType.Seperator).ToArray();

            for (int i = 0; i < Info.ParamSpecifiers.Count; i++)
            {
                if (parameters[i].TokType == TokenType.Integer)
                {
                    cmd.parameters.Add(int.Parse(parameters[i].Text.Remove(0, 2),
                                                 System.Globalization.NumberStyles.HexNumber));
                }
                else if (Info.ParamSpecifiers[i] == 2)
                {
                    cmd.parameters.Add(decimal.Parse(parameters[i].Text));
                }
                else if (parameters[i].TokType == TokenType.FloatingPoint)
                {
                    cmd.parameters.Add(float.Parse(parameters[i].Text));
                }
            }
            return(cmd);
        }
        private int SerializeLoop(int index)
        {
            int i = index;

            Script.Add(ParseCMD(Lines[i]));
            decimal len = 0;

            while (ParseCMD(Lines[++i]).CRC != 0x38A3EC78)
            {
                ACMDCommand tmp = ParseCMD(Lines[i]);
                len += (tmp.CalcSize() / 4);
                i   += SerializeCommands(i, tmp.CRC);
                Script.Add(tmp);
            }
            ACMDCommand endLoop = ParseCMD(Lines[i]);

            endLoop.Parameters[0] = len / -1;
            Script.Add(endLoop);
            // Next line should be closing bracket, ignore and skip it
            return(++i - index);
        }
Example #7
0
        private int ParseLoop(int index)
        {
            int i = index;

            CommandList.Add(Lines[i].Parse());
            decimal len = 0;

            while (Lines[++i].Parse()._commandInfo.Identifier != 0x38A3EC78)
            {
                ACMDCommand tmp = Lines[i].Parse();
                len += (tmp.CalcSize() / 4);
                i   += ParseCommands(i, tmp._commandInfo.Identifier);
                CommandList.Add(tmp);
            }
            ACMDCommand endLoop = Lines[i].Parse();

            endLoop.parameters[0] = len / -1;
            CommandList.Add(endLoop);
            // Next line should be closing bracket, ignore and skip it
            return(++i - index);
        }
        private int SerializeConditional(int startIndex)
        {
            ACMDCommand cmd = ParseCMD(Lines[startIndex]);
            int         i   = startIndex;
            int         len = 2;

            Script.Add(cmd);
            while (Lines[++i].Trim() != "}")
            {
                ACMDCommand tmp = ParseCMD(Lines[i]);
                len += tmp.CalcSize() / 4;
                if (IsCmdHandled(tmp.CRC))
                {
                    i += SerializeCommands(i, tmp.CRC);
                }
                else
                {
                    Script.Add(tmp);
                }
            }
            Script[Script.IndexOf(cmd)].Parameters[0] = len;
            // Next line should be closing bracket, ignore and skip it
            return(i - startIndex);
        }
Example #9
0
        private int ParseConditional(int startIndex)
        {
            ACMDCommand cmd = Lines[startIndex].Parse();
            int         i   = startIndex;
            int         len = 2;

            CommandList.Add(cmd);
            while (Lines[++i].TrimText != "}")
            {
                ACMDCommand tmp = Lines[i].Parse();
                len += tmp.CalcSize() / 4;
                if (IsCmdHandled(tmp._commandInfo.Identifier))
                {
                    i += ParseCommands(i, tmp._commandInfo.Identifier);
                }
                else
                {
                    CommandList.Add(tmp);
                }
            }
            CommandList[CommandList.IndexOf(cmd)].parameters[0] = len;
            // Next line should be closing bracket, ignore and skip it
            return(i - startIndex);
        }