Esempio n. 1
0
 public static void ExportProtoPackets()
 {
     Directory.CreateDirectory("files");
     foreach (var file in Directory.EnumerateFiles(@"H:\Source\HG\Client\Resource_Client\packets\"))
     {
         Console.WriteLine($"Reading {new FileInfo(file).Name}");
         var pkts = XProtoPacket.ReadPackets(File.ReadAllBytes(file));
         foreach (var packet in pkts)
         {
             var protoBuf = new ProtoBuffPacket(packet.Payload);
             File.WriteAllBytes($"files/{new FileInfo(file).Name}.bin", protoBuf.Payload);
         }
     }
 }
Esempio n. 2
0
        public void TestLoginParsing()
        {
            var packets = XProtoPacket.ReadPackets(GetTestData("0login"));

            Assert.AreEqual(1, packets.Count);

            var packet = packets[0];

            Assert.AreEqual(XProtoPackets.SendProtoBuff, (int)packet.Id);

            var protoBufPacket = new ProtoBuffPacket(packet.Payload);

            Assert.AreEqual(3, protoBufPacket.Messages.Count);

            var protoBufMessage = protoBufPacket.Messages[0];

            Assert.IsAssignableFrom(typeof(Up_Login), protoBufMessage);

            TestContext.WriteLine((string)(new ProtoBuffPacket(packets[0].Payload).Messages[0]).ToString());
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            var data = File.ReadAllBytes(@"H:\Source\HG\Client\Resource_Client\packets\2system_setting");

            Console.WriteLine(data.HexDump());

            var packets = XProtoPacket.ReadPackets(data);

            foreach (var packet in packets)
            {
                switch (packet.Id)
                {
                case XProtoPacket.XProtoPackets.SendProtoBuff:
                    var p = new ProtoBuffPacket(packet.Payload);
                    Console.WriteLine(packet.Payload.HexDump());
                    Console.WriteLine(p.Payload.HexDump());
                    foreach (var message in p.Messages)
                    {
                        Console.WriteLine(message);
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }
            }

            Console.ReadKey();

            //var data = File.ReadAllBytes(@"H:\Source\HG\Client\Resource_Client\packets\0login");
            //var data = File.ReadAllBytes(@"H:\Source\HG\Client\Resource_Client\packets\1system_setting");
            //var data = File.ReadAllBytes(@"H:\Source\HG\Client\Resource_Client\packets\2get_svr_time");
            //var data = File.ReadAllBytes(@"H:\Source\HG\Client\Resource_Client\packets\2login");

            //var pkt = new Packet(data);

            /*using (var ms = new MemoryStream(data))
             * {
             *  using (var reader = new BinaryReader(ms))
             *  {
             *      if(reader.BaseStream.Length - reader.BaseStream.Position < 8)
             *          throw new Exception("XPROTO_ERROR_CODE::XPROTO_PACKET_LESS_THAN_HDRLEN");
             *
             *      // while($br->getBytesAvailable()>=8)
             *      // Is this ever be true a 2nd time?
             *      while (reader.BaseStream.Length - reader.BaseStream.Position >= 8)
             *      {
             *          var savePosition = reader.BaseStream.Position;
             *          var len = reader.ReadInt32();
             *          var cmd = reader.ReadInt32();
             *
             *          Console.WriteLine($"Len: {len}, CMD: {cmd}");
             *
             *          if (len > ms.Length)
             *              throw new Exception("XPROTO_ERROR_CODE::XPROTO_PACKET_LENGTH_OVERFLOW");
             *
             *          if (cmd <= 0 || cmd > _EMSG_ServerInterface.CMSG_MAX ||
             *              cmd < _EMSG_ServerInterface.CMSG_DoLogin)
             *              throw new Exception("XPROTO_ERROR_CODE::XPROTO_XCMD_OUT_OF_RANGE");
             *
             *          reader.BaseStream.Seek(savePosition, SeekOrigin.Begin);
             *
             *          var packetData = reader.ReadBytes(len+1);
             *          switch (cmd)
             *          {
             *              default:
             *                  throw new Exception("XPROTO_ERROR_CODE::XPROTO_XCMD_OUT_OF_RANGE");
             *              case 1: // OnDoLogin
             *                  OnDoLogin(packetData);
             *                  break;
             *              case 12: // OnInternalNotifyByProxy
             *                  OnInternalNotifyByProxy(packetData);
             *                  break;
             *              case 25: // OnKickout
             *                  OnKickout(packetData);
             *                  break;
             *              case 34: // OnPing
             *                  OnPing(packetData);
             *                  break;
             *              case 35: // OnProtoBuff (WorldSvc.php:218)
             *                  OnProtoBuff(packetData);
             *                  break;
             *          }
             *      }
             *
             *      /*
             *      // HandleReceivedData (GameProtocolServer.php:88)
             *      var len = reader.ReadInt32();
             *      var cmd = reader.ReadInt32();
             *
             *      if (len > ms.Length)
             *          throw new Exception("XPROTO_ERROR_CODE::XPROTO_PACKET_LENGTH_OVERFLOW");
             *
             *      Console.WriteLine($"Len: {len}, CMD: {cmd}");
             *
             *      if (cmd <= 0 || cmd > _EMSG_ServerInterface.CMSG_MAX ||
             *          cmd < _EMSG_ServerInterface.CMSG_DoLogin)
             *          throw new Exception("XPROTO_ERROR_CODE::XPROTO_XCMD_OUT_OF_RANGE");
             *
             *      byte[] packet = new byte[ms.Length-8];
             *      Array.Copy(ms.ToArray(), 8, packet, 0, ms.Length-8);
             *      switch (cmd)
             *      {
             *          default:
             *              throw new Exception("XPROTO_ERROR_CODE::XPROTO_XCMD_OUT_OF_RANGE");
             *          case 1: // OnDoLogin
             *              OnDoLogin(packet);
             *              break;
             *          case 12: // OnInternalNotifyByProxy
             *              OnInternalNotifyByProxy(packet);
             *              break;
             *          case 25: // OnKickout
             *              OnKickout(packet);
             *              break;
             *          case 34: // OnPing
             *              OnPing(packet);
             *              break;
             *          case 35: // OnProtoBuff (WorldSvc.php:218)
             *              OnProtoBuff(packet);
             *              break;
             *      }
             *  }
             * }*/

            LogManager.Shutdown();
        }