Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 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 = 'xxxxxxx';
  12. const password = 'xxxxxxxx';
  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 portWorld = 4015;
  57.  
  58. const socketWorld = clientWorld.connect(portWorld, hostWorld);
  59.  
  60. clientWorld.on('connect', function () {
  61. clientWorld.write(Buffer.from(Crypto.encryptGamePacket(buildSessionWorldPacket(), session, true)));
  62. setTimeout(() => clientWorld.write(Buffer.from(Crypto.encryptGamePacket(buildLoginWorldPacket(), session, false).concat(Crypto.encryptGamePacket(buildPasswordWorldPacket(), session, false)))), 200);
  63. });
  64. clientWorld.on('data', function () {
  65. const encryptStream = nosCrypto.createCipher();
  66. const decryptStream = nosCrypto.createDecipher();
  67.  
  68. const encodingStream = iconv.encodeStream('win1252');
  69. const decodingStream = iconv.decodeStream('win1252');
  70. pipeline(
  71. encodingStream,
  72. encryptStream,
  73. socketWorld,
  74. decryptStream,
  75. decodingStream,
  76. (err) => {
  77. if (err) {
  78. throw err
  79. }
  80.  
  81. console.log('Game closed because stream pipeline closed.')
  82. }
  83. );
  84. decodingStream.on('data', (data) => {
  85. console.log(data);
  86. });
  87. });
  88. });
  89.  
  90. async function buildLoginPacket () {
  91. const nostalePath = 'C:\\Program Files (x86)\\NosTale_FR';
  92.  
  93. const encodedUsername = iconv.encode(username, 'win1252');
  94. const encodedPassword = iconv.encode(password, 'win1252');
  95.  
  96. const random = Math.floor(Math.random() * 9999999);
  97. const encryptedPassword = nosCrypto.encryptPassword(encodedPassword);
  98. const guid = '12d45678-123d-422a-a223-25bde24865dc';
  99. const version = await nosCrypto.createVersion(nostalePath);
  100. const checksumHash = await nosCrypto.createChecksumHash(encodedUsername, nostalePath);
  101.  
  102. return `NoS0575 ${random} ${username} ${encryptedPassword} ${guid} ${version} 0 ${checksumHash}`;
  103. }
  104.  
  105. function buildSessionWorldPacket() {
  106. let packet = packetId + ' ' + session;
  107. packetId += 1;
  108. console.log(packet);
  109. return packet;
  110. }
  111.  
  112. function buildLoginWorldPacket() {
  113. let packet = packetId + ' ' + username;
  114. packetId += 1;
  115. console.log(packet);
  116. return packet;
  117. }
  118.  
  119. function buildPasswordWorldPacket() {
  120. let packet = packetId + ' ' + password;
  121. packetId += 1;
  122. console.log(packet);
  123. return packet;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement