Beispiel #1
0
        public virtual async ValueTask <bool> ParseReplayHeader(CustomBinaryReaderAsync binaryReader)
        {
            if (!await ParseMagicNumber(binaryReader))
            {
                return(false);
            }
            ReplayHeader.ReplayVersionHistory fileVersion = (ReplayHeader.ReplayVersionHistory) await binaryReader.ReadUInt32Async();

            int lengthInMs = await binaryReader.ReadInt32Async();

            uint networkVersion = await binaryReader.ReadUInt32Async();

            uint changelist = await binaryReader.ReadUInt32Async();

            string friendlyName = await binaryReader.ReadStringAsync();

            bool isLive = await binaryReader.ReadUInt32Async() != 0;

            DateTime timestamp = DateTime.MinValue;

            if (fileVersion >= ReplayHeader.ReplayVersionHistory.recordedTimestamp)
            {
                timestamp = DateTime.FromBinary(await binaryReader.ReadInt64Async());
            }
            bool compressed = false;

            if (fileVersion >= ReplayHeader.ReplayVersionHistory.compression)
            {
                compressed = await binaryReader.ReadUInt32Async() != 0;
            }
            ReplayHeader = new ReplayHeader(lengthInMs, networkVersion, changelist, friendlyName, timestamp, 0,
                                            isLive, compressed, fileVersion);
            return(true);
        }
Beispiel #2
0
        public virtual async ValueTask <bool> ParseEventHeader(CustomBinaryReaderAsync binaryReader)
        {
            string id = await binaryReader.ReadStringAsync();

            string group = await binaryReader.ReadStringAsync();

            string metadata = await binaryReader.ReadStringAsync();

            uint time1 = await binaryReader.ReadUInt32Async();

            uint time2 = await binaryReader.ReadUInt32Async();

            int eventSizeInBytes = await binaryReader.ReadInt32Async();

            return(await ChooseEventChunkType(binaryReader, new EventOrCheckpointInfo( id, group, metadata, time1, time2 )));
        }
Beispiel #3
0
        public virtual async ValueTask <bool> ParseCheckpointHeader(CustomBinaryReaderAsync binaryReader)
        {
            string id = await binaryReader.ReadStringAsync();

            string group = await binaryReader.ReadStringAsync();

            string metadata = await binaryReader.ReadStringAsync();

            uint time1 = await binaryReader.ReadUInt32Async();

            uint time2 = await binaryReader.ReadUInt32Async();

            int eventSizeInBytes = await binaryReader.ReadInt32Async();

            using (IMemoryOwner <byte> uncompressed = await binaryReader.UncompressData())
            {
                return(ParseCheckpointContent(new MemoryReader(uncompressed.Memory, Endianness.Native), id, group, metadata, time1, time2));
            }
        }
Beispiel #4
0
        public virtual async ValueTask <bool> ParseReplayDataChunkHeader(CustomBinaryReaderAsync chunkReader)
        {
            uint time1 = uint.MaxValue;
            uint time2 = uint.MaxValue;

            if (ReplayHeader !.FileVersion >= ReplayVersionHistory.streamChunkTimes)
            {
                time1 = await chunkReader.ReadUInt32Async();

                time2 = await chunkReader.ReadUInt32Async();

                int replaySizeInBytes = await chunkReader.ReadInt32Async();
            }
            using (IMemoryOwner <byte> uncompressedData = await chunkReader.UncompressData())//TODO: check compress
            {
                //return ParseReplayData( new MemoryReader( uncompressedData.Memory, Endianness.Native ));
            }
            return(true);
        }
Beispiel #5
0
        /// <summary>
        /// Parse the header of a chunk, with that we know the <see cref="ChunkType"/> and the length of the chunk
        /// Took extra caution because there is no <see cref="SubStream"/> to protect the reading.
        /// When I discover the length of the replay, I immediatly create a SubStream so i can protect the rest of the replay.
        /// </summary>
        /// <param name="replayInfo"></param>
        /// <returns></returns>
        public virtual async ValueTask <ChunkHeader> ParseChunkHeader()
        {
            if (SubStreamFactory.CanReadLength && SubStreamFactory.CanReadPosition &&
                SubStreamFactory.BaseStream.Position == SubStreamFactory.BaseStream.Length)
            {
                return(new ChunkHeader {
                    ChunkType = ChunkType.EndOfStream, ChunkSize = 0
                });
            }

            int       chunkSize;
            ChunkType chunkType;

            await using (SubStream chunkHeader = SubStreamFactory.CreateSubstream(8))
                await using (CustomBinaryReaderAsync customReader = new CustomBinaryReaderAsync(chunkHeader, true))
                {
                    try //TODO add case when you can seek.
                    {
                        chunkType = (ChunkType)await customReader.ReadUInt32Async();
                    }
                    catch (EndOfStreamException)
                    {
                        chunkHeader.CancelSelfRepositioning();
                        return(new ChunkHeader {
                            ChunkType = ChunkType.EndOfStream, ChunkSize = 0
                        });
                    }
                    chunkSize = await customReader.ReadInt32Async();

                    if ((uint)chunkType > 3)
                    {
                        return(new ChunkHeader {
                            ChunkType = ChunkType.Unknown, ChunkSize = 0
                        });
                    }
                }
            return(new ChunkHeader {
                ChunkType = chunkType, ChunkSize = chunkSize
            });
        }