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


C# Stream.WriteValueS32方法代码示例

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


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

示例1: Serialize

		public void Serialize(Stream output, Endian endian) {
			output.WriteValueU32(this.Size, endian);
			output.WriteValueEnum<HeaderFlags>(this.Flags, endian);
			output.WriteValueS32(this.Height, endian);
			output.WriteValueS32(this.Width, endian);
			output.WriteValueU32(this.PitchOrLinearSize, endian);
			output.WriteValueU32(this.Depth, endian);
			output.WriteValueU32(this.MipMapCount, endian);
			output.Write(this.Reserved1, 0, this.Reserved1.Length);
			this.PixelFormat.Serialize(output, endian);
			output.WriteValueU32(this.SurfaceFlags, endian);
			output.WriteValueU32(this.CubemapFlags, endian);
			output.Write(this.Reserved2, 0, this.Reserved2.Length);
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:14,代码来源:Header.cs

示例2: Serialize

        public void Serialize(Stream output)
        {
            if (this.Version < 1 || this.Version > 2)
            {
                throw new InvalidOperationException("unsupported blob version");
            }

            output.WriteValueU32(this.Version);
            output.WriteValueS32(this.Entries.Count);

            var nameLength = this.Version == 2 ? 32 : 14;

            foreach (var entry in this.Entries)
            {
                var name = entry.Name;

                if (name.Length + 1 > nameLength)
                {
                    throw new InvalidOperationException();
                }

                output.WriteString(name.PadRight(nameLength, '\0'));
                output.WriteValueU32((uint)entry.Offset);
                output.WriteValueU32(entry.Size);
            }
        }
开发者ID:gibbed,项目名称:Gibbed.Infantry,代码行数:26,代码来源:BlobFile.cs

示例3: Serialize

        public void Serialize(Stream output)
        {
            output.WriteValueU32(0x42494748, false);
            output.WriteValueU32(this.TotalFileSize, true);
            output.WriteValueS32(this.Entries.Count, false);
            output.WriteValueS32(16 + (this.Entries.Count * 12) + 8, false);

            foreach (var entry in this.Entries)
            {
                output.WriteValueU32(entry.Offset, false);
                output.WriteValueU32(entry.Size, false);
                output.WriteValueU32(entry.Name, false);
            }

            output.WriteValueU32(0x4C323833, false);
            output.WriteValueU32(0x15050000, false);
        }
开发者ID:tgp1994,项目名称:Gibbed.Visceral,代码行数:17,代码来源:BigFile.cs

示例4: Serialize

        public void Serialize(Stream output)
        {
            var endian = this.Endian;

            const uint headerSize = 32;
            output.WriteValueU32(0x42424947, endian);
            output.WriteValueU32(this.Version, endian);

            var keys = new List<string>() {""};

            int maxValueLength = 0;
            var blob = new StringBuilder();
            foreach (var file in this.Files)
            {
                keys.Add(file.Name);
                foreach (var section in file.Sections)
                {
                    keys.Add(section.Key);
                    foreach (var value in section.Value)
                    {
                        keys.Add(value.Key);
                        foreach (var item in value.Value)
                        {
                            if (item.Value != null)
                            {
                                blob.Append(item.Value + '\0');
                                maxValueLength = Math.Max(maxValueLength, item.Value.Length);
                            }
                        }
                    }
                }
            }

            var huffmanEncoder = new Huffman.Encoder();
            huffmanEncoder.Build(blob.ToString());

            keys = keys.Distinct().OrderBy(k => k.HashCrc32()).ToList();
            int maxKeyLength = keys.Max(k => k.Length);

            uint stringTableSize;
            using (var data = new MemoryStream())
            {
                data.Position = 4;
                data.WriteValueS32(keys.Count, endian);

                data.Position = 4 + 4 + (8 * keys.Count);
                var offsets = new List<KeyValuePair<uint, uint>>();
                foreach (var key in keys)
                {
                    var offset = (uint)data.Position;
                    data.WriteValueU16((ushort)key.Length, endian);
                    data.WriteString(key, Encoding.UTF8);
                    offsets.Add(new KeyValuePair<uint, uint>(key.HashCrc32(), offset));
                }

                data.Position = 8;
                foreach (var kv in offsets)
                {
                    data.WriteValueU32(kv.Key, endian);
                    data.WriteValueU32(kv.Value - 8, endian);
                }

                data.Position = 0;
                data.WriteValueU32((uint)data.Length, endian);

                data.Position = 0;
                stringTableSize = (uint)data.Length;

                output.Seek(headerSize, SeekOrigin.Begin);
                output.WriteFromStream(data, data.Length);
            }

            uint huffmanSize;
            using (var data = new MemoryStream())
            {
                var pairs = huffmanEncoder.GetPairs();
                data.WriteValueU16((ushort)pairs.Length, endian);
                foreach (var pair in pairs)
                {
                    data.WriteValueS32(pair.Left, endian);
                    data.WriteValueS32(pair.Right, endian);
                }

                data.Position = 0;
                huffmanSize = (uint)data.Length;

                output.Seek(headerSize + stringTableSize, SeekOrigin.Begin);
                output.WriteFromStream(data, data.Length);
            }

            var bits = new BitArray(huffmanEncoder.TotalBits);
            var bitOffset = 0;

            uint indexSize;
            using (var index = new MemoryStream())
            {
                var fileDataOffset = 2 + (this.Files.Count * 6);

                var files = new List<KeyValuePair<ushort, int>>();
                foreach (var file in this.Files.OrderBy(f => keys.IndexOf(f.Name)))
//.........这里部分代码省略.........
开发者ID:CreeperLava,项目名称:ME3Explorer,代码行数:101,代码来源:CoalescedFile.cs

示例5: Serialize

 public static void Serialize(Stream output, FieldType type, object value, bool littleEndian)
 {
     switch (type)
     {
         case FieldType.UInt8: output.WriteValueU8((byte)value); break;
         case FieldType.Int8: output.WriteValueS8((sbyte)value); break;
         case FieldType.UInt16: output.WriteValueU16((ushort)value); break;
         case FieldType.Int16: output.WriteValueS16((short)value); break;
         case FieldType.UInt32: output.WriteValueU32((uint)value); break;
         case FieldType.Int32: output.WriteValueS32((int)value); break;
         case FieldType.UInt64: output.WriteValueU64((ulong)value); break;
         case FieldType.Int64: output.WriteValueS64((long)value); break;
         case FieldType.Single: output.WriteValueF32((float)value); break;
         case FieldType.Double: output.WriteValueF64((double)value); break;
         case FieldType.Vector3:
         {
             if (value == null)
             {
                 throw new ArgumentNullException();
             }
             ((Builtins.Vector3)value).Serialize(output, littleEndian);
             break;
         }
         case FieldType.Vector4:
         {
             if (value == null)
             {
                 throw new ArgumentNullException();
             }
             ((Builtins.Vector4)value).Serialize(output, littleEndian);
             break;
         }
         case FieldType.Quaternion:
         {
             if (value == null)
             {
                 throw new ArgumentNullException();
             }
             ((Builtins.Quaternion)value).Serialize(output, littleEndian);
             break;
         }
         case FieldType.String:
         {
             throw new NotSupportedException("cannot serialize strings via Builtin");
         }
         case FieldType.Color:
         {
             if (value == null)
             {
                 throw new ArgumentNullException();
             }
             ((Builtins.Color)value).Serialize(output, littleEndian);
             break;
         }
         case FieldType.Matrix4x4:
         {
             if (value == null)
             {
                 throw new ArgumentNullException();
             }
             ((Builtins.Matrix4x4)value).Serialize(output, littleEndian);
             break;
         }
         default:
         {
             throw new NotSupportedException("unsupported builtin type");
         }
     }
 }
开发者ID:dhk-room101,项目名称:da2_toolset,代码行数:69,代码来源:Builtin.cs

示例6: Serialize

        public void Serialize(Stream output)
        {
            output.WriteValueU32(this.FileAlignment, this.LittleEndian);
            output.WriteString(this.BasePath, 64, Encoding.ASCII);
            output.WriteValueS32(this.Entries.Count, this.LittleEndian);

            var entries = this.Entries
                .OrderBy(e => e.UncompressedSize)
                .OrderBy(e => e.NameHash);

            foreach (var entry in entries)
            {
                output.WriteValueU32(entry.NameHash, this.LittleEndian);
            }

            foreach (var entry in entries)
            {
                output.WriteValueU32(entry.UncompressedSize, this.LittleEndian);
                output.WriteValueU32(entry.Offset, this.LittleEndian);
                output.WriteValueU32(entry.Locale, this.LittleEndian);
                output.WriteValueU32(entry.CompressedSize, this.LittleEndian);
            }
        }
开发者ID:shizacat,项目名称:gibbedtr,代码行数:23,代码来源:BigFileV2.cs

示例7: Serialize

        public void Serialize(Stream output)
        {
            if (this.Version == 1)
            {
                throw new NotSupportedException();
            }
            else if (this.Version == 2)
            {
                throw new NotSupportedException();
            }
            else if (this.Version == 3)
            {
                output.WriteString("ERF V3.0", Encoding.Unicode);

                var strings = new List<string>();
                foreach (var entry in this.Entries)
                {
                    if (entry.Name != null &&
                        strings.Contains(entry.Name) == false)
                    {
                        strings.Add(entry.Name);
                    }
                }
                strings.Sort();

                var stringOffsets = new Dictionary<string, uint>();
                var stringTable = new MemoryStream();

                foreach (var str in strings)
                {
                    stringOffsets[str] = (uint)stringTable.Length;
                    stringTable.WriteStringZ(str, Encoding.UTF8);
                }
                stringTable.SetLength(stringTable.Length.Align(16));
                stringTable.Position = 0;

                output.WriteValueU32((uint)stringTable.Length);
                output.WriteValueS32(this.Entries.Count);

                if (this.Encryption != EncryptionScheme.None ||
                    this.Compression != CompressionScheme.None)
                {
                    throw new NotSupportedException();
                }

                uint flags = 0;
                flags |= ((uint)this.Encryption) << 4;
                flags |= ((uint)this.Compression) << 29;
                output.WriteValueU32(flags);

                output.WriteValueU32(this.ContentId);
                if (this.PasswordDigest == null)
                {
                    output.Write(new byte[16], 0, 16);
                }
                else
                {
                    output.Write(this.PasswordDigest, 0, 16);
                }

                output.WriteFromStream(stringTable, stringTable.Length, 0x00100000);

                foreach (var entry in this.Entries)
                {
                    if (entry.Name != null)
                    {
                        entry.CalculateHashes();
                        output.WriteValueU32(stringOffsets[entry.Name]);
                    }
                    else
                    {
                        output.WriteValueU32(0xFFFFFFFF);
                    }

                    output.WriteValueU64(entry.NameHash);
                    output.WriteValueU32(entry.TypeHash);
                    output.WriteValueU32((uint)entry.Offset);
                    output.WriteValueU32(entry.CompressedSize);
                    output.WriteValueU32(entry.UncompressedSize);
                }
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
开发者ID:dhk-room101,项目名称:da2_toolset,代码行数:86,代码来源:EncapsulatedResourceFile.cs

示例8: Serialize

        public void Serialize(Stream output)
        {
            output.WriteValueU32(0x54414653, this.LittleEndian);
            output.WriteValueU32(this.Unknown04, this.LittleEndian);
            output.WriteValueU32(this.NumberOfFiles, this.LittleEndian);
            output.WriteValueS32(this.Entries.Count, this.LittleEndian);
            output.WriteValueU32(this.Unknown10, this.LittleEndian);
            output.WriteString(this.BasePath, 32, Encoding.ASCII);

            foreach (var e in this.Entries.OrderBy(e => e.NameHash))
            {
                output.WriteValueU32(e.NameHash, this.LittleEndian);
                output.WriteValueU32(e.Locale, this.LittleEndian);
                output.WriteValueU32(e.Size, this.LittleEndian);
                output.WriteValueU32(e.File | e.Offset, this.LittleEndian);
            }
        }
开发者ID:shizacat,项目名称:gibbedtr,代码行数:17,代码来源:BigFileV3.cs

示例9: Serialize

        public void Serialize(Stream output)
        {
            output.WriteValueU32(0x47464620u, false);
            output.WriteValueU32(0x56342E30u + this.FileVersion, false);
            output.WriteValueEnum<GFF.FilePlatform>(this.FilePlatform, false);
            output.WriteValueEnum<GFF.FormatType>(this.FormatType, false);
            output.WriteValueU32(this.FormatVersion, false);

            var littleEndian = this.FilePlatform == GFF.FilePlatform.PC;

            output.WriteValueS32(this.Structures.Count, littleEndian);

            int structuresOffset = (int)output.Position + 4;
            int fieldsOffset = structuresOffset + (this.Structures.Count * 16);
            int dataOffset = fieldsOffset + (this.Structures.Sum(s => s.Fields.Count) * 12);
            dataOffset = dataOffset.Align(16);
            output.WriteValueS32(dataOffset, littleEndian);

            int runningFieldCount = 0;
            foreach (var structDef in this.Structures)
            {
                output.WriteValueU32(structDef.Id, false);
                output.WriteValueS32(structDef.Fields.Count, littleEndian);
                output.WriteValueS32(fieldsOffset +
                    (runningFieldCount * 12), littleEndian);
                output.WriteValueU32(structDef.DataSize, littleEndian);
                runningFieldCount += structDef.Fields.Count;
            }

            foreach (var structDef in this.Structures)
            {
                foreach (var fieldDef in structDef.Fields)
                {
                    output.WriteValueS32(fieldDef.Id, littleEndian);

                    var flags = fieldDef.Flags;
                    ushort type;

                    if (fieldDef.Type == GFF.FieldType.Structure)
                    {
                        flags |= GFF.FieldFlags.IsStructure;
                        type = fieldDef.StructureId;
                    }
                    else
                    {
                        type = (ushort)fieldDef.Type;
                    }

                    uint rawFlags = 0;
                    rawFlags |= type;
                    rawFlags |= (uint)flags << 16;

                    output.WriteValueU32(rawFlags, littleEndian);
                    output.WriteValueU32(fieldDef.Offset, littleEndian);
                }
            }

            this.Data.Position = 0;
            output.Seek(dataOffset, SeekOrigin.Begin);
            output.WriteFromStream(this.Data, this.Data.Length);
        }
开发者ID:dhk-room101,项目名称:da2_toolset,代码行数:61,代码来源:GenericFile.cs


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