public void Write(SRBinaryWriter binaryWriter)
 {
     binaryWriter.Write(x);
     binaryWriter.Write(y);
     binaryWriter.Write(z);
     binaryWriter.Write(w);
 }
Exemple #2
0
        /// <summary>
        /// Writes the data block to a file binary stream.
        /// </summary>
        /// <param name="binaryWriter">Binary writer to write the block to.</param>
        public override void Write(SRBinaryWriter binaryWriter)
        {
            binaryWriter.Write(signature);
            binaryWriter.Write(version);
            var positionSize = binaryWriter.BaseStream.Position;
            binaryWriter.Write((UInt32)0);      // refDataSize (will rewrite later)
            binaryWriter.Write(refDataStart);
            binaryWriter.Write((UInt32)referenceData.Count);
            binaryWriter.Write((UInt32)unknown);
            for (int i = 0; i < 12; i++)
                binaryWriter.Write((Byte)0);
            referenceWriteOffsetsByName = new Dictionary<string, long>(referenceData.Count);
            var positionDataStart = binaryWriter.BaseStream.Position;
            for (int i = 0; i < referenceData.Count; i++)
            {
                string id = (i + 1).ToString();
                string name = referenceData[i];
                long offset = binaryWriter.BaseStream.Position - positionDataStart;
                referenceWriteOffsetsByName.Add(id, offset);
                if (!referenceWriteOffsetsByName.ContainsKey(name))
                    referenceWriteOffsetsByName.Add(name, offset);
                binaryWriter.Write(name);
            }
            var actualDataSize = binaryWriter.BaseStream.Position - positionDataStart;
            binaryWriter.Write((Byte)0);

            // Update the value size with the actual number of bytes written
            binaryWriter.Seek((int)positionSize, SeekOrigin.Begin);
            binaryWriter.Write((UInt32)actualDataSize);
            binaryWriter.Seek(0, SeekOrigin.End);
        }
 // See description of this method in the abstract base class SRZoneProperty.
 protected override void WriteData(SRBinaryWriter binaryWriter)
 {
     binaryWriter.Write(value);
 }
 /// <summary>
 /// Writes the data block to a file binary stream.
 /// </summary>
 /// <param name="binaryWriter">Binary writer to write the block to.</param>
 /// <param name="index">Index within a sequence (starts at 0).</param>
 public override void Write(SRBinaryWriter binaryWriter, int index)
 {
     try
     {
         binaryWriter.Write(m_pos_x);
         binaryWriter.Write(m_pos_y);
         binaryWriter.Write(m_pos_z);
         binaryWriter.Write(pitch);
         binaryWriter.Write(bank);
         binaryWriter.Write(heading);
         binaryWriter.Write((UInt16)vFileHeader.GetReferenceWriteOffsetByName(name));
     }
     catch (Exception e)
     {
         // Add context information for the error message
         if (index >= 0)
             e.Data[BlockName] = index + 1;
         throw;
     }
 }
Exemple #5
0
        /// <summary>
        /// Writes the data block to a file binary stream.
        /// </summary>
        /// <param name="binaryWriter">Binary writer to write the block to.</param>
        /// <param name="index">Index within a sequence (starts at 0).</param>
        public override void Write(SRBinaryWriter binaryWriter, int index)
        {
            try
            {
                binaryWriter.Align(Alignment);
                binaryWriter.Write(handleOffset);
                binaryWriter.Write(parentHandleOffset);
                binaryWriter.Write(objectTypeHash);
                binaryWriter.Write((UInt16)propertyList.Count);
                var positionBufferSize = binaryWriter.BaseStream.Position;
                binaryWriter.Write((UInt16)0);                      // Buffer size will be rewritten below
                binaryWriter.Write((UInt16)0);                      // Name offset will be rewritten below
                binaryWriter.Write(padding);
                UInt16 newNameOffset = 0;
                var startPosition = binaryWriter.BaseStream.Position;
                for (int i = 0; i < propertyList.Count; i++)
                {
                    binaryWriter.Align(SRZoneProperty.Alignment);
                    if (name != null && newNameOffset == 0 && (propertyList[i] is SRZoneStringProperty && propertyList[i].NameCrc == 0x355EF946 && propertyList[i].ToString() == name || (i + 1).ToString() == name))
                    {
                        if (propertyList[i].Type == SRZoneProperty.StringType)
                            newNameOffset = (UInt16)(binaryWriter.BaseStream.Position - startPosition + SRZoneProperty.DataOffset);
                        else
                            throw new SRZoneFileException("Object name references a non-string property.");
                    }
                    propertyList[i].Write(binaryWriter, i);
                }
                if (name != null && newNameOffset == 0)
                    throw new SRZoneFileException("Object name does not match a string property.");
                binaryWriter.Align(SRZoneProperty.Alignment);       // Align for buffer size calculation
                UInt16 newBufferSize = (UInt16)(binaryWriter.BaseStream.Position - startPosition);

                // Update the buffer size and name offset with the calculated values
                binaryWriter.Seek((int)positionBufferSize, SeekOrigin.Begin);
                binaryWriter.Write(newBufferSize);
                binaryWriter.Write(newNameOffset);
                binaryWriter.Seek(0, SeekOrigin.End);
            }
            catch (Exception e)
            {
                // Add context information for the error message
                if (index >= 0)
                    e.Data[BlockName] = index + 1;
                throw;
            }
        }
Exemple #6
0
        /// <summary>
        /// Writes the section block to a .czn_pc file binary stream.
        /// Recalculates the CPU data size so the original size is not used.
        /// </summary>
        /// <param name="binaryWriter">Binary writer to write the block to.</param>
        /// <param name="index">Index within a sequence (starts at 0).</param>
        public override void Write(SRBinaryWriter binaryWriter, int index)
        {
            try
            {
                binaryWriter.Align(Alignment);
                binaryWriter.Write(sectionID);
                var positionCpuSize = binaryWriter.BaseStream.Position;
                binaryWriter.Write((UInt32)0);      // Placeholder for CPU size, which is rewritten below
                if (HasGPUData())
                    binaryWriter.Write(gpuSize);
                var positionCpuDataStart = binaryWriter.BaseStream.Position;
                if (cpuData != null)
                    cpuData.Write(binaryWriter);
                var actualCpuDataSize = binaryWriter.BaseStream.Position - positionCpuDataStart;

                // Update the CPU data size with the actual number of bytes written
                binaryWriter.Seek((int)positionCpuSize, SeekOrigin.Begin);
                binaryWriter.Write((UInt32)actualCpuDataSize);
                binaryWriter.Seek(0, SeekOrigin.End);
            }
            catch (Exception e)
            {
                // Add context information for the error message
                if (index >= 0)
                    e.Data[BlockName] = index + 1;
                throw;
            }
        }
 /// <summary>
 /// Writes the data block to a file binary stream.
 /// </summary>
 /// <param name="binaryWriter">Binary writer to write the block to.</param>
 public override void Write(SRBinaryWriter binaryWriter)
 {
     binaryWriter.Align(Alignment);
     for (int i = 0; i < 4; i++)
         binaryWriter.Write((Byte)signature[i]);
     binaryWriter.Write(version);
     binaryWriter.Write((UInt32)0);
     fileReferenceOffset.Write(binaryWriter);
     binaryWriter.Write(fileReferencesPtr);
     binaryWriter.Write((UInt16)references.Count);
     binaryWriter.Write((Byte)zoneType);
     binaryWriter.Write((Byte)0);                        // Unused
     binaryWriter.Write((UInt32)0);                      // Interior Trigger Ptr (runtime)
     binaryWriter.Write((UInt16)0);                      // Number of Triggers (runtime)
     binaryWriter.Write((UInt16)0);                      // Extra objects (runtime)
     for (int i = 0; i < 24; i++)
         binaryWriter.Write((Byte)0);
     for (int i = 0; i < references.Count; i++)
         references[i].Write(binaryWriter, i);
 }
        /// <summary>
        /// Writes the data block to a file binary stream.
        /// </summary>
        /// <param name="binaryWriter">Binary writer to write the block to.</param>
        public override void Write(SRBinaryWriter binaryWriter)
        {
            binaryWriter.Write(signature);
            binaryWriter.Write(version);
            binaryWriter.Write((UInt32)objectList.Count);
            binaryWriter.Write((UInt32)handleList.Count);
            binaryWriter.Write(flags);
            binaryWriter.Write(handleListPointer);
            binaryWriter.Write(objectDataPointer);
            binaryWriter.Write(objectDataSize);

            if (OptionRebuildHandleList)
            {
                // BUILD HANDLE LIST
                UInt64[] newHandleList = new UInt64[objectList.Count];
                for (int i = 0; i < objectList.Count; i++)
                    newHandleList[i] = objectList[i].HandleOffset;
                Array.Sort(newHandleList);
                for (int i = 0; i < newHandleList.Length; i++)
                    binaryWriter.Write(newHandleList[i]);
            }
            else
            {
                for (int i = 0; i < handleList.Count; i++)
                    binaryWriter.Write(handleList[i]);
            }

            for (int i = 0; i < objectList.Count; i++)
                objectList[i].Write(binaryWriter, i);
        }
 /// <summary>
 /// Writes the data block to a file binary stream.
 /// </summary>
 /// <param name="binaryWriter">Binary writer to write the block to.</param>
 public override void Write(SRBinaryWriter binaryWriter)
 {
     binaryWriter.Write(data, 0, data.Length);
 }
Exemple #10
0
        // WRITERS
        /// <summary>
        /// Writes the data block to a file binary stream.
        /// </summary>
        /// <param name="binaryWriter">Binary writer to write the block to.</param>
        /// <param name="index">Index within a sequence (starts at 0).</param>
        public override void Write(SRBinaryWriter binaryWriter, int index)
        {
            try
            {
                binaryWriter.Align(Alignment);
                binaryWriter.Write(Type);
                var positionSize = binaryWriter.BaseStream.Position;
                binaryWriter.Write((UInt16)0);                          // Size Will be rewritten below
                binaryWriter.Write(nameCrc);
                var positionDataStart = binaryWriter.BaseStream.Position;
                WriteData(binaryWriter);
                var actualDataSize = binaryWriter.BaseStream.Position - positionDataStart;
                if (paddingData != null && paddingData.Size() == AlignPaddingSize(binaryWriter.BaseStream.Position, Alignment))
                    paddingData.Write(binaryWriter);

                // Update the value size with the actual number of bytes written
                binaryWriter.Seek((int)positionSize, SeekOrigin.Begin);
                binaryWriter.Write((UInt16)actualDataSize);
                binaryWriter.Seek(0, SeekOrigin.End);
            }
            catch (Exception e)
            {
                // Add context information for the error message
                if (index >= 0)
                    e.Data[BlockName] = index + 1;
                throw;
            }
        }