Example #1
0
        /// <summary>
        /// Reads the stats entries
        /// </summary>
        /// <param name="file">CSX stats file</param>
        /// <returns></returns>
        public static ObservableCollection<StatsEntry> ReadEntriesToList(string file)
        {
            if (!File.Exists(file))
            {
                throw new FileNotFoundException();
            }

            FileStream stream = File.Open(file, FileMode.Open);

            if (stream == null)
            {
                throw new FileLoadException();
            }

            BinaryReader br = new BinaryReader(stream);
            ObservableCollection<StatsEntry> list;

            try
            {
                short vers = br.ReadInt16();

                if (vers != RankVersion)
                {
                    throw new Exception("Bad stats version");
                }

                ushort num = br.ReadUInt16();
                list = new ObservableCollection<StatsEntry>();

                while (num != 0)
                {
                    StatsEntry entry = new StatsEntry();

                    byte[] name = br.ReadBytes(num);
                    num = br.ReadUInt16();
                    byte[] unique = br.ReadBytes(num);

                    entry.Name = Encoding.ASCII.GetString(name, 0, name.Length - 1);
                    entry.Unique = Encoding.ASCII.GetString(unique, 0, unique.Length - 1);

                    entry.TeamKills = br.ReadUInt32();
                    entry.Damage = br.ReadUInt32();
                    entry.Deaths = br.ReadUInt32();
                    entry.Kills = br.ReadInt32();
                    entry.Shots = br.ReadUInt32();
                    entry.Hits = br.ReadUInt32();
                    entry.Headshots = br.ReadUInt32();
                    entry.BDefusions = br.ReadUInt32();
                    entry.BDefused = br.ReadUInt32();
                    entry.BPlants = br.ReadUInt32();
                    entry.BExplosions = br.ReadUInt32();

                    for (int i = 0; i < entry.BodyHits.Length; i++)
                    {
                        entry.BodyHits[i] = br.ReadUInt32();
                    }

                    num = br.ReadUInt16();

                    list.Add(entry);
                }
            }
            catch
            {
                throw new FileLoadException("Error reading file");
            }
            finally
            {
                br.Close();
                stream.Close();
            }

            return list;
        }
        public static StatsEntry operator +(StatsEntry a, StatsEntry b)
        {
            StatsEntry temp = new StatsEntry
                                  {
                                      Name = a.Name,
                                      Unique = a.Unique,
                                      Headshots = a.Headshots + b.Headshots,
                                      BDefused = a.BDefused + b.BDefused,
                                      BDefusions = a.BDefusions + b.BDefusions,
                                      BExplosions = a.BExplosions + b.BExplosions,
                                      BPlants = a.BPlants + b.BPlants,
                                      Damage = a.Damage + b.Damage,
                                      Deaths = a.Deaths + b.Deaths,
                                      Hits = a.Hits + b.Hits,
                                      Kills = a.Kills + b.Kills,
                                      Shots = a.Shots + b.Shots,
                                      TeamKills = a.TeamKills + b.TeamKills,
                                  };
            temp.BodyHits[0] = a.BodyHits[0] + b.BodyHits[0];
            temp.BodyHits[1] = a.BodyHits[1] + b.BodyHits[1];
            temp.BodyHits[2] = a.BodyHits[2] + b.BodyHits[2];
            temp.BodyHits[3] = a.BodyHits[3] + b.BodyHits[3];
            temp.BodyHits[4] = a.BodyHits[4] + b.BodyHits[4];
            temp.BodyHits[5] = a.BodyHits[5] + b.BodyHits[5];
            temp.BodyHits[6] = a.BodyHits[6] + b.BodyHits[6];
            temp.BodyHits[7] = a.BodyHits[7] + b.BodyHits[7];
            temp.BodyHits[8] = a.BodyHits[8] + b.BodyHits[8];

            return temp;
        }