public void ParseFromBuffer(BinaryReader reader, LegacyGameStats.GameStatsVersion blobVersion) { _blobVersion = blobVersion; Count = reader.ReadInt32(); Seconds = reader.ReadInt32(); Seconds = Math.Max(Seconds, 0); Commentary = reader.ReadInt32(); Hdr = reader.ReadInt32(); Captions = reader.ReadInt32(); // Read the skill sections for (var i = 0; i < 3; i++) { Skill[i] = reader.ReadInt32(); if (Skill[i] > 100000 || Skill[i] < 0) { throw new InvalidOperationException("Invalid number of sections."); } } // Check section lengths if (Count > 100000 || Count < 0 || Seconds > 100000 || Seconds < 0 || Commentary > 100000 || Commentary < 0 || Hdr > 100000 || Hdr < 0 || Captions > 100000 || Captions < 0) { throw new InvalidOperationException("Invalid number of sections."); } if (_blobVersion > LegacyGameStats.GameStatsVersion.Old) { Steam = Convert.ToBoolean((int)reader.ReadChar()); } if (_blobVersion > LegacyGameStats.GameStatsVersion.Old2) { CyberCafe = Convert.ToBoolean((int)reader.ReadChar()); } if (_blobVersion > LegacyGameStats.GameStatsVersion.Old5) { Deaths = reader.ReadInt32(); } }
public void ParseFromBuffer(BinaryReader reader, LegacyGameStats.GameStatsVersion blobVersion) { _blobVersion = blobVersion; SecondsToCompleteGame = reader.ReadInt32(); Summary.ParseFromBuffer(reader, _blobVersion); // Read the number of map sections var sections = reader.ReadInt32(); if (sections > 1024 || sections < 0) { throw new InvalidOperationException("Invalid number of sections."); } // Read every map section for (var i = 0; i < sections; i++) { var mapName = reader.ReadNullTerminatedString(); var record = FindOrAddRecordForMap(mapName); record.ParseFromBuffer(reader, blobVersion); } // Read Stats Version 2 if (_blobVersion >= LegacyGameStats.GameStatsVersion.Old2) { Hl2ChapterUnlocked = reader.ReadChar(); Steam = Convert.ToBoolean((int)reader.ReadChar()); } // Read Stats Version 3 if (_blobVersion >= LegacyGameStats.GameStatsVersion.Old3) { CyberCafe = Convert.ToBoolean((int)reader.ReadChar()); DxLevel = reader.ReadInt16(); } }