示例#1
0
        /// <summary>
        /// Read a null terminatd string.
        /// </summary>
        /// <param name="br">The reader.</param>
        /// <returns>The string.</returns>
        public string ReadNullTerminated(BinaryDataReader br)
        {
            //Return the string.
            string ret = "";
            char   c   = br.ReadChar();

            while (c != 0)
            {
                ret += c;
                c    = br.ReadChar();
            }
            return(ret);
        }
示例#2
0
        protected override TileLayer Deserialize(BinaryDataReader reader)
        {
            var tile = new TileLayer();

            tile.Type      = reader.ReadChar();
            tile.Id        = reader.ReadByte();
            tile.Weight    = reader.ReadUInt16();
            tile.ImageData = reader.ReadRemaining();
            return(tile);
        }
示例#3
0
        protected override SpriteLinkLayer Deserialize(BinaryDataReader reader)
        {
            var version = reader.ReadByte();

            if (version != Version)
            {
                throw new ResourceException($"Unknown spritelink version: '{version}'");
            }

            var links = new SortedDictionary <short, SpriteLink>();

            while (true)
            {
                var id = reader.ReadInt16();
                if (id < 0)
                {
                    break;
                }

                var type = reader.ReadChar();
                switch (type)
                {
                case 't':
                    links[id] = ReadTileLink(reader);
                    break;

                case 'r':
                    links[id] = ReadResourceLink(reader);
                    break;

                default:
                    throw new ResourceException($"Unknown spritelink type: '{type}'");
                }
            }

            return(new SpriteLinkLayer {
                Version = version,
                Links = links,
                DefaultLinkId = reader.ReadInt16()
            });
        }
示例#4
0
        /// <summary>
        /// Open file.
        /// </summary>
        /// <param name="br">The reader.</param>
        /// <param name="writeMode">Write mode.</param>
        /// <param name="version">Version.</param>
        public void OpenFile(BinaryDataReader br, out WriteMode writeMode, out FileWriter.Version version)
        {
            //Set up variables.
            blockOffsets         = new List <int>();
            fileStartPos         = br.Position;
            sizedReferenceTables = new Dictionary <string, ReferenceStructures.SizedReferenceTableInfo>();
            referenceTables      = new Dictionary <string, ReferenceStructures.ReferenceTableInfo>();
            references           = new Dictionary <string, ReferenceStructures.ReferenceInfo>();
            sizedReferences      = new Dictionary <string, ReferenceStructures.SizedReferenceInfo>();
            structurePositions   = new Stack <long>();

            //Get F or C.
            char identifier = br.ReadChar();

            //Skip rest of magic.
            br.Position += 3;

            //Get byte order.
            br.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
            bool bigEndian = true;

            if (br.ReadUInt16() == ByteOrder.LittleEndian)
            {
                //Little endian.
                bigEndian    = false;
                br.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
            }

            //Get header size.
            UInt16 headerSize = br.ReadUInt16();

            //Get version.
            version = new FileWriter.Version(br.ReadUInt32(), identifier);

            //Get size.
            fileSize = br.ReadUInt32();

            //Number of blocks and padding.
            UInt16 numBlocks = br.ReadUInt16();

            br.ReadUInt16();

            //Read offsets.
            for (int i = 0; i < numBlocks; i++)
            {
                br.ReadUInt32();
                blockOffsets.Add(br.ReadInt32());
                br.ReadUInt32();
            }

            //If the format is an F type.
            bool FFiles = identifier == 'F';

            //Determine the write mode.
            writeMode = WriteMode.Cafe;
            if (FFiles && !bigEndian)
            {
                writeMode = WriteMode.NX;
            }
            if (!FFiles && !bigEndian)
            {
                writeMode = WriteMode.CTR;
            }
            if (!FFiles && bigEndian)
            {
                writeMode = WriteMode.C_BE;
            }

            //Set the position.
            br.Position = fileStartPos + headerSize;
        }
示例#5
0
 public char Read(BinaryDataReader reader)
 {
     return(reader.ReadChar());
 }