Example #1
0
        public void SendMessage(ChatType type, Character Destination, string message)
        {
            GameWriter gw = new GameWriter(gameData);
            gw.writeB(PacketList.Client.Say2);
            gw.writeS(message);
            gw.writeD((byte)type);

            if(type == ChatType.Private)
                gw.writeS(Destination.Name);
            gw.Encrypt();
            outBuffer.Push(gw.Finalize());
        }
Example #2
0
        public override void DataReceived(ref byte[] inputPacket)
        {
            if (gameData.CryptIn == null)
            {
                #region GameServer Auth stuff
                byte[] game_key = new byte[16];
                game_key[0] = inputPacket[4];
                game_key[1] = inputPacket[5];
                game_key[2] = inputPacket[6];
                game_key[3] = inputPacket[7];
                game_key[4] = inputPacket[8];
                game_key[5] = inputPacket[9];
                game_key[6] = inputPacket[10];
                game_key[7] = inputPacket[11];
                game_key[8] = 0xc8;
                game_key[9] = 0x27;
                game_key[10] = 0x93;
                game_key[11] = 0x01;
                game_key[12] = 0xa1;
                game_key[13] = 0x6c;
                game_key[14] = 0x31;
                game_key[15] = 0x97;
                gameData.CryptIn = new GameCrypt();
                gameData.CryptOut = new GameCrypt();
                gameData.CryptIn.setKey(game_key);
                gameData.CryptOut.setKey(game_key);

                int offset = 0;
                byte[] buff = new byte[1024];

                buff[offset++] = 0x2B;
                for (int i = 0; i < UserConfig.Username.Length; i++)
                {
                    buff[offset++] = (byte)UserConfig.Username[i];
                    buff[offset++] = 0x00;
                }
                buff[offset++] = 0x00;
                buff[offset++] = 0x00;
                buff[offset++] = gameData.PlayOK[4];
                buff[offset++] = gameData.PlayOK[5];
                buff[offset++] = gameData.PlayOK[6];
                buff[offset++] = gameData.PlayOK[7];
                buff[offset++] = gameData.PlayOK[0];
                buff[offset++] = gameData.PlayOK[1];
                buff[offset++] = gameData.PlayOK[2];
                buff[offset++] = gameData.PlayOK[3];
                buff[offset++] = gameData.LoginOK[0];
                buff[offset++] = gameData.LoginOK[1];
                buff[offset++] = gameData.LoginOK[2];
                buff[offset++] = gameData.LoginOK[3];
                buff[offset++] = gameData.LoginOK[4];
                buff[offset++] = gameData.LoginOK[5];
                buff[offset++] = gameData.LoginOK[6];
                buff[offset++] = gameData.LoginOK[7];
                buff[offset++] = 0x01;
                buff[offset++] = 0x00;
                buff[offset++] = 0x00;
                buff[offset++] = 0x00;
                buff[offset++] = 0x30;
                buff[offset++] = 0x01;
                buff[offset++] = 0x00;
                buff[offset++] = 0x00;
                for (int x = 0; x < 10; x++)
                    buff[offset++] = 0x00;

                byte[] realBuffer = new byte[offset];
                for (int i = 0; i < realBuffer.Length; i++)
                    realBuffer[i] = buff[i];

                GameWriter pck = new GameWriter(realBuffer, gameData);
                pck.Encrypt();
                byte[] bytes = pck.Finalize();
                Send(bytes);
                Debug.Information("Authenticating with the GameServer.");
                #endregion
            }
            else
            {
                GameReader packet = new GameReader(inputPacket, gameData);
                packet.Decrypt();
                PacketList.Server opcode = (PacketList.Server)packet.readB();

                if (opcode == PacketList.Server.DummyPacket)
                {
                    opcode = (PacketList.Server)BitConverter.ToUInt16(new byte[] {(byte)opcode, packet.readB()}, 0);
                }

                switch (opcode)
                {
                    case PacketList.Server.CharacterSelectionInfo:
                        if (!CallPlugin_HandlePacket(opcode, packet))
                        {
                            Debug.Information("Selecting the character specified in the config.");
                            GameWriter pw = new GameWriter(gameData);
                            pw.writeB(PacketList.Client.CharacterSelect);
                            pw.writeD(Int32.Parse(UserConfig.Toon) - 1);
                            pw.writeB(General.Hex("00 00 00 00 00 00 00 00 00 00 00 00 00 00"));
                            pw.Encrypt();
                            Send(pw.Finalize());
                        }
                        else
                        {
                            Debug.Information("The 'CharacterSelectionInfo' packet was overridden by a plugin.");
                        }
                        break;
                    case PacketList.Server.CharacterSelectedPacket:
                        if (!CallPlugin_HandlePacket(opcode, packet))
                        {
                            byte[] EnterWorldPacket = General.Hex(PacketList.EnterWorld);
                            GameWriter gw = new GameWriter(EnterWorldPacket, gameData);
                            gw.Encrypt();
                            Send(gw.Finalize());
                            Debug.Information("Character selected, entering world...");
                            CallPlugin_HandlePacket(opcode, packet);
                        }
                        else
                        {
                            Debug.Information("The 'CharacterSelectedPacket' packet was overridden by a plugin.");
                        }
                        break;
                    default:
                        CallPlugin_HandlePacket(opcode, packet);
                        break;
                }
            }
        }