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


C# IStream.WriteBlock方法代码示例

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


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

示例1: InjectPage

		public int InjectPage(IStream cacheStream, ResourcePage page, byte[] data)
		{
			const int pageSize = 0x1000;

			// Calculate how many pages we need to add to the raw table
			var pagesNeeded = (int)(Math.Ceiling(page.CompressedSize / (double)pageSize));

			// calculate sizes, positions and resize the raw table
			var injectSize = pagesNeeded * pageSize;
			var offsetInCache = (_rawTable.Offset + _rawTable.Size);
			var offsetInRaw = (_rawTable.Size);
			_rawTable.Resize(_rawTable.Size + injectSize, cacheStream);

			// write the raw page into the table
			cacheStream.SeekTo(offsetInCache);
			cacheStream.WriteBlock(data);

			return offsetInRaw;
		}
开发者ID:t3hm00kz,项目名称:Assembly,代码行数:19,代码来源:ResourcePageInjector.cs

示例2: WriteDataBlock

		private void WriteDataBlock(DataBlock block, SegmentPointer location, IStream stream, ITag tag = null)
		{
			if (tag == null && _dataBlockAddresses.ContainsKey(block)) // Don't write anything if the block has already been written
				return;

			// Associate the location with the block
			_dataBlockAddresses[block] = location.AsPointer();

			// Create a MemoryStream and write the block data to it (so fixups can be performed before writing it to the file)
			using (var buffer = new MemoryStream(block.Data.Length))
			{
				var bufferWriter = new EndianWriter(buffer, stream.Endianness);
				bufferWriter.WriteBlock(block.Data);

				// Apply fixups
				FixBlockReferences(block, bufferWriter, stream);
				FixTagReferences(block, bufferWriter, stream);
				FixResourceReferences(block, bufferWriter, stream);
				FixStringIdReferences(block, bufferWriter);
				if (tag != null)
					FixUnicListReferences(block, tag, bufferWriter, stream);

				// Write the buffer to the file
				stream.SeekTo(location.AsOffset());
				stream.WriteBlock(buffer.GetBuffer(), 0, (int) buffer.Length);
			}

			// Write shader fixups (they can't be done in-memory because they require cache file expansion)
			FixShaderReferences(block, stream, location);
		}
开发者ID:t3hm00kz,项目名称:Assembly,代码行数:30,代码来源:TagContainerInjector.cs

示例3: SaveStrings

        public void SaveStrings(IStream stream, List<LocalizedString> locales)
        {
            var offsetData = new MemoryStream();
            var stringData = new MemoryStream();
            var offsetWriter = new EndianWriter(offsetData, Endian.BigEndian);
            var stringWriter = new EndianWriter(stringData, Endian.BigEndian);

            try
            {
                // Write the string and offset data to buffers
                foreach (LocalizedString locale in locales)
                {
                    WriteLocalePointer(offsetWriter, locale.Key, (int) stringWriter.Position);
                    stringWriter.WriteUTF8(locale.Value);
                }

                // Round the size of the string data up
                var dataSize = (int) ((stringData.Position + _sizeAlign - 1) & ~(_sizeAlign - 1));
                stringData.SetLength(dataSize);

                // Update the two locale data hashes if we need to
                // (the hash arrays are set to null if the build doesn't need them)
                if (IndexTableHash != null)
                    IndexTableHash = SHA1.Transform(offsetData.GetBuffer(), 0, (int) offsetData.Length);
                if (StringDataHash != null)
                    StringDataHash = SHA1.Transform(stringData.GetBuffer(), 0, dataSize);

                // Make sure there's free space for the offset table and then write it to the file
                LocaleIndexTable.Resize((int) offsetData.Length, stream);
                stream.SeekTo(LocaleIndexTableLocation.AsOffset());
                stream.WriteBlock(offsetData.GetBuffer(), 0, (int) offsetData.Length);

                // Encrypt the string data if necessary
                byte[] strings = stringData.GetBuffer();
                if (_encryptionKey != null)
                    strings = AES.Encrypt(strings, 0, dataSize, _encryptionKey.Key, _encryptionKey.IV);

                // Make sure there's free space for the string data and then write it to the file
                LocaleData.Resize(dataSize, stream);
                stream.SeekTo(LocaleDataLocation.AsOffset());
                stream.WriteBlock(strings, 0, dataSize);

                // Update the string count and recalculate the language table offsets
                StringCount = locales.Count;
            }
            finally
            {
                offsetWriter.Close();
                stringWriter.Close();
            }
        }
开发者ID:ChadSki,项目名称:Assembly,代码行数:51,代码来源:ThirdGenLanguage.cs

示例4: ImportShader

		/// <summary>
		/// Deserializes a serialized shader and injects it into the cache file.
		/// </summary>
		/// <param name="serializedShader">The serialized shader data to inject.</param>
		/// <param name="stream">The stream to manipulate. It should be positioned where the shader pointer should be written.</param>
		/// <returns>
		///   <c>true</c> if the shader was successfully deserialized and injected.
		/// </returns>
		public bool ImportShader(byte[] serializedShader, IStream stream)
		{
			if (serializedShader == null || serializedShader.Length == 0)
			{
				// Null shader
				stream.WriteUInt32(0);
				return true;
			}

			var pointerOffset = stream.Position + _cacheFile.MetaArea.OffsetToPointer(0);
			using (var reader = new EndianReader(new MemoryStream(serializedShader), Endian.BigEndian))
			{
				// Check the magic
				if (reader.ReadInt32() != SerializationMagic)
					return false;

				// Read the shader type and determine which info layout to use
				var type = (ShaderType)reader.ReadByte();
				StructureLayout infoLayout = null;
				if (type == ShaderType.Pixel)
					infoLayout = _pixelShaderInfoLayout;
				else if (type == ShaderType.Vertex)
					infoLayout = _vertexShaderInfoLayout;
				if (infoLayout == null)
					return false;

				// Read and verify the layout size
				var infoLayoutSize = reader.ReadInt32();
				if (infoLayoutSize != infoLayout.Size)
					return false;

				// Read the raw debug info and data
				var debugInfoSize = reader.ReadUInt32();
				var debugInfo = reader.ReadBlock((int)debugInfoSize);
				var dataSize = reader.ReadUInt32();
				var data = reader.ReadBlock((int)dataSize);

				// Allocate space for the shader data and write it in
				var dataAddr = _cacheFile.Allocator.Allocate((int)dataSize, 0x10, stream); // 16-byte aligned
				var dataOffset = _cacheFile.MetaArea.PointerToOffset(dataAddr);
				stream.SeekTo(dataOffset);
				stream.WriteBlock(data);

				// Allocate and zero space for the info structures
				var infoSize = infoLayoutSize + (int)debugInfoSize;
				var infoAddr = _cacheFile.Allocator.Allocate(infoSize, stream);
				var infoOffset = _cacheFile.MetaArea.PointerToOffset(infoAddr);
				stream.SeekTo(infoOffset);
				StreamUtil.Fill(stream, 0, infoSize);

				// Write the basic info structure
				stream.SeekTo(infoOffset);
				var infoValues = new StructureValueCollection();
				infoValues.SetInteger("shader data address", dataAddr);
				StructureWriter.WriteStructure(infoValues, infoLayout, stream);

				// Write the debug info structure
				stream.WriteBlock(debugInfo);

				// Finally, write the shader pointer
				stream.SeekTo(pointerOffset - _cacheFile.MetaArea.OffsetToPointer(0));
				stream.WriteUInt32(infoAddr);
			}
			return true;
		}
开发者ID:t3hm00kz,项目名称:Assembly,代码行数:73,代码来源:ThirdGenShaderStreamer.cs

示例5: SaveResourceInfoBuffer

        private void SaveResourceInfoBuffer(byte[] buffer, StructureValueCollection values, IStream stream)
        {
            // Free the old info buffer
            var oldSize = (int) values.GetInteger("resource info buffer size");
            uint oldAddress = values.GetInteger("resource info buffer address");
            if (oldAddress >= 0 && oldSize > 0)
                _allocator.Free(oldAddress, oldSize);

            // Write a new one
            uint newAddress = 0;
            if (buffer.Length > 0)
            {
                newAddress = _allocator.Allocate(buffer.Length, 0x10, stream);
                stream.SeekTo(_metaArea.PointerToOffset(newAddress));
                stream.WriteBlock(buffer);
            }

            // Update values
            values.SetInteger("resource info buffer size", (uint) buffer.Length);
            values.SetInteger("resource info buffer address", newAddress);
        }
开发者ID:Cloms,项目名称:Assembly,代码行数:21,代码来源:ThirdGenResourceGestalt.cs

示例6: WriteDataBlock

        private void WriteDataBlock(DataBlock block, SegmentPointer location, IStream stream)
        {
            // Don't write anything if the block has already been written
            if (_dataBlockAddresses.ContainsKey(block))
                return;

            // Associate the location with the block
            _dataBlockAddresses[block] = location.AsPointer();

            // Create a MemoryStream and write the block data to it (so fixups can be performed before writing it to the file)
            using (var buffer = new MemoryStream(block.Data.Length))
            {
                var bufferWriter = new EndianWriter(buffer, stream.Endianness);
                bufferWriter.WriteBlock(block.Data);

                // Apply fixups
                FixBlockReferences(block, bufferWriter, stream);
                FixTagReferences(block, bufferWriter, stream);
                FixResourceReferences(block, bufferWriter, stream);
                FixStringIDReferences(block, bufferWriter);

                // Write the buffer to the file
                stream.SeekTo(location.AsOffset());
                stream.WriteBlock(buffer.GetBuffer(), 0, (int) buffer.Length);
            }
        }
开发者ID:Cloms,项目名称:Assembly,代码行数:26,代码来源:TagContainerInjector.cs

示例7: Insert

        /// <summary>
        /// Inserts space into a stream by copying everything back by a certain number of bytes.
        /// </summary>
        /// <param name="stream">The stream to insert space into.</param>
        /// <param name="size">The size of the space to insert.</param>
        /// <param name="fill">The byte to fill the inserted space with. See <see cref="Fill"/>.</param>
        public static void Insert(IStream stream, int size, byte fill)
        {
            if (size == 0)
                return;
            if (size < 0)
                throw new ArgumentException("The size of the data to insert must be >= 0");
            if (stream.Position == stream.Length)
                return; // Seeking past the end automatically increases the file size

            const int BufferSize = 0x1000;
            byte[] buffer = new byte[BufferSize];
            int endPos = (int)stream.Position;
            int oldLength = (int)stream.Length;
            int pos = Math.Max(endPos, oldLength - BufferSize);
            while (pos >= endPos)
            {
                int read = Math.Min(BufferSize, oldLength - pos);
                stream.SeekTo(pos);
                stream.ReadBlock(buffer, 0, read);

                stream.SeekTo(pos + size);
                stream.WriteBlock(buffer, 0, read);
                pos -= read;
            }

            stream.SeekTo(endPos);
            Fill(stream, fill, size);
        }
开发者ID:YxCREATURExY,项目名称:Assembly,代码行数:34,代码来源:StreamUtil.cs

示例8: Copy

        /// <summary>
        ///     Copies data between two locations in the same stream.
        ///     The source and destination areas may overlap.
        /// </summary>
        /// <param name="stream">The stream to copy data in.</param>
        /// <param name="originalPos">The position of the block of data to copy.</param>
        /// <param name="targetPos">The position to copy the block to.</param>
        /// <param name="size">The number of bytes to copy.</param>
        public static void Copy(IStream stream, long originalPos, long targetPos, long size)
        {
            if (size == 0)
                return;
            if (size < 0)
                throw new ArgumentException("The size of the data to copy must be >= 0");

            const int BufferSize = 0x1000;
            var buffer = new byte[BufferSize];
            long remaining = size;
            while (remaining > 0)
            {
                var read = (int) Math.Min(BufferSize, remaining);

                if (targetPos > originalPos)
                    stream.SeekTo(originalPos + remaining - read);
                else
                    stream.SeekTo(originalPos + size - remaining);

                stream.ReadBlock(buffer, 0, read);

                if (targetPos > originalPos)
                    stream.SeekTo(targetPos + remaining - read);
                else
                    stream.SeekTo(targetPos + size - remaining);

                stream.WriteBlock(buffer, 0, read);
                remaining -= read;
            }
        }
开发者ID:ChadSki,项目名称:Assembly,代码行数:38,代码来源:StreamUtil.cs

示例9: SaveStrings

        public void SaveStrings(IStream stream, LocaleTable locales)
        {
            MemoryStream offsetData = new MemoryStream();
            MemoryStream stringData = new MemoryStream();
            IWriter offsetWriter = new EndianWriter(offsetData, Endian.BigEndian);
            IWriter stringWriter = new EndianWriter(stringData, Endian.BigEndian);

            try
            {
                // Write the string and offset data to buffers
                foreach (Locale locale in locales.Strings)
                {
                    WriteLocalePointer(offsetWriter, locale.ID, (int)stringWriter.Position);
                    stringWriter.WriteUTF8(locale.Value);
                }

                // Round the size of the string data up to the nearest multiple of 0x10 (AES block size)
                stringData.SetLength((stringData.Position + 0xF) & ~0xF);

                // Update the two locale data hashes if we need to
                // (the hash arrays are set to null if the build doesn't need them)
                if (IndexTableHash != null)
                    IndexTableHash = SHA1.Transform(offsetData.GetBuffer(), 0, (int)offsetData.Length);
                if (StringDataHash != null)
                    StringDataHash = SHA1.Transform(stringData.GetBuffer(), 0, (int)stringData.Length);

                // Make sure there's free space for the offset table and then write it to the file
                LocaleDataLocation += StreamUtil.MakeFreeSpace(stream, LocaleIndexTableLocation.AsOffset(), LocaleDataLocation.AsOffset(), offsetData.Length, _pageSize);
                stream.SeekTo(LocaleIndexTableLocation.AsOffset());
                stream.WriteBlock(offsetData.GetBuffer(), 0, (int)offsetData.Length);

                // Encrypt the string data if necessary
                byte[] strings = stringData.GetBuffer();
                if (_encryptionKey != null)
                    strings = AES.Encrypt(strings, 0, (int)stringData.Length, _encryptionKey.Key, _encryptionKey.IV);

                // Make free space for the string data
                uint oldDataEnd = (uint)((LocaleDataLocation.AsOffset() + LocaleTableSize + _pageSize - 1) & ~(_pageSize - 1)); // Add the old table size and round it up
                StreamUtil.MakeFreeSpace(stream, LocaleDataLocation.AsOffset(), oldDataEnd, stringData.Length, _pageSize);
                LocaleTableSize = (int)stringData.Length;

                // Write it to the file
                stream.SeekTo(LocaleDataLocation.AsOffset());
                stream.WriteBlock(strings, 0, (int)stringData.Length);

                // Update the string count and recalculate the language table offsets
                StringCount = locales.Strings.Count;

                int localePointerSize = (int)(offsetData.Length / locales.Strings.Count);
                _languageGlobals.RecalculateLanguageOffsets(localePointerSize);
            }
            finally
            {
                offsetWriter.Close();
                stringWriter.Close();
            }
        }
开发者ID:YxCREATURExY,项目名称:Assembly,代码行数:57,代码来源:ThirdGenLanguage.cs


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