Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private string Builder(string nameSpace, string function)
- {
- counter++;
- switch (nameSpace)
- {
- case "Sts":
- {
- switch (function)
- {
- case "Connect":
- {
- string data = String.Format(
- "<Connect>\n" +
- "<ConnType>400</ConnType>\n" +
- "<Address>{0}</Address>\n" +
- "<ProductType>0</ProductType>\n" +
- "<AppIndex>1</AppIndex>\n" +
- "<Epoch>{1}</Epoch>\n" +
- "<Program>{2}</Program>\n" +
- "<Build>1001</Build>\n" +
- "<Process>{3}</Process>\n" +
- "</Connect>\n",
- localIP,
- epoch,
- LoginProgramid,
- pid);
- return string.Format("POST /Sts/Connect STS/1.0\r\nl:{0}\r\n\r\n{1}", data.Length, data);
- }
- break;
- case "Ping":
- {
- return "POST /Sts/Ping STS/1.0\r\nl:0\r\n\r\n";
- }
- break;
- default:
- break;
- }
- }
- break;
- case "Auth":
- {
- switch (function)
- {
- case "LoginStart":
- {
- string data = String.Format(
- "<Request>\n" +
- "<LoginName>{0}</LoginName>\n" +
- "</Request>\n",
- username
- );
- return string.Format("POST /Auth/LoginStart STS/1.0\r\ns:{4}\r\np:*{0} 0 1 0 {1}\r\nl:{2}\r\n\r\n{3}", localIP, epoch, data.Length, data, counter);
- }
- break;
- case "KeyData":
- {
- byte[][] values = GenerateKeyClient(exchangeKeyServer);
- MemoryStream ms = new MemoryStream();
- BinaryWriter bw = new BinaryWriter(ms);
- bw.Write(exchangeKey.getBytes().Length);
- bw.Write(exchangeKey.getBytes());
- bw.Write(values[0].Length);
- bw.Write(values[0]);
- validate = new BigInteger(values[1]);
- string data = String.Format(
- "<Request>\n" +
- "<KeyData>{0}</KeyData>\n" +
- "</Request>\n",
- Convert.ToBase64String(ms.ToArray())
- );
- bw.Close();
- ms.Close();
- return string.Format("POST /Auth/KeyData STS/1.0\r\ns:{4}\r\np:*{0} 0 1 0 {1}\r\nl:{2}\r\n\r\n{3}", localIP, epoch, data.Length, data, counter);
- }
- break;
- case "LoginFinish":
- {
- string data = "<Request>\n<Language>1</Language>\n</Request>\n";
- return string.Format("POST /Auth/LoginFinish STS/1.0\r\ns:{2}\r\nl:{0}\r\n\r\n{1}", data.Length, data, counter);
- }
- break;
- case "RequestToken":
- {
- string data = String.Format(
- "<Request>\n" +
- "<AppId>{0}</AppId>\n" +
- "</Request>\n",
- currentAppId);
- return string.Format("POST /Auth/RequestToken STS/1.0\r\ns:{2}\r\nl:{0}\r\n\r\n{1}", data.Length, data, counter);
- }
- break;
- default:
- break;
- }
- }
- break;
- default:
- break;
- }
- return null;
- }
- public void Try_Connection(object sender, DoWorkEventArgs e)
- {
- try
- {
- LoginServer = new TcpClient(LoginIp, LoginPort);
- LoginServer.ReceiveBufferSize = 1024;
- NetworkStream ns = LoginServer.GetStream();
- ns.ReadTimeout = 60000;
- ns.ReadTimeout = 60000;
- DateTime lastSent = DateTime.Now;
- int pingInterval = 30;
- string packet = Builder("Sts", "Connect");
- ns.Write(Encoding.ASCII.GetBytes(packet), 0, packet.Length);
- if (Debugging)
- Prompt.Popup("Sent Sts request to connect");
- packet = Builder("Auth", "LoginStart");
- ns.Write(Encoding.ASCII.GetBytes(packet), 0, packet.Length);
- if (Debugging)
- Prompt.Popup("Sent Auth request to start login");
- MemoryStream ms = new MemoryStream();
- byte[] buffer = new byte[1024];
- int bytesRec = 0;
- //Read data sent back from login server
- do
- {
- bytesRec = ns.Read(buffer, 0, buffer.Length);
- if (bytesRec > 0)
- {
- ms.Write(buffer, 0, bytesRec);
- }
- }
- while (bytesRec == buffer.Length);
- string reply = Encoding.ASCII.GetString(ms.ToArray());
- reply = reply.Split('\r')[0].Split(' ')[2];
- if (Debugging)
- Prompt.Popup("Server Reply: " + reply);
- switch (reply)
- {
- case "OK":
- break;
- case "ErrAccountNotFound":
- Prompt.Popup("The provided email address wasn't found");
- metroButton1.Enabled = true;
- Show(); // Shows the program on taskbar
- this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
- return;
- default:
- if (username.Length > 0 && password.Length > 0)
- {
- Prompt.Popup("Invalidly formated email");
- } else { AddTextLog("Cancelled"); }
- metroButton1.Enabled = true;
- Show(); // Shows the program on taskbar
- this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
- this.TopMost = true;
- this.TopMost = false;
- return;
- }
- ms.Close();
- try
- {
- ms = new MemoryStream();
- do
- {
- bytesRec = ns.Read(buffer, 0, buffer.Length);
- if (bytesRec > 0)
- {
- ms.Write(buffer, 0, bytesRec);
- }
- }
- while (bytesRec == buffer.Length);
- }
- catch
- {
- Prompt.Popup("Please verify your new ip to NCSoft's website(whitelist via security settings) or NCSoft Launcher via pin confirmation.");
- foreach (var process in Process.GetProcessesByName("Client"))
- {
- if (process.Id == appuniqueid)
- {
- process.Kill();
- }
- }
- metroButton1.Enabled = true;
- Show(); // Shows the program on taskbar
- this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
- return;
- }
- reply = Encoding.ASCII.GetString(ms.ToArray());
- ms.Close();
- reply = Regex.Match(reply, "<KeyData>([^<]*)</KeyData>", RegexOptions.IgnoreCase).Groups[1].Value;
- ms = new MemoryStream(Convert.FromBase64String(reply));
- BinaryReader br = new BinaryReader(ms);
- session = new BigInteger(br.ReadBytes(br.ReadInt32()));
- exchangeKeyServer = new BigInteger(br.ReadBytes(br.ReadInt32()));
- br.Close();
- ms.Close();
- if (Debugging)
- Prompt.Popup("Server Reply 1: " + session);
- if (Debugging)
- Prompt.Popup("Server Reply 2: " + exchangeKeyServer);
- packet = Builder("Auth", "KeyData");
- ns.Write(Encoding.ASCII.GetBytes(packet), 0, packet.Length);
- //Read data sent back from login server
- ms = new MemoryStream();
- do
- {
- bytesRec = ns.Read(buffer, 0, buffer.Length);
- if (bytesRec > 0)
- {
- ms.Write(buffer, 0, bytesRec);
- }
- }
- while (bytesRec == buffer.Length);
- reply = Encoding.ASCII.GetString(ms.ToArray());
- reply = reply.Split('\r')[0].Split(' ')[2];
- switch (reply)
- {
- case "OK":
- break;
- case "ErrBadPasswd":
- Prompt.Popup("Wrong Password or Email");
- metroButton1.Enabled = true;
- Show(); // Shows the program on taskbar
- this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
- return;
- case "ErrRiskMgmtDeclined":
- Prompt.Popup("You have exceeded the number of attempts allowed.\r\nFor security reasons, login is temporarily disabled.\r\nPlease try again later.");
- metroButton1.Enabled = true;
- Show(); // Shows the program on taskbar
- this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
- return;
- default:
- Prompt.Popup("Unknown Error: " + reply);
- metroButton1.Enabled = true;
- Show(); // Shows the program on taskbar
- this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
- return;
- }
- ms.Close();
- ms = new MemoryStream();
- do
- {
- bytesRec = ns.Read(buffer, 0, buffer.Length);
- if (bytesRec > 0)
- {
- ms.Write(buffer, 0, bytesRec);
- }
- }
- while (bytesRec == buffer.Length);
- reply = Encoding.ASCII.GetString(ms.ToArray());
- ms.Close();
- reply = Regex.Match(reply, "<KeyData>([^<]*)</KeyData>", RegexOptions.IgnoreCase).Groups[1].Value;
- ms = new MemoryStream(Convert.FromBase64String(reply));
- br = new BinaryReader(ms);
- buffer = br.ReadBytes(br.ReadInt32());
- if (new BigInteger(buffer) == validate)
- {
- var xor = new BNSXorEncryption(key);
- packet = Builder("Auth", "LoginFinish");
- buffer = Encoding.ASCII.GetBytes(packet);
- buffer = xor.Encrypt(buffer, 0, buffer.Length);
- ns.Write(buffer, 0, buffer.Length);
- buffer = new byte[1024];
- ms = new MemoryStream();
- do
- {
- bytesRec = ns.Read(buffer, 0, buffer.Length);
- if (bytesRec > 0)
- {
- ms.Write(buffer, 0, bytesRec);
- }
- }
- while (bytesRec == buffer.Length);
- buffer = ms.ToArray();
- buffer = xor.Decrypt(buffer, 0, buffer.Length);
- ms.Close();
- buffer = new byte[1024];
- ms = new MemoryStream();
- try
- {
- do
- {
- bytesRec = ns.Read(buffer, 0, buffer.Length);
- if (bytesRec > 0)
- {
- ms.Write(buffer, 0, bytesRec);
- }
- }
- while (bytesRec == buffer.Length);
- }
- catch
- {
- Prompt.Popup("Please verify your new ip to NCSoft's website(whitelist via security settings) or NCSoft Launcher via pin confirmation.");
- foreach (var process in Process.GetProcessesByName("Client"))
- {
- if (process.Id == appuniqueid)
- {
- process.Kill();
- }
- }
- metroButton1.Enabled = true;
- Show(); // Shows the program on taskbar
- this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
- return;
- }
- buffer = ms.ToArray();
- buffer = xor.Decrypt(buffer, 0, buffer.Length);
- packet = Encoding.ASCII.GetString(buffer);
- if (Debugging)
- Prompt.Popup("Debug: 0" + packet.ToString());
- if (packet.Contains("<AuthType>8</AuthType>"))
- {
- Prompt.Popup("This launcher doesn't support IP Verification, please do so on the website or official launcher then try again");
- Show();
- metroButton1.Enabled = true;
- this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
- return;
- }
- ms.Close();
- packet = Builder("Auth", "RequestToken");
- buffer = Encoding.ASCII.GetBytes(packet);
- buffer = xor.Encrypt(buffer, 0, buffer.Length);
- ns.Write(buffer, 0, buffer.Length);
- buffer = new byte[1024];
- ms = new MemoryStream();
- do
- {
- bytesRec = ns.Read(buffer, 0, buffer.Length);
- if (bytesRec > 0)
- {
- ms.Write(buffer, 0, bytesRec);
- }
- }
- while (bytesRec == buffer.Length);
- buffer = ms.ToArray();
- buffer = xor.Decrypt(buffer, 0, buffer.Length);
- if (Debugging)
- Prompt.Popup(Encoding.ASCII.GetString(buffer));
- ms.Close();
- reply = Encoding.ASCII.GetString(buffer);
- token = Regex.Match(reply, "<AuthnToken>([^<]*)</AuthnToken>", RegexOptions.IgnoreCase).Groups[1].Value;
- Action<bool> update = login_enable;
- Invoke(update, true);
- }
- else
- {
- Prompt.Popup("Negotiation Failed, please try again.");
- key = null;
- }
- while (LoginServer.Connected)
- {
- if (DateTime.Now >= lastSent.AddSeconds(pingInterval))
- {
- packet = Builder("Sts", "Ping");
- buffer = Encoding.ASCII.GetBytes(packet);
- if (key != null && buffer != null && xor != null)
- {
- buffer = xor.Encrypt(buffer, 0, buffer.Length);
- }
- ns.Write(buffer, 0, buffer.Length);
- lastSent = DateTime.Now;
- }
- }
- }
- catch (Exception ex)
- {
- if (GameStarted == false)
- {
- if (Debugging)
- Prompt.Popup(ex.ToString());
- }
- }
- }
- void login_enable(bool yes)
- {
- AddTextLog("Login successful!");
- if (!metroLabel14.Text.Contains("Clean"))
- {
- RestoreConfigFiles();
- }
- // Return token
- string tmp = String.Format(args, token);
- FinalToken = tmp;
- AddTextLog("Starting Client!");
- Process proc = new Process();
- proc.StartInfo.FileName = LaunchPath;
- string temp = metroComboBox1.SelectedItem.ToString();
- if (temp == "North America" || temp == "Europe") // NA/EU
- {
- proc.StartInfo.Arguments = "-lang:" + languageID + " -lite:2 -region:" + regionID + " /AuthnToken:\"" + FinalToken + "\" /AuthProviderCode:\"np\" /sesskey /launchbylauncher /CompanyID:12 /ChannelGroupIndex:-1 " + UseAllCores + " " + Unattended + " " + NoTextureStreaming + " " + metroTextBox5.Text;
- }
- else if (temp == "Korean") // KR
- {
- if (metroComboBox8.SelectedItem.ToString() == "Live")
- {
- proc.StartInfo.Arguments = "/LaunchByLauncher /AuthnToken:" + FinalToken + " /SessKey:" + FinalToken + " /ServiceRegion:" + LoginId + " /AuthProviderCode:np /ServiceNetwork:live /NPServerAddr:" + LoginIp + ":" + LoginPort + " -lite:8 /PresenceId:BNS_KOR " + UseAllCores + " " + Unattended + " " + NoTextureStreaming + " " + metroTextBox5.Text;
- }
- else
- {
- proc.StartInfo.Arguments = "/LaunchByLauncher /AuthnToken:" + FinalToken + " /SessKey:" + FinalToken + " /ServiceRegion:" + LoginId + " /AuthProviderCode:np /ServiceNetwork:live /NPServerAddr:" + LoginIp + ":" + LoginPort + " -lite:8 /PresenceId:BNS_KOR_TEST " + UseAllCores + " " + Unattended + " " + NoTextureStreaming + " " + metroTextBox5.Text;
- }
- }
- else if (temp == "Taiwan") // TW
- {
- proc.StartInfo.Arguments = "/LaunchByLauncher /SessKey:" + FinalToken + " /ServiceRegion:15 /ChannelGroupIndex:-1 /PresenceId:TWBNS22 " + UseAllCores + " " + Unattended + " " + NoTextureStreaming + " " + metroTextBox5.Text;
- }
- proc.StartInfo.UseShellExecute = false;
- proc.StartInfo.RedirectStandardError = true;
- bool gameworked = false;
- try
- {
- // Clean memory if true
- if (AutoClean == true)
- {
- CleanMem();
- }
- }
- catch
- {
- AddTextBoxLog("Notice: Could not clear any memory!");
- }
- try
- {
- proc.Start();
- AddTextLog("Started Client.exe!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement