Esempio n. 1
0
        private void DecodeReplay(string replayPath, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return;
            }

            Interlocked.Increment(ref activeThreads);

            string id = Path.GetFileNameWithoutExtension(replayPath);

            logger.LogDebug($"Decoding replay {id} on {activeThreads} threads.");
            try
            {
                dynamic MPQArchive = scriptScope.GetVariable("MPQArchive");

                var archive  = MPQArchive(replayPath);
                var contents = archive.header["user_data_header"]["content"];
                var versions = scriptScope.GetVariable("versions");

                dynamic header = null;
                lock (lockObject)
                {
                    header = versions.latest().decode_replay_header(contents);
                }
                var baseBuild = header["m_version"]["m_baseBuild"];
                var protocol  = versions.build(baseBuild);

                // details
                var details_enc = archive.read_file("replay.details");

                lib.Models.DSReplay replay = null;
                var details_dec            = protocol.decode_replay_details(details_enc);
                replay = DetailsService.GetDetails(details_dec);

                if (replay == null)
                {
                    throw new Exception($"Decoding details for {id} failed.");
                }
                replay.REPLAYPATH = replayPath;
                logger.LogDebug($"Got replay details with {replay.DSPlayer.Count} player.");

                // trackerevents
                var trackerevents_enc = archive.read_file("replay.tracker.events");
                var trackerevents_dec = protocol.decode_replay_tracker_events(trackerevents_enc);

                TrackerEventsService.GetTrackerEvents(replay, trackerevents_dec);

                Initialize.Replay(replay, false);

                var         json      = JsonSerializer.Serialize(replay);
                DsReplayDto newreplay = JsonSerializer.Deserialize <DsReplayDto>(json, new JsonSerializerOptions()
                {
                    PropertyNameCaseInsensitive = true
                });
                newreplay.VERSION = Version.ToString();
                Replays.Add(new Dsreplay(newreplay));
            }
            catch (Exception e)
            {
                FailedReplays.Add(replayPath);
                logger.LogError($"Failed decoding replay {id}: {e.Message}");
            }
            finally
            {
                Interlocked.Decrement(ref activeThreads);
                Interlocked.Increment(ref replaysDone);
            }
        }
Esempio n. 2
0
        public static DsReplayDto?DecodeReplay(string appPath, string replayPath, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            var scriptScope = LoadEngine(appPath);

            if (scriptScope == null)
            {
                return(null);
            }

            string id = Path.GetFileNameWithoutExtension(replayPath);

            try
            {
                dynamic MPQArchive = scriptScope.GetVariable("MPQArchive");

                var archive  = MPQArchive(replayPath);
                var contents = archive.header["user_data_header"]["content"];
                var versions = scriptScope.GetVariable("versions");

                dynamic header = null;
                lock (lockObject)
                {
                    header = versions.latest().decode_replay_header(contents);
                }
                var baseBuild = header["m_version"]["m_baseBuild"];
                var protocol  = versions.build(baseBuild);

                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                // details
                var details_enc = archive.read_file("replay.details");

                lib.Models.DSReplay?replay = null;
                var details_dec            = protocol.decode_replay_details(details_enc);
                replay = DetailsService.GetDetails(details_dec);

                if (replay == null)
                {
                    throw new Exception($"Decoding details for {id} failed.");
                }
                replay.REPLAYPATH = replayPath;

                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                // trackerevents
                var trackerevents_enc = archive.read_file("replay.tracker.events");
                var trackerevents_dec = protocol.decode_replay_tracker_events(trackerevents_enc);

                TrackerEventsService.GetTrackerEvents(replay, trackerevents_dec);

                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                Initialize.Replay(replay, false);

                var         json      = JsonSerializer.Serialize(replay);
                DsReplayDto?newreplay = JsonSerializer.Deserialize <DsReplayDto>(json, new JsonSerializerOptions()
                {
                    PropertyNameCaseInsensitive = true
                });

                if (newreplay == null)
                {
                    throw new Exception("failed deserializing DsReplayDto");
                }
                newreplay.VERSION = Version.ToString();
                return(newreplay);
            }
            catch (Exception e)
            {
                Console.WriteLine($"failed decoding replay {e.Message}");
            }
            return(null);
        }