Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. window.bothub = {
  2. ws: {},
  3. sendInterval: null,
  4. player: {
  5. x: 0,
  6. y: 0,
  7. posX: 0,
  8. posY: 0,
  9. ip: null,
  10. origin: window.location.origin
  11. },
  12. };
  13. window.bothub.botLoadPct = Math.floor((window.bothub.botC / window.bothub.botM) * 100);
  14.  
  15. window.botWebSocket = window.WebSocket;
  16.  
  17. //setTimeout(() => {
  18. window.__WebSocket = window.WebSocket;
  19. window.fakeWebSocket = function() {
  20. return {
  21. readyState: 0
  22. };
  23. };
  24. window._WebSocket = window.WebSocket = function(ip) {
  25. return new window.fakeWebSocket(ip);
  26. };
  27.  
  28. if (!window.OldSocket)
  29. window.OldSocket = window.__WebSocket;
  30. window._WebSocket = window.WebSocket = window.fakeWebSocket = function(ip) {
  31. var ws = new OldSocket(ip);
  32. ws.binaryType = "arraybuffer";
  33. var fakeWS = {};
  34. for (var i in ws)
  35. fakeWS[i] = ws[i];
  36. fakeWS.send = function() {
  37. var msg = new DataView(arguments[0]);
  38. if (msg.getInt8(0, true) === 16) {
  39. if (msg.byteLength === 21) {
  40. window.bothub.player.x = msg.getFloat64(1, true);
  41. window.bothub.player.y = msg.getFloat64(9, true);
  42. }
  43. if (msg.byteLength === 13) {
  44. window.bothub.player.x = msg.getInt32(1, true);
  45. window.bothub.player.y = msg.getInt32(5, true);
  46. }
  47. if (msg.byteLength === 5 || msg.byteLength < 4) {
  48. if (msg.getUint8(0, true) === 16) {
  49. window.bothub.player.x = msg.getInt16(1, true);
  50. window.bothub.player.y = msg.getInt16(3, true);
  51. }
  52. }
  53. }
  54. return ws.send.apply(ws, arguments);
  55. };
  56. ws.onmessage = function(message) {
  57. var msg = new DataView(arguments[0].data);
  58. if (window.location.origin == "http://rata.io") {
  59. var offset = 0;
  60. if (msg.getUint8(offset, true) == 64 && msg.byteLength == 33) {
  61. offset += 1;
  62. window.bothub.minX = msg.getFloat64(offset, true);
  63. offset += 8;
  64. window.bothub.minY = msg.getFloat64(offset, true);
  65. offset += 8;
  66. window.bothub.maxX = msg.getFloat64(offset, true);
  67. offset += 8;
  68. window.bothub.maxY = msg.getFloat64(offset, true);
  69. window.bothub.offsetX = (window.bothub.minX + window.bothub.maxX) / 2;
  70. window.bothub.offsetY = (window.bothub.minY + window.bothub.maxY) / 2;
  71. }
  72. }
  73. fakeWS.onmessage && fakeWS.onmessage.apply(ws, arguments);
  74. };
  75. ws.onopen = function() {
  76. window.bothub.player.ip = ws.url;
  77. fakeWS.readyState = 1;
  78. fakeWS.onopen.apply(ws, arguments);
  79. };
  80. ws.onclose = function() {
  81. fakeWS.readyState = 0;
  82. fakeWS.onclose.apply(ws, arguments);
  83. };
  84. return fakeWS;
  85. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement