예제 #1
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);
        }
예제 #2
0
파일: s2decode.cs 프로젝트: Mnuzz/dsmm_web
        public dsreplay DecodePython(Object stateInfo, int ID)
        {
            Interlocked.Increment(ref THREADS);
            //Console.WriteLine("Threads running: " + THREADS);
            dsreplay replay = null;
            string   rep    = (string)stateInfo;
            string   id     = Path.GetFileNameWithoutExtension(rep);

            Program.Log("Working on rep ..");
            Program.Log("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
            {
                Program.Log("No MPQArchive for " + id);
                FailCleanup(rep);
                return(null);
            }
            dynamic header = null;

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

            if (header != null)
            {
                Program.Log("Loading s2protocol header finished");
                var     baseBuild = header["m_version"]["m_baseBuild"];
                dynamic protocol  = null;
                try
                {
                    protocol = versions.build(baseBuild);
                }
                catch
                {
                    Program.Log("No protocol found for " + id);
                    FailCleanup(rep);
                    return(null);
                }
                Program.Log("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
                {
                    Program.Log("No Init version for " + id);
                    FailCleanup(rep);
                    return(null);
                }
                Program.Log("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
                {
                    Program.Log("No Version for " + id);
                    FailCleanup(rep);
                    return(null);
                }
                Program.Log("Loading s2protocol details finished");

                //s2replay replay = s2parse.GetDetails(rep, details_dec);
                replay = DSparseNG.GetDetails(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);
                    Program.Log("Loading trackerevents success");
                }
                catch
                {
                    Program.Log("No tracker version for " + id);
                    FailCleanup(rep);
                    return(null);
                }
                Program.Log("Loading s2protocol trackerevents finished");

                replay = DSparseNG.GetTrackerevents(rep, trackerevents_dec, replay);
                //s2parse.GetTrackerevents(rep, protocol.decode_replay_tracker_events(trackerevents_enc));
                Interlocked.Increment(ref REPID);
                //replay.ID = REPID;
                replay.ID = ID;
                replay.Init();
                //if (!replaysng.ContainsKey(repid)) replaysng.TryAdd(repid, replay);
                //Save(Program.myJson_file, replay);
                SaveDS(Program.myJson_file, replay);
            }

            Interlocked.Increment(ref TOTAL_DONE);
            double wr = 0;

            if (TOTAL > 0)
            {
                wr = TOTAL_DONE * 100 / TOTAL;
            }
            wr = Math.Round(wr, 2);

            if (TOTAL_DONE >= TOTAL)
            {
                DateTime end      = DateTime.UtcNow;
                TimeSpan timeDiff = end - START;
                Console.WriteLine(timeDiff.TotalSeconds);
                END = end;
                if (REDO.Count > 0)
                {
                    Console.WriteLine("REDO: " + REDO.Count);
                    //RedoScan();
                }
                else
                {
                    //Stop_decode();
                }
            }

            Interlocked.Decrement(ref THREADS);
            return(replay);
        }