Пример #1
0
        /// <summary>
        /// Read parameters, but only for prefix commands.
        /// </summary>
        /// <param name="br">The reader</param>
        public void ReadPrefixParameters(BinaryDataReader br)
        {
            //Read the objects.
            int count = 0;

            foreach (var t in SequenceParameterTypes)
            {
                //Switch the type.
                switch (t)
                {
                //U8.
                case SequenceParameterType.u8:
                    Parameters[count] = br.ReadByte();
                    break;

                //U16.
                case SequenceParameterType.u16:
                    Parameters[count] = br.ReadUInt16();
                    break;

                //U24.
                case SequenceParameterType.u24:
                    Parameters[count] = new UInt24(br);
                    break;

                //U32.
                case SequenceParameterType.u32:
                    Parameters[count] = br.ReadUInt32();
                    break;

                //U64.
                case SequenceParameterType.u64:
                    Parameters[count] = br.ReadUInt64();
                    break;

                //S8.
                case SequenceParameterType.s8:
                    Parameters[count] = br.ReadSByte();
                    break;

                //S16.
                case SequenceParameterType.s16:
                    Parameters[count] = br.ReadInt16();
                    break;

                //S32.
                case SequenceParameterType.s32:
                    Parameters[count] = br.ReadInt32();
                    break;

                //S64.
                case SequenceParameterType.s64:
                    Parameters[count] = br.ReadInt64();
                    break;

                //Boolean.
                case SequenceParameterType.boolean:
                    Parameters[count] = br.ReadBoolean();
                    break;

                //Variable length.
                case SequenceParameterType.VariableLength:
                    Parameters[count] = VariableLength.ReadVariableLength(br);
                    break;

                //Sequence command.
                case SequenceParameterType.SeqCommand:
                    Parameters[count] = Read(br);
                    break;
                }

                //Increase count.
                count++;
            }
        }
Пример #2
0
        /// <summary>
        /// Read a sequence command.
        /// </summary>
        /// <param name="br">The reader.</param>
        /// <param name="type">Type of sequence command.</param>
        /// <returns>The read sequence command.</returns>
        public static SequenceCommand Read(BinaryDataReader br, SequenceCommandType type = SequenceCommandType.Normal)
        {
            //Get sequence command.
            SequenceCommand s = null;

            switch (type)
            {
            case SequenceCommandType.Normal:
                s = NewFromType(br.ReadByte(), (int)br.Position);
                break;

            case SequenceCommandType.Extended:
                s = NewFromTypeExtended(br.ReadByte(), (int)br.Position);
                break;
            }

            //Read the objects.
            int count = 0;

            foreach (var t in s.SequenceParameterTypes)
            {
                //Switch the type.
                switch (t)
                {
                //U8.
                case SequenceParameterType.u8:
                    s.Parameters[count] = br.ReadByte();
                    break;

                //U16.
                case SequenceParameterType.u16:
                    s.Parameters[count] = br.ReadUInt16();
                    break;

                //U24.
                case SequenceParameterType.u24:
                    s.Parameters[count] = new UInt24(br);
                    break;

                //U32.
                case SequenceParameterType.u32:
                    s.Parameters[count] = br.ReadUInt32();
                    break;

                //U64.
                case SequenceParameterType.u64:
                    s.Parameters[count] = br.ReadUInt64();
                    break;

                //S8.
                case SequenceParameterType.s8:
                    s.Parameters[count] = br.ReadSByte();
                    break;

                //S16.
                case SequenceParameterType.s16:
                    s.Parameters[count] = br.ReadInt16();
                    break;

                //S32.
                case SequenceParameterType.s32:
                    s.Parameters[count] = br.ReadInt32();
                    break;

                //S64.
                case SequenceParameterType.s64:
                    s.Parameters[count] = br.ReadInt64();
                    break;

                //Boolean.
                case SequenceParameterType.boolean:
                    s.Parameters[count] = br.ReadBoolean();
                    break;

                //Variable length.
                case SequenceParameterType.VariableLength:
                    s.Parameters[count] = VariableLength.ReadVariableLength(br);
                    break;

                //Sequence command.
                case SequenceParameterType.SeqCommand:

                    //The type of sequence command embedded depends on the command type.
                    switch ((CommandType)s.Identifier)
                    {
                    //Extended.
                    case CommandType.Extended:
                        s.Parameters[count] = Read(br, SequenceCommandType.Extended);
                        break;

                    //Random.
                    case CommandType.Random:
                        s.Parameters[count] = NewFromType(br.ReadByte(), (int)br.Position);

                        //Extended.
                        if (((SequenceCommand)s.Parameters[count]).Identifier == (byte)CommandType.Extended)
                        {
                            //Read a new extended command.
                            ((SequenceCommand)s.Parameters[count]).Parameters[0] = NewFromTypeExtended(br.ReadByte(), (int)br.Position);

                            //Remove the last parameter of the sequence command.
                            ((SequenceCommand)((SequenceCommand)s.Parameters[count]).Parameters[0]).SequenceParameterTypes.RemoveAt(((SequenceCommand)((SequenceCommand)s.Parameters[count]).Parameters[0]).SequenceParameterTypes.Count - 1);

                            //Read the parameters.
                            ((SequenceCommand)((SequenceCommand)s.Parameters[count]).Parameters[0]).ReadPrefixParameters(br);
                        }

                        //Regular.
                        else
                        {
                            //Remove the last parameter, since it is replaced with the min and max.
                            ((SequenceCommand)s.Parameters[count]).SequenceParameterTypes.RemoveAt(((SequenceCommand)s.Parameters[count]).SequenceParameterTypes.Count - 1);
                            ((SequenceCommand)s.Parameters[count]).ReadPrefixParameters(br);
                        }
                        break;

                    //Variable.
                    case CommandType.Variable:
                        s.Parameters[count] = NewFromType(br.ReadByte(), (int)br.Position);

                        //Extended.
                        if (((SequenceCommand)s.Parameters[count]).Identifier == (byte)CommandType.Extended)
                        {
                            //Read a new extended command.
                            ((SequenceCommand)s.Parameters[count]).Parameters[0] = NewFromTypeExtended(br.ReadByte(), (int)br.Position);

                            //Remove the last parameter of the sequence command.
                            ((SequenceCommand)((SequenceCommand)s.Parameters[count]).Parameters[0]).SequenceParameterTypes.RemoveAt(((SequenceCommand)((SequenceCommand)s.Parameters[count]).Parameters[0]).SequenceParameterTypes.Count - 1);

                            //Read the parameters.
                            ((SequenceCommand)((SequenceCommand)s.Parameters[count]).Parameters[0]).ReadPrefixParameters(br);
                        }

                        //Regular.
                        else
                        {
                            //Remove the last parameter, since it is replaced with the min and max.
                            ((SequenceCommand)s.Parameters[count]).SequenceParameterTypes.RemoveAt(((SequenceCommand)s.Parameters[count]).SequenceParameterTypes.Count - 1);
                            ((SequenceCommand)s.Parameters[count]).ReadPrefixParameters(br);
                        }
                        break;

                    //Last resort.
                    default:
                        s.Parameters[count] = Read(br);
                        break;
                    }
                    break;
                }

                //Increase count.
                count++;
            }

            //Return the command.
            return(s);
        }
Пример #3
0
        /// <summary>
        /// Write the command.
        /// </summary>
        /// <param name="bw">The writer.</param>
        public void Write(BinaryDataWriter bw, List <SequenceCommand> commands)
        {
            //Write the identifier.
            bw.Write(Identifier);

            //Write each parameter.
            int count = 0;

            foreach (var t in SequenceParameterTypes)
            {
                //Write the item.
                switch (t)
                {
                //U8.
                case SequenceParameterType.u8:
                    bw.Write((byte)Parameters[count]);
                    break;

                //U16.
                case SequenceParameterType.u16:
                    bw.Write((UInt16)Parameters[count]);
                    break;

                //U24.
                case SequenceParameterType.u24:

                    //Uses an offset.
                    if ((CommandType)Identifier == CommandType.Call || (CommandType)Identifier == CommandType.Jump || (CommandType)Identifier == CommandType.OpenTrack)
                    {
                        new UInt24((uint)SequenceData.CommandIndexToOffset(commands, (int)((UInt24)Parameters[count]).Value)).Write(bw);
                    }

                    //Normal.
                    else
                    {
                        ((UInt24)Parameters[count]).Write(bw);
                    }
                    break;

                //U32.
                case SequenceParameterType.u32:
                    bw.Write((UInt32)Parameters[count]);
                    break;

                //U32.
                case SequenceParameterType.u64:
                    bw.Write((UInt64)Parameters[count]);
                    break;

                //S8.
                case SequenceParameterType.s8:
                    bw.Write((sbyte)Parameters[count]);
                    break;

                //S16.
                case SequenceParameterType.s16:
                    bw.Write((Int16)Parameters[count]);
                    break;

                //S32.
                case SequenceParameterType.s32:
                    bw.Write((Int32)Parameters[count]);
                    break;

                //S32.
                case SequenceParameterType.s64:
                    bw.Write((Int64)Parameters[count]);
                    break;

                //Boolean.
                case SequenceParameterType.boolean:
                    bw.Write((bool)Parameters[count]);
                    break;

                //Variable length.
                case SequenceParameterType.VariableLength:
                    VariableLength.WriteVariableLength(bw, (uint)Parameters[count]);
                    break;

                //Sequence command.
                case SequenceParameterType.SeqCommand:
                    ((SequenceCommand)Parameters[count]).Write(bw, commands);
                    break;
                }

                //Increment count.
                count++;
            }
        }