Beispiel #1
0
        public Stream Write()
        {
            // Buffer for new TXP File
            Stream stream = new MemoryStream();

            // Define a binary writer to write with.
            DhBinaryWriter bw = new DhBinaryWriter(stream, DhEndian.Big);

            // Write the fixed Unknown values
            bw.WriteU16(1);
            bw.WriteU16(0);

            // Write Entry Count
            bw.WriteU16((ushort)TXPEntries.Count);

            // Write Frame Count
            bw.WriteU16(FrameCount);

            //Calculate and write frame data offset
            bw.WriteU32((uint)(0xC * TXPEntries.Count));

            bw.SaveOffset(0);

            //Write dummy entry headers
            for (int i = 0; i < TXPEntries.Count; i++)
            {
                bw.WriteU64(0);
                bw.WriteU32(0);
            }

            //Make a list to store the offsets for each entry's frame data
            List <long> frameDataOffsets = new List <long>();

            //Write the entries
            for (int entry = 0; entry < TXPEntries.Count; entry++)
            {
                TXPEntries[entry].Write(bw, frameDataOffsets);
            }

            bw.LoadOffset(0);
            //Write frame data offsets
            for (int i = 0; i < TXPEntries.Count; i++)
            {
                bw.WriteU16(1);
                bw.WriteS16(TXPEntries[i].MaterialIndex);
                bw.WriteU32(0);
                bw.WriteU32((uint)frameDataOffsets[i]);
            }

            // Returns the TXP as a stream
            return(stream);
        }