public static Packet ChangePacketClass(Packet pak, float newVersion)
        {
            LogPacketData packetData = GetPacketData(newVersion, pak.Code, pak.Direction);
            if (packetData != null && pak.GetType().Equals(packetData.Type))
            {
                pak.Attribute = packetData.Attribute;
                return pak;
            }

            Packet newPacket = CreatePacket(packetData, (int)pak.Length);
            newPacket.CopyFrom(pak);
            return newPacket;
        }
Ejemplo n.º 2
0
        private void UpdateInstantParseTab()
        {
            float ver;
            Util.ParseFloat(instantVersion.Text, out ver, -1);

            Packet pak = new Packet(0);
            int code;
            if (!Util.ParseInt(instantCode.Text, out code))
                code = 0;
            pak.Code = (byte)code;
            bool daocLoggerPacket = false;
            try
            {
                if (instantParseInput.Text[0] == '<')
                {
                    try
                    {
                        string[] lines = instantParseInput.Lines;

                        ePacketDirection dir;
                        ePacketProtocol prot;
                        TimeSpan time;
                        int dataLen = DaocLoggerV3TextLogReader.ParseHeader(lines[0], out code, out dir, out prot, out time);
                        pak.Code = (byte)code;
                        pak.Direction = dir;
                        pak.Protocol = prot;
                        pak.Time = time;

                        for (int i = 1; i < lines.Length; i++)
                        {
                            DaocLoggerV3TextLogReader.ParseDataLine(lines[i], pak);
                        }
                        daocLoggerPacket = true;

                        if (pak.Direction == ePacketDirection.ClientToServer)
                        {
                            instantClientToServer.Checked = true;
                        }
                        else
                        {
                            instantServerToClient.Checked = true;
                        }
                    }
                    catch(Exception) {}
                }
                // failed to read daoc logger format
                if (!daocLoggerPacket)
                {
                    pak.Position = 0;
                    foreach (string line in instantParseInput.Text.Split('\n'))
                    {
                        foreach (string str in line.Split(' '))
                        {
                            try
                            {
                                if (str.Trim().Length != 2) continue;
                                byte b = byte.Parse(str.Trim(), NumberStyles.HexNumber);
                                pak.WriteByte(b);
                            }
                            catch(Exception)
                            {
                            }
                        }
                    }
                }
            }
            catch(Exception)
            {
            }

            if (instantServerToClient.Checked)
                pak.Direction = ePacketDirection.ServerToClient;
            else
                pak.Direction = ePacketDirection.ClientToServer;

            pak = PacketManager.CreatePacket(ver, pak.Code,  pak.Direction).CopyFrom(pak);

            StringBuilder result = new StringBuilder();
            result.AppendFormat("ver:{0}  code:0x{1:X2} (old:0x{2:X2})  dir:{3}  len:{4} (0x{4:X})  logger packet:{5}", ver, pak.Code, pak.Code^168, pak.Direction, pak.Length, daocLoggerPacket);
            result.Append("\npacket class: ").Append(pak.GetType().Name).Append("\n");
            result.AppendFormat("desc: \"{0}\"\n\n", pak.Description);
            try
            {
                pak.InitException = null;
                pak.Initialized = false;
                pak.Position = 0;
                pak.Init();
                pak.PositionAfterInit = pak.Position;
                pak.Initialized = true;
                result.Append(pak.GetPacketDataString(true));
            }
            catch (OutOfMemoryException e)
            {
                pak.Initialized = false;
                pak.InitException = e;
                result.Append(e.ToString());
            }
            catch (Exception e)
            {
                pak.InitException = e;
                result.AppendFormat("{0}: {1}", e.GetType().ToString(), e.Message);
            //				result.Append("\n\n").Append(e.ToString());
            }

            if (pak.PositionAfterInit > pak.Length)
            {
                result.AppendFormat("\n(pak.PositionAfterInit > pak.Length !)");
            }

            //			string notInitialized = pak.GetNotInitializedData();
            //			if (notInitialized.Length > 0)
            //			{
            //				result.AppendFormat("\n\nnot initialized:\n{0}", notInitialized);
            //			}
            using (StringWriter sw = new StringWriter())
            {
                pak.AppendNotInitializedData(sw);
                if (sw.ToString().Length > 0)
                    result.AppendFormat("\n\nnot initialized:\n{0}", sw.ToString());
            }

            result.Append('\n');

            instantParseOut.Text = result.ToString();

            if (daocLoggerPacket)
            {
                instantCode.Text = "0x"+pak.Code.ToString("X2");
                instantClientToServer.Checked = pak.Direction == ePacketDirection.ClientToServer;
            }
        }