Exemplo n.º 1
0
        private static TimeSpan ReadDurationFallback(ProtoReader source, ref ProtoReader.State state)
        {
            long         seconds = 0;
            int          nanos   = 0;
            SubItemToken token   = ProtoReader.StartSubItem(source, ref state);
            int          fieldNumber;

            while ((fieldNumber = source.ReadFieldHeader(ref state)) > 0)
            {
                switch (fieldNumber)
                {
                case 1:
                    seconds = source.ReadInt64(ref state);
                    break;

                case 2:
                    nanos = source.ReadInt32(ref state);
                    break;

                default:
                    source.SkipField(ref state);
                    break;
                }
            }
            ProtoReader.EndSubItem(token, source, ref state);
            return(FromDurationSeconds(seconds, nanos));
        }
Exemplo n.º 2
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            SubItemToken  token = ProtoReader.StartSubItem(source);
            int           fieldNumber;
            TimeSpanScale scale = TimeSpanScale.Days;
            long          value = 0;

            while ((fieldNumber = source.ReadFieldHeader()) > 0)
            {
                switch (fieldNumber)
                {
                case FieldTimeSpanScale:
                    scale = (TimeSpanScale)source.ReadInt32();
                    break;

                case FieldTimeSpanValue:
                    source.Assert(WireType.SignedVariant);
                    value = source.ReadInt64();
                    break;

                default:
                    source.SkipField();
                    break;
                }
            }
            ProtoReader.EndSubItem(token, source);
            switch (scale)
            {
            case TimeSpanScale.Days:
                return(value * TimeSpan.TicksPerDay);

            case TimeSpanScale.Hours:
                return(value * TimeSpan.TicksPerHour);

            case TimeSpanScale.Minutes:
                return(value * TimeSpan.TicksPerMinute);

            case TimeSpanScale.Seconds:
                return(value * TimeSpan.TicksPerSecond);

            case TimeSpanScale.Milliseconds:
                return(value * TimeSpan.TicksPerMillisecond);

            case TimeSpanScale.Ticks:
                return(value);

            case TimeSpanScale.MinMax:
                switch (value)
                {
                case 1: return(long.MaxValue);

                case -1: return(long.MinValue);

                default: throw new ProtoException("Unknown min/max value: " + value.ToString());
                }

            default:
                throw new ProtoException("Unknown timescale: " + scale.ToString());
            }
        }
Exemplo n.º 3
0
 static public int ReadInt64(IntPtr l)
 {
     try {
         ProtoBuf.ProtoReader self = (ProtoBuf.ProtoReader)checkSelf(l);
         var ret = self.ReadInt64();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemplo n.º 4
0
 private static long ReadTimeSpanTicks(ProtoReader source) {
     switch (source.WireType)
     {
         case WireType.String:
         case WireType.StartGroup:
             SubItemToken token = ProtoReader.StartSubItem(source);
             int fieldNumber;
             TimeSpanScale scale = TimeSpanScale.Days;
             long value = 0;
             while ((fieldNumber = source.ReadFieldHeader()) > 0)
             {
                 switch (fieldNumber)
                 {
                     case FieldTimeSpanScale:
                         scale = (TimeSpanScale)source.ReadInt32();
                         break;
                     case FieldTimeSpanValue:
                         source.Assert(WireType.SignedVariant);
                         value = source.ReadInt64();
                         break;
                     default:
                         source.SkipField();
                         break;
                 }
             }
             ProtoReader.EndSubItem(token, source);
             switch (scale)
             {
                 case TimeSpanScale.Days:
                     return value * TimeSpan.TicksPerDay;
                 case TimeSpanScale.Hours:
                     return value * TimeSpan.TicksPerHour;
                 case TimeSpanScale.Minutes:
                     return value * TimeSpan.TicksPerMinute;
                 case TimeSpanScale.Seconds:
                     return value * TimeSpan.TicksPerSecond;
                 case TimeSpanScale.Milliseconds:
                     return value * TimeSpan.TicksPerMillisecond;
                 case TimeSpanScale.Ticks:
                     return value;
                 case TimeSpanScale.MinMax:
                     switch (value)
                     {
                         case 1: return long.MaxValue;
                         case -1: return long.MinValue;
                         default: throw new ProtoException("Unknown min/max value: " + value.ToString());
                     }
                 default:
                     throw new ProtoException("Unknown timescale: " + scale.ToString());
             }
         case WireType.Fixed64:
             return source.ReadInt64();
         default:
             throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
     }
 }
Exemplo n.º 5
0
        private static long ReadTimeSpanTicks(ProtoReader source, out DateTimeKind kind)
        {
            kind = DateTimeKind.Unspecified;
            switch (source.WireType)
            {
            case WireType.String:
            case WireType.StartGroup:
                SubItemToken  token = ProtoReader.StartSubItem(source);
                int           fieldNumber;
                TimeSpanScale scale = TimeSpanScale.Days;
                long          value = 0;
                while ((fieldNumber = source.ReadFieldHeader()) > 0)
                {
                    switch (fieldNumber)
                    {
                    case FieldTimeSpanScale:
                        scale = (TimeSpanScale)source.ReadInt32();
                        break;

                    case FieldTimeSpanValue:
                        source.Assert(WireType.SignedVariant);
                        value = source.ReadInt64();
                        break;

                    case FieldTimeSpanKind:
                        kind = (DateTimeKind)source.ReadInt32();
                        switch (kind)
                        {
                        case DateTimeKind.Unspecified:
                        case DateTimeKind.Utc:
                        case DateTimeKind.Local:
                            break;             // fine

                        default:
                            throw new ProtoException("Invalid date/time kind: " + kind.ToString());
                        }
                        break;

                    default:
                        source.SkipField();
                        break;
                    }
                }
                ProtoReader.EndSubItem(token, source);
                switch (scale)
                {
                case TimeSpanScale.Days:
                    return(value * TimeSpan.TicksPerDay);

                case TimeSpanScale.Hours:
                    return(value * TimeSpan.TicksPerHour);

                case TimeSpanScale.Minutes:
                    return(value * TimeSpan.TicksPerMinute);

                case TimeSpanScale.Seconds:
                    return(value * TimeSpan.TicksPerSecond);

                case TimeSpanScale.Milliseconds:
                    return(value * TimeSpan.TicksPerMillisecond);

                case TimeSpanScale.Ticks:
                    return(value);

                case TimeSpanScale.MinMax:
                    switch (value)
                    {
                    case 1: return(long.MaxValue);

                    case -1: return(long.MinValue);

                    default: throw new ProtoException("Unknown min/max value: " + value.ToString());
                    }

                default:
                    throw new ProtoException("Unknown timescale: " + scale.ToString());
                }

            case WireType.Fixed64:
                return(source.ReadInt64());

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
        }
Exemplo n.º 6
0
        object BuildBody( uint realEMsg, Stream str )
        {
            EMsg eMsg = MsgUtil.GetMsg( realEMsg );

            if ( eMsg == EMsg.ClientLogonGameServer )
                eMsg = EMsg.ClientLogon; // temp hack for now
            else if( eMsg == EMsg.ClientGamesPlayedWithDataBlob)
                eMsg = EMsg.ClientGamesPlayed;

            var protomsgType = typeof(CMClient).Assembly.GetTypes().ToList().Find(type =>
            {
                if (type.GetInterfaces().ToList().Find(inter => inter == typeof(IExtensible)) == null)
                    return false;

                if (type.Name.EndsWith(eMsg.ToString(), StringComparison.OrdinalIgnoreCase))
                    return true;

                return false;
            });

            if (protomsgType != null)
            {
                return RuntimeTypeModel.Default.Deserialize(str, null, protomsgType);
            }

            // lets first find the type by checking all EMsgs we have
            var msgType = typeof( CMClient ).Assembly.GetTypes().ToList().Find( type =>
            {
                if ( type.GetInterfaces().ToList().Find( inter => inter == typeof( ISteamSerializableMessage ) ) == null )
                    return false;

                var gcMsg = Activator.CreateInstance( type ) as ISteamSerializableMessage;

                return gcMsg.GetEMsg() == eMsg;
            } );

            string eMsgName = eMsg.ToString();

            eMsgName = eMsgName.Replace( "Econ", "" ).Replace( "AM", "" );

            // check name
            if ( msgType == null )
                msgType = GetSteamKitType( string.Format( "SteamKit2.Msg{0}", eMsgName ) );


            if ( msgType != null )
            {
                var body = Activator.CreateInstance( msgType ) as ISteamSerializableMessage;
                body.Deserialize( str );

                return body;
            }

            msgType = GetSteamKitType( string.Format( "SteamKit2.CMsg{0}", eMsgName ) );
            if ( msgType != null )
            {
                return Deserialize( msgType, str );
            }

            if ( eMsg == EMsg.ClientToGC || eMsg == EMsg.ClientFromGC )
            {
                return Serializer.Deserialize<CMsgGCClient>( str );
            }

            var gcMsgName = BuildEMsg( realEMsg );
            var gcMsgPossibleTypePrefixes = new[]
            {
                "SteamKit2.GC.Internal.CMsg",
                "SteamKit2.GC.Dota.Internal.CMsg",
                "SteamKit2.GC.CSGO.Internal.CMsg",
                "SteamKit2.GC.TF.Internal.CMsg",
            };

            var typeMsgName = gcMsgName
                .Replace("GC", string.Empty)
                .Replace("k_", string.Empty)
                .Replace("ESOMsg", string.Empty)
                .TrimStart('_')
                .Replace("EMsg", string.Empty);

            
            if ( typeMsgName == "Create" || typeMsgName == "Destroy" || typeMsgName == "Update" )
                typeMsgName = "SingleObject";
            else if ( typeMsgName == "Multiple" )
                typeMsgName = "MultipleObjects";

            var possibleTypes = from type in typeof( CMClient ).Assembly.GetTypes()
                                from typePrefix in gcMsgPossibleTypePrefixes
                                where type.GetInterfaces().Contains( typeof ( IExtensible ) )
                                where type.FullName.StartsWith( typePrefix ) && type.FullName.EndsWith( typeMsgName )
                                select type;

            foreach ( var type in possibleTypes )
            {
                var streamPos = str.Position;
                try
                {
                    return Deserialize( type, str );
                }
                catch ( Exception )
                {
                    str.Position = streamPos;
                }
            }

            if (!MsgUtil.IsProtoBuf(realEMsg))
                return null;

            // try reading it as a protobuf
            using (ProtoReader reader = new ProtoReader(str, null, null))
            {
                var fields = new Dictionary<int, List<object>>();

                while(true)
                {
                    int field = reader.ReadFieldHeader();

                    if(field == 0)
                        break;

                    object fieldValue = null;

                    switch (reader.WireType)
                    {
                        case WireType.Variant:
                        case WireType.Fixed32:
                        case WireType.Fixed64:
                        case WireType.SignedVariant:
                            {
                                try
                                {
                                    fieldValue = reader.ReadInt64();
                                }
                                catch (Exception)
                                {
                                    fieldValue = "Unable to read Variant (debugme)";
                                }

                                break;
                            }
                        case WireType.String:
                            {
                                try
                                {
                                    fieldValue = reader.ReadString();
                                }
                                catch (Exception)
                                {
                                    fieldValue = "Unable to read String (debugme)";
                                }

                                break;
                            }
                        default:
                            {
                                fieldValue = string.Format( "{0} is not implemented", reader.WireType );
                                break;
                            }
                    }

                    if ( !fields.ContainsKey( field ) )
                    {
                        fields[ field ] = new List<object>();
                    }

                    fields[ field ].Add( fieldValue );
                }

                if (fields.Count > 0)
                    return fields;
            }

            return null;
        }
Exemplo n.º 7
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            switch (source.WireType)
            {
            case WireType.String:
            case WireType.StartGroup:
            {
                SubItemToken  token         = ProtoReader.StartSubItem(source);
                TimeSpanScale timeSpanScale = TimeSpanScale.Days;
                long          num           = 0L;
                int           num2;
                while ((num2 = source.ReadFieldHeader()) > 0)
                {
                    switch (num2)
                    {
                    case 2:
                        timeSpanScale = (TimeSpanScale)source.ReadInt32();
                        break;

                    case 1:
                        source.Assert(WireType.SignedVariant);
                        num = source.ReadInt64();
                        break;

                    default:
                        source.SkipField();
                        break;
                    }
                }
                ProtoReader.EndSubItem(token, source);
                switch (timeSpanScale)
                {
                case TimeSpanScale.Days:
                    return(num * 864000000000L);

                case TimeSpanScale.Hours:
                    return(num * 36000000000L);

                case TimeSpanScale.Minutes:
                    return(num * 600000000);

                case TimeSpanScale.Seconds:
                    return(num * 10000000);

                case TimeSpanScale.Milliseconds:
                    return(num * 10000);

                case TimeSpanScale.Ticks:
                    return(num);

                case TimeSpanScale.MinMax:
                    switch (num)
                    {
                    case 1L:
                        return(long.MaxValue);

                    case -1L:
                        return(long.MinValue);

                    default:
                        throw new ProtoException("Unknown min/max value: " + num);
                    }

                default:
                    throw new ProtoException("Unknown timescale: " + timeSpanScale);
                }
            }

            case WireType.Fixed64:
                return(source.ReadInt64());

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType);
            }
        }
Exemplo n.º 8
0
        // Token: 0x06003269 RID: 12905 RVA: 0x001266EC File Offset: 0x00124AEC
        private static long ReadTimeSpanTicks(ProtoReader source, out DateTimeKind kind)
        {
            kind = DateTimeKind.Unspecified;
            switch (source.WireType)
            {
            case WireType.Fixed64:
                return(source.ReadInt64());

            case WireType.String:
            case WireType.StartGroup:
            {
                SubItemToken  token         = ProtoReader.StartSubItem(source);
                TimeSpanScale timeSpanScale = TimeSpanScale.Days;
                long          num           = 0L;
                int           num2;
                while ((num2 = source.ReadFieldHeader()) > 0)
                {
                    switch (num2)
                    {
                    case 1:
                        source.Assert(WireType.SignedVariant);
                        num = source.ReadInt64();
                        break;

                    case 2:
                        timeSpanScale = (TimeSpanScale)source.ReadInt32();
                        break;

                    case 3:
                        kind = (DateTimeKind)source.ReadInt32();
                        switch (kind)
                        {
                        case DateTimeKind.Unspecified:
                        case DateTimeKind.Utc:
                        case DateTimeKind.Local:
                            break;

                        default:
                            throw new ProtoException("Invalid date/time kind: " + kind.ToString());
                        }
                        break;

                    default:
                        source.SkipField();
                        break;
                    }
                }
                ProtoReader.EndSubItem(token, source);
                switch (timeSpanScale)
                {
                case TimeSpanScale.Days:
                    return(num * 864000000000L);

                case TimeSpanScale.Hours:
                    return(num * 36000000000L);

                case TimeSpanScale.Minutes:
                    return(num * 600000000L);

                case TimeSpanScale.Seconds:
                    return(num * 10000000L);

                case TimeSpanScale.Milliseconds:
                    return(num * 10000L);

                case TimeSpanScale.Ticks:
                    return(num);

                default:
                    if (timeSpanScale != TimeSpanScale.MinMax)
                    {
                        throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
                    }
                    if (num == 1L)
                    {
                        return(long.MaxValue);
                    }
                    if (num != -1L)
                    {
                        throw new ProtoException("Unknown min/max value: " + num.ToString());
                    }
                    return(long.MinValue);
                }
            }

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
        }
Exemplo n.º 9
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            WireType wireType = source.WireType;

            if (wireType != WireType.Fixed64)
            {
                if ((uint)(wireType - 2) <= 1u)
                {
                    SubItemToken  token         = ProtoReader.StartSubItem(source);
                    TimeSpanScale timeSpanScale = TimeSpanScale.Days;
                    long          num           = 0L;
                    int           num2;
                    while ((num2 = source.ReadFieldHeader()) > 0)
                    {
                        switch (num2)
                        {
                        case 2:
                            timeSpanScale = (TimeSpanScale)source.ReadInt32();
                            break;

                        case 1:
                            source.Assert(WireType.SignedVariant);
                            num = source.ReadInt64();
                            break;

                        default:
                            source.SkipField();
                            break;
                        }
                    }
                    ProtoReader.EndSubItem(token, source);
                    switch (timeSpanScale)
                    {
                    case TimeSpanScale.Days:
                        return(num * 864000000000L);

                    case TimeSpanScale.Hours:
                        return(num * 36000000000L);

                    case TimeSpanScale.Minutes:
                        return(num * 600000000);

                    case TimeSpanScale.Seconds:
                        return(num * 10000000);

                    case TimeSpanScale.Milliseconds:
                        return(num * 10000);

                    case TimeSpanScale.Ticks:
                        return(num);

                    case TimeSpanScale.MinMax:
                        switch (num)
                        {
                        case 1L:
                            return(9223372036854775807L);

                        case -1L:
                            return(-9223372036854775808L);

                        default:
                            throw new ProtoException("Unknown min/max value: " + num.ToString());
                        }

                    default:
                        throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
                    }
                }
                wireType = source.WireType;
                throw new ProtoException("Unexpected wire-type: " + wireType.ToString());
            }
            return(source.ReadInt64());
        }
Exemplo n.º 10
0
 private static long ReadTimeSpanTicks(ProtoReader source)
 {
     switch (source.WireType)
     {
     case WireType.Fixed64:
         return source.ReadInt64();
     case WireType.String:
     case WireType.StartGroup:
     {
         SubItemToken token = ProtoReader.StartSubItem(source);
         TimeSpanScale timeSpanScale = TimeSpanScale.Days;
         long num = 0L;
         int num2;
         while ((num2 = source.ReadFieldHeader()) > 0)
         {
             int num3 = num2;
             if (num3 != 1)
             {
                 if (num3 != 2)
                 {
                     source.SkipField();
                 }
                 else
                 {
                     timeSpanScale = (TimeSpanScale)source.ReadInt32();
                 }
             }
             else
             {
                 source.Assert(WireType.SignedVariant);
                 num = source.ReadInt64();
             }
         }
         ProtoReader.EndSubItem(token, source);
         TimeSpanScale timeSpanScale2 = timeSpanScale;
         switch (timeSpanScale2)
         {
         case TimeSpanScale.Days:
             return num * 864000000000L;
         case TimeSpanScale.Hours:
             return num * 36000000000L;
         case TimeSpanScale.Minutes:
             return num * 600000000L;
         case TimeSpanScale.Seconds:
             return num * 10000000L;
         case TimeSpanScale.Milliseconds:
             return num * 10000L;
         case TimeSpanScale.Ticks:
             return num;
         default:
         {
             if (timeSpanScale2 != TimeSpanScale.MinMax)
             {
                 throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
             }
             long num4 = num;
             if (num4 >= -1L && num4 <= 1L)
             {
                 switch ((int)(num4 - -1L))
                 {
                 case 0:
                     return -9223372036854775808L;
                 case 2:
                     return 9223372036854775807L;
                 }
             }
             throw new ProtoException("Unknown min/max value: " + num.ToString());
         }
         }
         break;
     }
     default:
         throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
     }
 }
Exemplo n.º 11
0
 object ReadField(ProtoReader reader, Type memberT, string sClassName, CLS_Environment environment)
 {
     if (memberT == typeof(int))
     {
         return reader.ReadInt32();
     }
     else if (memberT == typeof(uint))
     {
         return reader.ReadUInt32();
     }
     else if (memberT == typeof(bool))
     {
         return reader.ReadBoolean();
     }
     else if (memberT == typeof(byte))
     {
         return reader.ReadByte();
     }
     else if (memberT == typeof(sbyte))
     {
         return reader.ReadSByte();
     }
     else if (memberT == typeof(float))
     {
         return reader.ReadSingle();
     }
     else if (memberT == typeof(double))
     {
         return reader.ReadDouble();
     }
     else if (memberT == typeof(short))
     {
         return reader.ReadInt16();
     }
     else if (memberT == typeof(ushort))
     {
         return reader.ReadUInt16();
     }
     else if (memberT == typeof(long))
     {
         return reader.ReadInt64();
     }
     else if (memberT == typeof(ulong))
     {
         return reader.ReadUInt64();
     }
     else if (memberT == typeof(string))
     {
         return reader.ReadString();
     }
     else if (memberT == typeof(byte[]))
     {
         return ProtoReader.AppendBytes(null, reader);
     }
     else if (memberT == typeof(SInstance))
     {
         SubItemToken st = ProtoReader.StartSubItem(reader);
         CLS_Type_Class sClass = environment.GetTypeByKeywordQuiet(sClassName) as CLS_Type_Class;
         if (!sClass.compiled)
             RuntimeCompilerClass(sClassName);
         CLS_Content content = CLS_Content.NewContent(environment);
         CLS_Content.Value retVal = sClass.function.New(content, m_emptyParams);
         CLS_Content.PoolContent(content);
         SInstance sInstance = (SInstance)retVal.value;
         ReadSInstance(reader, sInstance, environment);
         ProtoReader.EndSubItem(st, reader);
         return sInstance;
     }
     else
     {
         throw new NotImplementedException("未实现类型: " + memberT);
     }
 }
Exemplo n.º 12
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            TimeSpanScale timeSpanScale;

            switch (source.WireType)
            {
            case WireType.Fixed64:
            {
                return(source.ReadInt64());
            }

            case WireType.String:
            case WireType.StartGroup:
            {
                SubItemToken subItemToken = ProtoReader.StartSubItem(source);
                timeSpanScale = TimeSpanScale.Days;
                long num = (long)0;
                while (true)
                {
                    int num1 = source.ReadFieldHeader();
                    int num2 = num1;
                    if (num1 <= 0)
                    {
                        break;
                    }
                    switch (num2)
                    {
                    case 1:
                    {
                        source.Assert(WireType.SignedVariant);
                        num = source.ReadInt64();
                        continue;
                    }

                    case 2:
                    {
                        timeSpanScale = (TimeSpanScale)source.ReadInt32();
                        continue;
                    }

                    default:
                    {
                        source.SkipField();
                        continue;
                    }
                    }
                }
                ProtoReader.EndSubItem(subItemToken, source);
                TimeSpanScale timeSpanScale1 = timeSpanScale;
                switch (timeSpanScale1)
                {
                case TimeSpanScale.Days:
                {
                    return(num * 864000000000L);
                }

                case TimeSpanScale.Hours:
                {
                    return(num * 36000000000L);
                }

                case TimeSpanScale.Minutes:
                {
                    return(num * (long)600000000);
                }

                case TimeSpanScale.Seconds:
                {
                    return(num * (long)10000000);
                }

                case TimeSpanScale.Milliseconds:
                {
                    return(num * (long)10000);
                }

                case TimeSpanScale.Ticks:
                {
                    return(num);
                }

                default:
                {
                    if (timeSpanScale1 == TimeSpanScale.MinMax)
                    {
                        break;
                    }
                    else
                    {
                        throw new ProtoException(string.Concat("Unknown timescale: ", timeSpanScale.ToString()));
                    }
                }
                }
                long num3 = num;
                if (num3 <= (long)1 && num3 >= (long)-1)
                {
                    switch ((int)(num3 - (long)-1))
                    {
                    case 0:
                    {
                        return(-9223372036854775808L);
                    }

                    case 2:
                    {
                        return(9223372036854775807L);
                    }
                    }
                }
                throw new ProtoException(string.Concat("Unknown min/max value: ", num.ToString()));
            }
            }
            throw new ProtoException(string.Concat("Unexpected wire-type: ", source.WireType.ToString()));
            throw new ProtoException(string.Concat("Unknown timescale: ", timeSpanScale.ToString()));
        }
Exemplo n.º 13
0
        object BuildBody( uint realEMsg, Stream str )
        {
            EMsg eMsg = MsgUtil.GetMsg( realEMsg );

            if ( eMsg == EMsg.ClientLogonGameServer )
                eMsg = EMsg.ClientLogon; // temp hack for now
            else if( eMsg == EMsg.ClientGamesPlayedWithDataBlob)
                eMsg = EMsg.ClientGamesPlayed;

            var protomsgType = typeof(CMClient).Assembly.GetTypes().ToList().Find(type =>
            {
                if (type.GetInterfaces().ToList().Find(inter => inter == typeof(IExtensible)) == null)
                    return false;

                if (type.Name.EndsWith(eMsg.ToString()))
                    return true;

                return false;
            });

            if (protomsgType != null)
            {
                return RuntimeTypeModel.Default.Deserialize(str, null, protomsgType);
            }

            // lets first find the type by checking all EMsgs we have
            var msgType = typeof( CMClient ).Assembly.GetTypes().ToList().Find( type =>
            {
                if ( type.GetInterfaces().ToList().Find( inter => inter == typeof( ISteamSerializableMessage ) ) == null )
                    return false;

                var gcMsg = Activator.CreateInstance( type ) as ISteamSerializableMessage;

                return gcMsg.GetEMsg() == eMsg;
            } );

            string eMsgName = eMsg.ToString();

            eMsgName = eMsgName.Replace( "Econ", "" ).Replace( "AM", "" );

            // check name
            if ( msgType == null )
                msgType = GetSteamKitType( string.Format( "SteamKit2.Msg{0}", eMsgName ) );


            if ( msgType != null )
            {
                var body = Activator.CreateInstance( msgType ) as ISteamSerializableMessage;
                body.Deserialize( str );

                return body;
            }

            msgType = GetSteamKitType( string.Format( "SteamKit2.CMsg{0}", eMsgName ) );
            if ( msgType != null )
            {
                return Deserialize( msgType, str );
            }

            if ( eMsg == EMsg.ClientToGC || eMsg == EMsg.ClientFromGC )
            {
                return Serializer.Deserialize<CMsgGCClient>( str );
            }

            // try reading it as a protobuf
            using (ProtoReader reader = new ProtoReader(str, null, null))
            {
                var fields = new Dictionary<int, List<object>>();

                while(true)
                {
                    int field = reader.ReadFieldHeader();

                    if(field == 0)
                        break;

                    object fieldValue = null;

                    switch (reader.WireType)
                    {
                        case WireType.Variant:
                        case WireType.Fixed32:
                        case WireType.Fixed64:
                        case WireType.SignedVariant:
                            {
                                try
                                {
                                    fieldValue = reader.ReadInt64();
                                }
                                catch (Exception)
                                {
                                    fieldValue = "Unable to read Variant (debugme)";
                                }

                                break;
                            }
                        case WireType.String:
                            {
                                try
                                {
                                    fieldValue = reader.ReadString();
                                }
                                catch (Exception)
                                {
                                    fieldValue = "Unable to read String (debugme)";
                                }

                                break;
                            }
                        default:
                            {
                                fieldValue = string.Format( "{0} is not implemented", reader.WireType );
                                break;
                            }
                    }

                    if ( !fields.ContainsKey( field ) )
                    {
                        fields[ field ] = new List<object>();
                    }

                    fields[ field ].Add( fieldValue );
                }

                if (fields.Count > 0)
                    return fields;
            }

            return null;
        }
Exemplo n.º 14
0
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            switch (source.WireType)
            {
            case WireType.Fixed64:
                return(source.ReadInt64());

            case WireType.String:
            case WireType.StartGroup:
            {
                SubItemToken  token         = ProtoReader.StartSubItem(source);
                TimeSpanScale timeSpanScale = TimeSpanScale.Days;
                long          num           = 0L;
                int           num2;
                while ((num2 = source.ReadFieldHeader()) > 0)
                {
                    int num3 = num2;
                    if (num3 != 1)
                    {
                        if (num3 != 2)
                        {
                            source.SkipField();
                        }
                        else
                        {
                            timeSpanScale = (TimeSpanScale)source.ReadInt32();
                        }
                    }
                    else
                    {
                        source.Assert(WireType.SignedVariant);
                        num = source.ReadInt64();
                    }
                }
                ProtoReader.EndSubItem(token, source);
                TimeSpanScale timeSpanScale2 = timeSpanScale;
                switch (timeSpanScale2)
                {
                case TimeSpanScale.Days:
                    return(num * 864000000000L);

                case TimeSpanScale.Hours:
                    return(num * 36000000000L);

                case TimeSpanScale.Minutes:
                    return(num * 600000000L);

                case TimeSpanScale.Seconds:
                    return(num * 10000000L);

                case TimeSpanScale.Milliseconds:
                    return(num * 10000L);

                case TimeSpanScale.Ticks:
                    return(num);

                default:
                {
                    if (timeSpanScale2 != TimeSpanScale.MinMax)
                    {
                        throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
                    }
                    long num4 = num;
                    if (num4 >= -1L && num4 <= 1L)
                    {
                        switch ((int)(num4 - -1L))
                        {
                        case 0:
                            return(-9223372036854775808L);

                        case 2:
                            return(9223372036854775807L);
                        }
                    }
                    throw new ProtoException("Unknown min/max value: " + num.ToString());
                }
                }
                break;
            }

            default:
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
        }
Exemplo n.º 15
0
		public static Dictionary<int, List<object>> ReadProtobuf(Stream stream)
		{
			// try reading it as a protobuf
			using (var reader = new ProtoReader(stream, null, null))
			{
				var fields = new Dictionary<int, List<object>>();

				while (true)
				{
					int field = reader.ReadFieldHeader();

					if (field == 0)
						break;

					object fieldValue = null;

					switch (reader.WireType)
					{
						case WireType.Variant:
						case WireType.Fixed32:
						case WireType.Fixed64:
						case WireType.SignedVariant:
							{
								try
								{
									fieldValue = reader.ReadInt64();
								}
								catch (Exception)
								{
									fieldValue = "Unable to read Variant (debugme)";
								}

								break;
							}
						case WireType.String:
							{
								try
								{
									fieldValue = reader.ReadString();
								}
								catch (Exception)
								{
									fieldValue = "Unable to read String (debugme)";
								}

								break;
							}
						default:
							{
								fieldValue = string.Format("{0} is not implemented", reader.WireType);
								break;
							}
					}

					if (!fields.ContainsKey(field))
					{
						fields[field] = new List<object>();
					}

					fields[field].Add(fieldValue);
				}

				if (fields.Count > 0)
					return fields;
			}

			return null;
		}
Exemplo n.º 16
0
        // Token: 0x06000039 RID: 57 RVA: 0x0000A274 File Offset: 0x00008474
        private static long ReadTimeSpanTicks(ProtoReader source)
        {
            WireType wireType = source.WireType;

            if (wireType == WireType.Fixed64)
            {
                return(source.ReadInt64());
            }
            if (wireType - WireType.String > 1)
            {
                throw new ProtoException("Unexpected wire-type: " + source.WireType.ToString());
            }
            SubItemToken  token         = ProtoReader.StartSubItem(source);
            TimeSpanScale timeSpanScale = TimeSpanScale.Days;
            long          num           = 0L;
            int           num2;

            while ((num2 = source.ReadFieldHeader()) > 0)
            {
                if (num2 != 1)
                {
                    if (num2 == 2)
                    {
                        timeSpanScale = (TimeSpanScale)source.ReadInt32();
                    }
                    else
                    {
                        source.SkipField();
                    }
                }
                else
                {
                    source.Assert(WireType.SignedVariant);
                    num = source.ReadInt64();
                }
            }
            ProtoReader.EndSubItem(token, source);
            switch (timeSpanScale)
            {
            case TimeSpanScale.Days:
                return(num * 864000000000L);

            case TimeSpanScale.Hours:
                return(num * 36000000000L);

            case TimeSpanScale.Minutes:
                return(num * 600000000L);

            case TimeSpanScale.Seconds:
                return(num * 10000000L);

            case TimeSpanScale.Milliseconds:
                return(num * 10000L);

            case TimeSpanScale.Ticks:
                return(num);

            default:
                if (timeSpanScale != TimeSpanScale.MinMax)
                {
                    throw new ProtoException("Unknown timescale: " + timeSpanScale.ToString());
                }
                if (num == -1L)
                {
                    return(long.MinValue);
                }
                if (num == 1L)
                {
                    return(long.MaxValue);
                }
                throw new ProtoException("Unknown min/max value: " + num.ToString());
            }
        }