Beispiel #1
0
        public static BinkAtlasEntry Read(Stream input)
        {
            // Validate input
            var size = input.ReadInt32BE();

            if (size < 0)
            {
                throw new EntryReadException(string.Format(ERR_BINK_ATLAS_SIZE, size));
            }
            var binkAtlasVersion = input.ReadInt32BE();

            if (binkAtlasVersion != BINK_ATLAS_VERSION)
            {
                throw new EntryReadException(string.Format(ERR_BINK_ATLAS_VERSION, size, BINK_ATLAS_VERSION));
            }

            // Read the values we need
            var name   = StreamHelpers.ReadString(input);
            var width  = input.ReadInt32BE();
            var height = input.ReadInt32BE();

            // Make the entry
            return(new BinkAtlasEntry()
            {
                Name = name,
                Width = width,
                Height = height
            });
        }
        public void StreamHelpers_EmptyArray()
        {
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadSByte(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadByte(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadInt16(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadUInt16(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadInt32(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadUInt32(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadInt64(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadUInt64(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadSingle(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadDouble(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadDecimal(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadChar(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadBoolean(new MemoryStream()));
            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadGuid(new MemoryStream()));

            using var stream = new MemoryStream();

            stream.WriteUInt32Compact(42u);
            stream.Position = 0;

            Assert.ThrowsException <EndOfStreamException>(() => StreamHelpers.ReadString(stream));
        }
Beispiel #3
0
        public static AtlasEntry Read(Stream input, bool isManifest)
        {
            // Validate input
            var size = input.ReadInt32BE();

            if (size < 0)
            {
                throw new EntryReadException(string.Format(ERR_ATLAS_SIZE, size));
            }

            // Read the header of the atlas.
            int atlasVersionCode = 0;
            int numSubAtlases    = input.ReadInt32BE();

            if (numSubAtlases == NEW_ATLAS_VERSION_MAGIC)
            {
                // New texture atlas format: Ignore the first integer
                atlasVersionCode = input.ReadInt32BE();
                numSubAtlases    = input.ReadInt32BE();
            }

            var entry = new AtlasEntry();

            entry.Entries     = new List <SubAtlas>();
            entry.VersionCode = atlasVersionCode;

            // Read all sub atlases.
            for (int i = 0; i < numSubAtlases; i++)
            {
                string    name = StreamHelpers.ReadString(input);
                Rectangle rect = new Rectangle(input.ReadInt32BE(), input.ReadInt32BE(),
                                               input.ReadInt32BE(), input.ReadInt32BE());
                Point   topLeft        = new Point(input.ReadInt32BE(), input.ReadInt32BE());
                Point   originalSize   = new Point(input.ReadInt32BE(), input.ReadInt32BE());
                Vector2 scaleRatio     = new Vector2(input.ReadSingleBE(), input.ReadSingleBE());
                bool    isMultiTexture = false;
                bool    isMip          = false;
                if (atlasVersionCode > 0)
                {
                    int atlasType = input.ReadByte();
                    if (atlasVersionCode > 1)
                    {
                        isMultiTexture = (atlasType & IS_MULTI_TEXTURE_FLAG) != 0;
                        isMip          = (atlasType & IS_MIP_FLAG) != 0;
                    }
                    else
                    {
                        isMultiTexture = atlasType != 0;
                    }
                }
                List <IntVector2> hull = null;
                if (atlasVersionCode > 2)
                {
                    int hullCount = input.ReadInt32BE();
                    hull = new List <IntVector2>();
                    for (int j = 0; j < hullCount; j++)
                    {
                        int num10 = input.ReadInt32BE();
                        int num11 = input.ReadInt32BE();
                        hull.Add(new IntVector2(num10, num11));
                    }
                }

                entry.Entries.Add(new SubAtlas()
                {
                    Parent         = entry,
                    Name           = name,
                    Rect           = rect,
                    TopLeft        = topLeft,
                    OriginalSize   = originalSize,
                    ScaleRatio     = scaleRatio,
                    IsMultiTexture = isMultiTexture,
                    IsMip          = isMip,
                    Hull           = hull,
                });
            }

            // Is this a reference to the texture, or the actual thing? If we're reading a manifest, then its always a
            // reference.
            //byte unkByte = (byte)input.ReadByte();
            byte refByte     = (byte)input.ReadByte();
            bool isReference = refByte == REFERENCE_CODE || isManifest;

            entry.IsReference = isReference;
            if (isReference)
            {
                // Read the name.
                entry.ReferencedTextureName = StreamHelpers.ReadString(input);
            }
            else
            {
                entry.IncludedTextureEntry = TextureEntry.Read(input);
            }

            return(entry);
        }
Beispiel #4
0
 public static IncludePackageEntry Read(Stream input)
 {
     return(new IncludePackageEntry(StreamHelpers.ReadString(input)));
 }