From 591cab6b104e680b0708b54dc7ca337802746d43 Mon Sep 17 00:00:00 2001 From: Kevin Oliva Date: Tue, 16 Jun 2020 21:04:11 -0500 Subject: [PATCH 1/2] Battelobby will now parse AI games --- Heroes.ReplayParser/DataParser.cs | 2 +- .../MPQFiles/ReplayInitData.cs | 47 ++++++------------- .../MPQFiles/ReplayServerBattlelobby.cs | 26 +++++----- 3 files changed, 26 insertions(+), 49 deletions(-) diff --git a/Heroes.ReplayParser/DataParser.cs b/Heroes.ReplayParser/DataParser.cs index e0d5689..cf6af40 100644 --- a/Heroes.ReplayParser/DataParser.cs +++ b/Heroes.ReplayParser/DataParser.cs @@ -166,7 +166,7 @@ private static void ParseReplayArchive(Replay replay, MpqArchive archive, ParseO player.Talents = talentGameEventsDictionary[player]; } // Replay Server Battlelobby - if (!parseOptions.IgnoreErrors && archive.Any(i => i.Filename == ReplayServerBattlelobby.FileName)) + if (archive.Any(i => i.Filename == ReplayServerBattlelobby.FileName)) { if (parseOptions.ShouldParseDetailedBattleLobby) ReplayServerBattlelobby.Parse(replay, GetMpqFile(archive, ReplayServerBattlelobby.FileName)); diff --git a/Heroes.ReplayParser/MPQFiles/ReplayInitData.cs b/Heroes.ReplayParser/MPQFiles/ReplayInitData.cs index d66bac9..2a87355 100644 --- a/Heroes.ReplayParser/MPQFiles/ReplayInitData.cs +++ b/Heroes.ReplayParser/MPQFiles/ReplayInitData.cs @@ -91,40 +91,21 @@ public static void Parse(Replay replay, byte[] buffer) // m_ammId if (replay.ReplayBuild >= 43905 && reader.ReadBoolean()) - switch (reader.ReadInt32()) + { + replay.GameMode = (reader.ReadInt32()) switch { - case 50021: // Versus AI (Cooperative) - case 50041: // Practice - break; - - case 50001: - replay.GameMode = GameMode.QuickMatch; - break; - - case 50031: - replay.GameMode = GameMode.Brawl; - break; - - case 50051: - replay.GameMode = GameMode.UnrankedDraft; - break; - - case 50061: - replay.GameMode = GameMode.HeroLeague; - break; - - case 50071: - replay.GameMode = GameMode.TeamLeague; - break; - - case 50091: - replay.GameMode = GameMode.StormLeague; - break; - - default: - replay.GameMode = GameMode.Unknown; - break; - } + 50001 => GameMode.QuickMatch, + 50021 => GameMode.Cooperative, + 50031 => GameMode.Brawl, + 50041 => GameMode.Practice, + 50051 => GameMode.UnrankedDraft, + 50061 => GameMode.HeroLeague, + 50071 => GameMode.TeamLeague, + 50091 => GameMode.StormLeague, + + _ => GameMode.Unknown, + }; + } reader.Read(3); // Game Speed diff --git a/Heroes.ReplayParser/MPQFiles/ReplayServerBattlelobby.cs b/Heroes.ReplayParser/MPQFiles/ReplayServerBattlelobby.cs index b36c07f..adddc31 100644 --- a/Heroes.ReplayParser/MPQFiles/ReplayServerBattlelobby.cs +++ b/Heroes.ReplayParser/MPQFiles/ReplayServerBattlelobby.cs @@ -181,7 +181,8 @@ private static void DetailedParse(BitReader bitReader, Replay replay, uint s2maC bitReader.ReadBytes(25); bitReader.Read(24); - // bitReader.ReadBytes(8); ai games have 8 more bytes somewhere around here + if (replay.GameMode == GameMode.Cooperative) + bitReader.ReadBytes(8); // ai games have 8 more bytes somewhere around here bitReader.Read(7); @@ -190,24 +191,19 @@ private static void DetailedParse(BitReader bitReader, Replay replay, uint s2maC // repeat of the collection section above if (replay.ReplayBuild >= 51609 || replay.ReplayBuild == 47903 || replay.ReplayBuild == 47479) { - uint size = bitReader.Read(12); - - int bytesSize = (int)(size / 8); - int bitsSize = (int)(size % 8); - - bitReader.ReadBytes(bytesSize); - bitReader.Read(bitsSize); - - bitReader.ReadBoolean(); + bitReader.ReadBitArray(bitReader.Read(12)); } - else + else if (replay.ReplayBuild > 47219) { - bitReader.Read(1); - uint size = bitReader.Read(15); - // each byte has a max value of 0x7F (127) - bitReader.ReadBytes((int)size * 2); + bitReader.ReadBytes((int)bitReader.Read(15) * 2); } + else + { + bitReader.ReadBitArray(bitReader.Read(9)); + } + + bitReader.ReadBoolean(); } bitReader.ReadBoolean(); // m_hasSilencePenalty From 447e1f580909dd0db1d4d4ef493cd84b8e81bc08 Mon Sep 17 00:00:00 2001 From: Kevin Oliva Date: Wed, 17 Jun 2020 12:29:09 -0500 Subject: [PATCH 2/2] Switched back to the switch statement --- .../MPQFiles/ReplayInitData.cs | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/Heroes.ReplayParser/MPQFiles/ReplayInitData.cs b/Heroes.ReplayParser/MPQFiles/ReplayInitData.cs index 2a87355..205fea2 100644 --- a/Heroes.ReplayParser/MPQFiles/ReplayInitData.cs +++ b/Heroes.ReplayParser/MPQFiles/ReplayInitData.cs @@ -91,21 +91,44 @@ public static void Parse(Replay replay, byte[] buffer) // m_ammId if (replay.ReplayBuild >= 43905 && reader.ReadBoolean()) - { - replay.GameMode = (reader.ReadInt32()) switch + switch (reader.ReadInt32()) { - 50001 => GameMode.QuickMatch, - 50021 => GameMode.Cooperative, - 50031 => GameMode.Brawl, - 50041 => GameMode.Practice, - 50051 => GameMode.UnrankedDraft, - 50061 => GameMode.HeroLeague, - 50071 => GameMode.TeamLeague, - 50091 => GameMode.StormLeague, - - _ => GameMode.Unknown, - }; - } + case 50001: + replay.GameMode = GameMode.QuickMatch; + break; + + case 50021: + replay.GameMode = GameMode.Cooperative; + break; + + case 50031: + replay.GameMode = GameMode.Brawl; + break; + + case 50041: + replay.GameMode = GameMode.TryMe; + break; + + case 50051: + replay.GameMode = GameMode.UnrankedDraft; + break; + + case 50061: + replay.GameMode = GameMode.HeroLeague; + break; + + case 50071: + replay.GameMode = GameMode.TeamLeague; + break; + + case 50091: + replay.GameMode = GameMode.StormLeague; + break; + + default: + replay.GameMode = GameMode.Unknown; + break; + } reader.Read(3); // Game Speed