ReadInt16() public method

public ReadInt16 ( ) : short
return short
Example #1
0
 public void LoadFromStream(BinaryReader reader)
 {
     this.First = reader.ReadInt16();
       this.Second = reader.ReadInt16();
       this.UseLine = reader.ReadInt16();
       this.Third = reader.ReadInt16();
 }
        //public ushort MaxAudioLevel;

        private static WaveProcessor WaveHeaderIN(char Digit)
        {

            String Path = HttpContext.Current.Server.MapPath(String.Format("~/Epayment/DigitVoice/{0}.WAV", Digit));
            FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read);

            BinaryReader br = new BinaryReader(fs);
            try
            {
                WaveProcessor Header = new WaveProcessor {Length = (int) fs.Length - 8};

                fs.Position = 22;

                Header.Channels = br.ReadInt16(); //1
                fs.Position = 24;

                Header.SampleRate = br.ReadInt32(); //8000
                fs.Position = 34;

                Header.BitsPerSample = br.ReadInt16(); //16

                Header.DataLength = (int)fs.Length - 44;
                byte[] arrfile = new byte[fs.Length - 44];
                fs.Position = 44;
                fs.Read(arrfile, 0, arrfile.Length);
                return Header;

            }
            finally
            {
                br.Close();
                fs.Close();
            }

        }
Example #3
0
        private ushort usTotalLength; //Шестнадцать битов для общей длины датаграммы (заголовок + сообщение)

        #endregion Fields

        #region Constructors

        public IPHeader(byte[] byBuffer, int nReceived)
        {
            try
            {
                MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived);
                BinaryReader binaryReader = new BinaryReader(memoryStream);

                byVersionAndHeaderLength = binaryReader.ReadByte();
                byDifferentiatedServices = binaryReader.ReadByte();
                usTotalLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                usIdentification = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                usFlagsAndOffset = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                byTTL = binaryReader.ReadByte();
                byProtocol = binaryReader.ReadByte();
                sChecksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                uiSourceIPAddress = (uint)(binaryReader.ReadInt32());
                uiDestinationIPAddress = (uint)(binaryReader.ReadInt32());

                byHeaderLength = byVersionAndHeaderLength;
                byHeaderLength <<= 4;
                byHeaderLength >>= 4;
                byHeaderLength *= 4;

                Array.Copy(byBuffer, byHeaderLength, byIPData, 0, usTotalLength - byHeaderLength);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Example #4
0
 public UDPHeader(byte[] byBuffer, int nReceived)
 {
     try
     {
         using (var memoryStream = new MemoryStream(byBuffer, 0, nReceived))
         {
             using (var binaryReader = new BinaryReader(memoryStream))
             {
                 _sourcePort = (ushort) IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                 _destinationPort = (ushort) IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                 _length = (ushort) IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                 _checksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                 var tempData = new byte[nReceived - 8];
                 Array.Copy(byBuffer, 8, tempData, 0, nReceived - 8);
                 foreach (var b in tempData)
                 {
                     _data.Add(b);
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
        /// <summary>
        /// The read.
        /// </summary>
        /// <param name="client">
        /// </param>
        /// <param name="packet">
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            LogUtil.Debug(DebugInfoDetail.Network, "\r\nReceived:\r\n" + HexOutput.Output(packet));

            MemoryStream m_stream = new MemoryStream(packet);
            BinaryReader m_reader = new BinaryReader(m_stream);

            // now we should do password check and then send OK or Error
            // sending OK now
            m_stream.Position = 8;

            short userNameLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16());
            string userName = Encoding.ASCII.GetString(m_reader.ReadBytes(userNameLength));
            short loginKeyLength = IPAddress.NetworkToHostOrder(m_reader.ReadInt16());
            string loginKey = Encoding.ASCII.GetString(m_reader.ReadBytes(loginKeyLength));

            LoginEncryption loginEncryption = new LoginEncryption();

            if (loginEncryption.IsValidLogin(loginKey, client.ServerSalt, userName))
            {
                client.IsBot = true;
                byte[] chars = AccountCharacterList.Create(userName);
                LogUtil.Debug(DebugInfoDetail.Network, "\r\nReceived:\r\n" + HexOutput.Output(chars));

                client.Send(chars);
            }
            else
            {
                byte[] loginerr = LoginError.Create();
                client.Send(loginerr);
                client.Server.DisconnectClient(client);
            }
        }
        // As found in .DAT archives (RESOURCE.DAT, IO.DAT)
        public void Load(string destinationDirectory, string baseName, BinaryReader binaryReader)
        {
            xOffset = binaryReader.ReadInt16();
            yOffset = binaryReader.ReadInt16();
            binaryReader.BaseStream.Seek(4, SeekOrigin.Current);
            width = binaryReader.ReadUInt16();
            height = binaryReader.ReadUInt16();
            binaryReader.BaseStream.Seek(2, SeekOrigin.Current);
            uint length = binaryReader.ReadUInt32();

            var imageOffset = binaryReader.BaseStream.Position;

            var rowDataOffsets = new ushort[height];
            for (int i = 0; i < height; ++i) {
                rowDataOffsets[i] = binaryReader.ReadUInt16();
            }

            var bmp = new Bmp(width, height);
            var imageData = binaryReader.ReadBytes((int)length - 2*height);

            ReadImage(imageData, rowDataOffsets, false, bmp.Data);

            Debug.Assert(binaryReader.BaseStream.Position - imageOffset == length);
            bmp.Save(Path.Combine(destinationDirectory, baseName), ImageFormat);
            Bmp.SaveOffsets(baseName, xOffset, yOffset);
        }
Example #7
0
        static ItemBounds()
        {
            m_Bounds = new Rectangle2D[TileData.ItemTable.Length];

            if (File.Exists("Data/Binary/Bounds.bin"))
            {
                using (FileStream fs = new FileStream("Data/Binary/Bounds.bin", FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader bin = new BinaryReader(fs);

                    int count = Math.Min(m_Bounds.Length, (int)(fs.Length / 8));

                    for (int i = 0; i < count; ++i)
                    {
                        int xMin = bin.ReadInt16();
                        int yMin = bin.ReadInt16();
                        int xMax = bin.ReadInt16();
                        int yMax = bin.ReadInt16();

                        m_Bounds[i].Set(xMin, yMin, (xMax - xMin) + 1, (yMax - yMin) + 1);
                    }

                    bin.Close();
                }
            }
            else
            {
                Console.WriteLine("Warning: Data/Binary/Bounds.bin does not exist");
            }
        }
Example #8
0
        private static bool Version(BinaryReader reader)
        {
            reader.ReadInt16(); // minor
            var major = reader.ReadInt16();

            return major == 2 || major == 3;
        }
        public static void AddCliloc( string lang )
        {
            StringList list = StringList.GetList( lang );
            if ( list == null )
                list = StringList.AddLanguage( lang );

            string path = Core.FindDataFile( String.Format( "cliloc.{0}", lang ) );

            if ( path == null )
            {
                Console.WriteLine( "Warning: cliloc.{0} not found", lang );
                return;
            }

            using ( BinaryReader bin = new BinaryReader( new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ), Encoding.ASCII ) )
            {
                bin.ReadInt32();
                bin.ReadInt16();

                Encoding utf8 = Encoding.GetEncoding( "UTF-8", new EncoderReplacementFallback(""), new DecoderReplacementFallback("") );

                while ( bin.PeekChar() != -1 )
                {
                    int number = bin.ReadInt32();
                    bin.ReadByte(); //State in Cliloc
                    int length = bin.ReadInt16(); //Max of 65535 characters

                    StringEntry entry = new StringEntry( number, LState.Original, StringList.FormatArguments( utf8.GetString( bin.ReadBytes( length ) ) ) );

                    list.Table[number] = entry;
                }

                bin.Close();
            }
        }
Example #10
0
 public void load_chr(string path)
 {
     this.listBox.Items.Clear();
     BinaryReader binaryReader = new BinaryReader(File.Open(path, FileMode.Open), Encoding.GetEncoding("EUC-KR"));
     int num = (int)binaryReader.ReadInt16();
     for (int num2 = 0; num2 != num; num2++)
     {
         Mesh mesh = new Mesh();
         mesh.read(ref binaryReader);
         this.list_mesh.Add(mesh);
     }
     int num3 = (int)binaryReader.ReadInt16();
     for (int num2 = 0; num2 != num3; num2++)
     {
         Materiel materiel = new Materiel();
         materiel.read(ref binaryReader);
         this.list_materiel.Add(materiel);
     }
     int num4 = (int)binaryReader.ReadInt16();
     for (int num2 = 0; num2 != num4; num2++)
     {
         Effect effect = new Effect();
         effect.read(ref binaryReader);
         this.list_effect.Add(effect);
     }
     int num5 = (int)binaryReader.ReadInt16();
     for (int num2 = 0; num2 != num5; num2++)
     {
         Object @object = new Object();
         @object.read(ref binaryReader);
         this.list_object.Add(@object);
         this.listBox.Items.Add("Entry [" + num2 + "] : ");
     }
     binaryReader.Close();
 }
Example #11
0
 public void Load(string filePath, ClientType clientType)
 {
     this.Path = filePath;
     this.clientType = clientType;
     BinaryReader binaryReader = new BinaryReader(File.Open(filePath, FileMode.Open));
     short num = binaryReader.ReadInt16();
     this.listDDS = new List<TSI.DDS>((int)num);
     for (int i = 0; i < (int)num; i++)
     {
         TSI.DDS dDS = new TSI.DDS();
         dDS.Path = RoseFile.ReadSString(ref binaryReader);
         dDS.ColourKey = binaryReader.ReadInt32();
         this.listDDS.Add(dDS);
     }
     short num2 = binaryReader.ReadInt16();
     for (int i = 0; i < (int)num; i++)
     {
         short num3 = binaryReader.ReadInt16();
         this.listDDS[i].ListDDS_element = new List<TSI.DDS.DDSElement>((int)num3);
         for (int j = 0; j < (int)num3; j++)
         {
             TSI.DDS.DDSElement dDSElement = new TSI.DDS.DDSElement();
             dDSElement.OwnerId = binaryReader.ReadInt16();
             dDSElement.X = binaryReader.ReadInt32();
             dDSElement.Y = binaryReader.ReadInt32();
             dDSElement.Width = binaryReader.ReadInt32() - dDSElement.X;
             dDSElement.Height = binaryReader.ReadInt32() - dDSElement.Y;
             dDSElement.Color = binaryReader.ReadInt32();
             dDSElement.Name = RoseFile.ReadFString(ref binaryReader, 32);
             this.listDDS[i].ListDDS_element.Add(dDSElement);
         }
     }
     binaryReader.Close();
 }
Example #12
0
        public StringTable(string path)
        {
            m_Entries = new Dictionary<int, StringEntry>();

            using (BinaryReader bin = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                m_Header1 = bin.ReadInt32();
                m_Header2 = bin.ReadInt16();

                byte[] m_Buffer = new byte[1024];

                while (bin.BaseStream.Length != bin.BaseStream.Position)
                {
                    int number = bin.ReadInt32();
                    byte flag = bin.ReadByte();
                    int length = bin.ReadInt16();

                    if (length > m_Buffer.Length)
                        m_Buffer = new byte[(length + 1023) & ~1023];

                    bin.Read(m_Buffer, 0, length);
                    string text = Encoding.UTF8.GetString(m_Buffer, 0, length);

                    m_Entries.Add(number, new StringEntry(number, text, flag));
                }
            }
        }
Example #13
0
        public void Load(string destinationDirectory, string resourceName, BinaryReader binaryReader)
        {
            binaryReader.BaseStream.Seek(2, SeekOrigin.Current);
            uint length = binaryReader.ReadUInt32();
            byte[] imageData = binaryReader.ReadBytes((int)length);
            short xOffset = binaryReader.ReadInt16();
            short yOffset = binaryReader.ReadInt16();
            ushort width = binaryReader.ReadUInt16();
            ushort height = binaryReader.ReadUInt16();
            binaryReader.BaseStream.Seek(8, SeekOrigin.Current);

            var bmp = new Bmp(width, height);
            var colorData = bmp.Data;
            var palette = PaletteLoader.DefaultPalette;
            int index = 0;
            for (int y = 0; y < height; ++y) {
                for (int x = 0; x < width; ++x) {
                    colorData[y, x] = palette.Colors[imageData[index]];
                    ++index;
                }
            }

            bmp.Save(Path.Combine(destinationDirectory, resourceName), ImageFormat);
            Bmp.SaveOffsets(resourceName, xOffset, yOffset);
        }
Example #14
0
        static ItemBounds()
        {
            string path = Path.Combine(Path.Combine(Core.Config.ConfigDirectory, "Binary"), "Bounds.bin");

            if ( File.Exists( path ) )
            {
                using ( FileStream fs = new FileStream( path, FileMode.Open, FileAccess.Read, FileShare.Read ) )
                {
                    BinaryReader bin = new BinaryReader( fs );

                    m_Bounds = new Rectangle2D[0x4000];

                    for ( int i = 0; i < 0x4000; ++i )
                    {
                        int xMin = bin.ReadInt16();
                        int yMin = bin.ReadInt16();
                        int xMax = bin.ReadInt16();
                        int yMax = bin.ReadInt16();

                        m_Bounds[i].Set( xMin, yMin, (xMax - xMin) + 1, (yMax - yMin) + 1 );
                    }

                    bin.Close();
                }
            }
            else
            {
                log.Warn(String.Format("{0} does not exist", path));

                m_Bounds = new Rectangle2D[0x4000];
            }
        }
Example #15
0
 /// <summary>
 /// Initializes new instance.
 /// </summary>
 public TinyImage(Stream stream)
 {
     BinaryReader reader = new BinaryReader(stream, Encoding.ASCII);
     Width = reader.ReadInt16();
     Height = reader.ReadInt16();
     ImageData = reader.ReadBytes(Width*Height);
 }
Example #16
0
        public IPHeader(ArraySegment<byte> buffer)
        {

            using (var memoryStream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count))
            {
                using (var binaryReader = new BinaryReader(memoryStream))
                {
                    var versionAndHeaderLength = binaryReader.ReadByte();
                    var differentiatedServices = binaryReader.ReadByte();

                    DifferentiatedServices = (byte)(differentiatedServices >> 2);
                    CongestionNotification = (byte)(differentiatedServices & 0x03);

                    TotalLength = (ushort) IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                    Debug.Assert(TotalLength >= 20, "Invalid IP packet Total Lenght");
                    Identification = (ushort) IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                    _flagsAndOffset = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                    Ttl = binaryReader.ReadByte();

                    _protocol = binaryReader.ReadByte();

                    Checksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());

                    SourceAddress = new IPAddress(binaryReader.ReadUInt32());
                    DestinationAddress = new IPAddress(binaryReader.ReadUInt32());

                    HeaderLength = (versionAndHeaderLength & 0x0f) * 4;
                }
            }

            Raw = buffer;
            Data = new ArraySegment<byte>(buffer.Array, buffer.Offset + HeaderLength, MessageLength);
        }
Example #17
0
 public void Load(string Path)
 {
     this.path = Path;
     BinaryReader binaryReader = new BinaryReader(File.Open(Path, FileMode.Open));
     short num = binaryReader.ReadInt16();
     for (int i = 0; i < (int)num; i++)
     {
         ZSC.Mesh mesh = new ZSC.Mesh();
         mesh.read(ref binaryReader);
         this.listMesh.Add(mesh);
     }
     short num2 = binaryReader.ReadInt16();
     for (int i = 0; i < (int)num2; i++)
     {
         ZSC.Materiel materiel = new ZSC.Materiel();
         materiel.read(ref binaryReader);
         this.listMateriel.Add(materiel);
     }
     short num3 = binaryReader.ReadInt16();
     for (int i = 0; i < (int)num3; i++)
     {
         ZSC.Effect effect = new ZSC.Effect();
         effect.read(ref binaryReader);
         this.listEffect.Add(effect);
     }
     short num4 = binaryReader.ReadInt16();
     for (int i = 0; i < (int)num4; i++)
     {
         ZSC.Object @object = new ZSC.Object();
         @object.read(ref binaryReader);
         this.listObject.Add(@object);
     }
     binaryReader.Close();
 }
Example #18
0
        static Map LoadHeaderInternal( [NotNull] Stream stream ) {
            if( stream == null ) throw new ArgumentNullException( "stream" );
            BinaryReader bs = new BinaryReader( stream );

            // Read in the magic number
            if( bs.ReadByte() != 0xbe || bs.ReadByte() != 0xee || bs.ReadByte() != 0xef ) {
                throw new MapFormatException( "MapMinerCPP: Map header is incorrect." );
            }

            // Read in the map dimesions
            // Saved in big endian for who-knows-what reason.
            // XYZ(?)
            int width = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
            int height = IPAddress.NetworkToHostOrder( bs.ReadInt16() );
            int length = IPAddress.NetworkToHostOrder( bs.ReadInt16() );

            // ReSharper disable UseObjectOrCollectionInitializer
            Map map = new Map( null, width, length, height, false );
            // ReSharper restore UseObjectOrCollectionInitializer

            // Read in the spawn location
            // XYZ(?)
            map.Spawn = new Position {
                X = IPAddress.NetworkToHostOrder( bs.ReadInt16() ),
                Z = IPAddress.NetworkToHostOrder( bs.ReadInt16() ),
                Y = IPAddress.NetworkToHostOrder( bs.ReadInt16() ),
                R = bs.ReadByte(),
                L = bs.ReadByte()
            };

            // Skip over the block count, totally useless
            bs.ReadInt32();

            return map;
        }
Example #19
0
        public static Bitmap Open(string filePath)
        {
            using (var reader = new BinaryReader(new FileStream(filePath, FileMode.Open, FileAccess.Read)))
            {
                if(new string(reader.ReadChars(3)) != "PSF" || reader.ReadByte() != 1)
                    throw new Exception();

                var width = reader.ReadInt16();
                var height = reader.ReadInt16();
                var alphaMark = reader.ReadByte();

                var bmp = new Bitmap(width, height);
                var bmpData = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);
                try
                {
                    var scanPointer = bmpData.Scan0;
                    for (var y = 0; y < bmpData.Height; y++, scanPointer += bmpData.Stride)
                    {
                        var dataBuffer = reader.ReadBytes(bmpData.Width * 4);
                        Marshal.Copy(dataBuffer, 0, scanPointer, dataBuffer.Length);
                    }

                    return bmp;
                }
                finally
                {
                    bmp.UnlockBits(bmpData);
                }

            }
        }
Example #20
0
 public static Message ReadMessage(Stream input)
 {
     var buffer = new BinaryReader(input);
     Message msg = new Message();
     msg.ProtocolVersion = buffer.ReadByte();
     msg.MessageType = buffer.ReadByte();
     // read kv
     IDictionary<string, object> dict = new Dictionary<string, object>();
     short headerType = buffer.ReadInt16();
     while (headerType != MessageType.HeaderType.EndOfHeaders)
     {
         if (headerType == MessageType.HeaderType.Custom)
             dict.Add(ReadCountedString(buffer), ReadCustomValue(buffer));
         else if (headerType == MessageType.HeaderType.StatusCode)
             msg.StatusCode = buffer.ReadInt32();
         else if (headerType == MessageType.HeaderType.StatusPhrase)
             msg.StatusPhase = ReadCountedString(buffer);
         else if (headerType == MessageType.HeaderType.Flag)
             msg.Flag = buffer.ReadInt32();
         else if (headerType == MessageType.HeaderType.Token)
             msg.Token = ReadCountedString(buffer);
         headerType = buffer.ReadInt16();
     }
     msg.Content = dict;
     return msg;
 }
        public unsafe FlacMetadataStreamInfo(Stream stream, Int32 length, bool lastBlock)
            : base(FlacMetaDataType.StreamInfo, lastBlock, length)
        {
            //http://flac.sourceforge.net/format.html#metadata_block_streaminfo
            BinaryReader reader = new BinaryReader(stream, Encoding.ASCII);
            try
            {
                MinBlockSize = reader.ReadInt16();
                MaxBlockSize = reader.ReadInt16();
            }
            catch (IOException e)
            {
                throw new FlacException(e, FlacLayer.Metadata);
            }
            int bytesToRead = (240 / 8) - 16;
            byte[] buffer = reader.ReadBytes(bytesToRead);
            if (buffer.Length != bytesToRead)
                throw new FlacException(new EndOfStreamException("Could not read StreamInfo-content"), FlacLayer.Metadata);

            fixed (byte* b = buffer)
            {
                FlacBitReader bitreader = new FlacBitReader(b, 0);
                MinFrameSize = bitreader.ReadBits(24);
                MaxFrameSize = bitreader.ReadBits(24);
                SampleRate = (int)bitreader.ReadBits(20);
                Channels = 1 + (int)bitreader.ReadBits(3);
                BitsPerSample = 1 + (int)bitreader.ReadBits(5);
                TotalSamples = (long)bitreader.ReadBits64(36);
                MD5 = new String(reader.ReadChars(16));
            }
        }
Example #22
0
 public void ReadFromStream(Stream stream)
 {
     BinaryReader br = new BinaryReader(stream);
     SamplesPerBlock = br.ReadInt16();
     CoefficientsCount = br.ReadInt16();
     Coefficients = stream.ReadContent<AdPcmCoefficientSet>(CoefficientsCount);
 }
Example #23
0
 public override void Deserialize(BinaryReader reader)
 {
     base.Deserialize(reader);
     Interaction = reader.ReadUInt16();
     CalleeID = reader.ReadInt16();
     Param0 = reader.ReadInt16();
 }
Example #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static DibSection GetDibData(Stream stream)
        {
            var data = new DibSection();

            var reader = new BinaryReader(stream);
            reader.BaseStream.Seek(0, SeekOrigin.Begin);
            if (reader.ReadByte() != 'B' || reader.ReadByte() != 'M')
            {
                throw new ArgumentException("Invalid bitmap stream.", "stream");
            }

            reader.BaseStream.Seek(10, SeekOrigin.Begin);
            var offBits = reader.ReadInt32();

            reader.ReadInt32(); // biSize

            data.Width = reader.ReadInt32();
            data.Height = reader.ReadInt32();

            reader.ReadInt16(); // biPlanes

            data.BitCount = reader.ReadInt16();

            reader.BaseStream.Seek(offBits, SeekOrigin.Begin);
            data.pixelsPerY = (((data.Width * (data.BitCount >> 3)) + 3) >> 2) << 2;
            data.data = reader.ReadBytes(data.pixelsPerY * data.Height);

            return data;
        }
Example #25
0
        public wavefile(FileStream file)
        {
            BinaryReader binRead = new BinaryReader(file);

            //head data
            ChunkID =  binRead.ReadChars(4);
            ChunkSize = binRead.ReadInt32();
            Format = binRead.ReadChars(4);
            Subchunk1ID = binRead.ReadChars(4);
            Subchunk1Size = binRead.ReadInt32();//in bytes
            AudioFormat = binRead.ReadInt16();
            NumChannels = binRead.ReadInt16();
            SampleRate = binRead.ReadInt32();//samples per second?
            ByteRate = binRead.ReadInt32();
            BlockAlign = binRead.ReadInt16();
            BitsPerSample = binRead.ReadInt16();
            Subchunk2ID = binRead.ReadChars(4);
            Subchunk2Size = binRead.ReadInt32();//in bytes

            int numSamples = Subchunk2Size / (BitsPerSample / 8);
            data = new byte[numSamples];
            wave = new float[numSamples];

            data = binRead.ReadBytes(numSamples);

            for (int i = 0; i < numSamples; i++)
            {
                wave[i] = ((float)data[i] - 128) / 128;
            }
        }
Example #26
0
        public static byte[] GetWaveData(BinaryReader file, ref WaveInfo waveInfo)
        {
            byte[] returnData;

            //Read the wave file header from the buffer. 

            waveInfo.ChunkID = file.ReadInt32();
            waveInfo.FileSize = file.ReadInt32();
            waveInfo.RiffType = file.ReadInt32();
            waveInfo.FormatID = file.ReadInt32();
            waveInfo.FormatSize = file.ReadInt32();
            waveInfo.FormatCode = file.ReadInt16();
            waveInfo.Channels = file.ReadInt16();
            waveInfo.SampleRate = file.ReadInt32();
            waveInfo.FormatAverageBps = file.ReadInt32();
            waveInfo.FormatBlockAlign = file.ReadInt16();
            waveInfo.BitDepth = file.ReadInt16();

            if (waveInfo.FormatSize == 18)
            {
                // Read any extra values
                waveInfo.FormatExtraSize = file.ReadInt16();
                file.ReadBytes(waveInfo.FormatExtraSize);
            }

            waveInfo.DataID = file.ReadInt32();
            waveInfo.DataSize = file.ReadInt32();


            // Store the audio data of the wave file to a byte array. 

            returnData = file.ReadBytes(waveInfo.DataSize);

            return returnData;
        }
Example #27
0
	private static bool ParseFileHeader(BinaryReader reader, out string filename)
	{
		filename = null;
		if (reader.BaseStream.Position < reader.BaseStream.Length)
		{
			int headerSignature = reader.ReadInt32();
			if (headerSignature == 67324752) //PKZIP
			{
				reader.BaseStream.Seek(14, SeekOrigin.Current); //ignore unneeded values
				int compressedSize = reader.ReadInt32();
				int unCompressedSize = reader.ReadInt32();
				short fileNameLenght = reader.ReadInt16();
				short extraFieldLenght = reader.ReadInt16();
				filename = new string(reader.ReadChars(fileNameLenght));
				if (string.IsNullOrEmpty(filename))
					return false;
				//Seek to the next file header
				reader.BaseStream.Seek(extraFieldLenght + compressedSize, SeekOrigin.Current);
				if (unCompressedSize == 0) //Directory or not supported. Skip it
					return ParseFileHeader(reader, out filename);
				else
					return true;
			}
		}
		return false;
	}
Example #28
0
        /// <summary>
        /// Parse an IDX file
        /// </summary>
        /// <param name="streamIdx">stream that contains IDX data</param>
        /// <param name="streamImg">stream that contains IMG data</param>
        public IDX(System.IO.Stream streamIdx, System.IO.Stream streamImg)
        {
            BinaryReader reader = new BinaryReader(streamIdx);

            // First 4 bytes are the entries count
            filesCount = reader.ReadInt32();
            idx = new FileIdx[filesCount];

            // Parse IDX file
            for (int i = 0; i < filesCount; i++)
            {
                idx[i].hash32 = reader.ReadInt32();
                idx[i].hash16 = reader.ReadInt16();
                idx[i].clength = reader.ReadInt16();
                idx[i].position = reader.ReadInt32();
                idx[i].length = reader.ReadInt32();

                idx[i].compressed = (idx[i].clength & 0x4000) != 0;
                idx[i].streamed = (idx[i].clength & 0x8000) != 0;
                idx[i].clength = (idx[i].clength & 0x3FFF) * 0x800 + 0x800;
                idx[i].position *= 0x800;
            }

            // Get the stream of IMG
            this.streamImg = streamImg;
        }
Example #29
0
        static Map LoadHeaderInternal( [NotNull] Stream stream ) {
            if( stream == null ) throw new ArgumentNullException( "stream" );
            BinaryReader reader = new BinaryReader( stream );

            // Read in the magic number
            if( reader.ReadUInt32() != Identifier ) {
                throw new MapFormatException();
            }

            // Read in the map dimesions
            int width = reader.ReadInt16();
            int length = reader.ReadInt16();
            int height = reader.ReadInt16();

            // ReSharper disable UseObjectOrCollectionInitializer
            Map map = new Map( null, width, length, height, false );
            // ReSharper restore UseObjectOrCollectionInitializer

            // Read in the spawn location
            map.Spawn = new Position {
                X = reader.ReadInt16(),
                Y = reader.ReadInt16(),
                Z = reader.ReadInt16(),
                R = reader.ReadByte(),
                L = reader.ReadByte()
            };

            return map;
        }
Example #30
0
 public IPHeader(byte[] byBuffer, int nReceived)
 {
     try
     {
         using (var memoryStream = new MemoryStream(byBuffer, 0, nReceived))
         {
             using (var binaryReader = new BinaryReader(memoryStream))
             {
                 _versionAndHeaderLength = binaryReader.ReadByte();
                 _differentiatedServices = binaryReader.ReadByte();
                 _totalLength = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                 _identification = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                 _flags = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                 _TTL = binaryReader.ReadByte();
                 _protocol = binaryReader.ReadByte();
                 _checksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16());
                 _sourceIPAddress = (uint)(binaryReader.ReadInt32());
                 _destinationIPAddress = (uint)(binaryReader.ReadInt32());
                 _headerLength = _versionAndHeaderLength;
                 _headerLength <<= 4;
                 _headerLength >>= 4;
                 _headerLength *= 4;
                 var tempData = new byte[_totalLength - _headerLength];
                 Array.Copy(byBuffer, _headerLength, tempData, 0, _totalLength - _headerLength);
                 foreach (var b in tempData)
                 {
                     _data.Add(b);
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }