Last active 1697523181

My bitburner scripts. adapted from alain mostly

Revision 33c94ae122c92d3b993f26a043cbec51caa94460

_firstboot.js Raw
1/** @param {NS} ns */
2// script to be run after each augment to recover hack level and money
3// 1. run scan.js, backdoor n00dles and foodnstuff
4// 2. run this script, starts hacking those servers
5// 3. once you have 200k, go to aevum, then run alain/casino.js
6// 3a. go to tech store, buy darkweb, connect darkweb, buy -a
7// 4. run scan.js, update targets.js with any extra servers you can backdoor, make sure you do backdoor them with the links in scan's output
8// 5. run purchase.js, update with higher ram allowance (32>2048) if you have enough money
9// * run delete-pserv.js if there's an issue with buying the servers
10// 6. run init.js, this will boot up stockmaster and stats, as well as starting the hack scripts running across all pservs and home
11export async function main(ns) {
12 const scripts = [
13 {name: "/alain/stats.js", args:[]},
14// {name: "/alain/stockmaster.js", args:[]},
15// {name: "/pserv.js", args:[]},
16 {name: "/local.js", args:[]},
17 ];
18 for(const {name,args,waitFor=false} of scripts) {
19 const pid = ns.run(name,1,...args);
20 if(pid) {
21 ns.tprint(`Started ${name} with [${args}]`);
22 if(waitFor) {
23 ns.tprint("Waiting for it to exit...");
24 await awaitByPid(ns,pid);
25 }
26 }
27 else
28 ns.tprint(`ERROR: Failed to start ${name} with ${args}!`);
29 await ns.sleep(100);
30 }
31}
_init.js Raw
1/** @param {NS} ns */
2export async function main(ns) {
3 const scripts = [
4 {name: "/alain/stats.js", args:[]},
5 {name: "/alain/stockmaster.js", args:[]},
6 {name: "/pserv.js", args:[]},
7 {name: "/local.js", args:[]},
8 ];
9 for(const {name,args,waitFor=false} of scripts) {
10 const pid = ns.run(name,1,...args);
11 if(pid) {
12 ns.tprint(`Started ${name} with [${args}]`);
13 if(waitFor) {
14 ns.tprint("Waiting for it to exit...");
15 await awaitByPid(ns,pid);
16 }
17 }
18 else
19 ns.tprint(`ERROR: Failed to start ${name} with ${args}!`);
20 await ns.sleep(100);
21 }
22}
_shutdown.js Raw
1/** @param {NS} ns */
2export async function main(ns) {
3 const scripts = [
4 {name: "/alain/stockmaster.js", args:["-l"]},
5 {name: "/alain/kill-all-scripts.js", args:[]},
6 ];
7 for(const {name,args,waitFor=false} of scripts) {
8 const pid = ns.run(name,1,...args);
9 if(pid) {
10 ns.tprint(`Started ${name} with [${args}]`);
11 if(waitFor) {
12 ns.tprint("Waiting for it to exit...");
13 await awaitByPid(ns,pid);
14 }
15 }
16 else
17 ns.tprint(`ERROR: Failed to start ${name} with ${args}!`);
18 await ns.sleep(100);
19 }
20}
delete-pserv.js Raw
1export async function main(ns) {
2 // Iterator we'll use for our loop
3 let i = 0;
4
5 while (i < ns.getPurchasedServerLimit()) {
6 let hostname = "pserv-" + i;
7 ns.deleteServer(hostname)
8 ++i;
9 await ns.sleep(100);
10 }
11}
early-hack-template.js Raw
1import { targets } from "/targets.js";
2
3export async function main(ns) {
4 const args = ns.flags([['help', false]]);
5 let hostname = args._[0];
6 if(!hostname) {
7 hostname = targets[Math.floor(Math.random()*targets.length)];
8 }
9 while (true) {
10 if (ns.getServerSecurityLevel(hostname) > (ns.getServerMinSecurityLevel(hostname)+1)) {
11 await ns.weaken(hostname);
12 } else if (ns.getServerMoneyAvailable(hostname) < (ns.getServerMaxMoney(hostname)*0.75)) {
13 await ns.grow(hostname);
14 } else {
15 await ns.hack(hostname);
16 }
17 }
18}
local.js Raw
1export async function main(ns) {
2 var i = 0;
3 var ram = ns.getScriptRam("early-hack-template.js")*100,
4 total_ram = ns.getServerMaxRam("home")-1024,
5 used_ram = ns.getServerUsedRam("home")
6
7 ns.tail();
8
9 while (i < ((total_ram-used_ram)/ram)) {
10 ns.run("early-hack-template.js", 100);
11 ++i;
12 await ns.sleep(100);
13 }
14}
pserv.js Raw
1import { targets } from "/targets.js";
2
3export async function main(ns) {
4 // Iterator we'll use for our loop
5 let i = 0;
6 ns.tail();
7
8 while (i < ns.getPurchasedServerLimit()) {
9 let hostname = "pserv-" + i;
10// ns.deleteServer(hostname)
11// ns.purchaseServer(hostname, 1024)
12 ns.scp("targets.js", hostname);
13 ns.scp("early-hack-template.js", hostname);
14 for (var z = 0; z < Math.floor(ns.getServerMaxRam(hostname)/2.4/10); z++)
15 ns.exec("early-hack-template.js", hostname, 10, targets[z % targets.length]);
16 ++i;
17 await ns.sleep(100);
18 }
19}
purchase.js Raw
1export async function main(ns) {
2 // Iterator we'll use for our loop
3 let i = 0;
4 ns.tail();
5
6 while (i < ns.getPurchasedServerLimit()) {
7 let hostname = "pserv-" + i;
8 ns.purchaseServer(hostname, 32) // update this by powers of 2 as you get more money. i usually have it at 2048
9 ++i;
10 await ns.sleep(100);
11 }
12}
scan.js Raw
1/**
2 * @param {NS} ns
3 * @returns interactive server map
4 */
5export function main(ns) {
6 const factionServers = ["CSEC", "avmnite-02h", "I.I.I.I", "run4theh111z", "w0r1d_d43m0n", "fulcrumassets"],
7 css = ` <style id="scanCSS">
8 .serverscan {white-space:pre; color:#ccc; font:14px monospace; line-height: 16px; }
9 .serverscan .server {color:#080;cursor:pointer;text-decoration:underline}
10 .serverscan .faction {color:#088}
11 .serverscan .rooted {color:#6f3}
12 .serverscan .rooted.faction {color:#0ff}
13 .serverscan .rooted::before {color:#6f3}
14 .serverscan .hack {display:inline-block; font:12px monospace}
15 .serverscan .red {color:red;}
16 .serverscan .green {color:green;}
17 .serverscan .backdoor {color:#6f3}
18 .serverscan .linky {font:12px monospace}
19 .serverscan .linky > a {cursor:pointer; text-decoration:underline;}
20 .serverscan .cct {color:#0ff;}
21 </style>`,
22 doc = eval("document"),
23 terminalInsert = html => doc.getElementById("terminal").insertAdjacentHTML('beforeend', `<li>${html}</li>`),
24 terminalInput = doc.getElementById("terminal-input"),
25 terminalEventHandlerKey = Object.keys(terminalInput)[1],
26 setNavCommand = async inputValue => {
27 terminalInput.value = inputValue
28 terminalInput[terminalEventHandlerKey].onChange({ target: terminalInput })
29 terminalInput.focus()
30 await terminalInput[terminalEventHandlerKey].onKeyDown({ key: 'Enter', preventDefault: () => 0 })
31 },
32 myHackLevel = ns.getHackingLevel(),
33 serverInfo = (serverName) => {
34 // Costs 2 GB. If you can't don't need backdoor links, uncomment and use the alternate implementations below
35 return ns.getServer(serverName)
36 /* return {
37 requiredHackingSkill: ns.getServerRequiredHackingLevel(serverName),
38 hasAdminRights: ns.hasRootAccess(serverName),
39 purchasedByPlayer: serverName.includes('daemon') || serverName.includes('hacknet'),
40 backdoorInstalled: true // No way of knowing without ns.getServer
41 } */
42 },
43 createServerEntry = serverName => {
44 let server = serverInfo(serverName),
45 requiredHackLevel = server.requiredHackingSkill,
46 rooted = server.hasAdminRights,
47 canHack = requiredHackLevel <= myHackLevel,
48 shouldBackdoor = !server?.backdoorInstalled && canHack && serverName != 'home' && rooted && !server.purchasedByPlayer,
49 contracts = ns.ls(serverName, ".cct")
50
51 return `<span id="${serverName}">`
52 + `<a class="server${factionServers.includes(serverName) ? " faction" : ""}`
53 + `${rooted ? " rooted" : ""}">${serverName}</a>`
54 + (server.purchasedByPlayer ? '' : ` <span class="hack ${(canHack ? 'green' : 'red')} monitor linky">(<a>${requiredHackLevel}</a>)</span>`)
55 + `${((canHack && !rooted) || shouldBackdoor ? ' <span class="backdoor linky">[<a>backdoor</a>]</span>' : '')}`
56 + ` ${contracts.map(c => `<span class="cct" title="${c}">@</span>`)}`
57 + "</span>"
58 },
59 buildOutput = (parent = servers[0], prefix = ["\n"]) => {
60 let output = prefix.join("") + createServerEntry(parent)
61 for (let i = 0; i < servers.length; i++) {
62 if (parentByIndex[i] != parent) continue
63 let newPrefix = prefix.slice()
64 const appearsAgain = parentByIndex.slice(i + 1).includes(parentByIndex[i]),
65 lastElementIndex = newPrefix.length - 1
66
67 newPrefix.push(appearsAgain ? "├╴" : "└╴")
68
69 newPrefix[lastElementIndex] = newPrefix[lastElementIndex].replace("├╴", "│ ").replace("└╴", " ")
70 output += buildOutput(servers[i], newPrefix)
71 }
72
73 return output
74 },
75 ordering = (serverA, serverB) => {
76 // Sort servers with fewer connections towards the top.
77 let orderNumber = ns.scan(serverA).length - ns.scan(serverB).length
78 // Purchased servers to the very top
79 orderNumber = orderNumber != 0 ? orderNumber
80 : serverInfo(serverB).purchasedByPlayer - serverInfo(serverA).purchasedByPlayer
81 // Hack: compare just the first 2 chars to keep purchased servers in order purchased
82 orderNumber = orderNumber != 0 ? orderNumber
83 : serverA.slice(0, 2).toLowerCase().localeCompare(serverB.slice(0, 2).toLowerCase())
84
85 return orderNumber
86 }
87
88 // refresh css (in case it changed)
89 doc.getElementById("scanCSS")?.remove()
90 doc.head.insertAdjacentHTML('beforeend', css)
91 let servers = ["home"],
92 parentByIndex = [""],
93 routes = { home: "home" }
94 for (let server of servers)
95 for (let oneScanResult of ns.scan(server).sort(ordering))
96 if (!servers.includes(oneScanResult)) {
97 const backdoored = serverInfo(oneScanResult)?.backdoorInstalled
98 servers.push(oneScanResult)
99 parentByIndex.push(server)
100 routes[oneScanResult] = backdoored ? "connect " + oneScanResult : routes[server] + ";connect " + oneScanResult
101 }
102
103 terminalInsert(`<div class="serverscan new">${buildOutput()}</div>`)
104 doc.querySelectorAll(".serverscan.new .server").forEach(serverEntry => serverEntry
105 .addEventListener('click', setNavCommand.bind(null, routes[serverEntry.childNodes[0].nodeValue])))
106 doc.querySelectorAll(".serverscan.new .monitor").forEach(monitorButton => monitorButton
107 .addEventListener('click', setNavCommand.bind(null, "run monitor.js " + monitorButton.parentNode.childNodes[0].childNodes[0].nodeValue)))
108 doc.querySelectorAll(".serverscan.new .backdoor").forEach(backdoorButton => backdoorButton
109 .addEventListener('click', setNavCommand.bind(null, routes[backdoorButton.parentNode.childNodes[0].childNodes[0].nodeValue] + ";run brutessh.exe;run httpworm.exe;run sqlinject.exe;run ftpcrack.exe;run relaysmtp.exe;run nuke.exe;backdoor")))
110 doc.querySelector(".serverscan.new").classList.remove("new")
111}
112
targets.js Raw
1/** @param {NS} ns */
2export var targets = [
3 "foodnstuff",
4// "iron-gym",
5// "joesguns",
6// "sigma-cosmetics",
7// "hong-fang-tea",
8// "nectar-net",
9// "silver-helix",
10// "computek",
11// "neo-net",
12// "the-hub",
13// "netlink",
14// "summit-uni",
15// "rothman-uni",
16// "rho-construction",
17// "johnson-ortho",
18// "catalyst",
19// "aevum-police",
20// "millenium-fitness",
21 "n00dles",
22// "phantasy",
23// "harakiri-sushi",
24// "zer0",
25// "max-hardware",
26// "omega-net",
27// "crush-fitness",
28// ".",
29// "alpha-ent",
30];