public void Deserialize(byte[] mySerializedBytes)
            {
                var reader = new SerializationReader(mySerializedBytes);

                ObjectLocation = reader.ReadString();
                RightUUID       = new UUID(reader.ReadByteArray());
                EntitiyUUID     = new UUID(reader.ReadByteArray());
            }
 public void Deserialize(byte[] mySerializedBytes)
 {
     var _SerializationReader    = new SerializationReader(mySerializedBytes);
     FailedCopy                  = _SerializationReader.ReadInt32();
     MaxNumberOfCopies           = _SerializationReader.ReadInt32();
     SerializedObjectStream      = _SerializationReader.ReadByteArray();
 }
Esempio n. 3
0
        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");
            }
        }
Esempio n. 4
0
 public void ReadFromStream(SerializationReader sr)
 {
     Filename     = sr.ReadString();
     Length       = sr.ReadInt32();
     Offset       = sr.ReadInt32();
     Hash         = sr.ReadByteArray();
     CreationTime = (DateTime)sr.ReadObject();
     ModifiedTime = (DateTime)sr.ReadObject();
 }
Esempio n. 5
0
        public void ReadFromStream(SerializationReader sr)
        {
            if (sr.BaseStream.Position == 1)
            {
                ReadHeaderFromStream(sr);
            }

            ReplayCompressed = sr.ReadByteArray();

            if (Version >= 20140721)
            {
                OnlineId = sr.ReadInt64();
            }
            else if (Version >= General.VERSION_FIRST_OSZ2)
            {
                OnlineId = sr.ReadInt32();
            }

            ReadModSpecificData(sr);
        }
Esempio n. 6
0
        public static Replay Parse(Stream stream)
        {
            using var sr = new SerializationReader(stream);
            var replay = new Replay();

            replay.PlayMode = (PlayMode)sr.ReadByte();
            sr.ReadInt32(); // Version

            replay.BeatmapChecksum = sr.ReadString();
            replay.Username        = sr.ReadString();

            sr.ReadString(); // Replay Checksum

            replay.Count300  = sr.ReadUInt16();
            replay.Count100  = sr.ReadUInt16();
            replay.Count50   = sr.ReadUInt16();
            replay.CountGeki = sr.ReadUInt16();
            replay.CountKatu = sr.ReadUInt16();
            replay.CountMiss = sr.ReadUInt16();

            replay.TotalScore = sr.ReadInt32();
            replay.MaxCombo   = sr.ReadUInt16();

            sr.ReadBoolean(); // Perfect

            replay.Mods = (Mods)sr.ReadInt32();

            sr.ReadString();    // HpGraph
            sr.ReadInt64();     // Date
            sr.ReadByteArray(); // Replay Data

            sr.ReadInt64();     // OnlineID, i guess we don't need check 2012-2014 clients

            // TODO: replay data parsing (i do it when will make anticheat)

            return(replay);
        }
        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);
        }
Esempio n. 8
0
        private object Deserialize(ref SerializationReader mySerializationReader, DirectoryEntry myDirectoryEntry)
        {
            try
            {

                #region Read the Inlinedata

                myDirectoryEntry._InlineData = mySerializationReader.ReadByteArray();

                #region Estimated Size

                if (myDirectoryEntry._InlineData != null)
                {
                    myDirectoryEntry._estimatedSize += Convert.ToUInt64(myDirectoryEntry._InlineData.Length) * EstimatedSizeConstants.Byte;
                }

                #endregion

                #endregion

                #region Read the INodePositions

                #region Estimated Size

                myDirectoryEntry._estimatedSize += EstimatedSizeConstants.HashSet;

                #endregion

                var _NumOfINodePositions = mySerializationReader.ReadUInt32();

                if (_NumOfINodePositions > 0)
                {
                    for (var j = 0UL; j < _NumOfINodePositions; j++)
                    {
                        StorageUUID ID = new StorageUUID();
                        ID.Deserialize(ref mySerializationReader);
                        myDirectoryEntry._INodePositions.Add(new ExtendedPosition(ID, mySerializationReader.ReadUInt64()));

                        #region Estimated Size

                        myDirectoryEntry._estimatedSize += EstimatedSizeConstants.ExtendedPosition;

                        #endregion

                    }
                }

                #endregion

                #region Read the ObjectStreamsList

                #region Estimated Size

                myDirectoryEntry._estimatedSize += EstimatedSizeConstants.HashSet;

                #endregion

                var _NumberOfObjectStreamTypes = mySerializationReader.ReadUInt32();

                if (_NumberOfObjectStreamTypes > 0)
                {
                    for (var j = 0UL; j < _NumberOfObjectStreamTypes; j++)
                    {
                        myDirectoryEntry._ObjectStreamsList.Add(mySerializationReader.ReadString());

                        #region Estimated Size

                        myDirectoryEntry._estimatedSize += EstimatedSizeConstants.Char * EstimatedSizeConstants.EstimatedObjectStreamNameLength;

                        #endregion

                    }
                }

                #endregion

            }

            catch (GraphFSException e)
            {
                throw new GraphFSException("DirectoryEntry could not be deserialized!\n\n" + e);
            }

            myDirectoryEntry.isDirty = true;

            return myDirectoryEntry;
        }
Esempio n. 9
0
        public void Deserialize(Byte[] mySerializedData, IIntegrityCheck myIntegrityCheckAlgorithm, ISymmetricEncryption myEncryptionAlgorithm)
        {
            #region Data

            Byte[]  IntegrityCheckValue;
            int     IntegrityCheckValue_Length;
            Int64   IntegrityCheckValue_Position;
            Byte[]  actualIntegrityCheckValue;

            Byte[]  EncryptionParameters;
            int     EncryptionParameters_Length;

            int     DataPadding_Length;
            int     AdditionalPadding_Length = 0;

            #endregion

            #region Check if data is larger than the minimum allowed size

            if (mySerializedData == null)
                throw new GraphFSException_InvalidInformationHeader("The information header is invalid!");

            if (mySerializedData.Length < 8)
                throw new GraphFSException_InvalidInformationHeader("The information header is invalid!");

            #endregion

            try
            {

                #region Init reader

                var reader = new SerializationReader(mySerializedData);

                #endregion

                #region Read HeaderVersion

                var _HeaderVersion = reader.ReadByte();

                #endregion

                #region Read Length of the Integrity Check Value

                // Multiply the value of the first byte with 8
                IntegrityCheckValue_Length = reader.ReadByte() << 3;

                if (IntegrityCheckValue_Length > mySerializedData.Length - HeaderLength)
                    throw new GraphFSException_InvalidIntegrityCheckLengthField("The length of the integrity check value is invalid!");

                // HACK: Remeber that a IntegrityCheckValue of 0 will circumvent the whole integrity checking!
                if (myIntegrityCheckAlgorithm != null)
                    if ((IntegrityCheckValue_Length > 0) && (IntegrityCheckValue_Length != myIntegrityCheckAlgorithm.HashSize))
                        throw new GraphFSException_InvalidIntegrityCheckLengthField("The length of the integrity check value is " + IntegrityCheckValue_Length + ", but " + myIntegrityCheckAlgorithm.HashSize + " was expected!");

                #endregion

                #region Read Length of the Encryption Parameters

                // Multiply the value of the second byte with 8
                EncryptionParameters_Length = reader.ReadByte() << 3;

                if (EncryptionParameters_Length > mySerializedData.Length - HeaderLength - IntegrityCheckValue_Length)
                    throw new GraphFSException_InvalidEncryptionParametersLengthField("The length of the encryption parameters is invalid!");

                #endregion

                #region Read Padding lengths

                DataPadding_Length        = (Int32) reader.ReadByte();
                AdditionalPadding_Length  = (Int32) (256 * reader.ReadByte() + reader.ReadByte()) << 3;

                if ((HeaderLength + IntegrityCheckValue_Length + EncryptionParameters_Length + AdditionalPadding_Length) >= mySerializedData.Length)
                    throw new GraphFSException_InvalidAdditionalPaddingLengthField("The length of the additional padding is invalid!");

                reader.ReadBytesDirect(2);  // Read reserved bytes

                #endregion

                #region Read Integrity Check Value and Encryption Parameters

                IntegrityCheckValue_Position = reader.BaseStream.Position;

                if (IntegrityCheckValue_Length > 0)
                    IntegrityCheckValue = reader.ReadBytesDirect(IntegrityCheckValue_Length);

                if (EncryptionParameters_Length > 0)
                    EncryptionParameters = reader.ReadBytesDirect(EncryptionParameters_Length);

                #endregion

                #region Verify the integrity of the data

                if (myIntegrityCheckAlgorithm != null && IntegrityCheckValue_Length > 0)
                {

                    // Save the read IntegrityCheckValue
                    IntegrityCheckValue = new Byte[IntegrityCheckValue_Length];
                    Array.Copy(mySerializedData, IntegrityCheckValue_Position, IntegrityCheckValue, 0, IntegrityCheckValue_Length);

                    // Zero the IntegrityCheckValue within the serialized data
                    var AllZeros = new Byte[IntegrityCheckValue_Length];
                    Array.Copy(AllZeros, 0, mySerializedData, IntegrityCheckValue_Position, IntegrityCheckValue_Length);

                    // Calculate the actual IntegrityCheckValue
                    actualIntegrityCheckValue = myIntegrityCheckAlgorithm.GetHashValueAsByteArray(mySerializedData);

                    // Compare read and actual IntegrityCheckValue
                    if (IntegrityCheckValue.CompareByteArray(actualIntegrityCheckValue) != 0)
                        throw new GraphFSException_IntegrityCheckFailed(String.Concat("The IntegrityCheck failed as ", actualIntegrityCheckValue.ToHexString(), " is not equal to the expected ", IntegrityCheckValue.ToHexString()));

                }

                #endregion

                #region Decrypt the remaining data

                //EncryptedData_Length      = (UInt64) (mySerializedData.Length - (HeaderLength + IntegrityCheckValue_Length + EncryptionParameters_Length + AdditionalPadding_Length));
                //EncryptedData             = new Byte[EncryptedData_Length];
                //Array.Copy(mySerializedData, HeaderLength + IntegrityCheckValue_Length + EncryptionParameters_Length, EncryptedData, 0, (Int64) EncryptedData_Length);

                //#endregion

                //#region Decrypt Data

                // Decrypt Data, sooon...!

                //if ( (UInt64) DataPadding_Length >= EncryptedData_Length)
                //    throw new GraphFSException_InvalidDataPaddingLengthField("The length of the data padding is invalid!");

                //DecryptedData = new Byte[EncryptedData_Length - (UInt64) DataPadding_Length];
                //Array.Copy(EncryptedData, 0, DecryptedData, 0, (Int64) (EncryptedData_Length - (UInt64) DataPadding_Length));

                #endregion

                #region Deserialize Inner Object

                _StructureVersion       = BitConverter.ToUInt16(reader.ReadBytesDirect(2), 0);
                ObjectUUID              = new ObjectUUID(reader.ReadByteArray());   // n or at least 16 Bytes

                Deserialize(ref reader);

                #endregion

            }

            catch (GraphFSException_IntegrityCheckFailed e)
            {
                throw new GraphFSException_IntegrityCheckFailed("The AGraphStructure could not be deserialized as its integrity is corrupted!\n\n" + e);
            }

            catch (Exception e)
            {
                throw new GraphFSException_AGraphStructureCouldNotBeDeserialized("The AGraphStructure could not be deserialized!\n\n" + e);
            }

            _SerializedAGraphStructure = mySerializedData;
            _EstimatedSize               = (UInt64) _SerializedAGraphStructure.LongLength;
        }
Esempio n. 10
0
        public override void Deserialize(ref SerializationReader mySerializationReader)
        {
            try
            {

                //var _count = mySerializationReader.BaseStream.Length - mySerializationReader.BaseStream.Position;
                //_ObjectData = new Byte[_count];

                //var b = mySerializationReader.BaseStream.Read(_ObjectData, 0, (int)_count);

                _ContentType = mySerializationReader.ReadString();
                _ObjectData  = mySerializationReader.ReadByteArray();

            }

            catch (Exception e)
            {
                throw new GraphFSException_FileObjectCouldNotBeDeserialized("The FileObject could not be deserialized!\n\n" + e);
            }
        }
Esempio n. 11
0
        private object Deserialize(ref SerializationReader mySerializationReader, DirectoryEntry myDirectoryEntry)
        {
            try
            {

                #region Read the Inlinedata

                myDirectoryEntry._InlineData = mySerializationReader.ReadByteArray();

                #endregion

                #region Read the INodePositions

                var _NumOfINodePositions = mySerializationReader.ReadUInt32();

                if (_NumOfINodePositions > 0)
                {
                    for (var j = 0UL; j < _NumOfINodePositions; j++)
                    {
                        StorageUUID ID = new StorageUUID();
                        ID.Deserialize(ref mySerializationReader);
                        myDirectoryEntry._INodePositions.Add(new ExtendedPosition(ID, mySerializationReader.ReadUInt64()));
                    }
                }

                #endregion

                #region Read the ObjectStreamsList

                var _NumberOfObjectStreamTypes = mySerializationReader.ReadUInt32();

                if (_NumberOfObjectStreamTypes > 0)
                {
                    for (var j = 0UL; j < _NumberOfObjectStreamTypes; j++)
                        myDirectoryEntry._ObjectStreamsList.Add(mySerializationReader.ReadString());
                }

                #endregion

            }

            catch (GraphFSException e)
            {
                throw new GraphFSException("DirectoryEntry could not be deserialized!\n\n" + e);
            }

            myDirectoryEntry.isDirty = true;

            return myDirectoryEntry;
        }
Esempio n. 12
0
        public void Deserialize(byte[] mySerializedData)
        {
            #region Data
            SerializationReader reader;

            reader = new SerializationReader(mySerializedData);

            #endregion

            #region Read Basics
            try
            {
                Name                = reader.ReadString();
                Description         = reader.ReadString();
                OwnerID             = new EntityUUID(reader.ReadByteArray());
                Type                = new TypeUUID(reader.ReadByteArray());
                Default.SetValue(reader.ReadObject());
                _Value.SetValue(reader.ReadObject());
            }
            catch (Exception e)
            {
                throw new GraphFSException_EntityCouldNotBeDeserialized("ADBSetting could not be deserialized!\n\n" + e);
            }
            #endregion
        }
Esempio n. 13
0
        public override void Deserialize(ref SerializationReader mySerializationReader)
        {
            UInt16 NumberOfObjectLocatorPositions;
            UInt16 NumberOfINodePositions;

            try
            {

                #region Read Common attributes

                _CreationTime                   =           mySerializationReader.ReadUInt64();
                _LastModificationTime           =           mySerializationReader.ReadUInt64();
                _LastAccessTime                 =           mySerializationReader.ReadUInt64();
                _DeletionTime                   =           mySerializationReader.ReadUInt64();
                _ObjectSize                     =           mySerializationReader.ReadUInt64();

                #endregion

                #region Object Safety and Security

                _IntegrityCheckAlgorithm        =           (IntegrityCheckTypes)mySerializationReader.ReadOptimizedByte();
                _EncryptionAlgorithm            =           (SymmetricEncryptionTypes)mySerializationReader.ReadOptimizedByte();

                #endregion

                #region Read list of ObjectLocatorPositions

                _ObjectLocatorLength            =           mySerializationReader.ReadUInt64();
                _ObjectLocatorCopies            =           mySerializationReader.ReadUInt64();

                NumberOfObjectLocatorPositions  =           mySerializationReader.ReadUInt16();
                _ObjectLocatorPositions         =           new List<ExtendedPosition>();

                for (int i = 1; i <= NumberOfObjectLocatorPositions; i++)
                    _ObjectLocatorPositions.Add(new ExtendedPosition(new StorageUUID(mySerializationReader.ReadByteArray()), mySerializationReader.ReadUInt64()));

                #endregion

                #region Read list of INodePositions

                NumberOfINodePositions          =           mySerializationReader.ReadUInt16();
                _INodePositions                 =           new List<ExtendedPosition>();

                for (int i = 1; i <= NumberOfINodePositions; i++)
                    _INodePositions.Add(new ExtendedPosition(new StorageUUID(mySerializationReader.ReadByteArray()), mySerializationReader.ReadUInt64()));

                #endregion

                #region Read State

                _ObjectLocatorStates = (ObjectLocatorStates)mySerializationReader.ReadOptimizedByte();

                #endregion

            }

            catch (Exception e)
            {
                throw new GraphFSException_INodeCouldNotBeDeserialized("INode could not be deserialized!\n\n" + e);
            }

            //isDirty = true;       // this is not useful!
        }
Esempio n. 14
0
        public override void Deserialize(ref SerializationReader mySerializationReader)
        {
            #region Data

            UInt64               _NumberOfACLs;
            RightUUID            _RightUUID;
            EntityUUID           _EntityUUID;
            UInt64               _NumberOfEntityUUIDs;
            HashSet<EntityUUID>  _EntityUUIDHashSet;

            #endregion

            try
            {

                #region NotificationHandling

                _NotificationHandling = (NHAccessControlObject)mySerializationReader.ReadOptimizedByte();

                #endregion

                #region DefaultRule

                _DefaultRule = (DefaultRuleTypes)mySerializationReader.ReadOptimizedByte();

                #endregion

                #region AllowACL

                _AllowACL = new Dictionary<RightUUID, HashSet<EntityUUID>>();

                _NumberOfACLs = mySerializationReader.ReadUInt64();

                for (UInt64 i=0; i<_NumberOfACLs; i++)
                {

                    #region KEY

                    _RightUUID = new RightUUID(mySerializationReader.ReadByteArray());

                    #endregion

                    #region VALUE

                    _EntityUUIDHashSet = new HashSet<EntityUUID>();

                    _NumberOfEntityUUIDs = mySerializationReader.ReadUInt64();

                    for (UInt64 j=0; j<_NumberOfEntityUUIDs; j++)
                    {
                        _EntityUUID = new EntityUUID(mySerializationReader.ReadByteArray());
                        _EntityUUIDHashSet.Add(_EntityUUID);
                    }

                    // Finally... add it to the AllowACL!
                    _AllowACL.Add(_RightUUID, _EntityUUIDHashSet);

                    #endregion

                }

                #endregion

                #region DenyACL

                _DenyACL = new Dictionary<RightUUID, HashSet<EntityUUID>>();

                _NumberOfACLs = mySerializationReader.ReadUInt64();

                for (UInt64 i=0; i<_NumberOfACLs; i++)
                {

                    #region KEY

                    _RightUUID = new RightUUID(mySerializationReader.ReadByteArray());

                    #endregion

                    #region VALUE

                    _EntityUUIDHashSet = new HashSet<EntityUUID>();

                    _NumberOfEntityUUIDs = mySerializationReader.ReadUInt64();

                    for (UInt64 j=0; j<_NumberOfEntityUUIDs; j++)
                    {
                        _EntityUUID = new EntityUUID(mySerializationReader.ReadByteArray());
                        _EntityUUIDHashSet.Add(_EntityUUID);
                    }

                    // Finally... add it to the DenyACL!
                    _DenyACL.Add(_RightUUID, _EntityUUIDHashSet);

                    #endregion

                }

                #endregion

            }

            catch (Exception e)
            {
                throw new GraphFSException_AccessControlObjectCouldNotBeDeserialized("AccessControlObject could not be deserialized!\n\n" + e);
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
        public override void Deserialize(ref SerializationReader mySerializationReader)
        {
            mySerializationReader.CheckNull("mySerializationReader");

            _IPAddress = new System.Net.IPAddress(mySerializationReader.ReadByteArray());
        }
Esempio n. 18
0
        private object Deserialize(ref SerializationReader mySerializationReader, ADBSettingsBase myValue)
        {
            #region Read Basics

            try
            {
                if (myValue != null)
                {
                    myValue.Name = mySerializationReader.ReadString();
                    myValue.Description = mySerializationReader.ReadString();
                    myValue.OwnerID = (EntityUUID)mySerializationReader.ReadObject();
                    myValue.Type = new TypeUUID(mySerializationReader.ReadByteArray());
                    myValue.Default.SetValue(mySerializationReader.ReadObject());
                    myValue._Value.SetValue(mySerializationReader.ReadObject());
                }
                else
                {
                    Name = mySerializationReader.ReadString();
                    Description = mySerializationReader.ReadString();
                    OwnerID = (EntityUUID)mySerializationReader.ReadObject();
                    Type = new TypeUUID(mySerializationReader.ReadByteArray());
                    Default.SetValue(mySerializationReader.ReadObject());
                    _Value.SetValue(mySerializationReader.ReadObject());
                }
            }
            catch (Exception e)
            {
                throw new GraphFSException_EntityCouldNotBeDeserialized("ADBSetting could not be deserialized!\n\n" + e);
            }

            #endregion
            return myValue;
        }
Esempio n. 19
0
        public override void Deserialize(ref SerializationReader mySerializationReader)
        {
            mySerializationReader.CheckNull("mySerializationReader");

            _IPAddress = new System.Net.IPAddress(mySerializationReader.ReadByteArray());
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        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);
        }