private void OpenMenuItem_Click(object sender, RoutedEventArgs e) { Reset(); var ofd = new OpenFileDialog(); ofd.Filter = "Demo files (*.dem)|*.dem"; if (ofd.ShowDialog(this) == true) { using (var parser = new DemoParser(ofd.OpenFile())) { parser.ParseHeader(); try { _demo.Parse(parser); } catch (DemoDataException ex) { MessageBox.Show($"Failed to load demo: {ex.Message}", "Unable to load demo", MessageBoxButton.OK, MessageBoxImage.Error); } minimap.LoadMap(parser.Header.MapName); timeline.Init(_demo.Rounds, _demo.LastTick); } } }
private void ParseDemo(FileStream file) { _parser = new DemoParser(file); _parser.ParseHeader(); _parser.MatchStarted += Parser_MatchStarted; _parser.RoundStart += Parser_RoundStart; _parser.PlayerKilled += Parser_PlayerKilled; _parser.RoundEnd += Parser_RoundEnd; _parser.TickDone += Parser_TickDone; _parser.BombPlanted += Parser_BombPlanted; _parser.BombDefused += Parser_BombDefused; _parser.BombExploded += Parser_BombExploded; _parser.PlayerBind += Parser_PlayerBind; _parser.FreezetimeEnded += Parser_FreezetimeEnded; _parser.PlayerHurt += Parser_PlayerHurt; _progress.Report($"Parse file: \"{_demoFileName}\" Size: {new FileInfo(file.Name).Length.ToSize(LongExtension.SizeUnits.MB)}Mb"); var sw = new Stopwatch(); sw.Start(); _parser.ParseToEnd(); sw.Stop(); MatchFinish(); _progress.Report($"It took: {sw.Elapsed:mm':'ss':'fff}"); }
public void Start() { MatchData = new Match(); using (var compressedStream = _matchInformation != null ? Helpers.GetStreamFromUrl(_matchInformation.roundstats.map) : replayStream) using (var outputStream = new MemoryStream()) { if (replayCompressed) { BZip2.Decompress(compressedStream, outputStream, false); outputStream.Seek(0L, SeekOrigin.Begin); parser = new DemoParser(outputStream); } else { parser = new DemoParser(compressedStream); } parser.MatchStarted += MatchStarted_Event; parser.ParseHeader(); parser.ParseToEnd(); MatchEnded_Event(); } }
private void StartParseThread(string filePath) { using (var filestream = File.OpenRead(filePath)) { using (var parser = new DemoParser(filestream)) { parser.HeaderParsed += (s, e) => _parsingEventsQueue.Enqueue(new ParserEvent <object>(_eventsHandler.OnHeaderParsed, s, e, "header PArsed")); parser.RoundOfficiallyEnd += (s, e) => _parsingEventsQueue.Enqueue(new ParserEvent <object>(_eventsHandler.OnRoundEnd, s, e, "rounf official end")); parser.RoundStart += (s, e) => _parsingEventsQueue.Enqueue(new ParserEvent <object>(_eventsHandler.OnRoundStart, s, e, "round start")); parser.PlayerTeam += (s, e) => _parsingEventsQueue.Enqueue(new ParserEvent <object>(_eventsHandler.OnPlayerTeam, s, e, "Player team")); parser.SmokeNadeStarted += (s, e) => _parsingEventsQueue.Enqueue(new ParserEvent <object>(_eventsHandler.OnSmokeNadeStarted, s, e)); parser.MatchStarted += (s, e) => MatchStarted = true; parser.WeaponFired += _eventsHandler.OnWeaponFired; parser.PlayerHurt += _eventsHandler.OnPlayerHurt; parser.TickDone += _eventsHandler.OnTickDone; parser.ParseHeader(); parser.ParseToEnd(); OnParsingComplete(); Thread.CurrentThread.Abort(); } } }
public void parseToSQLite() { setSqlSubscription(); parser.ParseHeader(); parser.ParseToEnd(); }
/// <summary> /// Parses the replay till the matchHasStarted event occurs /// Initializes game-specific info /// </summary> /// <returns>true if it successully ran through</returns> public bool ParseToMatchStart() { using (var fileStream = File.OpenRead(_filePath)) { using (DemoParser parser = new DemoParser(fileStream)) { parser.ParseHeader(); Map = parser.Header.MapName; _matchTime = parser.Header.PlaybackTime; CancellationTokenSource tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; parser.MatchStarted += (sender, e) => { Counterterrorists = parser.PlayingParticipants.Where(a => a.Team == Team.CounterTerrorist).ToArray(); Terrorists = parser.PlayingParticipants.Where(a => a.Team == Team.Terrorist).ToArray(); Terrorists.CopyTo(Players, 0); Counterterrorists.CopyTo(Players, 5); tokenSource.Cancel(); }; parser.ParseToEnd(token); } return(true); } }
private void addPlayers(String fileName) { var parser = new DemoParser(File.OpenRead(fileName)); parser.ParseHeader(); int count = 0; while (count < 10) { for (int i = 0; i < 100; i++) { parser.ParseNextTick(); } count = 0; foreach (var p in parser.PlayingParticipants) { count++; } } List <long> tempList = new List <long>(); foreach (var player in parser.PlayingParticipants) { tempList.Add(player.SteamID); } playersInFile.Add(fileName, tempList); }
private static void InitDemo() { demoParser = new DemoParser(File.OpenRead("pov_qwerty.dem")); demoParser.TickDone += parser_TickDone; demoParser.ParseHeader(); demoParser.ParseToEnd(); }
public static DemoParser CsgoDemoParser(string file) { var csgodemo = new DemoParser(File.OpenRead(file)); csgodemo.ParseHeader(); csgodemo.ParseToEnd(); return(csgodemo); }
public DemoAnalysis ParseHeaderOnly() { parser.ParseHeader(); analysis.Metadata = parser.Header; SetCoordinates(analysis.Metadata.MapName); return(analysis); }
private static void DemoTest1() { parser = new DemoParser(File.OpenRead("commu.dem")); parser.TickDone += parser_TickDone; parser.ParseHeader(); parser.ParseToEnd(); }
private static void DemoTest() { parser = new DemoParser(File.OpenRead("match730_003317647861457354858_2030613425_135.dem")); parser.TickDone += parser_TickDone; parser.ParseHeader(); parser.ParseToEnd(); }
public void ReadHeader() { myDemoFileStream = File.OpenRead(myDemo.FilePath); myDemoParser = new DemoParser(myDemoFileStream); myDemoParser.ParseHeader(); Match.Map = myDemoParser.Map; Match.Id = myDemoParser.Header.MapName.Replace("/", "") + "_" + myDemoParser.Header.SignonLength + myDemoParser.Header.PlaybackTicks + myDemoParser.Header.PlaybackFrames; Match.Demo.Id = Match.Id; }
public MatchScanner(Stream inputDemoStream) { _parserStream = inputDemoStream; _demoParser = new DemoParser(_parserStream); _demoParser.ParseHeader(); secondsPerTick = 1.0 / _demoParser.TickRate; RegisterCallbacks(); }
private void ParseHeader() { Parser.ParseHeader(); Demo.ServerName = Parser.Header.ServerName; Demo.ClientName = Parser.Header.ClientName; Demo.MapName = Parser.Header.MapName; Demo.PlaybackTime = Parser.Header.PlaybackTime; Demo.PlaybackTicks = Parser.Header.PlaybackTicks; Demo.PlaybackFrames = Parser.Header.PlaybackFrames; }
public void ParseHeader(DemoParser parser) { parser.ParseHeader(); parser.MatchStarted += (sender, e) => { Team1 = parser.CTClanName; Team2 = parser.TClanName; mapName = parser.Map; }; parser.ParseToEnd(); }
static void Main(string[] args) { DemoParser dp = new DemoParser(File.OpenRead("1.dem")); int mollies = 0; dp.ParseHeader(); dp.FireNadeStarted += (sender, e) => { mollies++; }; dp.ParseToEnd(); Console.WriteLine("{0}", mollies); }
private void ParserHeader(string folderName, string fileName) { DateTime dateFile = File.GetCreationTime(folderName + fileName); txtResult.AppendText("=======Start Parser " + fileName + " at " + DateTime.Now + "============="); txtResult.AppendText(Environment.NewLine); try { parser.ParseHeader(); } catch (Exception ex) { MessageBox.Show("Exception:" + ex.ToString()); } DemoHeader header = parser.Header; FileInfo fi = new FileInfo(folderName + fileName); int seconds = (int)fi.LastWriteTime.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; txtResult.AppendText(header.MapName.Replace("/", "") + "_" + header.SignonLength + header.PlaybackTicks + header.PlaybackFrames + seconds + fi.Length); txtResult.AppendText(Environment.NewLine); txtResult.AppendText("Client name: " + header.ClientName); txtResult.AppendText(Environment.NewLine); txtResult.AppendText("Server name: " + header.ServerName); txtResult.AppendText(Environment.NewLine); if (header.PlaybackTicks != 0 && header.PlaybackTime != 0) { txtResult.AppendText(("Tick Rate: " + header.PlaybackTicks / header.PlaybackTime).ToString()); txtResult.AppendText(Environment.NewLine); } else { txtResult.AppendText("corrupted"); txtResult.AppendText(Environment.NewLine); } if (header.PlaybackFrames != 0 && header.PlaybackTime != 0) { //Tick rate txtResult.AppendText("Tick Rate: " + ((int)Math.Round((double)header.PlaybackFrames / header.PlaybackTime)).ToString()); txtResult.AppendText(Environment.NewLine); } txtResult.AppendText("Playback time: " + header.PlaybackTime.ToString()); //Duration txtResult.AppendText(Environment.NewLine); txtResult.AppendText("Map name: " + header.MapName); txtResult.AppendText(Environment.NewLine); txtResult.AppendText("Playback tick: " + header.PlaybackTicks.ToString()); txtResult.AppendText(Environment.NewLine); }
public static void Main(string[] args) { foreach (var file in Directory.GetFiles(@"D:\Users\Moritz\Desktop\playtest2", "*.dem")) { Console.WriteLine("Parsing " + file); using (var input = File.OpenRead(args[0])) { using (DemoParser p = new DemoParser(input)) { p.ParseHeader(); p.ParseToEnd(); } } } }
public static void GenerateFrags(DemoParser parser) { parser.ParseHeader(); // Make a print on round-start so you can see the actual frags per round. parser.RoundStart += (sender, e) => Console.WriteLine("New Round, Current Score: T {0} : {1} CT", parser.TScore, parser.CTScore); parser.PlayerKilled += (sender, e) => { if (e.Killer == null) { // The player has murdered himself (falling / own nade / ...) Console.WriteLine("<World><0><None>"); } else { Console.Write("<{0}><{1}><{2}>", e.Killer.Name, e.Killer.SteamID, ShortTeam(e.Killer.Team)); } if (e.Assister == null) { // nothing } else { Console.Write(" + <{0}><{1}><{2}>", e.Assister.Name, e.Assister.SteamID, ShortTeam(e.Assister.Team)); } Console.Write(" [{0}]", e.Weapon.Weapon); if (e.Headshot) { Console.Write("[HS]"); } if (e.PenetratedObjects > 0) { Console.Write("[Wall]"); } Console.Write(" "); Console.Write("<{0}><{1}><{2}>", e.DeathPerson.Name, e.DeathPerson.SteamID, ShortTeam(e.DeathPerson.Team)); Console.WriteLine(); }; parser.ParseToEnd(); }
public static Result <DemoHeader> ParseHeader(string filePath) { if (!File.Exists(filePath)) { return(Result.Fail <DemoHeader>("Demo file does not exist")); } using (var filestream = File.OpenRead(filePath)) { using (var parser = new DemoParser(filestream)) { parser.ParseHeader(); return(Result.Ok(parser.Header)); } } }
private static void PrintSteamIdList(string fileName) { using (var fileStream = File.OpenRead(fileName)) { Console.WriteLine("==== List of the steamids of the players ===="); using (var parser = new DemoParser(fileStream)) { parser.ParseHeader(); parser.ParseToEnd(); foreach (var player in parser.PlayingParticipants) { Console.WriteLine(" - {0} {1}", player.SteamID, player.Name); } } } }
public static mapstatus isDownloaded(string demoPath) { //Make our return var mapstatus stat = new mapstatus(); //Do parsing DemoParser demofile = new DemoParser(File.OpenRead(demoPath)); demofile.ParseHeader(); //TRY AND FIND INSTANCE OF MAP ON DISK Debug.Info("Scanning for map on disk"); //Do workshop check stat.isWorkshop = false; string checkPath = "maps/"; stat.localname = demofile.Map; if (demofile.Map.StartsWith("workshop")) //Detected its a workshop map { stat.isWorkshop = true; checkPath = "maps/workshop/"; //Switch to the workshopped folder Debug.Log("Map workshopped"); //Sets the local name to something that will not cause collisions string[] demoref = demofile.Map.Split('/'); stat.localname = demoref[1] + demoref[2]; } //Go through the folder to check if the instance is still there foreach (string map in Directory.GetFiles(checkPath, "*.maprad")) { if (Path.GetFileNameWithoutExtension(map) == stat.localname) { Debug.Success("Found match on disk! {0}", map); //phew, no need to flood steam servers! stat.isDownloaded = true; //Since it found a pre-downloaded instance it can just carry on with that instance + demo } } stat.filename = Path.GetFileNameWithoutExtension(demoPath); stat.activeParser = demofile; return(stat); }
public Task <string> GetOldId(Demo demo) { string id = string.Empty; try { DemoParser parser = new DemoParser(File.OpenRead(demo.Path)); parser.ParseHeader(); DateTime dateTime = File.GetCreationTime(demo.Path); int seconds = (int)dateTime.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; id = parser.Header.MapName.Replace("/", "") + "_" + seconds + parser.Header.SignonLength + parser.Header.PlaybackFrames; } catch { // Silently ignore no CSGO demos or unreadable file } return(Task.FromResult(id)); }
static void Main(string[] args) { var watch = new System.Diagnostics.Stopwatch(); Dictionary <Player, int> killsPerPlayer = new Dictionary <Player, int>(); watch.Start(); using (var file = File.OpenRead("demo3.dem")) { using (var demo = new DemoParser(file)) { demo.ParseHeader(); string map = demo.Map; demo.MatchStarted += (sender, e) => { foreach (var player in demo.PlayingParticipants) { killsPerPlayer[player] = 0; } }; demo.PlayerKilled += (object sender, PlayerKilledEventArgs e) => { if (e.Killer != null) { if (killsPerPlayer.ContainsKey(e.Killer)) { killsPerPlayer[e.Killer]++; } } }; demo.ParseToEnd(); } } watch.Stop(); Console.WriteLine("Base Run time: " + watch.Elapsed); foreach (KeyValuePair <Player, int> x in killsPerPlayer) { Console.WriteLine("{0} : {1}", x.Key.Name, x.Value); } Console.ReadKey(); }
public Results ParseDemo(string demoPath) { this.matchStarted = false; // Verify hash of demo SHA256Managed sha = new SHA256Managed(); byte[] bhash = sha.ComputeHash(File.OpenRead(demoPath)); string hash = BitConverter.ToString(bhash).Replace("-", String.Empty); Debug.WriteLine(String.Format("Demo hash: {0}", hash)); this.results = new Results(hash); parser = new DemoParser(File.OpenRead(demoPath)); parser.ParseHeader(); // Record the map this.results.Map = parser.Map; this.currentRound = new Round(); Debug.WriteLine(String.Format("Map: {0}", this.results.Map)); parser.MatchStarted += Parser_MatchStarted; parser.RoundStart += Parser_RoundStart; parser.PlayerKilled += Parser_PlayerKilled; parser.RoundEnd += Parser_RoundEnd; parser.TickDone += Parser_TickDone; parser.BombPlanted += Parser_BombPlanted; parser.BombDefused += Parser_BombDefused; parser.ParseToEnd(); // Record the final score and MVPs foreach (DemoInfo.Player p in parser.PlayingParticipants) { this.results.Players[p.SteamID].Score = p.AdditionaInformations.Score; this.results.Players[p.SteamID].MVPs = p.AdditionaInformations.MVPs; } return(this.results); }
public ReplayViewer() { InitializeComponent(); drawingBitmap = new Bitmap(1024, 1024); g = Graphics.FromImage(drawingBitmap); OpenFileDialog diag = new OpenFileDialog(); diag.DefaultExt = "*.dem"; diag.Filter = "CS:GO Demo (*.dem)|*.dem"; diag.FileName = "~/.steam/steam/SteamApps/common/Counter-Strike Global Offensive/csgo/replays/"; diag.ShowDialog(); if (!File.Exists(diag.FileName)) { MessageBox.Show("No valid file specified. "); this.Close(); Environment.Exit(0); } var reader = File.OpenRead(diag.FileName); parser = new DemoParser(reader); parser.ParseHeader(); parser.ParseToEnd(); LoadBackgroundInfo(); timer1.Enabled = true; parser.TickDone += parser_TickDone; parser.MatchStarted += parser_MatchStarted; parser.PlayerKilled += HandlePlayerKilled; parser.WeaponFired += HandleWeaponFired; }
private void fileButtonClick(object sender, EventArgs e) { int size = -1; DialogResult result = openFileDialog.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. { string file = openFileDialog.FileName; try { DemoParser parser = new DemoParser(File.OpenRead(file)); parser.ParseHeader(); Form1 form = new Form1(file); form.Show(); } catch (Exception) { MessageBox.Show("This file type is not supported. Select one with .dem extension.", "Reading error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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; }
public DemoReader(DemoFile file) { this.file = file; stats = new Statistics(); var demoId = file.FileName.GetHashCode(); parser = new DemoParser(file.Stream); parser.PlayerKilled += Parser_PlayerKilled; parser.RoundMVP += Parser_RoundMVP; parser.PlayerHurt += Parser_PlayerHurt; parser.RoundEnd += Parser_RoundEnd; parser.BombDefused += Parser_BombDefused; parser.BombPlanted += Parser_BombPlanted; parser.RoundStart += Parser_RoundStart; parser.TickDone += Parser_TickDone; parser.ParseHeader(); DemoService service = DemoService.Unknown; if (parser.Header.ServerName.ToLower().StartsWith("faceit", StringComparison.Ordinal)) { service = DemoService.FaceIt; } if (parser.Header.ServerName.ToLower().StartsWith("valve", StringComparison.Ordinal)) { service = DemoService.MatchMaking; } demo = new Demo { Id = demoId, DateTime = file.LastModified, Map = parser.Header.MapName, Duration = new TimeSpan(0, 0, (int)(parser.TickTime * parser.Header.PlaybackTicks)), Service = service, Players = new HashSet <long>() }; }