forked from shipguy55/agarmods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mods.js
71 lines (64 loc) · 2.62 KB
/
mods.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function main() {
// inject into agariomods
httpGet("http://agariomods.com/mods.js", function(data) {
var inject = function() {
var orig_agariomodsRuntimePatches = agariomodsRuntimePatches;
agariomodsRuntimePatches = function() {
// let agariomods do the initial patching
orig_agariomodsRuntimePatches();
// add our own patches
gamejs = patchScript(gamejs);
};
};
// get the function body
data += inject.toString()
.replace(/function \(\) {([^]+)}/, "$1");
eval(data);
});
}
// XMLHttp, because apparently raven is doing funky stuff with jQuery
function httpGet(url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
callback(xmlHttp.responseText);
}
};
}
function patchScript(gamejs) {
//bypass obfuscation
var ownedCells = /\w+?=-1!=(\w+?)\.indexOf\(this\);/.exec(gamejs)[1];
var isVirus = /this\.(\w+?)\?"miter":"round"/.exec(gamejs)[1];
var haxx = function() {
var mass = ~~(this.size * this.size / 100);
var mysize = $ownedCells.reduce(function(previous, current) {
return previous > current.size ? previous : current.size;
}, 0);
mysize = ~~(mysize * mysize / 100);
if (this.$isVirus) {
this.color = "#666666"; // Viruses are always gray, and everything is gray when dead
} else if (~$ownedCells.indexOf(this)) {
this.color = "#0000FF"; // Cells we own are blue
} else if (mass > mysize * 2.5) {
this.color = "#FF0000"; // Cells that can split on us are red
} else if (mass > mysize * 1.25) {
this.color = "#FF6600"; // Cells that can eat us are orange
} else if (mass > mysize * 0.75) {
this.color = "#FFFF00"; // Cells that we can't, and they can't eat us are yellow
} else if (mass > mysize * 0.4) {
this.color = "#007700"; // Cells that we can eat are dark green
} else {
this.color = "#00FF00"; // Cells that we can split on are ligth green
}
};
haxx = haxx.toString()
.replace(/function \(\) {([^]+)}/, "$1") // get the function body
.replace(/\$ownedCells/g, ownedCells) // fix pseudo-variables
.replace(/\$isVirus/g, isVirus);
gamejs = gamejs.replace(/(if\(this\.\w+?\(\)\)\{)/, "$1" + haxx + "");
//console.log(gamejs);
return gamejs;
}
main();