Exemplo n.º 1
0
        private void buttonLoadPacket_Click(object o)
        {
            var openFileDialog = new OpenFileDialog
            {
                Filter      = "All Files|*.*",
                Multiselect = false
            };
            var showDialog = openFileDialog.ShowDialog();

            if (showDialog == null || !(bool)showDialog)
            {
                return;
            }

            var packet     = new BDPacket(File.ReadAllBytes(openFileDialog.FileName));
            var packetBody = packet.ToArray().Extract(2);

            if (packet.IsEncrypted)
            {
                if (packetTransformer != null)
                {
                    packetTransformer.Transform(ref packetBody, 0, true);
                }
                else
                {
                    MessageBox.Show("You need to specify the encryption packet first in order to decrypt encrypted packets.", "Encryption packet required", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }

            FormatPacket(new BDPacket(packet.ToArray().Extract(0, 2).Concat(packetBody).ToArray()));
        }
Exemplo n.º 2
0
        public static void CreateWorldNotice(string message)
        {
            using (var packet = new BDPacket())
            {
                packet.AddUShort(0);
                packet.AddBool(false);
                packet.AddUShort(0);
                packet.AddUShort(0xEAF);

                packet.AddByte(1);
                packet.AddByte(1);
                packet.AddInt(0);                                     // session id?
                packet.AddString(string.Empty, Encoding.Unicode, 62); // character name
                packet.AddByte(1);
                packet.AddByte(1);
                packet.AddByte(1);

                byte[] bMessage = Encoding.Unicode.GetBytes(message);
                var    len      = bMessage.Length + 2;
                packet.AddUShort((ushort)len);
                packet.AddBytes(bMessage);
                packet.AddBytes("0000");

                packet.SetUShort(packet.Length, 0);

                MainContext.gameProxy.SendToGame(packet);
            }
        }
Exemplo n.º 3
0
        private void LoginProxy_GameToServerPacket(object sender, BDPacket e)
        {
            foreach (Script plugin in scriptController.Scripts)
            {
                e = plugin.Login_CMSG(e);
            }

            MainContext.loginProxy.SendToServer(e);
        }
Exemplo n.º 4
0
        private void GameProxy_ServerToGamePacket(object sender, BDPacket e)
        {
            foreach (Script plugin in scriptController.Scripts)
            {
                e = plugin.Game_SMSG(e);
            }

            MainContext.gameProxy.SendToGame(e);
        }
Exemplo n.º 5
0
        public override BDPacket Game_SMSG(BDPacket packet)
        {
            if (PacketProcessor.ServerMessages.Packets.Any(t => t.Id == packet.PacketId))
            {
                Console.WriteLine("{0}", PacketProcessor.ServerMessages.Packets.Where(t => t.Id == packet.PacketId).First().Name);
            }

            return(base.Game_SMSG(packet));
        }
Exemplo n.º 6
0
        private async Task StartReceive(Socket socket, int needed, bool SMSG)
        {
            try
            {
                var buffer = new byte[needed];
                Buffer.BlockCopy(BitConverter.GetBytes(needed), 0, buffer, 0, 2);

                var bytesRead = 2;
                while (bytesRead < needed)
                {
                    var bytesReceived =
                        await ReceiveAsyncTask(socket, buffer, bytesRead, needed - bytesRead).ConfigureAwait(false);

                    bytesRead += bytesReceived;

                    if (bytesReceived <= 0)
                    {
                        break;
                    }
                }

                await Task.Factory.StartNew(() =>
                {
                    BDPacket packet = ProcessPacket(buffer);
                    if (SMSG)
                    {
                        if (ServerToGamePacket != null)
                        {
                            ServerToGamePacket(this, packet);
                        }
                    }
                    else
                    {
                        if (GameToServerPacket != null)
                        {
                            GameToServerPacket(this, packet);
                        }
                    }
                });
            }
            catch (Exception e)
            {
                Logger.Log("Server", "{0}", Logger.LogLevel.Error, e);
            }

            if (SMSG)
            {
                socket.BeginReceive(SMSG_Buffer, 0, 2, SocketFlags.None, new AsyncCallback(serverReceivedCallback), null);
            }
            else
            {
                socket.BeginReceive(CMSG_Buffer, 0, 2, SocketFlags.None, new AsyncCallback(connectionReceiveCallback), null);
            }
        }
Exemplo n.º 7
0
        private void FormatPacket(BDPacket packet)
        {
            var b = new StringBuilder();

            b.AppendLine($"Size: {packet.Length}");
            b.AppendLine($"OpCode: 0x{packet.PacketId:X4}");
            b.AppendLine($"Encrypted: {packet.IsEncrypted}");
            if (packet.IsEncrypted)
            {
                b.AppendLine($"SequenceId: {packet.SequenceId}");
            }
            b.AppendLine();
            b.Append(packet.ToArray().FormatHex());
            txtPacketView = b.ToString();
        }
Exemplo n.º 8
0
        private BDPacket ProcessPacket(byte[] buffer)
        {
            var packet = new BDPacket(buffer);

            if (packet.PacketId == 0x03EB)
            {
                cryptoTransformer = new BDTransformer(packet.ToArray().Extract(5));
            }

            if (packet.IsEncrypted)
            {
                packet.Transform(ref cryptoTransformer, false);
            }

            return(packet);
        }
Exemplo n.º 9
0
        public void SendToGame(BDPacket packet)
        {
            if (packet == null)
            {
                return;
            }

            if (packet.IsEncrypted)
            {
                packet.Transform(ref cryptoTransformer, true);
            }

            connectionSocket.BeginSend(packet.ToArray(), 0, packet.Length, SocketFlags.None, ar =>
            {
                connectionSocket.EndSend(ar);
            }, null);
        }
Exemplo n.º 10
0
        private void GameProxy_GameToServerPacket(object sender, BDPacket e)
        {
            foreach (Script plugin in scriptController.Scripts)
            {
                e = plugin.Game_CMSG(e);
            }

            if (e.PacketId == 0xCEE)
            {
                MainContext.IsPlayerIngame = true;
            }

            if (e.PacketId == 0xEA8)
            {
                var    messageLen = e.GetUShort(11) - 2;
                string message    = e.GetString(Encoding.Unicode, messageLen, 13);

                if (message.StartsWith("/"))
                {
                    string commandName = message.Replace("/", "").Split(' ')[0];

                    List <Command> list = new List <Command>(CommandProcessor.GetCommandsByName(commandName));
                    if (list.Count > 0)
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            var      command    = list[i];
                            string[] parameters = message.Replace("/", "").Split(' ');
                            command.Parameters.Clear();
                            for (int j = 1; j < parameters.Length; j++)
                            {
                                command.Parameters.Add(parameters[j]);
                            }
                            command.Callback(command);
                        }
                    }
                    else
                    {
                        WorldProcessor.CreateWorldNotice("[CommandProcessor] Command does not exist.");
                    }
                    return;
                }
            }
            MainContext.gameProxy.SendToServer(e);
        }
Exemplo n.º 11
0
        private void buttonLoadCryptoPacket_Click(object o)
        {
            var openFileDialog = new OpenFileDialog
            {
                Filter      = "All Files|*.*",
                Multiselect = false
            };
            var showDialog = openFileDialog.ShowDialog();

            if (showDialog == null || !(bool)showDialog)
            {
                return;
            }

            var packet = new BDPacket(File.ReadAllBytes(openFileDialog.FileName));

            packetTransformer = new BDTransformer(packet.ToArray().Extract(5));
        }
Exemplo n.º 12
0
        public override BDPacket Login_SMSG(BDPacket packet)
        {
            if (packet.PacketId == 0x0C82)
            {
                var p = new BDPacket();
                p.AddUShort(0);  // changeto length later
                p.AddBool(true); // is encrypted
                p.AddUShort(packet.SequenceId);
                p.AddUShort(packet.PacketId);

                p.AddInt(0);           // unk
                p.AddLong(1457907576); // time?

                p.AddShort(1);         // server count


                p.AddShort(1);                                                              // channel id
                p.AddShort(1);                                                              // server id
                p.AddShort(16384);                                                          // ranodm value,

                p.AddString(Config.GetValue <string>("ChannelName"), Encoding.Unicode, 62); // channel name
                p.AddString(Config.GetValue <string>("ServerName"), Encoding.Unicode, 62);  // server name

                p.AddByte(0);
                p.AddString("127.0.0.1", Encoding.ASCII, 16);
                p.AddByte(0);

                p.AddBytes(new byte[84]);

                p.AddShort(8889); // server port

                p.AddByte(1);     // population status
                p.AddByte(1);     // can joined by public?
                p.AddByte(1);     // unk

                p.AddByte(0);     // characters
                p.AddByte(0);     // characters to be deleted lol

                p.AddShort(0);    // dunno

                p.AddLong(0);
                p.AddLong(0);

                p.AddByte(0); // exp drop bonus?

                p.AddBytes(new byte[13]);

                p.AddByte(0);

                p.SetUShort(p.Length, 0);

                Logger.Log("ServerListHook", "modified server list packet!");

                return(p);
            }


            //if(packet.PacketId == 0xc82)
            //{

            //    ushort realmCount = packet.GetUShort(19);

            //    Console.WriteLine(realmCount);
            //    int index = 21;

            //    string edan="";
            //    string orwen ="";
            //    string uno="";
            //    string croxus="";
            //    string jordine ="";
            //    string alustin="";
            //    for(int i = 0; i < realmCount; i++)
            //    {
            //        string channelName = packet.GetString(Encoding.Unicode, 62, index + 6);
            //        channelName = channelName.Split('\0')[0];

            //        string servername = packet.GetString(Encoding.Unicode, 62, index + 6 + 62);
            //        servername = servername.Split('\0')[0];

            //        string ip = packet.GetString(Encoding.ASCII, 16, index + 6 + 62 + 62 + 1);
            //        ip = ip.Split('\0')[0];

            //        Console.WriteLine(channelName + " - " + servername + " - " + ip);

            //        if(servername=="Edan")
            //        {
            //            edan += string.Format("Channels.Add(new KeyValuePair<string, string>(\"{0}\", \"{1}\"));{2}", channelName, ip, Environment.NewLine);
            //        }
            //        if(servername == "Orwen")
            //        {
            //            orwen += string.Format("Channels.Add(new KeyValuePair<string, string>(\"{0}\", \"{1}\"));{2}", channelName, ip, Environment.NewLine);
            //        }
            //        if(servername == "Uno")
            //        {
            //            uno += string.Format("Channels.Add(new KeyValuePair<string, string>(\"{0}\", \"{1}\"));{2}", channelName, ip, Environment.NewLine);
            //        }

            //        if(servername == "Croxus")
            //        {
            //            croxus += string.Format("Channels.Add(new KeyValuePair<string, string>(\"{0}\", \"{1}\"));{2}", channelName, ip, Environment.NewLine);
            //        }
            //        if(servername == "Jordine")
            //        {
            //            jordine += string.Format("Channels.Add(new KeyValuePair<string, string>(\"{0}\", \"{1}\"));{2}", channelName, ip, Environment.NewLine);
            //        }
            //        if(servername == "Alustin")
            //        {
            //            alustin += string.Format("Channels.Add(new KeyValuePair<string, string>(\"{0}\", \"{1}\"));{2}", channelName, ip, Environment.NewLine);
            //        }

            //        index += 272;
            //    }

            //    File.WriteAllText("C:\\Users\\Johannes\\Desktop\\Edan.txt", edan);
            //    File.WriteAllText("C:\\Users\\Johannes\\Desktop\\Orwen.txt", orwen);
            //    File.WriteAllText("C:\\Users\\Johannes\\Desktop\\Uno.txt", uno);
            //    File.WriteAllText("C:\\Users\\Johannes\\Desktop\\Croxus.txt", croxus);
            //    File.WriteAllText("C:\\Users\\Johannes\\Desktop\\Jordine.txt", jordine);
            //    File.WriteAllText("C:\\Users\\Johannes\\Desktop\\Alustin.txt", alustin);
            //}


            return(packet);
        }
Exemplo n.º 13
0
 /// <summary>
 /// Emulates a gameserver packet to official server.
 /// </summary>
 /// <param name="packet"></param>
 public void SendGamePacketToServer(BDPacket packet)
 {
     MainContext.gameProxy.SendToServer(packet);
 }
Exemplo n.º 14
0
 /// <summary>
 /// Emulates a loginserver packet to official server.
 /// </summary>
 /// <param name="packet"></param>
 public void SendLoginPacketToServer(BDPacket packet)
 {
     MainContext.loginProxy.SendToServer(packet);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Emulates a loginserver packet to the game.
 /// </summary>
 /// <param name="packet"></param>
 public void SendLoginPacketToGame(BDPacket packet)
 {
     MainContext.loginProxy.SendToGame(packet);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Occurs when receiving a game packet from game.
 /// </summary>
 /// <param name="packet"></param>
 /// <returns>The modified packet and redirects it to official server.</returns>
 public virtual BDPacket Game_CMSG(BDPacket packet)
 {
     return(packet);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Occurs when receiving a login packet from game.
 /// </summary>
 /// <param name="packet"></param>
 /// <returns>The modified packet and redirects it to official server.</returns>
 public virtual BDPacket Login_CMSG(BDPacket packet)
 {
     return(packet);
 }