User:Fearthe1337/Hacky

From the RuneScape Wiki, the wiki for all things RuneScape
Jump to: navigation, search

The script below is a temp 'Patch'/fix for the Avatar viewer. Included is the MediaWiki:AL3DUI.js script. It works by setting the broken check to true, then restoring the page segments that were deleted. Finally it also injects the AL3DUI script.

Please note that this code was written in a short period of time as a "hotfix". No guarantees are given that it will work for everyone. I do not take responsibility for this code, so run it at own risk.

// Fix the broken check
Modernizr.websockets = true;
// Restore the page shit
$('#browserError').removeClass('avatar-viewer__browser-error--show');

$('#avatar-viewer').append(atob('PGRpdiBjbGFzcz0iYXZhdGFyLXZpZXdlcl9fY29udGFpbmVyIj4NCgk8ZGl2IGNsYXNzPSJhdmF0YXItdmlld2VyX19sb2FkaW5nIiBpZD0iYXZhdGFyTG9hZGluZyI+DQoJCTxkaXYgY2xhc3M9ImF2YXRhci12aWV3ZXJfX2NlbGwiPg0KCQkJPGltZyBjbGFzcz0iYXZhdGFyLXZpZXdlcl9fc3Bpbm5lciIgc3JjPSJodHRwOi8vd3d3LnJ1bmVzY2FwZS5jb20vaW1nL3JzMy9nbG9iYWwvbG9hZGluZ19zcGluLnBuZyIgdGl0bGU9IkxvYWRpbmcuLi4iIGFsdD0iTG9hZGluZyIgLz4NCgkJPC9kaXY+DQoJPC9kaXY+DQoJPHNlY3Rpb24gY2xhc3M9ImF2YXRhci12aWV3ZXJfX2FwcGVhcmFuY2UtZXJyb3IiIGlkPSJhcHBlYXJhbmNlRXJyb3IiPg0KCQk8ZGl2IGNsYXNzPSJhdmF0YXItdmlld2VyX19lcnJvci1tZXRhIj4NCgkJPGgyIGNsYXNzPSJhdmF0YXItdmlld2VyX19lcnJvci10aXRsZSI+PHNwYW4+VmlzaXQgdGhlPC9zcGFuPiBwaG90byBib290aDwvaDI+DQoJCTxwIGNsYXNzPSJhdmF0YXItdmlld2VyX19lcnJvci1jb3B5Ij5UaGVyZSB3YXMgYSBwcm9ibGVtIHJldHJpZXZpbmcgeW91ciA8c3Ryb25nPmF2YXRhcjwvc3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ureKeyboard: true,
preRun: [],
postRun: [],
print: function (text){},
printErr: function (text){},
canvas: document.getElementById('canvas'),
totalDependencies: 0,
monitorRunDependencies: function (left){
this.totalDependencies = Math.max(this.totalDependencies, left);
},
loadingComplete: window.avatarViewer.canvas_onload
};
Module.avatar = new Avatar(Module);
window.websocketURL = "ws://js5-provider.runescape.com";
window.avatarURL = "http://services.runescape.com/m=avatar-rs";

var getWorker = function(url,callback) {
	  return callback(url);
};

window.avatarViewerAssetWorkerURL = "avatarviewer-asset-worker.js?6";
window.avatarViewerJs5WorkerURL = "avatarviewer-js5-worker.js?6";
window.addAvatarViewer = function() {
	  var script = document.createElement("script");
	  script.type = "text/javascript";
	  script.src = "avatarviewer.js?6";
	  document.body.appendChild(script);
};

addAvatarViewer();
$('body').append('<script>'+atob('DQp2YXIgR0lGLCBHSUZFbmNvZGVyLCBXaGFtbXksIGJpbmluZGV4LCBieXRlYmxvY2ssIGNoYXJzLCBjdXJiaW4sIGhlaWdodCwgaW1nY2FwdCwgbG9hZGVkU3RyLCBzY3IsIHNldGZyYW1lY2FtLCB3aWR0aDsNCg0KZnVuY3Rpb24gYWIoKSB7DQogICd1c2Ugc3RyaWN0JzsNCg0KICBpZiAod2luZG93LmltZ2NhcHQpIHsNCiAgICBpbWdjYXB0LmZpcnN0TG9hZCA9IGZhbHNlOw0KICB9IGVsc2Ugew0KICAgIGltZ2NhcHQgPSB7DQogICAgICBmaXJzdExvYWQ6IHRydWUNCiAgICB9Ow0KICB9DQoNCiAgLy9EZWZpbml0aW9ucw0KICBjaGFycyA9ICJBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6MDEyMzQ1Njc4OSotIjsNCiAgY3VyYmluID0gIjAwMDAwMDAwMTExMTExMTExMDExMTExMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDA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DsNCiAgICAgIGxvZygiZmluaXNoZWQgLSAiICsgKERhdGUubm93KCkgLSBzdGFydHRpbWUpICsgIm1zIik7DQogICAgICBhbmltZW5kZWQgPSB0cnVlOw0KICAgICAgaWYgKGZvcm1hdCA9PSAiZ2lmIikgew0KICAgICAgICBlbmNvZGVyLmZpbmlzaCgpOw0KICAgICAgICB1cmwgPSAiZGF0YTppbWFnZS9naWY7YmFzZTY0LCIgKyBidG9hKGVuY29kZXIuc3RyZWFtKCkNCiAgICAgICAgICAuZ2V0RGF0YSgpKTsNCiAgICAgIH0NCiAgICAgIGlmIChmb3JtYXQgPT0gIndlYm0iKSB7DQogICAgICAgIHVybCA9ICh3aW5kb3cud2Via2l0VVJMIHx8IHdpbmRvdy5VUkwpDQogICAgICAgICAgLmNyZWF0ZU9iamVjdFVSTChlbmNvZGVyLmNvbXBpbGUoKSk7DQogICAgICB9DQogICAgICBpZiAoZm9ybWF0ID09ICJnaWYyIikgew0KICAgICAgICBlbmNvZGVyLm9uKCdmaW5pc2hlZCcsIGZ1bmN0aW9uKGJsb2IpIHsNCiAgICAgICAgICB3aW5kb3cub3BlbihVUkwuY3JlYXRlT2JqZWN0VVJMKGJsb2IpKTsNCiAgICAgICAgfSk7DQogICAgICAgIGVuY29kZXIucmVuZGVyKCk7DQogICAgICB9DQogICAgICBpZiAodXJsKSB7DQogICAgICAgIHdpbmRvdy5vcGVuKHVybCk7DQogICAgICB9DQogICAgfTsNCiAgICBhZGRmcmFtZSA9IGZ1bmN0aW9uKCkgew0KICAgICAgdmFyIGlzbGFzdGZyYW1lLCBmcmFtZXRpbWU7DQogICAgICBpZiAoYW5pbWVuZGVkKSB7DQogICAgICAgIHJldHVybjsNCiAgICAgIH0NCiAgICAgIC8vY2hlY2sgaWYgdGhpcyBpcyBsYXN0IGZyYW1lDQogICAgICBpc2xhc3RmcmFtZSA9IGZhbHNlOw0KICAgICAgaWYgKHRlbXBsYXRlLmZyYW1lcykgew0KICAgICAgICBpZiAoZnJhbWV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hcHQuZ2lmMndvcmtlcnN0ciksDQogICAgICAgIHdpZHRoOiB0ZW1wbGF0ZS5jcm9wLncsDQogICAgICAgIGhlaWdodDogdGVtcGxhdGUuY3JvcC5oLA0KICAgICAgICB0cmFuc3BhcmVudDogdHJhbnMNCiAgICAgIH0pOw0KICAgIH0NCiAgICBzdGFydCgpOw0KICB9Ow0KDQogIC8vSGV4IHRhYmxlDQogIGltZ2NhcHQuZHJhd3N0ciA9IGZ1bmN0aW9uKHN0cikgew0KICAgIHZhciBhLCBiLCBjLCByLCBwYXJ0cywgYmxvY2ssIGJsb2NrcywgaGV4LCByb290Ow0KDQogICAgLy9CeXRlYmxvY2sgY2xhc3MNCiAgICBieXRlYmxvY2sgPSBmdW5jdGlvbigpIHsNCiAgICAgICAgdGhpcy5oZXggPSAiIjsNCiAgICAgICAgdGhpcy5yZWFkID0gZnVuY3Rpb24obCkgew0KICAgICAgICAgIHJldHVybiBwYXJzZUludCh0aGlzLmhleC5zbGljZSgwLCBsICogMiksIDE2KTsNCiAgICAgICAgfTsNCiAgICAgICAgdGhpcy5yZWFkSGV4ID0gZnVuY3Rpb24obCkgew0KICAgICAgICAgIHJldHVybiB0aGlzLmhleC5zbGljZSgwLCBsICogMik7DQogICAgICAgIH07DQogICAgICAgIHRoaXMuc2V0aW50ID0gZnVuY3Rpb24obiwgbCkgew0KICAgICAgICAgIHRoaXMuaGV4ID0gbnVtVG9IZXgobiwgbCAqIDIpOw0KICAgICAgICB9Ow0KICAgICAgfTsNCg0KICAgIC8vUGFyc2Vycw0KICAgIHZhciBwYXJzZWdlbmRlciA9IGZ1bmN0aW9uKG9iaikgew0KICAgICAgb2JqLmwgPSAxOw0KICAgICAgb2JqLmNvbnRyb2wgPSB7DQogICAgICAgIHQ6ICJkcm9wZG93biIsDQogICAgICAgIHY6IG9iai5yZWFkKDEpLA0KICAgICAgICBvcHRzOiBbDQogICAgICAgICAgWzAsICJNYWxlIl0sDQogICAgICAgICAgWzEsICJGZW1hbGUiXQ0KICAgICAgICBdLA0KICAgICAgICBmdW5jOiBmdW5jdGlvbihvYmosIHYpIHsNCiAgICAgICAgICBvYmouc2V0aW50KHYsIDEpOw0KICAgICAgICB9DQogICAgICB9Ow0KICAgICAgb2JqLnJlc2V0ID0gZnVuY3Rpb24ob2JqKSB7DQogICAgICAgIG9iai5zZXRpbnQoMCwgMSk7DQogICAgICB9Ow0KICAgIH07DQogICAgdmFyIHBhcnNlc2xvdCA9IGZ1bmN0aW9uKG9iaikgew0KICAgICAgdmFyIGlkOw0KICAgICAgaWYgKG9iai5yZWFkKDEpICE9PSAwKSB7IC8vaXMgZXF1aXBlZA0KICAgICAgICBpZCA9IG9iai5yZWFkKDIpIC0gMHg0MDAwOw0KICAgICAgICBvYmoubCA9IDI7DQogICAgICAgIG9iai5jb250cm9sID0gew0KICAgICAgICAgIHQ6ICJpbnQiLA0KICAgICAgICAgIHY6IGlkLA0KICAgICAgICAgIGZ1bmM6IGZ1bmN0aW9uKG9iaiwgdikgew0KICAgICAgICAgICAgb2JqLmwgPSAyOw0KICAgICAgICAgICAgb2JqLnNldGludCgrdiArIDB4NDAwMCwgMik7DQogICAgICAgICAgfQ0KICAgICAgICB9Ow0KICAgICAgICBpZiAoaWQgPj0gMCkgew0KICAgICAgICAgLy8gb2JqLmNvbnRyb2wudGl0bGUgPSBpdGVtc1tpZF0gJiYgaXRlbXNbaWRdLm47DQogICAgICAgIH0NCiAgICAgICAgb2JqLnJlc2V0ID0gZnVuY3Rpb24ob2JqKSB7DQogICAgICAgICAgb2JqLmwgPSAxOw0KICAgICAgICAgIG9iai5zZXRpbnQoMCwgMSk7DQogICAgICAgIH07DQogICAgICB9IGVsc2Ugew0KICAgICAgICBvYmoubCA9IDE7DQogICAgICAgIG9iai5jb250cm9sID0gew0KICAgICAgICAgIHQ6ICJidXR0b24iLA0KICAgICAgICAgIHY6ICJFcXVpcCIsDQogICAgICAgICAgZnVuYzogZnVuY3Rpb24ob2JqKSB7DQogICAgICAgICAgICBvYmoubCA9IDI7DQogICAgICAgICAgICBvYmouc2V0aW50KDB4NDAwMCwgMik7DQogICAgICAgICAgfQ0KICAgICAgICB9Ow0KICAgICAgfQ0KICAgIH07DQogICAgdmFyIHNldHJlY29sID0gZnVuY3Rpb24ob2JqLCBpbmRleCkgew0KICAgICAgdmFyIGEsIGIsIGxlbjsNCiAgICAgIG9iai5sID0gMjsNCiAgICAgIGEgPSBudW1Ub0JpbihwYXJzZUludChvYmoucmVhZCgyKSksIDE2KTsNCiAgICAgIGxlbiA9IGEubGVuZ3RoIC0gMTsNCiAgICAgIGZvciAoYiA9IGxlbjsgYiA+PSAwOyBiLS0pIHsNCiAgICAgICAgaWYgKGFbYl0gPT0gIjAiKSB7DQogICAgICAgICAgY29udGludWU7DQogICAgICAgIH0NCiAgICAgICAgcGFydHMuc3BsaWNlKCsraW5kZXgsIDAsIHsNCiAgICAgICAgICBuOiAiYy4iICsgc2xvdG5hbWVzW2xlbiAtIGJdLA0KICAgICAgICAgIHBhcnNlOiBwYXJzZWl0ZW1kYXRhDQogICAgICAgIH0pOw0KICAgICAgfQ0KICAgIH07DQogICAgdmFyIHBhcnNlaXRlbWRhdGEgPSBmdW5jdGlvbihvYmosIGluZGV4KSB7DQogICAgICB2YXIgZmxhZ3M7DQogICAgICBvYmoubCA9IDE7DQogICAgICBmbGFncyA9IG9iai5yZWFkKDEpOw0KICAgICAgaWYgKGZsYWdzICYgMHgxKSB7DQogICAgICAgIHBhcnRzLnNwbGljZSgrK2luZGV4LCAwLCB7DQogICAgICAgICAgbjogImRhdGEgMCIsDQogICAgICAgICAgbDogMg0KICAgICAgICB9KTsNCiAgICAgICAgcGFydHMuc3BsaWNlKCsraW5kZXgsIDAsIHsNCiAgICAgICAgICBuOiAiZGF0YSAxIiwNCiAgICAgICAgICBsOiAyDQogICAgICAgIH0pOw0KICAgICAgICBwYXJ0cy5zcGxpY2UoKytpbmRleCwgMCwgew0KICAgICAgICAgIG46ICJkYXRhIDIiLA0KICAgICAgICAgIGw6IDINCiAgICAgICAgfSk7DQogICAgICAgIHBhcnRzLnNwbGljZSgrK2luZGV4LCAwLCB7DQogICAgICAgICAgbjogImRhdGEgMyIsDQogICAgICAgICAgbDogMg0KICAgICAgICB9KTsNCiAgICAgIH0NCiAgICAgIGlmIChmbGFncyAmIDB4Mikgew0KICAgICAgICAvL2NvbnNvbGUubG9nKCJzbG90IGRhdGEgZmxhZyAweDIgPz8iKTsNCiAgICAgIH0NCiAgICAgIGlmIChmbGFncyAmIDB4NCkgew0KICAgICAgICBwYXJ0cy5zcGxpY2UoKytpbmRleCwgMCwgew0KICAgICAgICAgIG46ICJ0eXBlIiwNCiAgICAgICAgICBwYXJzZTogcGFyc2Vjb2wNCiAgICAgICAgfSk7DQogICAgICB9DQogICAgICBpZiAoZmxhZ3MgJiAweDgpIHsNCiAgICAgICAgLy9jb25zb2xlLmxvZygic2xvdCBkYXRhIGZsYWcgMHg4ID8/Iik7DQogICAgICB9DQogICAgfTsNCiAgICB2YXIgcGFyc2Vjb2wgPSBmdW5jdGlvbihvYmosIGluZGV4KSB7DQogICAgICB2YXIgY29kZTsNCiAgICAgIG9iai5sID0gMjsNCiAgICAgIGNvZGUgPSBvYmoucmVhZCgyKTsNCiAgICAgIGlmIChjb2RlID09IDB4MzIxMCkgew0KICAgICAgICBwYXJ0cy5zcGxpY2UoaW5kZXggKyAxLCAwLCB7DQogICAgICAgICAgbjogImNvbG9yIiwNCiAgICAgICAgICB0eXBlOiAiY29sb3I0Ig0KICAgICAgICB9KTsNCiAgICAgIH0NCiAgICAgIGlmIChjb2RlID09IDB4ODAwMSB8fCBjb2RlID09IDB4MjIwZikgew0KICAgICAgICBwYXJ0cy5zcGxpY2UoaW5kZXggKyAxLCAwLCB7DQogICAgICAgICAgbjogImNvbCAwIiwNCiAgICAgICAgICB0eXBlOiAiY29sb3IiDQogICAgICAgIH0pOw0KICAgICAgICBwYXJ0cy5zcGxpY2UoaW5kZXggKyAyLCAwLCB7DQogICAgICAgICAgbjogImNvbCAxIiwNCiAgICAgICAgICB0eXBlOiAiY29sb3IiDQogICAgICAgIH0pOw0KICAgICAgfQ0KICAgIH07DQogICAgLy9VbnVzZWQgdmFyDQogICAgLyp2YXIgcGFyc2VzdWJjb2wgPSBmdW5jdGlvbihvYmopIHsNCiAgICAgIG9iai5sID0gMjsNCiAgICAgIG9iai5jb250cm9sID0gew0KICAgICAgICB0OiAiY29sb3IiLA0KICAgICAgICB2OiBvYmoucmVhZEhleCgyKSwNCiAgICAgICAgZnVuYzogZnVuY3Rpb24ob2JqLCB2KSB7DQogICAgICAgICAgb2JqLnNldGludChyZ2JUb0hzbCh2LnNsaWNlKDEpKSwgMik7DQogICAgICAgIH0NCiAgICAgIH07DQogICAgfTsqLw0KICAgIHZhciBzbG90bmFtZXMgPSBbIkhlbG0iLCAiQ2FwZSIsICJOZWNrIiwgIldlYXBvbiIsICJCb2R5IiwgIk9mZi1oYW5kIiwgIkFybXMiLCAiTGVncyIsICJGYWNlIiwgIkhhbmRzIiwgIkJvb3RzIiwgIkphdyIsICJBdXJhIiwgIlNoLiBtaCIsICJTaC4gb2giLCAiV2luZ3MiXTsNCiAgICBwYXJ0cyA9IFt7DQogICAgICAgIG46ICJHZW5kZXIiLA0KICAgICAgICBwYXJzZTogcGFyc2VnZW5kZXINCiAgICAgIH0sIHsNCiAgICAgICAgbjogIkhlbG0iLA0KICAgICAgICBwYXJzZTogcGFyc2VzbG90DQogICAgICB9LCB7DQogICAgICAgIG46ICJDYXBlIiwNCiAgICAgICAgcGFyc2U6IHBhcnNlc2xvdA0KICAgICAgfSwgLy9DYW4gYWxzbyBiZSBXaW5nDQogICAgICB7DQogICAgICAgIG46ICJOZWNrIiwNCiAgICAgICAgcGFyc2U6IHBhcnNlc2xvdA0KICAgICAgfSwgew0KICAgICAgICBuOiAiV2VhcG9uIiwNCiAgICAgICAgcGFyc2U6IHBhcnNlc2xvdA0KICAgICAgfSwgLy9JdGVtIGlkICs2NCwgMHg0MCBib29naWUgYm93DQogICAgICB7DQogICAgICAgIG46ICJCb2R5IiwNCiAgICAgICAgcGFyc2U6IHBhcnNlc2xvdA0KICAgICAgfSwgew0KICAgICAgICBuOiAiT2ZmLWhhbmQiLA0KICAgICAgICBwYXJzZTogcGFyc2VzbG90DQogICAgICB9LCB7DQogICAgICAgIG46ICJBcm1zIiwNCiAgICAgICAgcGFyc2U6IHBhcnNlc2xvdA0KICAgICAgfSwgew0KICAgICAgICBuOiAiTGVncyIsDQogICAgICAgIHBhcnNlOiBwYXJzZXNsb3QNCiAgICAgIH0sIHsNCiAgICAgICAgbjogIkZhY2UiLA0KICAgICAgICBwYXJzZTogcGFyc2VzbG90DQogICAgICB9LCB7DQogICAgICAgIG46ICJIYW5kcyIsDQogICAgICAgIHBhcnNlOiBwYXJzZXNsb3QNCiAgICAgIH0sIHsNCiAgICAgICAgbjogIkJvb3RzIiwNCiAgICAgICAgcGFyc2U6IHBhcnNlc2xvdA0KICAgICAgfSwgew0KICAgICAgICBuOiAiSmF3IiwNCiAgICAgICAgcGFyc2U6IHBhcnNlc2xvdA0KICAgICAgfSwgew0KICAgICAgICBuOiAiQXVyYSIsDQogICAgICAgIHBhcnNlOiBwYXJzZXNsb3QNCiAgICAgIH0sIHsNCiAgICAgICAgbjogIlNoLiBtaCIsDQogICAgICAgIHBhcnNlOiBwYXJzZXNsb3QNCiAgICAgIH0sIC8vbWgNCiAgICAgIHsNCiAgICAgICAgbjogIlNoLiBvaCIsDQogICAgICAgIHBhcnNlOiBwYXJzZXNsb3QNCiAgICAgIH0sIHsNCiAgICAgICAgbjogIldpbmdzIiwNCiAgICAgICAgcGFyc2U6IHBhcnNlc2xvdA0KICAgICAgfSwgew0KICAgICAgICBuOiAiUmVjb2wiLA0KICAgICAgICBwYXJzZTogc2V0cmVjb2wNCiAgICAgIH0sIHsNCiAgICAgICAgbjogImMuSGFpciIsDQogICAgICAgIGw6IDENCiAgICAgIH0sIHsNCiAgICAgICAgbjogImMuVG9wIiwNCiAgICAgICAgbDogMQ0KICAgICAgfSwgew0KICAgICAgICBuOiAiYy5MZWdzIiwNCiAgICAgICAgbDogMQ0KICAgICAgfSwgew0KICAgICAgICBuOiAiYy5Cb290cyIsDQogICAgICAgIGw6IDENCiAgICAgIH0sIHsNCiAgICAgICAgbjogImMuV3Jpc3Q/IiwNCiAgICAgICAgbDogMQ0KICAgICAgfSwgew0KICAgICAgICBuOiAiQmluIiwNCiAgICAgICAgbDogMg0KICAgICAgfSwgew0KICAgICAgICBuOiAiQmluIiwNCiAgICAgICAgbDogMg0KICAgICAgfSwgew0KICAgICAgICBuOiAiQmluIiwNCiAgICAgICAgbDogMQ0KICAgICAgfSwgew0KICAgICAgICBuOiAiQW5pbSIsDQogICAgICAgIGw6IDIsDQogICAgICAgIHR5cGU6ICJpbnQiDQogICAgICB9DQogICAgXTsNCiAgICBoZXggPSBiYXNlNjRUb0hleChzdHIpOw0KICAgIGJsb2NrcyA9IFtdOw0KICAgIGZvciAoYSA9IDA7IGEgPCBwYXJ0cy5sZW5ndGg7IGErKykgew0KICAgICAgYmxvY2sgPSBuZXcgYnl0ZWJsb2NrKCk7DQogICAgICBibG9jay5oZXggPSBoZXg7DQogICAgICBibG9jay5uYW1lID0gcGFydHNbYV0ubjsNCiAgICAgIGlmIChwYXJ0c1thXS5wYXJzZSkgew0KICAgICAgICBwYXJ0c1thXS5wYXJzZShibG9jaywgYSk7DQogICAgICB9DQogICAgICBpZiAocGFydHNbYV0ubCAhPT0gdW5kZWZpbmVkKSB7DQogICAgICAgIGJsb2NrLmwgPSBwYXJ0c1thXS5sOw0KICAgICAgfQ0KICAgICAgaWYgKHBhcnRzW2FdLnR5cGUpIHsNCiAgICAgICAgaWYgKHBhcnRzW2FdLnR5cGUgPT0gImludCIpIHsNCiAgICAgICAgICBibG9jay5jb250cm9sID0gew0KICAgICAgICAgICAgdjogYmxvY2sucmVhZChibG9jay5sKSwNCiAgICAgICAgICAgIHQ6ICJpbnQiLA0KICAgICAgICAgICAgZnVuYzogZnVuY3Rpb24ob2JqLCB2KSB7DQogICAgICAgICAgICAgIG9iai5zZXRpbnQoK3YsIG9iai5sKTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgICB9Ow0KICAgICAgICB9DQogICAgICAgIGlmIChwYXJ0c1thXS50eXBlID09ICJjb2xvciIpIHsNCiAgICAgICAgICBibG9jay5sID0gMjsNCiAgICAgICAgICBibG9jay5jb250cm9sID0gew0KICAgICAgICAgICAgdjogYmxvY2sucmVhZEhleCgyKSwNCiAgICAgICAgICAgIHQ6ICJjb2xvciIsDQogICAgICAgICAgICBmdW5jOiBmdW5jdGlvbihvYmosIHYpIHsNCiAgICAgICAgICAgICAgb2JqLmhleCA9IHJnYlRvSHNsKHYuc2xpY2UoMSkpOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgIH07DQogICAgICAgIH0NCiAgICAgICAgaWYgKHBhcnRzW2FdLnR5cGUgPT0gImNvbG9yNCIpIHsNCiAgICAgICAgICBibG9jay5sID0gODsNCiAgICAgICAgICBibG9jay5jb250cm9sID0gew0KICAgICAgICAgICAgdjogYmxvY2sucmVhZEhleCg4KSwNCiAgICAgICAgICAgIHQ6ICJjb2xvcjQiLA0KICAgICAgICAgICAgZnVuYzogZnVuY3Rpb24ob2JqLCB2KSB7DQogICAgICAgICAgICAgIG9iai5oZXggPSBvYmouaGV4LnNsaWNlKDAsIHZbMF0gKiA0KSArIHJnYlRvSHNsKHZbMV0uc2xpY2UoMSkpICsgb2JqLmhleC5zbGljZSh2WzBdICogNCArIDQpOw0KICAgICAgICAgICAgfQ0KICAgICAgICAgIH07DQogICAgICAgIH0NCiAgICAgIH0NCiAgICAgIGJsb2NrLmhleCA9IGhleC5zbGljZSgwLCBibG9jay5sICogMik7DQogICAgICBoZXggPSBoZXguc2xpY2UoYmxvY2subCAqIDIpOw0KICAgICAgYmxvY2tzLnB1c2goYmxvY2spOw0KICAgIH0NCiAgICByID0gIjx0YWJsZT48dHI+PHRoPk5hbWU8L3RoPjx0aD5IZXg8L3RoPjx0aD5FZGl0PC90aD48dGg+UmVzZXQ8L3RoPjwvdHI+IjsNCiAgICBmb3IgKGEgPSAwOyBhIDwgYmxvY2tzLmxlbmd0aDsgYSsrKSB7DQogICAgICBibG9jayA9IGJsb2Nrc1thXTsNCiAgICAgIHIgKz0gIjx0cj4iOw0KICAgICAgLy9OYW1lDQogICAgICByICs9ICI8dGQ+IiArIGJsb2NrLm5hbWUgKyAiPC90ZD4iOw0KICAgICAgLy9IZXgNCiAgICAgIHIgKz0gIjx0ZD4iOw0KICAgICAgYyA9ICIiOw0KICAgICAgZm9yIChiID0gMDsgYiA8IGJsb2NrLmw7IGIrKykgew0KICAgICAgICBjICs9IChiID09PSAwID8gIiIgOiAiICIpICsgYmxvY2suaGV4LnNsaWNlKGIgKiAyLCBiICogMiArIDIpOw0KICAgICAgfQ0KICAgICAgciArPSAiPGlucHV0IHN0eWxlPSd3aWR0aDozNXB4Oycgb25rZXlkb3duPSdpbWdjYXB0LmJsb2Nra2V5ZG93bigiICsgYSArICIsZXZlbnQpOycgb25jaGFuZ2U9J2ltZ2NhcHQuZWRpdGJsb2NraGV4KCIgKyBhICsgIix0aGlzLnZhbHVlKScgdmFsdWU9JyIgKyBjICsgIicvPiI7DQogICAgICByICs9ICI8L3RkPiI7DQogICAgICAvL0VkaXQNCiAgICAgIGlmIChibG9jay5jb250cm9sKSB7DQogICAgICAgIHIgKz0gIjx0ZD4iOw0KICAgICAgICBpZiAoYmxvY2suY29udHJvbC50ID09ICJidXR0b24iKSB7DQogICAgICAgICAgciArPSAiPGlucHV0IHR5cGU9J2J1dHRvbicgc3R5bGU9J3dpZHRoOjY0cHg7JyBvbmNsaWNrPSdpbWdjYXB0LmVkaXRibG9jaygiICsgYSArICIsdHJ1ZSknIHZhbHVlPSciICsgYmxvY2suY29udHJvbC52ICsgIicgLz4iOw0KICAgICAgICB9DQogICAgICAgIGlmIChibG9jay5jb250cm9sLnQgPT0gImludCIpIHsNCiAgICAgICAgICByICs9ICI8aW5wdXQgdHlwZT0nbnVtYmVyJyBzdHlsZT0nd2lkdGg6NjRweDsnICIgKyAoYmxvY2suY29udHJvbC50aXRsZSA/ICJ0aXRsZT0nIiArIGJsb2NrLmNvbnRyb2wudGl0bGUucmVwbGFjZSgvJy9nLCAiJmFwb3M7IikgKyAiJyIgOiAiIikgKyAiIG9uY2hhbmdlPSdpbWdjYXB0LmVkaXRibG9jaygiICsgYSArICIsdGhpcy52YWx1ZSknIHZhbHVlPSciICsgYmxvY2suY29udHJvbC52ICsgIicgLz4iOw0KICAgICAgICB9DQogICAgICAgIGlmIChibG9jay5jb250cm9sLnQgPT0gImRyb3Bkb3duIikgew0KICAgICAgICAgIHIgKz0gIjxzZWxlY3Qgb25jaGFuZ2U9J2ltZ2NhcHQuZWRpdGJsb2NrKCIgKyBhICsgIix0aGlzLnZhbHVlKSc+IjsNCiAgICAgICAgICBmb3IgKGIgPSAwOyBiIDwgYmxvY2suY29udHJvbC5vcHRzLmxlbmd0aDsgYisrKSB7DQogICAgICAgICAgICByICs9ICI8b3B0aW9uICIgKyAoYmxvY2suY29udHJvbC52ID09IGJsb2NrLmNvbnRyb2wub3B0c1tiXVswXSA/ICJzZWxlY3RlZCIgOiAiIikgKyAiIHZhbHVlPSciICsgYmxvY2suY29udHJvbC5vcHRzW2JdWzBdICsgIic+IiArIGJsb2NrLmNvbnRyb2wub3B0c1tiXVsxXSArICI8L29wdGlvbj4iOw0KICAgICAgICAgIH0NCiAgICAgICAgICByICs9ICI8L3NlbGVjdD4iOw0KICAgICAgICB9DQogICAgICAgIGlmIChibG9jay5jb250cm9sLnQgPT0gImNvbG9yIikgew0KICAgICAgICAgIHIgKz0gIjxpbnB1dCB0eXBlPSdjb2xvcicgc3R5bGU9J3dpZHRoOjY0cHgnIG9uY2hhbmdlPSdpbWdjYXB0LmVkaXRibG9jaygiICsgYSArICIsdGhpcy52YWx1ZSk7JyB2YWx1ZT0nIyIgKyBoc2xUb1JnYihibG9jay5jb250cm9sLnYpICsgIicgLz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AgfQ0KICAgIHN0ciArPSBpbWdjYXB0LnN0cmVkaXQuaGV4dGFpbDsNCiAgICBpZiAod2luZG93LmV2ZW50KSB7DQogICAgICByb290ID0gZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoInN0cmVkaXRyb290Iik7DQogICAgICBpZiAocm9vdCkgew0KICAgICAgICBzY3JvbGwgPSByb290LnNjcm9sbFRvcDsNCiAgICAgIH0NCiAgICAgIGEgPSB3aW5kb3cuZXZlbnQudGFyZ2V0Ow0KICAgICAgaWYgKGEpIHsNCiAgICAgICAgaWYgKGEudHlwZSA9PSAidGV4dCIpIHsNCiAgICAgICAgICBzZWxlY3RzdGFydCA9IGEuc2VsZWN0aW9uU3RhcnQ7DQogICAgICAgIH0NCiAgICAgICAgYSA9IGEucGFyZW50RWxlbWVudDsNCiAgICAgIH0NCiAgICAgIGlmIChhKSB7DQogICAgICAgIG50aDIgPSAxOw0KICAgICAgICBiID0gYTsNCiAgICAgICAgd2hpbGUgKGIubm9kZVR5cGUgPT09IE5vZGUuRUxFTUVOVF9OT0RFICYmIChiID0gYi5wcmV2aW91c1NpYmxpbmcpKSB7DQogICAgICAgICAgbnRoMisrOw0KICAgICAgICB9DQogICAgICAgIGEgPSBhLnBhcmVudEVsZW1lbnQ7DQogICAgICB9DQogICAgICBpZiAoYSkgew0KICAgICAgICBudGggPSAxOw0KICAgICAgICBiID0gYTsNCiAgICAgICAgd2hpbGUgKGIubm9kZVR5cGUgPT09IE5vZGUuRUxFTUVOVF9OT0RFICYmIChiID0gYi5wcmV2aW91c1NpYmxpbmcpKSB7DQogICAgICAgICAgbnRoKys7DQogICAgICAgIH0NCiAgICAgIH0NCiAgICB9DQogICAgaW1nY2FwdC5zZXRzdHJpbmcoaGV4VG9CYXNlNjQoc3RyKSk7DQogICAgaWYgKG50aCAhPT0gdW5kZWZpbmVkKSB7DQogICAgICBhID0gIiNzdHJlZGl0cm9vdCA+IHRhYmxlID4gdGJvZHkgPiB0cjpudGgtY2hpbGQ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AgfQ0KICAgICAgICBpZiAoaW1nY2FwdC5maXJzdExvYWQpIHsNCiAgICAgICAgICBpbWdjYXB0LmZpcnN0TG9hZCA9IGZhbHNlOw0KICAgICAgICB9IGVsc2UgaWYgKGIpIHsNCiAgICAgICAgICBpbWdjYXB0LnVwbG9hZEltZygpOw0KICAgICAgICAgIGltZ2NhcHQubGFzdExvYWQgPSBEYXRlLm5vdygpOw0KICAgICAgICAgIGltZ2NhcHQuY2FwdHVyZWQucHVzaCh7DQogICAgICAgICAgICBzdHI6IGltZ2NhcHQuY3VycmVudFN0ciwNCiAgICAgICAgICAgIHN1Y2Nlc3M6IHRydWUNCiAgICAgICAgICB9KTsNCiAgICAgICAgfQ0KICAgICAgICBpbWdjYXB0LnNldE5leHRQbGF5ZXIoKTsNCiAgICAgIH0sIGltZ2NhcHQuc2V0dGxlVGltZSk7DQogICAgICByZXR1cm47DQogICAgfQ0KICAgIGlmIChjIDwgMC41ICYmIGltZ2NhcHQubGFzdExvYWQgPCBEYXRlLm5vdygpIC0gaW1nY2FwdC5za2lwVGltZSAmJiAhaW1nY2FwdC5maXJzdExvYWQpIHsNCiAgICAgIGltZ2NhcHQubG9ndXBsb2FkKCJsb2FkIGZhaWxlZCIpOw0KICAgICAgaW1nY2FwdC5sYXN0TG9hZCA9IERhdGUubm93KCk7DQogICAgICBpbWdjYXB0LmNhcHR1cmVkLnB1c2goew0KICAgICAgICBzdHI6IGltZ2NhcHQuY3VycmVudFN0ciwNCiAgICAgICAgc3VjY2VzczogZmFsc2UNCiAgICAgIH0pOw0KICAgICAgaW1nY2FwdC5zZXROZXh0UGxheWVyKCk7DQogICAgICByZXR1cm47DQogICAgfQ0KICAgIHNldFRpbWVvdXQoaW1nY2FwdC5jaGVja0ltZywgaW1nY2FwdC5jaGVja1RpbWUpOw0KICB9Ow0KICBpbWdjYXB0LmdldEltZyA9IGZ1bmN0aW9uKCkgew0KICAgIGltZ2NhcHQuc2F2ZUNudi53aWR0aCA9IGltZ2NhcHQud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VuY3Rpb24gdm1wcih2LCBtKSB7IC8vVmVjdG9yLW1hdHJpeCBwcm9kdWN0DQogICAgdmFyIGEsIGIsIHIsIHZsOw0KICAgIHIgPSBbXTsNCiAgICB2bCA9IHYubGVuZ3RoOw0KICAgIGZvciAoYSA9IDA7IGEgPCB2bDsgYSsrKSB7DQogICAgICByW2FdID0gMDsNCiAgICAgIGZvciAoYiA9IDA7IGIgKiB2bCA8IG0ubGVuZ3RoOyBiKyspIHsNCiAgICAgICAgclthXSArPSB2W2JdICogbVthICsgYiAqIHZsXTsNCiAgICAgIH0NCiAgICB9DQogICAgcmV0dXJuIHI7DQogIH0NCg0KICBmdW5jdGlvbiBtbXByKG0xLCBtMikgew0KICAgIHZhciBhLCBiLCBjLCBzaXplLCByOw0KICAgIHNpemUgPSBNYXRoLnNxcnQobTEubGVuZ3RoKTsNCiAgICByID0gW107DQogICAgZm9yIChiID0gMDsgYiA8IHNpemU7IGIrKykgew0KICAgICAgZm9yIChhID0gMDsgYSA8IHNpemU7IGErKykgew0KICAgICAgICByW2EgKyBzaXplICogYl0gPSAwOw0KICAgICAgICBmb3IgKGMgPSAwOyBjIDwgc2l6ZTsgYysrKSB7DQogICAgICAgICAgclthICsgc2l6ZSAqIGJdICs9IG0xW2MgKyBzaXplICogYl0gKiBtMlthICsgc2l6ZSAqIGNdOw0KICAgICAgICB9DQogICAgICB9DQogICAgfQ0KICAgIHJldHVybiByOw0KICB9DQoNCiAgaW1nY2FwdC5zZXRDYW0gPSBmdW5jdGlvbihjYW1vYmopIHsNCiAgICB2YXIgdHIxLCB0cjIsIHRyMywgciwgaW5pdGlhbCwgYXNwZWN0Ow0KICAgIHZhciBhYSwgYWIsIGFjLCB4LCB5LCB6Ow0KICAgIGlmIChjYW1vYmopIHsNCiAgICAgIGFhID0gY2Ftb2JqLmFuZ2xlWzBdOw0KICAgICAgYWIgPSBjYW1vYmouYW5nbGVbMV07DQogICAgICBhYyA9IGNhbW9iai5hbmdsZVsyXTsNCiAgICA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HEsIGggKyAxIC8gMyk7DQogICAgICBnID0gaHVlMnJnYihwLCBxLCBoKTsNCiAgICAgIGIgPSBodWUycmdiKHAsIHEsIGggLSAxIC8gMyk7DQogICAgfQ0KICAgIHJldHVybiBbTWF0aC5yb3VuZChyICogMjU1KSwgTWF0aC5yb3VuZChnICogMjU1KSwgTWF0aC5yb3VuZChiICogMjU1KV07DQogIH0NCg0KICBmdW5jdGlvbiBfcmdiVG9Ic2wociwgZywgYikgew0KICAgICAgciAvPSAyNTUsIGcgLz0gMjU1LCBiIC89IDI1NTsNCiAgICAgIHZhciBtYXggPSBNYXRoLm1heChyLCBnLCBiKSwNCiAgICAgICAgbWluID0gTWF0aC5taW4ociwgZywgYik7DQogICAgICB2YXIgaCwgcywgbCA9IChtYXggKyBtaW4pIC8gMjsNCiAgICAgIGlmIChtYXggPT0gbWluKSB7DQogICAgICAgIGggPSBzID0gMDsgLy8gYWNocm9tYXRpYw0KICAgICAgfSBlbHNlIHsNCiAgICAgICAgdmFyIGQgPSBtYXggLSBtaW47DQogICAgICAgIHMgPSBsID4gMC41ID8gZCAvICgyIC0gbWF4IC0gbWluKSA6IGQgLyAobWF4ICsgbWluKTsNCiAgICAgICAgc3dpdGNoIChtYXgpIHsNCiAgICAgICAgICBjYXNlIHI6DQogICAgICAgICAgICBoID0gKGcgLSBiKSAvIGQgKyAoZyA8IGIgPyA2IDogMCk7DQogICAgICAgICAgICBicmVhazsNCiAgICAgICAgICBjYXNlIGc6DQogICAgICAgICAgICBoID0gKGIgLSByKSAvIGQgKyAyOw0KICAgICAgICAgICAgYnJlYWs7DQogICAgICAgICAgY2FzZSBiOg0KICAgICAgICAgICAgaCA9IChyIC0gZykgLyBkICsgNDsNCiAgICAgICAgICAgIGJyZWFrOw0KICAgICAgICB9DQogICAgICAgIGggLz0gNjsNCiAgICAgIH0NCiAgICAgIHJldHVybiBbaCwgcywgbF07DQogICAgfQ0KDQogIC8vTGlicmFyeQ0KICBmdW5jdGlvbiBkbHBhZ2UodXJsLCBmdW5jLCBlcnJvcmZ1bmMpIHsNCiAgICAgIHZhciByZXE7DQogICAgICByZXEgPSBuZXcgWE1MSHR0cFJlcXVlc3QoKTsNCiAgICAgIGlmIChmdW5jKSB7DQogICAgICAgIHJlcS5vbmxvYWQgPSBmdW5jdGlvbigpIHsNCiAgICAgICAgICBmdW5jKHJlcS5yZXNwb25zZVRleHQpOw0KICAgICAgICB9Ow0KICAgICAgfQ0KICAgICAgaWYgKGVycm9yZnVuYykgew0KICAgICAgICByZXEub25lcnJvciA9IGZ1bmN0aW9uKCkgew0KICAgICAgICAgIGVycm9yZnVuYygpOw0KICAgICAgICB9Ow0KICAgICAgfQ0KICAgICAgcmVxLm9wZW4oIkdFVCIsIHVybCwgdHJ1ZSk7DQogICAgICByZXEuc2VuZCgpOw0KICAgIH0NCg0KICAvL090aGVyDQogIGZ1bmN0aW9uIHNjYW5tZW0oc3RyKSB7DQogICAgdmFyIGEsIGIsIHI7DQogICAgciA9IFtdOw0KICAgIGZvciAoYSA9IDA7IGEgPCBNb2R1bGUuSEVBUDgubGVuZ3RoOyBhKyspIHsNCiAgICAgIGlmIChhICUgMTAwMDAwMDAgPT09IDApIHsNCiAgICAgICAgY29uc29sZS5sb2coIm1lbXNjYW46IiwgYSk7DQogICAgICB9DQogICAgICBmb3IgKGIgPSAwOyBiIDwgc3RyLmxlbmd0aDsgYisrKSB7DQogICAgICAgIGlmIChNb2R1bGUuSEVBUDhbYSArIGJdICE9IHN0ci5jaGFyQ29kZUF0KGIpKSB7DQogICAgICAgICAgYnJlYWs7DQogICAgICAgIH0NCiAgICAgIH0NCiAgICAgIGlmIChiID09IHN0ci5sZW5ndGgpIHsNCiAgICAgICAgci5wdXNoKGEpOw0KICAgICAgfQ0KICAgIH0NCiAgICBjb25zb2xlLmxvZyhyKTsNCiAgfQ0KDQogIGZ1bmN0aW9uIHRlc3R3aXRobWVtKHN0cikgew0KICAgIGNhbGxTdHJpbmcoc3RyKTsNCiAgICBzY2FubWVt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