Ejemplo n.º 1
0
        private bool ServerPacketHandler(Context context, Packet packet)
        {
            bool retval = false;
            switch (packet.Opcode)
            {
                case 0x303D:
                    {
                        packet.SeekRead(24, SeekOrigin.Begin);
                        uint maxHP = packet.ReadUInt32();
                        uint maxMP = packet.ReadUInt32();
                        _charracter.MaxHP = maxHP;
                        _charracter.MaxMP = maxMP;
                        if (_charracter.CurrentHP > 0)
                        {
                            _mainForm.UpdateProgressBarValue(_charracter.MaxHP, _charracter.MaxHP, _charracter.MaxMP, _charracter.MaxMP);
                        }

                    }
                    break;
                case 0x3020:
                    {
                        _charracter.Id = packet.ReadUInt32();
                        Packet packet3013 = _charracter.Opcode3013;
                        string id = BitConverter.ToString(BitConverter.GetBytes(_charracter.Id)).Replace("-", "");
                        string tempPacket = BitConverter.ToString(packet3013.GetBytes()).Replace("-", "");
                        int index = tempPacket.IndexOf(id, 0);

                        if (index > 0)
                        {
                            float X = 0, Y = 0;
                            byte XX = 0, YY = 0;
                            index = index / 2 + 4;
                            packet3013.SeekRead(index, SeekOrigin.Begin);
                            ushort zonetype = packet3013.ReadUInt16();
                            XX = BitConverter.GetBytes(zonetype)[0];
                            YY = BitConverter.GetBytes(zonetype)[1];
                            if (zonetype >= 32769 && zonetype <= 32775)
                            {
                                X = packet3013.ReadSingle();
                                packet3013.SeekRead(index + 14, SeekOrigin.Begin);
                                Y = packet3013.ReadSingle();
                            }
                            else
                            {
                                X = packet3013.ReadSingle();
                                packet3013.SeekRead(index + 10, SeekOrigin.Begin);
                                Y = packet3013.ReadSingle();
                            }
                            _charracter.XCoord = (int)Math.Floor((XX - 135) * 192 + X / 10);
                            _charracter.YCoord = (int)Math.Floor((YY - 92) * 192 + Y / 10);
                            _mainForm.UpdateCoord("X : " + _charracter.XCoord + "   " + "Y : " + _charracter.YCoord);
                        }

                        packet3013.Dispose();
                        _charracter.Opcode3013 = null;
                    }
                    break;
                case 0x3057:
                    {
                        uint tempID = packet.ReadUInt32();
                        packet.SeekRead(6, SeekOrigin.Begin);

                        if (tempID == _charracter.Id)
                        {
                            byte check = packet.ReadUInt8();
                            if (check == 1)
                            {
                                _charracter.CurrentHP = packet.ReadUInt32();
                            }
                            else if (check == 2)
                            {
                                _charracter.CurrentMP = packet.ReadUInt32();
                            }
                        }
                        _mainForm.UpdateProgressBarValue(_charracter.MaxHP, _charracter.CurrentHP, _charracter.MaxMP, _charracter.CurrentMP);
                    }
                    break;
                case 0x3013:
                    {
                        //Print(packet, "S->P");
                        _charracter.Opcode3013 = packet;
                        packet.SeekRead(42, SeekOrigin.Begin);
                        _charracter.CurrentHP = packet.ReadUInt32();
                        _charracter.CurrentMP = packet.ReadUInt32();
                        //_mainForm.UpdateProgressBarValue(_charracter.MaxHP, _charracter.CurrentHP, _charracter.MaxMP, _charracter.CurrentMP);
                    }
                    break;
                case 0xB021:
                    {
                        byte XX = 0, YY = 0;
                        ushort X = 0, Y = 0;
                        uint uintObjectID = packet.ReadUInt32();
                        byte byteDes = packet.ReadUInt8();
                        XX = packet.ReadUInt8();
                        YY = packet.ReadUInt8();
                        packet.SeekRead(5, SeekOrigin.Begin);
                        ushort zonetype = packet.ReadUInt16();
                        packet.SeekRead(7, SeekOrigin.Begin);
                        if (byteDes != 0)
                        {
                            if (uintObjectID == _charracter.Id)
                            {
                                if (zonetype >= 32769 && zonetype <= 32775)
                                {
                                    X = (ushort)(packet.ReadUInt16() - packet.ReadUInt16());
                                    packet.SeekRead(15, SeekOrigin.Begin);
                                    Y = (ushort)(packet.ReadUInt16() - packet.ReadUInt16());
                                }
                                else
                                {
                                    X = packet.ReadUInt16();
                                    packet.ReadUInt16();
                                    Y = packet.ReadUInt16();
                                }
                                _charracter.XCoord = (int)Math.Floor((XX - 135) * 192 + X / 10.0);
                                _charracter.YCoord = (int)Math.Floor((YY - 92) * 192 + Y / 10.0);

                                _mainForm.UpdateCoord("X : " + _charracter.XCoord + "   " + "Y : " + _charracter.YCoord);
                            }
                        }
                    }
                    break;
                default:
                    break;
            }
            return retval;
        }