// Connect button click private void dlgConnect_Click(object sender, EventArgs e) { connection_ = new Connection(); connection_.connect("83.171.11.57", 2106);//178.162.166.11 // l2_client_.Connect("178.162.166.11", 2106); // recv_send_stream_ = l2_client_.GetStream(); // int byte_count = recv_send_stream_.Read(data_buffer_, 0, 65533); //#if DEBUG // output_.output_debug("-client-recv[" + byte_count + "]: "); // output_.output_debug(data_buffer_, byte_count); //#endif // blowfish_cipher_.init(false, blowfish_key_); // blowfish_cipher_.processBigBlock(data_buffer_, 0x02, decoded_buffer_, 0x00, byte_count - 2); // Global.decXORPass(decoded_buffer_, 0x00, byte_count - 2, // System.BitConverter.ToInt32(decoded_buffer_, byte_count - 10)); // RSA_key_[0] = decoded_buffer_[1]; // RSA_key_[1] = decoded_buffer_[2]; // RSA_key_[2] = decoded_buffer_[3]; // RSA_key_[3] = decoded_buffer_[4]; // for (int i = 0; i < 128; i++) // { // RSA_enc_key_[i] = decoded_buffer_[9 + i]; // } // for (int i = 0; i < 0x40; i++) // { // RSA_enc_key_[0x40 + i] = (byte)(RSA_enc_key_[0x40 + i] ^ RSA_enc_key_[i]); // } // for (int i = 0; i < 4; i++) // { // RSA_enc_key_[0x0d + i] = (byte)(RSA_enc_key_[0x0d + i] ^ RSA_enc_key_[0x34 + i]); // } // // step 2 : xor first 0x40 bytes with last 0x40 bytes // for (int i = 0; i < 0x40; i++) // { // RSA_enc_key_[i] = (byte)(RSA_enc_key_[i] ^ RSA_enc_key_[0x40 + i]); // } // // step 1 : 0x4d-0x50 <-> 0x00-0x04 // for (int i = 0; i < 4; i++) // { // byte temp = RSA_enc_key_[0x00 + i]; // RSA_enc_key_[0x00 + i] = RSA_enc_key_[0x4D + i]; // RSA_enc_key_[0x4d + i] = temp; // } //#if DEBUG // output_.output_debug("-client-recv-dec: "); // output_.output_debug(decoded_buffer_, byte_count); //#endif // for (int i = 0; i < 16; i++) // blowfish_key_[i] = decoded_buffer_[i + 153]; //#if DEBUG // output_.output_debug("-client-new-blowfish-key: "); // output_.output_debug(blowfish_key_, 16); // output_.output_debug("-client-RSA-key: "); // output_.output_debug(RSA_enc_key_, 128); // output_.output_debug("-client-GameGuard-packet"); //#endif // // wtf Oo (?) // byte[] send_packet = new byte[40]; // byte[] pre_send_packet = new byte[40]; // send_packet[0] = 0x07; // Request GG packet // send_packet[1] = RSA_key_[0]; // send_packet[2] = RSA_key_[1]; // send_packet[3] = RSA_key_[2]; // send_packet[4] = RSA_key_[3]; // game_guard_fill(send_packet, 0x05); // ulong checksum = Global.CheckSum(send_packet, 0x18); // send_packet[24] = (byte)(checksum & 0xff); // send_packet[25] = (byte)(checksum >> 0x08 & 0xff); // send_packet[26] = (byte)(checksum >> 0x10 & 0xff); // send_packet[27] = (byte)(checksum >> 0x18 & 0xff); // blowfish_cipher_.init(true, blowfish_key_); // blowfish_cipher_.processBigBlock(send_packet, 0, pre_send_packet, 0, 40); // byte[] out_packet = new byte[42]; // out_packet[0] = 0x2A; // out_packet[1] = 0x00; // pre_send_packet.CopyTo(out_packet, 2); // recv_send_stream_.Write(out_packet, 0, 42); // byte_count = recv_send_stream_.Read(data_buffer_, 0, 65533); //#if DEBUG // output_.output_debug("-client-recv-GOOD?[" + byte_count + "]: "); // output_.output_debug(data_buffer_, byte_count); //#endif // blowfish_cipher_.init(false, blowfish_key_); // blowfish_cipher_.processBigBlock(data_buffer_, 2, decoded_buffer_, 0, byte_count - 2); // //Global.decXORPass(decoded_buffer_, 0x00, byte_count - 2, // // System.BitConverter.ToInt32(decoded_buffer_, byte_count - 10)); //#if DEBUG // output_.output_debug("-client-recv-decGOOD?++++: "); // output_.output_debug(decoded_buffer_, byte_count); //#endif }
// Main processor public void process_packet(byte[] data_buffer, int packet_lenght, Socket socket) { if (first_packet_ && login_) { process_first_packet(data_buffer, packet_lenght, socket); } else { if (login_) { blowfish_cipher_.init(false, blowfish_key_); blowfish_cipher_.processBigBlock(data_buffer, 0x02, decoded_buffer_, 0x00, packet_lenght - 2); output_.output_debug("-server: packet code: "); output_.output_debug(decoded_buffer_, 1); output_.output_debug("\n"); switch (decoded_buffer_[0]) { case 0x0B: output_.output_debug("-client: login packet\n"); craft_login_packet(socket); break; case 0x03: output_.output_debug("-client: login accepted.\n"); craft_login_ok_packet(socket, decoded_buffer_); break; case 0x01: output_.output_debug("-client: login fail.\n"); break; case 0x04: output_.output_debug("-server: total servers: "); output_.output_debug(decoded_buffer_[1].ToString()); output_.output_debug("\n"); craft_select_server_packet(socket, decoded_buffer_); break; case 0x07: output_.output_debug("-server: server selected.\n-client: connecting to game server\n"); play_ok_[0] = decoded_buffer_[1]; play_ok_[1] = decoded_buffer_[2]; play_ok_[2] = decoded_buffer_[3]; play_ok_[3] = decoded_buffer_[4]; play_ok_[4] = decoded_buffer_[5]; play_ok_[5] = decoded_buffer_[6]; play_ok_[6] = decoded_buffer_[7]; play_ok_[7] = decoded_buffer_[8]; play_ok_[8] = decoded_buffer_[9]; login_ = false; socket.Close(); connection_.connect("178.162.141.22", 2106); craft_gameserver_protocol_packet(connection_.socket_); break; } } else { Buffer.BlockCopy(data_buffer, 2, data_buffer, 0, packet_lenght - 2); output_.output_debug("-server: GS packet code: "); output_.output_debug(data_buffer, 1); output_.output_debug("\n"); switch (data_buffer[0]) { case 0x2E: output_.output_debug("-server: auth key packet\n"); break; } } } }