Inheritance: SparkleBlock
Ejemplo n.º 1
0
        public void LoadFile(BinaryReaderEx reader)
        {
            BasePosition = reader.BaseStream.Position;

            reader.ReadInt32();
            Unknown1 = reader.ReadInt16();
            NumOffsets = reader.ReadInt16();
            Unknown2 = reader.ReadInt16();
            Unknown3 = reader.ReadInt16();
            Unknown4 = reader.ReadInt16();
            NumFiles = reader.ReadInt16();
            Unknown5 = reader.ReadInt32();

            for (var i = 0; i < NumOffsets; i++)
            {
                this.Offsets.Add(reader.ReadInt32());
            }

            SparkleBlock b;
            for (var i = 0; i < NumOffsets; i++)
            {
                long offsetPos = BasePosition + this.Offsets[i];
                reader.BaseStream.Position = offsetPos;
                short type = reader.ReadInt16();
                switch (type)
                {
                    case 0:
                        b = new SparkleImageClip();
                        break;
                    case 1:
                        b = new SparkleType1();
                        break;
                    case 2:
                        b = new SparkleContainer();
                        break;
                    default:
                        throw new InvalidOperationException("Unexpected SparkleBlock Type: " + type);
                }

                reader.BaseStream.Position = offsetPos;
                b.Load(reader);
                this.Blocks.Add(b);
            }

            SparkleContainer fileContainer = this.Blocks[0] as SparkleContainer;
            if (fileContainer == null)
            {
                throw new InvalidOperationException("First sparkle block is not a container?");
            }

            SparkleImage img;
            for (var i = 0; i < NumFiles; i++)
            {
                img = new SparkleImage();
                img.Parent = this;

                if (i < fileContainer.Strings.Count)
                {
                    img.FileName = fileContainer.Strings[i];
                }

                SparkleChunkBase c = fileContainer.Chunks[i];
                if (c.Reference == 0)
                {
                    img.ImageClip = null;
                }
                else
                {
                    b = this.Blocks[c.Reference - 1];
                    int recursion = 0;
                    while (recursion < 5)
                    {
                        if (b is SparkleImageClip)
                        {
                            img.ImageClip = (SparkleImageClip)b;
                            break;
                        }
                        else if (b is SparkleType1)
                        {
                            img.ImageClip = null;
                            break;
                        }
                        else if (b is SparkleContainer)
                        {
                            SparkleContainer cont = (SparkleContainer)b;
                            if (cont.Chunks[0].Reference == 0)
                            {
                                img.ImageClip = null;
                                break;
                            }

                            b = this.Blocks[cont.Chunks[0].Reference - 1];
                        }
                        recursion++;
                    }
                }

                if (img.ImageClip != null)
                {
                    this.Children.Add(img);
                    this.Images.Add(img);
                }
            }
        }
Ejemplo n.º 2
0
        public void LoadFile(BinaryReaderEx reader)
        {
            BasePosition = reader.BaseStream.Position;

            reader.ReadInt32();
            Unknown1   = reader.ReadInt16();
            NumOffsets = reader.ReadInt16();
            Unknown2   = reader.ReadInt16();
            Unknown3   = reader.ReadInt16();
            Unknown4   = reader.ReadInt16();
            NumFiles   = reader.ReadInt16();
            Unknown5   = reader.ReadInt32();

            for (var i = 0; i < NumOffsets; i++)
            {
                this.Offsets.Add(reader.ReadInt32());
            }

            SparkleBlock b;

            for (var i = 0; i < NumOffsets; i++)
            {
                long offsetPos = BasePosition + this.Offsets[i];
                reader.BaseStream.Position = offsetPos;
                short type = reader.ReadInt16();
                switch (type)
                {
                case 0:
                    b = new SparkleImageClip();
                    break;

                case 1:
                    b = new SparkleType1();
                    break;

                case 2:
                    b = new SparkleContainer();
                    break;

                default:
                    throw new InvalidOperationException("Unexpected SparkleBlock Type: " + type);
                }

                reader.BaseStream.Position = offsetPos;
                b.Load(reader);
                this.Blocks.Add(b);
            }

            SparkleContainer fileContainer = this.Blocks[0] as SparkleContainer;

            if (fileContainer == null)
            {
                throw new InvalidOperationException("First sparkle block is not a container?");
            }

            SparkleImage img;

            for (var i = 0; i < NumFiles; i++)
            {
                img        = new SparkleImage();
                img.Parent = this;

                if (i < fileContainer.Strings.Count)
                {
                    img.FileName = fileContainer.Strings[i];
                }

                SparkleChunkBase c = fileContainer.Chunks[i];
                if (c.Reference == 0)
                {
                    img.ImageClip = null;
                }
                else
                {
                    b = this.Blocks[c.Reference - 1];
                    int recursion = 0;
                    while (recursion < 5)
                    {
                        if (b is SparkleImageClip)
                        {
                            img.ImageClip = (SparkleImageClip)b;
                            break;
                        }
                        else if (b is SparkleType1)
                        {
                            img.ImageClip = null;
                            break;
                        }
                        else if (b is SparkleContainer)
                        {
                            SparkleContainer cont = (SparkleContainer)b;
                            if (cont.Chunks[0].Reference == 0)
                            {
                                img.ImageClip = null;
                                break;
                            }

                            b = this.Blocks[cont.Chunks[0].Reference - 1];
                        }
                        recursion++;
                    }
                }

                if (img.ImageClip != null)
                {
                    this.Children.Add(img);
                    this.Images.Add(img);
                }
            }
        }