예제 #1
0
 private void DisposeDemoParser()
 {
     if (demoParser != null)
     {
         RemoveListeners(demoParser);
         demoParser.Dispose();
         demoParser = null;
     }
 }
예제 #2
0
 public void Dispose()
 {
     Parser.Dispose();
     Demo                   = null;
     CurrentTick            = null;
     MostRecentPlayerStates = null;
     MostRecentEntityStates = null;
     ProgressCallback       = null;
 }
예제 #3
0
    public void SelfDestruct()
    {
        demoParser.Dispose();

        if (port < 0)
        {
            loadedDemos.Remove(locationToParse);
        }
        demoMap.SetVisibility(false);
        Stop();
    }
예제 #4
0
        public void Dispose()
        {
            myDemoParser.MatchStarted       -= HandleMatchStarted;
            myDemoParser.RoundStart         -= HandleRoundStarted;
            myDemoParser.PlayerKilled       -= HandlePlayerKilled;
            myDemoParser.RoundOfficiallyEnd -= HandleRoundOfficiallyEnd;
            myDemoParser.Dispose();

            myDemoFileStream.Dispose();

            myDemoParser = null;
        }
예제 #5
0
 private static void WebClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
 {
     progressBar.Dispose();
     Console.WriteLine("finished.");
     Console.Write("Uncompressing... ");
     using (var fStream = File.Create(_FileName))
     {
         BZip2.Decompress(File.OpenRead(_ArchiveFileName), fStream, true);
     }
     Console.WriteLine("finished.");
     Console.Write("Parsing demo... ");
     using (var demoStream = File.OpenRead(_FileName))
     {
         _dp             = new DemoParser(demoStream);
         _dp.RoundStart += _dp_RoundStart;
         _dp.ParseHeader();
         _dp.ParseToEnd();
         _dp.Dispose();
     }
     Console.WriteLine("finished.");
     Finished = true;
 }
        private void btnParser_Click(object sender, EventArgs e)
        {
            try
            {
                txtResult.Clear();

                folderName       = txtInputFolder.Text;
                outputFolderName = txtOutputFolder.Text;

                if (Directory.Exists(folderName) && Directory.Exists(outputFolderName))
                {
                    string[] files = Directory.GetFiles(folderName, "*.dem", SearchOption.TopDirectoryOnly);

                    string fileNameWithoutExtension = "";
                    string fileName = "";

                    foreach (string file in files)
                    {
                        fileName = Path.GetFileName(file);
                        fileNameWithoutExtension = fileName.Substring(0, fileName.Length - 4);

                        outputFolderName = txtOutputFolder.Text + fileNameWithoutExtension + "\\";

                        //If an folder with the same name as the currently processed file exists,
                        //then the current file is not processed.
                        if (Directory.Exists(outputFolderName))
                        {
                            txtResult.AppendText(fileName + " was parsered");
                            txtResult.AppendText(Environment.NewLine);
                            txtResult.AppendText(Environment.NewLine);
                        }
                        else
                        {
                            parser = new DemoParser(File.OpenRead(file));
                            RegisterEvents();
                            isMatchStarted     = true;
                            isFreezetime       = true;
                            showDetailInfo     = cbShowDetailInfo.Checked;
                            stopRoundNumber    = int.Parse(txtParserRoundNumber.Text);
                            currentRoundNumber = 1;

                            sbWeapon = new StringBuilder();
                            sbHurt   = new StringBuilder();
                            sbNade   = new StringBuilder();

                            Directory.CreateDirectory(outputFolderName);

                            txtResult.AppendText("======Strat Parser " + fileName + " at " + DateTime.Now + "======");
                            txtResult.AppendText(Environment.NewLine);

                            //As the movement data is hugh, we need to immediately write each record to the file to prevent this procedure run out the memory
                            using (swMovement = new StreamWriter(Path.Combine(outputFolderName, fileNameWithoutExtension + ".csv")))
                            {
                                parser.ParseHeader();

                                txtResult.AppendText("ClientName: " + parser.Header.ClientName + ";  Map: " + parser.Header.MapName + ";  ServerName: " + parser.Header.ServerName);
                                txtResult.AppendText(Environment.NewLine);
                                txtResult.AppendText("PlaybackTicks: " + parser.Header.PlaybackTicks + ";  PlaybackTime: " + parser.Header.PlaybackTime + ";  TickRate: " + parser.TickRate + ";  TickTime: " + parser.TickTime);
                                txtResult.AppendText(Environment.NewLine);

                                parser.ParseToEnd();
                                parser.Dispose();
                            }

                            File.WriteAllText(Path.Combine(outputFolderName, fileNameWithoutExtension + "-Weapon.csv"), sbWeapon.ToString());
                            File.WriteAllText(Path.Combine(outputFolderName, fileNameWithoutExtension + "-Hurt.csv"), sbHurt.ToString());
                            File.WriteAllText(Path.Combine(outputFolderName, fileNameWithoutExtension + "-Nade.csv"), sbNade.ToString());

                            txtResult.AppendText(Environment.NewLine);
                            txtResult.AppendText("==============Parser Completed==============");
                            txtResult.AppendText(Environment.NewLine);
                            txtResult.AppendText(Environment.NewLine);
                        }
                    }
                }
                else
                {
                    txtResult.AppendText("Folder is not exist.");
                    txtResult.AppendText(Environment.NewLine);
                }
            }
            catch (Exception ex)
            {
                txtResult.AppendText(ex.ToString());
            }
        }
예제 #7
0
파일: Collector.cs 프로젝트: JamesT-W/IDemO
        public void Process()
        {
            #region detect demos
            string[] demos;
            demos = System.IO.Directory.GetFiles(System.Environment.CurrentDirectory + "/" + TARGET_FOLDER + "/", "*.dem", System.IO.SearchOption.AllDirectories);

            Debug.Success("Found {0} demo files", demos.Count());


            for (int i = 0; i < demos.Count();)
            { //                                                                                        KB     MB
                Debug.Blue("{0} - {1}mb\t", Path.GetFileName(demos[i]), new FileInfo(demos[i]).Length / 1024 / 1024);
                i++;

                if (i % 3 == 0)
                {
                    Console.Write("\n");
                }
            }

            Console.Write("\n\n");

            Debug.Info("Press enter to start processing");

            Console.ReadLine();

            #endregion

            #region collect match structure
            //Doing the processing
            Dictionary <int, string> matches = new Dictionary <int, string>();
            int mId = 0;
            foreach (string mPath in demos)
            {
                matches.Add(mId, demos[mId]);
                mId++;
            }
            #endregion

            #region process all demos
            //Now for each demo
            foreach (int matchID in matches.Keys)
            {
                //Debug.Log("Starting processing match id {0}, demo: {1}", matchID, Path.GetFileName(demos[matchID]));
                Debug.progressBar(matchID + "/" + demos.Count() + "  |  " + Path.GetFileName(demos[matchID]), 0);

                Dictionary <int, long> playerLookups = new Dictionary <int, long>();

                //Set up recorder settings
                RecorderSettings rs = new RecorderSettings();
                rs.matchID       = matchID;
                rs.playerLookups = playerLookups;

                currentRS = rs;

                //Create the parser
                DemoParser dp = new DemoParser(File.OpenRead(matches[matchID]));

                dp.ParseHeader();

                //Trigger subscription event
                EventSubscription?.Invoke(new EventSubscriptionEventArgs(dp));


                //Hard coded necessary event handlers ---------------------------------------------------
                dp.PlayerBind += (object sender, PlayerBindEventArgs e) =>
                {
                    if (!playerLookups.ContainsKey(e.Player.EntityID))
                    {
                        if (e.Player.SteamID != 0)
                        {
                            playerLookups.Add(e.Player.EntityID, e.Player.SteamID);
                        }
                    }
                };

                int tickCounter = 0;
                dp.TickDone += (object sender, TickDoneEventArgs e) =>
                {
                    tickCounter++;

                    if (tickCounter > 1000)
                    {
                        tickCounter = 0;

                        Debug.updateProgressBar((int)(dp.ParsingProgess * 100));
                    }
                };
                // -------------------------------------------------------------------------------------



                //End of event handlers
                try
                {
                    dp.ParseToEnd();
                }
                catch
                {
                    Debug.exitProgressBar();
                    Debug.Error("Attempted to read past end of stream...");
                }

                dp.Dispose();

                Debug.exitProgressBar();
            }
            #endregion

            Debug.Success("Complete!!!");
        }
예제 #8
0
    public void ParseReplay()
    {
        if (port > -1)
        {
            if (gotvSocket == null)
            {
                gotvSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                gotvSocket.ReceiveTimeout = 500;
                gotvSocket.SendTimeout    = 500;
                gotvEndPoint = new IPEndPoint(IPAddress.Parse(locationToParse), port);
                gotvSocket.Connect(gotvEndPoint);

                byte[] clientMessage;
                byte[] gotvReply;

                short header          = -1;
                short protocolVersion = -1;
                int   challengeNum    = -1;

                try
                {
                    clientMessage = GetBytesUTF16("\xff\xff\xff\xff" + "qconnect" + "0x00000000" + "\x00");
                    //initialConnect = HexStringToByteArray("ffffffff" + StringToHexString("qconnect") + StringToHexString("0x00000000") + "00");
                    //initialConnect = System.Text.Encoding.ASCII.GetBytes("");
                    gotvSocket.Send(clientMessage);
                }
                catch (Exception e) { Debug.Log(e.Message); }

                try
                {
                    gotvReply = new byte[59];
                    gotvSocket.Receive(gotvReply);

                    header          = (short)gotvReply[4];
                    challengeNum    = BitConverter.ToInt32(gotvReply, 5);
                    protocolVersion = BitConverter.ToInt16(gotvReply, 42);
                    //Debug.Log("Connect Reply: " + GetStringUTF16(gotvReply));
                    Debug.Log("Header: " + header + " Challenge Number: " + challengeNum + " Protocol Version: " + protocolVersion);

                    //Debug.Log("Before BZip2: " + System.Text.Encoding.Default.GetString(gotvReply));
                    //System.IO.MemoryStream decompressed = new System.IO.MemoryStream();
                    //BZip2.Decompress(new NetworkStream(gotvSocket), decompressed, true);
                    //gotvReply = new byte[((int)decompressed.Length)];
                    //decompressed.Read(gotvReply, 0, gotvReply.Length);
                    //Debug.Log("After BZip2: " + System.Text.Encoding.Default.GetString(gotvReply));
                }
                catch (Exception e) { Debug.Log(e.Message); }

                if (challengeNum > -1)
                {
                    try
                    {
                        //clientMessage = HexStringToByteArray("ffffffff6bc734000003000000cdf23a000037423436324445443235454644424531414633323436343445423143463832463834433437453836414344344242323437464231353042453131363746353330000110aa010aa7010a0d120931363935353539383018010a0512013118030a0512013018040a0512013018050a0a1206546865204f7818060a0512013218070a0512013118080a061202363418090a0612022430180a0a05120130180b0a05120131180c0a05120133180d0a0612023634180e0a08120431323030180f0a091205383030303018100a0512013118110a0512013118120a091205302e30333118130a0512013018140a05120134181500000000000000000200000000e4011870361402002002280000005a027168f64ee8a51970361402002002fa95c3ac300000000200000004000000048648b30100000008b74e00040000006401000064000000080000001870361402002002b4050000048648b3d9005081010000005c7cbcac5cdbf3ac02001aa60100000000001e4fefdd838a1de4c1f4b33cf21e98fef558760080cc9db102a76836b8b68f78b469e2da01293a6091e290e3dd0f6bf4d2cc542e2fa687c1c2d5542b9d00d0d1d442501a51306945c05951152302ddd615362f66e2ebe6c68bfabdac0c32b416eb4e74df967f825c815f45ca9ef460c68545c4a81629a00a48c106b3dd89f98501");
                        clientMessage = GetBytesUTF16(GenerateChallengePacket(challengeNum, protocolVersion));
                        gotvSocket.Send(clientMessage);
                    }
                    catch (Exception e) { Debug.Log(e.Message); }
                }
            }
        }
        else if (!alreadyParsed)
        {
            System.IO.FileStream replayFile = new System.IO.FileStream(locationToParse, System.IO.FileMode.Open);
            demoParser               = new DemoInfo.DemoParser(replayFile);
            demoParser.TickDone     += demoParser_TickDone;
            demoParser.HeaderParsed += demoParser_HeaderParsed;
            demoParser.ParseHeader();
            demoParser.ParseToEnd();
            replayFile.Close();

            if (BSPMap.loadedMaps.ContainsKey(demoParser.Map))
            {
                demoMap = BSPMap.loadedMaps[demoParser.Map];
            }
            else
            {
                demoMap = new BSPMap(demoParser.Map);
                //Camera.main.GetComponent<ProgramInterface>().CoroutineRunner(demoMap.BuildMap);
                demoMap.BuildMap();
            }

            demoParser.Dispose();
        }
    }
예제 #9
0
 public void Dispose()
 {
     parser.Dispose();
     file.Dispose();
 }
예제 #10
0
 public void Dispose()
 {
     _demoParser.Dispose();
     _parserStream.Dispose();
 }