예제 #1
0
        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]);
                }
            }
        }
예제 #2
0
파일: YkdFile.cs 프로젝트: pinguallyj/Pulse
 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);
 }
예제 #3
0
        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);
        }
예제 #4
0
        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()));
        }
예제 #5
0
파일: YkdFile.cs 프로젝트: pinguallyj/Pulse
 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>();
 }
예제 #6
0
        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>();
            }
        }
예제 #7
0
        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;
                }
            }
        }
예제 #8
0
        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();
            }
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
 public void WriteToStream(Stream stream)
 {
     YkdOffsets.WriteToStream(stream, ref Offsets, ref Resources, b => b.CalcSize());
     stream.WriteContent(Resources);
 }