源数据中出现意外的最终组;这通常意味着源数据已损坏

时间:2016-03-02 07:28:25

标签: c# protocol-buffers protobuf-net steambot

每当我尝试反序列化一个protobuf字节数组时,我都会收到此错误...我的代码如下:

public void GetFloatValue(ulong sid64, string ilink)
    {
        string param_s = null;
        string param_a = null;
        string param_d = null;
        string param_m = null;
        bool goodlink = false;
        bool isinv = false;
        CallbackManager Manager = new CallbackManager(SteamClient);
        new Callback<SteamGameCoordinator.MessageCallback>(onFloatCallback, Manager);
        var Msg = new ClientGCMsgProtobuf<CMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockRequest>((uint)ECsgoGCMsg.k_EMsgGCCStrike15_v2_Client2GCEconPreviewDataBlockRequest);
        if (ilink.Contains("steam://rungame/730") && ilink.Contains("%20S7656"))
        {
            param_s = ilink.Substring(67, 84 - 67);
            param_a = ilink.Substring(85, 95 - 85);
            param_d = ilink.Substring(96, 115 - 96);
            goodlink = true;
            isinv = true;
        }
        else if (ilink.Contains("steam://rungame/730"))
        {
            param_m = ilink.Substring(67, 85 - 67);
            param_a = ilink.Substring(86, 96 - 86);
            param_d = ilink.Substring(97, 116 - 97);
            goodlink = true;
            isinv = false;
        }
        else
        {
            goodlink = false;
        }

        if (goodlink == false)
        {
            SteamFriends.SendChatMessage(sid64, EChatEntryType.ChatMsg, "Error: Bad Inspect Link");
        }
        else if (goodlink == true)
        {
            if (isinv == true)
            {
                Msg.Body.param_a = Convert.ToUInt64(param_a);
                Msg.Body.param_d = Convert.ToUInt64(param_d);
                Msg.Body.param_s = Convert.ToUInt64(param_s);
            }
            else
            {
                Msg.Body.param_a = Convert.ToUInt64(param_a);
                Msg.Body.param_d = Convert.ToUInt64(param_d);
                Msg.Body.param_m = Convert.ToUInt64(param_m);
            }

            var playGame = new ClientMsgProtobuf<CMsgClientGamesPlayed>(EMsg.ClientGamesPlayed);

            playGame.Body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed
            {
                game_id = new GameID(730),
            });

            SteamClient.Send(playGame);

            var clientHello = new ClientGCMsgProtobuf<CMsgClientHello>((uint)EGCBaseClientMsg.k_EMsgGCClientHello);
            SteamGameCoordinator.Send(clientHello, 730);

            SteamGameCoordinator.Send(Msg, 730);

            Manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
        }
    }

    public void onFloatCallback(SteamGameCoordinator.MessageCallback callback)
    {
        byte[] bytes = callback.Message.GetData();
        MemoryStream stream = new MemoryStream(bytes);
        var obj = ProtoBuf.Serializer.Deserialize<CEconItemPreviewDataBlock>(stream);
        Console.WriteLine(obj.origin);
    }

控制台中的错误包括发生错误的多行,其中一些是在protobuf-net类文件中,但实际上包含一行代码的第一行是{{{ 1}}下一个是var obj = ProtoBuf.Serializer.Deserialize<CEconItemPreviewDataBlock>(stream);

0 个答案:

没有答案