Esempio n. 1
0
        /// <summary>
        /// Read a supported replay file or parse if a demo file is given
        /// </summary>
        /// <param name="demopath"></param>
        private static EncounterDetectionReplay ReadGamestateJSONFile(string demopath, ParseTaskSettings ptask)
        {
            Console.WriteLine("Reading: " + Path.GetFileName(demopath));
            try
            {
                var jsonpath = demopath.Replace(".dem", ".json");
                if (File.Exists(jsonpath) || Path.GetExtension(demopath) != ".json")
                {
                    if (new FileInfo(jsonpath).Length == 0)
                    {
                        Console.WriteLine("----- File empty -----");
                        return(null); //File was empty -> skipped parsing it but wrote json
                    }
                    Console.WriteLine("----- .dem file already parsed -----");
                    Console.WriteLine("----- Reading: " + jsonpath + " for Encounter Detection -----");

                    using (var reader = new StreamReader(jsonpath))
                    {
                        var deserializedGamestate = JsonConvert.DeserializeObject <ReplayGamestate>(reader.ReadToEnd(), ptask.Settings);
                        Console.WriteLine("Map: " + deserializedGamestate.Meta.Mapname);
                        if (deserializedGamestate == null)
                        {
                            throw new Exception("Gamestate null");
                        }

                        string metapath = META_PATH + deserializedGamestate.Meta.Mapname + ".txt";
                        var    mapmeta  = MapMetaDataPropertyReader.ReadProperties(metapath);
                        Console.WriteLine("Detecting Encounters");
                        Console.WriteLine("----- Reading GamestateJSON was sucessful ----- ");
                        return(new EncounterDetection(deserializedGamestate, mapmeta, new CSGOPreprocessor()).DetectEncounters());
                    }
                }
                else
                {
                    Console.WriteLine("----- File not existent or right format: " + demopath + "-----");
                    return(null);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("----- Error occured. Skip file: " + demopath + "-----");
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Read a demo json file if the corresponding replay file was already parsed
        /// </summary>
        /// <param name="jsonpath"></param>
        /// <param name="ptask"></param>
        public static EncounterDetection ReadDemoJSON(string jsonpath, ParseTaskSettings ptask)
        {
            Console.WriteLine("Reading: " + jsonpath + " for Encounter Detection");

            using (var reader = new StreamReader(jsonpath))
            {
                var deserializedGamestate = JsonConvert.DeserializeObject <ReplayGamestate>(reader.ReadToEnd(), ptask.Settings);
                Console.WriteLine("Map: " + deserializedGamestate.Meta.Mapname);
                if (deserializedGamestate == null)
                {
                    throw new Exception("Gamestate null");
                }

                string metapath = META_PATH + deserializedGamestate.Meta.Mapname + ".txt";
                var    mapmeta  = MapMetaDataPropertyReader.ReadProperties(metapath);
                mapmeta.Mapname = deserializedGamestate.Meta.Mapname;
                Console.WriteLine(mapmeta);
                Console.WriteLine("Detecting Encounters");
                return(new EncounterDetection(deserializedGamestate, mapmeta, new CSGOPreprocessor()));
            }
        }