protected function onReplayFileDecrypted(ReplayInterface $replay, $fileType, $fileId, $binary)
    {
        if (ReplayDownloader::FILETYPE_KEYFRAME == $fileType) {
            echo PHP_EOL; // formatting, don't care

            // Work with hex, easier
            $hex = strtoupper(bin2hex($binary));
            // Search for "Turret_T1" or "Turret_T2" strings
            if (!preg_match_all('/5475727265745F54[31|32]/', $hex, $matches, PREG_OFFSET_CAPTURE)) {
                echo 'The keyframe #' . $fileId . ' has no turret' . PHP_EOL;
            }

            $turrets = [];
            foreach ($matches[0] as $turretId => $match) {
                $turretHex = substr($hex, $match[1]);

                // Byte after first 0x00 are meaningless
                $pos = strpos($turretHex, '00');
                if (1 === $pos % 2) {
                    ++$pos;
                }

                // Convert hex to readable string
                $turretName = hex2bin(substr($turretHex, 0, $pos));
                if (!is_string($turretName)) {
                    echo 'The parsing turret method seems to be outdated, please report an issue' . PHP_EOL;
                }

                // Wrong ?
                if (false === strpos($turretName, 'Turret_T')) {
                    continue;
                }

                $team = 'blue';
                if (false !== strpos($turretName, 'T2')) {
                    $team = 'purple';
                }

                $turrets[$team][] = $turretName;
            }

            // Count the destroyed turrets
            echo ' - Minute ' . ($fileId - 1) . ' :' . PHP_EOL;
            foreach ($turrets as $teamName => $turretNames) {
                echo '   > The ' . $teamName . ' team has destroyed ';

                $opponent = 'blue';
                if ('blue' == $teamName) {
                    $opponent = 'purple';
                }

                // There are 11 turrets by team
                echo (11 - count($turrets[$opponent])) . ' turret(s)' . PHP_EOL;
            }

            echo "\t\t\t\t"; // formatting, don't care
        }
    }
protected function onReplayFileDecrypted(ReplayInterface $replay, $fileType, $fileId, $binary)
    {
        if (ReplayDownloader::FILETYPE_KEYFRAME == $fileType) {
            echo PHP_EOL; // formatting, don't care

            // Work with hex, easier
            $hex = strtoupper(bin2hex($binary));
            // Search for "Turret_T1" or "Turret_T2" strings
            if (!preg_match_all('/5475727265745F54[31|32]/', $hex, $matches, PREG_OFFSET_CAPTURE)) {
                echo 'The keyframe #' . $fileId . ' has no turret' . PHP_EOL;
            }

            $turrets = [];
            foreach ($matches[0] as $turretId => $match) {
                $turretHex = substr($hex, $match[1]);

                // Byte after first 0x00 are meaningless
                $pos = strpos($turretHex, '00');
                if (1 === $pos % 2) {
                    ++$pos;
                }

                // Convert hex to readable string
                $turretName = hex2bin(substr($turretHex, 0, $pos));
                if (!is_string($turretName)) {
                    echo 'The parsing turret method seems to be outdated, please report an issue' . PHP_EOL;
                }

                // Wrong ?
                if (false === strpos($turretName, 'Turret_T')) {
                    continue;
                }

                $team = 'blue';
                if (false !== strpos($turretName, 'T2')) {
                    $team = 'purple';
                }

                $turrets[$team][] = $turretName;
            }

            // Count the destroyed turrets
            echo ' - Minute ' . ($fileId - 1) . ' :' . PHP_EOL;
            foreach ($turrets as $teamName => $turretNames) {
                echo '   > The ' . $teamName . ' team has destroyed ';

                $opponent = 'blue';
                if ('blue' == $teamName) {
                    $opponent = 'purple';
                }

                // There are 11 turrets by team
                echo (11 - count($turrets[$opponent])) . ' turret(s)' . PHP_EOL;
            }

            echo "\t\t\t\t"; // formatting, don't care
        }
    }
protected function onReplayFileDecrypted ( ReplayInterface $ replay , $ fileType , $ fileId , $ binary ) { if ( ReplayDownloader :: FILETYPE_KEYFRAME == $ fileType ) { echo PHP_EOL ; // formatting, don't care // Work with hex, easier $ hex = strtoupper ( bin2hex ( $ binary ) ) ; // Search for "Turret_T1" or "Turret_T2" strings if ( ! preg_match_all ( '/5475727265745F54[31|32]/' , $ hex , $ matches , PREG_OFFSET_CAPTURE ) ) { echo 'The keyframe #' . $ fileId . ' has no turret' . PHP_EOL ; } $ turrets = [ ] ; foreach ( $ matches [ 0 ] as $ turretId => $ match ) { $ turretHex = substr ( $ hex , $ match [ 1 ] ) ; // Byte after first 0x00 are meaningless $ pos = strpos ( $ turretHex , '00' ) ; if ( 1 === $ pos % 2 ) { ++ $ pos ; } // Convert hex to readable string $ turretName = hex2bin ( substr ( $ turretHex , 0 , $ pos ) ) ; if ( ! is_string ( $ turretName ) ) { echo 'The parsing turret method seems to be outdated, please report an issue' . PHP_EOL ; } // Wrong ? if ( false === strpos ( $ turretName , 'Turret_T' ) ) { continue ; } $ team = 'blue' ; if ( false !== strpos ( $ turretName , 'T2' ) ) { $ team = 'purple' ; } $ turrets [ $ team ] [ ] = $ turretName ; } // Count the destroyed turrets echo ' - Minute ' . ( $ fileId - 1 ) . ' :' . PHP_EOL ; foreach ( $ turrets as $ teamName => $ turretNames ) { echo '   > The ' . $ teamName . ' team has destroyed ' ; $ opponent = 'blue' ; if ( 'blue' == $ teamName ) { $ opponent = 'purple' ; } // There are 11 turrets by team echo ( 11 - count ( $ turrets [ $ opponent ] ) ) . ' turret(s)' . PHP_EOL ; } echo "\t\t\t\t" ; // formatting, don't care } }
This method counts how many turrets were destroyed by a team

@param ReplayInterface $replay
@param string          $fileType
@param int             $fileId
@param string          $binary

@return bool
This method counts how many turrets were destroyed by a team