本文整理汇总了C#中Stream.WriteValueU32方法的典型用法代码示例。如果您正苦于以下问题:C# Stream.WriteValueU32方法的具体用法?C# Stream.WriteValueU32怎么用?C# Stream.WriteValueU32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stream
的用法示例。
在下文中一共展示了Stream.WriteValueU32方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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);
}
示例3: 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);
}
示例4: Serialize
public void Serialize(Stream output, Endian endian)
{
output.WriteValueU32(this.Size, endian);
output.WriteValueEnum<PixelFormatFlags>(this.Flags, endian);
output.WriteValueU32(this.FourCC, endian);
output.WriteValueU32(this.RGBBitCount, endian);
output.WriteValueU32(this.RedBitMask, endian);
output.WriteValueU32(this.GreenBitMask, endian);
output.WriteValueU32(this.BlueBitMask, endian);
output.WriteValueU32(this.AlphaBitMask, endian);
}
示例5: 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)))
//.........这里部分代码省略.........
示例6: 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");
}
}
}
示例7: 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);
}
}
示例8: 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();
}
}
示例9: 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);
}
}
示例10: 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);
}
示例11: Serialize
public void Serialize(Stream output)
{
output.WriteValueU32(this.Version);
if (this.Version >= 114)
{
output.WriteValueU16((ushort)((this.EncryptionKey >> 16) & 0xFFFF));
}
var magic = GetRealKey(this.EncryptionKey);
output.WriteValueEncodedS32(this.Keys.Count);
foreach (var kv in this.Keys)
{
output.WriteEncodedString(kv.Key);
output.WriteValueU32(kv.Value ^ magic);
}
if (this.Version >= 114)
{
output.WriteValueU16((ushort)((this.EncryptionKey >> 0) & 0xFFFF));
}
uint fileStringsHash = 0;
var hashPosition = output.Position;
if (this.Version >= 200)
{
output.WriteValueU32(0);
}
output.WriteValueEncodedS32(this.Texts.Count);
foreach (var kv in this.Texts)
{
output.WriteValueU32(kv.Key ^ magic);
/*
byte[] buffer;
if (kv.Key == 65434)
{
using (var test = File.OpenRead("corrupt_string.bin"))
{
buffer = new byte[test.Length];
test.Read(buffer, 0, buffer.Length);
}
}
else
{
buffer = Encoding.Unicode.GetBytes(kv.Value);
}
*/
var buffer = Encoding.Unicode.GetBytes(kv.Value);
ushort stringKey = (ushort)(magic >> 8);
for (int j = 0; j < buffer.Length; j += 2)
{
if (this.Version >= 200)
{
var charKey = (ushort)(((buffer.Length / 2) + 1) * stringKey);
buffer[j + 0] ^= (byte)((charKey >> 0) & 0xFF);
buffer[j + 1] ^= (byte)((charKey >> 8) & 0xFF);
stringKey = stringKey.RotateLeft(1);
}
else
{
throw new NotImplementedException("string obfuscation for old strings files is untested");
// untested
buffer[j + 0] ^= (byte)((stringKey >> 0) & 0xFF);
buffer[j + 1] ^= (byte)((stringKey >> 8) & 0xFF);
stringKey++;
}
fileStringsHash += BitConverter.ToUInt16(buffer, j);
}
output.WriteEncodedStringBuffer(buffer);
}
if (this.Version >= 200)
{
var endPosition = output.Position;
output.Seek(hashPosition, SeekOrigin.Begin);
output.WriteValueU32(fileStringsHash ^ magic);
output.Seek(endPosition, SeekOrigin.Begin);
}
else if (this.Version >= 114)
{
output.WriteValueU32(fileStringsHash);
}
}