Exemplo n.º 1
0
 /// <summary>
 ///     The main constructor with a string param for openwith file thingy
 /// </summary>
 /// <param name="file"></param>
 public Main(string file)
 {
     InitializeComponent();
     SettingsManager(false);
     richTextBox1.Font = MainFont;
     AllowDrop         = true;
     netdecodeToolStripMenuItem.Enabled         = false;
     heatmapGeneratorToolStripMenuItem1.Enabled = false;
     statisticsToolStripMenuItem.Enabled        = false;
     HotkeyTimer.Start();
     if (File.Exists(LogPath))
     {
         File.Delete(LogPath);
     }
     Log("Application loaded!");
     CurrentFile = file;
     if ((File.Exists(CurrentFile) && Path.GetExtension(CurrentFile) == ".dem"))
     {
         richTextBox1.Text = @"Analyzing file...";
         UpdateForm();
         CurrentDemoFile = CrossDemoParser.Parse(CurrentFile);
         PrintDemoDetails(CurrentDemoFile);
         Log(Path.GetFileName(CurrentFile + " opened"));
     }
     else
     {
         SourceToolsToolStripMenuItem.Enabled     = false;
         goldSourceToolsToolStripMenuItem.Enabled = false;
         richTextBox1.Text = @"^ Use File->Open to open a correct .dem file or drop the file here!";
         UpdateForm();
     }
 }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e) //SELECT
        {
            richTextBox1.Text = "";
            var a = new OpenFileDialog
            {
                Multiselect = false,
                Filter      = @"Demo files .dem | *.dem"
            };

            if (a.ShowDialog() == DialogResult.OK)
            {
                if (CrossDemoParser.CheckDemoType(a.FileName) != Parseresult.GoldSource)
                {
                    richTextBox1.Text = (@"Only goldsource, understund?!");
                    return;
                }
                label1.Text = Path.GetFileName(a.FileName);
                DemoFile    = a.FileName;
                richTextBox1.AppendText("Selected: " + a.FileName);
            }
            else
            {
                richTextBox1.AppendText("Failed to select file. Please reselect!");
            }
        }
Exemplo n.º 3
0
 /// <summary>
 ///     Font setting
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void fontToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     try
     {
         using (var fd = new FontDialog())
         {
             if (fd.ShowDialog() == DialogResult.OK)
             {
                 richTextBox1.Font = fd.Font;
                 var parser = new FileIniDataParser();
                 var cvt    = new FontConverter();
                 var iniD   = parser.ReadFile(SettingsPath);
                 iniD["SETTINGS"]["main_font"] = cvt.ConvertToString(fd.Font);
                 parser.WriteFile(SettingsPath, iniD);
             }
         }
         if (CurrentFile == null || (!File.Exists(CurrentFile) || Path.GetExtension(CurrentFile) != ".dem"))
         {
             return;
         }
         richTextBox1.Text = @"Analyzing file...";
         CurrentDemoFile   = CrossDemoParser.Parse(CurrentFile);
         PrintDemoDetails(CurrentDemoFile);
         Log(Path.GetFileName(CurrentFile + " rescanned for font change."));
         Log("Font changed");
     }
     catch (Exception ex)
     {
         Log(ex.Message);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Rescan the demo file.
 /// </summary>
 public void RescanFile()
 {
     if (CurrentFile != null && (File.Exists(CurrentFile) && Path.GetExtension(CurrentFile) == ".dem"))
     {
         richTextBox1.Text = @"Analyzing file...";
         UpdateForm();
         CurrentDemoFile = CrossDemoParser.Parse(CurrentFile);
     }
     PrintDemoDetails(CurrentDemoFile);
     Log(Path.GetFileName(CurrentFile) + " rescanned.");
 }
Exemplo n.º 5
0
        /// <summary>
        ///     Normal constructor
        /// </summary>
        public Main()
        {
            InitializeComponent();
            SettingsManager(false);
            richTextBox1.Font = MainFont;
            AllowDrop         = true;
            netdecodeToolStripMenuItem.Enabled         = false;
            heatmapGeneratorToolStripMenuItem1.Enabled = false;
            statisticsToolStripMenuItem.Enabled        = false;
            HotkeyTimer.Start();
            if (File.Exists(LogPath))
            {
                File.Delete(LogPath);
            }

            #region OpenedWithFile check

            var dropFile = (Environment.GetCommandLineArgs().Any(x => Path.GetExtension(x) == ".dem"))
                ? Environment.GetCommandLineArgs().First(x => Path.GetExtension(x) == ".dem")
                : null;
            if (dropFile == null)
            {
                richTextBox1.Text = @"^ Use demo_file->Open to open a correct .dem file or drop the file here!";
                UpdateForm();
            }
            else
            {
                if ((File.Exists(dropFile) && Path.GetExtension(dropFile) == ".dem"))
                {
                    CurrentFile       = dropFile;
                    richTextBox1.Text = @"Analyzing file...";
                    UpdateForm();
                    CurrentDemoFile = CrossDemoParser.Parse(CurrentFile);
                    PrintDemoDetails(CurrentDemoFile);
                    Log(Path.GetFileName(CurrentFile + " opened"));
                }
                else
                {
                    SourceToolsToolStripMenuItem.Enabled     = false;
                    goldSourceToolsToolStripMenuItem.Enabled = false;
                    richTextBox1.Text = @"^ Use demo_file->Open to open a correct .dem file or drop the file here!";
                    UpdateForm();
                }
            }

            #endregion

            Log("Application loaded!");
        }
Exemplo n.º 6
0
 private static void MonitorDemo(BackgroundWorker worker, string demo)
 {
     Thread.Sleep(DirectoryScannerRefreshRate);
     while (!worker.CancellationPending)
     {
         try
         {
             var demoParseResult = CrossDemoParser.Parse(demo);
             worker.ReportProgress(0, demoParseResult);
             return;
         }
         catch
         {
             //demo still being written to
         }
         Thread.Sleep(DirectoryScannerRefreshRate);
     }
 }
Exemplo n.º 7
0
        private void hotkeytimer_Tick(object sender, EventArgs e)
        {
            Currentwindow = GetActiveWindowTitle() ?? "";
            var exitstate = KeyInputApi.GetKeyState(ExitKey);
            var rstate    = KeyInputApi.GetKeyState(RescanKey);

            if ((exitstate & 0x8000) != 0)
            {
                Close();
            }
            if ((rstate & 0x8000) != 0)
            {
                if (File.Exists(FilePath) && Path.GetExtension(FilePath) == ".dem" && FilePath != null)
                {
                    var cpr = CrossDemoParser.Parse(FilePath);
                    PrintOverlayData(cpr);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///     This happens when we drop the file on the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Main_DragDrop(object sender, DragEventArgs e)
        {
            var dropfiles = (string[])e.Data.GetData(DataFormats.FileDrop);
            var dropfile  = (dropfiles.Any(x => Path.GetExtension(x) == ".dem"))
                ? dropfiles.First(x => Path.GetExtension(x) == ".dem")
                : null;

            if (dropfile != null)
            {
                CurrentFile = dropfile;
            }
            if (CurrentFile != null && (File.Exists(CurrentFile) && Path.GetExtension(CurrentFile) == ".dem"))
            {
                richTextBox1.Text = @"Analyzing file...";
                UpdateForm();
                CurrentDemoFile = CrossDemoParser.Parse(CurrentFile);
                PrintDemoDetails(CurrentDemoFile);
                Log(Path.GetFileName(CurrentFile) + " opened!");
            }
            else
            {
                richTextBox1.Text = @"Bad file!";
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///     The constructor of the overlay form
        /// </summary>
        /// <param name="file"> Path to the demo file</param>
        public OverlayForm(string file)
        {
            InitializeComponent();
            var initialStyle = GetWindowLong(Handle, -20);

            SetWindowLong(Handle, -20, initialStyle | 0x80000 | 0x20);
            SetWindowPos(Handle, HwndTopmost, 0, 0, 0, 0, TopmostFlags);
            OnResize(null);
            TopMost = true;

            #region Settings Load

            var iniD = _parser.ReadFile(Main.SettingsPath);
            TextFont = _cvt.ConvertFromString(iniD["SETTINGS"]["overlay_font"]) as Font;
            var colorstring = iniD["SETTINGS"]["overlay_color"].Split(':');
            TextColor = Color.FromArgb(
                Convert.ToInt32(colorstring[0]),
                Convert.ToInt32(colorstring[1]),
                Convert.ToInt32(colorstring[2]),
                Convert.ToInt32(colorstring[3]));
            RescanKey = Convert.ToInt32(iniD["HOTKEYS"]["overlay_rescan"], 16);
            ExitKey   = Convert.ToInt32(iniD["HOTKEYS"]["overlay_exit"], 16);
            //SOURCE OVERLAY_SOURCE

            /* object[] settings = { Sos = new OVERLAY_SOURCE(),Hos = new OVERLAY_HLSOOE(),Los = new OVERLAY_L4D2BRANCH(),Gos = new OVERLAY_GOLDSOURCE()};
             * foreach (var obj in settings)
             * {
             *  var objType = obj.GetType();
             *  var fields = objType.GetFields();
             *  foreach (var field in fields)
             *  {
             *      var piInstance = objType.GetProperty(field.Name);
             *      piInstance.SetValue(obj, Convert.ToBoolean(int.Parse(iniD[objType.Name][field.Name])));
             *  }
             *
             * }*/
            Sos.DemoProtocol  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["demo_protocol"]));
            Sos.NetProtocol   = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["net_protocol"]));
            Sos.ServerName    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["server_name"]));
            Sos.ClientName    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["client_name"]));
            Sos.MapName       = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["map_name"]));
            Sos.GameDirectory = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["game_directory"]));
            Sos.MeasuredTime  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["measured_time"]));
            Sos.MeasuredTicks = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["measured_ticks"]));
            Sos.SaveFlag      = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["save_flag"]));
            Sos.AutosaveFlag  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_SOURCE"]["autosave_flag"]));
            //HLSOOE OVERLAY_HLSOOE
            Hos.DemoProtocol  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["demo_protocol"]));
            Hos.NetProtocol   = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["net_protocol"]));
            Hos.ServerName    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["server_name"]));
            Hos.ClientName    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["client_name"]));
            Hos.MapName       = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["map_name"]));
            Hos.GameDirectory = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["game_directory"]));
            Hos.MeasuredTime  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["measured_time"]));
            Hos.MeasuredTime  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["measured_ticks"]));
            Hos.SaveFlag      = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["save_flag"]));
            Hos.AutosaveFlag  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_HLSOOE"]["autosave_flag"]));
            //L4D2 Branch OVERLAY_L4D2BRANCH
            Los.DemoProtocol  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["demo_protocol"]));
            Los.NetProtocol   = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["net_protocol"]));
            Los.ServerName    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["server_name"]));
            Los.ClientName    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["client_name"]));
            Los.MapName       = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["map_name"]));
            Los.GameDirectory = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["game_directory"]));
            Los.MeasuredTime  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["measured_time"]));
            Los.MeasuredTicks = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["measured_ticks"]));
            Los.SaveFlag      = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["save_flag"]));
            Los.AutosaveFlag  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["autosave_flag"]));
            Los.AdjustedTime  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["adjusted_time"]));
            Los.AdjustedTicks = Convert.ToBoolean(int.Parse(iniD["OVERLAY_L4D2BRANCH"]["adjusted_ticks"]));
            //GOLDSOURCE OVERLAY_GOLDSOURCE
            Gos.DemoProtocol  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["demo_protocol"]));
            Gos.NetProtocol   = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["net_protocol"]));
            Gos.ServerName    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["server_name"]));
            Gos.ClientName    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["client_name"]));
            Gos.MapName       = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["map_name"]));
            Gos.GameDirectory = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["game_directory"]));
            Gos.MeasuredTime  = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["measured_time"]));
            Gos.MeasuredTicks = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["measured_ticks"]));
            Gos.HighestFps    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["highest_fps"]));
            Gos.LowestFps     = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["lowest_fps"]));
            Gos.AverageFps    = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["average_fps"]));
            Gos.LowestFps     = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["lowest_msec"]));
            Gos.HighestMsec   = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["highest_msec"]));
            Gos.AverageMsec   = Convert.ToBoolean(int.Parse(iniD["OVERLAY_GOLDSOURCE"]["average_msec"]));

            #endregion

            _timer1.Interval = 300;
            _timer1.Enabled  = true;
            _timer1.Start();
            FilePath = file;

            if (new FileInfo(FilePath).Length > 540)
            {
                var cpr = CrossDemoParser.Parse(FilePath);
                PrintOverlayData(cpr);
            }
            else
            {
                Demodata = "";
            }

            DemoParserSlave.RunWorkerAsync(FilePath);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Rename the demo
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void renameDemoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (CurrentFile != null && File.Exists(CurrentFile) && Path.GetExtension(CurrentFile) == ".dem")
                {
                    if (CurrentDemoFile == null)
                    {
                        richTextBox1.Text = @"Analyzing file...";
                        UpdateForm();
                        CurrentDemoFile = CrossDemoParser.Parse(CurrentFile);
                    }
                    switch (CurrentDemoFile.Type)
                    {
                    case Parseresult.UnsupportedFile:
                        MessageBox.Show(@"Couldn't rename! There is no file loaded/non-supported file!");
                        Log("Tried to rename file but failed " + CurrentFile);
                        break;

                    case Parseresult.GoldSource:
                        File.Move(CurrentFile,
                                  Path.GetDirectoryName(CurrentFile) + "\\" +
                                  CurrentDemoFile.GsDemoInfo.Header.MapName + "-" +
                                  $"{CurrentDemoFile.GsDemoInfo.DirectoryEntries.Last().TrackTime.ToString("#,0.000")}" + "-" +
                                  Environment.UserName + ".dem");
                        break;

                    case Parseresult.Hlsooe:
                        File.Move(CurrentFile,
                                  Path.GetDirectoryName(CurrentFile) + "\\" +
                                  CurrentDemoFile.HlsooeDemoInfo.Header.MapName + "-" +
                                  $"{CurrentDemoFile.HlsooeDemoInfo.DirectoryEntries.Last().PlaybackTime.ToString("#,0.000")}" +
                                  "-" + Environment.UserName + ".dem");
                        break;

                    case Parseresult.Source:
                        var stime = (CurrentDemoFile.Sdi.Flags.Count(x => x.Name == "#SAVE#") == 0)
                                ? CurrentDemoFile.Sdi.Seconds.ToString("#,0.000")
                                : CurrentDemoFile.Sdi.Flags.Last(x => x.Name == "#SAVE#").Time.ToString("#,0.000");
                        File.Move(CurrentFile,
                                  Path.GetDirectoryName(CurrentFile) + "\\" +
                                  CurrentDemoFile.Sdi.MapName + "-" +
                                  $"{stime}" + "-" + CurrentDemoFile.Sdi.ClientName + ".dem");
                        break;

                    case Parseresult.Portal:
                        File.Move(CurrentFile,
                                  Path.GetDirectoryName(CurrentFile) + "\\" +
                                  CurrentDemoFile.L4D2BranchInfo.PortalDemoInfo.MapName + "-" +
                                  (CurrentDemoFile.L4D2BranchInfo.PortalDemoInfo?.AdjustedTicks * (1f / (CurrentDemoFile.L4D2BranchInfo.Header.PlaybackTicks / CurrentDemoFile.L4D2BranchInfo.Header.PlaybackTime))) + "-" + CurrentDemoFile.L4D2BranchInfo.PortalDemoInfo.PlayerName + ".dem");
                        break;

                    case Parseresult.L4D2Branch:
                        File.Move(CurrentFile,
                                  Path.GetDirectoryName(CurrentFile) + "\\" +
                                  CurrentDemoFile.L4D2BranchInfo.Header.MapName + "-" +
                                  (CurrentDemoFile.L4D2BranchInfo.Header.PlaybackTime) + "-" + CurrentDemoFile.L4D2BranchInfo.Header.ClientName + ".dem");
                        break;
                    }
                    Log("Renamed demo");
                }
                else
                {
                    richTextBox1.Text = @"Please select a file first!";
                }
            }
            catch (Exception ex)
            {
                Log(ex);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Method to parse the files and update the datagridview
        /// </summary>
        /// <param name="files"></param>
        public void UpdateDgv(string[] files)
        {
            TickSum = 0;
            TimeSum = TimeSpan.FromSeconds(0);
            listView1.Items.Clear();
            listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            var head = new ListViewItem();

            foreach (var s in files)
            {
                var r = CrossDemoParser.Parse(s);
                if (r.Type == Parseresult.Portal || r.Type == Parseresult.L4D2Branch)
                {
                    var listViewItem2 = new ListViewItem(new string[8]);
                    var dd            = new ListViewItem();
                    listViewItem2.SubItems[0].Text = Path.GetFileNameWithoutExtension(s);
                    listViewItem2.SubItems[1].Text = r.L4D2BranchInfo.Header.GameDirectory + "/" +
                                                     r.L4D2BranchInfo.PortalDemoInfo.MapName;
                    listViewItem2.SubItems[2].Text = r.L4D2BranchInfo.PortalDemoInfo.PlayerName;
                    listViewItem2.SubItems[3].Text = r.L4D2BranchInfo.PortalDemoInfo.TotalTicks.ToString();
                    listViewItem2.SubItems[4].Text = r.L4D2BranchInfo.PortalDemoInfo.StartAdjustmentTick + "(" +
                                                     r.L4D2BranchInfo.PortalDemoInfo.StartAdjustmentType + ")";
                    listViewItem2.SubItems[5].Text = r.L4D2BranchInfo.PortalDemoInfo.EndAdjustmentTick + "(" +
                                                     r.L4D2BranchInfo.PortalDemoInfo.EndAdjustmentType + ")";
                    listViewItem2.SubItems[6].Text = r.L4D2BranchInfo.PortalDemoInfo.AdjustedTicks.ToString();
                    listViewItem2.SubItems[7].Text =
                        TimeSpan.FromSeconds(r.L4D2BranchInfo.PortalDemoInfo.AdjustedTicks *
                                             (1f /
                                              (r.L4D2BranchInfo.Header.PlaybackTicks /
                                               r.L4D2BranchInfo.Header.PlaybackTime))).ToString("g");
                    TickSum += r.L4D2BranchInfo.PortalDemoInfo.AdjustedTicks;
                    TimeSum +=
                        TimeSpan.FromSeconds(r.L4D2BranchInfo.PortalDemoInfo.AdjustedTicks *
                                             (1f /
                                              (r.L4D2BranchInfo.Header.PlaybackTicks /
                                               r.L4D2BranchInfo.Header.PlaybackTime)));
                    listView1.Items.Add(listViewItem2);
                }
            }
            var k = new ListViewItem(new string[8]);

            k.SubItems[0].Text = "- TOTAL -";
            k.SubItems[6].Text = TickSum.ToString();
            k.SubItems[7].Text = TimeSum.ToString("g");
            listView1.Items.Add(k);
            listView1.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            listView1.Columns[1].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            listView1.Columns[2].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            listView1.Columns[3].AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
            listView1.Columns[4].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            listView1.Columns[5].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            listView1.Columns[6].AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
            listView1.Columns[7].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            Width = listView1.Columns[0].Width +
                    listView1.Columns[1].Width +
                    listView1.Columns[2].Width +
                    listView1.Columns[3].Width +
                    listView1.Columns[4].Width +
                    listView1.Columns[5].Width +
                    listView1.Columns[6].Width +
                    listView1.Columns[7].Width + 100;
        }
Exemplo n.º 12
0
        /// <summary>
        ///     This is the actuall verification method
        /// </summary>
        /// <param name="files">The paths of the files</param>
        public void Verify(string[] files)
        {
            this.Text = $"Verification [{CategoryCB.SelectedItem.ToString()}]";
            Df.Clear();
            mrtb.Text = $@"Please wait. Parsing demos... 0/{files.Length}";
            mrtb.Invalidate();
            mrtb.Update();
            mrtb.Refresh();
            Application.DoEvents();
            var curr = 0;

            foreach (var dt in files.Where(file => File.Exists(file) && Path.GetExtension(file) == ".dem"))
            {
                DemopathList.Add(dt);
                Df.Add(dt, CrossDemoParser.Parse(dt)); //If someone bothers me that its slow make it async.
                mrtb.Text = $@"Please wait. Parsing demos... {curr++}/{files.Length}";
                mrtb.Invalidate();
                mrtb.Update();
                mrtb.Refresh();
                Application.DoEvents();
            }
            if (Df.Any(x => x.Value.GsDemoInfo.ParsingErrors.Count > 0))
            {
                var brokendemos = Df.Where(x => x.Value.GsDemoInfo.ParsingErrors.Count > 0)
                                  .ToList()
                                  .Aggregate("", (c, n) => c += "\n" + n.Key);
                MessageBox.Show(@"Broken demos found:
" + brokendemos, @"Error!", MessageBoxButtons.OK);
                Main.Log("Broken demos when verification: " + brokendemos);
                mrtb.Text = @"Please fix the demos then reselect the files!";
                return;
            }
            if (Df.Any(x => x.Value.Type != Parseresult.GoldSource))
            {
                MessageBox.Show(@"Only goldsource supported");
            }
            else
            {
                mrtb.Text = "";
                mrtb.AppendText("" + "\n");
                mrtb.AppendText("Parsed demos. Results:" + "\n");
                mrtb.AppendText("General stats:" + "\n");
                mrtb.AppendText($@"
Highest FPS:                {(1/Df.Select(x => x.Value).ToList().Min(y => y.GsDemoInfo.AditionalStats.FrametimeMin)).ToString("N2")}
Lowest FPS:                 {(1/Df.Select(x => x.Value).ToList().Max(y => y.GsDemoInfo.AditionalStats.FrametimeMax)).ToString("N2")}
Average FPS:                {(Df.Select(z => z.Value).ToList().Average(k => k.GsDemoInfo.AditionalStats.Count/k.GsDemoInfo.AditionalStats.FrametimeSum)).ToString("N2")}
Lowest msec:                {(1000.0/Df.Select(x => x.Value).ToList().Min(y => y.GsDemoInfo.AditionalStats.MsecMin)).ToString("N2")} FPS
Highest msec:               {(1000.0/Df.Select(x => x.Value).ToList().Max(y => y.GsDemoInfo.AditionalStats.MsecMax)).ToString("N2")} FPS
Average msec:               {(Df.Select(x => x.Value).ToList().Average(y => y.GsDemoInfo.AditionalStats.MsecSum/(double) y.GsDemoInfo.AditionalStats.Count)).ToString("N2")} FPS

Total time of the demos:    {Df.Sum(x => x.Value.GsDemoInfo.DirectoryEntries.Sum(y => y.TrackTime))}s
Human readable time:        {TimeSpan.FromSeconds(Df.Sum(x => x.Value.GsDemoInfo.DirectoryEntries.Sum(y => y.TrackTime))).ToString("g")}" + "\n\n");

                mrtb.AppendText("Demo cheat check:" + "\n");
                foreach (var dem in Df)
                {
                    if (dem.Value.GsDemoInfo.Cheats.Count > 0)
                    {
                        mrtb.AppendText("Possible cheats:\n");
                        foreach (var cheat in dem.Value.GsDemoInfo.Cheats.Distinct())
                        {
                            mrtb.AppendText("\t" + cheat + "\n");
                        }
                    }
                    mrtb.AppendText(Path.GetFileName(dem.Key) + " -> " + dem.Value.GsDemoInfo.Header.MapName);
                    mrtb.AppendText("\nBXTData:");
                    var verif = bxtver.ParseBxtData(dem);
                    mrtb.AppendText("\n" + verif.Item2);
                    BXTTreeView.Nodes.Clear();
                    BXTTreeView.Nodes.Add(verif.Item1);
                }
            }
        }
Exemplo n.º 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            var of = new OpenFileDialog
            {
                Filter      = @"Demo files (.dem) | *.dem",
                Multiselect = true
            };

            if (of.ShowDialog() == DialogResult.OK)
            {
                mrtb.Text = @"Please wait. Parsing demos...";
                mrtb.Invalidate();
                mrtb.Update();
                mrtb.Refresh();
                Application.DoEvents();
                foreach (var dt in of.FileNames.Where(file => File.Exists(file) && Path.GetExtension(file) == ".dem"))
                {
                    Df.Add(dt, CrossDemoParser.Parse(dt)); //TODO: Make this async
                }
                if (Df.Any(x => x.Value.Type != Parseresult.GoldSource))
                {
                    MessageBox.Show(@"Only goldsource supported");
                }
                else
                {
                    Task.WaitAll();
                    mrtb.Text = "";
                    mrtb.AppendText("" + "\n");
                    mrtb.AppendText("Parsed demos. Results:" + "\n");
                    mrtb.AppendText("General stats:" + "\n");
                    var frametimeMax = new List <float>();
                    var frametimeMin = new List <float>();
                    var frametimeSum = new List <double>();
                    var msecMin      = new List <double>();
                    var msecMax      = new List <double>();
                    var avgmsec      = new List <double>();
                    foreach (var d in Df)
                    {
                        float ftm = 0f, ftmx = 0f;
                        var   fts = 0.0;
                        var   count = 0;
                        int   mm = 0, mmx = 0;
                        long  msecSum = 0;
                        var   first   = true;
                        foreach (var f in from entry in d.Value.GsDemoInfo.DirectoryEntries
                                 from frame in entry.Frames
                                 where (int)frame.Key.Type < 2 || (int)frame.Key.Type > 9
                                 select(Demo_stuff.GoldSource.GoldSource.NetMsgFrame) frame.Value)
                        {
                            fts     += f.RParms.Frametime;
                            msecSum += f.UCmd.Msec;
                            count++;

                            if (first)
                            {
                                first = false;
                                ftm   = f.RParms.Frametime;
                                ftmx  = f.RParms.Frametime;
                                mm    = f.UCmd.Msec;
                                mmx   = f.UCmd.Msec;
                            }
                            else
                            {
                                ftm  = Math.Min(ftm, f.RParms.Frametime);
                                ftmx = Math.Max(ftmx, f.RParms.Frametime);
                                mm   = Math.Min(mm, f.UCmd.Msec);
                                mmx  = Math.Max(mmx, f.UCmd.Msec);
                            }
                        }
                        frametimeMax.Add(1 / ftmx);
                        frametimeMin.Add(1 / ftm);
                        frametimeSum.Add(count / fts);
                        msecMin.Add(1000.0 / mm);
                        msecMax.Add(1000.0 / mmx);
                        avgmsec.Add(1000.0 / (msecSum / (double)count));
                    }
                    mrtb.AppendText(
                        $@"
Highest FPS:                {(frametimeMin.Max()).ToString("N2")}
Lowest FPS:                 {(frametimeMin.Min()).ToString("N2")}
Average FPS:                {frametimeSum.Average().ToString("N2")}
Lowest msec:                {(msecMax.Min()).ToString("N2")} FPS
Highest msec:               {(msecMin.Max()).ToString("N2")} FPS
Average msec:               {avgmsec.Average().ToString("N2")} FPS

Total time of the demos:    {Df.Sum(x => x.Value.GsDemoInfo.DirectoryEntries.Sum(y => y.TrackTime))}s" + "\n\n");
                    mrtb.AppendText("Demo cheat check:" + "\n");
                    foreach (var dem in Df)
                    {
                        mrtb.AppendText(Path.GetFileName(dem.Key) + " -> " + dem.Value.GsDemoInfo.Header.MapName + "\n");
                        foreach (var f in dem.Value.GsDemoInfo.DirectoryEntries.SelectMany(entry =>
                                                                                           (from frame in entry.Frames.Where(
                                                                                                x => x.Key.Type == Demo_stuff.GoldSource.GoldSource.DemoFrameType.ConsoleCommand)
                                                                                            select(Demo_stuff.GoldSource.GoldSource.ConsoleCommandFrame) frame.Value into f
                                                                                            let cheats = new List <string>
                        {
                            "+lookup",
                            "+lookdown",
                            "+left",
                            "+right"
                        } where cheats.Contains(f.Command) select f)))
                        {
                            mrtb.AppendText(f.Command + "\n");
                        }
                    }
                }
            }
            else
            {
                mrtb.Text = @"No file selected/bad file!";
            }
        }
Exemplo n.º 14
0
        static void Main(string[] args)
        {
            Base[] checks =
            {
                new Base()
                {
                    Enabled = false
                },
                new BunnyHop()
                {
                    Enabled = true
                },
                new AimBot()
                {
                    Enabled = false
                },
                // new StrafeChecker()
            };

            if (!File.Exists(CurrentFile) || Path.GetExtension(CurrentFile) != ".dem")
            {
                Console.WriteLine($"Can't open {CurrentFile} / wrong format.");
                return;
            }

            CurrentDemoFile = CrossDemoParser.Parse(CurrentFile);

            /*
             * Console.WriteLine("Demo data:");
             * foreach (var data in CurrentDemoFile.DisplayData)
             * {
             *  Console.WriteLine($"\t{data}");
             *
             *
             * }
             */
            if (CurrentDemoFile.Type != Parseresult.GoldSource)
            {
                Console.WriteLine($"Not GoldSrc demo type ({CurrentDemoFile.Type}).");
                return;
            }

            #region My code
            foreach (var entry in CurrentDemoFile.GsDemoInfo.DirectoryEntries)
            {
                if (entry.Type != 1) // Only PLAYBACK state
                {
                    continue;
                }

                foreach (var frame in entry.Frames)
                {
                    //Console.WriteLine($"-> .Index:{frame.Key.Index} .FrameIndex:{frame.Key.FrameIndex} .Time:{frame.Key.Time}");

                    foreach (var check in checks)
                    {
                        if (!check.Enabled)
                        {
                            continue;
                        }

                        check.Frame(frame);
                    }

                    if (enableDataLogging)
                    {
                        continue;
                    }

                    var type = frame.Key.Type;
                    //Console.WriteLine($"Type: {type}");

                    switch (type)
                    {
                    case GoldSource.DemoFrameType.ConsoleCommand:
                    {
                        var Command = ((GoldSource.ConsoleCommandFrame)frame.Value).Command;
                        Console.WriteLine($" Command: {Command}");

                        break;
                    }

                    /*
                     * case GoldSource.DemoFrameType.ClientData:
                     * {
                     *  var CData = ((GoldSource.ClientDataFrame)frame.Value);
                     *  var CData_string = "ClientData: {\n"
                     + $"\t Origin: [ {CData.Origin.X}, {CData.Origin.Y}, {CData.Origin.Z} ] \n"
                     + $"\t Viewangles: [ {CData.Viewangles.X}, {CData.Viewangles.Y}, {CData.Viewangles.Z} ] \n"
                     + $"\t WeaponBits: {CData.WeaponBits} \n"
                     + $"\t Fov: {CData.Fov}"
                     + "\n}";
                     +
                     +  Console.WriteLine(CData_string);
                     +
                     +  break;
                     + }
                     +
                     + case GoldSource.DemoFrameType.Event:
                     + {
                     +  var EventData = ((GoldSource.EventFrame)frame.Value);
                     +  var EventData_string = "EventData: {\n"
                     + $"\t Delay: [ {EventData.Delay} ] \n"
                     + $"\t Index: {EventData.Index} \n"
                     + "\t EventArguments: { \n"
                     + $"\t\t EntityIndex: {EventData.EventArguments.EntityIndex} \n"
                     + $"\t\t Velocity:[ {EventData.EventArguments.Velocity.X}, {EventData.EventArguments.Velocity.Y}, {EventData.EventArguments.Velocity.Z}] \n"
                     + $"\t\t Angles: [ {EventData.EventArguments.Angles.X}, {EventData.EventArguments.Angles.Y}, {EventData.EventArguments.Angles.Z}] \n"
                     + $"\t\t Flags: {EventData.EventArguments.Flags} \n"
                     + $"\t\t Ducking: {EventData.EventArguments.Ducking} \n"
                     + "\t }"
                     + "\n}";
                     +
                     +  Console.WriteLine(EventData_string);
                     +
                     +  break;
                     + }
                     */
                    case GoldSource.DemoFrameType.NetMsg:
                    {
                        var NetMsgData = ((GoldSource.NetMsgFrame)frame.Value);

                        var NetMsgData_string = "NetMsgData: {\n"
                                                + $"\t RParms.Onground: {NetMsgData.RParms.Onground}\n"
                                                + $"\t RParms.ClViewangles: [{NetMsgData.RParms.ClViewangles.X},{NetMsgData.RParms.ClViewangles.Y},{NetMsgData.RParms.ClViewangles.Z}]\n"
                                                + $"\t RParms.Viewangles: [{NetMsgData.RParms.Viewangles.X},{NetMsgData.RParms.Viewangles.Y},{NetMsgData.RParms.Viewangles.Z}]\n"
                                                + $"\t UCmd.Buttons: {NetMsgData.UCmd.Buttons}\n"
                                                + $"\t UCmd.Msec: {NetMsgData.UCmd.Msec}\n"
                                                + "\n}";

                        Console.WriteLine(NetMsgData_string);
                        break;
                    }

                    case GoldSource.DemoFrameType.WeaponAnim:
                    {
                        var WeaponAnim = ((GoldSource.WeaponAnimFrame)frame.Value);

                        break;
                    }
                    }
                }
            }
            #endregion

            Console.WriteLine($"Analyze finished!");
            Console.ReadKey();
        }