示例#1
0
        public static TextureEntry Read(Stream input)
        {
            string textureName = input.ReadString();
            int    size        = input.ReadInt32BE();

            if (size < 0)
            {
                throw new EntryReadException(string.Format(ERR_TEXTURE_SIZE, textureName, size));
            }
            if (input.Length - input.Position < size)
            {
                throw new EntryReadException(string.Format(ERR_TEXTURE_DATA, textureName, size));
            }
            var originalPosition = input.Position;
            var crs   = ContentManagerShim.GetContentReaderFromXnb(textureName, input, new BinaryReader(input));
            var entry = new TextureEntry()
            {
                Name    = textureName,
                Texture = (Texture)crs.ReadAsset <Texture>()
            };

            input.Position = originalPosition + size;
            return(entry);
        }
示例#2
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);
        }