Greasy Fork is available in English.
A userscript to add custom gamemode VarTOL to bonk.io
当前为
// ==UserScript==
// @name bonk-vartol
// @version 1.0.0
// @author Blu
// @description A userscript to add custom gamemode VarTOL to bonk.io
// @match https://bonk.io/gameframe-release.html
// @run-at document-start
// @grant none
// @namespace http://greasyfork.icu/users/826975
// ==/UserScript==
// for use as a userscript ensure you have Excigma's code injector userscript
// http://greasyfork.icu/en/scripts/433861-code-injector-bonk-io
const injectorName = `VarTOL`;
const errorMsg = `Whoops! ${injectorName} was unable to load.
This may be due to an update to Bonk.io. If so, please report this error!
This could also be because you have an extension that is incompatible with \
${injectorName}`;
function injector(src){
newSrc = src;
// Add the VTOL movement code
newSrc = newSrc.replace('"v"){;}', VARTOL_GAME);
// Allow VarTOL to be selected
newSrc=newSrc.replace('[S9L.C1E(107),S9L.W1E(1130),S9L.C1E(1131),S9L.W1E(1132),', VARTOL_MODE);
newSrc=newSrc.replace('P1R[43][P1R[7][551]][S9L.C1E(116)]={lobbyName:S9L.C1E(2093),gameStartName:S9L.C1E(2094),lobbyDescription:S9L.W1E(2095),tutorialTitle:S9L.W1E(2096),tutorialText:S9L.W1E(2097),forceTeams:true,forceTeamCount:2,editorCanTarget:false};', MODE_METADATA);
// register outline, bow, and jetpack graphics
newSrc = newSrc.replace('this[S5p[4][149]][S5p[4][118]] == S9L.C1E(1131)', 'this[S5p[4][149]][S5p[4][118]] == S9L.C1E(1131) || this[S5p[4][149]][S5p[4][118]] == "var"');
newSrc = newSrc.replace('this[S5p[4][149]][S5p[4][118]] == S9L.W1E(1131)', 'this[S5p[4][149]][S5p[4][118]] == S9L.W1E(1131) || this[S5p[4][149]][S5p[4][118]] == "var"');
newSrc = newSrc.replace('build(D2i,h2i) {',RENDER_JETPACK);
// Attempt to add var in same places as ar
// recover cooldown a1a +8 to 1000
newSrc = newSrc.replace(`&& (O7R[0][4][O7R[8][118]] == "ar" ||`,`&& (O7R[0][4][O7R[8][118]] == "ar" || O7R[0][4][O7R[8][118]] == "var" ||`);
// arrow direction and charge
newSrc = newSrc.replace(`if(O7R[0][4][O7R[8][118]] == "ar" ||`, `if(O7R[0][4][O7R[8][118]] == "ar" || O7R[0][4][O7R[8][118]] == "var" ||`);
// doArrows
newSrc = newSrc.replace(`this[t1C[149]][t1C[118]] == "ar"`, `this[t1C[149]][t1C[118]] == "ar" || this[t1C[149]][t1C[118]] == "var"`);
// movement (DONT NEED: movement already taken care of in VARTOL_GAME)
// newSrc = newSrc.replace('&& O7R[5][O7R[956]][O7R[8][189]] == 0){', '&& O7R[5][O7R[956]][O7R[8][189]] == 0 || O7R[0][4][O7R[8][118]] == "var" && O7R[5][O7R[956]][O7R[8][189]] == 0){');
// Attempt to add var in same places as v
// body rotation true
newSrc = newSrc.replace(`if(O7R[0][4][O7R[8][118]] == "v"){O7R[10][O7R[8][198]]=false;`, `if(O7R[0][4][O7R[8][118]] == "v" || O7R[0][4][O7R[8][118]] == "var"){O7R[10][O7R[8][198]]=false;`);
// vtolwing physics
newSrc = newSrc.replace(`){O7R[48]=new P1R[22]();`, `|| O7R[0][4][O7R[8][118]] == "var"){O7R[48]=new P1R[22]();`);
// ??? draw rects but not called :/
newSrc = newSrc.replace(`if(B1V[0][3][B1V[3][118]] == S9L.C1E(62)){B`, `if(B1V[0][3][B1V[3][118]] == S9L.C1E(62) || B1V[0][3][B1V[3][118]] == "var"){debugger; B`);
// ??? idek
newSrc = newSrc.replace(`B1V[0][3][B1V[3][118]] == S9L.C1E(62)){f`, `B1V[0][3][B1V[3][118]] == S9L.C1E(62) || B1V[0][3][B1V[3][118]] == "var"){f`);
// Account for body rotation when firing
newSrc = newSrc.replace(`O7R[5][O7R[956]][O7R[8][190]] *`, ARROW_COMPENSATION);
if(src === newSrc) throw "Injection failed!";
console.log(injectorName+" injector run");
return newSrc;
}
// Adds VarTOL to mode selection button
const VARTOL_MODE= `[S9L.C1E(107),S9L.W1E(1130),S9L.C1E(1131),S9L.W1E(1132),"var",`;
// Adds VarTOL to bonk mode directory
const MODE_METADATA= `P1R[43][P1R[7][551]][S9L.C1E(116)]={lobbyName:S9L.C1E(2093),gameStartName:S9L.C1E(2094),lobbyDescription:S9L.W1E(2095),tutorialTitle:S9L.W1E(2096),tutorialText:S9L.W1E(2097),forceTeams:true,forceTeamCount:2,editorCanTarget:false}; P1R[43][P1R[7][551]]["var"] = {lobbyName:"VarTOL",gameStartName:"VARTOL",lobbyDescription:"VTOL and Arrows had a baby. And this baby knows how to rock.",tutorialTitle:"VarTOL Mode",tutorialText:"•Fly around with the arrow keys\\r\\n•Hold Z to draw an arrow\\r\\n•Hold X to make yourself heavier",forceTeams:false,forceTeamCount:null,editorCanTarget:false};`;
// Renders jetpack
const RENDER_JETPACK=`
build(D2i,h2i) {
var S5p=[arguments];
S5p[4]=y3uu;
if(this["gameSettings"]["mo"]=="var") {
this["VTOLWing"]=new PIXI["Graphics"]();
this["VTOLWing"]["beginFill"](0xff3030);
this["VTOLWing"]["drawRect"](
this["radius"]*(-V["footHW"]+V["footOffsetX"]),
this["radius"]*(-V["footHH"]+V["footOffsetY"]),
this["radius"]*(V["footHW"]*6),
this["radius"]*(V["footHH"]*2)
);
this["container"]["addChild"](this["VTOLWing"]);
}`;
const VARTOL_GAME = `"v"){;} if (O7R[0][4][O7R[8][118]] == "var"){
var O1B=[];
O1B[11]=(-22/30)*O7R[445];
O1B[791]=0.12;
O1B[874]=new P1R[2](0,O1B[11]);
O1B[874]=O7R[5][O7R[956]]["body"]["GetWorldVector"](O1B[874],O1B[874]);
O1B[857]=new P1R[2](0,O1B[11]*O1B[791]);
O1B[857]=O7R[5][O7R[956]]["body"]["GetWorldVector"](
O1B[857],
O1B[857]
);
O1B[347]=O7R[5][O7R[956]]["body"]["GetWorldPoint"](new P1R[2](
V["footOffsetX"]*O7R[445],
V["footOffsetY"]*O7R[445]
));
O1B[848]=O7R[5][O7R[956]]["body"]["GetWorldPoint"](new P1R[2](
-V["footOffsetX"]*O7R[445],
V["footOffsetY"]*O7R[445]
));
O1B[195]="none";
if(O7R[0][1][O7R[956]]["up"]) {
if(O7R[0][1][O7R[956]]["left"] && O7R[5][O7R[956]][O7R[8][189]] == 0) {
O1B[195]="right";
}
else if(O7R[0][1][O7R[956]]["right"] && O7R[5][O7R[956]][O7R[8][189]] == 0) {
O1B[195]="left";
}
else {
O1B[195]="both";
}
}
else if(O7R[0][1][O7R[956]]["left"] && O7R[0][1][O7R[956]]["right"] && O7R[5][O7R[956]][O7R[8][189]] == 0) {
O1B[195]="both";
}
else if(O7R[0][1][O7R[956]]["left"] && O7R[5][O7R[956]][O7R[8][189]] == 0) {
O1B[195]="right";
}
else if(O7R[0][1][O7R[956]]["right"] && O7R[5][O7R[956]][O7R[8][189]] == 0) {
O1B[195]="left";
}
if(O1B[195]=="both") {
O7R[5][O7R[956]]["body"]["ApplyImpulse"](O1B[874],O1B[347]);
O7R[5][O7R[956]]["body"]["ApplyImpulse"](O1B[874],O1B[848]);
}
if(O1B[195]=="left") {
O7R[5][O7R[956]]["body"]["ApplyImpulse"](O1B[874],O1B[347]);
O7R[5][O7R[956]]["body"]["ApplyImpulse"](O1B[857],O1B[848]);
}
if(O1B[195]=="right") {
O7R[5][O7R[956]]["body"]["ApplyImpulse"](O1B[857],O1B[347]);
O7R[5][O7R[956]]["body"]["ApplyImpulse"](O1B[874],O1B[848]);
}
}`;
// Calculate player angle from rotation matrix and add to the arrow's angle
const ARROW_COMPENSATION = `(O7R[5][O7R[956]][O7R[8][190]] + (-Math.round(Math.atan2(O7R[5][O7R[956]]["body"]["m_xf"]["R"].col2.x, O7R[5][O7R[956]]["body"]["m_xf"]["R"].col1.x) * (180/Math.PI)))) *`;
// Compatibility with Excigma's code injector userscript
if(!window.bonkCodeInjectors) window.bonkCodeInjectors = [];
// only using unshift() to ensure first priority as Salama's VTOL implementation breaks my hacky regex.
// If you are intending to create your own code injection please use push() instead if possible
window.bonkCodeInjectors.unshift(bonkCode => {
try {
return injector(bonkCode);
} catch (error) {
alert(errorMsg);
throw error;
}
});
console.log(injectorName+" injector loaded");