Last active
May 13, 2023 09:12
-
-
Save raidan00/065f70d6f2f58ad6f9ac7dcd3699a62b to your computer and use it in GitHub Desktop.
(obsolete) StarBreak-Multi-Acc.user.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name StarBreak: Multi Acc | |
// @version 1.1 | |
// @description StarBreak: Multi Acc | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_addValueChangeListener | |
// @match https://*.starbreak.com/* | |
// ==/UserScript== | |
let goToLeadKeyCode = 88; | |
let un = getAccountUsername(); | |
let accsData = getAccsData(); | |
let activeBots = GM_getValue("activeBots") ?? {}; | |
let botsLead = GM_getValue("botsLead") ?? {}; | |
if(!botsLead.main)botsLead.main = un; | |
GM_setValue("botsLead", botsLead); | |
activeBots[un] = true; | |
GM_setValue("activeBots", activeBots); | |
for (const key in accsData) { | |
if(!activeBots[key]){ | |
let button = document.createElement("button"); | |
button.id = "newBotButton"; | |
button.textContent = "New Bot Tab"; | |
button.addEventListener('click', function (e) { | |
e.preventDefault(); | |
localStorage.setItem('LocalStorage.pb', accsData[key]); | |
document.body.removeChild(button); | |
window.open("https://www.starbreak.com/", '_blank', "location=yes, height=100, width=300, top=500, left=500"); | |
}); | |
document.body.appendChild(button); | |
break; | |
} | |
} | |
function sendKey(type, keyCode) { | |
if(typeof XDL == 'undefined')return; | |
let preventDefault = function dummyPreventDefault() {}; | |
let ev = { type, keyCode, preventDefault }; | |
XDL.onKey(ev); | |
} | |
GM_addValueChangeListener("keyPressArr-"+un, function(key, oldValue, newValue, remote) { | |
sendKey(newValue.type, newValue.keyCode); | |
}); | |
GM_addValueChangeListener("makeBotsCentred", function(key, oldValue, newValue, remote) { | |
if(botsLead.main == un) return; | |
let lastKeyCode = 0; | |
let interval = setInterval(()=>{ | |
let distance = leadPos.x - center.x; | |
if(Math.abs(distance) < 7){ | |
clearInterval(interval) | |
sendKey("keyup", 37); | |
sendKey("keyup", 39); | |
return; | |
} | |
if(distance > 0){ | |
var keyCode = 39; | |
}else{ | |
keyCode = 37; | |
}; | |
if(lastKeyCode != keyCode){ | |
sendKey("keyup", lastKeyCode); | |
lastKeyCode = keyCode; | |
sendKey("keydown", keyCode); | |
} | |
}, 0) | |
}); | |
function listener(e){ | |
if (XDL.textInputActive && e.keyCode != 13) return; | |
if(e.keyCode == goToLeadKeyCode && e.type == "keydown"){ | |
GM_setValue("makeBotsCentred", Math.random()); | |
} | |
if(botsLead.main != un) return; | |
if(e.keyCode == 16 || e.keyCode == 82 || e.keyCode == 9 || e.keyCode == 19 || e.keyCode == 65 || e.keyCode == 83) return; | |
e.stopImmediatePropagation(); | |
for (const key in accsData) { | |
GM_setValue("keyPressArr-"+key, {type:e.type, keyCode:e.keyCode}); | |
} | |
} | |
document.addEventListener('keydown', listener, true); | |
document.addEventListener('keyup', listener, true); | |
let textEventsOnceName = new Map(); | |
let textEventsOnceId = new Map(); | |
let tids = new Map(); | |
let center = {}; | |
let leadTid = 0; | |
let leadPos = {}; | |
let rope = {}; | |
for (const key in accsData) { | |
rope[key] = {tid: 0, lastSeen: 0}; | |
} | |
function onLoaded(){ | |
(function (orig) { | |
RenderEngineWebGL._Z21XDL_CreateTextTextureiPKcijS0_ij = function (textureId, fontName, size, color, text, outlineSize, outlineColor) { | |
var textStr = Pointer_stringify(text); | |
var font = size + 'px ' + Pointer_stringify(fontName); | |
var csscolor = TextUtils.loadColorToCSSRGBA(color); | |
let key = textStr+"##"+font+"##"+csscolor; | |
var tid = orig.apply(null, arguments); | |
let reg = new RegExp(`^\\[\\d{1,2}\\] ${ botsLead.main }`); | |
if(font == "14px TenbyFive" && csscolor == "rgba(255,255,255,1)" && textStr.match(reg)){ | |
leadTid = tid; | |
} | |
if(botsLead.main == un && font == "14px TenbyFive" && csscolor == "rgba(255,255,255,1)") { | |
for (const key in rope) { | |
let reg = new RegExp(`^\\[\\d{1,2}\\] ${ key }`); | |
if(textStr.match(reg)){ | |
rope[key].tid = tid | |
} | |
} | |
} | |
if(textEventsOnceName.has(key)){ | |
textEventsOnceId.set(tid, textEventsOnceName.get(key) ) | |
textEventsOnceName.delete(key) | |
} | |
return tid; | |
}; | |
})(RenderEngineWebGL._Z21XDL_CreateTextTextureiPKcijS0_ij); | |
(function (orig) { | |
RenderEngineWebGL.addTexture = function (drawable) { | |
let tid = orig.apply(null, arguments); | |
let name = drawable.src.match(/\w+\.\d/)[0]; | |
tids.set(tid, name); | |
return tid; | |
}; | |
})(RenderEngineWebGL.addTexture); | |
(function (orig) { | |
RenderEngineWebGL._Z15XDL_DrawTextureiiiiiiiiiiiiij9BlendMode = function(texture, sx, sy, sw, sh, dx, dy, dw, dh, rot, rpx, rpy, flip, cm, blendMode) { | |
if(textEventsOnceId.has(texture)){ | |
let fn = textEventsOnceId.get(texture); | |
fn(); | |
textEventsOnceId.delete(texture); | |
} | |
let textureName = tids.get(texture); | |
if(textureName == "base.1" && sx == 1271 && sy == 1182){ | |
center.x = dx + dw/2; | |
center.y = dy + dh/2; | |
if(botsLead.main == un) { | |
canvas.setAttribute("width", Module.canvas.widthNative); | |
canvas.setAttribute("height", Module.canvas.heightNative); | |
let add = 0; | |
for (const key in rope) { | |
if(rope[key].lastSeen + 200 < Date.now() && key != botsLead.main){ | |
ctx.font = "60px serif"; | |
ctx.fillStyle = "#e3e3e3"; | |
ctx.fillText(key, 300+add, 60); | |
ctx.fill(); | |
add+=key.length*37; | |
} | |
} | |
} | |
} | |
for (const key in rope) { | |
if(rope[key].tid == texture){ | |
rope[key].lastSeen = Date.now(); | |
ctx.lineWidth = 3; | |
ctx.strokeStyle = "#e3e3e3"; | |
ctx.beginPath(); | |
ctx.moveTo(center.x, center.y); | |
ctx.lineTo(dx + dw/2, dy + dh/2 - 70); | |
ctx.stroke(); | |
} | |
} | |
if(texture == leadTid){ | |
leadPos.x = dx + dw/2; | |
leadPos.y = dy + dh/2; | |
} | |
if(document.hidden) return; | |
return orig.apply(null, arguments); | |
}; | |
})(RenderEngineWebGL._Z15XDL_DrawTextureiiiiiiiiiiiiij9BlendMode); | |
textEventsOnceName.set("PLAY##32px HemiHeadBold##rgba(255,255,255,1)", () => { | |
sendKey("keydown", 13); | |
sendKey("keyup", 13); | |
document.title = un; | |
}) | |
} | |
function waitUntilLoaded () { | |
if (typeof RenderEngineWebGL == 'undefined' || typeof XDL == 'undefined' || typeof Module === 'undefined') { | |
setTimeout(waitUntilLoaded, 100); | |
return; | |
} | |
onLoaded(); | |
} | |
waitUntilLoaded(); | |
function startBots(){ | |
GM_setValue("activeBots", {}); | |
GM_setValue("botsLead", {}); | |
for (const key in accsData) { | |
GM_setValue("keyPressArr-"+key, null); | |
} | |
document.location.reload(); | |
} | |
function getAccsData() { | |
return GM_getValue("accsData") ?? {}; | |
} | |
function setAccsData(d) { | |
GM_setValue("accsData", d); | |
} | |
function readString(b, fieldname) { | |
let i = b.indexOf(fieldname); | |
if (i === -1) return null; | |
return b.substr(i+fieldname.length+2, b.charCodeAt(i+fieldname.length+1)); | |
} | |
function getAccountUsername() { | |
let b = atob(localStorage.getItem('LocalStorage.pb')); | |
let n = readString(b, '\x08username'); | |
return n; | |
} | |
function addAccount() { | |
var d = getAccsData(); | |
let un = getAccountUsername(); | |
if (un === null) { | |
alert('you need register'); | |
return; | |
} | |
d[un] = localStorage.getItem('LocalStorage.pb'); | |
setAccsData(d); | |
document.location.reload(); | |
} | |
function removeAccount(an) { | |
var d = getAccsData(); | |
delete d[an]; | |
setAccsData(d); | |
} | |
let div; | |
function addControlButton(name, fn) { | |
let el = document.createElement('a'); | |
el.textContent = name; | |
el.setAttribute('href', '#'); | |
el.setAttribute('style', 'display: block; margin: 3px'); | |
el.addEventListener('click', function (e) { | |
e.preventDefault(); | |
fn(); | |
}); | |
div.appendChild(el); | |
} | |
function showBotControl(){ | |
div = document.createElement("div"); | |
div.id = "botControl"; | |
document.body.appendChild(div); | |
for (let an of Object.keys(accsData)) { | |
let innerDiv = document.createElement("div"); | |
div.appendChild(innerDiv); | |
let acc = document.createElement('a'); | |
acc.textContent = an; | |
acc.setAttribute('href', '#'); | |
acc.setAttribute('class', 'an'); | |
if(an == un) acc.setAttribute('style', 'color: green'); | |
acc.addEventListener('click', function (e) { | |
e.preventDefault(); | |
localStorage.setItem('LocalStorage.pb', accsData[an]); | |
document.location.reload(); | |
}); | |
innerDiv.appendChild(acc); | |
let remove = document.createElement('a'); | |
remove.textContent = "X"; | |
remove.setAttribute('href', '#'); | |
remove.setAttribute('class', 'remove'); | |
remove.addEventListener('click', function (e) { | |
e.preventDefault(); | |
removeAccount(an); | |
document.location.reload(); | |
}); | |
innerDiv.appendChild(remove); | |
} | |
addControlButton('Add/Update Account', addAccount); | |
addControlButton('Start Bots', startBots); | |
} | |
showBotControl(); | |
let canvas = document.createElement("canvas"); | |
canvas.id = "botDirections"; | |
const ctx = canvas.getContext("2d"); | |
document.body.appendChild(canvas); | |
const innerStyle = ` | |
#botControl { | |
position: fixed; | |
background-color: rgba(16, 16, 16, 0.9); | |
top: 200px; | |
left: -190px; | |
color: #f0f0f0; | |
font-size: 12pt; | |
font-family: Consolas, monospace; | |
padding: 10px; | |
text-align: center; | |
border-radius: 5px; | |
padding-right: 23px; | |
border: 1px solid #a5a5a5; | |
transition-duration: 0.35s; | |
} | |
#botControl:hover{ | |
left: 0px; | |
} | |
#botControl a:link { | |
color: #e0e0e0; | |
} | |
#botControl a:visited { | |
color: #e0e0e0; | |
} | |
#botControl a:hover { | |
color: #f0f0f0; | |
} | |
#botControl a:active { | |
color: #e8e8e8; | |
} | |
.remove { | |
color: red !important; | |
margin-left: 10px; | |
} | |
#newBotButton { | |
position: fixed; | |
left: 40px; | |
top: 30px; | |
font-size: 140px; | |
} | |
#botDirections { | |
position: absolute; | |
left: 0px; | |
top: 0px; | |
pointer-events: none; | |
width: 100vw; | |
height: 100vh; | |
} | |
` | |
let css = document.createElement('style'); | |
css.innerHTML = innerStyle; | |
document.head.appendChild(css); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment