예제 #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
        protected override Stream UnParse()
        {
            long         posn, tgiPosn, end;
            MemoryStream s = new MemoryStream();
            BinaryWriter w = new BinaryWriter(s);

            w.Write(version);
            posn = s.Position;
            w.Write((int)0); //offset

            if (presets == null)
            {
                presets = new PresetList(OnResourceChanged);
            }
            presets.UnParse(s);

            BigEndianUnicodeString.Write(s, unknown1);
            w.Write(sortPriority);
            w.Write(unknown2);
            w.Write((uint)clothing);
            w.Write((uint)dataType);
            if (ageGender == null)
            {
                ageGender = new AgeGenderFlags(0, OnResourceChanged);
            }
            ageGender.UnParse(s);
            w.Write((uint)clothingCategory);
            w.Write(casPart1Index);
            w.Write(casPart2Index);
            w.Write(blendInfoFatIndex);
            w.Write(blendInfoFitIndex);
            w.Write(blendInfoThinIndex);
            w.Write(blendInfoSpecialIndex);
            w.Write(overlayPriority);

            if (tgiBlocks == null)
            {
                tgiBlocks = new CountedTGIBlockList(OnResourceChanged, "IGT");
            }
            if (vpxyIndexes == null)
            {
                vpxyIndexes = new ByteIndexList(OnResourceChanged, ReadByte, WriteByte, byte.MaxValue, tgiBlocks);
            }
            vpxyIndexes.UnParse(s);
            if (lodInfo == null)
            {
                lodInfo = new LODInfoEntryList(OnResourceChanged);
            }
            lodInfo.UnParse(s);
            if (diffuse1Indexes == null)
            {
                diffuse1Indexes = new ByteIndexList(OnResourceChanged, ReadByte, WriteByte, byte.MaxValue, tgiBlocks);
            }
            diffuse1Indexes.UnParse(s);
            if (specular1Indexes == null)
            {
                specular1Indexes = new ByteIndexList(OnResourceChanged, ReadByte, WriteByte, byte.MaxValue, tgiBlocks);
            }
            specular1Indexes.UnParse(s);
            if (diffuse2Indexes == null)
            {
                diffuse2Indexes = new ByteIndexList(OnResourceChanged, ReadByte, WriteByte, byte.MaxValue, tgiBlocks);
            }
            diffuse2Indexes.UnParse(s);
            if (specular2Indexes == null)
            {
                specular2Indexes = new ByteIndexList(OnResourceChanged, ReadByte, WriteByte, byte.MaxValue, tgiBlocks);
            }
            specular2Indexes.UnParse(s);
            if (bondIndexes == null)
            {
                bondIndexes = new ByteIndexList(OnResourceChanged, ReadByte, WriteByte, byte.MaxValue, tgiBlocks);
            }
            bondIndexes.UnParse(s);
            BigEndianUnicodeString.Write(s, unknown4);

            tgiPosn = s.Position;
            w.Write((byte)tgiBlocks.Count);
            tgiBlocks.UnParse(s);

            end = s.Position;

            s.Position = posn;
            w.Write((int)(tgiPosn - posn - sizeof(int)));
            s.Position = end;

            vpxyIndexes.ParentTGIBlocks         = diffuse1Indexes.ParentTGIBlocks = specular1Indexes.ParentTGIBlocks =
                diffuse2Indexes.ParentTGIBlocks = specular2Indexes.ParentTGIBlocks = bondIndexes.ParentTGIBlocks = tgiBlocks;

            s.Flush();
            return(s);
        }