public void Write(SRBinaryWriter binaryWriter) { binaryWriter.Write(x); binaryWriter.Write(y); binaryWriter.Write(z); binaryWriter.Write(w); }
// See description of this method in the abstract base class SRZoneProperty. protected override void WriteData(SRBinaryWriter binaryWriter) { position.Write(binaryWriter); }
/// <summary> /// Reads a data block from a file binary stream. /// </summary> /// <param name="binaryReader">Binary reader to read the block from. Must point to the beginning of the block.</param> /// <param name="size">Maximum number of bytes to read.</param> // abstract public void Read(SRBinaryReader binaryReader, int size); /// <summary> /// Writes the data block to a file binary stream. /// </summary> /// <param name="binaryWriter">Binary writer to write the block to.</param> public abstract void Write(SRBinaryWriter binaryWriter);
// 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; } }
/// <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; } }
/// <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 zone to a file. /// </summary> /// <param name="cznFile">File system path to the ".czn_pc" zone file.</param> public void WriteDataFile(string cznFile) { FileStream stream = null; SRBinaryWriter binaryWriter = null; try { if (sectionList == null) throw new SRZoneFileException("No zone data to write."); stream = File.Open(cznFile, FileMode.Create); binaryWriter = new SRBinaryWriter(stream); int index = 0; foreach (SRZoneSection section in sectionList) section.Write(binaryWriter, index++); } catch (Exception e) { // Add context information for the error message e.Data["Action"] = "writing Zone Data file"; throw; } finally { if (binaryWriter != null) binaryWriter.Close(); } }
// See description of this method in the abstract base class SRZoneProperty. protected override void WriteData(SRBinaryWriter binaryWriter) { data.Write(binaryWriter); }
/// <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); }
/// <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 property data for a specific property type to a file binary stream. /// </summary> /// <param name="binaryWriter">Binary writer to write the property data to.</param> protected abstract void WriteData(SRBinaryWriter binaryWriter);
// 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; } }
/// <summary> /// Writes the zone to a file. /// </summary> /// <param name="czhFile">File system path to the ".czh_pc" zone file.</param> public void WriteHeaderFile(string czhFile) { FileStream stream = null; SRBinaryWriter binaryWriter = null; try { if (vFileHeader == null || worldZoneHeader == null) throw new SRZoneFileException("No zone header to write."); stream = File.Open(czhFile, FileMode.Create); binaryWriter = new SRBinaryWriter(stream); vFileHeader.Write(binaryWriter); worldZoneHeader.Write(binaryWriter); } catch (Exception e) { // Add context information for the error message e.Data["Action"] = "writing Zone Header file"; throw; } finally { if (binaryWriter != null) binaryWriter.Close(); } }
/// <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); }
/// <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); }
// See description of this method in the abstract base class SRZoneProperty. protected override void WriteData(SRBinaryWriter binaryWriter) { base.WriteData(binaryWriter); // Write the position part orientation.Write(binaryWriter); }
/// <summary> /// Reads a data block from a file binary stream. /// </summary> /// <param name="binaryReader">Binary reader to read the block from. Must point to the beginning of the block.</param> /// <param name="index">Index within a sequence (starts at 0).</param> // abstract public void Read(SRBinaryReader binaryReader, int index, int size); /// <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 abstract void Write(SRBinaryWriter binaryWriter, int index);