Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- window.bothub = {
- ws: {},
- sendInterval: null,
- player: {
- x: 0,
- y: 0,
- posX: 0,
- posY: 0,
- ip: null,
- origin: window.location.origin
- },
- };
- window.bothub.botLoadPct = Math.floor((window.bothub.botC / window.bothub.botM) * 100);
- window.botWebSocket = window.WebSocket;
- //setTimeout(() => {
- window.__WebSocket = window.WebSocket;
- window.fakeWebSocket = function() {
- return {
- readyState: 0
- };
- };
- window._WebSocket = window.WebSocket = function(ip) {
- return new window.fakeWebSocket(ip);
- };
- if (!window.OldSocket)
- window.OldSocket = window.__WebSocket;
- window._WebSocket = window.WebSocket = window.fakeWebSocket = function(ip) {
- var ws = new OldSocket(ip);
- ws.binaryType = "arraybuffer";
- var fakeWS = {};
- for (var i in ws)
- fakeWS[i] = ws[i];
- fakeWS.send = function() {
- var msg = new DataView(arguments[0]);
- if (msg.getInt8(0, true) === 16) {
- if (msg.byteLength === 21) {
- window.bothub.player.x = msg.getFloat64(1, true);
- window.bothub.player.y = msg.getFloat64(9, true);
- }
- if (msg.byteLength === 13) {
- window.bothub.player.x = msg.getInt32(1, true);
- window.bothub.player.y = msg.getInt32(5, true);
- }
- if (msg.byteLength === 5 || msg.byteLength < 4) {
- if (msg.getUint8(0, true) === 16) {
- window.bothub.player.x = msg.getInt16(1, true);
- window.bothub.player.y = msg.getInt16(3, true);
- }
- }
- }
- return ws.send.apply(ws, arguments);
- };
- ws.onmessage = function(message) {
- var msg = new DataView(arguments[0].data);
- if (window.location.origin == "http://rata.io") {
- var offset = 0;
- if (msg.getUint8(offset, true) == 64 && msg.byteLength == 33) {
- offset += 1;
- window.bothub.minX = msg.getFloat64(offset, true);
- offset += 8;
- window.bothub.minY = msg.getFloat64(offset, true);
- offset += 8;
- window.bothub.maxX = msg.getFloat64(offset, true);
- offset += 8;
- window.bothub.maxY = msg.getFloat64(offset, true);
- window.bothub.offsetX = (window.bothub.minX + window.bothub.maxX) / 2;
- window.bothub.offsetY = (window.bothub.minY + window.bothub.maxY) / 2;
- }
- }
- fakeWS.onmessage && fakeWS.onmessage.apply(ws, arguments);
- };
- ws.onopen = function() {
- window.bothub.player.ip = ws.url;
- fakeWS.readyState = 1;
- fakeWS.onopen.apply(ws, arguments);
- };
- ws.onclose = function() {
- fakeWS.readyState = 0;
- fakeWS.onclose.apply(ws, arguments);
- };
- return fakeWS;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement