Ejemplo n.º 1
0
        //Program entry point
        static void Main(string[] args)
        {
            string cfgPath = "config.cfg";

            bool   recursive           = false;
            bool   steaminfo           = false;
            bool   clear               = false;
            bool   parseChickens       = true;
            string outputRootFolder    = "parsed";
            bool   sameFilename        = false;
            bool   sameFolderStructure = false;
            bool   lowOutputMode       = false;

            List <string> foldersToProcess = new List <string>();
            List <string> demosToProcess   = new List <string>();

            if (args.Count() == 0)
            {
                helpText();
                return;
            }

            for (int i = 0; i < args.Count(); i++)
            {
                var arg = args[i].ToLower();

                if (arg == "-config")
                {
                    if (i < args.Count())
                    {
                        cfgPath = args[i + 1];
                    }

                    i++;
                }
                else if (arg == "-folders")
                {
                    bool searching = true;
                    while (i < args.Count() - 1 && searching)
                    {
                        i++;

                        if (args[i][0] == '-')
                        {
                            searching = false;
                        }
                        else
                        {
                            foldersToProcess.Add(args[i]);
                        }
                    }
                    i--;
                }
                else if (arg == "-demos")
                {
                    bool searching = true;
                    while (i < args.Count() - 1 && searching)
                    {
                        i++;

                        if (args[i][0] == '-')
                        {
                            searching = false;
                        }
                        else
                        {
                            demosToProcess.Add(args[i]);
                        }
                    }
                    i--;
                }
                else if (arg == "-output")
                {
                    outputRootFolder = args[i + 1];
                    i++;
                }
                else if (arg == "-clear")
                {
                    clear = true;
                }
                else if (arg == "-steaminfo")
                {
                    steaminfo = true;
                }
                else if (arg == "-recursive")
                {
                    recursive = true;
                }
                else if (arg == "-help")
                {
                    helpText();
                    return;
                }
                else if (arg == "-nochickens")
                {
                    parseChickens = false;
                }
                else if (arg == "-samefilename")
                {
                    sameFilename = true;
                }
                else if (arg == "-samefolderstructure")
                {
                    sameFolderStructure = true;
                }
                else if (arg == "-lowoutputmode")
                {
                    lowOutputMode = true;
                }
            }

            if (steaminfo)
            {
                if (File.Exists(cfgPath))
                {
                    try
                    {
                        Config cfg = new Config(cfgPath);

                        Steam.setAPIKey(cfg.keyVals["apikey"]);

                        if (Steam.getSteamUserNamesLookupTable(new List <long>()
                        {
                            76561198072130043
                        }) == null)
                        {
                            throw new Exception("CONFIG::STEAM_API_KEY::INVALID");
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.Error("CONFIG ERROR... INFO:: {0}\nSteam names will not be retrieved!!!", e.Message);
                        steaminfo = false;
                    }
                }
                else
                {
                    Debug.Error("Config unreadable... Steam names will not be retrieved!!!");
                    steaminfo = false;
                }
            }

            //Clear by recreating folder
            if (clear && Directory.Exists(outputRootFolder))
            {
                Directory.Delete(outputRootFolder, true);
                Directory.CreateDirectory(outputRootFolder);
            }
            else if (!Directory.Exists(outputRootFolder))
            {
                Directory.CreateDirectory(outputRootFolder);
            }

            List <DemoInformation> demosInformation = new List <DemoInformation>();

            foreach (string folder in foldersToProcess)
            {
                try
                {
                    string[] subDemos = Directory.GetFiles(Path.GetFullPath(folder), "*.dem", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
                    foreach (string demo in subDemos)
                    {
                        string[] pathSplit = demo.Split('\\');
                        string   testDate, testType, mapname;

                        Guid     guid;
                        string[] filenameSplit = pathSplit[pathSplit.Count() - 1].Split('.');
                        bool     isFaceitDemo  = Guid.TryParse(filenameSplit[0], out guid);

                        if (isFaceitDemo)
                        {
                            testDate = "unknown";
                            testType = "unknown";
                            mapname  = "unknown";
                        }
                        else
                        {
                            filenameSplit = pathSplit[pathSplit.Count() - 1].Split('_', '.');

                            bool isSEDiscordDemo = filenameSplit.Count() > 5 ? true : false;

                            if (isSEDiscordDemo)
                            {
                                testDate = $"{ filenameSplit[1] }/{ filenameSplit[0] }/{ filenameSplit[2] }";
                                testType = $"{ filenameSplit[filenameSplit.Count() - 2] }";
                                mapname  = $"{ filenameSplit[3] }";

                                for (int i = 4; i < filenameSplit.Count() - 2; i++)
                                {
                                    mapname += $"_{ filenameSplit[i] }";
                                }
                            }
                            else //cannot determine demo name format
                            {
                                testDate = "unknown";
                                testType = "unknown";
                                mapname  = "unknown";
                            }
                        }

                        demosInformation.Add(new DemoInformation()
                        {
                            DemoName = demo, MapName = mapname, TestDate = testDate, TestType = testType
                        });
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            foreach (string demo in demosToProcess)
            {
                try
                {
                    string testDate, testType, mapname;

                    Guid     guid;
                    string[] filenameSplit = demo.Split('.');
                    bool     isFaceitDemo  = Guid.TryParse(filenameSplit[0], out guid);

                    if (isFaceitDemo)
                    {
                        testDate = "unknown";
                        testType = "unknown";
                        mapname  = "unknown";
                    }
                    else
                    {
                        filenameSplit = demo.Split('_', '.');

                        bool isSEDiscordDemo = filenameSplit.Count() > 5 ? true : false;

                        if (isSEDiscordDemo)
                        {
                            testDate = $"{ filenameSplit[1] }/{ filenameSplit[0] }/{ filenameSplit[2] }";
                            testType = $"{ filenameSplit[filenameSplit.Count() - 2] }";
                            mapname  = $"{ filenameSplit[3] }";

                            for (int i = 4; i < filenameSplit.Count() - 2; i++)
                            {
                                mapname += $"_{ filenameSplit[i] }";
                            }
                        }
                        else //cannot determine demo name format
                        {
                            testDate = "unknown";
                            testType = "unknown";
                            mapname  = "unknown";
                        }
                    }

                    demosInformation.Add(new DemoInformation()
                    {
                        DemoName = demo, MapName = mapname, TestDate = testDate, TestType = testType
                    });
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            Debug.Info("Starting processing of {0} demos.\n", demosInformation.Count());
            DateTime startTime = DateTime.Now;

            int passCount = 0;

            Console.CursorVisible = false;
            //Process all the found demos
            for (int i = 0; i < demosInformation.Count(); i++)
            {
                Console.WriteLine($"Parsing demo {demosInformation[i].DemoName}");

                MatchData mdTest = MatchData.FromDemoFile(demosInformation[i].DemoName, parseChickens, lowOutputMode);

                IEnumerable <MatchStartedEventArgs>        mse = new List <MatchStartedEventArgs>();
                IEnumerable <SwitchSidesEventArgs>         sse = new List <SwitchSidesEventArgs>();
                IEnumerable <FeedbackMessage>              fme = new List <FeedbackMessage>();
                IEnumerable <TeamPlayers>                  tpe = new List <TeamPlayers>();
                IEnumerable <PlayerKilledEventArgs>        pke = new List <PlayerKilledEventArgs>();
                Dictionary <string, IEnumerable <Player> > pe  = new Dictionary <string, IEnumerable <Player> >();
                IEnumerable <Equipment>          pwe           = new List <Equipment>();
                IEnumerable <int>                poe           = new List <int>();
                IEnumerable <BombPlanted>        bpe           = new List <BombPlanted>();
                IEnumerable <BombExploded>       bee           = new List <BombExploded>();
                IEnumerable <BombDefused>        bde           = new List <BombDefused>();
                IEnumerable <HostageRescued>     hre           = new List <HostageRescued>();
                IEnumerable <HostagePickedUp>    hpu           = new List <HostagePickedUp>();
                IEnumerable <DisconnectedPlayer> dpe           = new List <DisconnectedPlayer>();
                IEnumerable <Team>               te            = new List <Team>();
                IEnumerable <RoundEndReason>     re            = new List <RoundEndReason>();
                IEnumerable <double>             le            = new List <double>();
                IEnumerable <TeamEquipmentStats> tes           = new List <TeamEquipmentStats>();
                IEnumerable <NadeEventArgs>      ge            = new List <NadeEventArgs>();
                //IEnumerable<SmokeEventArgs> gse = new List<SmokeEventArgs>();
                //IEnumerable<FlashEventArgs> gfe = new List<FlashEventArgs>();
                //IEnumerable<GrenadeEventArgs> gge = new List<GrenadeEventArgs>();
                //IEnumerable<FireEventArgs> gie = new List<FireEventArgs>();
                //IEnumerable<DecoyEventArgs> gde = new List<DecoyEventArgs>();
                IEnumerable <ChickenKilledEventArgs> cke = new List <ChickenKilledEventArgs>();
                IEnumerable <ShotFired> sfe = new List <ShotFired>();

                mse = (from start in mdTest.GetEvents <MatchStartedEventArgs>()
                       select(start as MatchStartedEventArgs));

                sse = (from switchSide in mdTest.GetEvents <SwitchSidesEventArgs>()
                       select(switchSide as SwitchSidesEventArgs));

                fme = (from message in mdTest.GetEvents <FeedbackMessage>()
                       select(message as FeedbackMessage));

                pke = (from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(player as PlayerKilledEventArgs));

                pe.Add("Kills", from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(player as PlayerKilledEventArgs).Killer);

                pe.Add("Deaths", from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(player as PlayerKilledEventArgs).Victim);

                pe.Add("Headshots", from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       where (player as PlayerKilledEventArgs).Headshot
                       select(player as PlayerKilledEventArgs).Killer);

                pe.Add("Assists", from player in mdTest.GetEvents <PlayerKilledEventArgs>()
                       where (player as PlayerKilledEventArgs).Assister != null
                       select(player as PlayerKilledEventArgs).Assister);

                pwe = (from weapon in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(weapon as PlayerKilledEventArgs).Weapon);

                poe = (from penetration in mdTest.GetEvents <PlayerKilledEventArgs>()
                       select(penetration as PlayerKilledEventArgs).PenetratedObjects);

                pe.Add("MVPs", from player in mdTest.GetEvents <RoundMVPEventArgs>()
                       select(player as RoundMVPEventArgs).Player);

                pe.Add("Shots", from player in mdTest.GetEvents <WeaponFiredEventArgs>()
                       select(player as WeaponFiredEventArgs).Shooter);

                pe.Add("Plants", from player in mdTest.GetEvents <BombPlanted>()
                       select(player as BombPlanted).Player);

                pe.Add("Defuses", from player in mdTest.GetEvents <BombDefused>()
                       select(player as BombDefused).Player);

                pe.Add("Rescues", from player in mdTest.GetEvents <HostageRescued>()
                       select(player as HostageRescued).Player);

                bpe = (from plant in mdTest.GetEvents <BombPlanted>()
                       select plant as BombPlanted)
                      .GroupBy(p => p.Round)
                      .Select(p => p.FirstOrDefault());

                bee = (from explode in mdTest.GetEvents <BombExploded>()
                       select explode as BombExploded)
                      .GroupBy(p => p.Round)
                      .Select(p => p.FirstOrDefault());

                bde = (from defuse in mdTest.GetEvents <BombDefused>()
                       select defuse as BombDefused)
                      .GroupBy(p => p.Round)
                      .Select(p => p.FirstOrDefault());

                hre = (from hostage in mdTest.GetEvents <HostageRescued>()
                       select hostage as HostageRescued);

                hpu = (from hostage in mdTest.GetEvents <HostagePickedUp>()
                       select hostage as HostagePickedUp);

                dpe = (from disconnection in mdTest.GetEvents <DisconnectedPlayer>()
                       select(disconnection as DisconnectedPlayer));

                te = (from team in mdTest.GetEvents <RoundEndedEventArgs>()
                      select(team as RoundEndedEventArgs).Winner);

                re = (from reason in mdTest.GetEvents <RoundEndedEventArgs>()
                      select(reason as RoundEndedEventArgs).Reason);

                le = (from length in mdTest.GetEvents <RoundEndedEventArgs>()
                      select(length as RoundEndedEventArgs).Length);

                tpe = (from teamPlayers in mdTest.GetEvents <TeamPlayers>()
                       where (teamPlayers as TeamPlayers).Round <= te.Count() // removes extra TeamPlayers if freezetime_end event triggers once a playtest is finished
                       select(teamPlayers as TeamPlayers));

                tes = (from round in mdTest.GetEvents <TeamEquipmentStats>()
                       select(round as TeamEquipmentStats));

                ge = (from nade in mdTest.GetEvents <NadeEventArgs>()
                      select(nade as NadeEventArgs));

                cke = (from chickenKill in mdTest.GetEvents <ChickenKilledEventArgs>()
                       select(chickenKill as ChickenKilledEventArgs));

                sfe = (from shot in mdTest.GetEvents <ShotFired>()
                       select(shot as ShotFired));

                tanookiStats tanookiStats = tanookiStatsCreator(tpe, dpe);


                if (mdTest.passed)
                {
                    // create the json output files using the data gathered
                    var processedData = new ProcessedData()
                    {
                        DemoInformation          = demosInformation[i],
                        SameFilename             = sameFilename,
                        SameFolderStructure      = sameFolderStructure,
                        ParseChickens            = parseChickens,
                        FoldersToProcess         = foldersToProcess,
                        OutputRootFolder         = outputRootFolder,
                        tanookiStats             = tanookiStats,
                        MatchStartValues         = mse,
                        SwitchSidesValues        = sse,
                        MessagesValues           = fme,
                        TeamPlayersValues        = tpe,
                        PlayerKilledEventsValues = pke,
                        PlayerValues             = pe,
                        WeaponValues             = pwe,
                        PenetrationValues        = poe,
                        BombsitePlantValues      = bpe,
                        BombsiteExplodeValues    = bee,
                        BombsiteDefuseValues     = bde,
                        HostageRescueValues      = hre,
                        HostagePickedUpValues    = hpu,
                        TeamValues           = te,
                        RoundEndReasonValues = re,
                        RoundLengthValues    = le,
                        TeamEquipmentValues  = tes,
                        GrenadeValues        = ge,
                        ChickenValues        = cke,
                        ShotsFiredValues     = sfe,
                        WriteTicks           = true
                    };

                    var allStats = mdTest.CreateFiles(processedData);

                    passCount++;

                    Console.WriteLine($"Finished parsing demo {demosInformation[i].DemoName}.\n");
                }
                else
                {
                    Console.WriteLine($"Failed parsing demo {demosInformation[i].DemoName}.\n");
                }
            }

            Console.CursorVisible = true;

            Debug.Blue("========== PROCESSING COMPLETE =========\n");
            DateTime end = DateTime.Now;

            Debug.White("Processing took {0} minutes\n", (end - startTime).TotalMinutes);
            Debug.White("Passed: {0}\n", passCount);
            Debug.White("Failed: {0}\n", demosInformation.Count() - passCount);
        }