Beispiel #1
0
        Type GetMessageBodyType(uint realEMsg)
        {
            EMsg eMsg = MsgUtil.GetMsg(realEMsg);

            if (MessageTypeOverrides.BodyMap.ContainsKey(eMsg))
            {
                return(MessageTypeOverrides.BodyMap[eMsg]);
            }

            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);
            });

            return(protomsgType);
        }
Beispiel #2
0
        static bool FilterProtobufMessageBodyType(Type type, EMsg eMsg)
        {
            if (type.GetInterfaces().ToList().Find(inter => inter == typeof(IExtensible)) == null)
            {
                return(false);
            }

            if (type.Namespace != "SteamKit2.Internal")
            {
                return(false);
            }

            if (!type.Name.EndsWith(eMsg.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(true);
        }
Beispiel #3
0
		static bool FilterProtobufMessageBodyType(Type type, EMsg eMsg)
		{
			if (type.GetInterfaces().ToList().Find(inter => inter == typeof(IExtensible)) == null)
			{
				return false;
			}

			if (type.Namespace != "SteamKit2.Internal")
			{
				return false;
			}

			if (!type.Name.EndsWith(eMsg.ToString(), StringComparison.OrdinalIgnoreCase))
			{
				return false;
			}

			return true;
		}
Beispiel #4
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));
            }

            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(false);
            }

            // 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);
        }
Beispiel #5
0
        object BuildBody(uint realEMsg, Stream str, uint gcAppid = 0)
        {
            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 = GetMessageBodyType(realEMsg);

            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));
            }

            foreach (var type in GetGCMessageBodyTypeCandidates(realEMsg, gcAppid))
            {
                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);
        }