/// <summary>
        /// Compile an array of code lines.
        /// </summary>
        /// <param name="lines">Array of plaintext code lines.</param>
        /// <returns></returns>
        public ACMDCommand[] Compile(string[] lines)
        {
            var tmpList = lines.ToList();

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

                ACMDCommand cmd   = this.CompileSingleCommand(tmpList[i]);
                uint        ident = cmd.Ident;


                int amt = 0;
                if ((amt = this.HandleSpecialCommands(i, ident, ref tmpList)) > 0)
                {
                    i += amt;
                    continue;
                }
                else
                {
                    Commands.Add(cmd);
                }
            }
            return(Commands.ToArray());
        }
        /// <summary>
        /// Compile a single ACMD command from plaintext.
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        private ACMDCommand CompileSingleCommand(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);
        }
        private int CompileConditional(int startIndex, ref List <string> lines)
        {
            ACMDCommand cmd = this.CompileSingleCommand(lines[startIndex]);
            int         i   = startIndex;
            int         len = 2;

            Commands.Add(cmd);
            while (lines[++i].Trim() != "}")
            {
                ACMDCommand tmp = this.CompileSingleCommand(lines[i]);
                len += tmp.Size / 4;
                if (this.IsCmdHandled(tmp.Ident))
                {
                    i += this.HandleSpecialCommands(i, tmp.Ident, ref lines);
                }
                else
                {
                    Commands.Add(tmp);
                }
            }

            Commands[Commands.IndexOf(cmd)].Parameters[0] = len;
            // Next line should be closing bracket, ignore and skip it
            return(i - startIndex);
        }
Exemple #4
0
        public void Serialize(List <string> lines)
        {
            lines.RemoveAll(x => string.IsNullOrEmpty(x));
            this.Clear();
            for (int i = 0; i < lines.Count; i++)
            {
                string lineText = lines[i].Trim();
                if (lineText.StartsWith("//"))
                {
                    continue;
                }

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


                int amt = 0;
                if ((amt = this.SerializeCommands(i, ident, ref lines)) > 0)
                {
                    i += amt;
                    continue;
                }
                else
                {
                    this.Add(cmd);
                }
            }
        }
Exemple #5
0
        private ACMDScript ParseEventList(uint cRC, int offset)
        {
            ACMDScript _list = new ACMDScript(cRC);

            ACMDCommand c;

            VoidPtr addr = (this._workingSource.Address + offset);

            // Loop through Event List.
            while (Util.GetWordUnsafe(addr, this.Endian) != 0x5766F889)
            {
                // Try to get command definition
                uint ident = (uint)Util.GetWordUnsafe(addr, this.Endian);
                // Get command parameters and add the command to the event list.
                c = new ACMDCommand(ident);
                for (int i = 0; i < c.ParamSpecifiers.Length; i++)
                {
                    switch (c.ParamSpecifiers[i])
                    {
                    case 0:
                        c.Parameters.Add(Util.GetWordUnsafe(0x04 + (addr + (i * 4)), this.Endian));
                        break;

                    case 1:
                        c.Parameters.Add(Util.GetFloatUnsafe(0x04 + (addr + (i * 4)), this.Endian));
                        break;

                    case 2:
                        c.Parameters.Add((decimal)Util.GetWordUnsafe(0x04 + (addr + (i * 4)), this.Endian));
                        break;

                    default:
                        goto case 0;
                    }
                }

                _list.Add(c);
                addr += c.Size;
            }

            // If we hit a script_end command, add it to the the Event List and terminate looping.
            if (Util.GetWordUnsafe(addr, this.Endian) == 0x5766F889)
            {
                c = new ACMDCommand(0x5766F889);
                _list.Add(c);
            }

            _list.Initialize();
            return(_list);
        }
Exemple #6
0
        /// <summary>
        /// Compile an array of code lines.
        /// </summary>
        /// <param name="lines">Array of plaintext code lines.</param>
        /// <returns></returns>
        public static ACMDCommand[] CompileCommands(string[] lines)
        {
            var tmpList = lines.ToList();

            tmpList.RemoveAll(x => string.IsNullOrWhiteSpace(x));
            Commands.Clear();
            for (int i = 0; i < tmpList.Count; i++)
            {
                string lineText = tmpList[i].Trim();

                // Handle comments
                if (lineText.StartsWith("//"))
                {
                    continue;
                }

                if (lineText.StartsWith("/*"))
                {
                    while (tmpList[i].Trim() != "*/")
                    {
                        i++;
                    }
                    if (++i < tmpList.Count)
                    {
                        lineText = tmpList[i].Trim();
                    }
                    else
                    {
                        break;
                    }
                }

                ACMDCommand cmd   = CompileSingleCommand(tmpList[i]);
                uint        ident = cmd.Ident;


                int amt = 0;
                if ((amt = HandleSpecialCommands(i, ident, ref tmpList)) > 0)
                {
                    i += amt;
                    continue;
                }
                else
                {
                    Commands.Add(cmd);
                }
            }
            return(Commands.ToArray());
        }
        private int CompileLoop(int index, ref List <string> lines)
        {
            int i = index;

            Commands.Add(this.CompileSingleCommand(lines[i]));
            decimal len = 0;

            while (this.CompileSingleCommand(lines[++i]).Ident != 0x38A3EC78)
            {
                ACMDCommand tmp = this.CompileSingleCommand(lines[i]);
                len += (tmp.Size / 4);
                i   += this.HandleSpecialCommands(i, tmp.Ident, ref lines);
                Commands.Add(tmp);
            }

            ACMDCommand endLoop = this.CompileSingleCommand(lines[i]);

            endLoop.Parameters[0] = len / -1;
            Commands.Add(endLoop);
            // Next line should be closing bracket, ignore and skip it
            return(++i - index);
        }
Exemple #8
0
 public int IndexOf(ACMDCommand var)
 {
     return(this._commands.IndexOf(var));
 }
Exemple #9
0
 public bool Contains(ACMDCommand var)
 {
     return(this._commands.Contains(var));
 }
Exemple #10
0
 public bool Remove(ACMDCommand var)
 {
     return(this._commands.Remove(var));
 }
Exemple #11
0
 public void Add(ACMDCommand var)
 {
     this._commands.Add(var);
 }
Exemple #12
0
 public void InsertAfter(int index, ACMDCommand var)
 {
     this._commands.Insert(index + 1, var);
 }