Пример #1
0
        private void ProcessScreenshot(string filePath)
        {
            bool writeOutStats = false;

            imageProcessingStopWatch = new Stopwatch();
            imageProcessingStopWatch.Start();
            string imageText = OCRService.GetImageWords(filePath);

            imageProcessingStopWatch.Stop();

            totalScreenProcessed++;
            SetTotalImagesScannedLabel(totalScreenProcessed.ToString());

            totalProcessingTime += imageProcessingStopWatch.Elapsed.TotalSeconds;
            SetAverageProcessingTimeLabel((totalProcessingTime / totalScreenProcessed).ToString());

            /*
             * Some hacky ass processing right here, but whatever gets the job done, ya know/
             */
            List <string> textParts = imageText
                                      .Split(' ')
                                      .Select(z => z.ToLower().Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " "))
                                      .SelectMany(z => z.Split(' '))
                                      .ToList();

            if (textParts.Contains("kills") ||
                textParts.Contains("kill") ||
                textParts.Contains("ikill") ||
                textParts.Count > 2 && textParts[0] == "you" && textParts[1] == "killed" ||
                textParts.Any(z => z.IndexOf("m)") > -1)
                )
            {
                try
                {
                    if (DateTime.UtcNow.AddSeconds(-6) > PUBGStats.LastKill)
                    {
                        PUBGStats.Kills++;
                        PUBGStats.LastKill = DateTime.UtcNow;
                        SetKillsLabel(PUBGStats.Kills.ToString());
                        writeOutStats = true;
                    }
                }
                catch (Exception ex)
                {
                    //Meh
                }
            }
            //else if (textParts.Contains("next") || textParts.Any(z => z.IndexOf("time!") > -1))
            else if (textParts.Contains("killed"))
            {
                try
                {
                    int killedIndex = textParts.IndexOf("killed");
                    if (textParts[killedIndex + 1] == "you" && DateTime.UtcNow.AddMinutes(-2) > PUBGStats.LastDeath)
                    {
                        //This death ocurred more than 2 minutes after the last, probs real
                        PUBGStats.Deaths++;
                        PUBGStats.LastDeath = DateTime.UtcNow;
                        SetDeathsLabel(PUBGStats.Deaths.ToString());
                        writeOutStats = true;
                    }
                }
                catch (Exception ex)
                {
                }
            }
            //else if (textParts.Contains("winner"))
            //{
            //    try
            //    {
            //        if (DateTime.UtcNow.AddMinutes(-20) > PUBGStats.LastWin)
            //        {
            //            //This win happened 20 mins after the last, probs real
            //            PUBGStats.Wins++;
            //            PUBGStats.LastWin = DateTime.UtcNow;
            //            writeOutStats = true;
            //        }
            //    }
            //    catch (Exception ex)
            //    {

            //    }
            //}

            if (writeOutStats)
            {
                try
                {
                    WriteStats();
                }
                catch (Exception)
                {
                }
            }

            /*
             * Wipe the screenshot directory every 10
             */
            if (this.cbDeleteImagesAfterProcessing.Checked && totalScreenProcessed % 10 == 0)
            {
                DirectoryInfo di = new DirectoryInfo(applicationSettings.ScreenshotDirectory);
                Parallel.ForEach(di.GetFiles(), file =>
                {
                    file.Delete();
                });
            }
        }