示例#1
0
        public Batch(ABinaryReader binaryReader)
        {
            FaceCount = binaryReader.Read16();
            int size = (binaryReader.Read16() << 5);

            Attributes = (BatchAttributes)(uint)binaryReader.Read32();
            UseNormals = (binaryReader.Read8() != 0);
            positions  = binaryReader.Read8();
            int uvCount = binaryReader.Read8();

            UseNBT = (binaryReader.Read8() != 0);
            Offset = binaryReader.Read32();

            if (binaryReader.Read8s(8).Any(zero => zero != 0))
            {
#if AROOKAS_DEMOLISHER_CHECKPADDING
                throw new Exception(String.Format("Batch padding != 0 at 0x{0:X8}.", binaryReader.Stream.Position));
#endif
            }

            int faces = 0;
            List <Primitive> primitives = new List <Primitive>();
            binaryReader.Goto(Offset);

            while (faces < FaceCount && binaryReader.Position < Offset + size)
            {
                Primitive primitive = new Primitive(binaryReader, UseNBT, uvCount, Attributes);

                if (!primitive.Type.IsDefined())
                {
                    break;
                }

                primitives.Add(primitive);
                faces += primitive.FaceCount;
            }

            binaryReader.Back();

            this.primitives = primitives.ToArray();
        }
示例#2
0
        // Token: 0x06000155 RID: 341 RVA: 0x00004F50 File Offset: 0x00003150
        public static MIDI FromStream(Stream stream)
        {
            ABinaryReader abinaryReader = new ABinaryReader(stream, Endianness.Big);
            MIDI          midi          = new MIDI();

            if (abinaryReader.ReadRawString(4) != "MThd")
            {
                throw new InvalidDataException("Missing header chunk in MIDI file.");
            }
            if (abinaryReader.Read32() != 6U)
            {
                throw new InvalidDataException("Invalid header size in MIDI file.");
            }
            MIDIFormat enumValue = (MIDIFormat)abinaryReader.Read16();

            if (!enumValue.IsDefined <MIDIFormat>())
            {
                throw new InvalidDataException("Invalid format in MIDI file.");
            }
            abinaryReader.Read16();
            int num = (int)abinaryReader.Read16();

            if ((num & 32768) != 0)
            {
                midi.division = new SMPTEDivision((SMPTEFrameRate)(-(int)(num >> 8)), num & 255);                 // TODO: Cannot infer type, so: (ModularType) -> (int)
            }
            else
            {
                midi.division = new TicksPerBeatDivision(num);
            }
            int num2 = 0;

            while (!abinaryReader.IsAtEndOfStream)
            {
                if (abinaryReader.ReadRawString(4) != "MTrk")
                {
                    throw new InvalidDataException("Missing track chunk in MIDI file.");
                }
                ulong num3 = 0UL;
                uint  num4 = abinaryReader.Read32();
                abinaryReader.SetAnchor();
                Track track = new Track();
                byte  b     = 0;
                while (abinaryReader.Position < (long)((ulong)num4))
                {
                    ulong num5 = abinaryReader.ReadUIntVar();
                    byte  b2   = abinaryReader.Read8();
                    if (b2 < 128)
                    {
                        if (b == 0)
                        {
                            throw new InvalidDataException("Encountered running status event with no previous status available.");
                        }
                        b2 = b;
                        abinaryReader.Position -= 1L;
                    }
                    if (b2 >= 240 && b2 <= 247)
                    {
                        b = 0;
                    }
                    else if (b2 >= 128 && b2 <= 239)
                    {
                        b = b2;
                    }
                    num3 += num5;
                    if (b2 == 255)
                    {
                        MetaEventType metaEventType = (MetaEventType)abinaryReader.Read8();
                        int           num6          = (int)abinaryReader.ReadUIntVar();
                        if (!metaEventType.IsDefined <MetaEventType>())
                        {
                            throw new InvalidDataException(string.Format("Encountered unsupported meta event type {0}.", metaEventType));
                        }
                        MetaEventType metaEventType2 = metaEventType;
                        if (metaEventType2 <= MetaEventType.EndOfTrack)
                        {
                            switch (metaEventType2)
                            {
                            case MetaEventType.SequenceNumber:
                                if (num6 != 2)
                                {
                                    throw new InvalidDataException("Invalid size in sequence-number event.");
                                }
                                track.Add(new SequenceNumberEvent(num5, (int)abinaryReader.Read16()), num3);
                                continue;

                            case MetaEventType.Text:
                                track.Add(new TextEvent(num5, abinaryReader.ReadRawString(num6)), num3);
                                continue;

                            case MetaEventType.CopyrightNotice:
                                track.Add(new CopyrightNoticeEvent(num5, abinaryReader.ReadRawString(num6)), num3);
                                continue;

                            case MetaEventType.Name:
                                track.Add(new TrackNameEvent(num5, abinaryReader.ReadRawString(num6)), num3);
                                continue;

                            case MetaEventType.InstrumentName:
                                track.Add(new InstrumentNameEvent(num5, abinaryReader.ReadRawString(num6)), num3);
                                continue;

                            case MetaEventType.Lyrics:
                                track.Add(new LyricsEvent(num5, abinaryReader.ReadRawString(num6)), num3);
                                continue;

                            case MetaEventType.Marker:
                                track.Add(new MarkerEvent(num5, abinaryReader.ReadRawString(num6)), num3);
                                continue;

                            case MetaEventType.CuePoint:
                                track.Add(new CuePointEvent(num5, abinaryReader.ReadRawString(num6)), num3);
                                continue;

                            default:
                                if (metaEventType2 != MetaEventType.ChannelPrefix)
                                {
                                    if (metaEventType2 == MetaEventType.EndOfTrack)
                                    {
                                        if (num6 != 0)
                                        {
                                            throw new InvalidDataException("Invalid size in end-of-track event.");
                                        }
                                        track.Add(new EndOfTrackEvent(num5), num3);
                                        continue;
                                    }
                                }
                                else
                                {
                                    if (num6 != 1)
                                    {
                                        throw new InvalidDataException("Invalid size in channel-prefix event.");
                                    }
                                    track.Add(new ChannelPrefixEvent(num5, abinaryReader.Read8()), num3);
                                    continue;
                                }
                                break;
                            }
                        }
                        else if (metaEventType2 != MetaEventType.TempoChange)
                        {
                            switch (metaEventType2)
                            {
                            case MetaEventType.TimeSignature:
                                if (num6 != 4)
                                {
                                    throw new InvalidDataException("Invalid size in time-signature event.");
                                }
                                track.Add(new TimeSignatureEvent(num5, (int)abinaryReader.Read8(), (int)abinaryReader.Read8(), (int)abinaryReader.Read8(), (int)abinaryReader.Read8()), num3);
                                continue;

                            case MetaEventType.KeySignature:
                                if (num6 != 2)
                                {
                                    throw new InvalidDataException("Invalid size in key-signature event.");
                                }
                                track.Add(new KeySignatureEvent(num5, (int)abinaryReader.ReadS8(), (Scale)abinaryReader.Read8()), num3);
                                continue;

                            default:
                                if (metaEventType2 == MetaEventType.SequencerSpecific)
                                {
                                    byte[] array = abinaryReader.Read8s(num6);
                                    if (num6 == 0 || num6 < ((array[0] == 0) ? 3 : 1))
                                    {
                                        throw new InvalidDataException("Invalid size in sequencer-specific event.");
                                    }
                                    bool flag           = array[0] == 0;
                                    int  manufacturerID = flag ? ((int)array[1] << 8 | (int)array[2]) : ((int)array[0]);
                                    track.Add(new SequencerSpecificEvent(num5, manufacturerID, flag, array.Duplicate(flag ? 3 : 1, array.Length - (flag ? 3 : 1))), num3);
                                    continue;
                                }
                                break;
                            }
                        }
                        else
                        {
                            if (num6 != 3)
                            {
                                throw new InvalidDataException("Invalid size in tempo-change event.");
                            }
                            track.Add(new TempoChangeEvent(num5, abinaryReader.Read24()), num3);
                            continue;
                        }
                        throw new NotImplementedException(string.Format("Encountered unimplemented meta event type {0}.", metaEventType));
                    }
                    else if (b2 == 240 || b2 == 247)
                    {
                        byte[] array2 = abinaryReader.Read8s((int)abinaryReader.ReadUIntVar());
                        if (array2.Length == 0 || array2.Length < ((array2[0] == 0) ? 3 : 1))
                        {
                            throw new InvalidDataException("Encountered a SysEx event with an invalid size.");
                        }
                        SystemExclusiveEventType type = SystemExclusiveEventType.Normal;
                        bool flag2           = b2 == 247;
                        bool flag3           = array2.Last <byte>() == 247;
                        bool flag4           = array2[0] == 0;
                        int  manufacturerID2 = flag4 ? ((int)array2[1] << 8 | (int)array2[2]) : ((int)array2[0]);
                        if (flag2)
                        {
                            type = (flag3 ? SystemExclusiveEventType.Terminating : SystemExclusiveEventType.Continuation);
                        }
                        if (flag3)
                        {
                            array2 = array2.Duplicate(array2.Length - 1);
                        }
                        track.Add(new SystemExclusiveEvent(num5, type, manufacturerID2, flag4, array2), num3);
                    }
                    else
                    {
                        ChannelEventType channelEventType = (ChannelEventType)(b2 & 240);
                        byte             channelNumber    = (byte)(b2 & 15);
                        if (!channelEventType.IsDefined <ChannelEventType>())
                        {
                            throw new InvalidDataException(string.Format("Encountered undefined channel-event type {0}.", channelEventType));
                        }
                        ChannelEventType channelEventType2 = channelEventType;
                        if (channelEventType2 <= ChannelEventType.NoteAftertouch)
                        {
                            if (channelEventType2 == ChannelEventType.NoteOff)
                            {
                                track.Add(new NoteOffEvent(num5, (int)channelNumber, abinaryReader.Read8(), (int)abinaryReader.Read8()), num3);
                                continue;
                            }
                            if (channelEventType2 == ChannelEventType.NoteOn)
                            {
                                track.Add(new NoteOnEvent(num5, (int)channelNumber, (int)abinaryReader.Read8(), (int)abinaryReader.Read8()), num3);
                                continue;
                            }
                            if (channelEventType2 == ChannelEventType.NoteAftertouch)
                            {
                                track.Add(new NoteAftertouchEvent(num5, (int)channelNumber, (int)abinaryReader.Read8(), (int)abinaryReader.Read8()), num3);
                                continue;
                            }
                        }
                        else if (channelEventType2 <= ChannelEventType.ProgramChange)
                        {
                            if (channelEventType2 == ChannelEventType.Controller)
                            {
                                track.Add(new ControllerEvent(num5, (int)channelNumber, (int)abinaryReader.Read8(), (int)abinaryReader.Read8()), num3);
                                continue;
                            }
                            if (channelEventType2 == ChannelEventType.ProgramChange)
                            {
                                track.Add(new ProgramChangeEvent(num5, (int)channelNumber, (int)abinaryReader.Read8()), num3);
                                continue;
                            }
                        }
                        else
                        {
                            if (channelEventType2 == ChannelEventType.ChannelAftertouch)
                            {
                                track.Add(new ChannelAftertouchEvent(num5, (int)channelNumber, (int)abinaryReader.Read8()), num3);
                                continue;
                            }
                            if (channelEventType2 == ChannelEventType.PitchBend)
                            {
                                track.Add(new PitchBendEvent(num5, (int)channelNumber, (int)(abinaryReader.Read8() & 127) | (int)(abinaryReader.Read8() & 127) << 7), num3);
                                continue;
                            }
                        }
                        throw new NotImplementedException(string.Format("Encountered unimplemented channel event type {0}.", channelEventType));
                    }
                }
                midi.tracks.Add(track);
                abinaryReader.ResetAnchor();
                num2++;
            }
            return(midi);
        }
示例#3
0
        // Token: 0x06000008 RID: 8 RVA: 0x00002124 File Offset: 0x00000324
        private static MIDIEvent FromStream(ABinaryReader binaryReader, ulong deltaTime, byte statusByte)
        {
            if (statusByte == 255)
            {
                MetaEventType metaEventType = (MetaEventType)binaryReader.Read8();
                int           num           = (int)binaryReader.ReadUIntVar();
                if (!metaEventType.IsDefined <MetaEventType>())
                {
                    throw new InvalidDataException(string.Format("Encountered unsupported meta event type {0}.", metaEventType));
                }
                MetaEventType metaEventType2 = metaEventType;
                if (metaEventType2 <= MetaEventType.EndOfTrack)
                {
                    switch (metaEventType2)
                    {
                    case MetaEventType.SequenceNumber:
                        if (num != 2)
                        {
                            throw new InvalidDataException("Invalid size in sequence-number event.");
                        }
                        return(new SequenceNumberEvent(deltaTime, (int)binaryReader.Read16()));

                    case MetaEventType.Text:
                        return(new TextEvent(deltaTime, binaryReader.ReadRawString(num)));

                    case MetaEventType.CopyrightNotice:
                        return(new CopyrightNoticeEvent(deltaTime, binaryReader.ReadRawString(num)));

                    case MetaEventType.Name:
                        return(new TrackNameEvent(deltaTime, binaryReader.ReadRawString(num)));

                    case MetaEventType.InstrumentName:
                        return(new InstrumentNameEvent(deltaTime, binaryReader.ReadRawString(num)));

                    case MetaEventType.Lyrics:
                        return(new LyricsEvent(deltaTime, binaryReader.ReadRawString(num)));

                    case MetaEventType.Marker:
                        return(new MarkerEvent(deltaTime, binaryReader.ReadRawString(num)));

                    case MetaEventType.CuePoint:
                        return(new CuePointEvent(deltaTime, binaryReader.ReadRawString(num)));

                    default:
                        if (metaEventType2 != MetaEventType.ChannelPrefix)
                        {
                            if (metaEventType2 == MetaEventType.EndOfTrack)
                            {
                                if (num != 0)
                                {
                                    throw new InvalidDataException("Invalid size in end-of-track event.");
                                }
                                return(new EndOfTrackEvent(deltaTime));
                            }
                        }
                        else
                        {
                            if (num != 1)
                            {
                                throw new InvalidDataException("Invalid size in channel-prefix event.");
                            }
                            return(new ChannelPrefixEvent(deltaTime, binaryReader.Read8()));
                        }
                        break;
                    }
                }
                else if (metaEventType2 != MetaEventType.TempoChange)
                {
                    switch (metaEventType2)
                    {
                    case MetaEventType.TimeSignature:
                        if (num != 4)
                        {
                            throw new InvalidDataException("Invalid size in time-signature event.");
                        }
                        return(new TimeSignatureEvent(deltaTime, (int)binaryReader.Read8(), (int)binaryReader.Read8(), (int)binaryReader.Read8(), (int)binaryReader.Read8()));

                    case MetaEventType.KeySignature:
                        if (num != 2)
                        {
                            throw new InvalidDataException("Invalid size in key-signature event.");
                        }
                        return(new KeySignatureEvent(deltaTime, (int)binaryReader.ReadS8(), (Scale)binaryReader.Read8()));

                    default:
                        if (metaEventType2 == MetaEventType.SequencerSpecific)
                        {
                            byte[] array = binaryReader.Read8s(num);
                            if (num == 0 || num < ((array[0] == 0) ? 3 : 1))
                            {
                                throw new InvalidDataException("Invalid size in sequencer-specific event.");
                            }
                            bool flag           = array[0] == 0;
                            int  manufacturerID = flag ? ((int)array[1] << 8 | (int)array[2]) : ((int)array[0]);
                            return(new SequencerSpecificEvent(deltaTime, manufacturerID, flag, array.Duplicate(flag ? 3 : 1, array.Length - (flag ? 3 : 1))));
                        }
                        break;
                    }
                }
                else
                {
                    if (num != 3)
                    {
                        throw new InvalidDataException("Invalid size in tempo-change event.");
                    }
                    return(new TempoChangeEvent(deltaTime, binaryReader.Read24()));
                }
                throw new NotImplementedException(string.Format("Encountered unimplemented meta event type {0}.", metaEventType));
            }
            else if (statusByte == 240 || statusByte == 247)
            {
                byte[] array2 = binaryReader.Read8s((int)binaryReader.ReadUIntVar());
                if (array2.Length == 0 || array2.Length < ((array2[0] == 0) ? 3 : 1))
                {
                    throw new InvalidDataException("Encountered a SysEx event with an invalid size.");
                }
                SystemExclusiveEventType type = SystemExclusiveEventType.Normal;
                bool flag2           = statusByte == 247;
                bool flag3           = array2.Last <byte>() == 247;
                bool flag4           = array2[0] == 0;
                int  manufacturerID2 = flag4 ? ((int)array2[1] << 8 | (int)array2[2]) : ((int)array2[0]);
                if (flag2)
                {
                    type = (flag3 ? SystemExclusiveEventType.Terminating : SystemExclusiveEventType.Continuation);
                }
                if (flag3)
                {
                    array2 = array2.Duplicate(array2.Length - 1);
                }
                return(new SystemExclusiveEvent(deltaTime, type, manufacturerID2, flag4, array2));
            }
            else
            {
                ChannelEventType channelEventType = (ChannelEventType)(statusByte & 240);
                byte             channelNumber    = (byte)(statusByte & 15);
                if (!channelEventType.IsDefined <ChannelEventType>())
                {
                    throw new InvalidDataException(string.Format("Encountered undefined channel-event type {0}.", channelEventType));
                }
                ChannelEventType channelEventType2 = channelEventType;
                if (channelEventType2 <= ChannelEventType.NoteAftertouch)
                {
                    if (channelEventType2 == ChannelEventType.NoteOff)
                    {
                        return(new NoteOffEvent(deltaTime, (int)channelNumber, binaryReader.Read8(), (int)binaryReader.Read8()));
                    }
                    if (channelEventType2 == ChannelEventType.NoteOn)
                    {
                        return(new NoteOnEvent(deltaTime, (int)channelNumber, (int)binaryReader.Read8(), (int)binaryReader.Read8()));
                    }
                    if (channelEventType2 == ChannelEventType.NoteAftertouch)
                    {
                        return(new NoteAftertouchEvent(deltaTime, (int)channelNumber, (int)binaryReader.Read8(), (int)binaryReader.Read8()));
                    }
                }
                else if (channelEventType2 <= ChannelEventType.ProgramChange)
                {
                    if (channelEventType2 == ChannelEventType.Controller)
                    {
                        return(new ControllerEvent(deltaTime, (int)channelNumber, (int)binaryReader.Read8(), (int)binaryReader.Read8()));
                    }
                    if (channelEventType2 == ChannelEventType.ProgramChange)
                    {
                        return(new ProgramChangeEvent(deltaTime, (int)channelNumber, (int)binaryReader.Read8()));
                    }
                }
                else
                {
                    if (channelEventType2 == ChannelEventType.ChannelAftertouch)
                    {
                        return(new ChannelAftertouchEvent(deltaTime, (int)channelNumber, (int)binaryReader.Read8()));
                    }
                    if (channelEventType2 == ChannelEventType.PitchBend)
                    {
                        return(new PitchBendEvent(deltaTime, (int)channelNumber, (int)(binaryReader.Read8() & 127) | (int)(binaryReader.Read8() & 127) << 7));
                    }
                }
                throw new NotImplementedException(string.Format("Encountered unimplemented channel event type {0}.", channelEventType));
            }
        }