コード例 #1
0
        public virtual void Read(BinaryReader reader)
        {
            this.ChunkType = this._header.ChunkType;
            this.Version   = this._header.Version;
            this.Offset    = this._header.Offset;
            this.ID        = this._header.ID;
            this.Size      = this._header.Size;

            reader.BaseStream.Seek(this._header.Offset, 0);

            if (this._model.FileVersion == FileVersionEnum.CryTek_3_4 || this._model.FileVersion == FileVersionEnum.CryTek_3_5)
            {
                this.ChunkType = (ChunkTypeEnum)Enum.ToObject(typeof(ChunkTypeEnum), reader.ReadUInt32());
                this.Version   = reader.ReadUInt32();
                this.Offset    = reader.ReadUInt32();
                this.ID        = reader.ReadUInt32();
            }

            if (this.Offset != this._header.Offset || this.Size != this._header.Size)
            {
                Utils.Log(LogLevelEnum.Warning, "Conflict in chunk definition");
                Utils.Log(LogLevelEnum.Warning, "{0:X}+{1:X}", this._header.Offset, this._header.Size);
                Utils.Log(LogLevelEnum.Warning, "{0:X}+{1:X}", this.Offset, this.Size);
            }
        }
コード例 #2
0
ファイル: HepPacket.cs プロジェクト: spFly/sip
        /// <summary>
        /// Gets the chunk bytes for IP address type chunks.
        /// </summary>
        public static byte[] GetBytes(ChunkTypeEnum chunkType, IPAddress address)
        {
            if (chunkType == ChunkTypeEnum.IPv4SourceAddress || chunkType == ChunkTypeEnum.IPv4DesinationAddress)
            {
                if (address.AddressFamily != AddressFamily.InterNetwork)
                {
                    throw new ApplicationException("Incorrect IP address family suppled to HepChunk.");
                }

                byte[] buf = InitBuffer(chunkType, MINIMUM_CHUNK_LENGTH + 4);
                Buffer.BlockCopy(address.GetAddressBytes(), 0, buf, MINIMUM_CHUNK_LENGTH, 4);
                return(buf);
            }
            else if (chunkType == ChunkTypeEnum.IPv6SourceAddress || chunkType == ChunkTypeEnum.IPv6DesinationAddress)
            {
                if (address.AddressFamily != AddressFamily.InterNetworkV6)
                {
                    throw new ApplicationException("Incorrect IP address family suppled to HepChunk.");
                }

                byte[] buf = InitBuffer(chunkType, MINIMUM_CHUNK_LENGTH + 16);
                Buffer.BlockCopy(address.GetAddressBytes(), 0, buf, MINIMUM_CHUNK_LENGTH, 16);
                return(buf);
            }
            else
            {
                throw new ApplicationException("IP address HepChunk does not support the chunk type.");
            }
        }
コード例 #3
0
 // Write an empty node list.
 private static void WriteOctreeNodes(MemoryStream stream, ChunkTypeEnum type)
 {
     new ChunkHeader()
     {
         ChunkType = type,
         Version   = CURRENT_VERSION_OCTREE_NODES,
         Size      = 0
     }.WriteTo(stream);
 }
コード例 #4
0
        public static Chunk New(ChunkTypeEnum chunkType, UInt32 version)
        {
            switch (chunkType)
            {
            case ChunkTypeEnum.SourceInfo:
                return(Chunk.New <ChunkSourceInfo>(version));

            case ChunkTypeEnum.Timing:
                return(Chunk.New <ChunkTimingFormat>(version));

            case ChunkTypeEnum.ExportFlags:
                return(Chunk.New <ChunkExportFlags>(version));

            case ChunkTypeEnum.Mtl:
            //Utils.Log(LogLevelEnum.Debug, "Mtl Chunk here");  // Obsolete.  Not used?
            case ChunkTypeEnum.MtlName:
                return(Chunk.New <ChunkMtlName>(version));

            case ChunkTypeEnum.DataStream:
                return(Chunk.New <ChunkDataStream>(version));

            case ChunkTypeEnum.Mesh:
                return(Chunk.New <ChunkMesh>(version));

            case ChunkTypeEnum.MeshSubsets:
                return(Chunk.New <ChunkMeshSubsets>(version));

            case ChunkTypeEnum.Node:
                return(Chunk.New <ChunkNode>(version));

            case ChunkTypeEnum.CompiledBones:
                return(Chunk.New <ChunkCompiledBones>(version));

            case ChunkTypeEnum.Helper:
                return(Chunk.New <ChunkHelper>(version));

            case ChunkTypeEnum.Controller:
                return(Chunk.New <ChunkController>(version));

            case ChunkTypeEnum.SceneProps:
                return(Chunk.New <ChunkSceneProp>(version));

            case ChunkTypeEnum.CompiledPhysicalProxies:
                return(Chunk.New <ChunkCompiledPhysicalProxies>(version));

            case ChunkTypeEnum.MeshPhysicsData:
                return(Chunk.New <ChunkMeshPhysicsData>(version));

            default:
                return(new ChunkUnknown());
            }
        }
コード例 #5
0
ファイル: HepPacket.cs プロジェクト: pookokok/sipsorcery
        /// <summary>
        /// Gets the chunk bytes for an unsigned int chunk type.
        /// </summary>
        public static byte[] GetBytes(ChunkTypeEnum chunkType, uint val)
        {
            byte[] buf = InitBuffer(chunkType, MINIMUM_CHUNK_LENGTH + 4);

            if (BitConverter.IsLittleEndian)
            {
                Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(val)), 0, buf, MINIMUM_CHUNK_LENGTH, 4);
            }
            else
            {
                Buffer.BlockCopy(BitConverter.GetBytes(val), 0, buf, MINIMUM_CHUNK_LENGTH, 4);
            }
            return(buf);
        }
コード例 #6
0
        private static void WriteEmptyProviderLeaf(MemoryStream stream, UInt64 key, ChunkTypeEnum type)
        {
            var header = new ChunkHeader()
            {
                ChunkType = type,
                // ReSharper disable once BuiltInTypeReferenceStyle
                Size    = 0 + sizeof(UInt64), // increase chunk size by the size of key (which is inserted before it)
                Version = CURRENT_VERSION_OCTREE_LEAVES,
            };

            header.WriteTo(stream);

            stream.Write(key);
        }
コード例 #7
0
ファイル: HepPacket.cs プロジェクト: pookokok/sipsorcery
 /// <summary>
 /// Creates the initial buffer for the HEP packet and sets the vendor, chunk type ID and length fields.
 /// Note: Vendor ID could change and make endianess relevant.
 /// </summary>
 /// <param name="chunkType">The chunk type to set in the serialised chunk.</param>
 /// <param name="length">The value to set in the length field of the serialised chunk.</param>
 /// <returns>A buffer that contains the serialised chunk EXCEPT for the payload.</returns>
 private static byte[] InitBuffer(ChunkTypeEnum chunkType, ushort length)
 {
     byte[] buf = new byte[length];
     if (BitConverter.IsLittleEndian)
     {
         Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(GENERIC_VENDOR_ID)), 0, buf, 0, 2);
         Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian((ushort)chunkType)), 0, buf, 2, 2);
         Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian(length)), 0, buf, 4, 2);
     }
     else
     {
         Buffer.BlockCopy(BitConverter.GetBytes(GENERIC_VENDOR_ID), 0, buf, 0, 2);
         Buffer.BlockCopy(BitConverter.GetBytes((ushort)chunkType), 0, buf, 2, 2);
         Buffer.BlockCopy(BitConverter.GetBytes(length), 0, buf, 4, 2);
     }
     return(buf);
 }
コード例 #8
0
        private static unsafe void WriteOctreeNodes(Stream stream, ChunkTypeEnum type, Dictionary <UInt64, MyOctreeNode> nodes)
        {
            new ChunkHeader()
            {
                ChunkType = type,
                Version   = CURRENT_VERSION_OCTREE_NODES,
                Size      = nodes.Count * (sizeof(UInt64) + MyOctreeNode.SERIALIZED_SIZE)
            }.WriteTo(stream);

            foreach (var entry in nodes)
            {
                stream.WriteNoAlloc(entry.Key);
                var node = entry.Value;
                stream.WriteNoAlloc(node.ChildMask);
                stream.WriteNoAlloc(node.Data, 0, MyOctreeNode.CHILD_COUNT);
            }
        }
コード例 #9
0
ファイル: HepPacket.cs プロジェクト: pookokok/sipsorcery
        /// <summary>
        /// Gets a serialised HEP packet for a SIP request or response that can be sent to a HOMER server.
        /// </summary>
        /// <param name="srcEndPoint">The end point that sent the SIP request or response.</param>
        /// <param name="dstEndPoint">The end point that the SIP request or response was sent to.</param>
        /// <param name="timestamp">The timestamp the request or response was generated.</param>
        /// <param name="agentID">An agent ID that is used by the HOMER server to identify the agent generating
        /// HEP packets. Ideally should be unique amongst all agents logging to the same HOMER server.</param>
        /// <param name="password">The password required by the HOMER server. Can be set to null if no password
        /// is required. Default value for HOMER5 and 7 is 'myHep".</param>
        /// <param name="payload">The SIP request or response.</param>
        /// <returns>An array of bytes representing the serialised HEP packet and that is ready for transmission
        /// to a HOMER server.</returns>
        public static byte[] GetBytes(SIPEndPoint srcEndPoint, SIPEndPoint dstEndPoint, DateTime timestamp, uint agentID, string password, string payload)
        {
            byte[] packetBuffer = new byte[1024];
            int    offset       = 0;

            // HEP3 ASCII code to start the packet.
            packetBuffer[0] = 0x48;
            packetBuffer[1] = 0x45;
            packetBuffer[2] = 0x50;
            packetBuffer[3] = 0x33;

            offset = 6;

            // IP family.
            var familyChunkBuffer = HepChunk.GetBytes(ChunkTypeEnum.IPFamily, (byte)srcEndPoint.Address.AddressFamily);

            Buffer.BlockCopy(familyChunkBuffer, 0, packetBuffer, offset, familyChunkBuffer.Length);
            offset += familyChunkBuffer.Length;

            // IP transport layer protocol.
            var protocolChunkBuffer = HepChunk.GetBytes(ChunkTypeEnum.IPProtocolID, GetProtocolNumber(srcEndPoint.Protocol));

            Buffer.BlockCopy(protocolChunkBuffer, 0, packetBuffer, offset, protocolChunkBuffer.Length);
            offset += protocolChunkBuffer.Length;

            // Source IP address.
            ChunkTypeEnum srcChunkType = srcEndPoint.Address.AddressFamily == AddressFamily.InterNetwork ? ChunkTypeEnum.IPv4SourceAddress : ChunkTypeEnum.IPv6SourceAddress;
            var           srcIPAddress = HepChunk.GetBytes(srcChunkType, srcEndPoint.Address);

            Buffer.BlockCopy(srcIPAddress, 0, packetBuffer, offset, srcIPAddress.Length);
            offset += srcIPAddress.Length;

            // Destination IP address.
            ChunkTypeEnum dstChunkType = dstEndPoint.Address.AddressFamily == AddressFamily.InterNetwork ? ChunkTypeEnum.IPv4DesinationAddress : ChunkTypeEnum.IPv6DesinationAddress;
            var           dstIPAddress = HepChunk.GetBytes(dstChunkType, dstEndPoint.Address);

            Buffer.BlockCopy(dstIPAddress, 0, packetBuffer, offset, dstIPAddress.Length);
            offset += dstIPAddress.Length;

            // Source port.
            var srcPortBuffer = HepChunk.GetBytes(ChunkTypeEnum.SourcePort, (ushort)srcEndPoint.Port);

            Buffer.BlockCopy(srcPortBuffer, 0, packetBuffer, offset, srcPortBuffer.Length);
            offset += srcPortBuffer.Length;

            // Destination port.
            var dstPortBuffer = HepChunk.GetBytes(ChunkTypeEnum.DestinationPort, (ushort)dstEndPoint.Port);

            Buffer.BlockCopy(dstPortBuffer, 0, packetBuffer, offset, dstPortBuffer.Length);
            offset += dstPortBuffer.Length;

            // Timestamp.
            var timestampBuffer = HepChunk.GetBytes(ChunkTypeEnum.TimestampSeconds, (uint)timestamp.GetEpoch());

            Buffer.BlockCopy(timestampBuffer, 0, packetBuffer, offset, timestampBuffer.Length);
            offset += timestampBuffer.Length;

            // Timestamp micro seconds (.NET only has milliscond resolution).
            var timestampMicrosBuffer = HepChunk.GetBytes(ChunkTypeEnum.TimestampMicroSeconds, (uint)(timestamp.Millisecond * 1000));

            Buffer.BlockCopy(timestampMicrosBuffer, 0, packetBuffer, offset, timestampMicrosBuffer.Length);
            offset += timestampMicrosBuffer.Length;

            // Protocol type, only interested in SIP at this point.
            var protocolTypeBuffer = HepChunk.GetBytes(ChunkTypeEnum.ProtocolType, (byte)CaptureProtocolTypeEnum.SIP);

            Buffer.BlockCopy(protocolTypeBuffer, 0, packetBuffer, offset, protocolTypeBuffer.Length);
            offset += protocolTypeBuffer.Length;

            // Capture agent ID.
            var agentIDBuffer = HepChunk.GetBytes(ChunkTypeEnum.CaptureAgentID, agentID);

            Buffer.BlockCopy(agentIDBuffer, 0, packetBuffer, offset, agentIDBuffer.Length);
            offset += agentIDBuffer.Length;

            // Auth key
            if (!String.IsNullOrEmpty(password))
            {
                var passwordBuffer = HepChunk.GetBytes(ChunkTypeEnum.AuthenticationKey, Encoding.UTF8.GetBytes(password));
                Buffer.BlockCopy(passwordBuffer, 0, packetBuffer, offset, passwordBuffer.Length);
                offset += passwordBuffer.Length;
            }

            // Payload
            var payloadBuffer = HepChunk.GetBytes(ChunkTypeEnum.CapturedPayload, Encoding.UTF8.GetBytes(payload));

            Buffer.BlockCopy(payloadBuffer, 0, packetBuffer, offset, payloadBuffer.Length);
            offset += payloadBuffer.Length;

            // Length
            if (BitConverter.IsLittleEndian)
            {
                Buffer.BlockCopy(BitConverter.GetBytes(NetConvert.DoReverseEndian((ushort)offset)), 0, packetBuffer, 4, 2);
            }
            else
            {
                Buffer.BlockCopy(BitConverter.GetBytes((ushort)offset), 0, packetBuffer, 4, 2);
            }

            return(packetBuffer.Take(offset).ToArray());
        }
コード例 #10
0
ファイル: HepPacket.cs プロジェクト: pookokok/sipsorcery
 /// <summary>
 /// Gets the chunk bytes for an arbitrary payload.
 /// </summary>
 public static byte[] GetBytes(ChunkTypeEnum chunkType, byte[] payload)
 {
     byte[] buf = InitBuffer(chunkType, (ushort)(MINIMUM_CHUNK_LENGTH + payload.Length));
     Buffer.BlockCopy(payload, 0, buf, MINIMUM_CHUNK_LENGTH, (ushort)payload.Length);
     return(buf);
 }
コード例 #11
0
ファイル: HepPacket.cs プロジェクト: pookokok/sipsorcery
 /// <summary>
 /// Gets the chunk bytes for a single byte chunk type.
 /// </summary>
 public static byte[] GetBytes(ChunkTypeEnum chunkType, byte val)
 {
     byte[] buf = InitBuffer(chunkType, MINIMUM_CHUNK_LENGTH + 1);
     buf[MINIMUM_CHUNK_LENGTH] = val;
     return(buf);
 }
コード例 #12
0
        private static void WriteDefaultMicroOctreeLeaf(MemoryStream stream, UInt64 key, ChunkTypeEnum type, byte val)
        {
            var header = new ChunkHeader()
            {
                ChunkType = type,
                // ReSharper disable once BuiltInTypeReferenceStyle
                Size =
                    sizeof(int) + sizeof(byte) +
                    sizeof(UInt64), // increase chunk size by the size of key (which is inserted before it)
                Version = CURRENT_VERSION_OCTREE_LEAVES,
            };

            header.WriteTo(stream);

            stream.Write(4);   // micro octree height
            stream.Write(val); // micro octree default value

            // don't write any nodes.  (this *should* be okay)
        }
コード例 #13
0
 public void ReadFrom(Stream stream)
 {
     ChunkType    = (ChunkTypeEnum)stream.Read7BitEncodedInt();
     Version = stream.Read7BitEncodedInt();
     Size    = stream.Read7BitEncodedInt();
 }
コード例 #14
0
ファイル: Chunk.cs プロジェクト: hck509/Cryengine-Converter
        public static Chunk New(ChunkTypeEnum chunkType, UInt32 version)
        {
            switch (chunkType)
            {
            case ChunkTypeEnum.SourceInfo:
                return(Chunk.New <ChunkSourceInfo>(version));

            case ChunkTypeEnum.Timing:
                return(Chunk.New <ChunkTimingFormat>(version));

            case ChunkTypeEnum.ExportFlags:
                return(Chunk.New <ChunkExportFlags>(version));

            case ChunkTypeEnum.MtlName:
                return(Chunk.New <ChunkMtlName>(version));

            case ChunkTypeEnum.DataStream:
                return(Chunk.New <ChunkDataStream>(version));

            case ChunkTypeEnum.Mesh:
                return(Chunk.New <ChunkMesh>(version));

            case ChunkTypeEnum.MeshSubsets:
                return(Chunk.New <ChunkMeshSubsets>(version));

            case ChunkTypeEnum.Node:
                return(Chunk.New <ChunkNode>(version));

            case ChunkTypeEnum.Helper:
                return(Chunk.New <ChunkHelper>(version));

            case ChunkTypeEnum.Controller:
                return(Chunk.New <ChunkController>(version));

            case ChunkTypeEnum.SceneProps:
                return(Chunk.New <ChunkSceneProp>(version));

            case ChunkTypeEnum.MeshPhysicsData:
                return(Chunk.New <ChunkMeshPhysicsData>(version));

            case ChunkTypeEnum.BoneAnim:
                return(Chunk.New <ChunkBoneAnim>(version));

            // Compiled chunks
            case ChunkTypeEnum.CompiledBones:
                return(Chunk.New <ChunkCompiledBones>(version));

            case ChunkTypeEnum.CompiledPhysicalProxies:
                return(Chunk.New <ChunkCompiledPhysicalProxies>(version));

            case ChunkTypeEnum.CompiledPhysicalBones:
                return(Chunk.New <ChunkCompiledPhysicalBones>(version));

            case ChunkTypeEnum.CompiledIntSkinVertices:
                return(Chunk.New <ChunkCompiledIntSkinVertices>(version));

            case ChunkTypeEnum.CompiledMorphTargets:
                return(Chunk.New <ChunkCompiledMorphTargets>(version));

            case ChunkTypeEnum.CompiledExt2IntMap:
                return(Chunk.New <ChunkCompiledExtToIntMap>(version));

            case ChunkTypeEnum.CompiledIntFaces:
                return(Chunk.New <ChunkCompiledIntFaces>(version));

            // Star Citizen equivalents
            case ChunkTypeEnum.CompiledBonesSC:
                return(Chunk.New <ChunkCompiledBones>(version));

            case ChunkTypeEnum.CompiledPhysicalBonesSC:
                return(Chunk.New <ChunkCompiledPhysicalBones>(version));

            case ChunkTypeEnum.CompiledExt2IntMapSC:
                return(Chunk.New <ChunkCompiledExtToIntMap>(version));

            case ChunkTypeEnum.CompiledIntFacesSC:
                return(Chunk.New <ChunkCompiledIntFaces>(version));

            case ChunkTypeEnum.CompiledIntSkinVerticesSC:
                return(Chunk.New <ChunkCompiledIntSkinVertices>(version));

            case ChunkTypeEnum.CompiledMorphTargetsSC:
                return(Chunk.New <ChunkCompiledMorphTargets>(version));

            case ChunkTypeEnum.CompiledPhysicalProxiesSC:
                return(Chunk.New <ChunkCompiledPhysicalProxies>(version));

            // Old chunks
            case ChunkTypeEnum.BoneNameList:
                return(Chunk.New <ChunkBoneNameList>(version));

            case ChunkTypeEnum.MeshMorphTarget:
                return(Chunk.New <ChunkMeshMorphTargets>(version));

            case ChunkTypeEnum.Mtl:
            //Utils.Log(LogLevelEnum.Debug, "Mtl Chunk here");  // Obsolete.  Not used
            default:
                return(new ChunkUnknown());
            }
        }
コード例 #15
0
 public void ReadFrom(Stream stream)
 {
     ChunkType = (ChunkTypeEnum)stream.Read7BitEncodedInt();
     Version   = stream.Read7BitEncodedInt();
     Size      = stream.Read7BitEncodedInt();
 }