Exemplo n.º 1
0
        /// <summary>
        /// https://github.com/EpicGames/UnrealEngine/blob/7d9919ac7bfd80b7483012eab342cb427d60e8c9/Engine/Source/Runtime/Engine/Private/DemoNetDriver.cpp#L3220
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public virtual ReadPacketState ParsePacket(ChunkArchive reader)
        {
            const int MaxBufferSize = 2 * 1024;
            int       bufferSize    = reader.ReadInt32();

            if (bufferSize > MaxBufferSize || bufferSize < 0)
            {
                return(ReadPacketState.Error);
            }
            if (bufferSize == 0)
            {
                return(ReadPacketState.End);
            }
            var buffer = reader.HeapReadBytes(bufferSize);

            if (ProcessRawPacket(new BitArchive(buffer, DemoHeader !, ReplayHeader !)))
            {
                return(ReadPacketState.Success);
            }
            return(ReadPacketState.Error);
        }