Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. const net = require('net');
  2. const { pipeline } = require('stream');
  3. const iconv = require('iconv-lite');
  4. const sleep = require('system-sleep');
  5. const nbind = require('nbind');
  6. const lib = nbind.init().lib;
  7. const Crypto = new lib.Crypto();
  8. let session = 0;
  9. let packetId = Math.random() * 999999;
  10.  
  11. const username = 'xxxxxxxxxx';
  12. const password = 'xxxxxxxxxx';
  13.  
  14.  
  15. const nosCrypto = require('nostale-cryptography/client');
  16.  
  17. let client = new net.Socket();
  18. const hostLogin = '79.110.84.75';
  19. const portLogin = 4002;
  20.  
  21. const socketLogin = client.connect(portLogin, hostLogin);
  22.  
  23. client.on('connect', function () {
  24. const encryptStream = nosCrypto.createCipher();
  25. const decryptStream = nosCrypto.createDecipher();
  26.  
  27. const encodingStream = iconv.encodeStream('win1252');
  28. const decodingStream = iconv.decodeStream('win1252');
  29. pipeline(
  30. encodingStream,
  31. encryptStream,
  32. socketLogin,
  33. decryptStream,
  34. decodingStream,
  35. (err) => {
  36. if (err) {
  37. throw err
  38. }
  39.  
  40. console.log('Game closed because stream pipeline closed.')
  41. }
  42. );
  43. buildLoginPacket().then((loginPacket) => {
  44. console.log(loginPacket);
  45. encodingStream.write(loginPacket);
  46. decodingStream.on('data', (packetLogin) => {
  47. console.log(packetLogin);
  48. session = parseInt(packetLogin.split(' ')[2]);
  49. })
  50. });
  51. });
  52.  
  53. client.on('close', function() {
  54. let clientWorld = new net.Socket();
  55. const hostLogin = '79.110.84.75';
  56. const portLogin = 4002;
  57.  
  58. const socketWorld = clientWorld.connect(portLogin, hostLogin);
  59.  
  60. clientWorld.on('connect', function () {
  61. const encryptStream = nosCrypto.createCipher(session);
  62. const decryptStream = nosCrypto.createDecipher(session);
  63.  
  64. const encodingStream = iconv.encodeStream('win1252');
  65. const decodingStream = iconv.decodeStream('win1252');
  66. pipeline(
  67. encodingStream,
  68. encryptStream,
  69. socketWorld,
  70. decryptStream,
  71. decodingStream,
  72. (err) => {
  73. if (err) {
  74. throw err
  75. }
  76.  
  77. console.log('Game closed because stream pipeline closed.')
  78. }
  79. );
  80.  
  81. clientWorld.write(Buffer.from(Crypto.encryptGamePacket(buildSessionWorldPacket(), session, true)));
  82. setTimeout(() => clientWorld.write(Buffer.from(Crypto.encryptGamePacket(buildLoginWorldPacket(), session, false).concat(Crypto.encryptGamePacket(buildPasswordWorldPacket(), session, false)))), 200);
  83. });
  84. clientWorld.on('data', function () {
  85. const encryptStream = nosCrypto.createCipher();
  86. const decryptStream = nosCrypto.createDecipher();
  87.  
  88. const encodingStream = iconv.encodeStream('win1252');
  89. const decodingStream = iconv.decodeStream('win1252');
  90. pipeline(
  91. encodingStream,
  92. encryptStream,
  93. socketLogin,
  94. decryptStream,
  95. decodingStream,
  96. (err) => {
  97. if (err) {
  98. throw err
  99. }
  100.  
  101. console.log('Game closed because stream pipeline closed.')
  102. }
  103. );
  104. decodingStream.on('data', (data) => {
  105. console.log(data);
  106. });
  107. });
  108. });
  109.  
  110. async function buildLoginPacket () {
  111. const nostalePath = 'C:\\Program Files (x86)\\NosTale_FR';
  112.  
  113. const encodedUsername = iconv.encode(username, 'win1252');
  114. const encodedPassword = iconv.encode(password, 'win1252');
  115.  
  116. const random = Math.floor(Math.random() * 9999999);
  117. const encryptedPassword = nosCrypto.encryptPassword(encodedPassword);
  118. const guid = '12d45678-123d-422a-a223-25bde24865dc';
  119. const version = await nosCrypto.createVersion(nostalePath);
  120. const checksumHash = await nosCrypto.createChecksumHash(encodedUsername, nostalePath);
  121.  
  122. return `NoS0575 ${random} ${username} ${encryptedPassword} ${guid} ${version} 0 ${checksumHash}`;
  123. }
  124.  
  125. function buildSessionWorldPacket() {
  126. let packet = packetId++ + ' ' + session;
  127. console.log(packet);
  128. return packet;
  129. }
  130.  
  131. function buildLoginWorldPacket() {
  132. let packet = packetId++ + ' ' + username;
  133. console.log(packet);
  134. return packet;
  135. }
  136.  
  137. function buildPasswordWorldPacket() {
  138. let packet = packetId++ + ' ' + password;
  139. console.log(packet);
  140. return packet;
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement