Ejemplo n.º 1
0
        void ReadCMP(ABinaryReader binaryReader)
        {
            // image
            for (int y = 0; y < Height; y += 8)
            {
                for (int x = 0; x < Width; x += 8)
                {
                    // 2x2 block
                    for (int ay = 0; ay < 8; ay += 4)
                    {
                        for (int ax = 0; ax < 8; ax += 4)
                        {
                            // 4x4 tile
                            Color[] colors = Color.FromST3C1(binaryReader.Read64());

                            for (int by = 0; by < 4 && y + ay + by < Height; by++)
                            {
                                for (int bx = 0; bx < 4 && x + ax + bx < Width; bx++)
                                {
                                    data[Width * (y + ay + by) + (x + ax + bx)] = colors[by * 4 + bx];
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void ReadRGB5A3(ABinaryReader binaryReader)
        {
            for (int y = 0; y < Height; y += 4)
            {
                for (int x = 0; x < Width; x += 4)
                {
                    for (int by = 0; by < 4 && y + by < Height; by++)
                    {
                        for (int bx = 0; bx < 4 && x + bx < Width; bx++)
                        {
                            ushort color_u16 = binaryReader.Read16();
                            Color  color;

                            if ((color_u16 & 0x8000) == 0x8000)
                            {
                                color = Color.FromRGB5(color_u16);
                            }
                            else
                            {
                                color = Color.FromRGB4A3(color_u16);
                            }

                            data[Width * (y + by) + (x + bx)] = color;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void ReadRGB8(ABinaryReader binaryReader)
        {
            for (int y = 0; y < Height; y += 4)
            {
                for (int x = 0; x < Width; x += 4)
                {
                    uint[] colors = new uint[16];

                    for (int by = 0; by < 4 && y + by < Height; by++)                     // AR
                    {
                        for (int bx = 0; bx < 4 && x + bx < Width; bx++)
                        {
                            colors[4 * by + bx] = (uint)(binaryReader.Read8() << 16);
                        }
                    }

                    for (int by = 0; by < 4 && y + by < Height; by++)                     // GB
                    {
                        for (int bx = 0; bx < 4 && x + bx < Width; bx++)
                        {
                            colors[4 * by + bx] |= binaryReader.Read8();
                        }
                    }

                    for (int by = 0; by < 4 && y + by < Height; by++)
                    {
                        for (int bx = 0; bx < 4 && x + bx < Width; bx++)
                        {
                            data[Width * (y + by) + (x + bx)] = Color.FromARGB8(colors[4 * by + bx]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public Bin(string fileName, Vector3 position, Vector3 rotation, Vector3 scale)
        {
            // header
            binaryReader = new ABinaryReader(Yay0.Decompress(fileName), Endianness.Big, Encoding.GetEncoding(932));
            unk1 = binaryReader.Read8();
            name = binaryReader.ReadClampedString(11);
            offsets = binaryReader.Read32s(21);

            // data
            graphObjects = (HasGraph ? GetGraphObjects(0) : new GraphObject[0]);
            batches = (HasBatches ? CollectionUtility.Initialize(GetBatchCount(), index => GetBatch(index)) : new Batch[0]);
            shaders = (HasShaders ? CollectionUtility.Initialize(GetShaderCount(), index => GetShader(index)) : new Shader[0]);
            materials = (HasMaterials ? CollectionUtility.Initialize(GetMaterialCount(), index => GetMaterial(index)) : new Material[0]);
            textures = (HasTextures ? CollectionUtility.Initialize(GetTextureCount(), index => GetTexture(index)) : new Texture[0]);
            positions = (HasPositions ? CollectionUtility.Initialize(GetPositionCount(), index => GetPosition(index)) : new Vector3[0]);
            normals = (HasNormals ? CollectionUtility.Initialize(GetNormalCount(), index => GetNormal(index)) : new Vector3[0]);
            texCoord0s = (HasTexCoord0s ? CollectionUtility.Initialize(GetTexCoord0Count(), index => GetTexCoord0(index)) : new Vector2[0]);
            texCoord1s = (HasTexCoord1s ? CollectionUtility.Initialize(GetTexCoord1Count(), index => GetTexCoord1(index)) : new Vector2[0]);

            // Load textures.
            glTextures = textures.Select(texture => texture.ToGLTexture()).ToArray();

            // Orient.
            Position = position;
            Rotation = rotation;
            Scale = scale;
        }
Ejemplo n.º 5
0
        public Bin(string fileName, Vector3 position, Vector3 rotation, Vector3 scale)
        {
            // header
            binaryReader = new ABinaryReader(Yay0.Decompress(fileName), Endianness.Big, Encoding.GetEncoding(932));
            unk1         = binaryReader.Read8();
            name         = binaryReader.ReadClampedString(11);
            offsets      = binaryReader.Read32s(21);

            // data
            graphObjects = (HasGraph ? GetGraphObjects(0) : new GraphObject[0]);
            batches      = (HasBatches ? CollectionUtility.Initialize(GetBatchCount(), index => GetBatch(index)) : new Batch[0]);
            shaders      = (HasShaders ? CollectionUtility.Initialize(GetShaderCount(), index => GetShader(index)) : new Shader[0]);
            materials    = (HasMaterials ? CollectionUtility.Initialize(GetMaterialCount(), index => GetMaterial(index)) : new Material[0]);
            textures     = (HasTextures ? CollectionUtility.Initialize(GetTextureCount(), index => GetTexture(index)) : new Texture[0]);
            positions    = (HasPositions ? CollectionUtility.Initialize(GetPositionCount(), index => GetPosition(index)) : new Vector3[0]);
            normals      = (HasNormals ? CollectionUtility.Initialize(GetNormalCount(), index => GetNormal(index)) : new Vector3[0]);
            texCoord0s   = (HasTexCoord0s ? CollectionUtility.Initialize(GetTexCoord0Count(), index => GetTexCoord0(index)) : new Vector2[0]);
            texCoord1s   = (HasTexCoord1s ? CollectionUtility.Initialize(GetTexCoord1Count(), index => GetTexCoord1(index)) : new Vector2[0]);

            // Load textures.
            glTextures = textures.Select(texture => texture.ToGLTexture()).ToArray();

            // Orient.
            Position = position;
            Rotation = rotation;
            Scale    = scale;
        }
Ejemplo n.º 6
0
        // Token: 0x06000006 RID: 6 RVA: 0x00002090 File Offset: 0x00000290
        internal static MIDIEvent FromStream(Stream stream)
        {
            ABinaryReader abinaryReader = new ABinaryReader(stream, Endianness.Big);
            ulong         num           = abinaryReader.ReadUIntVar();
            byte          statusByte    = abinaryReader.Read8();

            return(MIDIEvent.FromStream(abinaryReader, num, statusByte));
        }
Ejemplo n.º 7
0
 // Token: 0x0600023B RID: 571 RVA: 0x000070FE File Offset: 0x000052FE
 public sfModList(ABinaryReader binaryReader)
 {
     this.sfModSrcOper    = binaryReader.Read16();
     this.sfModDestOper   = binaryReader.Read16();
     this.modAmount       = binaryReader.ReadS16();
     this.sfModAmtSrcOper = binaryReader.Read16();
     this.sfModTransOper  = (SFTransform)binaryReader.Read16();
 }
Ejemplo n.º 8
0
        }                     // see CreateInverse

        public Texture(ABinaryReader binaryReader)
        {
            Width  = binaryReader.Read16();
            Height = binaryReader.Read16();
            Format = (TextureFormat)binaryReader.Read8();
            Unk1   = binaryReader.Read8();

            if (binaryReader.Read16() != 0)
            {
                throw new Exception("Texture.unk4 != 0");
            }

            uint offset = binaryReader.Read32();

            data = new Color[Width * Height];

            binaryReader.Goto(offset);

            switch (Format)
            {
            case TextureFormat.I4:
                ReadI4(binaryReader);
                break;

            case TextureFormat.I8:
                ReadI8(binaryReader);
                break;

            case TextureFormat.IA4:
                ReadIA4(binaryReader);
                break;

            case TextureFormat.IA8:
                ReadIA8(binaryReader);
                break;

            case TextureFormat.RGB565:
                ReadRGB565(binaryReader);
                break;

            case TextureFormat.RGB5A3:
                ReadRGB5A3(binaryReader);
                break;

            case TextureFormat.RGBA8:
                ReadRGB8(binaryReader);
                break;

            case TextureFormat.CMP:
                ReadCMP(binaryReader);
                break;

            default:
                throw new NotImplementedException(String.Format("Encountered an indexed texture Format {0}, which aren't implemented.", Format));
            }

            binaryReader.Back();
        }
Ejemplo n.º 9
0
 // Token: 0x06000241 RID: 577 RVA: 0x00007240 File Offset: 0x00005440
 public sfPresetHeader(ABinaryReader binaryReader)
 {
     this.achPresetName = binaryReader.ReadClampedString(20);
     this.wPreset       = binaryReader.Read16();
     this.wBank         = binaryReader.Read16();
     this.wPresetBagNdx = binaryReader.Read16();
     this.dwLibrary     = binaryReader.Read32();
     this.dwGenre       = binaryReader.Read32();
     this.dwMorphology  = binaryReader.Read32();
 }
Ejemplo n.º 10
0
        public uint     unk6;     // zeroes

        public Material(ABinaryReader binaryReader)
        {
            textureIndex = binaryReader.ReadS16();
            unk1         = binaryReader.ReadS16();
            wrapS        = (WrapMode)binaryReader.Read8();
            wrapT        = (WrapMode)binaryReader.Read8();
            unk3         = binaryReader.Read16();
            unk4         = binaryReader.Read32();
            unk5         = binaryReader.Read32();
            unk6         = binaryReader.Read32();
        }
Ejemplo n.º 11
0
        public GraphObject(ABinaryReader binaryReader)
        {
            Visible     = true;
            ParentIndex = binaryReader.ReadS16();
            ChildIndex  = binaryReader.ReadS16();
            NextIndex   = binaryReader.ReadS16();
            PrevIndex   = binaryReader.ReadS16();

            if (binaryReader.Read8() != 0)
            {
#if AROOKAS_DEMOLISHER_CHECKPADDING
                throw new Exception(String.Format("GraphObject padding != 0 at 0x{0:X8}.", binaryReader.Stream.Position));
#endif
            }

            RenderFlags = (GraphObjectRenderFlags)binaryReader.Read8();

            if (binaryReader.Read16() != 0)
            {
#if AROOKAS_DEMOLISHER_CHECKPADDING
                throw new Exception(String.Format("GraphObject padding != 0 at 0x{0:X8}.", binaryReader.Stream.Position));
#endif
            }

            Scale       = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
            Rotation    = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
            Position    = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
            BoundingBox = new BoundingBox(binaryReader.ReadVector3D().ToVector3(), binaryReader.ReadVector3D().ToVector3());
            unk3        = binaryReader.ReadSingle();

            int partCount = binaryReader.ReadS16();

            if (binaryReader.Read16() != 0)
            {
#if AROOKAS_DEMOLISHER_CHECKPADDING
                throw new Exception(String.Format("GraphObject padding != 0 at 0x{0:X8}.", binaryReader.Stream.Position));
#endif
            }

            int partOffset = binaryReader.ReadS32();

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

            binaryReader.Goto(partOffset);
            parts = CollectionHelper.Initialize <Part>(partCount, () => new Part(binaryReader));
            binaryReader.Back();
        }
Ejemplo n.º 12
0
 // Token: 0x0600023D RID: 573 RVA: 0x00007168 File Offset: 0x00005368
 public sfSample(ABinaryReader binaryReader)
 {
     this.achSampleName = binaryReader.ReadClampedString(20);
     this.dwStart       = binaryReader.Read32();
     this.dwEnd         = binaryReader.Read32();
     this.dwStartLoop   = binaryReader.Read32();
     this.dwEndLoop     = binaryReader.Read32();
     this.dwSampleRate  = binaryReader.Read32();
     this.byOriginalKey = binaryReader.Read8();
     this.chCorrect     = binaryReader.ReadS8();
     this.wSampleLink   = binaryReader.Read16();
     this.sfSampleType  = (SFSampleLink)binaryReader.Read16();
 }
Ejemplo n.º 13
0
        // stupid f*****g C#
        public Shader(ABinaryReader binaryReader)
            : this()
        {
            unk1 = binaryReader.Read24();
            Tint = Color.FromRGBA8(binaryReader.Read32());
            unk2 = binaryReader.Read8();
            MaterialIndex = binaryReader.ReadS16s(8);
            unk3 = binaryReader.ReadS16s(8);

            if (unk3[0] != 0 || unk3[1] != -1)
            {
                throw new System.Exception("shader unk3!!");
            }
        }
Ejemplo n.º 14
0
        public Shader(ABinaryReader binaryReader)
            : this()             // stupid f*****g C#
        {
            unk1          = binaryReader.Read24();
            Tint          = Color.FromRGBA8(binaryReader.Read32());
            unk2          = binaryReader.Read8();
            MaterialIndex = binaryReader.ReadS16s(8);
            unk3          = binaryReader.ReadS16s(8);

            if (unk3[0] != 0 || unk3[1] != -1)
            {
                throw new System.Exception("shader unk3!!");
            }
        }
Ejemplo n.º 15
0
 void ReadRGB565(ABinaryReader binaryReader)
 {
     for (int y = 0; y < Height; y += 4)
     {
         for (int x = 0; x < Width; x += 4)
         {
             for (int by = 0; by < 4 && y + by < Height; by++)
             {
                 for (int bx = 0; bx < 4 && x + bx < Width; bx++)
                 {
                     data[Width * (y + by) + (x + bx)] = Color.FromRGB565(binaryReader.Read16());
                 }
             }
         }
     }
 }
Ejemplo n.º 16
0
        // Token: 0x06000007 RID: 7 RVA: 0x000020BC File Offset: 0x000002BC
        internal static MIDIEvent FromStream(Stream stream, ChannelEventType eventType, int channelNumber)
        {
            if (!eventType.IsDefined <ChannelEventType>())
            {
                throw new ArgumentOutOfRangeException("eventType", eventType, "The specified ChannelEventType was not a defined value.");
            }
            if (channelNumber < 0 || channelNumber > 15)
            {
                throw new ArgumentOutOfRangeException("channelNumber", channelNumber, "The specified channel number was negative or greater than 15.");
            }
            ABinaryReader abinaryReader = new ABinaryReader(stream, Endianness.Big);
            ulong         num           = abinaryReader.ReadUIntVar();
            byte          statusByte    = (byte)((int)eventType | channelNumber);

            return(MIDIEvent.FromStream(abinaryReader, num, statusByte));
        }
Ejemplo n.º 17
0
 void ReadIA8(ABinaryReader binaryReader)
 {
     for (int y = 0; y < Height; y += 4)
     {
         for (int x = 0; x < Width; x += 4)
         {
             for (int by = 0; by < 4 && y + by < Height; by++)
             {
                 for (int bx = 0; bx < 4 && x + bx < Width; bx++)
                 {
                     data[Width * (y + by) + (x + bx)] = new Color(binaryReader.Read8(), binaryReader.Read8());
                 }
             }
         }
     }
 }
Ejemplo n.º 18
0
        public static bool IsCompressed(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("bytes");
            }

            using (ABinaryReader binaryReader = new ABinaryReader(File.OpenRead(fileName), Endianness.Big, Encoding.GetEncoding(932)))
            {
                if (binaryReader.Length < 0x10)
                {
                    return(false);
                }

                return(binaryReader.Read32() == Identifier);
            }
        }
Ejemplo n.º 19
0
 void ReadIA4(ABinaryReader binaryReader)
 {
     for (int y = 0; y < Height; y += 4)
     {
         for (int x = 0; x < Width; x += 4)
         {
             for (int by = 0; by < 4 && y + by < Height; by++)
             {
                 for (int bx = 0; bx < 4 && x + bx < Width; bx++)
                 {
                     byte ia4 = binaryReader.Read8();
                     data[Width * (y + by) + (x + bx)] = new Color(Lookup4Bit[(ia4 >> 4) & 0xF], Lookup4Bit[ia4 & 0xF]);
                 }
             }
         }
     }
 }
Ejemplo n.º 20
0
        public Vertex(ABinaryReader binaryReader, bool useNBT, int uvCount, BatchAttributes attributes)
            : this()             // stupid f*****g C#
        {
            MatrixIndex   = null;
            PositionIndex = null;
            NormalIndex   = null;
            BinormalIndex = null;
            TangentIndex  = null;
            ColorIndex    = new short?[2];
            UVIndex       = new short?[8];

            if (attributes.HasFlag(BatchAttributes.Position))
            {
                PositionIndex = binaryReader.ReadS16();
            }

            if (attributes.HasFlag(BatchAttributes.Normal))
            {
                NormalIndex = binaryReader.ReadS16();

                if (useNBT)
                {
                    BinormalIndex = binaryReader.ReadS16();
                    TangentIndex  = binaryReader.ReadS16();
                }
            }

            if (attributes.HasFlag(BatchAttributes.Color0))
            {
                ColorIndex[0] = binaryReader.ReadS16();
            }

            if (attributes.HasFlag(BatchAttributes.Color1))
            {
                ColorIndex[1] = binaryReader.ReadS16();
            }

            for (int texCoord = 0; texCoord < uvCount; texCoord++)
            {
                if (attributes.HasFlag((BatchAttributes)(1 << (13 + texCoord))))
                {
                    UVIndex[texCoord] = binaryReader.ReadS16();
                }
            }
        }
Ejemplo n.º 21
0
        // stupid f*****g C#
        public Vertex(ABinaryReader binaryReader, bool useNBT, int uvCount, BatchAttributes attributes)
            : this()
        {
            MatrixIndex = null;
            PositionIndex = null;
            NormalIndex = null;
            BinormalIndex = null;
            TangentIndex = null;
            ColorIndex = new short?[2];
            UVIndex = new short?[8];

            if (attributes.HasFlag(BatchAttributes.Position))
            {
                PositionIndex = binaryReader.ReadS16();
            }

            if (attributes.HasFlag(BatchAttributes.Normal))
            {
                NormalIndex = binaryReader.ReadS16();

                if (useNBT)
                {
                    BinormalIndex = binaryReader.ReadS16();
                    TangentIndex = binaryReader.ReadS16();
                }
            }

            if (attributes.HasFlag(BatchAttributes.Color0))
            {
                ColorIndex[0] = binaryReader.ReadS16();
            }

            if (attributes.HasFlag(BatchAttributes.Color1))
            {
                ColorIndex[1] = binaryReader.ReadS16();
            }

            for (int texCoord = 0; texCoord < uvCount; texCoord++)
            {
                if (attributes.HasFlag((BatchAttributes)(1 << (13 + texCoord))))
                {
                    UVIndex[texCoord] = binaryReader.ReadS16();
                }
            }
        }
Ejemplo n.º 22
0
 void ReadI4(ABinaryReader binaryReader)
 {
     for (int y = 0; y < Height; y += 8)
     {
         for (int x = 0; x < Width; x += 8)
         {
             for (int by = 0; by < 8 && y + by < Height; by++)
             {
                 for (int bx = 0; bx < 8 && x + bx < Width; bx += 2)
                 {
                     byte i4 = binaryReader.Read8();
                     data[Width * (y + by) + (x + bx)]     = new Color(Lookup4Bit[(i4 >> 4) & 0xF]);
                     data[Width * (y + by) + (x + bx + 1)] = new Color(Lookup4Bit[i4 & 0xF]);
                 }
             }
         }
     }
 }
Ejemplo n.º 23
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();
        }
Ejemplo n.º 24
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);
        }
Ejemplo n.º 25
0
 // Token: 0x0600023F RID: 575 RVA: 0x00007209 File Offset: 0x00005409
 public sfInst(ABinaryReader binaryReader)
 {
     this.achInstName = binaryReader.ReadClampedString(20);
     this.wInstBagNdx = binaryReader.Read16();
 }
Ejemplo n.º 26
0
 // Token: 0x0600023C RID: 572 RVA: 0x0000713C File Offset: 0x0000533C
 public sfGenList(ABinaryReader binaryReader)
 {
     this.sfGenOper         = (SFGenerator)binaryReader.Read16();
     this.genAmount         = default(genAmountType);
     this.genAmount.wAmount = binaryReader.Read16();
 }
Ejemplo n.º 27
0
        public static Stream Decompress(string fileName)
        {
            if (!IsCompressed(fileName))
            {
                return(File.OpenRead(fileName));
            }

            byte[] bytesToDecompress = File.ReadAllBytes(fileName);

            using (ABinaryReader codeReader = new ABinaryReader(bytesToDecompress.ToMemoryStream(false, true), Endianness.Big, Encoding.GetEncoding(932)),
                   countReader = new ABinaryReader(bytesToDecompress.ToMemoryStream(false, true), Endianness.Big, Encoding.GetEncoding(932)),
                   dataReader = new ABinaryReader(bytesToDecompress.ToMemoryStream(false, true), Endianness.Big, Encoding.GetEncoding(932)))
            {
                // Parse the header.
                string headerIdentifier = codeReader.ReadRawString(4);
                int    uncompressedSize = codeReader.ReadS32();
                countReader.Position = codeReader.ReadS32();
                dataReader.Position  = codeReader.ReadS32();

                // This is the buffer where we will put our decompressed data.
                // I would use an ABinaryWriter for this, but we need to read/write from the same buffer for the RLE parts.
                byte[] outputArray = new byte[uncompressedSize];

                int  outPosition     = 0;                       // Our position in the destination buffer.
                uint validBitsCount  = 0;                       // The number of valid bits left in the code byte.
                byte currentCodeByte = 0;                       // Our current code byte.

                // Begin decompression.
                while (outPosition < uncompressedSize)
                {
                    // If the current code byte is used, get a new one.
                    if (validBitsCount <= 0)
                    {
                        currentCodeByte = codeReader.Read8();
                        validBitsCount  = 8;
                    }

                    // If the next bit in the code byte is a 1, do a direct, 1:1 copy of the next data byte; otherwise, uncompress a chunk of data.
                    if ((currentCodeByte & 0x80) == 0x80)
                    {
                        outputArray[outPosition++] = dataReader.Read8();
                    }
                    else
                    {
                        // Read the count data.
                        ushort count = countReader.Read16();

                        // The last three nybbles represent the distance in the buffer to go back.
                        int distance = (count & 0xFFF);

                        // Calculate the position from which we start.
                        int startOffset = (outPosition - (distance + 1));

                        // The upper nybble of count; if zero, read a third byte and add 0x10.
                        int byteCount = ((count >> 12) & 0xF);

                        // If the upper nybble of the count is equal to zero, that means the number of bytes is too large for a nybble and is actually in the next whole byte.
                        // Add 0x10 to this byte's value, possibly to account for the original nybble. (How does Thakis figure this crap out?)
                        if (byteCount == 0)
                        {
                            byteCount = (dataReader.Read8() + 0x10);
                        }

                        // Take into consideration the two bytes for the count by adding two to the byte count.
                        byteCount += 2;

                        // Copy the run data.
                        Repeater.Repeat(byteCount, () => outputArray[outPosition++] = outputArray[startOffset++]);
                    }

                    // Get the next bit in the code byte.
                    currentCodeByte <<= 1;
                    validBitsCount--;
                }

                // Return the uncompressed data.
                return(outputArray.ToMemoryStream(false, true));
            }
        }
Ejemplo n.º 28
0
        public static bool IsCompressed(string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("bytes");
            }

            using (ABinaryReader binaryReader = new ABinaryReader(File.OpenRead(fileName), Endianness.Big, Encoding.GetEncoding(932)))
            {
                if (binaryReader.Length < 0x10)
                {
                    return false;
                }

                return binaryReader.Read32() == Identifier;
            }
        }
Ejemplo n.º 29
0
 public Primitive(ABinaryReader binaryReader, bool useNBT, int uvCount, BatchAttributes attributes)
 {
     Type     = (PrimitiveType)binaryReader.Read8();
     vertices = CollectionUtility.Initialize <Vertex>(binaryReader.Read16(), () => new Vertex(binaryReader, useNBT, uvCount, attributes));
 }
Ejemplo n.º 30
0
 public Part(ABinaryReader binaryReader)
     : this()             // stupid f*****g C#
 {
     ShaderIndex = binaryReader.ReadS16();
     BatchIndex  = binaryReader.ReadS16();
 }
Ejemplo n.º 31
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));
            }
        }
Ejemplo n.º 32
0
 // Token: 0x0600023E RID: 574 RVA: 0x000071EF File Offset: 0x000053EF
 public sfInstBag(ABinaryReader binaryReader)
 {
     this.wInstGenNdx = binaryReader.Read16();
     this.wInstModNdx = binaryReader.Read16();
 }
Ejemplo n.º 33
0
        public static Stream Decompress(string fileName)
        {
            if (!IsCompressed(fileName))
            {
                return File.OpenRead(fileName);
            }

            byte[] bytesToDecompress = File.ReadAllBytes(fileName);

            using (ABinaryReader codeReader = new ABinaryReader(bytesToDecompress.ToMemoryStream(false, true), Endianness.Big, Encoding.GetEncoding(932)),
                    countReader = new ABinaryReader(bytesToDecompress.ToMemoryStream(false, true), Endianness.Big, Encoding.GetEncoding(932)),
                    dataReader = new ABinaryReader(bytesToDecompress.ToMemoryStream(false, true), Endianness.Big, Encoding.GetEncoding(932)))
            {
                // Parse the header.
                string headerIdentifier = codeReader.ReadRawString(4);
                int uncompressedSize = codeReader.ReadS32();
                countReader.Position = codeReader.ReadS32();
                dataReader.Position = codeReader.ReadS32();

                // This is the buffer where we will put our decompressed data.
                // I would use an ABinaryWriter for this, but we need to read/write from the same buffer for the RLE parts.
                byte[] outputArray = new byte[uncompressedSize];

                int outPosition = 0;		// Our position in the destination buffer.
                uint validBitsCount = 0;	// The number of valid bits left in the code byte.
                byte currentCodeByte = 0;	// Our current code byte.

                // Begin decompression.
                while (outPosition < uncompressedSize)
                {
                    // If the current code byte is used, get a new one.
                    if (validBitsCount <= 0)
                    {
                        currentCodeByte = codeReader.Read8();
                        validBitsCount = 8;
                    }

                    // If the next bit in the code byte is a 1, do a direct, 1:1 copy of the next data byte; otherwise, uncompress a chunk of data.
                    if ((currentCodeByte & 0x80) == 0x80)
                    {
                        outputArray[outPosition++] = dataReader.Read8();
                    }
                    else
                    {
                        // Read the count data.
                        ushort count = countReader.Read16();

                        // The last three nybbles represent the distance in the buffer to go back.
                        int distance = (count & 0xFFF);

                        // Calculate the position from which we start.
                        int startOffset = (outPosition - (distance + 1));

                        // The upper nybble of count; if zero, read a third byte and add 0x10.
                        int byteCount = ((count >> 12) & 0xF);

                        // If the upper nybble of the count is equal to zero, that means the number of bytes is too large for a nybble and is actually in the next whole byte.
                        // Add 0x10 to this byte's value, possibly to account for the original nybble. (How does Thakis figure this crap out?)
                        if (byteCount == 0)
                        {
                            byteCount = (dataReader.Read8() + 0x10);
                        }

                        // Take into consideration the two bytes for the count by adding two to the byte count.
                        byteCount += 2;

                        // Copy the run data.
                        Repeater.Repeat(byteCount, () => outputArray[outPosition++] = outputArray[startOffset++]);
                    }

                    // Get the next bit in the code byte.
                    currentCodeByte <<= 1;
                    validBitsCount--;
                }

                // Return the uncompressed data.
                return outputArray.ToMemoryStream(false, true);
            }
        }
Ejemplo n.º 34
0
 // Token: 0x06000240 RID: 576 RVA: 0x00007225 File Offset: 0x00005425
 public sfPresetBag(ABinaryReader binaryReader)
 {
     this.wGenNdx = binaryReader.Read16();
     this.wModNdx = binaryReader.Read16();
 }