当前位置: 首页>>代码示例>>C#>>正文


C# Stream.ReadStruct方法代码示例

本文整理汇总了C#中Stream.ReadStruct方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.ReadStruct方法的具体用法?C# Stream.ReadStruct怎么用?C# Stream.ReadStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stream的用法示例。


在下文中一共展示了Stream.ReadStruct方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Packfile

        public Packfile(Stream stream)
        {
            DataStream = stream;

            stream.Seek(0, SeekOrigin.Begin);
            FileData = stream.ReadStruct<PackfileFileData>();

            m_Files = new List<IPackfileEntry>();

            stream.Seek(GetEntryDataOffset(), SeekOrigin.Begin);

            List<PackfileEntryFileData> entryFileData = new List<PackfileEntryFileData>();

            for (int i = 0; i < FileData.IndexCount; i++)
            {
                var fileData = stream.ReadStruct<PackfileEntryFileData>();
                entryFileData.Add(fileData);
            }

            List<string> fileNames = new List<string>();
            for (int i = 0; i < FileData.IndexCount; i++)
            {
                var fileData = entryFileData[i];
                stream.Seek(CalculateEntryNamesOffset() + fileData.FilenameOffset, SeekOrigin.Begin);
                string name = stream.ReadAsciiNullTerminatedString();

                stream.Seek(CalculateExtensionsOffset() + fileData.ExtensionOffset, SeekOrigin.Begin);
                string extension = stream.ReadAsciiNullTerminatedString();

                m_Files.Add(new PackfileEntry(this, fileData, name + "." + extension));
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:32,代码来源:Packfile.cs

示例2: AudioMetadata

        public AudioMetadata(Stream stream, IGameInstance instance)
        {
            Instance = instance;

            Header = stream.ReadStruct<AudioMetadataHeader>();
            
            if (Header.LipsyncSize > 0)
            {
                stream.Seek(0x24 + Header.LipsyncOffset, SeekOrigin.Begin);
                LipsyncData = new byte[Header.LipsyncSize];
                stream.Read(LipsyncData, 0, LipsyncData.Length);
            }

            if (Header.SubtitleSize > 0)
            {
                stream.Seek(0x24 + Header.SubtitleOffset, SeekOrigin.Begin);
                SubtitleHeader = stream.ReadStruct<AudioMetadataSubtitleHeader>();

                long subtitleOffset = stream.Position;
               
                for (int i = 0; i < SubtitleHeader.LocalizedVoiceSubtitleHeaders.Length; i++)
                {
                    LocalizedVoiceSubtitleHeader localizedVoiceSubtitleHeader = SubtitleHeader.LocalizedVoiceSubtitleHeaders[i];
                    Language language = (Language)i;

                    if (localizedVoiceSubtitleHeader.Length == 0)
                    {
                        Subtitles.Add(language, "");

                        continue;
                    }

                    long offset = subtitleOffset + localizedVoiceSubtitleHeader.Offset;
                    stream.Seek(offset, SeekOrigin.Begin);
                    byte[] subtitleData = new byte[localizedVoiceSubtitleHeader.Length];
                    stream.Read(subtitleData, 0, (int)localizedVoiceSubtitleHeader.Length);

                    var map = LanguageUtility.GetDecodeCharMap(instance, language);

                    StringBuilder subtitleBuilder = new StringBuilder();
                    for (int pos = 0; pos < subtitleData.Length; pos+=2)
                    {
                        char src = BitConverter.ToChar(subtitleData, pos);

                        char value = src;
                        if (map.ContainsKey(src))
                            value = map[src];

                        if (value == 0x00)
                            continue;

                        subtitleBuilder.Append(value);
                    }

                    string subtitle = subtitleBuilder.ToString();
                    Subtitles.Add(language, subtitle);
                }
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:59,代码来源:AudioMetadata.cs

示例3: Container

        public Container(Stream stream)
        {
            UInt16 stringLength = stream.ReadUInt16();
            Name = stream.ReadAsciiString(stringLength);
            ContainerType = stream.ReadUInt8();
            Flags = (ContainerFlags)stream.ReadUInt16();
            PrimitiveCount = stream.ReadUInt16();
            PackfileBaseOffset = stream.ReadUInt32();
            CompressionType = stream.ReadUInt8();
            stringLength = stream.ReadUInt16();
            StubContainerParentName = stream.ReadAsciiString(stringLength);
            Int32 auxDataSize = stream.ReadInt32();
            AuxData = new byte[auxDataSize];
            stream.Read(AuxData, 0, auxDataSize);
            TotalCompressedPackfileReadSize = stream.ReadInt32();

            Primitives = new List<Primitive>();
            PrimitiveSizes = new List<WriteTimeSizes>();

            for (UInt16 i = 0; i < PrimitiveCount; i++)
            {
                var sizes = stream.ReadStruct<WriteTimeSizes>();
                PrimitiveSizes.Add(sizes);
            }

            for (UInt16 i = 0; i < PrimitiveCount; i++)
            {
                Primitive primitive = new Primitive(stream);
                Primitives.Add(primitive);
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:31,代码来源:Container.cs

示例4: LoadHeader

        public Pe LoadHeader(Stream _ExeStream)
        {
            ExeStream = _ExeStream;
            DosExe = new DosExe().LoadHeader(ExeStream);
            PeStream = ExeStream.SliceWithLength(DosExe.Header.OffsetToPEHeader);
            PeHeader = PeStream.ReadStruct<PeHeaderStruct>();
            OptionalHeaderStream = PeStream.ReadStream(PeHeader.SizeOfOptionalHeader);
            PeOptionalHeader = OptionalHeaderStream.ReadStruct<PeOptionalHeaderStruct>();
            ImageSectionHeaderList = new ImageSectionHeader[PeHeader.NumSections];
            for (int n = 0; n < PeHeader.NumSections; n++)
            {
                ImageSectionHeaderList[n] = PeStream.ReadStruct<ImageSectionHeader>();
            }

            return this;
        }
开发者ID:soywiz-emulation,项目名称:cs360emu,代码行数:16,代码来源:Pe.cs

示例5: StreamingSoundbank

        public StreamingSoundbank(Stream s)
        {
            DataStream = new MemoryStream();
            s.CopyTo(DataStream);

            DataStream.Seek(0, SeekOrigin.Begin);

            Header = DataStream.ReadStruct<SoundbankHeader>();

            if (Header.Signature != 0x42535756)
                throw new InvalidDataException("File is not a streaming soundbank.");

            for (int i = 0; i < Header.NumFiles; i++)
            {
                var fileInfo = DataStream.ReadStruct<SoundbankEntryInfo>();
                var entry = new SoundbankEntry(this, fileInfo);
                Files.Add(entry);
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:19,代码来源:StreamingSoundbank.cs

示例6: read

        /*
         *
         * Programming Guide for DDS
         * https://msdn.microsoft.com/en-us/library/windows/desktop/bb943991(v=vs.85).aspx#File_Layout1
         *
         * File Structure
         *
         * DWORD               dwMagic;
         * DDS_HEADER          header;
         *
         * If the DDS_PIXELFORMAT dwFlags is set to DDPF_FOURCC and dwFourCC is set to "DX10" an additional DDS_HEADER_DXT10
         *
         * DDS_HEADER_DXT10    header10;
         *
         * A pointer to an array of bytes that contains the main surface data.
         *
         * BYTE bdata[]
         *
         * BYTE bdata2[]
         *
         */
        public static DDS read(Stream stream)
        {
            var dds = new DDS();

            int readIndex = 0;

            // Read headers

            DDS_Magic fileMagicData;

            readIndex += stream.ReadStruct(out fileMagicData);

            readIndex += stream.ReadStruct(out dds.ddsHeader);

            // Only read the ddsHeaderDXT10 when the FOURCC.DX10 is set
            if (dds.ddsHeader.ddspf.dwFourCC == DDS_PIXELFORMAT.FOURCC.DX10)
            {
                readIndex += stream.ReadStruct(out dds.ddsHeaderDXT10);
            }

            if (dds.ddsHeader.ddspf.dwFourCC != DDS_PIXELFORMAT.FOURCC.DXT1 ||
               (dds.ddsHeader.dwFlags & DDS_HEADER.Flags.DDSD_LINEARSIZE) == 0)
            {
                throw new NotImplementedException("Format not implemented");
            }

            // Initialize and read DXT1 blocks

            var size = dds.height * dds.width;

            dds.blocks = new DXT1Block[size];

            for (uint i = 0; i < size; i++)
            {
                DDS_DXT1Block block;
                readIndex += stream.ReadStruct(out block);

                dds.blocks[i] = block;
            }

            return dds;
        }
开发者ID:jonanh,项目名称:dxtc,代码行数:63,代码来源:DDS.Parse.cs

示例7: ReadChunk

 public Chunk ReadChunk(Stream Stream)
 {
     var ChunkSize = (uint)Stream.ReadStruct<uint_be>();
     //var ChunkType = (ushort)Stream.ReadStruct<ushort_be>();
     var ChunkStream = Stream.ReadStream(ChunkSize);
     return new Chunk()
     {
         Size = ChunkSize,
         //Type = ChunkType,
         Stream = ChunkStream,
     };
 }
开发者ID:e-COS,项目名称:cspspemu,代码行数:12,代码来源:Pmf.cs

示例8: Load

 public void Load(Stream Stream)
 {
     Entries = new Dictionary<string, Entry>();
     Stream.Position = 8;
     while (Stream.Position < Stream.Length)
     {
         var Entry = Stream.ReadStruct<Entry>();
         if (Entry.ImageId != 0)
         {
             Entries.Add(Entry.Name, Entry);
         }
     }
 }
开发者ID:talestra,项目名称:talestra,代码行数:13,代码来源:CgDb.cs

示例9: Load

        public Pmf Load(Stream Stream)
        {
            Header = Stream.ReadStruct<HeaderStruct>();

            var Chunk = ReadChunk(Stream.SliceWithLength(0x50));
            InfoHeader = Chunk.Stream.ReadStruct<InfoHeaderStruct>();
            /*
            Console.WriteLine("0x{0:X}", (ulong)InfoHeader.FirstTimestamp);
            Console.WriteLine("0x{0:X}", (ulong)InfoHeader.LastTimestamp);
            Console.WriteLine("{0}", (ulong)InfoHeader.Width);
            Console.WriteLine("{0}", (ulong)InfoHeader.Height);
            */

            return this;
        }
开发者ID:e-COS,项目名称:cspspemu,代码行数:15,代码来源:Pmf.cs

示例10: Load

		public virtual void Load(Stream FileStream, string Name)
		{
			FileStream = new MemoryStream(FileStream.ReadAll());

			this.FileStream = FileStream;

			this.Header = FileStream.ReadStruct<Elf.HeaderStruct>();
			if (this.Header.Magic != Elf.HeaderStruct.MagicEnum.ExpectedValue)
			{
				throw(new InvalidProgramException("Not an ELF File '" + Name + "'"));
			}

			if (this.Header.Machine != Elf.HeaderStruct.MachineEnum.ALLEGREX)
			{
				throw (new InvalidProgramException("Invalid Elf.Header.Machine"));
			}

			this.ProgramHeaders = FileStream.ReadStructVectorAt<Elf.ProgramHeader>(Header.ProgramHeaderOffset, Header.ProgramHeaderCount, Header.ProgramHeaderEntrySize);
			this.SectionHeaders = FileStream.ReadStructVectorAt<Elf.SectionHeader>(Header.SectionHeaderOffset, Header.SectionHeaderCount, Header.SectionHeaderEntrySize);

			this.NamesSectionHeader = this.SectionHeaders[Header.SectionHeaderStringTable];
			this.StringTable = FileStream.SliceWithLength(this.NamesSectionHeader.Offset, this.NamesSectionHeader.Size).ReadAll();

			this.SectionHeadersByName = new Dictionary<string, Elf.SectionHeader>();
			foreach (var SectionHeader in this.SectionHeaders)
			{
				var SectionHeaderName = GetStringFromStringTable(SectionHeader.Name);
				this.SectionHeadersByName[SectionHeaderName] = SectionHeader;
			}

			Console.WriteLine("ProgramHeaders:{0}", this.ProgramHeaders.Length);
			foreach (var ProgramHeader in ProgramHeaders)
			{
				Console.WriteLine("{0}", ProgramHeader.ToStringDefault());
			}

			Console.WriteLine("SectionHeaders:{0}", this.SectionHeaders.Length);
			foreach (var SectionHeader in SectionHeaders)
			{
				Console.WriteLine("{0}:{1}", GetStringFromStringTable(SectionHeader.Name), SectionHeader.ToStringDefault());
			}

			if (NeedsRelocation && this.ProgramHeaders.Length > 1)
			{
				//throw (new NotImplementedException("Not implemented several ProgramHeaders yet using relocation"));
			}
		}
开发者ID:shin527,项目名称:cspspemu,代码行数:47,代码来源:ElfLoader.cs

示例11: SaveFile

        public SaveFile(Stream s)
        {
            MainHeader = s.ReadStruct<SaveGameMainHeader>();

            while (s.Position < s.Length)
            {
                long sectionStart = s.Position;
                Section section = new Section(s);
                if (section.Size == 0 && section.Version == 0)
                    break;
                
                Console.WriteLine("Got {0} ({4:X2}) at {3:X4}. Version {1:X2}, {2:X4} bytes.", section.SectionId, section.Version, section.Size, sectionStart, (uint)section.SectionId);
                Sections.Add(section.SectionId, section);
            }

            Player = new PlayerSection(Sections[SectionId.GSSI_PLAYER]);
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:17,代码来源:SaveFile.cs

示例12: Load

		public Pbp Load(Stream Stream)
		{
			this.Stream = Stream;
			this.Header = Stream.ReadStruct<HeaderStruct>();
			this.Files = new Dictionary<string, Stream>();

			if (Header.Magic != HeaderStruct.MagicEnum.ExpectedValue)
			{
				throw(new Exception("Not a PBP file"));
			}

			var Offsets = Header.Offsets.Concat(new[] { (uint)Stream.Length }).ToArray();

			for (int n = 0; n < 8; n++)
			{
				Files[Names[n]] = Stream.SliceWithBounds(Offsets[n + 0], Offsets[n + 1]);
			}

			return this;
		}
开发者ID:shin527,项目名称:cspspemu,代码行数:20,代码来源:Pbp.cs

示例13: Load

 public Psf Load(Stream Stream)
 {
     EntryDictionary = new Dictionary<string, object>();
     Header = Stream.ReadStruct<HeaderStruct>();
     Entries = Stream.ReadStructVector<EntryStruct>(Header.NumberOfPairs);
     KeysStream = Stream.SliceWithLength(Header.KeyTable);
     ValuesStream = Stream.SliceWithLength(Header.ValueTable);
     foreach (var Entry in Entries)
     {
         var Key = KeysStream.ReadStringzAt(Entry.KeyOffset);
         var ValueStream = ValuesStream.SliceWithLength(Entry.ValueOffset, Entry.ValueSize);;
         switch (Entry.DataType)
         {
             case DataType.Binary: EntryDictionary[Key] = ValueStream.ReadAll(); break;
             case DataType.Int: EntryDictionary[Key] = ValueStream.ReadStruct<int>(); break;
             case DataType.Text: EntryDictionary[Key] = ValueStream.ReadStringz(-1, Encoding.UTF8); break;
             default: throw(new NotImplementedException());
         }
     }
     return this;
 }
开发者ID:e-COS,项目名称:cspspemu,代码行数:21,代码来源:Psf.cs

示例14: Stream2File

        public Stream2File(Stream stream)
        {
            Header = stream.ReadStruct<ContainerFileHeader>();

            uint allocatorTypeCount = stream.ReadUInt32();
            for (uint i = 0; i < allocatorTypeCount; i++)
            {
                UInt16 stringLength = stream.ReadUInt16();
                string name = stream.ReadAsciiString(stringLength);
                byte id = stream.ReadUInt8();
                AllocatorTypes.Add(id, name);
            }

            uint primitiveTypeCount = stream.ReadUInt32();
            for (uint i = 0; i < primitiveTypeCount; i++)
            {
                UInt16 stringLength = stream.ReadUInt16();
                string name = stream.ReadAsciiString(stringLength);
                byte id = stream.ReadUInt8();
                PrimitiveTypes.Add(id, name);
            }

            uint containerTypeCount = stream.ReadUInt32();
            for (uint i = 0; i < containerTypeCount; i++)
            {
                UInt16 stringLength = stream.ReadUInt16();
                string name = stream.ReadAsciiString(stringLength);
                byte id = stream.ReadUInt8();
                ContainerTypes.Add(id, name);
            }

            for (uint i = 0; i < Header.NumContainers; i++)
            {
                Container container = new Container(stream);
                Containers.Add(container);
            }
        }
开发者ID:rodrigonh,项目名称:ThomasJepp.SaintsRow,代码行数:37,代码来源:Stream2File.cs

示例15: Load

        public PGF Load(Stream FileStream)
        {
            this.Header = FileStream.ReadStruct<HeaderStruct>();

            if (this.Header.Revision >= 3)
            {
                this.HeaderExtraRevision3 = FileStream.ReadStruct<HeaderRevision3Struct>();
            }

            FileStream.ReadStructVector(ref DimensionTable, Header.TableDimLength);
            FileStream.ReadStructVector(ref XAdjustTable, Header.TableXAdjustLength);
            FileStream.ReadStructVector(ref YAdjustTable, Header.TableYAdjustLength);
            FileStream.ReadStructVector(ref AdvanceTable, Header.TableAdvanceLength);

            PackedShadowCharMap = FileStream.ReadBytes(BitsToBytesHighAligned(Header.TableShadowMapLength * Header.TableShadowMapBpe));

            if (Header.Revision == 3)
            {
                FileStream.ReadStructVector(ref CharmapCompressionTable1, HeaderExtraRevision3.TableCompCharMapLength1);
                FileStream.ReadStructVector(ref CharmapCompressionTable2, HeaderExtraRevision3.TableCompCharMapLength2);
            }

            PackedCharMap = FileStream.ReadBytes(BitsToBytesHighAligned(Header.TableCharMapLength * Header.TableCharMapBpe));
            PackedCharPointerTable = FileStream.ReadBytes(BitsToBytesHighAligned(Header.TableCharPointerLength * Header.TableCharPointerBpe));

            /*
            int BytesLeft = (int)(FileStream.Length - FileStream.Position);
            charData = new byte[BytesLeft];
            FileStream.Read(charData, 0, BytesLeft);
            */

            CharData = FileStream.ReadBytes((int)(FileStream.Length - FileStream.Position));

            var NumberOfCharacters = Header.TableCharPointerLength;

            CharMap = new int[Header.FirstGlyph + Header.LastGlyph + 1];
            CharPointer = new int[NumberOfCharacters];
            Glyphs = new Glyph[NumberOfCharacters];
            ReverseCharMap = new Dictionary<int, int>();
            ShadowCharMap = new Dictionary<int, int>();
            ReverseShadowCharMap = new Dictionary<int, int>();

            foreach (var Pair in BitReader.FixedBitReader(PackedShadowCharMap, Header.TableShadowMapBpe))
            {
                var UnicodeIndex = (int)Pair.Key + Header.FirstGlyph;
                var GlyphIndex = (int)Pair.Value;
                ShadowCharMap[UnicodeIndex] = GlyphIndex;
                ReverseShadowCharMap[GlyphIndex] = UnicodeIndex;
            }

            foreach (var Pair in BitReader.FixedBitReader(PackedCharMap, Header.TableCharMapBpe))
            {
                var UnicodeIndex = (int)Pair.Key + Header.FirstGlyph;
                var GlyphIndex = (int)Pair.Value;
                CharMap[UnicodeIndex] = GlyphIndex;
                ReverseCharMap[GlyphIndex] = UnicodeIndex;
            }

            foreach (var Pair in BitReader.FixedBitReader(PackedCharPointerTable, Header.TableCharPointerBpe))
            {
                CharPointer[Pair.Key] = (int)Pair.Value;
            }

            /*
            for (int n = 0; n < NumberOfCharacters; n++)
            {
                Glyphs[n] = new Glyph().Read(this, n);
            }
            */

            Console.WriteLine(this.Header.FontName);

            /*
            Console.WriteLine(this.header.fontName);
            for (int n = 0; n < 300; n++)
            {
                Console.WriteLine(GetGlyphId((char)n));
            }
            */

            return this;
        }
开发者ID:soywiz,项目名称:cspspemu,代码行数:82,代码来源:PGF.cs


注:本文中的Stream.ReadStruct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。