示例#1
0
        /// <summary>
        /// Return a <see cref="Stream"/> containing the data in this GenericRCOLResource instance.
        /// </summary>
        /// <returns>A <see cref="Stream"/> containing the data in this GenericRCOLResource instance.</returns>
        protected override Stream UnParse()
        {
            long rcolIndexPos;

            MemoryStream ms = new MemoryStream();
            BinaryWriter w  = new BinaryWriter(ms);

            w.Write(version);
            w.Write(publicChunks);
            w.Write(unused);
            if (resources == null)
            {
                resources = new CountedTGIBlockList(OnResourceChanged, "ITG");
            }
            w.Write(resources.Count);
            if (blockList == null)
            {
                blockList = new ChunkEntryList(OnResourceChanged)
                {
                    ParentTGIBlocks = resources,
                }
            }
            ;
            w.Write(blockList.Count);
            foreach (ChunkEntry ce in blockList)
            {
                ce.TGIBlock.UnParse(ms);
            }
            resources.UnParse(ms);

            rcolIndexPos = ms.Position;
            RCOLIndexEntry[] index = new RCOLIndexEntry[blockList.Count];
            for (int i = 0; i < blockList.Count; i++)
            {
                w.Write((uint)0); w.Write((uint)0);
            }                                                                                 // Pad for the index

            int j = 0;

            foreach (ChunkEntry ce in blockList)
            {
                byte[] data = ce.RCOLBlock.AsBytes;
                while (w.BaseStream.Position % 4 != 0)
                {
                    w.Write((byte)0);
                }
                index[j].Position = (uint)ms.Position;
                index[j].Length   = data.Length;
                w.Write(data);
                j++;
            }

            ms.Position = rcolIndexPos;
            foreach (RCOLIndexEntry entry in index)
            {
                w.Write(entry.Position); w.Write(entry.Length);
            }

            return(ms);
        }
示例#2
0
        void Parse(Stream s)
        {
            BinaryReader r = new BinaryReader(s);

            version      = r.ReadUInt32();
            publicChunks = r.ReadInt32();
            unused       = r.ReadUInt32();
            int countResources = r.ReadInt32();
            int countChunks    = r.ReadInt32();

            TGIBlock[] chunks = new TGIBlock[countChunks];
            for (int i = 0; i < countChunks; i++)
            {
                chunks[i] = new TGIBlock(0, OnResourceChanged, "ITG", s);
            }
            resources = new CountedTGIBlockList(OnResourceChanged, "ITG", countResources, s);

            RCOLIndexEntry[] index = new RCOLIndexEntry[countChunks];
            for (int i = 0; i < countChunks; i++)
            {
                index[i].Position = r.ReadUInt32(); index[i].Length = r.ReadInt32();
            }
            if (countChunks == 1)
            {
                index[0].Position = 0x2c + (uint)countResources * 16;
                index[0].Length   = (int)(s.Length - index[0].Position);
                if (chunks[0].ResourceType == 0)
                {
                    string tag = new string(r.ReadChars(4));
                    chunks[0].ResourceType = GenericRCOLResourceHandler.RCOLTypesForTag(tag).FirstOrDefault();
                }
            }

            blockList = new ChunkEntryList(requestedApiVersion, OnResourceChanged, s, chunks, index)
            {
                ParentTGIBlocks = resources,
            };
        }