Exemplo n.º 1
0
        /// <summary>
        /// Encrypts the given packet
        /// </summary>
        /// <param name="p">The packet to encrypt</param>
        public static Packet Encrypt(Packet p, int key)
        {
            byte[] buffer       = p.GetBuffer();
            int    packetLength = buffer.Length - 4;
            string value;
            int    Lenght;
            byte   AL, BL;
            long   CX, CL, DL;

            value  = buffer[3].ToString("x2");
            value += buffer[2].ToString("x2");
            Lenght = Int32.Parse(value, NumberStyles.HexNumber);

            AL = (byte)key;
            BL = buffer[0];
            CX = Lenght + 4;
            CL = CX;
            DL = CL;

            DL        = (byte)(DL + AL);
            BL        = (byte)(BL + DL); // First encrypted byte
            buffer[0] = BL;

            DL        = (byte)(BL);      // DL = Packet first byte
            DL        = (byte)(DL + CL); // ADD DL, CL
            DL        = (byte)(AL + DL); // ADD DL, AL (gotta parse 1)
            DL        = (byte)(DL + buffer[1]);
            buffer[1] = (byte)DL;


            for (int i = 0; i < packetLength; i++)
            {
                BL = (byte)(CL);
                BL = (byte)(DL + BL);
                BL = (byte)(AL + BL);
                BL = (byte)(BL + buffer[i + 4]);

                buffer[i + 4] = BL;
                DL            = BL;
            }

            return(new Packet(buffer));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decrypts the given packet
        /// </summary>
        /// <param name="p">The packet to decrypt</param>
        public static Packet Decrypt(Packet p, int key)
        {
            byte[] data         = p.GetBuffer();
            int    packetLength = data.Length - 4;
            string value;
            int    Lenght;
            byte   BL, DL, CL;
            long   AL;

            value  = data[3].ToString("x2");
            value += data[2].ToString("x2");
            Lenght = Int32.Parse(value, NumberStyles.HexNumber);

            BL = (byte)key;
            CL = data[0];
            AL = Lenght + 4;

            DL      = CL;
            DL      = (byte)(DL - AL);
            DL      = (byte)(DL - BL);
            data[0] = DL;
            DL      = data[1];

            BL      = DL;
            BL      = (byte)(BL - AL);
            BL      = (byte)(BL - CL);
            BL      = (byte)(BL - key);
            data[1] = BL;

            for (int a = 0; a < Lenght; a++)
            {
                BL          = data[a + 4];
                BL          = (byte)(BL - AL);
                BL          = (byte)(BL - DL);
                BL          = (byte)(BL - key);
                DL          = data[a + 4];
                data[a + 4] = BL;
            }
            return(new Packet(data));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Decrypts the given packet 
        /// </summary>
        /// <param name="p">The packet to decrypt</param>
        public static Packet Decrypt(Packet p, int key)
        {
            byte[] data = p.GetBuffer();
            int packetLength = data.Length - 4;
            string value;
            int Lenght;
            byte BL, DL, CL;
            long AL;

            value = data[3].ToString("x2");
            value += data[2].ToString("x2");
            Lenght = Int32.Parse(value, NumberStyles.HexNumber);

            BL = (byte)key;
            CL = data[0];
            AL = Lenght + 4;

            DL = CL;
            DL = (byte)(DL - AL);
            DL = (byte)(DL - BL);
            data[0] = DL;
            DL = data[1];

            BL = DL;
            BL = (byte)(BL - AL);
            BL = (byte)(BL - CL);
            BL = (byte)(BL - key);
            data[1] = BL;

            for (int a = 0; a < Lenght; a++)
            {
                BL = data[a + 4];
                BL = (byte)(BL - AL);
                BL = (byte)(BL - DL);
                BL = (byte)(BL - key);
                DL = data[a + 4];
                data[a + 4] = BL;
            }
            return new Packet(data);
        }
Exemplo n.º 4
0
 public static Packet Normal(Packet p)
 {
     byte[] data = p.GetBuffer();
     return(new Packet(data));
 }
Exemplo n.º 5
0
 public static Packet Normal(Packet p)
 {
     byte[] data = p.GetBuffer();
     return new Packet(data);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Encrypts the given packet
        /// </summary>
        /// <param name="p">The packet to encrypt</param>
        public static Packet Encrypt(Packet p, int key)
        {
            byte[] buffer = p.GetBuffer();
            int packetLength = buffer.Length - 4;
            string value;
            int Lenght;
            byte AL, BL;
            long CX, CL, DL;

            value = buffer[3].ToString("x2");
            value += buffer[2].ToString("x2");
            Lenght = Int32.Parse(value, NumberStyles.HexNumber);

            AL = (byte)key;
            BL = buffer[0];
            CX = Lenght + 4;
            CL = CX;
            DL = CL;

            DL = (byte)(DL + AL);
            BL = (byte)(BL + DL); // First encrypted byte
            buffer[0] = BL;

            DL = (byte)(BL); // DL = Packet first byte
            DL = (byte)(DL + CL); // ADD DL, CL
            DL = (byte)(AL + DL); // ADD DL, AL (gotta parse 1)
            DL = (byte)(DL + buffer[1]);
            buffer[1] = (byte)DL;

            for (int i = 0; i < packetLength; i++)
            {
                BL = (byte)(CL);
                BL = (byte)(DL + BL);
                BL = (byte)(AL + BL);
                BL = (byte)(BL + buffer[i + 4]);

                buffer[i + 4] = BL;
                DL = BL;
            }

            return new Packet(buffer);
        }
Exemplo n.º 7
0
        private void HandlePacket(Packet p)
        {
            int curByte = 0;
            int maxByte = p.Length;

            while (curByte < maxByte)
            {
                int parsedLength = p.ReadShort((curByte + 2)) + 4;
                byte[] parsed = new byte[parsedLength];

                // read bytes from buffer to parsed packets.
                for (int i = 0; i < parsed.Length; i++)
                {
                    parsed[i] = p.GetBuffer()[i + curByte];
                }

                // decrypt those bytes as a new real deal parsed packet
                Packet Parsed = Packet.Decrypt(new Packet(parsed), key);
                curByte += parsedLength;

                PacketIds PI = (PacketIds)Parsed.ReadShort();
                switch (PI)
                {
                    #region Login Recvs
                    case PacketIds.Recv_GameLogin:
                        HandleRecvGameLogin(Parsed);
                        break;

                    case PacketIds.Recv_ConnectWorld:
                        HandleRecvConnectWorld(Parsed);
                        break;

                    #endregion

                    #region World Recvs

                    case PacketIds.RecvUnitLogin:
                        HandleRecvUnitLogin(Parsed);
                        break;

                    case PacketIds.RecvCreateCharacter:
                        HandleRecvCreateCharacter(Parsed);
                        break;

                    case PacketIds.RecvChannelRequest:
                        HandleRecvChannelRequest(Parsed);
                        break;

                    #endregion

                    #region Channel Recvs
                    case PacketIds.RecvPing:
                        // needs check if too fast or so :I
                        break;

                    case PacketIds.RecvChannelLogin:
                        HandleRecvChannelLogin(Parsed);
                        break;

                    case PacketIds.RecvChannelChange:
                        HandleRecvChannelChange(Parsed);
                        break;

                    case PacketIds.RecvChannelSomething:
                        HandleRecvChannelStuff(Parsed);
                        break;

                    case PacketIds.RecvLoadMap:
                        HandleRecvMapRequest(Parsed);
                        break;

                    case PacketIds.RecvRequestSkillList:
                        HandleRecvSkillRequest(Parsed);
                        break;

                    case PacketIds.RecvRequestInventory:
                        HandleRecvInventoryRequest(Parsed);
                        break;

                    case PacketIds.RecvMoveItem:
                        HandleRecvMoveItem(Parsed);
                        break;

                    case PacketIds.RecvDropItem:
                        HandleRecvDropItem(Parsed);
                        break;

                    case PacketIds.RecvPickItem:
                        HandleRecvPickItem(Parsed);
                        break;

                    case PacketIds.RecvImbueItem:
                        HandleRecvImbueItem(Parsed);
                        break;

                    case PacketIds.RecvAcceptImbueItem:
                        HandleRecvAcceptImbueItem(Parsed);
                        break;

                    case PacketIds.RecvNpcTrade:
                        HandleRecvNpcTrade(Parsed);
                        break;

                    case PacketIds.RecvBuyItem:
                        HandleRecvBuyItem(Parsed);
                        break;

                    case PacketIds.RecvSomething:
                        Send(PacketManager.SendSomething());
                        break;

                    case PacketIds.RecvRequestFriendList:
                        Send(PacketManager.SendFriendList());
                        break;

                    case PacketIds.RecvRequestGuildList:
                        // AD GUILD LIST SEND
                        break;

                    case PacketIds.RecvSomething2:
                        Send(PacketManager.SendSomething2());
                        break;

                    case PacketIds.RecvStatRequest:
                        HandleRecvStatRequest(Parsed);
                        break;

                    case PacketIds.RecvSpawnRequest:
                        HandleRecvSpawnRequest(Parsed);
                        break;

                    case PacketIds.RecvSpawnPlayer: // request for other player to spawn
                        HandleRecvSpawnOtherPlayerRequest(Parsed);
                        break;

                    case PacketIds.RecvRequestStats:
                        HandleRecvRequestStats(Parsed);
                        break;

                    case PacketIds.RecvAddStat:
                        HandleRecvAddStat(Parsed);
                        break;

                    case PacketIds.RecvPlayerID:
                        HandleRecvSendPlayerIDRequest(Parsed);
                        break;

                    case PacketIds.RecvStartMoving:
                        HandleRecvStartMoving(Parsed);
                        break;

                    case PacketIds.RecvKeepMoving:
                        HandleRecvKeepMoving(Parsed);
                        break;

                    case PacketIds.RecvStopMoving:
                        HandleRecvStopMoving(Parsed);
                        break;

                    case PacketIds.RecvWalkToPortal:
                        HandleRecvWalkToPortal(Parsed);
                        break;

                    case PacketIds.RecvChatMessage:
                        HandleRecvChatMessage(Parsed);
                        break;

                    case PacketIds.RecvCommand:
                        HandleRecvCommand(Parsed);
                        break;

                    #endregion

                    default:
                        HandleRecvUnknownPacket(Parsed);
                        break; // needs logging system like "packet id received: " then whole buffer like in old one
                }
            }
        }
Exemplo n.º 8
0
        private void HandlePacket(Packet p)
        {
            int curByte = 0;
            int maxByte = p.Length;

            while (curByte < maxByte)
            {
                int parsedLength = p.ReadShort((curByte + 2)) + 4;
                byte[] parsed = new byte[parsedLength];

                // read bytes from buffer to parsed packets.
                for (int i = 0; i < parsed.Length; i++)
                {
                    parsed[i] = p.GetBuffer()[i + curByte];
                }

                // decrypt those bytes as a new real deal parsed packet
                Packet Parsed = Packet.Decrypt(new Packet(parsed), key);
                curByte += parsedLength;

                PacketIds PI = (PacketIds)Parsed.ReadShort();
                switch (PI)
                {
                    #region Login Recvs
                    case PacketIds.Recv_GameLogin:
                        HandleRecvGameLogin(Parsed);
                        break;

                    case PacketIds.Recv_ConnectWorld:
                        HandleRecvConnectWorld(Parsed);
                        break;

                    #endregion

                    #region World Recvs

                    case PacketIds.RecvUnitLogin:
                        HandleRecvUnitLogin(Parsed);
                        break;

                    case PacketIds.RecvCreateCharacter:
                        HandleRecvCreateCharacter(Parsed);
                        break;

                    case PacketIds.RecvChannelRequest:
                        HandleRecvChannelRequest(Parsed);
                        break;

                    #endregion

                    #region Channel Recvs
                    case PacketIds.RecvPing:
                        // needs check if too fast or so :I
                        break;

                    case PacketIds.RecvChannelLogin:
                        HandleRecvChannelLogin(Parsed);
                        break;

                    case PacketIds.RecvChannelChange:
                        HandleRecvChannelChange(Parsed);
                        break;

                    case PacketIds.RecvChannelSomething:
                        HandleRecvChannelStuff(Parsed);
                        break;

                    case PacketIds.RecvLoadMap:
                        HandleRecvMapRequest(Parsed);
                        break;

                    case PacketIds.RecvRequestSkillList:
                        HandleRecvSkillRequest(Parsed);
                        break;

                    case PacketIds.RecvRequestInventory:
                        HandleRecvInventoryRequest(Parsed);
                        break;

                    case PacketIds.RecvRequestOpenWarehouse:
                        HandleRecvOpenWarehouse(Parsed);
                        break;

                    case PacketIds.RecvMoveWarehouseItemToBag:
                        HandleRecvMoveWarehouseItemToBag(Parsed);
                        break;

                    case PacketIds.RecvAddItemToWarehouse:
                        HandleRecvAddItemToWarehouse(Parsed);
                        break;

                    case PacketIds.RecvMoveWarehouseItem:
                        HandleRecvMoveWarehouseItem(Parsed);
                        break;

                    case PacketIds.RecvMoveItem:
                        HandleRecvMoveItem(Parsed);
                        break;

                    case PacketIds.RecvDropItem:
                        HandleRecvDropItem(Parsed);
                        break;

                    case PacketIds.RecvPickItem:
                        HandleRecvPickItem(Parsed);
                        break;

                    case PacketIds.RecvStackItem:
                        HandleRecvStackItem(Parsed);
                        break;

                    case PacketIds.RecvImbueItem:
                        HandleRecvImbueItem(Parsed);
                        break;

                    case PacketIds.RecvAcceptImbueItem:
                        HandleRecvAcceptImbueItem(Parsed);
                        break;

                    case PacketIds.RecvNpcTrade:
                        HandleRecvNpcTrade(Parsed);
                        break;

                    case PacketIds.RecvBuyItem:
                        HandleRecvBuyItem(Parsed);
                        break;

                    case PacketIds.RecvSellItem:
                        HandleRecvSellItem(Parsed);
                        break;

                    case PacketIds.RecvUseItem:
                        HandleRecvUseItem(Parsed);
                        break;

                    case PacketIds.RecvUseRebirthPill:
                        HandleRecvUseRebirthPill(Parsed);
                        break;

                    case PacketIds.RecvTradePlayer:
                        HandleRecvTradePlayer(Parsed);
                        break;

                    case PacketIds.RecvTradePlayerCommands:
                        HandleRecvTradePlayerCommands(Parsed);
                        break;

                    case PacketIds.RecvTradeAddMoney:
                        HandleRecvTradeAddMoney(Parsed);
                        break;

                    case PacketIds.RecvTradeAddItem:
                        HandleRecvTradeAddItem(Parsed);
                        break;

                    case PacketIds.RecvBuyOtherPlayerShopItem:
                        HandleRecvBuyOtherPlayerShopItem(Parsed);
                        break;

                    case PacketIds.RecvShopTakeMoney:
                        HandleRecvShopTakeMoney(Parsed);
                        break;

                    case PacketIds.RecvOpenOtherPlayerShop:
                        HandleRecvOpenOtherPlayerShop(Parsed);
                        break;

                    case PacketIds.RecvShopStartSelling:
                        HandleRecvShopStartSelling(Parsed);
                        break;

                    case PacketIds.RecvAddItemToShop:
                        HandleRecvAddItemToShop(Parsed);
                        break;

                    case PacketIds.RecvMoveShopItem:
                        HandleRecvMoveShopItem(Parsed);
                        break;

                    case PacketIds.RecvMoveShopItemToBag:
                        HandleRecvMoveShopItemToBag(Parsed);
                        break;

                    case PacketIds.RecvChangeShopInfo:
                        HandleRecvChangeShopInfo(Parsed);
                        break;

                    case PacketIds.RecvLearnSkill:
                        HandleRecvLearnSkill(Parsed);
                        break;

                    case PacketIds.RecvQuickSlotRequest:
                        Send(PacketManager.SendQuickSlots(this.MyCharacter));
                        break;

                    case PacketIds.RecvUpdateQuickSlot:
                        HandleRecvUpdateQuickSlot(Parsed);
                        break;

                    case PacketIds.RecvSelectSkill:
                        HandleRecvSelectSkill(Parsed);
                        break;

                    case PacketIds.RecvRequestGuildList:
                        HandleRecvRequestGuild(Parsed);
                        break;

                    case PacketIds.RecvCreateGuild:
                        HandleRecvCreateGuild(Parsed);
                        break;

                    case PacketIds.RecvRequestGuildInformation:
                        HandleRecvRequestGuildInfo(Parsed);
                        break;

                    case PacketIds.RecvRequestGuildMemberStats:
                        HandleRecvRequestGuildMemberStats(Parsed);
                        break;

                    case PacketIds.RecvRequestChangeGuildMemberRank:
                        HandleRecvRequestChangeGuildMemberRank(Parsed);
                        break;

                    case PacketIds.RecvRequestChangeGuildMemberTitle:
                        HandleRecvRequestChangeGuildMemberTitle(Parsed);
                        break;

                    case PacketIds.RecvRequestChangeGuildNotice:
                        HandleRecvRequestChangeGuildNotice(Parsed);
                        break;

                    case PacketIds.RecvRequestJoinGuild:
                        HandleRecvRequestJoinGuild(Parsed);
                        break;

                    case PacketIds.RecvRequestCloseGuild:
                        HandleRecvRequestCloseGuild(Parsed);
                        break;

                    case PacketIds.RecvRequestLeaveGuild:
                        HandleRecvRequestLeaveGuild(Parsed);
                        break;

                    case PacketIds.RecvGuildChat:
                        HandleRecvGuildChat(Parsed);
                        break;

                    case PacketIds.RecvSomething2:
                        Send(PacketManager.SendSomething2());
                        break;

                    case PacketIds.RecvStatRequest:
                        HandleRecvStatRequest(Parsed);
                        break;

                    case PacketIds.RecvSpawnRequest:
                        HandleRecvSpawnRequest(Parsed);
                        break;

                    case PacketIds.RecvSpawnPlayer: // request for other player to spawn
                        HandleRecvSpawnOtherPlayerRequest(Parsed);
                        break;

                    case PacketIds.RecvRequestStats:
                        HandleRecvRequestStats(Parsed);
                        break;

                    case PacketIds.RecvAddStat:
                        HandleRecvAddStat(Parsed);
                        break;

                    case PacketIds.RecvPlayerPetReques:
                        HandleRecvSendPlayerPetRequest(Parsed);
                        break;

                    case PacketIds.RecvStartMoving:
                        HandleRecvStartMoving(Parsed);
                        break;

                    case PacketIds.RecvKeepMoving:
                        HandleRecvKeepMoving(Parsed);
                        break;

                    case PacketIds.RecvStopMoving:
                        HandleRecvStopMoving(Parsed);
                        break;

                    case PacketIds.RecvWalkToPortal:
                        HandleRecvWalkToPortal(Parsed);
                        break;

                    case PacketIds.RecvRequestFriendList:
                        HandleRecvRequestFriendList(Parsed);
                        break;

                    case PacketIds.RecvAddFriend:
                        HandleRecvAddFriend(Parsed);
                        break;

                    case PacketIds.RecvChatMessage:
                        HandleRecvChatMessage(Parsed);
                        break;

                    case PacketIds.RecvCommand:
                        HandleRecvCommand(Parsed);
                        break;

                    case PacketIds.RecvMonsterSpawnRequest:
                        HandleRecvMonsterSpawn(Parsed);
                        break;

                    case PacketIds.RecvUseTeleporter:
                        HandleRecvUseTeleporter(Parsed);
                        break;

                    case PacketIds.RecvAttack1:
                        HandleRecvAttack1(Parsed);
                        break;

                    case PacketIds.RecvAttack2:
                        HandleRecvAttack2(Parsed);
                        break;

                    case PacketIds.RecvCast1:
                        HandleRecvCast1(Parsed);
                        break;

                    case PacketIds.RecvCast2:
                        HandleRecvCast2(Parsed);
                        break;

                    case PacketIds.RecvCombineItems:
                        HandleRecvCombineItems(Parsed);
                        break;

                    case PacketIds.RecvPartyRequest:
                        HandleRecvPartyRequest(Parsed);
                        break;

                    case PacketIds.RecvLeaveParty:
                        HandleRecvLeaveParty(Parsed);
                        break;

                    case PacketIds.RecvChangePartyLeader:
                        HandleRecvChangePartyLeader(Parsed);
                        break;

                    case PacketIds.RecvAddToPartyRequest:
                        HandleRecvAddToParty(Parsed);
                        break;

                    case PacketIds.RecvPetStartMoving:
                        HandleRecvPetStartMoving(Parsed);
                        break;

                    case PacketIds.RecvPetKeepMoving:
                        HandleRecvPetKeepMoving(Parsed);
                        break;

                    case PacketIds.RecvPetStopMoving:
                        HandleRecvPetStopMoving(Parsed);
                        break;

                    case PacketIds.RecvKillPet:
                        HandleRecvKillPet(Parsed);
                        break;

                    case PacketIds.RecvBaitPet:
                        HandleRecvBaitPet(Parsed);
                        break;

                    case PacketIds.RecvRequestPetStats:
                        HandleRecvRequestPetStats(Parsed);
                        break;

                    case PacketIds.RecvRequestSpawnOtherPet:
                        HandleRecvSpawnOtherPet(Parsed);
                        break;

                    case PacketIds.RecvResurrectPet:
                        HandleRecvResurrectPet(Parsed);
                        break;

                    case PacketIds.RecvRenamePet:
                        HandleRecvRenamePet(Parsed);
                        break;

                    case PacketIds.RecvSendPetToMe:
                        HandleRecvSendPetToMe(Parsed);
                        break;

                    case PacketIds.RecvTradePet:
                        HandleRecvTradePet(Parsed);
                        break;

                    case PacketIds.RecvTradePetAmount:
                        HandleRecvTradePetAmount(Parsed);
                        break;

                    case PacketIds.RecvSealPet:
                        HandleRecvSealPet(Parsed);
                        break;

                    case PacketIds.RecvUnSealPet:
                        HandleRecvUnSealPet(Parsed);
                        break;

                    case PacketIds.RecvQuestListRequest:
                         List<QuestObject> objects = new List<QuestObject>();
                        objects.Add(new QuestObject(QuestObjectType.Hunt, 0, 5, 0));
                        objects.Add(new QuestObject(QuestObjectType.Hunt, 1, 5, 0));
                        objects.Add(new QuestObject(QuestObjectType.Hunt, 2, 5, 0));
                        objects.Add(new QuestObject(QuestObjectType.Join_Party, 0, 1, 1));
                        objects.Add(new QuestObject(QuestObjectType.Level_Up, 0, 5, 1));
                        objects.Add(new QuestObject(QuestObjectType.Obtain_Money, 0, 1000, 2));

                        List<QuestReward> rewards = new List<QuestReward>();
                        rewards.Add(new QuestReward(0, 23273, 10, QuestRewardType.PlusItem));
                        rewards.Add(new QuestReward(1, 20041, 10, QuestRewardType.Item));
                        rewards.Add(new QuestReward(2, 0, 1000, QuestRewardType.Money));
                        rewards.Add(new QuestReward(2, 0, 1, QuestRewardType.Fame));

                        Quest quest = new Quest
                        {
                            Name = "Fate and Meeting!",
                            ID = 1009,
                            Objectives = objects,
                            Rewards = rewards,
                            CurrentObjective = 2,
                            State = QuestState.Started
                        };

                        Send(PacketManager.SendQuestList(quest));
                        break;

                    case PacketIds.RecvPetRequestItems:
                        // this should send the equips and items in bag but without having anythign on it wont send anything
                        break;

                    case PacketIds.RecvRequestDeath:
                        HandleRecvRequestDeath(Parsed);
                        break;

                    #endregion

                    default:
                        HandleRecvUnknownPacket(Parsed);
                        break; // needs logging system like "packet id received: " then whole buffer like in old one
                }
            }
        }