/// <summary> /// Parses presence.db file. /// </summary> /// <param name="stream">Stream containing presence.db data.</param> /// <returns>A usable <see cref="PresenceDatabase"/>.</returns> public static PresenceDatabase DecodePresence(Stream stream) { PresenceDatabase db = new PresenceDatabase(); using (var r = new SerializationReader(stream)) { db.OsuVersion = r.ReadInt32(); int playersCount = r.ReadInt32(); for (int i = 0; i < playersCount; i++) { Player player = new Player(); player.UserId = r.ReadInt32(); player.Username = r.ReadString(); player.Timezone = r.ReadByte() - 24; player.CountryCode = r.ReadByte(); byte b = r.ReadByte(); player.Permissions = (Permissions)(b & ~0xe0); player.Ruleset = (Ruleset)Math.Max(0, Math.Min(3, ((b & 0xe0) >> 5))); player.Longitude = r.ReadSingle(); player.Latitude = r.ReadSingle(); player.Rank = r.ReadInt32(); player.LastUpdateTime = r.ReadDateTime(); db.Players.Add(player); } } return(db); }
internal Score(SerializationInfo info, StreamingContext ctxt) { SerializationReader sr = SerializationReader.GetReader(info); pass = true; fileChecksum = sr.ReadString(); playerName = sr.ReadString(); string scoreChecksumCheck = sr.ReadString(); count300 = sr.ReadUInt16(); count100 = sr.ReadUInt16(); count50 = sr.ReadUInt16(); countGeki = sr.ReadUInt16(); countKatu = sr.ReadUInt16(); countMiss = sr.ReadUInt16(); totalScore = sr.ReadInt32(); maxCombo = sr.ReadUInt16(); perfect = sr.ReadBoolean(); enabledMods = (Mods)sr.ReadInt32(); rawGraph = sr.ReadString(); rawReplayCompressed = sr.ReadByteArray(); date = sr.ReadDateTime(); if (scoreChecksumCheck != offlineScoreChecksum) { throw new Exception("f****d score"); } }
public void ReadFromStream(SerializationReader r) { OsuVersion = r.ReadInt32(); FolderCount = r.ReadInt32(); AccountUnlocked = r.ReadBoolean(); AccountUnlockDate = r.ReadDateTime(); AccountName = r.ReadString(); Beatmaps = new List <BeatmapEntry>(); int length = r.ReadInt32(); for (int i = 0; i < length; i++) { int currentIndex = (int)r.BaseStream.Position; int entryLength = r.ReadInt32(); Beatmaps.Add(BeatmapEntry.ReadFromReader(r, false, OsuVersion)); if (r.BaseStream.Position != currentIndex + entryLength + 4) { Debug.Fail($"Length doesn't match, {r.BaseStream.Position} instead of expected {currentIndex + entryLength + 4}"); } } AccountRank = (PlayerRank)r.ReadByte(); }
public Beatmap(SerializationInfo info, StreamingContext ctxt) { SerializationReader sr = SerializationReader.GetReader(info); Artist = sr.ReadString(); Title = sr.ReadString(); Creator = sr.ReadString(); Version = sr.ReadString(); AudioFilename = sr.ReadString(); BeatmapChecksum = sr.ReadString(); Filename = sr.ReadString(); submissionStatus = (SubmissionStatus)sr.ReadByte(); countNormal = sr.ReadUInt16(); countSlider = sr.ReadUInt16(); countSpinner = sr.ReadUInt16(); DateModified = sr.ReadDateTime(); DifficultyCircleSize = sr.ReadByte(); DifficultyHpDrainRate = sr.ReadByte(); DifficultyOverall = sr.ReadByte(); DifficultySliderMultiplier = sr.ReadDouble(); DrainLength = sr.ReadInt32(); TotalLength = sr.ReadInt32(); PreviewTime = sr.ReadInt32(); TimingPoints = (List <TimingPoint>)sr.ReadList <TimingPoint>(); BeatmapId = sr.ReadInt32(); BeatmapSetId = sr.ReadInt32(); BeatmapTopicId = sr.ReadInt32(); if (BeatmapManager.DatabaseVersion >= 361) { PlayerRank = (Rankings)sr.ReadByte(); PlayerOffset = sr.ReadInt16(); } if (BeatmapManager.DatabaseVersion >= 365) { StackLeniency = sr.ReadSingle(); } if (BeatmapManager.DatabaseVersion >= 372) { Mode = sr.ReadByte(); } if (BeatmapManager.DatabaseVersion >= 374) { Source = sr.ReadString(); Tags = sr.ReadString(); } ObjectCount = countNormal + countSpinner + countSlider; BeatmapPresent = true; AudioPresent = true; ContainingFolder = Path.GetDirectoryName(Filename); DatabaseNotFound = true; PopulateTitleStatics(); }
protected virtual void SetObjectData(SerializationReader sr) { f_TimeStamp = sr.ReadDateTime(); f_MessageParts = sr.ReadList <MessagePartModel>(); f_MessageType = (MessageType)sr.ReadInt32(); // backward compatibility with engines < 1.1 if (sr.PeekChar() != -1) { ID = sr.ReadString(); } }
public static MarketOrder DeserializeOrder(SerializationReader reader) { var deal = new MarketOrder { ID = reader.ReadInt32(), AccountID = reader.ReadInt32(), Comment = reader.ReadString(), ExitReason = (PositionExitReason)reader.ReadInt16(), ExpertComment = reader.ReadString(), PriceEnter = reader.ReadSingle(), ResultDepo = reader.ReadSingle(), ResultPoints = reader.ReadSingle(), Side = reader.ReadSByte(), State = (PositionState) reader.ReadInt16(), Symbol = reader.ReadString(), TimeEnter = reader.ReadDateTime(), Trailing = reader.ReadString(), Volume = reader.ReadInt32(), VolumeInDepoCurrency = reader.ReadSingle() }; // nullable values var flags = reader.ReadOptimizedBitVector32(); if (flags[magicIsValued]) deal.Magic = reader.ReadInt32(); if (flags[pendingOrderIdIsValued]) deal.PendingOrderID = reader.ReadInt32(); if (flags[priceBestIsValued]) deal.PriceBest = reader.ReadSingle(); if (flags[priceExitIsValued]) deal.PriceExit = reader.ReadSingle(); if (flags[priceWorstIsValued]) deal.PriceWorst = reader.ReadSingle(); if (flags[stopLossIsValued]) deal.StopLoss = reader.ReadSingle(); if (flags[swapIsValued]) deal.Swap = reader.ReadSingle(); if (flags[takeProfitIsValued]) deal.TakeProfit = reader.ReadSingle(); if (flags[timeExitIsValued]) deal.TimeExit = reader.ReadDateTime(); return deal; }
/// <summary> /// Parses scores.db file. /// </summary> /// <param name="stream">Stream containing scores.db data.</param> /// <returns>A usable <see cref="ScoresDatabase"/>.</returns> public static ScoresDatabase DecodeScores(Stream stream) { ScoresDatabase db = new ScoresDatabase(); using (var r = new SerializationReader(stream)) { db.OsuVersion = r.ReadInt32(); int beatmapCount = r.ReadInt32(); for (int i = 0; i < beatmapCount; i++) { string md5Hash = r.ReadString(); int scoresCount = r.ReadInt32(); List <Score> scores = new List <Score>(); for (int j = 0; j < scoresCount; j++) { Score score = new Score(); score.Ruleset = (Ruleset)r.ReadByte(); score.OsuVersion = r.ReadInt32(); score.BeatmapMD5Hash = r.ReadString(); score.PlayerName = r.ReadString(); score.ReplayMD5Hash = r.ReadString(); score.Count300 = r.ReadUInt16(); score.Count100 = r.ReadUInt16(); score.Count50 = r.ReadUInt16(); score.CountGeki = r.ReadUInt16(); score.CountKatu = r.ReadUInt16(); score.CountMiss = r.ReadUInt16(); score.ReplayScore = r.ReadInt32(); score.Combo = r.ReadUInt16(); score.PerfectCombo = r.ReadBoolean(); score.Mods = (Mods)r.ReadInt32(); string lifeBarGraphData = r.ReadString(); score.ScoreTimestamp = r.ReadDateTime(); r.BaseStream.Seek(sizeof(int), SeekOrigin.Current); score.ScoreId = r.ReadInt64(); scores.Add(score); } db.Scores.Add(new Tuple <string, List <Score> >(md5Hash, scores)); } } return(db); }
public void ReadFromStream(SerializationReader r) { PlayerId = r.ReadInt32(); PlayerName = r.ReadString(); UtcOffset = r.ReadByte(); CountryByte = r.ReadByte(); //TODO: create Country enum byte b = r.ReadByte(); PlayerRank = (PlayerRank)(b & 0b0001_1111); GameMode = (GameMode)((b & 0b1110_0000) >> 5); Debug.Assert((byte)GameMode <= 3, $"GameMode is byte {(byte)GameMode}, should be between 0 and 3"); Longitude = r.ReadSingle(); Latitude = r.ReadSingle(); GlobalRank = r.ReadInt32(); LastUpdate = r.ReadDateTime(); }
public void ReadHeaderFromStream(SerializationReader sr) { Pass = true; Version = sr.ReadInt32(); FileChecksum = sr.ReadString(); PlayerName = sr.ReadString(); var localScoreChecksum = sr.ReadString(); Count300 = sr.ReadUInt16(); Count100 = sr.ReadUInt16(); Count50 = sr.ReadUInt16(); CountGeki = sr.ReadUInt16(); CountKatu = sr.ReadUInt16(); CountMiss = sr.ReadUInt16(); TotalScore = sr.ReadInt32(); MaxCombo = sr.ReadUInt16(); Perfect = sr.ReadBoolean(); EnabledMods = (Mods)sr.ReadInt32(); HpGraphString = sr.ReadString(); Date = sr.ReadDateTime(); }
public void ReadFromStream(SerializationReader r) { OsuVersion = r.ReadInt32(); FolderCount = r.ReadInt32(); AccountUnlocked = r.ReadBoolean(); AccountUnlockDate = r.ReadDateTime(); AccountName = r.ReadString(); Beatmaps = new List <BeatmapEntry>(); int length = r.ReadInt32(); for (int i = 0; i < length; i++) { int currentIndex = (int)r.BaseStream.Position; int entryLength = 0; // After version 20191107, the size of the beatmap entry is no longer present // https://github.com/ppy/osu-wiki/commit/7ce3b8988d9945fe5867029a65750b40d66a3820 const int lengthOsuVersion = 20191107; if (OsuVersion < lengthOsuVersion) { entryLength = r.ReadInt32(); } Beatmaps.Add(BeatmapEntry.ReadFromReader(r, false, OsuVersion)); if (OsuVersion < lengthOsuVersion && r.BaseStream.Position != currentIndex + entryLength + 4) { Debug.Fail($"Length doesn't match, {r.BaseStream.Position} instead of expected {currentIndex + entryLength + 4}"); } } AccountRank = (PlayerRank)r.ReadByte(); }
public void ReadFromStream(SerializationReader sr) { Presence = new bUserPresence(sr); LastUpdate = sr.ReadDateTime(); }
/// <summary> /// Parses .osr file. /// </summary> /// <param name="stream">Stream containing replay data.</param> /// <returns>A usable <see cref="Replay"/>.</returns> public static Replay Decode(Stream stream) { Replay replay = new Replay(); using (var r = new SerializationReader(stream)) { replay.Ruleset = (Ruleset)r.ReadByte(); replay.OsuVersion = r.ReadInt32(); replay.BeatmapMD5Hash = r.ReadString(); replay.PlayerName = r.ReadString(); replay.ReplayMD5Hash = r.ReadString(); replay.Count300 = r.ReadUInt16(); replay.Count100 = r.ReadUInt16(); replay.Count50 = r.ReadUInt16(); replay.CountGeki = r.ReadUInt16(); replay.CountKatu = r.ReadUInt16(); replay.CountMiss = r.ReadUInt16(); replay.ReplayScore = r.ReadInt32(); replay.Combo = r.ReadUInt16(); replay.PerfectCombo = r.ReadBoolean(); replay.Mods = (Mods)r.ReadInt32(); string lifeData = r.ReadString(); if (!string.IsNullOrEmpty(lifeData)) { foreach (string lifeBlock in lifeData.Split(',')) { string[] split = lifeBlock.Split('|'); if (split.Length < 2) { continue; } replay.LifeFrames.Add(new LifeFrame() { Time = Convert.ToInt32(split[0]), Percentage = ParseHelper.ToFloat(split[1]) }); } } replay.ReplayTimestamp = r.ReadDateTime(); replay.ReplayLength = r.ReadInt32(); if (replay.ReplayLength > 0) { byte[] replayDataBytes = r.ReadBytes(replay.ReplayLength); byte[] decompressedBytes = LZMAHelper.Decompress(replayDataBytes); string decompressedString = Encoding.ASCII.GetString(decompressedBytes); int lastTime = 0; foreach (string frame in decompressedString.Split(',')) { if (string.IsNullOrEmpty(frame)) { continue; } string[] split = frame.Split('|'); if (split.Length < 4) { continue; } if (split[0] == "-12345") { replay.Seed = Convert.ToInt32(split[3]); continue; } ReplayFrame replayFrame = new ReplayFrame(); replayFrame.TimeDiff = Convert.ToInt32(split[0]); replayFrame.Time = Convert.ToInt32(split[0]) + lastTime; replayFrame.X = ParseHelper.ToFloat(split[1]); replayFrame.Y = ParseHelper.ToFloat(split[2]); switch (replay.Ruleset) { case Ruleset.Standard: replayFrame.StandardKeys = (StandardKeys)Convert.ToInt32(split[3]); break; case Ruleset.Taiko: replayFrame.TaikoKeys = (TaikoKeys)Convert.ToInt32(split[3]); break; case Ruleset.Fruits: replayFrame.CatchKeys = (CatchKeys)Convert.ToInt32(split[3]); break; case Ruleset.Mania: replayFrame.ManiaKeys = (ManiaKeys)replayFrame.X; break; } replay.ReplayFrames.Add(replayFrame); lastTime = replay.ReplayFrames.Last().Time; } } if (r.BaseStream.Length - r.BaseStream.Position > 0) { if (r.BaseStream.Length - r.BaseStream.Position == 4) { replay.OnlineId = r.ReadInt32(); } else { replay.OnlineId = r.ReadInt64(); } } } return(replay); }
public Score Parse(Stream stream) { var score = new Score { Replay = new Replay() }; WorkingBeatmap workingBeatmap; using (SerializationReader sr = new SerializationReader(stream)) { currentRuleset = GetRuleset(sr.ReadByte()); var scoreInfo = new ScoreInfo { Ruleset = currentRuleset.RulesetInfo }; score.ScoreInfo = scoreInfo; int version = sr.ReadInt32(); workingBeatmap = GetBeatmap(sr.ReadString()); if (workingBeatmap is DummyWorkingBeatmap) { throw new BeatmapNotFoundException(); } scoreInfo.User = new APIUser { Username = sr.ReadString() }; // MD5Hash sr.ReadString(); scoreInfo.SetCount300(sr.ReadUInt16()); scoreInfo.SetCount100(sr.ReadUInt16()); scoreInfo.SetCount50(sr.ReadUInt16()); scoreInfo.SetCountGeki(sr.ReadUInt16()); scoreInfo.SetCountKatu(sr.ReadUInt16()); scoreInfo.SetCountMiss(sr.ReadUInt16()); scoreInfo.TotalScore = sr.ReadInt32(); scoreInfo.MaxCombo = sr.ReadUInt16(); /* score.Perfect = */ sr.ReadBoolean(); scoreInfo.Mods = currentRuleset.ConvertFromLegacyMods((LegacyMods)sr.ReadInt32()).ToArray(); // lazer replays get a really high version number. if (version < LegacyScoreEncoder.FIRST_LAZER_VERSION) { scoreInfo.Mods = scoreInfo.Mods.Append(currentRuleset.CreateMod <ModClassic>()).ToArray(); } currentBeatmap = workingBeatmap.GetPlayableBeatmap(currentRuleset.RulesetInfo, scoreInfo.Mods); scoreInfo.BeatmapInfo = currentBeatmap.BeatmapInfo; /* score.HpGraphString = */ sr.ReadString(); scoreInfo.Date = sr.ReadDateTime(); byte[] compressedReplay = sr.ReadByteArray(); if (version >= 20140721) { scoreInfo.OnlineID = sr.ReadInt64(); } else if (version >= 20121008) { scoreInfo.OnlineID = sr.ReadInt32(); } if (compressedReplay?.Length > 0) { using (var replayInStream = new MemoryStream(compressedReplay)) { byte[] properties = new byte[5]; if (replayInStream.Read(properties, 0, 5) != 5) { throw new IOException("input .lzma is too short"); } long outSize = 0; for (int i = 0; i < 8; i++) { int v = replayInStream.ReadByte(); if (v < 0) { throw new IOException("Can't Read 1"); } outSize |= (long)(byte)v << (8 * i); } long compressedSize = replayInStream.Length - replayInStream.Position; using (var lzma = new LzmaStream(properties, replayInStream, compressedSize, outSize)) using (var reader = new StreamReader(lzma)) readLegacyReplay(score.Replay, reader); } } } PopulateAccuracy(score.ScoreInfo); // before returning for database import, we must restore the database-sourced BeatmapInfo. // if not, the clone operation in GetPlayableBeatmap will cause a dereference and subsequent database exception. score.ScoreInfo.BeatmapInfo = workingBeatmap.BeatmapInfo; return(score); }
/// <summary> /// Parses osu!.db file. /// </summary> /// <param name="stream">Stream containing osu!.db data.</param> /// <returns>A usable <see cref="OsuDatabase"/>.</returns> public static OsuDatabase DecodeOsu(Stream stream) { OsuDatabase db = new OsuDatabase(); using (var r = new SerializationReader(stream)) { db.OsuVersion = r.ReadInt32(); db.FolderCount = r.ReadInt32(); db.AccountUnlocked = r.ReadBoolean(); db.UnlockDate = r.ReadDateTime(); db.PlayerName = r.ReadString(); int beatmapCount = r.ReadInt32(); db.BeatmapCount = beatmapCount; for (int i = 0; i < beatmapCount; i++) { DbBeatmap beatmap = new DbBeatmap(); if (db.OsuVersion < 20191106) { beatmap.BytesOfBeatmapEntry = r.ReadInt32(); } beatmap.Artist = r.ReadString(); beatmap.ArtistUnicode = r.ReadString(); beatmap.Title = r.ReadString(); beatmap.TitleUnicode = r.ReadString(); beatmap.Creator = r.ReadString(); beatmap.Difficulty = r.ReadString(); beatmap.AudioFileName = r.ReadString(); beatmap.MD5Hash = r.ReadString(); beatmap.FileName = r.ReadString(); beatmap.RankedStatus = (RankedStatus)r.ReadByte(); beatmap.CirclesCount = r.ReadUInt16(); beatmap.SlidersCount = r.ReadUInt16(); beatmap.SpinnersCount = r.ReadUInt16(); beatmap.LastModifiedTime = r.ReadDateTime(); beatmap.ApproachRate = db.OsuVersion >= 20140609 ? r.ReadSingle() : r.ReadByte(); beatmap.CircleSize = db.OsuVersion >= 20140609 ? r.ReadSingle() : r.ReadByte(); beatmap.HPDrain = db.OsuVersion >= 20140609 ? r.ReadSingle() : r.ReadByte(); beatmap.OverallDifficulty = db.OsuVersion >= 20140609 ? r.ReadSingle() : r.ReadByte(); beatmap.SliderVelocity = r.ReadDouble(); if (db.OsuVersion >= 20140609) { beatmap.StandardStarRating = r.ReadDictionary <Mods, double>(); beatmap.TaikoStarRating = r.ReadDictionary <Mods, double>(); beatmap.CatchStarRating = r.ReadDictionary <Mods, double>(); beatmap.ManiaStarRating = r.ReadDictionary <Mods, double>(); } beatmap.DrainTime = r.ReadInt32(); beatmap.TotalTime = r.ReadInt32(); beatmap.AudioPreviewTime = r.ReadInt32(); int timingPointsCount = r.ReadInt32(); for (int j = 0; j < timingPointsCount; j++) { DbTimingPoint timingPoint = new DbTimingPoint(); timingPoint.BPM = r.ReadDouble(); timingPoint.Offset = r.ReadDouble(); timingPoint.Inherited = r.ReadBoolean(); beatmap.TimingPoints.Add(timingPoint); } beatmap.BeatmapId = r.ReadInt32(); beatmap.BeatmapSetId = r.ReadInt32(); beatmap.ThreadId = r.ReadInt32(); beatmap.StandardGrade = (Grade)r.ReadByte(); beatmap.TaikoGrade = (Grade)r.ReadByte(); beatmap.CatchGrade = (Grade)r.ReadByte(); beatmap.ManiaGrade = (Grade)r.ReadByte(); beatmap.LocalOffset = r.ReadInt16(); beatmap.StackLeniency = r.ReadSingle(); beatmap.Ruleset = (Ruleset)r.ReadByte(); beatmap.Source = r.ReadString(); beatmap.Tags = r.ReadString(); beatmap.OnlineOffset = r.ReadInt16(); beatmap.TitleFont = r.ReadString(); beatmap.IsUnplayed = r.ReadBoolean(); beatmap.LastPlayed = r.ReadDateTime(); beatmap.IsOsz2 = r.ReadBoolean(); beatmap.FolderName = r.ReadString(); beatmap.LastCheckedAgainstOsuRepo = r.ReadDateTime(); beatmap.IgnoreBeatmapSound = r.ReadBoolean(); beatmap.IgnoreBeatmapSkin = r.ReadBoolean(); beatmap.DisableStoryboard = r.ReadBoolean(); beatmap.DisableVideo = r.ReadBoolean(); beatmap.VisualOverride = r.ReadBoolean(); if (db.OsuVersion < 20140609) { r.BaseStream.Seek(sizeof(short), SeekOrigin.Current); //let's skip this unknown variable } r.BaseStream.Seek(sizeof(int), SeekOrigin.Current); //and this one beatmap.ManiaScrollSpeed = r.ReadByte(); db.Beatmaps.Add(beatmap); } db.Permissions = (Permissions)r.ReadInt32(); } return(db); }
public Score Parse(Stream stream) { var score = new Score { ScoreInfo = new ScoreInfo(), Replay = new Replay() }; using (SerializationReader sr = new SerializationReader(stream)) { currentRuleset = GetRuleset(sr.ReadByte()); score.ScoreInfo = new ScoreInfo { Ruleset = currentRuleset.RulesetInfo }; var version = sr.ReadInt32(); var workingBeatmap = GetBeatmap(sr.ReadString()); if (workingBeatmap is DummyWorkingBeatmap) { throw new BeatmapNotFoundException(); } currentBeatmap = workingBeatmap.Beatmap; score.ScoreInfo.Beatmap = currentBeatmap.BeatmapInfo; score.ScoreInfo.User = new User { Username = sr.ReadString() }; // MD5Hash sr.ReadString(); var count300 = (int)sr.ReadUInt16(); var count100 = (int)sr.ReadUInt16(); var count50 = (int)sr.ReadUInt16(); var countGeki = (int)sr.ReadUInt16(); var countKatu = (int)sr.ReadUInt16(); var countMiss = (int)sr.ReadUInt16(); switch (currentRuleset.LegacyID) { case 0: score.ScoreInfo.Statistics[HitResult.Great] = count300; score.ScoreInfo.Statistics[HitResult.Good] = count100; score.ScoreInfo.Statistics[HitResult.Meh] = count50; score.ScoreInfo.Statistics[HitResult.Miss] = countMiss; break; case 1: score.ScoreInfo.Statistics[HitResult.Great] = count300; score.ScoreInfo.Statistics[HitResult.Good] = count100; score.ScoreInfo.Statistics[HitResult.Miss] = countMiss; break; case 2: score.ScoreInfo.Statistics[HitResult.Perfect] = count300; score.ScoreInfo.Statistics[HitResult.Miss] = countMiss; break; case 3: score.ScoreInfo.Statistics[HitResult.Perfect] = countGeki; score.ScoreInfo.Statistics[HitResult.Great] = count300; score.ScoreInfo.Statistics[HitResult.Good] = countKatu; score.ScoreInfo.Statistics[HitResult.Ok] = count100; score.ScoreInfo.Statistics[HitResult.Meh] = count50; score.ScoreInfo.Statistics[HitResult.Miss] = countMiss; break; } score.ScoreInfo.TotalScore = sr.ReadInt32(); score.ScoreInfo.MaxCombo = sr.ReadUInt16(); /* score.Perfect = */ sr.ReadBoolean(); score.ScoreInfo.Mods = currentRuleset.ConvertLegacyMods((LegacyMods)sr.ReadInt32()).ToArray(); /* score.HpGraphString = */ sr.ReadString(); score.ScoreInfo.Date = sr.ReadDateTime(); var compressedReplay = sr.ReadByteArray(); if (version >= 20140721) { score.ScoreInfo.OnlineScoreID = sr.ReadInt64(); } else if (version >= 20121008) { score.ScoreInfo.OnlineScoreID = sr.ReadInt32(); } if (compressedReplay?.Length > 0) { using (var replayInStream = new MemoryStream(compressedReplay)) { byte[] properties = new byte[5]; if (replayInStream.Read(properties, 0, 5) != 5) { throw new IOException("input .lzma is too short"); } long outSize = 0; for (int i = 0; i < 8; i++) { int v = replayInStream.ReadByte(); if (v < 0) { throw new IOException("Can't Read 1"); } outSize |= (long)(byte)v << (8 * i); } long compressedSize = replayInStream.Length - replayInStream.Position; using (var lzma = new LzmaStream(properties, replayInStream, compressedSize, outSize)) using (var reader = new StreamReader(lzma)) readLegacyReplay(score.Replay, reader); } } } CalculateAccuracy(score.ScoreInfo); return(score); }
public void ReadFromStream(SerializationReader r) { Artist = r.ReadString(); if (_version >= OsuVersions.FirstOsz2) { ArtistUnicode = r.ReadString(); } Title = r.ReadString(); if (_version >= OsuVersions.FirstOsz2) { TitleUnicode = r.ReadString(); } Creator = r.ReadString(); Version = r.ReadString(); AudioFileName = r.ReadString(); BeatmapChecksum = r.ReadString(); //always 32 in length, so the 2 preceding bytes in the file are practically wasting space BeatmapFileName = r.ReadString(); RankedStatus = (SubmissionStatus)r.ReadByte(); CountHitCircles = r.ReadUInt16(); CountSliders = r.ReadUInt16(); CountSpinners = r.ReadUInt16(); LastModifiedTime = r.ReadDateTime(); if (_version >= OsuVersions.FloatDifficultyValues) { ApproachRate = r.ReadSingle(); CircleSize = r.ReadSingle(); HPDrainRate = r.ReadSingle(); OveralDifficulty = r.ReadSingle(); } else { ApproachRate = r.ReadByte(); CircleSize = r.ReadByte(); HPDrainRate = r.ReadByte(); OveralDifficulty = r.ReadByte(); } SliderVelocity = r.ReadDouble(); if (_version >= OsuVersions.FloatDifficultyValues) { DiffStarRatingStandard = r.ReadDictionary <Mods, double>(); DiffStarRatingTaiko = r.ReadDictionary <Mods, double>(); DiffStarRatingCtB = r.ReadDictionary <Mods, double>(); DiffStarRatingMania = r.ReadDictionary <Mods, double>(); // TODO: there may be different reading behavior for versions before 20190204, 20200916, 20200504 and 20191024 here. } DrainTimeSeconds = r.ReadInt32(); TotalTime = r.ReadInt32(); AudioPreviewTime = r.ReadInt32(); TimingPoints = r.ReadSerializableList <TimingPoint>(); BeatmapId = r.ReadInt32(); BeatmapSetId = r.ReadInt32(); ThreadId = r.ReadInt32(); GradeStandard = (Ranking)r.ReadByte(); GradeTaiko = (Ranking)r.ReadByte(); GradeCtB = (Ranking)r.ReadByte(); GradeMania = (Ranking)r.ReadByte(); OffsetLocal = r.ReadInt16(); StackLeniency = r.ReadSingle(); GameMode = (GameMode)r.ReadByte(); SongSource = r.ReadString(); SongTags = r.ReadString(); OffsetOnline = r.ReadInt16(); TitleFont = r.ReadString(); Unplayed = r.ReadBoolean(); LastPlayed = r.ReadDateTime(); IsOsz2 = r.ReadBoolean(); FolderName = r.ReadString(); LastCheckAgainstOsuRepo = r.ReadDateTime(); IgnoreBeatmapSounds = r.ReadBoolean(); IgnoreBeatmapSkin = r.ReadBoolean(); DisableStoryBoard = r.ReadBoolean(); DisableVideo = r.ReadBoolean(); VisualOverride = r.ReadBoolean(); if (_version < OsuVersions.FloatDifficultyValues) { OldUnknown1 = r.ReadInt16(); } LastEditTime = r.ReadInt32(); ManiaScrollSpeed = r.ReadByte(); }
public static MarketOrder DeserializeOrder(SerializationReader reader) { var deal = new MarketOrder { ID = reader.ReadInt32(), AccountID = reader.ReadInt32(), Comment = reader.ReadString(), ExitReason = (PositionExitReason)reader.ReadInt16(), ExpertComment = reader.ReadString(), PriceEnter = reader.ReadSingle(), ResultDepo = reader.ReadSingle(), ResultPoints = reader.ReadSingle(), Side = reader.ReadSByte(), State = (PositionState)reader.ReadInt16(), Symbol = reader.ReadString(), TimeEnter = reader.ReadDateTime(), Trailing = reader.ReadString(), Volume = reader.ReadInt32(), VolumeInDepoCurrency = reader.ReadSingle() }; // nullable values var flags = reader.ReadOptimizedBitVector32(); if (flags[magicIsValued]) { deal.Magic = reader.ReadInt32(); } if (flags[pendingOrderIdIsValued]) { deal.PendingOrderID = reader.ReadInt32(); } if (flags[priceBestIsValued]) { deal.PriceBest = reader.ReadSingle(); } if (flags[priceExitIsValued]) { deal.PriceExit = reader.ReadSingle(); } if (flags[priceWorstIsValued]) { deal.PriceWorst = reader.ReadSingle(); } if (flags[stopLossIsValued]) { deal.StopLoss = reader.ReadSingle(); } if (flags[swapIsValued]) { deal.Swap = reader.ReadSingle(); } if (flags[takeProfitIsValued]) { deal.TakeProfit = reader.ReadSingle(); } if (flags[timeExitIsValued]) { deal.TimeExit = reader.ReadDateTime(); } return(deal); }
public Score Parse(Stream stream) { Score score; using (SerializationReader sr = new SerializationReader(stream)) { score = new Score { Ruleset = rulesets.GetRuleset(sr.ReadByte()) }; currentRuleset = score.Ruleset.CreateInstance(); /* score.Pass = true;*/ var version = sr.ReadInt32(); /* score.FileChecksum = */ var beatmapHash = sr.ReadString(); score.Beatmap = beatmaps.QueryBeatmap(b => b.MD5Hash == beatmapHash); currentBeatmap = beatmaps.GetWorkingBeatmap(score.Beatmap).Beatmap; /* score.PlayerName = */ score.User = new User { Username = sr.ReadString() }; /* var localScoreChecksum = */ sr.ReadString(); /* score.Count300 = */ sr.ReadUInt16(); /* score.Count100 = */ sr.ReadUInt16(); /* score.Count50 = */ sr.ReadUInt16(); /* score.CountGeki = */ sr.ReadUInt16(); /* score.CountKatu = */ sr.ReadUInt16(); /* score.CountMiss = */ sr.ReadUInt16(); score.TotalScore = sr.ReadInt32(); score.MaxCombo = sr.ReadUInt16(); /* score.Perfect = */ sr.ReadBoolean(); /* score.EnabledMods = (Mods)*/ score.Mods = currentRuleset.ConvertLegacyMods((LegacyMods)sr.ReadInt32()).ToArray(); /* score.HpGraphString = */ sr.ReadString(); /* score.Date = */ sr.ReadDateTime(); var compressedReplay = sr.ReadByteArray(); if (version >= 20140721) { /*OnlineId =*/ sr.ReadInt64(); } else if (version >= 20121008) { /*OnlineId =*/ sr.ReadInt32(); } using (var replayInStream = new MemoryStream(compressedReplay)) { byte[] properties = new byte[5]; if (replayInStream.Read(properties, 0, 5) != 5) { throw new IOException("input .lzma is too short"); } long outSize = 0; for (int i = 0; i < 8; i++) { int v = replayInStream.ReadByte(); if (v < 0) { throw new IOException("Can't Read 1"); } outSize |= (long)(byte)v << (8 * i); } long compressedSize = replayInStream.Length - replayInStream.Position; using (var lzma = new LzmaStream(properties, replayInStream, compressedSize, outSize)) using (var reader = new StreamReader(lzma)) { score.Replay = new Replay { User = score.User }; readLegacyReplay(score.Replay, reader); } } } return(score); }
protected virtual void SetObjectData(SerializationReader sr) { f_TimeStamp = sr.ReadDateTime(); f_MessageParts = sr.ReadList<MessagePartModel>(); f_MessageType = (MessageType) sr.ReadInt32(); // backward compatibility with engines < 1.1 if (sr.PeekChar() != -1) { ID = sr.ReadString(); } }
public void ReadFromStream(SerializationReader r) { int length = 0; if (_readLength) { length = r.ReadInt32(); } int startPosition = (int)r.BaseStream.Position; Artist = r.ReadString(); ArtistUnicode = r.ReadString(); Title = r.ReadString(); TitleUnicode = r.ReadString(); Creator = r.ReadString(); Version = r.ReadString(); AudioFileName = r.ReadString(); BeatmapChecksum = r.ReadString(); //always 32 in length, so the 2 preceding bytes in the file are practically wasting space BeatmapFileName = r.ReadString(); RankedStatus = (SubmissionStatus)r.ReadByte(); CountHitCircles = r.ReadUInt16(); CountSliders = r.ReadUInt16(); CountSpinners = r.ReadUInt16(); LastModifiedTime = r.ReadDateTime(); if (_version >= 20140609) { ApproachRate = r.ReadSingle(); CircleSize = r.ReadSingle(); HPDrainRate = r.ReadSingle(); OveralDifficulty = r.ReadSingle(); } else { ApproachRate = r.ReadByte(); CircleSize = r.ReadByte(); HPDrainRate = r.ReadByte(); OveralDifficulty = r.ReadByte(); } SliderVelocity = r.ReadDouble(); if (_version >= 20140609) { DiffStarRatingStandard = r.ReadDictionary <Mods, double>(); DiffStarRatingTaiko = r.ReadDictionary <Mods, double>(); DiffStarRatingCtB = r.ReadDictionary <Mods, double>(); DiffStarRatingMania = r.ReadDictionary <Mods, double>(); } DrainTimeSeconds = r.ReadInt32(); TotalTime = r.ReadInt32(); AudioPreviewTime = r.ReadInt32(); TimingPoints = r.ReadSerializableList <TimingPoint>(); BeatmapId = r.ReadInt32(); BeatmapSetId = r.ReadInt32(); ThreadId = r.ReadInt32(); GradeStandard = (Ranking)r.ReadByte(); GradeTaiko = (Ranking)r.ReadByte(); GradeCtB = (Ranking)r.ReadByte(); GradeMania = (Ranking)r.ReadByte(); OffsetLocal = r.ReadInt16(); StackLeniency = r.ReadSingle(); GameMode = (GameMode)r.ReadByte(); SongSource = r.ReadString(); SongTags = r.ReadString(); OffsetOnline = r.ReadInt16(); TitleFont = r.ReadString(); Unplayed = r.ReadBoolean(); LastPlayed = r.ReadDateTime(); IsOsz2 = r.ReadBoolean(); FolderName = r.ReadString(); LastCheckAgainstOsuRepo = r.ReadDateTime(); IgnoreBeatmapSounds = r.ReadBoolean(); IgnoreBeatmapSkin = r.ReadBoolean(); DisableStoryBoard = r.ReadBoolean(); DisableVideo = r.ReadBoolean(); VisualOverride = r.ReadBoolean(); if (_version < 20140609) { OldUnknown1 = r.ReadInt16(); } Unknown2 = r.ReadInt32(); ManiaScrollSpeed = r.ReadByte(); Debug.Assert(!_readLength || length == r.BaseStream.Position - startPosition); //could throw error here }
public Score ReadReplayFile(string replayFilename) { Score score; using (Stream s = storage.GetStream(Path.Combine(replay_folder, replayFilename))) using (SerializationReader sr = new SerializationReader(s)) { var ruleset = Ruleset.GetRuleset((PlayMode)sr.ReadByte()); var processor = ruleset.CreateScoreProcessor(); score = processor.GetScore(); /* score.Pass = true;*/ var version = sr.ReadInt32(); /* score.FileChecksum = */ var beatmapHash = sr.ReadString(); score.Beatmap = beatmaps.Query <BeatmapInfo>().Where(b => b.Hash == beatmapHash).FirstOrDefault(); /* score.PlayerName = */ sr.ReadString(); /* var localScoreChecksum = */ sr.ReadString(); /* score.Count300 = */ sr.ReadUInt16(); /* score.Count100 = */ sr.ReadUInt16(); /* score.Count50 = */ sr.ReadUInt16(); /* score.CountGeki = */ sr.ReadUInt16(); /* score.CountKatu = */ sr.ReadUInt16(); /* score.CountMiss = */ sr.ReadUInt16(); score.TotalScore = sr.ReadInt32(); score.MaxCombo = sr.ReadUInt16(); /* score.Perfect = */ sr.ReadBoolean(); /* score.EnabledMods = (Mods)*/ sr.ReadInt32(); /* score.HpGraphString = */ sr.ReadString(); /* score.Date = */ sr.ReadDateTime(); var compressedReplay = sr.ReadByteArray(); if (version >= 20140721) { /*OnlineId =*/ sr.ReadInt64(); } else if (version >= 20121008) { /*OnlineId =*/ sr.ReadInt32(); } using (var replayInStream = new MemoryStream(compressedReplay)) { byte[] properties = new byte[5]; if (replayInStream.Read(properties, 0, 5) != 5) { throw (new Exception("input .lzma is too short")); } long outSize = 0; for (int i = 0; i < 8; i++) { int v = replayInStream.ReadByte(); if (v < 0) { throw (new Exception("Can't Read 1")); } outSize |= ((long)(byte)v) << (8 * i); } long compressedSize = replayInStream.Length - replayInStream.Position; using (var lzma = new LzmaStream(properties, replayInStream, compressedSize, outSize)) using (var reader = new StreamReader(lzma)) score.Replay = new LegacyReplay(reader); } } return(score); }
protected virtual void SetObjectData(SerializationReader sr) { f_TimeStamp = sr.ReadDateTime(); f_MessageParts = sr.ReadList <MessagePartModel>(); f_MessageType = (MessageType)sr.ReadInt32(); }
protected virtual void SetObjectData(SerializationReader sr) { f_TimeStamp = sr.ReadDateTime(); f_MessageParts = sr.ReadList<MessagePartModel>(); f_MessageType = (MessageType) sr.ReadInt32(); }
public Score Parse(Stream stream) { Score score; using (SerializationReader sr = new SerializationReader(stream)) { currentRuleset = GetRuleset(sr.ReadByte()); score = new Score { Ruleset = currentRuleset.RulesetInfo }; /* score.Pass = true;*/ var version = sr.ReadInt32(); /* score.FileChecksum = */ currentBeatmap = GetBeatmap(sr.ReadString()).Beatmap; score.Beatmap = currentBeatmap.BeatmapInfo; /* score.PlayerName = */ score.User = new User { Username = sr.ReadString() }; /* var localScoreChecksum = */ sr.ReadString(); var count300 = sr.ReadUInt16(); var count100 = sr.ReadUInt16(); var count50 = sr.ReadUInt16(); var countGeki = sr.ReadUInt16(); var countKatu = sr.ReadUInt16(); var countMiss = sr.ReadUInt16(); score.Statistics[HitResult.Great] = count300; score.Statistics[HitResult.Good] = count100; score.Statistics[HitResult.Meh] = count50; score.Statistics[HitResult.Perfect] = countGeki; score.Statistics[HitResult.Ok] = countKatu; score.Statistics[HitResult.Miss] = countMiss; score.TotalScore = sr.ReadInt32(); score.MaxCombo = sr.ReadUInt16(); /* score.Perfect = */ sr.ReadBoolean(); /* score.EnabledMods = (Mods)*/ score.Mods = currentRuleset.ConvertLegacyMods((LegacyMods)sr.ReadInt32()).ToArray(); /* score.HpGraphString = */ sr.ReadString(); /* score.Date = */ sr.ReadDateTime(); var compressedReplay = sr.ReadByteArray(); if (version >= 20140721) { /*OnlineId =*/ sr.ReadInt64(); } else if (version >= 20121008) { /*OnlineId =*/ sr.ReadInt32(); } switch (score.Ruleset.ID) { case 0: { int totalHits = count50 + count100 + count300 + countMiss; score.Accuracy = totalHits > 0 ? (double)(count50 * 50 + count100 * 100 + count300 * 300) / (totalHits * 300) : 1; break; } case 1: { int totalHits = count50 + count100 + count300 + countMiss; score.Accuracy = totalHits > 0 ? (double)(count100 * 150 + count300 * 300) / (totalHits * 300) : 1; break; } case 2: { int totalHits = count50 + count100 + count300 + countMiss + countKatu; score.Accuracy = totalHits > 0 ? (double)(count50 + count100 + count300) / totalHits : 1; break; } case 3: { int totalHits = count50 + count100 + count300 + countMiss + countGeki + countKatu; score.Accuracy = totalHits > 0 ? (double)(count50 * 50 + count100 * 100 + countKatu * 200 + (count300 + countGeki) * 300) / (totalHits * 300) : 1; break; } } using (var replayInStream = new MemoryStream(compressedReplay)) { byte[] properties = new byte[5]; if (replayInStream.Read(properties, 0, 5) != 5) { throw new IOException("input .lzma is too short"); } long outSize = 0; for (int i = 0; i < 8; i++) { int v = replayInStream.ReadByte(); if (v < 0) { throw new IOException("Can't Read 1"); } outSize |= (long)(byte)v << (8 * i); } long compressedSize = replayInStream.Length - replayInStream.Position; using (var lzma = new LzmaStream(properties, replayInStream, compressedSize, outSize)) using (var reader = new StreamReader(lzma)) { score.Replay = new Replay { User = score.User }; readLegacyReplay(score.Replay, reader); } } } return(score); }