Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 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.floor(Math.random() * 9999999);
  10.  
  11. const username = 'xxxxxxxx';
  12. const password = 'xxxxxxxxxxx';
  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 hostWorld = '79.110.84.37';
  56. const oortWorld = 4015;
  57.  
  58. const socketWorld = clientWorld.connect(oortWorld, hostWorld);
  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. decodingStream.on('data', (data) => {
  84. console.log(data);
  85. });
  86. });
  87. });
  88.  
  89. async function buildLoginPacket () {
  90. const nostalePath = 'C:\\Program Files (x86)\\NosTale_FR';
  91.  
  92. const encodedUsername = iconv.encode(username, 'win1252');
  93. const encodedPassword = iconv.encode(password, 'win1252');
  94.  
  95. const random = Math.floor(Math.random() * 9999999);
  96. const encryptedPassword = nosCrypto.encryptPassword(encodedPassword);
  97. const guid = '12d45678-123d-422a-a223-25bde24865dc';
  98. const version = await nosCrypto.createVersion(nostalePath);
  99. const checksumHash = await nosCrypto.createChecksumHash(encodedUsername, nostalePath);
  100.  
  101. return `NoS0575 ${random} ${username} ${encryptedPassword} ${guid} ${version} 0 ${checksumHash}`;
  102. }
  103.  
  104. function buildSessionWorldPacket() {
  105. let packet = packetId + ' ' + session;
  106. packetId += 1;
  107. console.log(packet);
  108. return packet;
  109. }
  110.  
  111. function buildLoginWorldPacket() {
  112. let packet = packetId + ' ' + username;
  113. packetId += 1;
  114. console.log(packet);
  115. return packet;
  116. }
  117.  
  118. function buildPasswordWorldPacket() {
  119. let packet = packetId + ' ' + password;
  120. packetId += 1;
  121. console.log(packet);
  122. return packet;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement