Exemplo n.º 1
0
        /// <summary>
        /// Given non-null ReplayFile object with valid Location, Name, and Type -
        /// Returns ReplayFile object with filled out Data.
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public async Task <ReplayFile> ReadFile(ReplayFile file)
        {
            if (file == null || String.IsNullOrEmpty(file.Location) || String.IsNullOrEmpty(file.Name))
            {
                throw new ArgumentNullException($"{exceptionOriginName} - File reference is null");
            }

            if (!File.Exists(file.Location))
            {
                throw new FileNotFoundException($"{exceptionOriginName} - File path not found, does the file exist?");
            }

            switch (file.Type)
            {
            case REPLAYTYPES.ROFL:
                file.Data = await ReadROFL(file.Location);

                break;

            case REPLAYTYPES.LRF:
                file.Data = await ReadLRF(file.Location);

                break;

            case REPLAYTYPES.LPR:
                file.Data = await ReadLPR(file.Location);

                break;
            }

            // Make some educated guesses
            GameDetailsInferrer detailsInferrer = new GameDetailsInferrer();

            file.Data.InferredData = new InferredData()
            {
                MapID = detailsInferrer.InferMap(file.Data.MatchMetadata)
            };

            return(file);
        }
Exemplo n.º 2
0
        public async Task <ReplayFile> ReadFile(string filePath)
        {
            // Make sure file exists
            if (String.IsNullOrEmpty(filePath))
            {
                _log.Error("File reference is null");
                throw new ArgumentNullException($"File reference is null");
            }

            if (!File.Exists(filePath))
            {
                _log.Error("File path not found, does the file exist?");
                throw new FileNotFoundException($"File path not found, does the file exist?");
            }

            // Reads the first 4 bytes and tries to find out the replay type
            ReplayType type = await ParserHelpers.GetReplayTypeAsync(filePath);

            // Match parsers to file types
            ReplayFile result;

            switch (type)
            {
            case ReplayType.ROFL:       // Official Replays
                result = await ReadROFL(filePath);

                break;

            //case ReplayType.LRF:    // LOLReplay
            //    file.Type = ReplayType.LRF;
            //    file.Data = await ReadLRF(file.Location);
            //    break;
            //case ReplayType.LPR:    // BaronReplays
            //    file.Type = ReplayType.LPR;
            //    file.Data = null;
            //    break;
            default:
                _log.Error($"File {filePath} is not an accepted format: rofl");
                return(null);
            }

            // Make some educated guesses
            GameDetailsInferrer detailsInferrer = new GameDetailsInferrer();

            result.Players = result.BluePlayers.Union(result.RedPlayers).ToArray();

            try
            {
                result.MapId = detailsInferrer.InferMap(result.Players);
            }
            catch (ArgumentNullException ex)
            {
                _log.Warning("Could not infer map type\n" + ex.ToString());
                result.MapId = MapCode.Unknown;
            }

            result.MapName          = detailsInferrer.GetMapName(result.MapId);
            result.IsBlueVictorious = detailsInferrer.InferBlueVictory(result.BluePlayers, result.RedPlayers);

            foreach (var player in result.Players)
            {
                player.Id = $"{result.MatchId}_{player.PlayerID}";
            }

            // Set the alternate name to the default
            result.AlternativeName = result.Name;

            return(result);
        }
Exemplo n.º 3
0
        private Map InferMap(MatchMetadata metadata)
        {
            GameDetailsInferrer detailsInferrer = new GameDetailsInferrer();

            return detailsInferrer.InferMap(metadata)
        }