class Bot {
constructor(name = "", sid = "") {
this.name = name;
this.serverId = sid || game.options.serverId;
this.server = game.options.servers[this.serverId];
this.ws = new WebSocket(wss://${this.server.hostname}:443/);
this.ws.binaryType = "arraybuffer";
this.ws.onmessage = this.onMessage.bind(this);
this.codec = new game.networkType().codec;
this.Module = wasmmodule();
}
sendPacket(event, data) {
this.ws.readyState == 1 && this.ws.send(this.codec.encode(event, data));
}
async onMessage(msg) {
const opcode = new Uint8Array(msg.data)[0];
if (opcode == 5) {
this.Module.onDecodeOpcode5(new Uint8Array(msg.data), this.server.ipAddress, e => {
this.sendPacket(4, {displayName: this.name, extra: e[5]});
this.enterworld2 = e[6];
});
return;
}
if (opcode == 10) {
this.ws.send(this.Module.finalizeOpcode10(new Uint8Array(msg.data)));
return;
}
const data = this.codec.decode(msg.data);
switch(opcode) {
case 4:
this.onEnterWorldHandler(data);
break;
}
}
onEnterWorldHandler(data) {
if (!data.allowed) return;
this.uid = data.uid;
this.enterworld2 && this.ws.send(this.enterworld2);
this.sendPacket(9, {name: "JoinPartyByShareKey", partyShareKey: game.ui.playerPartyShareKey});
for (let i = 0; i < 26; i++) this.ws.send(new Uint8Array([3, 17, 123, 34, 117, 112, 34, 58, 49, 44, 34, 100, 111, 119, 110, 34, 58, 48, 125]));
this.ws.send(new Uint8Array([7, 0]));
this.ws.send(new Uint8Array([9,6,0,0,0,126,8,0,0,108,27,0,0,146,23,0,0,82,23,0,0,8,91,11,0,8,91,11,0,0,0,0,0,32,78,0,0,76,79,0,0,172,38,0,0,120,155,0,0,166,39,0,0,140,35,0,0,36,44,0,0,213,37,0,0,100,0,0,0,120,55,0,0,0,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,134,6,0,0]));
console.log("bot in game");
}
}
Here's how the module is used, I can't afford to put it into an async IIFE