From 2621ef91285b6534ed18d48f525011901c8f3f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kooi?= Date: Thu, 8 Dec 2016 21:29:07 +0100 Subject: [PATCH] Fix reading pre-game lobby chat in HD Edition. Fixes #29 --- src/Analyzers/HeaderAnalyzer.php | 4 ++++ test/HeaderAnalyzerTest.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Analyzers/HeaderAnalyzer.php b/src/Analyzers/HeaderAnalyzer.php index a08939f..3821e92 100644 --- a/src/Analyzers/HeaderAnalyzer.php +++ b/src/Analyzers/HeaderAnalyzer.php @@ -112,6 +112,10 @@ protected function run() $this->position += 1; } + if ($version->isHDEdition) { + $this->position += 4; + } + $pregameChat = []; if ($version->isMgx) { $pregameChat = $this->readChat($playersByIndex); diff --git a/test/HeaderAnalyzerTest.php b/test/HeaderAnalyzerTest.php index 3b271dc..4b20be2 100644 --- a/test/HeaderAnalyzerTest.php +++ b/test/HeaderAnalyzerTest.php @@ -103,6 +103,16 @@ public function testAoe2RecordVictorySettings() $this->assertAttributeEquals(9000, 'timeLimit', $analysis->victory); } + /** + * @dataProvider chatCountsProvider + */ + public function testChat($file, $expectedCount) + { + $rec = $this->load($file); + $analysis = $rec->runAnalyzer(new HeaderAnalyzer); + $this->assertCount($expectedCount, $analysis->pregameChat); + } + public function playersProvider() { return [ @@ -160,4 +170,12 @@ public function playersProvider() ], 2], ]; } + + public function chatCountsProvider() + { + return [ + ['recs/versions/HD Tourney r1 robo_boro vs Dutch Class g1.aoe2record', 13], + ['recs/versions/HD_test.mgx', 50], + ]; + } }