Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.96 KB | None | 0 0
  1. private string Builder(string nameSpace, string function)
  2. {
  3. counter++;
  4. switch (nameSpace)
  5. {
  6. case "Sts":
  7. {
  8. switch (function)
  9. {
  10. case "Connect":
  11. {
  12. string data = String.Format(
  13. "<Connect>\n" +
  14. "<ConnType>400</ConnType>\n" +
  15. "<Address>{0}</Address>\n" +
  16. "<ProductType>0</ProductType>\n" +
  17. "<AppIndex>1</AppIndex>\n" +
  18. "<Epoch>{1}</Epoch>\n" +
  19. "<Program>{2}</Program>\n" +
  20. "<Build>1001</Build>\n" +
  21. "<Process>{3}</Process>\n" +
  22. "</Connect>\n",
  23. localIP,
  24. epoch,
  25. LoginProgramid,
  26. pid);
  27. return string.Format("POST /Sts/Connect STS/1.0\r\nl:{0}\r\n\r\n{1}", data.Length, data);
  28. }
  29. break;
  30. case "Ping":
  31. {
  32. return "POST /Sts/Ping STS/1.0\r\nl:0\r\n\r\n";
  33. }
  34. break;
  35. default:
  36. break;
  37. }
  38. }
  39. break;
  40. case "Auth":
  41. {
  42. switch (function)
  43. {
  44. case "LoginStart":
  45. {
  46. string data = String.Format(
  47. "<Request>\n" +
  48. "<LoginName>{0}</LoginName>\n" +
  49. "</Request>\n",
  50. username
  51. );
  52.  
  53. 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);
  54. }
  55. break;
  56. case "KeyData":
  57. {
  58. byte[][] values = GenerateKeyClient(exchangeKeyServer);
  59. MemoryStream ms = new MemoryStream();
  60. BinaryWriter bw = new BinaryWriter(ms);
  61.  
  62. bw.Write(exchangeKey.getBytes().Length);
  63. bw.Write(exchangeKey.getBytes());
  64. bw.Write(values[0].Length);
  65. bw.Write(values[0]);
  66.  
  67. validate = new BigInteger(values[1]);
  68.  
  69. string data = String.Format(
  70. "<Request>\n" +
  71. "<KeyData>{0}</KeyData>\n" +
  72. "</Request>\n",
  73. Convert.ToBase64String(ms.ToArray())
  74. );
  75.  
  76. bw.Close();
  77. ms.Close();
  78.  
  79. 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);
  80. }
  81. break;
  82. case "LoginFinish":
  83. {
  84. string data = "<Request>\n<Language>1</Language>\n</Request>\n";
  85. return string.Format("POST /Auth/LoginFinish STS/1.0\r\ns:{2}\r\nl:{0}\r\n\r\n{1}", data.Length, data, counter);
  86. }
  87. break;
  88. case "RequestToken":
  89. {
  90. string data = String.Format(
  91. "<Request>\n" +
  92. "<AppId>{0}</AppId>\n" +
  93. "</Request>\n",
  94. currentAppId);
  95. return string.Format("POST /Auth/RequestToken STS/1.0\r\ns:{2}\r\nl:{0}\r\n\r\n{1}", data.Length, data, counter);
  96. }
  97. break;
  98. default:
  99. break;
  100. }
  101. }
  102. break;
  103. default:
  104. break;
  105. }
  106.  
  107. return null;
  108. }
  109.  
  110. public void Try_Connection(object sender, DoWorkEventArgs e)
  111. {
  112.  
  113. try
  114. {
  115. LoginServer = new TcpClient(LoginIp, LoginPort);
  116. LoginServer.ReceiveBufferSize = 1024;
  117. NetworkStream ns = LoginServer.GetStream();
  118. ns.ReadTimeout = 60000;
  119. ns.ReadTimeout = 60000;
  120.  
  121. DateTime lastSent = DateTime.Now;
  122. int pingInterval = 30;
  123.  
  124. string packet = Builder("Sts", "Connect");
  125. ns.Write(Encoding.ASCII.GetBytes(packet), 0, packet.Length);
  126.  
  127. if (Debugging)
  128. Prompt.Popup("Sent Sts request to connect");
  129.  
  130. packet = Builder("Auth", "LoginStart");
  131. ns.Write(Encoding.ASCII.GetBytes(packet), 0, packet.Length);
  132.  
  133. if (Debugging)
  134. Prompt.Popup("Sent Auth request to start login");
  135.  
  136. MemoryStream ms = new MemoryStream();
  137. byte[] buffer = new byte[1024];
  138. int bytesRec = 0;
  139.  
  140. //Read data sent back from login server
  141. do
  142. {
  143. bytesRec = ns.Read(buffer, 0, buffer.Length);
  144.  
  145. if (bytesRec > 0)
  146. {
  147. ms.Write(buffer, 0, bytesRec);
  148. }
  149. }
  150. while (bytesRec == buffer.Length);
  151. string reply = Encoding.ASCII.GetString(ms.ToArray());
  152. reply = reply.Split('\r')[0].Split(' ')[2];
  153.  
  154. if (Debugging)
  155. Prompt.Popup("Server Reply: " + reply);
  156.  
  157. switch (reply)
  158. {
  159. case "OK":
  160. break;
  161. case "ErrAccountNotFound":
  162. Prompt.Popup("The provided email address wasn't found");
  163. metroButton1.Enabled = true;
  164. Show(); // Shows the program on taskbar
  165. this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
  166. return;
  167. default:
  168. if (username.Length > 0 && password.Length > 0)
  169. {
  170. Prompt.Popup("Invalidly formated email");
  171. } else { AddTextLog("Cancelled"); }
  172. metroButton1.Enabled = true;
  173. Show(); // Shows the program on taskbar
  174. this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
  175. this.TopMost = true;
  176. this.TopMost = false;
  177. return;
  178. }
  179. ms.Close();
  180.  
  181. try
  182. {
  183. ms = new MemoryStream();
  184. do
  185. {
  186. bytesRec = ns.Read(buffer, 0, buffer.Length);
  187.  
  188. if (bytesRec > 0)
  189. {
  190. ms.Write(buffer, 0, bytesRec);
  191. }
  192. }
  193. while (bytesRec == buffer.Length);
  194. }
  195. catch
  196. {
  197. Prompt.Popup("Please verify your new ip to NCSoft's website(whitelist via security settings) or NCSoft Launcher via pin confirmation.");
  198. foreach (var process in Process.GetProcessesByName("Client"))
  199. {
  200. if (process.Id == appuniqueid)
  201. {
  202. process.Kill();
  203. }
  204. }
  205. metroButton1.Enabled = true;
  206. Show(); // Shows the program on taskbar
  207. this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
  208. return;
  209. }
  210.  
  211. reply = Encoding.ASCII.GetString(ms.ToArray());
  212. ms.Close();
  213. reply = Regex.Match(reply, "<KeyData>([^<]*)</KeyData>", RegexOptions.IgnoreCase).Groups[1].Value;
  214. ms = new MemoryStream(Convert.FromBase64String(reply));
  215.  
  216. BinaryReader br = new BinaryReader(ms);
  217. session = new BigInteger(br.ReadBytes(br.ReadInt32()));
  218. exchangeKeyServer = new BigInteger(br.ReadBytes(br.ReadInt32()));
  219. br.Close();
  220. ms.Close();
  221.  
  222. if (Debugging)
  223. Prompt.Popup("Server Reply 1: " + session);
  224. if (Debugging)
  225. Prompt.Popup("Server Reply 2: " + exchangeKeyServer);
  226.  
  227. packet = Builder("Auth", "KeyData");
  228. ns.Write(Encoding.ASCII.GetBytes(packet), 0, packet.Length);
  229.  
  230. //Read data sent back from login server
  231. ms = new MemoryStream();
  232. do
  233. {
  234. bytesRec = ns.Read(buffer, 0, buffer.Length);
  235.  
  236. if (bytesRec > 0)
  237. {
  238. ms.Write(buffer, 0, bytesRec);
  239. }
  240. }
  241. while (bytesRec == buffer.Length);
  242. reply = Encoding.ASCII.GetString(ms.ToArray());
  243. reply = reply.Split('\r')[0].Split(' ')[2];
  244. switch (reply)
  245. {
  246. case "OK":
  247. break;
  248. case "ErrBadPasswd":
  249. Prompt.Popup("Wrong Password or Email");
  250. metroButton1.Enabled = true;
  251. Show(); // Shows the program on taskbar
  252. this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
  253. return;
  254. case "ErrRiskMgmtDeclined":
  255. Prompt.Popup("You have exceeded the number of attempts allowed.\r\nFor security reasons, login is temporarily disabled.\r\nPlease try again later.");
  256. metroButton1.Enabled = true;
  257. Show(); // Shows the program on taskbar
  258. this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
  259. return;
  260. default:
  261. Prompt.Popup("Unknown Error: " + reply);
  262. metroButton1.Enabled = true;
  263. Show(); // Shows the program on taskbar
  264. this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
  265. return;
  266. }
  267. ms.Close();
  268. ms = new MemoryStream();
  269. do
  270. {
  271. bytesRec = ns.Read(buffer, 0, buffer.Length);
  272.  
  273. if (bytesRec > 0)
  274. {
  275. ms.Write(buffer, 0, bytesRec);
  276. }
  277. }
  278. while (bytesRec == buffer.Length);
  279.  
  280. reply = Encoding.ASCII.GetString(ms.ToArray());
  281. ms.Close();
  282. reply = Regex.Match(reply, "<KeyData>([^<]*)</KeyData>", RegexOptions.IgnoreCase).Groups[1].Value;
  283. ms = new MemoryStream(Convert.FromBase64String(reply));
  284. br = new BinaryReader(ms);
  285. buffer = br.ReadBytes(br.ReadInt32());
  286.  
  287. if (new BigInteger(buffer) == validate)
  288. {
  289. var xor = new BNSXorEncryption(key);
  290.  
  291. packet = Builder("Auth", "LoginFinish");
  292. buffer = Encoding.ASCII.GetBytes(packet);
  293. buffer = xor.Encrypt(buffer, 0, buffer.Length);
  294. ns.Write(buffer, 0, buffer.Length);
  295.  
  296. buffer = new byte[1024];
  297. ms = new MemoryStream();
  298. do
  299. {
  300. bytesRec = ns.Read(buffer, 0, buffer.Length);
  301.  
  302. if (bytesRec > 0)
  303. {
  304. ms.Write(buffer, 0, bytesRec);
  305. }
  306. }
  307. while (bytesRec == buffer.Length);
  308. buffer = ms.ToArray();
  309. buffer = xor.Decrypt(buffer, 0, buffer.Length);
  310. ms.Close();
  311.  
  312. buffer = new byte[1024];
  313. ms = new MemoryStream();
  314. try
  315. {
  316. do
  317. {
  318. bytesRec = ns.Read(buffer, 0, buffer.Length);
  319.  
  320. if (bytesRec > 0)
  321. {
  322. ms.Write(buffer, 0, bytesRec);
  323. }
  324. }
  325. while (bytesRec == buffer.Length);
  326. }
  327. catch
  328. {
  329. Prompt.Popup("Please verify your new ip to NCSoft's website(whitelist via security settings) or NCSoft Launcher via pin confirmation.");
  330. foreach (var process in Process.GetProcessesByName("Client"))
  331. {
  332. if (process.Id == appuniqueid)
  333. {
  334. process.Kill();
  335. }
  336. }
  337. metroButton1.Enabled = true;
  338. Show(); // Shows the program on taskbar
  339. this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
  340. return;
  341. }
  342. buffer = ms.ToArray();
  343. buffer = xor.Decrypt(buffer, 0, buffer.Length);
  344. packet = Encoding.ASCII.GetString(buffer);
  345.  
  346. if (Debugging)
  347. Prompt.Popup("Debug: 0" + packet.ToString());
  348.  
  349. if (packet.Contains("<AuthType>8</AuthType>"))
  350. {
  351. Prompt.Popup("This launcher doesn't support IP Verification, please do so on the website or official launcher then try again");
  352. Show();
  353. metroButton1.Enabled = true;
  354. this.WindowState = FormWindowState.Normal; // Undoes the minimized state of the form
  355. return;
  356. }
  357. ms.Close();
  358.  
  359. packet = Builder("Auth", "RequestToken");
  360. buffer = Encoding.ASCII.GetBytes(packet);
  361. buffer = xor.Encrypt(buffer, 0, buffer.Length);
  362. ns.Write(buffer, 0, buffer.Length);
  363.  
  364. buffer = new byte[1024];
  365. ms = new MemoryStream();
  366. do
  367. {
  368. bytesRec = ns.Read(buffer, 0, buffer.Length);
  369.  
  370. if (bytesRec > 0)
  371. {
  372. ms.Write(buffer, 0, bytesRec);
  373. }
  374. }
  375. while (bytesRec == buffer.Length);
  376. buffer = ms.ToArray();
  377. buffer = xor.Decrypt(buffer, 0, buffer.Length);
  378. if (Debugging)
  379. Prompt.Popup(Encoding.ASCII.GetString(buffer));
  380. ms.Close();
  381.  
  382. reply = Encoding.ASCII.GetString(buffer);
  383. token = Regex.Match(reply, "<AuthnToken>([^<]*)</AuthnToken>", RegexOptions.IgnoreCase).Groups[1].Value;
  384. Action<bool> update = login_enable;
  385. Invoke(update, true);
  386. }
  387. else
  388. {
  389. Prompt.Popup("Negotiation Failed, please try again.");
  390. key = null;
  391. }
  392.  
  393. while (LoginServer.Connected)
  394. {
  395. if (DateTime.Now >= lastSent.AddSeconds(pingInterval))
  396. {
  397. packet = Builder("Sts", "Ping");
  398. buffer = Encoding.ASCII.GetBytes(packet);
  399. if (key != null && buffer != null && xor != null)
  400. {
  401. buffer = xor.Encrypt(buffer, 0, buffer.Length);
  402. }
  403. ns.Write(buffer, 0, buffer.Length);
  404. lastSent = DateTime.Now;
  405. }
  406. }
  407. }
  408. catch (Exception ex)
  409. {
  410. if (GameStarted == false)
  411. {
  412. if (Debugging)
  413. Prompt.Popup(ex.ToString());
  414. }
  415. }
  416. }
  417.  
  418. void login_enable(bool yes)
  419. {
  420. AddTextLog("Login successful!");
  421. if (!metroLabel14.Text.Contains("Clean"))
  422. {
  423. RestoreConfigFiles();
  424. }
  425. // Return token
  426. string tmp = String.Format(args, token);
  427. FinalToken = tmp;
  428. AddTextLog("Starting Client!");
  429. Process proc = new Process();
  430. proc.StartInfo.FileName = LaunchPath;
  431. string temp = metroComboBox1.SelectedItem.ToString();
  432. if (temp == "North America" || temp == "Europe") // NA/EU
  433. {
  434. proc.StartInfo.Arguments = "-lang:" + languageID + " -lite:2 -region:" + regionID + " /AuthnToken:\"" + FinalToken + "\" /AuthProviderCode:\"np\" /sesskey /launchbylauncher /CompanyID:12 /ChannelGroupIndex:-1 " + UseAllCores + " " + Unattended + " " + NoTextureStreaming + " " + metroTextBox5.Text;
  435. }
  436. else if (temp == "Korean") // KR
  437. {
  438. if (metroComboBox8.SelectedItem.ToString() == "Live")
  439. {
  440. 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;
  441. }
  442. else
  443. {
  444. 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;
  445. }
  446. }
  447. else if (temp == "Taiwan") // TW
  448. {
  449. proc.StartInfo.Arguments = "/LaunchByLauncher /SessKey:" + FinalToken + " /ServiceRegion:15 /ChannelGroupIndex:-1 /PresenceId:TWBNS22 " + UseAllCores + " " + Unattended + " " + NoTextureStreaming + " " + metroTextBox5.Text;
  450. }
  451. proc.StartInfo.UseShellExecute = false;
  452. proc.StartInfo.RedirectStandardError = true;
  453. bool gameworked = false;
  454. try
  455. {
  456. // Clean memory if true
  457. if (AutoClean == true)
  458. {
  459. CleanMem();
  460. }
  461. }
  462. catch
  463. {
  464. AddTextBoxLog("Notice: Could not clear any memory!");
  465. }
  466. try
  467. {
  468. proc.Start();
  469. AddTextLog("Started Client.exe!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement