Ejemplo n.º 1
0
        static object ReadMessageBody(uint rawEMsg, Stream stream)
        {
            var eMsg = MsgUtil.GetMsg(rawEMsg);

            var protoMsgType = MessageTypeFinder.GetProtobufMessageBodyType(rawEMsg);

            if (protoMsgType != null)
            {
                return(RuntimeTypeModel.Default.Deserialize(stream, null, protoMsgType));
            }

            // lets first find the type by checking all EMsgs we have
            var msgType = MessageTypeFinder.GetNonProtobufMessageBodyType(eMsg);

            var eMsgName = eMsg.ToString()
                           .Replace("Econ", "")
                           .Replace("AM", "");

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

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

                return(body);
            }

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

            // Last resort for protobufs
            if (MsgUtil.IsProtoBuf(rawEMsg))
            {
                var asFieldDictionary = ProtoBufFieldReader.ReadProtobuf(stream);
                return(asFieldDictionary);
            }

            return(null);
        }
Ejemplo n.º 2
0
        void DisplayDataAsProtobuf(object sender, EventArgs e)
        {
            var data = ( byte[] )value;

            try
            {
                using var ms = new MemoryStream(data);
                var dictionary = ProtoBufFieldReader.ReadProtobuf(ms);

                SetValueForDisplay(null, childNodes: new[] { new TreeNodeObjectExplorer("Protobuf", dictionary, configuration).TreeNode });
            }
            catch
            {
                SetValueForDisplay("Not a valid Protobuf object!");
            }

            TreeNode.ExpandAll();
        }