Example #1
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);
        }
Example #2
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);
            }
        }
Example #3
0
        public static DSReplay DecodePython(Object stateInfo, bool toJson = true, bool GetDetails = false)
        {
            Interlocked.Increment(ref THREADS);
            DSReplay dsreplay = null;
            string   rep      = (string)stateInfo;
            //Console.WriteLine("Working on rep ..");
            string id = Path.GetFileNameWithoutExtension(rep);

            AddLog("Working on rep .. " + id);
            AddLog("Loading s2protocol ..");
            dynamic MPQArchive = SCOPE.GetVariable("MPQArchive");
            dynamic archive    = null;
            //dynamic files = null;
            dynamic contents = null;
            dynamic versions = null;

            try
            {
                archive = MPQArchive(rep);
                //files = archive.extract();
                contents = archive.header["user_data_header"]["content"];

                //versions = SCOPE.GetVariable("versions");
                versions = SCOPE.GetVariable("versions");
            }
            catch
            {
                AddLog("No MPQArchive for " + id);
                FailCleanup(rep, GetDetails);
                return(null);
            }
            dynamic header = null;

            try
            {
                lock (_locker)
                {
                    header = versions.latest().decode_replay_header(contents);
                }
            }
            catch (Exception e)
            {
                AddLog("No header for " + id + ": " + e.Message + " " + versions.latest().ToString());
                FailCleanup(rep, GetDetails);
                return(null);
            }

            if (header != null)
            {
                AddLog("Loading s2protocol header finished");
                var     baseBuild = header["m_version"]["m_baseBuild"];
                dynamic protocol  = null;
                try
                {
                    protocol = versions.build(baseBuild);
                }
                catch
                {
                    AddLog("No protocol found for " + id + " " + baseBuild.ToString());
                    FailCleanup(rep, GetDetails);
                    return(null);
                }
                AddLog("Loading s2protocol protocol finished");


                // init

                /**
                 * var init_enc = archive.read_file("replay.initData");
                 * dynamic init_dec = null;
                 * try
                 * {
                 *  init_dec = protocol.decode_replay_initdata(init_enc);
                 * }
                 * catch
                 * {
                 *  AddLog("No Init version for " + id);
                 *  FailCleanup(rep, GetDetails);
                 *  return null;
                 * }
                 * AddLog("Loading s2protocol init finished");
                 *
                 * s2parse.GetInit(rep, init_dec);
                 **/

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

                dynamic details_dec = null;
                try
                {
                    details_dec = protocol.decode_replay_details(details_enc);
                }
                catch
                {
                    AddLog("No Version for " + id);
                    FailCleanup(rep, GetDetails);
                    return(null);
                }
                AddLog("Loading s2protocol details finished");

                //replay = DSparseNG.GetDetails(rep, details_dec);
                dsreplay = Details.Get(rep, details_dec);

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

                dynamic trackerevents_dec = null;
                try
                {
                    trackerevents_dec = protocol.decode_replay_tracker_events(trackerevents_enc);
                    AddLog("Loading trackerevents success");
                }
                catch
                {
                    AddLog("No tracker version for " + id);
                    FailCleanup(rep, GetDetails);
                    return(null);
                }
                AddLog("Loading s2protocol trackerevents finished");

                try
                {
                    //replay = DSparseNG.GetTrackerevents(trackerevents_dec, replay, GetDetails);
                    dsreplay = Trackerevents.Get(trackerevents_dec, dsreplay);
                }
                catch
                {
                    AddLog("Trackerevents failed for " + id);
                    FailCleanup(rep, GetDetails);
                    return(null);
                }

                AddLog("trackerevents analyzed.");

                Initialize.Replay(dsreplay, GetDetails);

                if (toJson == true)
                {
                    DSReplays.Add(dsreplay);
                }
            }
            Interlocked.Increment(ref DONE);
            Interlocked.Decrement(ref THREADS);

            return(null);
        }