コード例 #1
0
 public void Read(SRBinaryReader binaryReader)
 {
     x = binaryReader.ReadSingle();
     y = binaryReader.ReadSingle();
     z = binaryReader.ReadSingle();
     w = binaryReader.ReadSingle();
 }
コード例 #2
0
 // PROTECTED READERS / WRITERS
 // See description of this method in the abstract base class SRZoneProperty.
 protected override void ReadData(SRBinaryReader binaryReader, int size)
 {
     position = new SRPosition(binaryReader);
     SRTrace.WriteLine("        Value:     Position (x,y,z):  " + position.ToString());
     if (size != 12)
         throw new SRZoneFileException("Transform length is wrong.");
 }
コード例 #3
0
 // PROTECTED READERS / WRITERS
 // See description of this method in the abstract base class SRZoneProperty.
 protected override void ReadData(SRBinaryReader binaryReader, int size)
 {
     value = binaryReader.ReadString();
     SRTrace.WriteLine("        Value:     \"" + value + "\"");
     if (value.Length + 1 != size)
         throw new SRZoneFileException("String length is wrong.");
 }
コード例 #4
0
 // PROTECTED READERS / WRITERS
 // See description of this method in the abstract base class SRZoneProperty.
 protected override void ReadData(SRBinaryReader binaryReader, int size)
 {
     base.ReadData(binaryReader, 12);    // Read the position part
     orientation = new SRQuaternionOrientation(binaryReader);
     SRTrace.WriteLine("                   Orientation (x,y,z,w):  " + orientation.ToString());
     if (size != 28)
         throw new SRZoneFileException("Transform/Orientation length is wrong.");
 }
コード例 #5
0
ファイル: SRRawDataBlock.cs プロジェクト: clarosa/SRZoneTools
 // READERS / WRITERS
 /// <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>
 public void Read(SRBinaryReader binaryReader, int size)
 {
     if (size <= 0)
         throw new ArgumentOutOfRangeException("size", "Datablock size must not be zero.");
     data = new Byte[size];
     if (binaryReader.Read(data, 0, size) != size)
         throw new SRZoneFileException("EOF reached prematurely");
 }
コード例 #6
0
 // READERS / WRITERS
 /// <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>
 public void Read(SRBinaryReader binaryReader, int index)
 {
     try
     {
         m_pos_x = binaryReader.ReadInt16();
         m_pos_y = binaryReader.ReadInt16();
         m_pos_z = binaryReader.ReadInt16();
         pitch = binaryReader.ReadInt16();
         bank = binaryReader.ReadInt16();
         heading = binaryReader.ReadInt16();
         int m_str_offset = binaryReader.ReadInt16();
         SRTrace.WriteLine("    REFERENCE #{0}:  {1},{2},{3},{4},{5},{6},{7}", index + 1, m_pos_x, m_pos_y, m_pos_z, pitch, bank, heading, m_str_offset);
         name = vFileHeader.GetReferenceNameByReadOffset(m_str_offset);
     }
     catch (Exception e)
     {
         // Add context information for the error message
         if (index >= 0)
             e.Data[BlockName] = index + 1;
         throw;
     }
 }
コード例 #7
0
ファイル: SRZoneObject.cs プロジェクト: clarosa/SRZoneTools
 public SRZoneObject(SRBinaryReader binaryReader, int index)
 {
     Read(binaryReader, index);
 }
コード例 #8
0
ファイル: SRZoneObject.cs プロジェクト: clarosa/SRZoneTools
 // READERS / WRITERS
 /// <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>
 public void Read(SRBinaryReader binaryReader, int index)
 {
     try
     {
         binaryReader.Align(Alignment);
         SRTrace.WriteLine("");
         SRTrace.WriteLine("    OBJECT #{0}:  [file offset 0x{1:X8}]", index + 1, binaryReader.BaseStream.Position);
         handleOffset = binaryReader.ReadUInt64();
         SRTrace.WriteLine("      Handle Offset:         0x{0:X16}", handleOffset);
         parentHandleOffset = binaryReader.ReadUInt64();
         SRTrace.WriteLine("      Parent Handle Offset:  0x{0:X16}", parentHandleOffset);
         objectTypeHash = binaryReader.ReadInt32();
         SRTrace.WriteLine("      Object Type Hash:      0x{0:X8}", objectTypeHash);
         var propertyCount = binaryReader.ReadUInt16();
         SRTrace.WriteLine("      Number of Properties:  {0}", propertyCount);
         var bufferSize = binaryReader.ReadUInt16();
         SRTrace.WriteLine("      Buffer Size:           {0}", bufferSize);
         var nameOffset = binaryReader.ReadUInt16();
         SRTrace.WriteLine("      Name Offset:           {0}", nameOffset);
         padding = binaryReader.ReadUInt16();
         SRTrace.WriteLine("      Padding:               {0}", padding);
         if (propertyCount == 0)
             throw new SRZoneFileException("Object has no properties.");
         propertyList = new List<SRZoneProperty>(propertyCount);
         var namePosition = binaryReader.BaseStream.Position + nameOffset - SRZoneProperty.DataOffset;
         name = null;
         for (int i = 0; i < propertyCount; i++)
         {
             long position = AlignUp(binaryReader.BaseStream.Position, SRZoneProperty.Alignment);
             SRZoneProperty property = SRZoneProperty.Create(binaryReader, i);
             propertyList.Add(property);
             if (position == namePosition)
             {
                 if (property is SRZoneStringProperty)
                     name = property.ToString();
                 else if (property.Type == SRZoneProperty.StringType)
                     name = (i + 1).ToString();
                 else
                     throw new SRZoneFileException("Name Offset does not point to a string property.");
             }
         }
         if (nameOffset != 0 && name == null)
             throw new SRZoneFileException("Name Offset does not point to a valid property.");
     }
     catch (Exception e)
     {
         // Add context information for the error message
         if (index >= 0)
             e.Data[BlockName] = index + 1;
         throw;
     }
 }
コード例 #9
0
ファイル: SRZoneSection.cs プロジェクト: clarosa/SRZoneTools
 public SRZoneSection(SRBinaryReader binaryReader, int index)
 {
     Read(binaryReader, index);
 }
コード例 #10
0
ファイル: SRZoneSection.cs プロジェクト: clarosa/SRZoneTools
 // READERS / WRITERS
 /// <summary>
 /// Reads a section block from a .czn_pc 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>
 public void Read(SRBinaryReader binaryReader, int index)
 {
     try
     {
         binaryReader.Align(Alignment);
         SRTrace.WriteLine("");
         SRTrace.WriteLine("SECTION #{0}:  [file offset 0x{1:X8}]", index + 1, binaryReader.BaseStream.Position);
         sectionID = binaryReader.ReadUInt32();
         SRTrace.WriteLine("  Section ID:   0x{0:X8}", sectionID);
         if (SectionType() < 0x2233 || SectionType() >= 0x2300)
             throw new SRZoneFileException("Invalid section ID.  Not a valid zone file.");
         if (HasDescription())
             SRTrace.WriteLine("  Description:  " + Description());
         var cpuSize = binaryReader.ReadUInt32();
         SRTrace.WriteLine("  CPU Size:     {0} bytes", cpuSize);
         gpuSize = 0;
         if (HasGPUData())
         {
             gpuSize = binaryReader.ReadUInt32();
             SRTrace.WriteLine("  GPU Size:     {0} bytes", gpuSize);
         }
         if (cpuSize == 0)
             cpuData = null;
         else if (OptionParseObjects && SectionType() == 0x2234)
             cpuData = new SRZoneObjectSectionCpuData(binaryReader, (int)cpuSize);
         else
             cpuData = new SRRawDataBlock(binaryReader, (int)cpuSize);
     }
     catch (Exception e)
     {
         // Add context information for the error message
         if (index >= 0)
             e.Data[BlockName] = index + 1;
         throw;
     }
 }
コード例 #11
0
ファイル: SRPosition.cs プロジェクト: clarosa/SRZoneTools
 public SRPosition(SRBinaryReader binaryReader)
 {
     Read(binaryReader);
 }
コード例 #12
0
ファイル: SRVFileHeader.cs プロジェクト: clarosa/SRZoneTools
 public SRVFileHeader(SRBinaryReader binaryReader)
 {
     Read(binaryReader);
 }
コード例 #13
0
ファイル: SRZoneProperty.cs プロジェクト: clarosa/SRZoneTools
 // PROTECTED ABSTRACT METHODS
 /// <summary>
 /// Reads the property data for a specific property type from a file binary stream.
 /// </summary>
 /// <param name="binaryReader">Binary reader to read the property data from.
 ///   Must point to the beginning of the property data immediately following the header.</param>
 /// <param name="index">Number of bytes to read.</param>
 protected abstract void ReadData(SRBinaryReader binaryReader, int size);
コード例 #14
0
ファイル: SRZoneProperty.cs プロジェクト: clarosa/SRZoneTools
        /// <summary>
        /// Reads a property block from a file binary stream and creates a new property object containing the data.
        /// The returned property will be an instance of one of the concrete derived property classes.
        /// </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>
        /// <returns>The new zone property which was read from the input stream.</returns>
        public static SRZoneProperty Create(SRBinaryReader binaryReader, int index)
        {
            SRZoneProperty property;
            try
            {
                // Read the common header
                binaryReader.Align(Alignment);
                SRTrace.WriteLine("");
                SRTrace.WriteLine("      PROPERTY #{0}:  [file offset 0x{1:X8}]", index + 1, binaryReader.BaseStream.Position);
                UInt16 type = binaryReader.ReadUInt16();
                string typeName = (type < PropertyTypeNames.Length) ? PropertyTypeNames[type] : "unknown";
                SRTrace.WriteLine("        Type:      {0} ({1})", type, typeName);
                UInt16 size = binaryReader.ReadUInt16();
                SRTrace.WriteLine("        Size:      {0} bytes", size);
                Int32 nameCrc = binaryReader.ReadInt32();
                SRTrace.WriteLine("        Name CRC:  0x{0:X8} ({0})", nameCrc, nameCrc);

                // Create the appropriate derived class based on the header information
                property = Create(type, nameCrc);

                // Read the class-specific data into the derived class
                property.ReadData(binaryReader, size);

                // WARNING:  There's a bunch of cruft after the "size" length which is part of the padding to
                // a dword boundry, but if we don't save it then the output file won't compare to the input file.
                if (OptionPreservePadding)
                {
                    var paddingSize = AlignPaddingSize(binaryReader.BaseStream.Position, Alignment);
                    if (paddingSize > 0)
                        property.paddingData = new SRRawDataBlock(binaryReader, paddingSize);
                    else
                        property.paddingData = null;
                }
            }
            catch (Exception e)
            {
                // Add context information for the error message
                if (index >= 0)
                    e.Data[BlockName] = index + 1;
                throw;
            }
            return property;
        }
コード例 #15
0
 public SRQuaternionOrientation(SRBinaryReader binaryReader)
 {
     Read(binaryReader);
 }
コード例 #16
0
 // READERS / WRITERS
 /// <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>
 public void Read(SRBinaryReader binaryReader, int size)
 {
     SRTrace.WriteLine("");
     SRTrace.WriteLine("  OBJECT SECTION HEADER:");
     signature = binaryReader.ReadUInt32();
     SRTrace.WriteLine("    Header Signature:     0x{0:X8}", signature);
     if (signature != 0x574F4246)
         throw new SRZoneFileException("Invalid section ID");
     version = binaryReader.ReadUInt32();
     SRTrace.WriteLine("    Version:              {0}", version);
     if (version != 5)
         throw new SRZoneFileException("Invalid version number");
     var numObjects = binaryReader.ReadUInt32();
     SRTrace.WriteLine("    Number of Objects:    {0}", numObjects);
     var numHandles = binaryReader.ReadUInt32();
     SRTrace.WriteLine("    Number of Handles:    {0}", numHandles);
     flags = binaryReader.ReadUInt32();
     SRTrace.WriteLine("    Flags:                0x{0:X8}", flags);
     handleListPointer = binaryReader.ReadUInt32();
     SRTrace.WriteLine("    Handle List Pointer:  0x{0:X8}  (run-time)", handleListPointer);
     objectDataPointer = binaryReader.ReadUInt32();
     SRTrace.WriteLine("    Object Data Pointer:  0x{0:X8}  (run-time)", objectDataPointer);
     objectDataSize = binaryReader.ReadUInt32();
     SRTrace.WriteLine("    Object Data Size:     {0,-10}  (run-time)", objectDataSize);
     SRTrace.WriteLine("");
     SRTrace.WriteLine("    HANDLE LIST:");
     handleList = new List<UInt64>((int)numHandles);
     for (int i = 0; i < numHandles; i++)
     {
         handleList.Add(binaryReader.ReadUInt64());
         SRTrace.WriteLine("     {0,3}. 0x{1:X16}", i + 1, handleList[i]);
     }
     objectList = new List<SRZoneObject>((int)numObjects);
     for (int i = 0; i < numObjects; i++)
         objectList.Add(new SRZoneObject(binaryReader, i));
 }
コード例 #17
0
 public SRZoneObjectSectionCpuData(SRBinaryReader binaryReader, int size)
 {
     Read(binaryReader, size);
 }
コード例 #18
0
 public SRZoneMeshFileReference(SRBinaryReader binaryReader, int index, SRVFileHeader vFileHeader)
 {
     this.vFileHeader = vFileHeader;
     Read(binaryReader, index);
 }
コード例 #19
0
        /// <summary>
        /// Reads the zone file into memory.
        /// </summary>
        /// <param name="cznFile">File system path to the ".czn_pc" zone file.</param>
        public void ReadDataFile(string cznFile)
        {
            SRTrace.WriteLine("");
            SRTrace.WriteLine("-------------------------------------------------------------------------------");
            SRTrace.WriteLine("ZONE DATA FILE:  " + Path.GetFileName(cznFile));

            FileStream stream = null;
            try
            {
                sectionList = new List<SRZoneSection>();
                stream = new FileStream(cznFile, FileMode.Open, FileAccess.Read);
                SRBinaryReader binaryReader = new SRBinaryReader(stream);
                int index = 0;
                while (binaryReader.BaseStream.Position <= binaryReader.BaseStream.Length - 4)
                    sectionList.Add(new SRZoneSection(binaryReader, index++));
            }
            catch (Exception e)
            {
                // Add context information for the error message
                e.Data["Action"] = "reading Zone Data file";
                throw;
            }
            finally
            {
                if (stream != null)
                    stream.Close();
            }
        }
コード例 #20
0
 // PROTECTED READERS / WRITERS
 // See description of this method in the abstract base class SRZoneProperty.
 protected override void ReadData(SRBinaryReader binaryReader, int size)
 {
     data = new SRRawDataBlock(binaryReader, size);
     SRTrace.WriteLine("        Value:     " + data.ToString());
 }
コード例 #21
0
ファイル: SRRawDataBlock.cs プロジェクト: clarosa/SRZoneTools
 public SRRawDataBlock(SRBinaryReader binaryReader, int size)
 {
     Read(binaryReader, size);
 }
コード例 #22
0
ファイル: SRVFileHeader.cs プロジェクト: clarosa/SRZoneTools
 // READERS / WRITERS
 /// <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>
 public void Read(SRBinaryReader binaryReader)
 {
     SRTrace.WriteLine("");
     SRTrace.WriteLine("V-FILE HEADER:");
     signature = binaryReader.ReadUInt16();
     SRTrace.WriteLine("  V-File Signature:      0x{0:X4}", signature);
     if (signature != 0x3854)
         throw new Exception("Incorrect V-file signature.  Not a valid zone header file.");
     version = binaryReader.ReadUInt16();
     SRTrace.WriteLine("  V-File Version:        {0}", version);
     if (version != 4)
         throw new Exception("Incorrect V-file version.");
     int refDataSize = binaryReader.ReadInt32();
     SRTrace.WriteLine("  Reference Data Size:   {0}", refDataSize);
     refDataStart = binaryReader.ReadUInt32();
     SRTrace.WriteLine("  Reference Data Start:  0x{0:X8}", refDataStart);
     //            if (refDataStart != 0)
     //                throw new SRZoneFileException("Expected reference data start to be zero.");
     int refCount = binaryReader.ReadInt32();
     SRTrace.WriteLine("  Reference Count:       {0}", refCount);
     unknown = binaryReader.ReadUInt32();
     SRTrace.WriteLine("  Unknown:               0x{0:X8}", unknown);
     binaryReader.BaseStream.Seek(12, SeekOrigin.Current);
     long refDataOffset = binaryReader.BaseStream.Position;
     SRTrace.WriteLine("");
     SRTrace.WriteLine("  REFERENCE DATA:");
     referenceData = new List<string>(refCount);
     referenceNamesByReadOffset = new Dictionary<long, string>(refCount);
     var positionDataStart = binaryReader.BaseStream.Position;
     for (int i = 1; i <= refCount; i++)
     {
         long offset = binaryReader.BaseStream.Position - positionDataStart;
         string name = binaryReader.ReadString();
         SRTrace.WriteLine("   {0,3}. {1}", i, name);
         referenceData.Add(name);
         referenceNamesByReadOffset.Add(offset, OptionNameReferenceIdentifier ? name : i.ToString());
     }
     var finalNull = binaryReader.ReadByte();
     if (finalNull != 0)
         throw new Exception("Expected trailing null byte.");
 }
コード例 #23
0
 // READERS / WRITERS
 /// <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>
 public void Read(SRBinaryReader binaryReader)
 {
     binaryReader.Align(Alignment);
     SRTrace.WriteLine("");
     SRTrace.WriteLine("WORLD ZONE HEADER:  [file offset 0x{0:X8}]", binaryReader.BaseStream.Position);
     signature = new string(binaryReader.ReadChars(4));
     SRTrace.WriteLine("  World Zone Signature:   " + signature);
     if (signature != "SR3Z")
         throw new SRZoneFileException("Incorrect world zone signature.", binaryReader.BaseStream.Position - 4);
     version = binaryReader.ReadUInt32();
     SRTrace.WriteLine("  World Zone Version:     {0}", version);
     if (version != 29 && version != 32)  // version 29 = SR3, 32 = SR4
         throw new SRZoneFileException("Incorrect world zone version.");
     int v_file_header_ptr = binaryReader.ReadInt32();
     SRTrace.WriteLine("  V-File Header Pointer:  0x{0:X8}", v_file_header_ptr);
     fileReferenceOffset = new SRPosition(binaryReader);
     SRTrace.WriteLine("  File Reference Offset:  {0}", fileReferenceOffset.ToString());
     fileReferencesPtr = binaryReader.ReadUInt32();
     SRTrace.WriteLine("  WZ File Reference Ptr:  0x{0:X8}", fileReferencesPtr);
     int num_file_references = binaryReader.ReadInt16();
     SRTrace.WriteLine("  Number of File Refs:    {0}", num_file_references);
     zoneType = binaryReader.ReadByte();
     string typeName = (zoneType < WorldZoneTypeNames.Length) ? WorldZoneTypeNames[zoneType] : "unknown";
     SRTrace.WriteLine("  Zone Type:              {0} ({1})", zoneType, typeName);
     int unused = binaryReader.ReadByte();
     SRTrace.WriteLine("  Unused:                 {0}", unused);
     if (unused != 0)
         throw new SRZoneFileException("Expected unused field to be zero.");
     int interiorTriggerPtr = binaryReader.ReadInt32();
     SRTrace.WriteLine("  Interior Trigger Ptr:   0x{0:X8}  (run-time)", interiorTriggerPtr);
     if (interiorTriggerPtr != 0)
         throw new SRZoneFileException("Expected interior trigger pointer to be zero.");
     int numberOfTriggers = binaryReader.ReadInt16();
     SRTrace.WriteLine("  Number of Triggers:     {0,-10}  (run-time)", numberOfTriggers);
     if (numberOfTriggers != 0)
         throw new SRZoneFileException("Expected number of triggers to be zero.");
     int extraObjects = binaryReader.ReadInt16();
     SRTrace.WriteLine("  Extra Objects:          {0}", extraObjects);
     if (extraObjects != 0)
         throw new SRZoneFileException("Expected extra objects to be zero.");
     binaryReader.BaseStream.Seek(24, SeekOrigin.Current);
     SRTrace.WriteLine("");
     SRTrace.WriteLine("  MESH FILE REFERENCES:  [file offset 0x{0:X8}]", binaryReader.BaseStream.Position);
     references = new List<SRZoneMeshFileReference>(num_file_references);
     for (int i = 0; i < num_file_references; i++)
         references.Add(new SRZoneMeshFileReference(binaryReader, i, vFileHeader));
 }
コード例 #24
0
 public SRWorldZoneHeader(SRBinaryReader binaryReader, SRVFileHeader vFileHeader)
 {
     this.vFileHeader = vFileHeader;
     Read(binaryReader);
 }
コード例 #25
0
        // READERS / WRITERS
        /// <summary>
        /// Reads the zone header file into memory.
        /// </summary>
        /// <param name="czhFile">File system path to the ".czn_pc" zone file.</param>
        public void ReadHeaderFile(string czhFile)
        {
            SRTrace.WriteLine("");
            SRTrace.WriteLine("-------------------------------------------------------------------------------");
            SRTrace.WriteLine("ZONE HEADER FILE:  " + Path.GetFileName(czhFile));

            FileStream stream = null;
            try
            {
                stream = new FileStream(czhFile, FileMode.Open, FileAccess.Read);
                SRBinaryReader binaryReader = new SRBinaryReader(stream);
                vFileHeader = new SRVFileHeader(binaryReader);
                worldZoneHeader = new SRWorldZoneHeader(binaryReader, vFileHeader);
            }
            catch (Exception e)
            {
                // Add context information for the error message
                e.Data["Action"] = "reading Zone Header file";
                throw;
            }
            finally
            {
                if (stream != null)
                    stream.Close();
            }
        }