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


C# IReader.ReadBlock方法代码示例

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


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

示例1: ReadPatchInfo

		private static void ReadPatchInfo(IReader reader, byte version, Patch output)
		{
			// Version 0 (all versions)
			output.MapID = reader.ReadInt32();
			output.MapInternalName = reader.ReadAscii();
			output.Name = reader.ReadUTF16();
			output.Description = reader.ReadUTF16();
			output.Author = reader.ReadUTF16();

			int screenshotLength = reader.ReadInt32();
			if (screenshotLength > 0)
				output.Screenshot = reader.ReadBlock(screenshotLength);

			// Version 1
			if (version >= 1)
			{
				output.MetaPokeBase = reader.ReadUInt32();
				output.MetaChangesIndex = reader.ReadSByte();
			}

			// Version 2
			if (version >= 2)
				output.OutputName = reader.ReadAscii();
			else
				output.OutputName = "";
		}
开发者ID:t3hm00kz,项目名称:Assembly,代码行数:26,代码来源:AssemblyPatchLoader.cs

示例2: LoadCacheFile

        /// <summary>
        ///     Loads a cache file from a stream.
        /// </summary>
        /// <param name="reader">The stream to read from.</param>
        /// <param name="engineDb">The engine database to use to process the cache file.</param>
        /// <param name="engineInfo">On output, this will contain the cache file's engine description.</param>
        /// <returns>The cache file that was loaded.</returns>
        /// <exception cref="ArgumentException">Thrown if the cache file is invalid.</exception>
        /// <exception cref="NotSupportedException">Thrown if the cache file's target engine is not supported.</exception>
        public static ICacheFile LoadCacheFile(IReader reader, EngineDatabase engineDb, out EngineDescription engineInfo)
        {
            // Set the reader's endianness based upon the file's header magic
            reader.SeekTo(0);
            byte[] headerMagic = reader.ReadBlock(4);
            reader.Endianness = DetermineCacheFileEndianness(headerMagic);

            // Load engine version info
            var version = new CacheFileVersionInfo(reader);
            if (version.Engine != EngineType.SecondGeneration && version.Engine != EngineType.ThirdGeneration)
                throw new NotSupportedException("Engine not supported");

            // Load build info
            engineInfo = engineDb.FindEngineByVersion(version.BuildString);
            if (engineInfo == null)
                throw new NotSupportedException("Engine version \"" + version.BuildString + "\" not supported");

            // Load the cache file depending upon the engine version
            switch (version.Engine)
            {
                case EngineType.SecondGeneration:
                    return new SecondGenCacheFile(reader, engineInfo, version.BuildString);

                case EngineType.ThirdGeneration:
                    return new ThirdGenCacheFile(reader, engineInfo, version.BuildString);

                default:
                    throw new NotSupportedException("Engine not supported");
            }
        }
开发者ID:ChadSki,项目名称:Assembly,代码行数:39,代码来源:CacheFileLoader.cs

示例3: ReadByteArray

 private static byte[] ReadByteArray(IReader reader)
 {
     int size = reader.ReadInt32();
     if (size <= 0)
         return new byte[0];
     return reader.ReadBlock(size);
 }
开发者ID:ChadSki,项目名称:Assembly,代码行数:7,代码来源:TagContainerReader.cs

示例4: LoadPatch

        public static Patch LoadPatch(IReader reader, bool isAlteration)
        {
            Patch patch = new Patch();
            SegmentChange change = new SegmentChange(0, 0, 0, 0, true);
            patch.Author = "Ascension/Alteration Patch";
            patch.Description = "Ascension/Alteration Patch";
            if (isAlteration)
            {
                //do shitty alteration stuff
                byte authorLength = reader.ReadByte();
                patch.Author = reader.ReadAscii((int)authorLength);
                byte descLength = reader.ReadByte();
                patch.Description = reader.ReadAscii((int)descLength);

            }
            //create ascension patch object and change segment

            while (!reader.EOF)
            {
                //get valuable info
                var segmentOffset = reader.ReadUInt32();
                var segmentSize = reader.ReadInt32();
                var segmentData = reader.ReadBlock(segmentSize);

                //Add change data

                change.DataChanges.Add(new DataChange(segmentOffset, segmentData));

            }
            patch.SegmentChanges.Add(change);
            return patch;
        }
开发者ID:iBotPeaches,项目名称:Assembly,代码行数:32,代码来源:OldPatchLoader.cs

示例5: LoadCacheFile

        /// <summary>
        ///     Loads a cache file from a stream.
        /// </summary>
        /// <param name="reader">The stream to read from.</param>
        /// <param name="engineDb">The engine database to use to process the cache file.</param>
        /// <param name="engineInfo">On output, this will contain the cache file's engine description.</param>
        /// <returns>The cache file that was loaded.</returns>
        /// <exception cref="ArgumentException">Thrown if the cache file is invalid.</exception>
        /// <exception cref="NotSupportedException">Thrown if the cache file's target engine is not supported.</exception>
        public static ICacheFile LoadCacheFile(IReader map_reader, IReader tag_reader, IReader string_reader, out string tagnamesLocation, string filesLocation, EngineDatabase engineDb, out EngineDescription engineInfo)
        {
            // Set the reader's endianness based upon the file's header magic
            map_reader.SeekTo(0);
            byte[] headerMagic = map_reader.ReadBlock(4);
            Endian engianess = DetermineCacheFileEndianness(headerMagic);
            map_reader.Endianness = engianess;
            if(tag_reader != null) tag_reader.Endianness = engianess;
            if (tag_reader != null) string_reader.Endianness = engianess;

            // Load engine version info
            var version = new CacheFileVersionInfo(map_reader);
            if (version.Engine != EngineType.SecondGeneration && version.Engine != EngineType.ThirdGeneration && version.Engine != EngineType.FourthGeneration)
                throw new NotSupportedException("Engine not supported");

            // Load build info
            engineInfo = engineDb.FindEngineByVersion(version.BuildString);
            if (engineInfo == null)
                throw new NotSupportedException("Engine version \"" + version.BuildString + "\" not supported");

            // Load the cache file depending upon the engine version
            switch (version.Engine)
            {
                case EngineType.SecondGeneration:
                    tagnamesLocation = null;
                    return new SecondGenCacheFile(map_reader, engineInfo, version.BuildString);

                case EngineType.ThirdGeneration:
                    tagnamesLocation = null;
                    return new ThirdGenCacheFile(map_reader, engineInfo, version.BuildString);

                case EngineType.FourthGeneration:
                    if (tag_reader == null || tag_reader.BaseStream.Length == 0) throw new Exception("Can't load version 4 cache file without tags file. Please make sure that tags.dat is in the same folder at the map file.");
                    if (string_reader == null || tag_reader.BaseStream.Length == 0) throw new Exception("Can't load version 4 cache file without strings file. Please make sure that tags.dat is in the same folder at the map file.");

                    // Load the tag names csv file
                    string tagnames_filename = "tagnames_" + version.BuildString + ".csv";
                    string tagnames_location = filesLocation != null ? filesLocation + tagnames_filename : "";
                    if (!File.Exists(tagnames_location)) tagnames_location = "tagnames\\" + tagnames_filename;
                    if (!File.Exists(tagnames_location)) tagnames_location = null;

                    FileStream tagnamesFileStream = tagnames_location != null ? TryInitFilestream(tagnames_location) : null;
                    EndianReader tagnames_reader = null;
                    if (tagnamesFileStream != null)
                    {
                        tagnames_reader = new EndianReader(tagnamesFileStream, Endian.BigEndian);
                        tagnames_reader.Endianness = engianess;
                    }

                    tagnamesLocation = tagnames_location;

                    FourthGenCacheFile cache_file = new FourthGenCacheFile(map_reader, tag_reader, string_reader, tagnames_reader, engineInfo, version.BuildString);
                    tagnamesFileStream.Close();
                    return cache_file;

                default:
                    throw new NotSupportedException("Engine not supported");
            }
        }
开发者ID:no1dead,项目名称:Assembly,代码行数:68,代码来源:CacheFileLoader.cs

示例6: Copy

 public static void Copy(IReader input, IWriter output)
 {
     // http://stackoverflow.com/questions/230128/best-way-to-copy-between-two-stream-instances-c-sharp
     const int BufferSize = 0x1000;
     byte[] buffer = new byte[BufferSize];
     int read;
     while ((read = input.ReadBlock(buffer, 0, BufferSize)) > 0)
         output.WriteBlock(buffer, 0, read);
 }
开发者ID:0xdeafcafe,项目名称:vintage,代码行数:9,代码来源:StreamUtil.cs

示例7: ReadBlfInfo

        private static void ReadBlfInfo(IReader reader, Patch output)
        {
            // Version 0 (all versions)
            var targetGame = (TargetGame) reader.ReadByte();
            string mapInfoFileName = reader.ReadAscii();
            uint mapInfoLength = reader.ReadUInt32();
            byte[] mapInfo = reader.ReadBlock((int) mapInfoLength);
            short blfContainerCount = reader.ReadInt16();
            output.CustomBlfContent = new BlfContent(mapInfoFileName, mapInfo, targetGame);
            for (int i = 0; i < blfContainerCount; i++)
            {
                string fileName = Path.GetFileName(reader.ReadAscii());
                uint blfContainerLength = reader.ReadUInt32();
                byte[] blfContainer = reader.ReadBlock((int) blfContainerLength);

                output.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(fileName, blfContainer));
            }
        }
开发者ID:ChadSki,项目名称:Assembly,代码行数:18,代码来源:AssemblyPatchLoader.cs

示例8: DecryptData

        private IReader DecryptData(IReader reader, Pointer dataLocation, int tableSize, AESKey key)
        {
            // Round the table size to an AES block size
            tableSize = (tableSize + 0xF) & ~0xF;

            reader.SeekTo(dataLocation.AsOffset());
            byte[] data = reader.ReadBlock(tableSize);
            if (key != null)
                data = AES.Decrypt(data, key.Key, key.IV);
            return new EndianReader(new MemoryStream(data), Endian.BigEndian);
        }
开发者ID:YxCREATURExY,项目名称:Assembly,代码行数:11,代码来源:ThirdGenStringTable.cs

示例9: ReadMetaChanges

        private static void ReadMetaChanges(IReader reader, Patch output)
        {
            byte version = reader.ReadByte();

            // Version 0 (all versions)
            uint num4ByteChanges = 0;
            for (uint i = 0; i < num4ByteChanges; i++)
            {
                uint address = reader.ReadUInt32();
                byte[] data = reader.ReadBlock(4);
                output.MetaChanges.Add(new MetaChange(address, data));
            }

            uint numChanges = 0;
            for (uint i = 0; i < numChanges; i++)
            {
                uint address = reader.ReadUInt32();
                uint dataSize = reader.ReadUInt32();
                byte[] data = reader.ReadBlock((int)dataSize);
                output.MetaChanges.Add(new MetaChange(address, data));
            }
        }
开发者ID:YxCREATURExY,项目名称:Assembly,代码行数:22,代码来源:AssemblyPatchLoader.cs

示例10: ReadBlfInfo

        private static void ReadBlfInfo(IReader reader, Patch output)
        {
            // ReSharper disable UnusedVariable
            var version = reader.ReadByte();
            // ReSharper restore UnusedVariable

            // Version 0 (all versions)
            var targetGame = (TargetGame)reader.ReadByte();
            var mapInfoFileName = reader.ReadAscii();
            var mapInfoLength = reader.ReadUInt32();
            var mapInfo = reader.ReadBlock((int)mapInfoLength);
            var blfContainerCount = reader.ReadInt16();
            output.CustomBlfContent = new BlfContent(mapInfoFileName, mapInfo, targetGame);
            for (var i = 0; i < blfContainerCount; i++)
            {
                var fileName = Path.GetFileName(reader.ReadAscii());
                var blfContainerLength = reader.ReadUInt32();
                var blfContainer = reader.ReadBlock((int)blfContainerLength);

                output.CustomBlfContent.BlfContainerEntries.Add(new BlfContainerEntry(fileName, blfContainer));
            }
        }
开发者ID:iBotPeaches,项目名称:Assembly,代码行数:22,代码来源:AssemblyPatchLoader.cs

示例11: ReadShader

		/// <summary>
		/// Reads a shader from a stream.
		/// </summary>
		/// <param name="reader">The stream to read from. It should be positioned at the beginning of the shader pointer.</param>
		/// <param name="type">The type of shader to read.</param>
		/// <returns>
		/// The shader that was read, or <c>null</c> if reading failed.
		/// </returns>
		public IShader ReadShader(IReader reader, ShaderType type)
		{
			var info = ReadShaderInfo(reader, type);
			if (info == null || info.CodeDataSize == 0)
				return null;
			
			// Read the code data
			var dataOffset = _cacheFile.MetaArea.PointerToOffset(info.DataAddress);
			reader.SeekTo(dataOffset + info.ConstantDataSize); // Code data comes after the constant data
			var microcode = reader.ReadBlock((int)info.CodeDataSize);

			return new ThirdGenShader(type, microcode, info.DatabasePath);
		}
开发者ID:t3hm00kz,项目名称:Assembly,代码行数:21,代码来源:ThirdGenShaderStreamer.cs

示例12: CompareMeta

        /// <summary>
        /// Compares the tag meta between two cache files and adds the results to a patch.
        /// </summary>
        /// <param name="originalFile">The unmodified cache file.</param>
        /// <param name="originalReader">A stream open on the unmodified cache file.</param>
        /// <param name="newFile">The modified cache file.</param>
        /// <param name="newReader">A stream open on the modified cache file.</param>
        /// <param name="output">The Patch to add results to.</param>
        public static void CompareMeta(ICacheFile originalFile, IReader originalReader, ICacheFile newFile, IReader newReader, Patch output)
        {
            // TODO: Handle files with expanded meta partitions
            uint address = originalFile.Info.MetaBase.AsAddress();
            uint offset = originalFile.Info.MetaBase.AsOffset();
            uint endOffset = offset + originalFile.Info.MetaSize;

            const int BufferSize = 0x1000;
            byte[] oldBuffer = new byte[BufferSize];
            byte[] newBuffer = new byte[BufferSize];

            int diffStart = 0;
            uint diffAddress = 0;
            int diffSize = 0;

            originalReader.SeekTo(offset);
            newReader.SeekTo(offset);
            while (offset < endOffset)
            {
                // Read the meta in large blocks and then compare the blocks
                originalReader.ReadBlock(oldBuffer, 0, BufferSize);
                newReader.ReadBlock(newBuffer, 0, BufferSize);
                for (int i = 0; i < oldBuffer.Length; i++)
                {
                    if (oldBuffer[i] != newBuffer[i])
                    {
                        if (diffSize == 0)
                        {
                            diffStart = i;
                            diffAddress = (uint)(address + i);
                        }
                        diffSize++;
                    }
                    else if (diffSize > 0)
                    {
                        // Copy the differing bytes to a buffer
                        byte[] diff = new byte[diffSize];
                        Array.Copy(newBuffer, diffStart, diff, 0, diffSize);

                        // Export the change data
                        MetaChange change = new MetaChange((uint)(address + i), diff);
                        output.MetaChanges.Add(change);

                        diffSize = 0;
                    }
                }

                offset += BufferSize;
                address += BufferSize;
            }
        }
开发者ID:YxCREATURExY,项目名称:Assembly,代码行数:59,代码来源:MetaComparer.cs

示例13: ExportShader

        /// <summary>
        /// Reads a shader from a stream and then serializes it into a byte array which can then be exported.
        /// </summary>
        /// <param name="reader">The stream to read from. It should be positioned at the beginning of the shader pointer.</param>
        /// <param name="type">The type of shader to read.</param>
        /// <returns>
        /// The serialized shader data, or <c>null</c> if reading failed.
        /// </returns>
        public byte[] ExportShader(IReader reader, ShaderType type)
        {
            var info = ReadShaderInfo(reader, type);
            if (info == null)
                return null;

            using (var memStream = new MemoryStream())
            {
                using (var writer = new EndianWriter(memStream, Endian.BigEndian))
                {
                    writer.WriteInt32(SerializationMagic);
                    writer.WriteByte((byte)type);

                    // Write the layout size for compatibility checking when deserializing
                    if (type == ShaderType.Pixel)
                        writer.WriteInt32(_pixelShaderInfoLayout.Size);
                    else
                        writer.WriteInt32(_vertexShaderInfoLayout.Size);

                    // Write the raw debug info
                    reader.SeekTo(info.DebugInfoOffset);
                    writer.WriteUInt32(info.DebugInfoSize);
                    writer.WriteBlock(reader.ReadBlock((int)info.DebugInfoSize));

                    // Write the raw shader data
                    var dataOffset = _cacheFile.MetaArea.PointerToOffset(info.DataAddress);
                    reader.SeekTo(dataOffset);
                    writer.WriteUInt32(info.DataSize);
                    writer.WriteBlock(reader.ReadBlock((int)info.DataSize));

                    // Create the result from the memory stream's buffer
                    var result = new byte[memStream.Length];
                    Buffer.BlockCopy(memStream.GetBuffer(), 0, result, 0, (int)memStream.Length);
                    return result;
                }
            }
        }
开发者ID:ChadSki,项目名称:Assembly,代码行数:45,代码来源:ThirdGenShaderStreamer.cs

示例14: ReadByteArray

		private static byte[] ReadByteArray(IReader reader)
		{
			var size = reader.ReadInt32();
			return size <= 0 ? new byte[0] : reader.ReadBlock(size);
		}
开发者ID:t3hm00kz,项目名称:Assembly,代码行数:5,代码来源:TagContainerReader.cs

示例15: LoadResourceInfoBuffer

        private byte[] LoadResourceInfoBuffer(StructureValueCollection values, IReader reader)
        {
            var size = (int) values.GetInteger("resource info buffer size");
            uint address = values.GetInteger("resource info buffer address");
            if (size <= 0 || address == 0)
                return new byte[0];

            int offset = _metaArea.PointerToOffset(address);
            reader.SeekTo(offset);
            return reader.ReadBlock(size);
        }
开发者ID:Cloms,项目名称:Assembly,代码行数:11,代码来源:ThirdGenResourceGestalt.cs


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