Example #1
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;
            }
        }
Example #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.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);
 }
Example #3
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;
            }
        }
Example #4
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;
            }
        }