Exemplo n.º 1
0
        public static void LoadDivisonInfo()
        {
            try
            {
                var breader = new System.IO.BinaryReader(reader.GetFileStream("divisioninfo.txt"));
                Data.ServerInfo.Locale = breader.ReadByte();
                byte divCount = breader.ReadByte();
                for (int i = 0; i < divCount; i++)
                {
                    List <string> gateways = new List <string>();

                    int    divLength = breader.ReadInt32();
                    string divName   = new string(breader.ReadChars(divLength));
                    breader.ReadByte(); //??

                    byte gatewayCount = breader.ReadByte();
                    for (int j = 0; j < gatewayCount; j++)
                    {
                        int    gatewayLength = breader.ReadInt32();
                        string gatewayIP     = new string(breader.ReadChars(gatewayLength));
                        breader.ReadByte(); //??

                        gateways.Add(gatewayIP);
                    }

                    Data.ServerInfo.LoginDivisons.Add(new DataInfo.Division(divName, gateways));
                }
            } catch (Exception ex)
            {
                throw new Exception("Error loading ServerInfo divisioninfo\n" + ex.Message + "\n" + ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        //----------ファイル入出力用メソッド------------
        //ファイル読み込み
        public bool Read_File(string filename)
        {
            System.IO.FileStream   read_file;
            System.IO.BinaryReader br;

            if (System.IO.File.Exists(filename))
            {
                using (read_file = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    using (br = new System.IO.BinaryReader(read_file))
                    {
                        riff_chunk_ID   = br.ReadChars(4);
                        riff_chunk_size = br.ReadUInt32();
                        riff_form_type  = br.ReadChars(4);
                        string ID   = new string(riff_chunk_ID);
                        string TYPE = new string(riff_form_type);
                        if (ID == "RIFF" && TYPE == "WAVE")
                        {
                            fmt_chunk_ID         = br.ReadChars(4);
                            fmt_chunk_size       = br.ReadUInt32();
                            fmt_wave_format_type = br.ReadUInt16();
                            fmt_channel          = br.ReadUInt16();
                            fmt_sample_per_sec   = br.ReadUInt32();
                            fmt_bytes_per_sec    = br.ReadUInt32();
                            fmt_block_size       = br.ReadUInt16();
                            fmt_bits_per_sample  = br.ReadUInt16();
                            data_chunk_ID        = br.ReadChars(4);
                            data_chunk_size      = br.ReadUInt32();
                            Data_length          = data_chunk_size / fmt_block_size;
                            decimal tmp = fmt_sample_per_sec;
                            SampleT = 1 / tmp;
                            if (Read_Data(br))
                            {
                                Read_success = true;
                                //File_Information();
                                return(true);
                            }
                            else
                            {
                                Read_success = false;
                                MessageBox.Show("このファイルは読み込めません");
                                return(false);
                            }
                        }
                        else
                        {
                            Read_success = false;
                            MessageBox.Show("このファイルはWAVEフォーマットではありません。");
                            return(false);
                        }
                    }
                }
            }
            MessageBox.Show("ファイルが存在しません。");
            return(false);
        }
Exemplo n.º 3
0
        public AudioContent(System.IO.Stream inputStream, bool closeStream = true)
        {
            inputStream.Close();
            return;

            System.IO.BinaryReader r = new System.IO.BinaryReader(inputStream);
            if (r.ReadChars(4).ToString() != "RIFF")
            {
                throw new FormatException("No RIFF Magic header");
            }
            uint size = r.ReadUInt32() - 12;

            if (r.ReadChars(4).ToString() != "WAVE")
            {
                throw new FormatException("No Wave Content");
            }
            if (r.ReadChars(4).ToString() != "fmt ")
            {
                throw new FormatException("Missing format part");
            }
            uint formatLength = r.ReadUInt32();

            size -= formatLength;
            Format formatTag      = (Format)r.ReadUInt16();
            ushort channels       = r.ReadUInt16();
            uint   samplesPerSec  = r.ReadUInt32();
            uint   avgBytesPerSec = r.ReadUInt32();
            ushort blockAlign     = r.ReadUInt16();

            int frameSize = 0;

            switch (formatTag)
            {
            case Format.PCM:
                ushort bitsPerSample = r.ReadUInt16();
                frameSize = channels * ((bitsPerSample + 7) / 8);
                break;

            default:
                throw new FormatException("Format '" + formatTag.ToString() + "' not supported!");
            }
            while (size > 0)
            {
                if (r.ReadChars(4).ToString() != "data")
                {
                    throw new FormatException("Missing format part");
                }

                uint dataLength = r.ReadUInt32();
                size -= 8 + dataLength;
            }
        }
Exemplo n.º 4
0
        public Control Show_Info(sFile file)
        {
            System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path));
            string ext = "";

            try { ext = new String(br.ReadChars(4)); }
            catch { }
            br.Close();

            if (file.name.ToUpper().EndsWith(".TGA"))
            {
                return(new TGA(pluginHost, file.path).Show_Info());
            }
            else if (file.name.ToUpper().EndsWith(".JPG"))
            {
                return(new JPG(pluginHost, file.path).Show_Info());
            }
            else if (file.name.ToUpper().EndsWith(".PNG"))
            {
                return(new PNG(pluginHost, file.path).Show_Info());
            }
            else if (file.name.ToUpper().EndsWith(".WAV") || ext == "RIFF")
            {
                return(new WAV(pluginHost, file.path).Show_Info());
            }
            else if (file.name.ToUpper().EndsWith(".BMP"))
            {
                return(new BMP(pluginHost, file.path).Show_Info());
            }

            return(new Control());
        }
Exemplo n.º 5
0
        public void Populate(int iOffset, bool useMemoryStream)
        {
            this.isNulledOutReflexive = false;
            System.IO.BinaryReader BR = new System.IO.BinaryReader(map.SelectedMeta.MS);
            //set offsets
            BR.BaseStream.Position = iOffset + this.chunkOffset;
            this.offsetInMap = iOffset + this.chunkOffset;
            // If we need to read / save tag info directly to file...
            if (!useMemoryStream)
            {
                map.OpenMap(MapTypes.Internal);
                BR = map.BR;
                BR.BaseStream.Position = this.offsetInMap;
            }
            else
                this.offsetInMap += map.SelectedMeta.offset;

            if (this.entUnicode)
            {
                this.value = Encoding.Unicode.GetString(BR.ReadBytes(this.length));
            }
            else
            {
                this.value = new String(BR.ReadChars(this.length));
            }
            this.value = this.value.TrimEnd('\0');
            //this.RemoveNullCharFromValue();
            this.textBox1.Text = this.value;
            this.textBox1.Size = this.textBox1.PreferredSize;
            this.textBox1.Width += 5;

            // ...and then close the file once we are done!
            if (!useMemoryStream)
                map.CloseMap();
        }
Exemplo n.º 6
0
        private static string ReadString(System.IO.BinaryReader reader)
        {
            var size   = reader.ReadUInt32();
            var result = reader.ReadChars((int)size);

            return(new string(result));
        }
Exemplo n.º 7
0
        protected override void DataUpdate()
        {
            System.IO.BinaryReader BSReader = new System.IO.BinaryReader(ByteStream);
            ByteStream.Position = 12;
            int Len = BSReader.ReadInt32();

            Name = new string(BSReader.ReadChars(Len - 1));
            ByteStream.Position = ByteStream.Length - 8;
            Texture             = BSReader.ReadUInt32();
            LastNum             = BSReader.ReadUInt32();
        }
Exemplo n.º 8
0
        public static ValueTable Deserialize(System.IO.BinaryReader reader)
        {
            // Read the File Header with version
            var headerBuffer = reader.ReadChars(4);

            if (headerBuffer[0] != 'B' ||
                headerBuffer[1] != 'V' ||
                headerBuffer[2] != 'T' ||
                headerBuffer[3] != '\0')
            {
                throw new InvalidOperationException("Invalid Value Table file header");
            }

            var fileVersion = reader.ReadUInt32();

            if (fileVersion != FileVersion)
            {
                throw new InvalidOperationException("Value Table file version does not match expected");
            }

            // Read the root table
            headerBuffer = reader.ReadChars(4);
            if (headerBuffer[0] != 'T' ||
                headerBuffer[1] != 'B' ||
                headerBuffer[2] != 'L' ||
                headerBuffer[3] != '\0')
            {
                throw new InvalidOperationException("Invalid Value Table table header");
            }

            var rootTable = ReadValueTable(reader);

            if (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                var remaining = reader.BaseStream.Length - reader.BaseStream.Position;
                throw new InvalidOperationException($"Value Table file corrupted - Did not read the entire file {remaining}");
            }

            return(rootTable);
        }
Exemplo n.º 9
0
Arquivo: Main.cs Projeto: MetLob/tinke
        public System.Windows.Forms.Control Show_Info(sFile file)
        {
            System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path));
            string ext = new String(br.ReadChars(4));
            br.Close();

            if (ext == "NFTR" || ext == "RTFN")
            {
                return new FontControl(pluginHost, NFTR.Read(file, pluginHost.Get_Language()));
            }

            return new System.Windows.Forms.Control();
        }
Exemplo n.º 10
0
        public System.Windows.Forms.Control Show_Info(sFile file)
        {
            System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path));
            string ext = new String(br.ReadChars(4));

            br.Close();

            if (ext == "NFTR" || ext == "RTFN")
            {
                return(new FontControl(pluginHost, NFTR.Read(file, pluginHost.Get_Language())));
            }

            return(new System.Windows.Forms.Control());
        }
Exemplo n.º 11
0
 protected override void DataUpdate()
 {
     System.IO.BinaryReader BSReader = new System.IO.BinaryReader(ByteStream);
     ByteStream.Position = 0;
     InsideID            = BSReader.ReadUInt16();
     Mask = BSReader.ReadByte();
     Flag = BSReader.ReadByte();
     if (Flag == 0)
     {
         int len = BSReader.ReadInt32();
         Name = new string(BSReader.ReadChars(len));
     }
     ScriptArray = BSReader.ReadBytes((int)(ByteStream.Length - ByteStream.Position));
 }
Exemplo n.º 12
0
        /// <summary>
        /// Unserializes a BinaryStream into the Attributes of this Instance
        /// </summary>
        /// <param name="reader">The Stream that contains the FileData</param>
        protected override void Unserialize(System.IO.BinaryReader reader)
        {
            ///
            /// TODO: You have to put some real Code here, just delete the example
            ///

            reader.BaseStream.Seek(0x17, System.IO.SeekOrigin.Begin);
            char[] loaded = reader.ReadChars(10);
            data = "";
            foreach (char c in loaded)
            {
                data += c;
            }
        }
Exemplo n.º 13
0
        public void Load(System.IO.BinaryReader reader)
        {
            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC(reader.ReadChars(4));

            if (cc != this._fourCC)
            {
                throw new ApplicationException(this._fourCC.ToString() + " not found in stream");
            }

            this._size    = reader.ReadInt32();
            this._width   = reader.ReadInt32();
            this._height  = reader.ReadInt32();
            this._padding = reader.ReadInt32();
        }
Exemplo n.º 14
0
        public PrinterInfo(byte[] rBytes)
        {
            int i = 0;

            System.IO.MemoryStream ms = new System.IO.MemoryStream(rBytes);
            System.IO.BinaryReader br = new System.IO.BinaryReader(ms);

            bPrinterConnected = Convert.ToBoolean(br.ReadInt32());
            eModel            = br.ReadInt32();
            sModel            = br.ReadChars(32);
            ePrintheadtype    = br.ReadInt32();
            sPrinterSerial    = br.ReadChars(SERIAL_SIZE);
            sPrintheadSerial  = br.ReadChars(SERIAL_SIZE);
            sPCBSerial        = br.ReadChars(SERIAL_SIZE);

            byte[] sFV = new byte[SERIAL_SIZE];
            sFV = br.ReadBytes(SERIAL_SIZE);

            for (i = 0; i <= SERIAL_SIZE - 1; i += 2)
            {
                char tchar = (char)BitConverter.ToInt16(sFV, i);
                sFirmwareVersion[Convert.ToInt32(i / 2)] = tchar;
            }

            byte[] dummy = new byte[SERIAL_SIZE - sizeof(Int32)];
            dummy = br.ReadBytes(SERIAL_SIZE - sizeof(Int32));
            //  sPCBVersion = br.ReadChars(20);

            iES_Density          = br.ReadInt32();
            iHandFeed            = br.ReadInt32();
            iCardsPrinted        = br.ReadInt32();
            iCardsOnPrinthead    = br.ReadInt32();
            iDyePanelsPrinted    = br.ReadInt32();
            iCleansSinceShipped  = br.ReadInt32();
            iDyePanelsSinceClean = br.ReadInt32();
            iCardsSinceClean     = br.ReadInt32();
            iCardsBetweenCleans  = br.ReadInt32();

            iPrintHeadPosn  = br.ReadInt32();
            iImageStartPosn = br.ReadInt32();
            //is only returning 0 don't quite know why yet
            iImageEndPosn   = br.ReadInt32();
            iMajorError     = br.ReadInt32();
            iMinorError     = br.ReadInt32();
            sTagUID         = br.ReadChars(20);
            iShotsOnFilm    = br.ReadInt32();
            iShotsUsed      = br.ReadInt32();
            sDyeFilmType    = br.ReadChars(20);
            iColourLength   = br.ReadInt32();
            iResinLength    = br.ReadInt32();
            iOvercoatLength = br.ReadInt32();
            eDyeFlags       = br.ReadInt32();
            iCommandCode    = br.ReadInt32();
            iDOB            = br.ReadInt32();
            eDyeFilmManuf   = br.ReadInt32();
            eDyeFilmProg    = br.ReadInt32();
        }
Exemplo n.º 15
0
        static private List <STLTriangle> openBinary(string fileName)
        {
            UInt32             triCountBin = 0;
            List <STLTriangle> triangles   = new List <STLTriangle>();

            try
            {
                if (fileName != null && fileName != "" & System.IO.File.Exists(fileName))
                {
                    using (System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.Open(fileName, System.IO.FileMode.Open)))
                    {
                        br.BaseStream.Seek(0, System.IO.SeekOrigin.Begin);
                        char[] header   = new char[80];
                        UInt32 triIndex = 0;
                        header      = br.ReadChars(80);
                        triCountBin = br.ReadUInt32();

                        while (triIndex < triCountBin && br.BaseStream.Position < br.BaseStream.Length)
                        {
                            double  n1   = br.ReadSingle();
                            double  n2   = br.ReadSingle();
                            double  n3   = br.ReadSingle();
                            double  v1x  = br.ReadSingle();
                            double  v1y  = br.ReadSingle();
                            double  v1z  = br.ReadSingle();
                            double  v2x  = br.ReadSingle();
                            double  v2y  = br.ReadSingle();
                            double  v2z  = br.ReadSingle();
                            double  v3x  = br.ReadSingle();
                            double  v3y  = br.ReadSingle();
                            double  v3z  = br.ReadSingle();
                            UInt16  attr = br.ReadUInt16();
                            Vector3 norm = new Vector3(n1, n2, n3);
                            Vector3 p1   = new Vector3(v1x, v1y, v1z);
                            Vector3 p2   = new Vector3(v2x, v2y, v2z);
                            Vector3 p3   = new Vector3(v3x, v3y, v3z);
                            triangles.Add(new STLTriangle(p1, p2, p3, triIndex));
                            triIndex++;
                        }
                    }
                }
                return(triangles);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(triangles);
            }
        }
Exemplo n.º 16
0
        public void Load(System.IO.BinaryReader reader)
        {
            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC(reader.ReadChars(4));

            if (cc != this._fourCC)
            {
                throw new ApplicationException(this._fourCC.ToString() + " not found in stream");
            }

            this._size = reader.ReadInt32();
            cc         = new OEIShared.Utils.FourCC(reader.ReadChars(4));

            if (cc != this._compFourCC)
            {
                throw new ApplicationException(this._compFourCC.ToString() + " not found in stream");
            }

            this._sizeComp   = reader.ReadInt32();
            this._sizeDecomp = reader.ReadInt32();
            this._dataComp   = reader.ReadBytes(this._sizeComp);

            reader.BaseStream.Seek(0 - this._sizeComp, System.IO.SeekOrigin.Current);
            this._dataDecomp = new byte[this._sizeDecomp];
        }
Exemplo n.º 17
0
        internal HhMessageReply GetReply()
        {
            try
            {
                var    str      = host as System.Runtime.InteropServices.ComTypes.IStream;
                byte[] response = new byte[8];
                str.Read(response, (int)HhMessageHeader.FixedSize, IntPtr.Zero);
                System.IO.BinaryReader r = new System.IO.BinaryReader(new System.IO.MemoryStream(response));
                uint len = r.ReadUInt32();
                if (len == 0)
                {
                    return(null);
                }
                uint kind = r.ReadUInt32();
                switch (kind)
                {
                case GetPidMsgReplyId:
                    str.Read(response, 4, IntPtr.Zero);
                    return(new HhGetPidReply(BytesAsUInt32(response)));

                case StartRendererMsgReplyId:
                case StopRendererMsgReplyId:
                case SetPayloadMsgReplyId:
                case (uint)HhMessageId.SetParentHwndMsgReplyId:
                    str.Read(response, 4, IntPtr.Zero);
                    return(new HhResultReply(kind, BytesAsUInt32(response)));

                case ReadLogMsgReplyId:
                    response = new byte[len - 8];
                    str.Read(response, response.Length, IntPtr.Zero);
                    System.IO.BinaryReader logReader = new System.IO.BinaryReader(new System.IO.MemoryStream(response), Encoding.Unicode);
                    uint   charCount = logReader.ReadUInt32();   // text size.
                    string text      = new string(logReader.ReadChars((int)charCount));
                    return(new HhLogReply(text));

                default:
                    throw new InvalidOperationException("Unknown reply kind from host: " + kind);
                }
            }
            catch (Exception runError)
            {
                System.Diagnostics.Debug.WriteLine(runError);
                host = null;
                throw;
            }
        }
Exemplo n.º 18
0
        public void Load(System.IO.BinaryReader reader)
        {
            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC(reader.ReadChars(4));

            if (cc != this._fourCC)
            {
                throw new ApplicationException(this._fourCC.ToString() + " not found in stream");
            }

            this._size = reader.ReadInt32();
            long finalPosition = reader.BaseStream.Position + this._size;

            this._mapPart = OEIShared.Utils.CommonUtils.ConvertZeroTerminatedBytesToString(reader.ReadBytes(128)).TrimEnd('\0');

            this._ddsGroup = new DDSGroup(reader);

            for (int i = 0; i < 18; i++)
            {
                this._texVectors[i] = reader.ReadSingle();
            }

            this._vertexCount   = reader.ReadInt32();
            this._triangleCount = reader.ReadInt32();

            this._vertices = new Vertex[this._vertexCount];
            for (int i = 0; i < this._vertexCount; i++)
            {
                this._vertices[i] = new Vertex(reader);
            }

            this._triangles = new Triangle[this._triangleCount];
            for (int i = 0; i < this._triangleCount; i++)
            {
                this._triangles[i] = new Triangle(reader);
            }

            this._ddsGroup.Load(reader);
            this._ddsGroup.FirstVertex = this._vertices[0];

            this._unkownDataSize = (int)(finalPosition - reader.BaseStream.Position);
            if (this._unkownDataSize > 0)
            {
                this._unknownData = reader.ReadBytes(this._unkownDataSize);
            }
        }
Exemplo n.º 19
0
        public void Load(System.IO.BinaryReader reader)
        {
            this._unknownHeader = reader.ReadBytes(4);

            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC(reader.ReadChars(4));

            if (cc != this._fourCC)
            {
                throw new ApplicationException(
                          string.Format("{0} not found in stream.\nActual: ({1})\nStream Position: {2}",
                                        this._fourCC, cc.IntValue, reader.BaseStream.Position - 4));
            }

            this._unknown0    = reader.ReadInt32();
            this._unknown1    = reader.ReadInt32();
            this._width       = reader.ReadInt32();
            this._height      = reader.ReadInt32();
            this._unknown3    = reader.ReadBytes(108);
            this._textureData = reader.ReadBytes(this._width * this._height * 4);
        }
Exemplo n.º 20
0
Arquivo: Main.cs Projeto: MetLob/tinke
        public Control Show_Info(sFile file)
        {
            System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path));
            string ext = "";
            try { ext = new String(br.ReadChars(4)); }
            catch { }
            br.Close();

            if (file.name.ToUpper().EndsWith(".TGA"))
                return new TGA(pluginHost, file.path).Show_Info();
            else if (file.name.ToUpper().EndsWith(".JPG"))
                return new JPG(pluginHost, file.path).Show_Info();
            else if (file.name.ToUpper().EndsWith(".PNG"))
                return new PNG(pluginHost, file.path).Show_Info();
            else if (file.name.ToUpper().EndsWith(".WAV") || ext == "RIFF")
                return new WAV(pluginHost, file.path).Show_Info();
            else if (file.name.ToUpper().EndsWith(".BMP"))
                return new BMP(pluginHost, file.path).Show_Info();

            return new Control();
        }
Exemplo n.º 21
0
        public void Populate(int iOffset, bool useMemoryStream)
        {
            this.isNulledOutReflexive = false;
            System.IO.BinaryReader BR = new System.IO.BinaryReader(map.SelectedMeta.MS);
            //set offsets
            BR.BaseStream.Position = iOffset + this.chunkOffset;
            this.offsetInMap       = iOffset + this.chunkOffset;
            // If we need to read / save tag info directly to file...
            if (!useMemoryStream)
            {
                map.OpenMap(MapTypes.Internal);
                BR = map.BR;
                BR.BaseStream.Position = this.offsetInMap;
            }
            else
            {
                this.offsetInMap += map.SelectedMeta.offset;
            }

            if (this.entUnicode)
            {
                this.value = Encoding.Unicode.GetString(BR.ReadBytes(this.length));
            }
            else
            {
                this.value = new String(BR.ReadChars(this.length));
            }
            this.value = this.value.TrimEnd('\0');
            //this.RemoveNullCharFromValue();
            this.textBox1.Text   = this.value;
            this.textBox1.Size   = this.textBox1.PreferredSize;
            this.textBox1.Width += 5;

            // ...and then close the file once we are done!
            if (!useMemoryStream)
            {
                map.CloseMap();
            }
        }
Exemplo n.º 22
0
                bool GetPointCacheSourceStatistic(string path, ref string name, ref int vertCount, ref int framesCount, ref string message)
                {
                    string extension = System.IO.Path.GetExtension(path);

                    if (extension == ".obj")
                    {
                        MeshSequenceInfo msi = new MeshSequenceInfo(path, MeshSequenceInfo.SortModeEnum.ByNumber);
                        name        = msi.SequenceName;
                        framesCount = msi.infos.Length;
                        vertCount   = 0;
                        ObjData.GetObjInfo(path, ref vertCount);
                        return(true);
                    }
                    else
                    {
                        name = (new System.IO.FileInfo(path)).Name;
                        System.IO.FileStream   fs        = new System.IO.FileStream(path, System.IO.FileMode.Open);
                        System.IO.BinaryReader binReader = new System.IO.BinaryReader(fs);
                        binReader.ReadChars(12);
                        binReader.ReadInt32();
                        vertCount = binReader.ReadInt32();
                        binReader.ReadSingle(); //start frame
                        binReader.ReadSingle(); //sample rate
                        framesCount = binReader.ReadInt32();


#if UNITY_WSA
                        binReader.Dispose();
                        fs.Dispose();
#else
                        binReader.Close();
                        fs.Close();
#endif


                        return(vertCount > 0 && framesCount > 0);
                    }
                }
        static int _m_ReadChars(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                System.IO.BinaryReader gen_to_be_invoked = (System.IO.BinaryReader)translator.FastGetCSObj(L, 1);



                {
                    int _count = LuaAPI.xlua_tointeger(L, 2);

                    char[] gen_ret = gen_to_be_invoked.ReadChars(_count);
                    translator.Push(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
Exemplo n.º 24
0
        /////////PARENTS FUNCTION//////////
        protected override void DataUpdate()
        {
            System.IO.BinaryReader BSReader = new System.IO.BinaryReader(ByteStream);
            ByteStream.Position = 0;
            Chunks = BSReader.ReadInt32();
            Array.Resize(ref Chunk, Chunks);
            for (int i = 0; i <= Chunks - 1; i++)
            {
                ChunkType CH = new ChunkType {
                    Unknown = new uint[] { }
                };
                CH.Type = BSReader.ReadUInt32();
                switch (CH.Type)
                {
                case 0:
                {
                    CH.Path  = BSReader.ReadChars(BSReader.ReadInt32()).ToString();
                    CH.Flags = BSReader.ReadUInt32();
                    CH.PlayerTeleportScaleX = BSReader.ReadSingle();
                    CH.SomeInt1             = BSReader.ReadUInt32();
                    CH.SomeInt2             = BSReader.ReadUInt32();
                    CH.Null1                   = BSReader.ReadUInt32();
                    CH.SomeInt3                = BSReader.ReadUInt32();
                    CH.PlayerTeleportScaleY    = BSReader.ReadSingle();
                    CH.SomeInt4                = BSReader.ReadUInt32();
                    CH.Null2                   = BSReader.ReadUInt32();
                    CH.SomeInt5                = BSReader.ReadUInt32();
                    CH.SomeInt6                = BSReader.ReadUInt32();
                    CH.PlayerTeleportScaleZ    = BSReader.ReadSingle();
                    CH.Null3                   = BSReader.ReadUInt32();
                    CH.UnkV4.X                 = BSReader.ReadSingle();
                    CH.UnkV4.Y                 = BSReader.ReadSingle();
                    CH.UnkV4.Z                 = BSReader.ReadSingle();
                    CH.UnkV4.W                 = BSReader.ReadSingle();
                    CH.PlayerTeleport.X        = BSReader.ReadSingle();
                    CH.PlayerTeleport.Y        = BSReader.ReadSingle();
                    CH.PlayerTeleport.Z        = BSReader.ReadSingle();
                    CH.PlayerTeleport.W        = BSReader.ReadSingle();
                    CH.VisualSubchunkScaleX    = BSReader.ReadSingle();
                    CH.SomeInt7                = BSReader.ReadUInt32();
                    CH.SomeInt8                = BSReader.ReadUInt32();
                    CH.Null4                   = BSReader.ReadUInt32();
                    CH.SomeInt9                = BSReader.ReadUInt32();
                    CH.VisualSubchunkScaleY    = BSReader.ReadSingle();
                    CH.SomeInt10               = BSReader.ReadUInt32();
                    CH.Null5                   = BSReader.ReadUInt32();
                    CH.SomeInt11               = BSReader.ReadUInt32();
                    CH.SomeInt12               = BSReader.ReadUInt32();
                    CH.VisualSubchunkScaleZ    = BSReader.ReadSingle();
                    CH.Null6                   = BSReader.ReadUInt32();
                    CH.VisualSubchunkLocationX = BSReader.ReadSingle();
                    CH.VisualSubchunkLocationY = BSReader.ReadSingle();
                    CH.VisualSubchunkLocationZ = BSReader.ReadSingle();
                    CH.LoadWallPoint1.X        = BSReader.ReadSingle();
                    CH.LoadWallPoint1.Y        = BSReader.ReadSingle();
                    CH.LoadWallPoint1.Z        = BSReader.ReadSingle();
                    CH.LoadWallPoint1.W        = BSReader.ReadSingle();

                    CH.LoadWallPoint2.X = BSReader.ReadSingle();
                    CH.LoadWallPoint2.Y = BSReader.ReadSingle();
                    CH.LoadWallPoint2.Z = BSReader.ReadSingle();
                    CH.LoadWallPoint2.W = BSReader.ReadSingle();

                    CH.LoadWallPoint3.X = BSReader.ReadSingle();
                    CH.LoadWallPoint3.Y = BSReader.ReadSingle();
                    CH.LoadWallPoint3.Z = BSReader.ReadSingle();
                    CH.LoadWallPoint3.W = BSReader.ReadSingle();

                    CH.LoadWallPoint4.X = BSReader.ReadSingle();
                    CH.LoadWallPoint4.Y = BSReader.ReadSingle();
                    CH.LoadWallPoint4.Z = BSReader.ReadSingle();
                    CH.LoadWallPoint4.W = BSReader.ReadSingle();
                    break;
                }

                case 1:
                {
                    CH.Path  = BSReader.ReadChars(BSReader.ReadInt32()).ToString();
                    CH.Flags = BSReader.ReadUInt32();
                    CH.PlayerTeleportScaleX = BSReader.ReadSingle();
                    CH.SomeInt1             = BSReader.ReadUInt32();
                    CH.SomeInt2             = BSReader.ReadUInt32();
                    CH.Null1                   = BSReader.ReadUInt32();
                    CH.SomeInt3                = BSReader.ReadUInt32();
                    CH.PlayerTeleportScaleY    = BSReader.ReadSingle();
                    CH.SomeInt4                = BSReader.ReadUInt32();
                    CH.Null2                   = BSReader.ReadUInt32();
                    CH.SomeInt5                = BSReader.ReadUInt32();
                    CH.SomeInt6                = BSReader.ReadUInt32();
                    CH.PlayerTeleportScaleZ    = BSReader.ReadSingle();
                    CH.Null3                   = BSReader.ReadUInt32();
                    CH.UnkV4.X                 = BSReader.ReadSingle();
                    CH.UnkV4.Y                 = BSReader.ReadSingle();
                    CH.UnkV4.Z                 = BSReader.ReadSingle();
                    CH.UnkV4.W                 = BSReader.ReadSingle();
                    CH.PlayerTeleport.X        = BSReader.ReadSingle();
                    CH.PlayerTeleport.Y        = BSReader.ReadSingle();
                    CH.PlayerTeleport.Z        = BSReader.ReadSingle();
                    CH.PlayerTeleport.W        = BSReader.ReadSingle();
                    CH.VisualSubchunkScaleX    = BSReader.ReadSingle();
                    CH.SomeInt7                = BSReader.ReadUInt32();
                    CH.SomeInt8                = BSReader.ReadUInt32();
                    CH.Null4                   = BSReader.ReadUInt32();
                    CH.SomeInt9                = BSReader.ReadUInt32();
                    CH.VisualSubchunkScaleY    = BSReader.ReadSingle();
                    CH.SomeInt10               = BSReader.ReadUInt32();
                    CH.Null5                   = BSReader.ReadUInt32();
                    CH.SomeInt11               = BSReader.ReadUInt32();
                    CH.SomeInt12               = BSReader.ReadUInt32();
                    CH.VisualSubchunkScaleZ    = BSReader.ReadSingle();
                    CH.Null6                   = BSReader.ReadUInt32();
                    CH.VisualSubchunkLocationX = BSReader.ReadSingle();
                    CH.VisualSubchunkLocationY = BSReader.ReadSingle();
                    CH.VisualSubchunkLocationZ = BSReader.ReadSingle();
                    CH.LoadWallPoint1.X        = BSReader.ReadSingle();
                    CH.LoadWallPoint1.Y        = BSReader.ReadSingle();
                    CH.LoadWallPoint1.Z        = BSReader.ReadSingle();
                    CH.LoadWallPoint1.W        = BSReader.ReadSingle();

                    CH.LoadWallPoint2.X = BSReader.ReadSingle();
                    CH.LoadWallPoint2.Y = BSReader.ReadSingle();
                    CH.LoadWallPoint2.Z = BSReader.ReadSingle();
                    CH.LoadWallPoint2.W = BSReader.ReadSingle();

                    CH.LoadWallPoint3.X = BSReader.ReadSingle();
                    CH.LoadWallPoint3.Y = BSReader.ReadSingle();
                    CH.LoadWallPoint3.Z = BSReader.ReadSingle();
                    CH.LoadWallPoint3.W = BSReader.ReadSingle();

                    CH.LoadWallPoint4.X = BSReader.ReadSingle();
                    CH.LoadWallPoint4.Y = BSReader.ReadSingle();
                    CH.LoadWallPoint4.Z = BSReader.ReadSingle();
                    CH.LoadWallPoint4.W = BSReader.ReadSingle();
                    Array.Resize(ref CH.Unknown, 17);
                    CH.Null7 = BSReader.ReadUInt32();
                    for (int j = 0; j <= 16; j++)
                    {
                        CH.Unknown[j] = BSReader.ReadUInt32();
                    }
                    CH.V1.X = BSReader.ReadSingle();
                    CH.V1.Y = BSReader.ReadSingle();
                    CH.V1.Z = BSReader.ReadSingle();
                    CH.Z1   = BSReader.ReadSingle();

                    CH.V2.X = BSReader.ReadSingle();
                    CH.V2.Y = BSReader.ReadSingle();
                    CH.V2.Z = BSReader.ReadSingle();
                    CH.Y2   = BSReader.ReadSingle();

                    CH.V3.X = BSReader.ReadSingle();
                    CH.V3.Y = BSReader.ReadSingle();
                    CH.V3.Z = BSReader.ReadSingle();
                    CH.Z2   = BSReader.ReadSingle();

                    CH.V4.X = BSReader.ReadSingle();
                    CH.V4.Y = BSReader.ReadSingle();
                    CH.V4.Z = BSReader.ReadSingle();
                    CH.Y1   = BSReader.ReadSingle();

                    CH.V5.X = BSReader.ReadSingle();
                    CH.V5.Y = BSReader.ReadSingle();
                    CH.V5.Z = BSReader.ReadSingle();
                    CH.X2   = BSReader.ReadSingle();

                    CH.V6.X = BSReader.ReadSingle();
                    CH.V6.Y = BSReader.ReadSingle();
                    CH.V6.Z = BSReader.ReadSingle();
                    CH.X1   = BSReader.ReadSingle();

                    Array.Resize(ref CH.V4Arr, 6);
                    for (int j = 0; j <= 5; j++)
                    {
                        CH.V4Arr[j].X = BSReader.ReadSingle();
                        CH.V4Arr[j].Y = BSReader.ReadSingle();
                        CH.V4Arr[j].Z = BSReader.ReadSingle();
                        CH.V4Arr[j].W = BSReader.ReadSingle();
                    }
                    CH.Bytes = BSReader.ReadBytes(60);
                    break;
                }
                }
                Chunk[i] = CH;
            }
        }
Exemplo n.º 25
0
        protected override void DataUpdate()
        {
            System.IO.BinaryReader BSReader = new System.IO.BinaryReader(ByteStream);
            ByteStream.Position = 0;
            Class1               = BSReader.ReadUInt32();
            OGINumber            = BSReader.ReadByte();
            AnimationNumber      = OGINumber;
            ScriptNumber         = BSReader.ReadByte();
            GameObjectNumber     = BSReader.ReadByte();
            UnkI32Number         = BSReader.ReadByte();
            ByteStream.Position -= 4;
            Class2               = BSReader.ReadUInt32();
            Class3               = BSReader.ReadUInt32();
            SoundNumber          = (int)Class3;
            int Len = BSReader.ReadInt32();

            Name = new string(BSReader.ReadChars(Len));

            // UnkI32Number = BSReader.ReadInt32
            UnkI32 = new uint[UnkI32Number];
            for (int i = 0; i <= UnkI32Number - 1; i++)
            {
                UnkI32[i] = BSReader.ReadUInt32();
            }

            // OGINumber = BSReader.ReadInt32
            OGI = new ushort[OGINumber];
            for (int i = 0; i <= OGINumber - 1; i++)
            {
                OGI[i] = BSReader.ReadUInt16();
            }

            // AnimationNumber = BSReader.ReadInt32
            Animation = new ushort[AnimationNumber];
            for (int i = 0; i <= AnimationNumber - 1; i++)
            {
                Animation[i] = BSReader.ReadUInt16();
            }

            // ScriptNumber = BSReader.ReadInt32
            Script = new ushort[ScriptNumber];
            for (int i = 0; i <= ScriptNumber - 1; i++)
            {
                Script[i] = BSReader.ReadUInt16();
            }

            // GameObjectNumber = BSReader.ReadInt32
            _GameObject = new ushort[GameObjectNumber];
            for (int i = 0; i <= GameObjectNumber - 1; i++)
            {
                _GameObject[i] = BSReader.ReadUInt16();
            }

            // SoundNumber = BSReader.ReadInt32
            Sound = new ushort[SoundNumber];
            for (int i = 0; i <= SoundNumber - 1; i++)
            {
                Sound[i] = BSReader.ReadUInt16();
            }

            uint choose = BSReader.ReadUInt32();

            if (choose > 255)
            {
                ParametersHeader        = choose;
                ByteStream.Position    -= 4;
                ParametersUnkI321Number = BSReader.ReadByte();
                ParametersUnkI322Number = BSReader.ReadByte();
                ParametersUnkI323Number = BSReader.ReadByte();
                BSReader.ReadByte();
                ParametersUnkI32 = BSReader.ReadUInt32();

                // ParametersUnkI321Number = BSReader.ReadInt32

                ParametersUnkI321 = new uint[ParametersUnkI321Number];
                for (int i = 0; i <= ParametersUnkI321Number - 1; i++)
                {
                    ParametersUnkI321[i] = BSReader.ReadUInt32();
                }

                // ParametersUnkI322Number = BSReader.ReadInt32
                ParametersUnkI322 = new float[ParametersUnkI322Number];
                for (int i = 0; i <= ParametersUnkI322Number - 1; i++)
                {
                    ParametersUnkI322[i] = BSReader.ReadSingle();
                }

                // ParametersUnkI323Number = BSReader.ReadInt32
                ParametersUnkI323 = new uint[ParametersUnkI323Number];
                for (int i = 0; i <= ParametersUnkI323Number - 1; i++)
                {
                    ParametersUnkI323[i] = BSReader.ReadUInt32();
                }
                choose = BSReader.ReadUInt32();
            }
            else
            {
                ParametersHeader        = 0;
                ParametersUnkI32        = 0;
                ParametersUnkI321Number = 0;
                ParametersUnkI321       = new uint[] { };
                ParametersUnkI322Number = 0;
                ParametersUnkI322       = new float[] { };
                ParametersUnkI323Number = 0;
                ParametersUnkI323       = new uint[] { };
            }
            ChildFlag = choose;
            if (choose > 0)
            {
                string str = Convert.ToString(ChildFlag, 2);
                while (str.Length < 8)
                {
                    str = "0" + str;
                }
                bool GameObjectFlag = (str[7] == '1');
                bool OGIFlag        = (str[6] == '1');
                bool AnimationFlag  = (str[5] == '1');
                bool ID4Flag        = (str[4] == '1');
                bool ScriptFlag     = (str[3] == '1');
                bool UnknownFlag    = (str[2] == '1');
                bool SoundFlag      = (str[1] == '1');
                if (GameObjectFlag)
                {
                    ChildObjectNumber = BSReader.ReadInt32();
                    ChildObject       = new ushort[ChildObjectNumber];
                    for (int i = 0; i <= ChildObjectNumber - 1; i++)
                    {
                        ChildObject[i] = BSReader.ReadUInt16();
                    }
                }
                if (OGIFlag)
                {
                    ChildOGINumber = BSReader.ReadInt32();
                    ChildOGI       = new ushort[ChildOGINumber];
                    for (int i = 0; i <= ChildOGINumber - 1; i++)
                    {
                        ChildOGI[i] = BSReader.ReadUInt16();
                    }
                }
                if (AnimationFlag)
                {
                    ChildAnimationNumber = BSReader.ReadInt32();
                    ChildAnimation       = new ushort[ChildAnimationNumber];
                    for (int i = 0; i <= ChildAnimationNumber - 1; i++)
                    {
                        ChildAnimation[i] = BSReader.ReadUInt16();
                    }
                }
                if (ID4Flag)
                {
                    ChildID4Number = BSReader.ReadInt32();
                    ChildID4       = new ushort[ChildID4Number];
                    for (int i = 0; i <= ChildID4Number - 1; i++)
                    {
                        ChildID4[i] = BSReader.ReadUInt16();
                    }
                }
                if (ScriptFlag)
                {
                    ChildScriptNumber = BSReader.ReadInt32();
                    ChildScript       = new ushort[ChildScriptNumber];
                    for (int i = 0; i <= ChildScriptNumber - 1; i++)
                    {
                        ChildScript[i] = BSReader.ReadUInt16();
                    }
                }
                if (UnknownFlag)
                {
                    ChildUnknownNumber = BSReader.ReadInt32();
                    ChildUnknown       = new ushort[ChildUnknownNumber];
                    for (int i = 0; i <= ChildUnknownNumber - 1; i++)
                    {
                        ChildUnknown[i] = BSReader.ReadUInt16();
                    }
                }
                if (SoundFlag)
                {
                    ChildSoundNumber = BSReader.ReadInt32();
                    ChildSound       = new ushort[ChildSoundNumber];
                    for (int i = 0; i <= ChildSoundNumber - 1; i++)
                    {
                        ChildSound[i] = BSReader.ReadUInt16();
                    }
                }
                ScriptLength = (int)BSReader.ReadUInt32();
                if (ScriptLength > 1)
                {
                    var arrLen = 18;
                    ScriptParameters = new ushort[arrLen];
                    for (int i = 0; i < arrLen; i++)
                    {
                        ScriptParameters[i] = BSReader.ReadUInt16();
                    }
                }
                ScriptArray = BSReader.ReadBytes((int)(ByteStream.Length - ByteStream.Position));
            }
        }
Exemplo n.º 26
0
        private void Button6_Click(object sender, EventArgs e)
        {
            int index = TreeView1.SelectedNode.Index;

            if (OpenWAV.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.IO.FileStream   WAVFile   = new System.IO.FileStream(OpenWAV.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                System.IO.BinaryReader WAVReader = new System.IO.BinaryReader(WAVFile);
                char[] Header;
                int    FileSize;
                char[] WAVHeader;
                char[] fmtHeader;
                int    SubChunk1Size;
                Int16  Format;
                Int16  Chanells;
                uint   SampleRate;
                uint   BitRate;
                UInt16 Align;
                UInt16 BPS;
                char[] SubChunk2Id;
                int    SubChunk2Size;
                Header        = WAVReader.ReadChars(4);
                FileSize      = WAVReader.ReadInt32();
                WAVHeader     = WAVReader.ReadChars(4);
                fmtHeader     = WAVReader.ReadChars(4);
                SubChunk1Size = WAVReader.ReadInt32();
                Format        = WAVReader.ReadInt16();
                Chanells      = WAVReader.ReadInt16();
                SampleRate    = WAVReader.ReadUInt32();
                BitRate       = WAVReader.ReadUInt32();
                Align         = WAVReader.ReadUInt16();
                BPS           = WAVReader.ReadUInt16();
                SubChunk2Id   = WAVReader.ReadChars(4);
                SubChunk2Size = WAVReader.ReadInt32();
                System.IO.MemoryStream ADPCM     = new System.IO.MemoryStream();
                System.IO.MemoryStream PCM       = new System.IO.MemoryStream();
                System.IO.BinaryWriter PCMWriter = new System.IO.BinaryWriter(PCM);
                PCMWriter.Write(WAVReader.ReadBytes(SubChunk2Size));
                Twinsanity.ADPCM ADPCM_Device = new Twinsanity.ADPCM();
                if (Chanells == 2)
                {
                    System.IO.MemoryStream PCML   = new System.IO.MemoryStream();
                    System.IO.MemoryStream PCMR   = new System.IO.MemoryStream();
                    System.IO.MemoryStream ADPCML = new System.IO.MemoryStream();
                    System.IO.MemoryStream ADPCMR = new System.IO.MemoryStream();
                    ADPCM_Device.PCM_Demux(PCM, ref PCMR, ref PCML);
                    PCMR.Position = 0;
                    PCML.Position = 0;
                    ADPCM_Device.PCM2ADPCM(ref ADPCMR, PCMR);
                    ADPCM_Device.PCM2ADPCM(ref ADPCML, PCML);
                    ADPCM_Device.ADPCM_Mux(ref ADPCM, ADPCMR, ADPCML, Interleave);
                    Sounds[index].Type = 1;
                }
                else if (Chanells == 1)
                {
                    PCM.Position = 0;
                    ADPCM_Device.PCM2ADPCM(ref ADPCM, PCM);
                    Sounds[index].Type = 0;
                }
                Sounds[index].Size       = (uint)ADPCM.Length;
                Sounds[index].Offset     = 0;
                Sounds[index].SampleRate = SampleRate;
                Sounds[index].Skip       = 0;
                Sounds[index].External   = true;
                Sounds[index].Name       = "External";
                Sounds[index].Stream     = new System.IO.MemoryStream();
                Sounds[index].Stream.Write(ADPCM.ToArray(), 0, (int)ADPCM.Length);
                BuildTree();
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Converts WAV sound to Twinsanity's sound format
        /// </summary>
        /// <param name="Wav">WAV file represented as a stream in RAM</param>
        /// <param name="ADPCM">ADPCM file represented as a stream in RAM</param>
        public void WAV2Twin(System.IO.MemoryStream Wav, ref System.IO.MemoryStream ADPCM)
        {
            InitF2();
            char[] Header;
            int    FileSize;

            char[] WAVHeader;
            char[] fmtHeader;
            int    SubChunk1Size;
            short  Format;
            short  Chanells;
            uint   SampleRate;
            uint   BitRate;
            ushort Align;
            ushort BPS;

            char[] SubChunk2Id;
            int    SubChunk2Size;

            System.IO.BinaryReader WavReader   = new System.IO.BinaryReader(Wav);
            System.IO.BinaryWriter ADPCMWriter = new System.IO.BinaryWriter(ADPCM);
            Wav.Position   = 0;
            ADPCM.Position = 0;
            Header         = WavReader.ReadChars(4);
            FileSize       = WavReader.ReadInt32();
            WAVHeader      = WavReader.ReadChars(4);
            fmtHeader      = WavReader.ReadChars(4);
            SubChunk1Size  = WavReader.ReadInt32();
            Format         = WavReader.ReadInt16();
            Chanells       = WavReader.ReadInt16();
            SampleRate     = WavReader.ReadUInt32();
            BitRate        = WavReader.ReadUInt32();
            Align          = WavReader.ReadUInt16();
            BPS            = WavReader.ReadUInt16();
            SubChunk2Id    = WavReader.ReadChars(4);
            SubChunk2Size  = WavReader.ReadInt32();
            int samples = SubChunk2Size / 2;
            int size    = samples / 28;

            if (samples % 28 > 0)
            {
                size += 1;
            }
            int    ADPCM_Size = size * 16 + 16;
            ushort Frequency;

            switch (SampleRate)
            {
            case 8000:
            {
                Frequency = 682;
                break;
            }

            case 11025:
            {
                Frequency = 1024;
                break;
            }

            case 16000:
            {
                Frequency = 1365;
                break;
            }

            case 20000:
            {
                Frequency = 1706;
                break;
            }

            case 18000:
            {
                Frequency = 1536;
                break;
            }

            case 22050:
            {
                Frequency = 1881;
                break;
            }

            case 44100:
            {
                Frequency = 3763;
                break;
            }

            case 48000:
            {
                Frequency = 4096;
                break;
            }

            default:
            {
                Frequency = (ushort)Math.Round(SampleRate / (double)k);
                break;
            }
            }

            Random random = new Random();
            int    I32    = (int)Math.Round(random.NextDouble() * 1500 + 2000);

            ADPCMWriter.Write(I32);
            ADPCMWriter.Write(Frequency);
            ADPCMWriter.Write(ADPCM_Size);
            byte flags = 0;

            while (samples > 0 && Wav.Position < Wav.Length)
            {
                int     work_size;
                short[] wave = new short[3584];
                if (samples >= BUFFER_SIZE)
                {
                    work_size = BUFFER_SIZE;
                }
                else
                {
                    work_size = samples;
                }
                for (int i = 0; i <= work_size - 1; i++)
                {
                    wave[i] = WavReader.ReadInt16();
                }
                for (int i = 0; i <= work_size / 28 - 1; i++)
                {
                    float[] d_samples    = new float[28];
                    int[]   four_bit     = new int[28];
                    byte    predict_nr   = 0;
                    byte    shift_factor = 0;
                    find_predict(wave, (short)(i * 28), ref predict_nr, ref shift_factor, ref d_samples);
                    pack(d_samples, ref four_bit, predict_nr, shift_factor);
                    byte D = (byte)((predict_nr << 4) | shift_factor);
                    ADPCMWriter.Write(D);
                    ADPCMWriter.Write(flags);
                    for (int j = 0; j <= 27; j += 2)
                    {
                        byte ebit = (byte)(((four_bit[j + 1] >> 8) & 240) | ((four_bit[j] >> 12) & 15));
                        ADPCMWriter.Write(ebit);
                    }
                    samples -= 28;
                    if (samples < 28)
                    {
                        flags = 1;
                    }
                }
            }
            byte _D = 0;

            ADPCMWriter.Write(_D);
            _D = 7;
            ADPCMWriter.Write(_D);
            _D = 119;
            for (int i = 0; i <= 13; i++)
            {
                ADPCMWriter.Write(_D);
            }
            Wav.Position   = 0;
            ADPCM.Position = 0;
        }
Exemplo n.º 28
0
 private string ReadTag()
 {
     return(new string(reader.ReadChars(4)));
 }
Exemplo n.º 29
0
        /////////PARENTS FUNCTION//////////
        protected override void DataUpdate()
        {
            System.IO.BinaryReader BSReader = new System.IO.BinaryReader(ByteStream);
            ByteStream.Position = 0;
            Array.Resize(ref E3, 0);
            Header          = BSReader.ReadUInt32();
            LevelNameLength = BSReader.ReadUInt32();
            LevelName       = BSReader.ReadChars((int)LevelNameLength).ToString();
            Flags           = BSReader.ReadUInt32();
            EntryHeader     = BSReader.ReadUInt32();
            NullByte        = BSReader.ReadByte();
            SBID            = BSReader.ReadUInt32();
            uint tmp = 0;
            int  p   = (int)ByteStream.Position;

            while ((!(tmp == 5651)) && (ByteStream.Position < ByteStream.Length))
            {
                tmp = BSReader.ReadByte();
                if (tmp == 19)
                {
                    ByteStream.Position -= 1;
                    tmp = BSReader.ReadUInt32();
                    if (!(tmp == 5651))
                    {
                        ByteStream.Position -= 3;
                    }
                    else
                    {
                        ByteStream.Position -= 4;
                    }
                }
            }
            p = (int)ByteStream.Position - p;
            ByteStream.Position -= p;
            Garbadge             = BSReader.ReadBytes(p);
            if (tmp == 5651 && (ByteStream.Position < ByteStream.Length))
            {
                while ((ByteStream.Position < ByteStream.Length))
                {
                    Entry3 withBlock = new Entry3();
                    {
                        withBlock.EntryHeader = BSReader.ReadUInt32();
                        withBlock.GCCount     = BSReader.ReadUInt16();
                        withBlock.SBCount     = BSReader.ReadUInt16();
                        Array.Resize(ref withBlock.Vector1, withBlock.GCCount + withBlock.SBCount);
                        Array.Resize(ref withBlock.Vector2, withBlock.GCCount + withBlock.SBCount);
                        Array.Resize(ref withBlock.GCID, withBlock.GCCount);
                        Array.Resize(ref withBlock.SBID, withBlock.SBCount);
                        Array.Resize(ref withBlock.ChunkMatrix, withBlock.GCCount + withBlock.SBCount);
                        for (int i = 0; i <= withBlock.GCCount + withBlock.SBCount - 1; i++)
                        {
                            withBlock.Vector1[i].X = BSReader.ReadSingle();
                            withBlock.Vector1[i].Y = BSReader.ReadSingle();
                            withBlock.Vector1[i].Z = BSReader.ReadSingle();
                            withBlock.Vector1[i].W = BSReader.ReadSingle();
                            withBlock.Vector2[i].X = BSReader.ReadSingle();
                            withBlock.Vector2[i].Y = BSReader.ReadSingle();
                            withBlock.Vector2[i].Z = BSReader.ReadSingle();
                            withBlock.Vector2[i].W = BSReader.ReadSingle();
                        }
                        for (int i = 0; i <= withBlock.GCCount - 1; i++)
                        {
                            withBlock.GCID[i] = BSReader.ReadUInt32();
                        }
                        for (int i = 0; i <= withBlock.SBCount - 1; i++)
                        {
                            withBlock.SBID[i] = BSReader.ReadUInt32();
                        }
                        for (int i = 0; i <= withBlock.GCCount + withBlock.SBCount - 1; i++)
                        {
                            withBlock.ChunkMatrix[i].x1 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].y1 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].z1 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].w1 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].x2 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].y2 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].z2 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].w2 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].x3 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].y3 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].z3 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].w3 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].x4 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].y4 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].z4 = BSReader.ReadSingle();
                            withBlock.ChunkMatrix[i].w4 = BSReader.ReadSingle();
                        }
                        tmp = 0;
                        var len = ByteStream.Position;
                        while ((tmp != 5651) & (ByteStream.Position < ByteStream.Length))
                        {
                            tmp = BSReader.ReadByte();
                            if (tmp == 19)
                            {
                                ByteStream.Position -= 1;
                                tmp = BSReader.ReadUInt32();
                                if (tmp != 5651)
                                {
                                    ByteStream.Position -= 3;
                                }
                                else
                                {
                                    ByteStream.Position -= 4;
                                }
                            }
                        }
                        len = ByteStream.Position - len;
                        ByteStream.Position -= len;
                        withBlock.leftovers  = BSReader.ReadBytes((int)len);
                    }
                    _Entries.Add(withBlock);
                }
                E3 = _Entries.ToArray();
            }
        }
Exemplo n.º 30
0
        public static ActionLibrary Load(System.IO.Stream s)
        {
            ActionLibrary lib = new ActionLibrary();

            System.IO.BinaryReader br = new System.IO.BinaryReader(s, Encoding.ASCII);
            lib.GameMakerVersion = br.ReadInt32();
            bool gm5 = lib.GameMakerVersion == 500;

            lib.TabCaption              = new string(br.ReadChars(br.ReadInt32()));
            lib.LibraryID               = br.ReadInt32();
            lib.Author                  = new string(br.ReadChars(br.ReadInt32()));
            lib.Version                 = br.ReadInt32();
            lib.LastChanged             = new DateTime(1899, 12, 30).AddDays(br.ReadDouble());
            lib.Info                    = new string(br.ReadChars(br.ReadInt32()));
            lib.InitializationCode      = new string(br.ReadChars(br.ReadInt32()));
            lib.AdvancedModeOnly        = br.ReadInt32() == 0 ? false : true;
            lib.ActionNumberIncremental = br.ReadInt32();
            for (int i = br.ReadInt32(); i > 0; i--)
            {
                int ver            = br.ReadInt32();
                ActionDefinition a = new ActionDefinition(lib, new string(br.ReadChars(br.ReadInt32())), br.ReadInt32());
                a.GameMakerVersion = ver;
                int size = br.ReadInt32();
                a.OriginalImage = new byte[size];
                br.Read(a.OriginalImage, 0, size);
                System.IO.MemoryStream ms = new System.IO.MemoryStream(a.OriginalImage);
                System.Drawing.Bitmap  b  = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(ms);
                a.Image = new System.Drawing.Bitmap(24, 24, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                using (var g = System.Drawing.Graphics.FromImage(a.Image))
                {
                    g.DrawImage(b, new System.Drawing.Rectangle(0, 0, b.Width, b.Height));
                }
                if (b.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb)
                {
                    ((System.Drawing.Bitmap)a.Image).MakeTransparent(b.GetPixel(0, b.Height - 1));
                }
                ms.Close();
                b.Dispose();
                a.Hidden         = br.ReadInt32() == 0 ? false : true;
                a.Advanced       = br.ReadInt32() == 0 ? false : true;
                a.RegisteredOnly = ver == 500 || (br.ReadInt32() == 0) ? false : true;
                a.Description    = new string(br.ReadChars(br.ReadInt32()));
                a.ListText       = new string(br.ReadChars(br.ReadInt32()));
                a.HintText       = new string(br.ReadChars(br.ReadInt32()));
                a.Kind           = (ActionKind)br.ReadInt32();
                a.InterfaceKind  = (ActionInferfaceKind)br.ReadInt32();
                a.IsQuestion     = br.ReadInt32() == 0 ? false : true;
                a.ShowApplyTo    = br.ReadInt32() == 0 ? false : true;
                a.ShowRelative   = br.ReadInt32() == 0 ? false : true;
                a.ArgumentCount  = br.ReadInt32();
                int count = br.ReadInt32();
                if (a.Arguments.Length != count)
                {
                    a.Arguments = new ActionArgument[count];
                }
                for (int j = 0; j < count; j++)
                {
                    a.Arguments[j]              = new ActionArgument();
                    a.Arguments[j].Caption      = new string(br.ReadChars(br.ReadInt32()));
                    a.Arguments[j].Type         = (ActionArgumentType)br.ReadInt32();
                    a.Arguments[j].DefaultValue = new string(br.ReadChars(br.ReadInt32()));
                    a.Arguments[j].Menu         = new string(br.ReadChars(br.ReadInt32()));
                }
                a.ExecutionType = (ActionExecutionType)br.ReadInt32();
                a.FunctionName  = new string(br.ReadChars(br.ReadInt32()));
                a.Code          = new string(br.ReadChars(br.ReadInt32()));
                lib.Actions.Add(a);
            }
            //Hmm...
            //ActionDefinition d = new ActionDefinition(lib);
            //d.Description = "Font...";
            //d.ArgumentCount = 1;
            //d.Arguments[0] = new ActionArgument();
            //d.Arguments[0].Type = ActionArgumentType.FontString;
            //d.ListText = "@0";
            //lib.Actions.Add(d);
            //d.Arguments[0].DefaultValue = "\"Times New Roman\",10,0,0,0,0,0";
            return(lib);
        }
Exemplo n.º 31
0
        /// <summary>Loads a wave/riff audio file from a stream. Resource file can be passed as the stream.</summary>
        private static byte[] LoadWave(System.IO.Stream stream, out int channels, out int bits, out int rate)
        {
            if (stream == null) throw new ArgumentNullException("stream");

            // ReSharper disable UnusedVariable
            using (var reader = new System.IO.BinaryReader(stream))
            {
                //RIFF header
                var signature = new string(reader.ReadChars(4));
                if (signature != "RIFF") throw new NotSupportedException("Specified stream is not a wave file.");

                int riffChunckSize = reader.ReadInt32();

                var format = new string(reader.ReadChars(4));
                if (format != "WAVE") throw new NotSupportedException("Specified stream is not a wave file.");

                //WAVE header
                var formatSignature = new string(reader.ReadChars(4));
                if (formatSignature != "fmt ") throw new NotSupportedException("Specified wave file is not supported.");

                int formatChunkSize = reader.ReadInt32();
                int audioFormat = reader.ReadInt16();
                int numChannels = reader.ReadInt16();
                int sampleRate = reader.ReadInt32();
                int byteRate = reader.ReadInt32();
                int blockAlign = reader.ReadInt16();
                int bitsPerSample = reader.ReadInt16();

                var dataSignature = new string(reader.ReadChars(4));
                //check if the data dignature for this chunk is LIST headers, can happen with .wav files from web, or when converting other formats such as .mp3 to .wav using tools such as audacity
                //if this happens, the extra header info can be cleared using audacity, export to wave and select 'clear' when the extra header info window appears
                //see http://www.lightlink.com/tjweber/StripWav/WAVE.html
                if (dataSignature == "LIST") throw new NotSupportedException("Specified wave file contains LIST headers (author, copyright etc).");
                if (dataSignature != "data") throw new NotSupportedException("Specified wave file is not supported.");

                int dataChunkSize = reader.ReadInt32();

                channels = numChannels;
                bits = bitsPerSample;
                rate = sampleRate;

                return reader.ReadBytes((int)reader.BaseStream.Length);
            }
            // ReSharper restore UnusedVariable
        }
Exemplo n.º 32
0
        public void readFile()
        {
            System.IO.BinaryReader sr;

            try { //TODO: test, rather than try/fail?
                sr = new System.IO.BinaryReader(System.IO.File.Open(path, System.IO.FileMode.Open));
            } catch (System.IO.IOException) {
                throw;
            }

            //====================
            //RIFF chunk id
            char[] ckID = sr.ReadChars(4);
            String a = new string(ckID);
            if (a.CompareTo("RIFF") != 0) {
                throw new FormatException("RIFF chunkID missing. Found " + ckID[0] + ckID[1] + ckID[2] + ckID[3] + ".");
            }

            UInt32 RIFFSize = sr.ReadUInt32();

            //====================
            //WAVE chunk id
            ckID = sr.ReadChars(4);
            a = new string(ckID);
            if (a.CompareTo("WAVE") != 0) {
                throw new FormatException("WAVE chunkID missing. Found " + ckID[0] + ckID[1] + ckID[2] + ckID[3] + ".");
            }

            //====================
            //fmt_ chunk id
            ckID = sr.ReadChars(4);
            a = new string(ckID);
            UInt32 chunkSize = sr.ReadUInt32();
            while (a.CompareTo("fmt ") != 0) {
                sr.ReadBytes((int)chunkSize);
                ckID = sr.ReadChars(4);
                a = new string(ckID);
                chunkSize = sr.ReadUInt32();
            }
            Int16 wFormatTag = sr.ReadInt16();
            Int16 nChannels = sr.ReadInt16();
            Int32 nSamplesPerSec = sr.ReadInt32();
            Int32 nAvgBytesPerSec = sr.ReadInt32();
            Int16 nBlockAlign = sr.ReadInt16();
            Int16 wBitsPerSample = sr.ReadInt16();
            chunkSize -= 16;
            //there may be more bytes in fmt_ so skip those.
            sr.ReadBytes((int)chunkSize);

            if (wFormatTag != 0x0001) {
                throw new FormatException("Invalid wave format. Only PCM wave files supported.");
            }

            //====================
            //data chunk id
            ckID = sr.ReadChars(4);
            a = new string(ckID);
            chunkSize = sr.ReadUInt32();
            while (a.CompareTo("data") != 0) {
                sr.ReadBytes((int)chunkSize);
                ckID = sr.ReadChars(4);
                a = new string(ckID);
                chunkSize = sr.ReadUInt32();
            }

            channels = (short)nChannels;
            bitDepth = (short)wBitsPerSample;
            sampleRate = nSamplesPerSec;
            long numSamples = chunkSize / (bitDepth / 8) / channels;
            samples = new double[channels][];
            for (int c = 0; c < channels; c++) {
                samples[c] = new double[numSamples];
            }

            //======================
            // read samples
            if (bitDepth == 16) {
                for (int i = 0; i < numSamples; i++) {
                    for (int c = 0; c < channels; c++) {
                        //assuming signed
                        //normalized to -1.0..+1.0
                        samples[c][i] = (double)sr.ReadInt16() / 32768.0;
                    }
                }
            } else if (bitDepth == 8) {
                for (int i = 0; i < numSamples; i++) {
                    for (int c = 0; c < channels; c++) {
                        //assuming unsigned
                        //normalized to -1.0..+1.0
                        samples[c][i] = (double)sr.ReadByte() / 128.0 - 1.0;
                    }
                }
            } else {
                throw new FormatException("Bit depth must be one of 8 or 16 bits.");
            }
            sr.Close();
        }
Exemplo n.º 33
0
 public static ActionLibrary Load(System.IO.Stream s)
 {
     ActionLibrary lib = new ActionLibrary();
     System.IO.BinaryReader br = new System.IO.BinaryReader(s, Encoding.ASCII);
     lib.GameMakerVersion = br.ReadInt32();
     bool gm5 = lib.GameMakerVersion == 500;
     lib.TabCaption = new string(br.ReadChars(br.ReadInt32()));
     lib.LibraryID = br.ReadInt32();
     lib.Author = new string(br.ReadChars(br.ReadInt32()));
     lib.Version = br.ReadInt32();
     lib.LastChanged = new DateTime(1899, 12, 30).AddDays(br.ReadDouble());
     lib.Info = new string(br.ReadChars(br.ReadInt32()));
     lib.InitializationCode = new string(br.ReadChars(br.ReadInt32()));
     lib.AdvancedModeOnly = br.ReadInt32() == 0 ? false : true;
     lib.ActionNumberIncremental = br.ReadInt32();
     for (int i = br.ReadInt32(); i > 0; i--)
     {
         int ver = br.ReadInt32();
         ActionDefinition a = new ActionDefinition(lib, new string(br.ReadChars(br.ReadInt32())), br.ReadInt32());
         a.GameMakerVersion = ver;
         int size = br.ReadInt32();
         a.OriginalImage = new byte[size];
         br.Read(a.OriginalImage, 0, size);
         System.IO.MemoryStream ms = new System.IO.MemoryStream(a.OriginalImage);
         System.Drawing.Bitmap b = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(ms);
         a.Image = new System.Drawing.Bitmap(24, 24, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
         using (var g = System.Drawing.Graphics.FromImage(a.Image))
         {
             g.DrawImage(b, new System.Drawing.Rectangle(0, 0, b.Width, b.Height));
         }
         if (b.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb)
             ((System.Drawing.Bitmap)a.Image).MakeTransparent(b.GetPixel(0, b.Height - 1));
         ms.Close();
         b.Dispose();
         a.Hidden = br.ReadInt32() == 0 ? false : true;
         a.Advanced = br.ReadInt32() == 0 ? false : true;
         a.RegisteredOnly = ver == 500 || (br.ReadInt32() == 0) ? false : true;
         a.Description = new string(br.ReadChars(br.ReadInt32()));
         a.ListText = new string(br.ReadChars(br.ReadInt32()));
         a.HintText = new string(br.ReadChars(br.ReadInt32()));
         a.Kind = (ActionKind)br.ReadInt32();
         a.InterfaceKind = (ActionInferfaceKind)br.ReadInt32();
         a.IsQuestion = br.ReadInt32() == 0 ? false : true;
         a.ShowApplyTo = br.ReadInt32() == 0 ? false : true;
         a.ShowRelative = br.ReadInt32() == 0 ? false : true;
         a.ArgumentCount = br.ReadInt32();
         int count = br.ReadInt32();
         if (a.Arguments.Length != count)
             a.Arguments = new ActionArgument[count];
         for (int j = 0; j < count; j++)
         {
             a.Arguments[j] = new ActionArgument();
             a.Arguments[j].Caption = new string(br.ReadChars(br.ReadInt32()));
             a.Arguments[j].Type = (ActionArgumentType)br.ReadInt32();
             a.Arguments[j].DefaultValue = new string(br.ReadChars(br.ReadInt32()));
             a.Arguments[j].Menu = new string(br.ReadChars(br.ReadInt32()));
         }
         a.ExecutionType = (ActionExecutionType)br.ReadInt32();
         a.FunctionName = new string(br.ReadChars(br.ReadInt32()));
         a.Code = new string(br.ReadChars(br.ReadInt32()));
         lib.Actions.Add(a);
     }
     //Hmm...
     //ActionDefinition d = new ActionDefinition(lib);
     //d.Description = "Font...";
     //d.ArgumentCount = 1;
     //d.Arguments[0] = new ActionArgument();
     //d.Arguments[0].Type = ActionArgumentType.FontString;
     //d.ListText = "@0";
     //lib.Actions.Add(d);
     //d.Arguments[0].DefaultValue = "\"Times New Roman\",10,0,0,0,0,0";
     return lib;
 }
Exemplo n.º 34
0
        static private AddressLibrary.Header ReadHeader(System.IO.BinaryReader binaryReader, System.Int32 versionMajor, System.Int32 versionMinor, System.Int32 versionBuild, System.Int32 versionPrivate)
        {
            var header = new AddressLibrary.Header();

            header.Format = binaryReader.ReadInt32();

            if (header.Format != 1)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.Format)} encountered, {header.Format}. Expected 1");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.VersionMajor = binaryReader.ReadInt32();

            if (header.VersionMajor != versionMajor)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.VersionMajor)} encountered, {header.VersionMajor}. Expected {versionMajor}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.VersionMinor = binaryReader.ReadInt32();

            if (header.VersionMinor != versionMinor)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.VersionMinor)} encountered, {header.VersionMinor}. Expected {versionMinor}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.VersionBuild = binaryReader.ReadInt32();

            if (header.VersionBuild != versionBuild)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.VersionBuild)} encountered, {header.VersionBuild}. Expected {versionBuild}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.VersionPrivate = binaryReader.ReadInt32();

            if (header.VersionPrivate != versionPrivate)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.VersionPrivate)} encountered, {header.VersionPrivate}. Expected {versionPrivate}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.NameLength = binaryReader.ReadInt32();
            header.Name       = new System.String(binaryReader.ReadChars(header.NameLength));

            if (header.Name != Main.MainModuleName)
            {
                try
                {
                    throw new System.NotSupportedException($"{nameof(AddressLibrary)}: Unexpected {nameof(header.Name)} encountered, {header.Name}. Expected {Main.MainModuleName}");
                }
                catch (System.NotSupportedException notSupportedException)
                {
                    Log.Information($"{notSupportedException}");

                    throw;
                }
            }

            header.PointerSize  = binaryReader.ReadInt32();
            header.AddressCount = binaryReader.ReadInt32();

            return(header);
        }
Exemplo n.º 35
0
 public void Load(System.IO.BinaryReader reader)
 {
     this.Type    = new OEIShared.Utils.FourCC(reader.ReadChars(4));
     this.Address = reader.ReadInt32();
 }
Exemplo n.º 36
0
        public void Populate(int iOffset, bool useMemoryStream)
        {
            this.isNulledOutReflexive = false;
            System.IO.BinaryReader BR = new System.IO.BinaryReader(meta.MS);
            //set offsets
            BR.BaseStream.Position = iOffset + this.chunkOffset;
            this.offsetInMap = iOffset + this.chunkOffset;
            // If we need to read / save tag info directly to file...
            if (!useMemoryStream)
            {
                map.OpenMap(MapTypes.Internal);
                BR = map.BR;
                BR.BaseStream.Position = this.offsetInMap;
            }
            else
                this.offsetInMap += meta.offset;

            if (doesHaveTagType)
            {
                int nullCheck = BR.ReadInt32();
                if (nullCheck != -1)
                {
                    BR.BaseStream.Position -= 4;
                    char[] temptype = BR.ReadChars(4);
                    Array.Reverse(temptype);
                    this.tagType = new string(temptype);
                }
                else
                    this.tagType = "null";
            }
            else
                this.tagType = "null";

            int tempint = BR.ReadInt32();
            // ...and then close the file once we are done!
            if (!useMemoryStream)
                map.CloseMap();
            this.tagIndex = map.Functions.ForMeta.FindMetaByID(tempint);
            if (this.tagIndex != -1)
            {
                this.tagType = map.MetaInfo.TagType[this.tagIndex];
                this.tagName = map.FileNames.Name[this.tagIndex];
            }
            else
            {
                this.tagName = "null";
            }
            this.identInt32 = tempint;

            this.UpdateIdentBoxes();
        }
Exemplo n.º 37
0
        /// <summary>Loads a wave/riff audio file from a stream. Resource file can be passed as the stream.</summary>
        private static byte[] LoadWave(System.IO.Stream stream, out int channels, out int bits, out int rate)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            // ReSharper disable UnusedVariable
            using (var reader = new System.IO.BinaryReader(stream))
            {
                //RIFF header
                var signature = new string(reader.ReadChars(4));
                if (signature != "RIFF")
                {
                    throw new NotSupportedException("Specified stream is not a wave file.");
                }

                int riffChunckSize = reader.ReadInt32();

                var format = new string(reader.ReadChars(4));
                if (format != "WAVE")
                {
                    throw new NotSupportedException("Specified stream is not a wave file.");
                }

                //WAVE header
                var formatSignature = new string(reader.ReadChars(4));
                if (formatSignature != "fmt ")
                {
                    throw new NotSupportedException("Specified wave file is not supported.");
                }

                int formatChunkSize = reader.ReadInt32();
                int audioFormat     = reader.ReadInt16();
                int numChannels     = reader.ReadInt16();
                int sampleRate      = reader.ReadInt32();
                int byteRate        = reader.ReadInt32();
                int blockAlign      = reader.ReadInt16();
                int bitsPerSample   = reader.ReadInt16();

                var dataSignature = new string(reader.ReadChars(4));
                //check if the data dignature for this chunk is LIST headers, can happen with .wav files from web, or when converting other formats such as .mp3 to .wav using tools such as audacity
                //if this happens, the extra header info can be cleared using audacity, export to wave and select 'clear' when the extra header info window appears
                //see http://www.lightlink.com/tjweber/StripWav/WAVE.html
                if (dataSignature == "LIST")
                {
                    throw new NotSupportedException("Specified wave file contains LIST headers (author, copyright etc).");
                }
                if (dataSignature != "data")
                {
                    throw new NotSupportedException("Specified wave file is not supported.");
                }

                int dataChunkSize = reader.ReadInt32();

                channels = numChannels;
                bits     = bitsPerSample;
                rate     = sampleRate;

                return(reader.ReadBytes((int)reader.BaseStream.Length));
            }
            // ReSharper restore UnusedVariable
        }