public void WriteToStream(Stream stream) { BinaryWriter bw = new BinaryWriter(stream); bw.Write(Type); bw.Write(Index); bw.Write(AssociatedIndex); bw.Write(Unknown); for (int i = 0; i < TransformationMatrix.Length; i++) { bw.WriteBig(TransformationMatrix[i]); } YkdOffsets.WriteToStream(stream, ref Offsets, ref Entries, b => b.CalcSize()); stream.WriteContent(Entries); if (ZeroTail != null) { stream.WriteContent(ZeroTail); } else if (Tails4 != null) { stream.WriteContent(Tails4); } else if (Tail56 != null) { for (int i = 0; i < Tail56.Length; i++) { bw.Write(Tail56[i]); } } }
public void WriteToStream(Stream stream) { stream.WriteContent(Header); stream.WriteContent(Background); YkdOffsets.WriteToStream(stream, ref Offsets, ref Blocks, b => b.CalcSize()); stream.WriteContent(Blocks); stream.WriteContent(Resources); }
public void WriteToStream(Stream stream) { byte[] name = new byte[NameSize]; YkdFile.NamesEncoding.GetBytes(Name, 0, Name.Length, name, 0); stream.Write(name, 0, name.Length); YkdOffsets.WriteToStream(stream, ref Offsets, ref Frames, b => b.CalcSize()); stream.WriteContent(Frames); }
public int CalcSize() { YkdFrames[] frames = Frames ?? new YkdFrames[0]; YkdOffsets offsets = new YkdOffsets { Offsets = new int[frames.Length] }; return(NameSize + offsets.CalcSize() + frames.Sum(t => t.CalcSize())); }
public void ReadFromStream(Stream stream) { Header = stream.ReadContent <YkdHeader>(); Background = stream.ReadContent <YkdBlock>(); Offsets = stream.ReadContent <YkdOffsets>(); Blocks = new YkdBlock[Offsets.Count]; for (int i = 0; i < Blocks.Length; i++) { stream.SetPosition(Offsets[i]); Blocks[i] = stream.ReadContent <YkdBlock>(); } Resources = stream.ReadContent <YkdResources>(); }
public unsafe void ReadFromStream(Stream stream) { byte[] name = stream.EnsureRead(NameSize); fixed(byte *namePtr = &name[0]) Name = new string((sbyte *)namePtr, 0, NameSize, YkdFile.NamesEncoding).TrimEnd('\0'); Offsets = stream.ReadContent <YkdOffsets>(); Frames = new YkdFrames[Offsets.Count]; for (int i = 0; i < Frames.Length; i++) { Frames[i] = stream.ReadContent <YkdFrames>(); } }
public void ReadFromStream(Stream stream) { BinaryReader br = new BinaryReader(stream); IsFirstBlock = stream.Position == YkdHeader.Size; Type = br.ReadUInt32(); Index = br.ReadUInt32(); AssociatedIndex = br.ReadUInt32(); Unknown = br.ReadUInt32(); for (int i = 0; i < TransformationMatrix.Length; i++) { TransformationMatrix[i] = br.ReadBigInt32(); } Offsets = stream.ReadContent <YkdOffsets>(); Entries = new YkdBlockEntry[Offsets.Count]; for (int i = 0; i < Offsets.Count; i++) { stream.SetPosition(Offsets[i]); Entries[i] = stream.ReadContent <YkdBlockEntry>(); } if (!IsFirstBlock) { switch (Type) { case 0: ZeroTail = stream.ReadContent <YkdBlockOptionalTail>(); break; case 4: Tails4 = stream.ReadContent <YkdBlockOptionalTails>(); break; case 5: case 6: Tail56 = new int[12]; for (int i = 0; i < Tail56.Length; i++) { Tail56[i] = br.ReadInt32(); } break; } } }
public void ReadFromStream(Stream stream) { Offsets = stream.ReadContent <YkdOffsets>(); Resources = new YkdResource[Offsets.Count]; for (int i = 0; i < Resources.Length; i++) { YkdResource resource = Resources[i] = new YkdResource(); stream.SetPosition(Offsets[i]); resource.ReadFromStream(stream); } if (!stream.IsEndOfStream()) { throw new InvalidDataException(); } }
public static void WriteToStream <T>(Stream stream, ref YkdOffsets self, ref T[] values, Func <T, int> valueSizeCalculator) { if (values == null) { values = new T[0]; } if (self == null) { self = new YkdOffsets(); } self.Offsets = new int[values.Length]; int offset = (int)stream.Position + self.CalcSize(); for (int i = 0; i < self.Count; i++) { self[i] = offset; offset += valueSizeCalculator(values[i]); } stream.WriteContent(self); }
public int CalcSize() { YkdBlockEntry[] entries = Entries ?? new YkdBlockEntry[0]; YkdOffsets offsets = new YkdOffsets { Offsets = new int[entries.Length] }; int result = 4 * 4 + TransformationMatrixSize + offsets.CalcSize() + entries.Sum(t => t.CalcSize()); if (ZeroTail != null) { result += YkdBlockOptionalTail.Size; } else if (Tails4 != null) { result += Tails4.CalcSize(); } else if (Tail56 != null) { result += Tail56.Length * 4; } return(result); }
public void WriteToStream(Stream stream) { YkdOffsets.WriteToStream(stream, ref Offsets, ref Resources, b => b.CalcSize()); stream.WriteContent(Resources); }