示例#1
0
 public static void Main(string[] args)
 {
     using (var input = File.OpenRead(args[0])) {
         var parser = new DemoParser(input);
                         #if DEBUG
         parser.TickDone += (sender, e) => Console.Write(".");;
                         #endif
         parser.ParseDemo(true);
     }
 }
示例#2
0
 private void MonitorDemo(BackgroundWorker worker, string demo)
 {
     Thread.Sleep(DIRECTORY_SCANNER_REFRESH_RATE);
     while (!worker.CancellationPending)
     {
         try
         {
             DemoParseResult demoParseResult = DemoParser.ParseDemo(demo);
             worker.ReportProgress(0, demoParseResult);
             return;
         }
         catch
         {
             //demo still being written to
         }
         Thread.Sleep(DIRECTORY_SCANNER_REFRESH_RATE);
     }
 }
示例#3
0
        static void Main(string[] args)
        {
            DateTime begin;
            DateTime end;

            Stream inputStream = new FileStream(args[0], FileMode.Open);

            Console.WriteLine("Parsing...");

            begin = DateTime.Now;

            DemoParser parser = new DemoParser(inputStream);

            parser.ParseDemo(true);

            end = DateTime.Now;

            Console.WriteLine(String.Format("Started: {0}", begin.ToString("HH:mm:ss.ffffff")));
            Console.WriteLine(String.Format("Finished: {0}", end.ToString("HH:mm:ss.ffffff")));
            Console.WriteLine(String.Format("\nTotal: {0}", (end - begin)));

            Console.ReadKey();
        }
示例#4
0
        private void OpenSplitsFromDemosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CheckForUnsavedChanges())
            {
                OpenFileDialog openDemosDialog = new OpenFileDialog()
                {
                    Multiselect = true,
                    Title       = "Please select all the demos of your run",
                    Filter      = "Demo files (*.dem)|*.dem"
                };

                if (openDemosDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    List <FileInfo>        demos              = openDemosDialog.FileNames.Select(f => new FileInfo(f)).ToList();
                    List <FileInfo>        orderedDemos       = demos.OrderBy(f => f.LastWriteTime).ToList();
                    List <DemoParseResult> orderedDemoResults = orderedDemos.Select(f => DemoParser.ParseDemo(f.FullName)).ToList();

                    foreach (Category category in Category.Values)
                    {
                        string[] demoMaps = orderedDemoResults.Select(r => r.MapName).ToArray();
                        if (category.Maps.All(m => demoMaps.Contains(m)))
                        {
                            Run run = new Run(category, orderedDemoResults);
                            LoadRun(run);
                            return;
                        }
                    }
                    MessageBox.Show("An error occured while trying to create splits from the selected demos. Did you forget any?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public override async Task PlaytestCommandPost(bool replyInContext, SrcdsLogService srcdsLogService,
                                                       RconService rconService)
        {
            await base.PlaytestCommandPost(replyInContext, srcdsLogService, rconService);

            if (_dataService.RSettings.ProgramSettings.Debug)
            {
                _ = _log.LogMessage("CSGO class PlaytestCommandPost", false, color: LOG_COLOR);
            }

            //Fire and forget all of this.
            _ = Task.Run(async() =>
            {
                await rconService.RconCommand(PlaytestCommandInfo.ServerAddress,
                                              $"host_workshop_map {PlaytestCommandInfo.WorkshopId}");
                await Task.Delay(15000); //Wait for map to change

                await rconService.RconCommand(PlaytestCommandInfo.ServerAddress,
                                              $"sv_cheats 1; bot_stop 1;exec {_dataService.RSettings.General.PostgameConfig};sv_voiceenable 0");

                if (!IsCasual)
                {
                    await rconService.RconCommand(ServerLocation, $"sv_password {CompPassword}");
                }

                //Display ingame notification for in game voice and make it stick for a while.
                _ = Task.Run(async() =>
                {
                    for (var i = 0; i < 4; i++)
                    {
                        _ = rconService.RconCommand(PlaytestCommandInfo.ServerAddress,
                                                    "script ScriptPrintMessageCenterAll(\"Please join the level testing voice channel for feedback!\");",
                                                    false);

                        await Task.Delay(3000);
                    }
                });

                //Enable the no damage script, cause Thomas is a real one.
                _ = Task.Run(async() =>
                {
                    //Short delay to ensure that mp_restart game already happened.
                    await Task.Delay(5000);
                    _ = rconService.RconCommand(PlaytestCommandInfo.ServerAddress, "say No damage activated!; script_execute nodamage");
                });

                var demoPath = await DownloadHandler.DownloadPlaytestDemo(PlaytestCommandInfo);

                FileInfo jasonFile = null;
                try
                {
                    jasonFile = DemoParser.ParseDemo(Path.GetDirectoryName(demoPath));
                }
                catch (Exception e)
                {
                    Console.WriteLine("JIMCODE\nJIMCODE\nJIMCODE\nJIMCODE\nJIMCODE\nJIMCODE\nJIMCODE\nJIMCODE\n" +
                                      e.Message);
                }

                _ = Task.Run(async() =>
                {
                    foreach (var creator in Creators)
                    {
                        try
                        {
                            var user = _dataService.GetSocketGuildUser(creator.Id);
                            await user.RemoveRoleAsync(_dataService.ComptesterPlaytestCreator);
                        }
                        catch
                        {
                        }
                    }
                });

                var embed = new EmbedBuilder()
                            .WithAuthor($"Download playtest demo for {CleanedTitle}", _dataService.Guild.IconUrl,
                                        demoUrl)
                            .WithThumbnailUrl(PlaytestCommandInfo.ThumbNailImage)
                            .WithColor(new Color(243, 128, 72))
                            .WithDescription(
                    $"[Download Demo Here]({demoUrl}) | [Map Images]({PlaytestCommandInfo.ImageAlbum}) | [Playtesting Information](https://www.tophattwaffle.com/playtesting/)");

                if (jasonFile != null)
                {
                    embed.AddField("Analyzed Demo",
                                   $"[View Processed Demo Here!]({demoSiteUrlBase}{jasonFile.Name.Replace(jasonFile.Extension, "")})");
                }

                await AnnouncmentChannel.SendMessageAsync(PlaytestCommandInfo.CreatorMentions, embed: embed.Build());

                PlaytestCommandRunning = false;
            });
        }
示例#6
0
        private void ParseRun(string[] demos)
        {
            DemoParseResult demoParseResult;

            this.listView.Items.Clear();
            this._demoResults.Clear();
            int          num          = 0;
            bool         gameDir      = false;
            ListViewItem listViewItem = new ListViewItem();

            System.Drawing.Font font      = new System.Drawing.Font(listViewItem.Font.FontFamily, listViewItem.Font.Size, FontStyle.Bold);
            string[]            strArrays = demos;
            for (int i = 0; i < (int)strArrays.Length; i++)
            {
                string str = strArrays[i];
                try
                {
                    demoParseResult = DemoParser.ParseDemo(str);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    MessageBox.Show(string.Concat("Couldn't parse demo: ", Path.GetFileName(str), " - ", exception.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    break;
                }
                this._demoResults.Add(demoParseResult);
                gameDir = demoParseResult.GameDir == "portal2";
                int          totalTicks = demoParseResult.TotalTicks;
                ListViewItem fileName   = new ListViewItem(new string[this.listView.Columns.Count])
                {
                    UseItemStyleForSubItems = false
                };
                fileName.SubItems[0].Text = Path.GetFileName(str);
                fileName.SubItems[1].Text = string.Concat(demoParseResult.GameDir, " / ", demoParseResult.MapName);
                fileName.SubItems[2].Text = demoParseResult.PlayerName;
                fileName.SubItems[3].Text = demoParseResult.TotalTicks.ToString();
                if (demoParseResult.StartAdjustmentTick <= -1 || demoParseResult.EndAdjustmentTick <= -1)
                {
                    if (demoParseResult.StartAdjustmentTick <= -1)
                    {
                        fileName.SubItems[4].Text = "0";
                    }
                    else
                    {
                        totalTicks = demoParseResult.TotalTicks - demoParseResult.StartAdjustmentTick;
                        fileName.SubItems[4].Text = demoParseResult.StartAdjustmentTick.ToString();
                        if (!gameDir)
                        {
                            fileName.SubItems[4].Font = font;
                        }
                    }
                    if (demoParseResult.EndAdjustmentTick <= -1)
                    {
                        fileName.SubItems[5].Text = demoParseResult.TotalTicks.ToString();
                    }
                    else
                    {
                        totalTicks = demoParseResult.EndAdjustmentTick;
                        fileName.SubItems[5].Text = demoParseResult.EndAdjustmentTick.ToString();
                        if (!gameDir)
                        {
                            fileName.SubItems[5].Font = font;
                        }
                    }
                }
                else
                {
                    totalTicks = demoParseResult.EndAdjustmentTick - demoParseResult.StartAdjustmentTick;
                    fileName.SubItems[4].Text = demoParseResult.StartAdjustmentTick.ToString();
                    fileName.SubItems[5].Text = demoParseResult.EndAdjustmentTick.ToString();
                }
                if (demoParseResult.StartAdjustmentType != null)
                {
                    ListViewItem.ListViewSubItem item = fileName.SubItems[4];
                    item.Text = string.Concat(item.Text, " (", demoParseResult.StartAdjustmentType, ")");
                }
                if (demoParseResult.EndAdjustmentType != null)
                {
                    ListViewItem.ListViewSubItem listViewSubItem = fileName.SubItems[5];
                    listViewSubItem.Text = string.Concat(listViewSubItem.Text, " (", demoParseResult.EndAdjustmentType, ")");
                }
                fileName.SubItems[6].Text = totalTicks.ToString();
                if (!gameDir && totalTicks != demoParseResult.TotalTicks)
                {
                    fileName.SubItems[6].Font = font;
                }
                num = num + totalTicks;
                string str1 = string.Format("{0:hh\\:mm\\:ss\\.fff}", TimeSpan.FromSeconds(this.TicksToSecs(totalTicks, gameDir)));
                fileName.SubItems[7].Text = str1;
                this.listView.Items.Add(fileName);
            }
            ListViewItem listViewItem1 = new ListViewItem(new string[this.listView.Columns.Count])
            {
                Font = font
            };

            listViewItem1.SubItems[0].Text = "-- TOTAL --";
            listViewItem1.SubItems[6].Text = num.ToString();
            string str2 = string.Format("{0:hh\\:mm\\:ss\\.fff}", TimeSpan.FromSeconds(this.TicksToSecs(num, gameDir)));

            listViewItem1.SubItems[7].Text = str2;
            this.listView.Items.Add(listViewItem1);
            this.listView.Sort();
            this.listView.EnsureVisible(listViewItem1.Index);
        }
        private void buttonAnalyze_Click(object sender, RoutedEventArgs e)
        {
            this.buttonLoad.IsEnabled    = false;
            this.buttonAnalyze.IsEnabled = false;
            this.buttonPause.IsEnabled   = true;
            this.t1 = Stopwatch.StartNew();
            timer.Start();

            demoParser.ParseDemo(false);

            bw = new BackgroundWorker();
            bw.WorkerReportsProgress      = true;
            bw.WorkerSupportsCancellation = true;

            // what to do in the background thread
            bw.DoWork += new DoWorkEventHandler(
                delegate(object o, DoWorkEventArgs args)
            {
                BackgroundWorker b = o as BackgroundWorker;

                while (demoParser.ParseNextTick() && !bw.CancellationPending)
                {
                    if (demoParser.Header.PlaybackTicks == 0)
                    {
                        continue;
                    }

                    // report the progress in percent
                    b.ReportProgress(Convert.ToInt32(((float)demoParser.CurrentTick / demoParser.Header.PlaybackTicks) * 100), demoParser);
                    // ability to pause/resume thread
                    locker.WaitOne(Timeout.Infinite);
                }

                if (bw.CancellationPending)
                {
                    args.Cancel = true;
                    return;
                }
            });

            // what to do when progress changed (update the progress bar for example)
            bw.ProgressChanged += new ProgressChangedEventHandler(
                delegate(object o, ProgressChangedEventArgs args)
            {
                this.progressBar.Value     = args.ProgressPercentage;
                this.labelProgress.Content = args.ProgressPercentage + "% - Tick : " + ((DemoParser)args.UserState).CurrentTick + "/" + ((DemoParser)args.UserState).Header.PlaybackTicks;
            });

            // what to do when worker completes its task (notify the user)
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
                delegate(object o, RunWorkerCompletedEventArgs args)
            {
                bw.CancelAsync();
                bw.Dispose();
                t1.Stop();
                timer.Stop();
                this.textblockContent.Text         += "Finished!" + Environment.NewLine;
                this.textblockContent.Text         += "Time: " + t1.Elapsed.ToString(@"ss\.fffffff");
                this.dataGridTeams.ItemsSource      = demoParser.Teams;
                this.dataGridPlayers.ItemsSource    = demoParser.Players;
                this.dataGridScoreboard.ItemsSource = scoreboardObserver.scoreBoard.GetLines();
                SortScoreboard();
                this.dataGridCheatAnalyze.ItemsSource = cheatObserver.results;
                this.buttonPause.IsEnabled            = false;
                this.tabItemData.IsEnabled            = true;
                this.tabItemScoreboard.IsEnabled      = true;
            });

            bw.Disposed += new EventHandler(
                delegate(object s, EventArgs ea)
            {
                this.buttonLoad.IsEnabled = true;
            });

            bw.RunWorkerAsync();
        }