Advertisement
Guest User

Untitled

a guest
Jul 30th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.16 KB | None | 0 0
  1. namespace Clientless_login
  2. {
  3.     using SilkroadSecurityApi;
  4.     using System;
  5.     using System.Collections.Generic;
  6.     using System.Drawing;
  7.     using System.Net.Sockets;
  8.     using System.Threading;
  9.  
  10.     public class Agent
  11.     {
  12.         private static List<Packet> ag_packets = new List<Packet>();
  13.         private static TransferBuffer ag_recv_buffer = new TransferBuffer(0x1000, 0, 0);
  14.         private static Security ag_security = new Security();
  15.         private static Socket ag_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  16.         private static uint locale = uint.Parse(Globals.MainWindow.slocale.Text);
  17.         private static uint loginID;
  18.         private static Thread loop;
  19.         private static string password;
  20.         private static string username;
  21.         private static uint version = uint.Parse(Globals.MainWindow.sversion.Text);
  22.  
  23.         public void Agent_thread()
  24.         {
  25.             while (true)
  26.             {
  27.                 SocketError success;
  28.                 Packet current;
  29.                 byte[] bytes;
  30.                 ag_recv_buffer.Size = ag_socket.Receive(ag_recv_buffer.Buffer, 0, ag_recv_buffer.Buffer.Length, SocketFlags.None, out success);
  31.                 if (success != SocketError.Success)
  32.                 {
  33.                     if (success != SocketError.WouldBlock)
  34.                     {
  35.                         return;
  36.                     }
  37.                 }
  38.                 else if (ag_recv_buffer.Size > 0)
  39.                 {
  40.                     ag_security.Recv(ag_recv_buffer);
  41.                 }
  42.                 else
  43.                 {
  44.                     return;
  45.                 }
  46.                 List<Packet> collection = ag_security.TransferIncoming();
  47.                 if (collection != null)
  48.                 {
  49.                     ag_packets.AddRange(collection);
  50.                 }
  51.                 if (ag_packets.Count > 0)
  52.                 {
  53.                     using (List<Packet>.Enumerator enumerator = ag_packets.GetEnumerator())
  54.                     {
  55.                         while (enumerator.MoveNext())
  56.                         {
  57.                             current = enumerator.Current;
  58.                             bytes = current.GetBytes();
  59.                             if (current.Opcode == 0x3026)
  60.                             {
  61.                                 string str3;
  62.                                 string str4;
  63.                                 switch (current.ReadUInt8())
  64.                                 {
  65.                                     case 2:
  66.                                         this.test("[PM] " + current.ReadAscii() + ": " + current.ReadAscii(), Color.LightBlue, new object[0]);
  67.                                         break;
  68.  
  69.                                     case 6:
  70.                                         str3 = current.ReadAscii();
  71.                                         str4 = current.ReadAscii();
  72.                                         this.test("[GLOBAL] " + str3 + ": " + str4, Color.Yellow, new object[0]);
  73.                                         break;
  74.  
  75.                                     case 1:
  76.                                     {
  77.                                         uint num2 = current.ReadUInt32();
  78.                                         string str5 = current.ReadAscii();
  79.                                         this.test(string.Concat(new object[] { "[Public] (ID:", num2, ") : ", str5 }), Color.White, new object[0]);
  80.                                         break;
  81.                                     }
  82.                                     case 3:
  83.                                     {
  84.                                         uint num3 = current.ReadUInt32();
  85.                                         string str6 = current.ReadAscii();
  86.                                         this.test(string.Concat(new object[] { "[GM]  (ID:", num3, ") - ", str6, ": " }), Color.Red, new object[0]);
  87.                                         break;
  88.                                     }
  89.                                     case 4:
  90.                                         str3 = current.ReadAscii();
  91.                                         str4 = current.ReadAscii();
  92.                                         this.textdata("[PARTY]" + str3 + ": " + str4, new object[0]);
  93.                                         break;
  94.  
  95.                                     case 5:
  96.                                         str3 = current.ReadAscii();
  97.                                         this.textdata("[GUILD]" + str3 + ": " + current.ReadAscii(), new object[0]);
  98.                                         break;
  99.  
  100.                                     case 7:
  101.                                         this.test("[Notice]" + current.ReadAscii(), Color.HotPink, new object[0]);
  102.                                         break;
  103.                                 }
  104.                             }
  105.                             if (((current.Opcode == 0x2113) && (current.ReadUInt8() == 1)) && Globals.MainWindow.checkBox1.Checked)
  106.                             {
  107.                                 this.Meldung("Xtrap packet was sent !", new object[0]);
  108.                                 Packet packet = new Packet(0);
  109.                                 packet.WriteUInt8((byte) 1);
  110.                                 packet.WriteUInt8((byte) 1);
  111.                                 Send(packet);
  112.                             }
  113.                             if (current.Opcode == 0x3013)
  114.                             {
  115.                                 this.Meldung("Spawned successfully !", new object[0]);
  116.                             }
  117.                             if ((current.Opcode == 0x3017) && (current.ReadUInt8() == 2))
  118.                             {
  119.                                 Packet packet3 = new Packet(0x34b6);
  120.                                 Send(packet3);
  121.                             }
  122.                             this.Log("[S->C][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", new object[] { current.Opcode, bytes.Length, current.Encrypted ? "[Encrypted]" : "", current.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(bytes), Environment.NewLine });
  123.                             if ((current.Opcode != 0x5000) && (current.Opcode != 0x9000))
  124.                             {
  125.                                 Packet packet4;
  126.                                 Packet packet5;
  127.                                 Packet packet6;
  128.                                 if (current.Opcode == 0x2001)
  129.                                 {
  130.                                     if (current.ReadAscii() == "GatewayServer")
  131.                                     {
  132.                                         Globals.Server = Globals.ServerEnum.Gateway;
  133.                                         packet4 = new Packet(0x6100, true, false);
  134.                                         packet4.WriteUInt8(locale);
  135.                                         packet4.WriteAscii("SR_Client");
  136.                                         packet4.WriteUInt32(version);
  137.                                         ag_security.Send(packet4);
  138.                                     }
  139.                                     else
  140.                                     {
  141.                                         Globals.Server = Globals.ServerEnum.Agent;
  142.                                         packet5 = new Packet(0x6103);
  143.                                         packet5.WriteUInt32(loginID);
  144.                                         packet5.WriteAscii(username);
  145.                                         packet5.WriteAscii(password);
  146.                                         packet5.WriteUInt8((byte) 0x16);
  147.                                         packet5.WriteUInt32((uint) 0);
  148.                                         packet5.WriteUInt16((ushort) 0);
  149.                                         ag_security.Send(packet5);
  150.                                     }
  151.                                 }
  152.                                 else if (current.Opcode == 0xa103)
  153.                                 {
  154.                                     if (current.ReadUInt8() == 1)
  155.                                     {
  156.                                         packet4 = new Packet(0x7007);
  157.                                         packet4.WriteUInt8((byte) 2);
  158.                                         ag_security.Send(packet4);
  159.                                     }
  160.                                 }
  161.                                 else if (current.Opcode == 0xb007)
  162.                                 {
  163.                                     Login.HandleCharList(current);
  164.                                 }
  165.                                 else if (current.Opcode == 0x3020)
  166.                                 {
  167.                                     packet5 = new Packet(0x3012);
  168.                                     Send(packet5);
  169.                                 }
  170.                        
  171.                             }
  172.                         }
  173.                     }
  174.                     ag_packets.Clear();
  175.                 }
  176.  
  177.                 List<KeyValuePair<TransferBuffer, Packet>> list2 = ag_security.TransferOutgoing();
  178.                 if (list2 != null)
  179.                 {
  180.                     foreach (KeyValuePair<TransferBuffer, Packet> pair in list2)
  181.                     {
  182.                         TransferBuffer key = pair.Key;
  183.                         current = pair.Value;
  184.                         success = SocketError.Success;
  185.                         while (key.Offset != key.Size)
  186.                         {
  187.                             int num6 = ag_socket.Send(key.Buffer, key.Offset, key.Size - key.Offset, SocketFlags.None, out success);
  188.                             if ((success != SocketError.Success) && (success != SocketError.WouldBlock))
  189.                             {
  190.                                 break;
  191.                             }
  192.                             key.Offset += num6;
  193.                             Thread.Sleep(1);
  194.                         }
  195.                         if (success != SocketError.Success)
  196.                         {
  197.                             break;
  198.                         }
  199.                         bytes = current.GetBytes();
  200.                         this.Log("[C->S][{0:X4}][{1} bytes]{2}{3}{4}{5}{6}", new object[] { current.Opcode, bytes.Length, current.Encrypted ? "[Encrypted]" : "", current.Massive ? "[Massive]" : "", Environment.NewLine, Utility.HexDump(bytes), Environment.NewLine });
  201.                     }
  202.                     if (success != SocketError.Success)
  203.                     {
  204.                         return;
  205.                     }
  206.                 }
  207.                 Thread.Sleep(1);
  208.             }
  209.         }
  210.  
  211.         public void Log(string msg, params object[] values)
  212.         {
  213.             msg = string.Format(msg, values);
  214.         }
  215.  
  216.         public void Meldung(string msg, params object[] values)
  217.         {
  218.             msg = string.Format(msg, values);
  219.             Globals.MainWindow.globalchat.AppendText(msg + "\r\n");
  220.         }
  221.  
  222.         public static void Send(Packet packet)
  223.         {
  224.             ag_security.Send(packet);
  225.         }
  226.  
  227.         public void Start(string IP, string Port, uint _loginID, string _username, string _password)
  228.         {
  229.             loginID = _loginID;
  230.             username = _username;
  231.             password = _password;
  232.             loop = new Thread(new ThreadStart(this.Agent_thread));
  233.             ag_socket.Connect(IP, int.Parse(Port));
  234.             loop.Start();
  235.             ag_socket.Blocking = false;
  236.             ag_socket.NoDelay = true;
  237.         }
  238.  
  239.         public void test(string msg, Color color, params object[] values)
  240.         {
  241.             msg = string.Format(msg, color, values);
  242.             int length = Globals.MainWindow.richTextBox1.Text.Length;
  243.             Globals.MainWindow.richTextBox1.Text = Globals.MainWindow.richTextBox1.Text + msg + "\r\n";
  244.             Globals.MainWindow.richTextBox1.Select(length, msg.Length);
  245.             Globals.MainWindow.richTextBox1.SelectionColor = color;
  246.         }
  247.  
  248.         public void textdata(string msg, params object[] values)
  249.         {
  250.             msg = string.Format(msg, values);
  251.             Globals.MainWindow.globalchat.AppendText(msg + "\r\n");
  252.         }
  253.     }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement