Ejemplo n.º 1
0
        public static Score ReadReplayFromFile(string filename)
        {
            //Make sure the score manager is already initialized.
            if (scoreList == null)
            {
                InitializeScoreManager();
            }

            Stream stream  = File.Open(filename, FileMode.Open);
            Score  inScore = (Score)DynamicDeserializer.Deserialize(stream);

            stream.Close();

            if (BeatmapManager.GetBeatmapByChecksum(inScore.fileChecksum) == null)
            {
                GameBase.ShowMessage("You do not have the beatmap this replay was made for.");
                return(null);
            }

            InsertScore(inScore, false, true);


            return(inScore);

            /*  }
             * catch (Exception e)
             * {
             *  GameBase.ShowMessage("Error reading replay...");
             *  return null;
             * }*/
        }
Ejemplo n.º 2
0
        internal static void ProcessBeatmaps()
        {
            ReadingDatabase = File.Exists("osu!.db");

            if (BeatmapAvailable == null)
            {
                if (ReadingDatabase)
                {
                    try
                    {
                        Stream stream = File.Open("osu!.db", FileMode.Open);
                        DatabaseVersion  = new BinaryReader(stream).ReadInt32();
                        BeatmapAvailable = (List <Beatmap>)DynamicDeserializer.Deserialize(stream);
                        stream.Close();
                    }
                    catch (Exception e)
                    {
                        BeatmapAvailable = new List <Beatmap>();
                        Console.WriteLine("corrupt database - recreating\n" + e);
                        try
                        {
                            if (File.Exists("osu!.db"))
                            {
                                File.Move("osu!.db", "osu!.bak");
                            }
                        }
                        catch { }
                    }
                }
                else
                {
                    BeatmapAvailable = new List <Beatmap>();
                }
            }
            else
            {
                BeatmapAvailable.ForEach(delegate(Beatmap b) { b.DatabaseNotFound = true; });
            }

            BeatmapTreeManager.Root.Children.Clear();

            TotalUniqueFolders = 0;
            TotalAudioOnly     = 0;

            ProcessFolder("Songs", BeatmapTreeManager.Root);

            if (ReadingDatabase)
            {
                BeatmapAvailable.RemoveAll(b => b.DatabaseNotFound);
            }

            Console.WriteLine("Loaded " + BeatmapAvailable.Count);

            if (Current != null)
            {
                SetCurrent(Current.Filename);
            }
        }
Ejemplo n.º 3
0
        /// <summary> Reads an object which was added to the buffer by WriteObject. </summary>
        public object ReadObject()
        {
            ObjType t = (ObjType)ReadByte();

            switch (t)
            {
            case ObjType.boolType:
                return(ReadBoolean());

            case ObjType.byteType:
                return(ReadByte());

            case ObjType.uint16Type:
                return(ReadUInt16());

            case ObjType.uint32Type:
                return(ReadUInt32());

            case ObjType.uint64Type:
                return(ReadUInt64());

            case ObjType.sbyteType:
                return(ReadSByte());

            case ObjType.int16Type:
                return(ReadInt16());

            case ObjType.int32Type:
                return(ReadInt32());

            case ObjType.int64Type:
                return(ReadInt64());

            case ObjType.charType:
                return(ReadChar());

            case ObjType.stringType:
                return(base.ReadString());

            case ObjType.singleType:
                return(ReadSingle());

            case ObjType.doubleType:
                return(ReadDouble());

            case ObjType.decimalType:
                return(ReadDecimal());

            case ObjType.dateTimeType:
                return(ReadDateTime());

            case ObjType.byteArrayType:
                return(ReadByteArray());

            case ObjType.charArrayType:
                return(ReadCharArray());

            case ObjType.otherType:
                return(DynamicDeserializer.Deserialize(BaseStream));

            default:
                return(null);
            }
        }
Ejemplo n.º 4
0
        internal static void InitializeScoreManager()
        {
            if (scoreList != null)
            {
                return;
            }

            scoreList = new List <Score>();

            if (File.Exists("scores.db"))
            {
                try
                {
                    Stream stream = File.Open("scores.db", FileMode.Open);
                    scoreList = (List <Score>)DynamicDeserializer.Deserialize(stream);
                    stream.Close();
                    scoreList.RemoveAll(s => BeatmapManager.GetBeatmapByChecksum(s.fileChecksum) == null);
                }
                catch (Exception)
                {
                    Console.WriteLine("corrupt scores database - recreating");
                    try
                    {
                        if (File.Exists("scores.db"))
                        {
                            File.Move("scores.db", "scores.bak");
                        }
                    }
                    catch { }
                }
            }
            else if (File.Exists("scores.dat"))
            {
                StreamReader s = new StreamReader("scores.dat");

                while (!s.EndOfStream)
                {
                    try
                    {
                        string[] line = s.ReadLine().Split(':');

                        Score score = new Score();

                        int i = 0;
                        score.pass         = true;
                        score.fileChecksum = line[i++];
                        score.playerName   = line[i++];
                        string scoreChecksum = line[i++];
                        score.count300     = Convert.ToUInt16(line[i++]);
                        score.count100     = Convert.ToUInt16(line[i++]);
                        score.count50      = Convert.ToUInt16(line[i++]);
                        score.countGeki    = Convert.ToUInt16(line[i++]);
                        score.countKatu    = Convert.ToUInt16(line[i++]);
                        score.countMiss    = Convert.ToUInt16(line[i++]);
                        score.totalScore   = Convert.ToInt32(line[i++]);
                        score.maxCombo     = Convert.ToUInt16(line[i++]);
                        score.perfect      = Convert.ToBoolean(line[i++]);
                        score.enabledMods  = (Mods)Convert.ToInt32(line[i++]);
                        score.rawReplayOld = line[i++];
                        score.ReadGraphData(line[i++]);
                        if (line.Length > i)
                        {
                            score.date = DateTime.FromBinary(long.Parse(line[i]));
                        }

                        if (score.date < DateTime.MinValue || score.date > DateTime.MaxValue)
                        {
                            score.date = DateTime.Now;
                        }

                        scoreList.Add(score);
                    }
                    catch (Exception)
                    {
                    }
                }
                s.Close();

                if (!File.Exists("scores.db"))
                {
                    if (ConfigManager.sFullscreen)
                    {
                        GameBase.ToggleFullscreen();
                    }
                    if (DialogResult.No == MessageBox.Show(
                            "osu! is about to perform some awesome maintenance on your local scores file.  Depending on how many scores and replays you have saved, this could take UP TO 5 MINUTES.  It will only happen ONCE, so please be patient!",
                            "stealin' ur cpu timez", MessageBoxButtons.YesNo,
                            MessageBoxIcon.Information))
                    {
                        MessageBox.Show("You think you have a choice?\nThink again... :>",
                                        "it won't take too long, don't worry", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    UpdateScores();
                    if (ConfigManager.sFullscreen)
                    {
                        GameBase.ToggleFullscreen();
                    }
                    if (File.Exists("scores.dat"))
                    {
                        if (!File.Exists("scores.dat.backup"))
                        {
                            File.Move("scores.dat", "scores.dat.backup");
                        }
                    }
                }
            }

            scoreList.Sort(delegate(Score s2, Score s1) { return(s1.totalScore.CompareTo(s2.totalScore)); });
        }
Ejemplo n.º 5
0
        public static Score ReadReplayFromFile(string filename, bool handlePickup)
        {
            //Make sure the score manager is already initialized.
            InitializeScoreManager();

            Score inScore = null;

            bool success = false;

            try
            {
                using (Stream stream = File.Open(filename, FileMode.Open))
                {
                    SerializationReader sr = new SerializationReader(stream);
                    inScore = ScoreFactory.Create((PlayModes)sr.ReadByte(), null);
                    inScore.ReadHeaderFromStream(sr);
                    if (ModManager.CheckActive(inScore.EnabledMods, Mods.Target))
                    {
                        inScore = new ScoreTarget(inScore);
                    }
                    inScore.ReadFromStream(sr);
                    if (inScore.Date < DateTime.UtcNow + new TimeSpan(365 * 5, 0, 0, 0))
                    {
                        success = true;
                    }
                }
            }
            catch { }


            if (!success)
            {
                try
                {
                    using (Stream stream = File.Open(filename, FileMode.Open))
                        inScore = (Score)DynamicDeserializer.Deserialize(stream);
                }
                catch
                {
                    NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_ReplayCorrupt));
                    return(null);
                }
            }

            if (inScore == null)
            {
                NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_ReplayCorrupt));
                return(null);
            }

            if (inScore.Date.Year > 2050 || inScore.Date == DateTime.MinValue)
            {
                string[] split = filename.Split('-');
                if (split.Length > 1)
                {
                    long outfiletime = 0;
                    if (long.TryParse(split[1].Replace(@".osr", string.Empty), out outfiletime))
                    {
                        inScore.Date = DateTime.FromFileTimeUtc(outfiletime);
                    }
                }
            }

            if (inScore.Date.Year > 2050)
            {
                //this score is TOTALLY f****d.
                File.Delete(filename);
                NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_ReplayCorrupt));
                return(null);
            }

            if (BeatmapManager.GetBeatmapByChecksum(inScore.FileChecksum) == null)
            {
                //attempt pickup.
                if (handlePickup)
                {
                    OsuDirect.HandlePickup(inScore.FileChecksum, null,
                                           delegate
                    {
                        NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_DontHaveBeatmap));
                    });
                }
                return(null);
            }

            InsertScore(inScore, false);

            return(inScore);
        }