summaryrefslogtreecommitdiff
path: root/start
diff options
context:
space:
mode:
Diffstat (limited to 'start')
-rw-r--r--start/augbaseprice.txt1
-rw-r--r--start/augments.js130
-rw-r--r--start/buyservers.js134
-rw-r--r--start/hacker.js255
-rw-r--r--start/hacknet2.js182
-rw-r--r--start/home.js35
-rw-r--r--start/milestones.js133
-rw-r--r--start/root.js358
-rw-r--r--start/tempgrow.js34
-rw-r--r--start/temphack.js25
10 files changed, 1287 insertions, 0 deletions
diff --git a/start/augbaseprice.txt b/start/augbaseprice.txt
new file mode 100644
index 0000000..cbe955a
--- /dev/null
+++ b/start/augbaseprice.txt
@@ -0,0 +1 @@
+419229000000 \ No newline at end of file
diff --git a/start/augments.js b/start/augments.js
new file mode 100644
index 0000000..c6a7f60
--- /dev/null
+++ b/start/augments.js
@@ -0,0 +1,130 @@
+/** @param {NS} ns */
+export async function main(ns) {
+
+ ns.tail();
+ ns.moveTail(950, 300);
+ ns.resizeTail(250, 100);
+
+ // ns.disableLog("disableLog");
+ // ns.disableLog("clearLog");
+ ns.disableLog("sleep");
+ // ns.disableLog("singularity.getAugmentationRepReq");
+ // ns.disableLog("singularity.getAugmentationPrice");
+ ns.disableLog("singularity.donateToFaction");
+ ns.disableLog("getServerMoneyAvailable");
+ ns.clearLog();
+
+ // Buffer time after game startup so it will read properly
+ await ns.sleep(6000);
+
+ // INITIALIZE
+ let owned = ns.singularity.getOwnedAugmentations(true); // Get the currently owned augments
+ const baseprice = ns.read("augbaseprice.txt"); // Get the base price from the start of the installation
+ let n; // No clue
+
+ while (true) {
+ let factions = ns.getPlayer().factions;
+ for (let i = 0; i < factions.length; i++) {
+ if (factions[i] == "Shadows of Anarchy") { continue; }
+
+ let augs = ns.singularity.getAugmentationsFromFaction(factions[i]);
+
+ for (let j = 0; j < augs.length; j++) {
+ if (augs[j] == "NeuroFlux Governor" || owned.includes(augs[j])) { continue; }
+ if (augs[j] == "The Red Pill") {
+ if (ns.singularity.getFactionFavor(factions[i]) < 150) {
+ if ((ns.singularity.getFactionFavorGain(factions[i]) + ns.singularity.getFactionFavor(factions[i])) > 150) {
+ ns.singularity.installAugmentations("start.js");
+ }
+ } else if (ns.singularity.getFactionRep(factions[i]) >= ns.singularity.getAugmentationRepReq(augs[j])) {
+ ns.singularity.purchaseAugmentation(factions[i], augs[j]);
+ await ns.sleep(500);
+ ns.singularity.installAugmentations("start.js");
+ } else if (ns.singularity.getFactionRep(factions[i]) < ns.singularity.getAugmentationRepReq(augs[j]) && ns.getPlayer().money > 10000000) {
+ ns.singularity.donateToFaction(factions[i], (ns.getPlayer().money - 10000000));
+ }
+ }
+
+ if (ns.singularity.getFactionRep(factions[i]) > ns.singularity.getAugmentationRepReq(augs[j])) {
+ if (ns.getPlayer().money > ns.singularity.getAugmentationPrice(augs[j])) {
+ if (ns.singularity.purchaseAugmentation(factions[i], augs[j])) {
+ ns.print("Buying ", augs[j]);
+ owned.push(augs[j]);
+ }
+ }
+ } else if (!n) {
+ ns.singularity.workForFaction(factions[i], "hacking", false);
+ n = factions[i];
+ }
+ }
+ if (augs.length == 0 && n == factions[i]) {
+ n = "";
+ }
+ }
+ if ((ns.singularity.getAugmentationPrice("NeuroFlux Governor") / baseprice) > 16000) {
+ ns.singularity.installAugmentations("start.js");
+ }
+ if (owned.includes("The Red Pill") && !ns.singularity.getOwnedAugmentations(false).includes("The Red Pill")) {
+ ns.singularity.installAugmentations("start.js");
+ }
+ if (ns.singularity.getOwnedAugmentations(false).includes("The Red Pill")) {
+ ns.singularity.workForFaction("Sector-12", "hacking", false);
+ while (true) {
+ ns.clearLog();
+ // if ((Date.now() - ns.getResetInfo().lastAugReset) > 3600000) {
+ // while (ns.singularity.getAugmentationPrice("NeuroFlux Governor") < ns.getPlayer().money) {
+ // if (ns.singularity.getAugmentationRepReq("NeuroFlux Governor") < ns.singularity.getFactionRep("Sector-12")) {
+ // ns.singularity.purchaseAugmentation("Sector-12", "NeuroFlux Governor");
+ // } else {
+ // ns.singularity.donateToFaction("Sector-12", ns.getPlayer().money - ns.singularity.getAugmentationPrice("NeuroFlux Governor") - 10e9)
+ // }
+ // await ns.sleep(100);
+ // }
+ // try { ns.singularity.installAugmentations("start.js"); }
+ // catch {
+ // while (ns.singularity.installAugmentations("start.js")) {
+ // try { ns.singularity.purchaseAugmentation("Sector-12", "NeuroFlux Governor"); }
+ // catch {}
+ // await ns.sleep(100);
+ // }
+ // }
+ // } else {
+ // ns.print("Time since last reset: ", Math.round((Date.now() - ns.getResetInfo().lastAugReset) / 60), " minutes");
+ // }
+ if ((ns.singularity.getAugmentationPrice("NeuroFlux Governor") / baseprice) > 16000) {
+ ns.singularity.installAugmentations("start.js");
+ } else {
+ ns.print("Current price multiplier: ", Math.round(ns.singularity.getAugmentationPrice("NeuroFlux Governor") / baseprice));
+ ns.print("Current price: ", formatLargeNumber(Math.round(5*10e10 + (ns.singularity.getAugmentationPrice("NeuroFlux Governor")))));
+ }
+ if (ns.getPlayer().money > (5*10e10 + ns.singularity.getAugmentationPrice("NeuroFlux Governor"))) {
+ if (ns.singularity.getAugmentationRepReq("NeuroFlux Governor") <= ns.singularity.getFactionRep("Sector-12")) {
+ ns.singularity.purchaseAugmentation("Sector-12", "NeuroFlux Governor");
+ }
+ } else { ns.print("Need more money: ", (100 * Math.floor(ns.getPlayer().money) / Math.ceil(5*10e10 + ns.singularity.getAugmentationPrice("NeuroFlux Governor"))).toFixed(4), "%")}
+
+ if (ns.singularity.getFactionRep("Sector-12") < ns.singularity.getAugmentationRepReq("NeuroFlux Governor")) {
+ ns.print("Current reputation: ", formatLargeNumber(ns.singularity.getFactionRep("Sector-12")));
+ ns.print("Reputation needed: ", formatLargeNumber(ns.singularity.getAugmentationRepReq("NeuroFlux Governor") - ns.singularity.getFactionRep("Sector-12")));
+ if (ns.getPlayer().money > (5*10e10 + ns.singularity.getAugmentationPrice("NeuroFlux Governor"))) {
+ ns.singularity.donateToFaction("Sector-12", ns.getPlayer().money - (5*10e10 + ns.singularity.getAugmentationPrice("NeuroFlux Governor")));
+ }
+ }
+ await ns.sleep(6000);
+ }
+ }
+ await ns.sleep(6000);
+ }
+}
+
+function formatLargeNumber(number) {
+ const suffixes = ['', ' thousand', ' million', ' billion', ' trillion', ' quadrillion', ' quintillion', ' sextillion', ' septillion', ' octillion', ' nonillion', ' decillion'];
+ let suffixIndex = 0;
+
+ while (number >= 1000 && suffixIndex < suffixes.length - 1) {
+ number /= 1000;
+ suffixIndex++;
+ }
+
+ return number.toFixed(2).replace(/\.00$/, '') + suffixes[suffixIndex];
+} \ No newline at end of file
diff --git a/start/buyservers.js b/start/buyservers.js
new file mode 100644
index 0000000..af82de7
--- /dev/null
+++ b/start/buyservers.js
@@ -0,0 +1,134 @@
+
+// enter ram size, number of servers, upgrade yes or no.
+
+
+/** @param {NS} ns */
+export async function main(ns) {
+ const HOME = "home";
+ let size = ns.args[0]; // int; home many GB of ram to buy standard: 2048
+ let number = ns.args[1]; // int; how many pservs to obtain standard: "max"
+ const upgrade = ns.args[2]; // bool; does it upgrade existing pservs standard: true
+ const debug = ns.args[3]; // bool; does it log what happens standard: false
+ const LIMIT = 64000; // sets the max on how much ram a pserv can have (64 TB)
+
+ if (size == "--help") {
+ ns.tprint("\n 1st arg is the Ram size of the servers; does not do anything if upgrade is true; Mandatory.\n 2nd arg is the number of servers; does not do anything if upgrade is true; default to 24.\n 3rd arg is whether to continously upgrade servers; default to false.\n 4th arg is whether to enable debug logs; default is false.");
+ ns.exit();
+ }
+ if (debug != true) {
+ ns.disableLog("getServerMaxRam");
+ ns.disableLog("sleep");
+ ns.disableLog("getServerMoneyAvailable");
+ }
+
+ if (size === undefined) {
+ ns.print("Arguments for this script are RAM size of the servers, number of servers, and true or false for if existing servers should be upgraded.");
+ ns.exit();
+ } else if (Math.log2(size) % 1 != 0) {
+ ns.print("The RAM size must be a power of two.");
+ ns.exit();
+ } else if (number === undefined) {
+ number = 1;
+ } if (number > 25 || number == "max") {
+ number = 25;
+ ns.print("The Maximum number of servers is 25. Reverting to 25 servers");
+ }
+
+ if (upgrade) {
+ const homeram = ns.getServerMaxRam(HOME);
+ let fullservs = 0;
+ while (fullservs < 24) {
+ // start a for loop that goes through each server name
+ for (let i = 0; i < number; i++) {
+ // set the server name
+ let serv;
+ if (i < 10) {
+ serv = "pserv-0" + i;
+ } else {
+ serv = "pserv-" + i;
+ }
+ // check if the server already exists, if it does, upgrade it up to 1/2 of home
+ if (ns.serverExists(serv)) {
+ let servram = ns.getServerMaxRam(serv);
+ // upgrading until server ram is 1/2 home ram
+ if (servram < LIMIT) {
+ // wait to upgrade the server until we have enough money
+ if (ns.getPurchasedServerUpgradeCost(serv, servram * 2) > ns.getServerMoneyAvailable(HOME)) {
+ ns.print("Not enough money yet to upgrade ", serv);
+ ns.print("Need ", ns.getPurchasedServerUpgradeCost(serv, servram * 2), " to upgrade ", serv);
+ while (ns.getPurchasedServerUpgradeCost(serv, servram * 2) > ns.getServerMoneyAvailable(HOME)) {
+ await ns.sleep(60000);
+ }
+ }
+ ns.print("Upgrading ", serv, " from ", servram, " to ", servram * 2);
+ ns.upgradePurchasedServer(serv, servram * 2);
+ }
+ } else {
+ // wait to buy the server until we have enough money
+ while (ns.getPurchasedServerCost(size) > ns.getServerMoneyAvailable(HOME)) {
+ ns.print("Not enough money yet for new server.");
+ await ns.sleep(60000);
+ }
+ // buy the server (root.js will take care of hacking)
+ ns.purchaseServer(serv, size);
+ }
+ }
+ for (let i = 0; i < number; i++) {
+ // set the server name
+ let serv = "pserv-" + i;
+ // check if the server already exists, if it does, see if it is upgraded
+ if (ns.serverExists(serv)) {
+ let servram = ns.getServerMaxRam(serv);
+ // counting how many servers are fully upgraded
+ if (servram >= LIMIT) {
+ fullservs++;
+ } else {
+ fullservs = 0;
+ break;
+ }
+ }
+ }
+ await ns.sleep(100);
+ }
+ ns.print("All servers fully upgraded");
+ } else {
+ // start a for loop that goes through each server name
+ for (let i = 0; i < number; i++) {
+ // set the server name
+ let serv;
+ if (i < 10) {
+ serv = "pserv-0" + i;
+ } else {
+ serv = "pserv-" + i;
+ }
+ // check if the server already exists, if it does, skip it
+ for (let j = 0; j < 24 && ns.serverExists(serv); j++) {
+ if ((i + j) < 10) {
+ serv = "pserv-0" + (i + j);
+ } else {
+ serv = "pserv-" + (i + j);
+ }
+ if ((i + j) >= 24) {
+ ns.print("Maximum amount of purchased servers acquired.");
+ ns.exit();
+ }
+ }
+ // wait to buy the server until we have enough money
+ while (ns.getPurchasedServerCost(size) > ns.getServerMoneyAvailable(HOME)) {
+ ns.print("Not enough money yet for new server.");
+ await ns.sleep(60000);
+ }
+ // buy the server (root.js will take care of hacking)
+ ns.purchaseServer(serv, size);
+ }
+ }
+
+ if (debug == true) {
+ ns.print("Debug time!");
+ await ns.sleep(60000);
+ }
+}
+
+
+// enter ram size, number of servers, upgrade yes or no.
+// auto copy and exec hack.js at maximum threads \ No newline at end of file
diff --git a/start/hacker.js b/start/hacker.js
new file mode 100644
index 0000000..c4c827b
--- /dev/null
+++ b/start/hacker.js
@@ -0,0 +1,255 @@
+let growhost = ["home"]; // Initialize the growhost array -- Include "home" if you want to grow servers from home as well as pservs
+let targets;
+let full = false;
+let grown = [];
+let running = [];
+const debug = false; // True to print debugging logs
+let hostmax = 25; // Set the maximum number of hosts -- Useful for changing between using home and not
+
+/** @param {NS} ns */
+export async function main(ns) {
+ const hackram = ns.getScriptRam("temphack.js");
+ const growram = ns.getScriptRam("tempgrow.js");
+ if (ns.args[0] == "-f") {
+ full = true;
+ }
+
+ ns.tail();
+ ns.moveTail(1075, 350);
+ ns.resizeTail(300, 200);
+
+ ns.tail();
+ if (!debug) {ns.disableLog("ALL")}
+ if (debug) {ns.disableLog("sleep")}
+
+ targets = Array(ns.read("moneyServers.txt"))[0].split("\n");
+
+ if (debug) {ns.print("Line 27")}
+ for (let i = targets.length - 1; i >= 0; i--) {
+ if (ns.getRunningScript("temphack.js", "home", targets[i], true)) {
+ ns.print("Already running ", targets[i]);
+ running.push(targets[i]);
+ }
+ await ns.sleep(100);
+ }
+
+ gethosts(ns);
+
+ if (debug) {ns.print("Line 38")}
+ // if (growhost.length < 5) {
+ // ns.print("waiting for pservs");
+ // while (growhost.length < 5) {
+ // gethosts(ns);
+ // await ns.sleep(1000);
+ // }
+ // ns.print("done waiting for pservs");
+ // }
+
+ if (debug) {ns.print("Line 48")}
+ let m = false;
+ if (growhost.length == 1 || growhost.length == 0) {
+ ns.print("Growhost length:", growhost.length);
+ ns.exec("hack.js", "home", Math.floor((ns.getServerMaxRam("home") - ns.getServerUsedRam("home")) / ns.getScriptRam("hack.js")), "foodnstuff", true);
+ m = true;
+ }
+
+ if (debug) {ns.print("Line 56")}
+ if (m == true) {
+ ns.kill("hack.js", "home", "foodnstuff", true);
+ }
+
+ // Wait until we have FTPCrack.exe
+ // if (!ns.fileExists("FTPCrack.exe")) {
+ // ns.print("Waiting for FTPCrack.exe");
+ // while (!ns.fileExists("FTPCrack.exe")) {
+ // await ns.sleep(6000);
+ // }
+ // }
+
+ // Main Loop
+ let n = 0;
+ while (n < targets.length) {
+ if (debug) {ns.print("Beginning of loop")}
+ n = 0;
+
+ // Check for new pserv's
+ if (growhost.length < 25) {
+ gethosts(ns);
+ }
+
+ // correct grown[] by reseting and counting all that are currently being grown
+ // so that they can be hacked afterward
+ grown = [];
+ if (debug) {ns.print("Before first for loop"); ns.print("Growhost length: ", growhost.length); ns.print("Targets length: ", targets.length)}
+ for (let i = 0; i < growhost.length; i++) {
+ for (let j = 0; j < targets.length; j++) {
+ if (debug) {ns.clearLog(); ns.print("Checking grown ", i, ":", j)}
+ if (ns.getRunningScript("tempgrow.js", growhost[i], targets[j])) {
+ grown.push(targets[j]);
+ }
+ await ns.sleep(10);
+ }
+ await ns.sleep(100);
+ }
+
+ running = [];
+ if (debug) {ns.print("Before second for loop")}
+ for (let i = targets.length - 1; i >= 0; i--) {
+ if (ns.getRunningScript("temphack.js", "home", targets[i], true)) {
+ ns.print("Already running ", targets[i]);
+ running.push(targets[i]);
+ }
+ await ns.sleep(100);
+ }
+
+
+ if (debug) {ns.print("Targets: ");ns.print(targets);ns.print("Before third for loop")}
+ for (let i = targets.length - 1; i >= 0; i--) { // for every target, going backwards from most to least money
+ // for (let i = 0; i < targets.length; i++) { // for every target, going backwards from most to least money
+ if (!grown.includes(targets[i]) && !running.includes(targets[i])) { // not running or grown
+ // ns.print("Don't have ", targets[i], " running");
+ let hacklevel = ns.getHackingLevel() * 0.9; // get the player's hacking level
+ if (hacklevel >= ns.getServerRequiredHackingLevel(targets[i])) { // when the target is hackable
+ if (!ns.hasRootAccess(targets[i])) { // if we don't have access
+ ns.print(i + 1, ": ", targets[i], "\n");
+ ns.brutessh(targets[i]);
+ try {
+ ns.ftpcrack(targets[i]);
+ ns.relaysmtp(targets[i]);
+ ns.httpworm(targets[i]);
+ ns.sqlinject(targets[i]);
+ } catch {}
+ try {
+ ns.nuke(targets[i]);
+ ns.print("Gained root access to ", targets[i]);
+ } catch {
+ continue;
+ }
+ }
+ if (ns.getServerMoneyAvailable(targets[i]) != ns.getServerMaxMoney(targets[i])) { // if it needs to be grown
+ let host = ghost(ns);
+ ns.print("Host: ", host);
+ if (!ns.getRunningScript("tempgrow.js", host, targets[i])) {
+ ns.print("Host: ", host);
+ let threads = growthreads(ns, targets[i]);
+ if (threads * growram > netram(ns, host)) {
+ threads = Math.floor(netram(ns, host) / growram);
+ }
+ ns.print("Host: ", host);
+ if (threads > 0) {
+ ns.print("Growing ", targets[i]);
+ ns.exec("tempgrow.js", host, threads, targets[i]);
+ grown.push(targets[i]);
+ break;
+ }
+ }
+ } else { // if it can now be hacked
+ let threads = hackthreads(ns, targets[i]);
+ let host = "home"
+ if (threads * hackram < netram(ns, host)) {
+ if (threads > 0) {
+ ns.print("Threads for: ", targets[i], ", ", hackthreads(ns, targets[i]), "\n");
+ ns.exec("temphack.js", "home", threads, targets[i], true);
+ running.push(targets[i]);
+ }
+ } else {
+ host = ghost(ns);
+ if (threads * hackram > netram(ns, host)) {
+ threads = Math.floor(netram(ns, host) / hackram);
+ }
+ if (threads > 0) {
+ ns.exec("temphack.js", host, threads, targets[i], true);
+ running.push(targets[i]);
+ }
+ }
+ }
+ }
+ }
+ await ns.sleep(100);
+ }
+ if (debug) {ns.print("End of loop")}
+ display(ns);
+ await ns.sleep(100);
+ }
+ ns.tprint("All targets grown and being hacked");
+}
+
+function netram(ns, serv) {
+ ns.print("netram");
+ return ns.getServerMaxRam(serv) - ns.getServerUsedRam(serv);
+}
+
+// Finds the minimum number of threads to hack a target server
+function hackthreads(ns, serv) {
+ ns.print("hackthreads");
+ try {
+ return Math.ceil(1 / (ns.formulas.hacking.hackPercent(ns.getServer(serv), ns.getPlayer())));
+ } catch {
+ return 1000
+ }
+}
+
+function ghost(ns) {
+ ns.print("ghosts");
+ for (let i = 0; i < growhost.length; i++) {
+ if (ns.getServerUsedRam(growhost[i]) == 0) {
+ return growhost[i];
+ }
+ }
+ for (let i = 0; i < growhost.length; i++) {
+ if (netram(ns, growhost[i]) > 2000) {
+ return growhost[i];
+ }
+ }
+ return growhost[0];
+}
+
+function growthreads(ns, serv) {
+ ns.print("growthreads");
+ try {
+ return Math.max(
+ (ns.formulas.hacking.growThreads(ns.getServer(serv), ns.getPlayer(), ns.getServerMaxMoney(serv))) * 2,
+ Math.ceil((ns.getServerSecurityLevel(serv) - ns.getServerMinSecurityLevel(serv)) / 0.05)
+ );
+ } catch {
+ return 500;
+ }
+}
+
+function gethosts (ns) {
+ ns.print("gethosts");
+ for (let s = growhost.length - 1; s < 25; s++) {
+ if (s < 10) {
+ if (ns.serverExists("pserv-0" + s) && !growhost.includes("pserv-0" + s)) {
+ growhost.push("pserv-0" + s);
+ ns.scp("tempgrow.js", growhost[growhost.length - 1]);
+ ns.scp("temphack.js", growhost[growhost.length - 1]);
+ }
+ } else {
+ if (ns.serverExists("pserv-" + s) && !growhost.includes("pserv-" + s)) {
+ growhost.push("pserv-" + s);
+ ns.scp("tempgrow.js", growhost[growhost.length - 1]);
+ ns.scp("temphack.js", growhost[growhost.length - 1]);
+ }
+ }
+ }
+}
+
+function display(ns) {
+ ns.clearLog();
+ for (let i = 0; i < targets.length; i++) {
+ if (ns.getRunningScript("temphack.js", "home", targets[i], true)) {
+ ns.print(targets[i], ": Running\n");
+ } else if (full == true) {
+ ns.print(targets[i], ": Idle\n");
+ } else {
+ for (let j = 0; j < growhost.length; j++) {
+ if (ns.getRunningScript("tempgrow.js", growhost[j], targets[i])) {
+ ns.print(targets[i], ": Growing\n");
+ break;
+ }
+ }
+ }
+ }
+ ns.print("Growhosts: ", growhost.length);
+} \ No newline at end of file
diff --git a/start/hacknet2.js b/start/hacknet2.js
new file mode 100644
index 0000000..1e67b97
--- /dev/null
+++ b/start/hacknet2.js
@@ -0,0 +1,182 @@
+const MoneyFormat = '$0.0a';
+const TimeFormat = '00:00:00';
+
+/** @param {import(".").NS } ns */
+export async function main(ns) {
+
+ /*
+ ns.hacknet-auto.script for Bitburner v0.47.2
+ Winners don't use copyright
+
+ Latest version of this script should be at
+ https://github.com/iuriguilherme/netscripts.d
+ Bitburner should be at https://github.com/danielyxie/bitburner
+
+ This script requires 5.70 GB of RAM to run for 1 thread(s)
+
+ This script will buy a ns.hacknet Node, fully upgrade it and then buy the next
+ one in an infinite loop. If the cost of the next upgrade is higher than
+ buying a new ns.hacknet Node, then a new one will be bought before the last one
+ is upgraded. There is an option to set the budget limit.
+*/
+
+ ns.tail();
+ ns.moveTail(1650, 825);
+ ns.resizeTail(250, 100);
+
+ // We will not buy anything if there's less money than this ammount
+ var reserveMoney = 2000;
+ // How many nodes to buy
+ var k = 1;
+ // Number of times to upgrade (shouldn't have to change this)
+ var n = 1;
+
+ ns.disableLog("getServerMoneyAvailable");
+ ns.disableLog("sleep");
+
+ //ns.tail();
+
+ ns.print('Waiting to purchase next upgrade...');
+
+ // Buy first ns.hacknetNode if there are none
+ if (
+ ns.hacknet.numNodes() === 0 &&
+ ns.getServerMoneyAvailable("home") >= reserveMoney
+ ) {
+ ns.hacknet.purchaseNode();
+ displayDashBoard(ns);
+ }
+
+ // If there are no ns.hacknet Nodes, we can't do anything, so the script ends.
+ while (ns.hacknet.numNodes() > 0) {
+ // If there is not enough money, we wait for it instead of ending the loop.
+ while (ns.getServerMoneyAvailable("home") >= reserveMoney) {
+ for (var i = 0; i < ns.hacknet.numNodes(); i++) {
+ while (
+ ns.hacknet.getLevelUpgradeCost(i, n) < Infinity &&
+ ns.hacknet.upgradeLevel(i, n)
+ ) {
+ displayDashBoard(ns);
+ await ns.sleep(100);
+ }
+ while (
+ ns.hacknet.getRamUpgradeCost(i, n) < Infinity &&
+ ns.hacknet.upgradeRam(i, n)
+ ) {
+ displayDashBoard(ns);
+ await ns.sleep(100);
+ }
+ while (
+ ns.hacknet.getCoreUpgradeCost(i, n) < Infinity &&
+ ns.hacknet.upgradeCore(i, n)
+ ) {
+ displayDashBoard(ns);
+ await ns.sleep(100);
+ }
+ } // END for (i = 0; i < ns.hacknet.numNodes(); i++)
+ /*
+ Buy next ns.hacknet Node if the last one is already fully upgraded.
+ If for some reason the last ns.hacknet Node is fully upgraded and the
+ others don't, the loop above will still attempt to upgrade them all.
+ */
+ if (
+ ns.hacknet.getLevelUpgradeCost((ns.hacknet.numNodes() - 1), n) === Infinity &&
+ ns.hacknet.getRamUpgradeCost((ns.hacknet.numNodes() - 1), n) === Infinity &&
+ ns.hacknet.getCoreUpgradeCost((ns.hacknet.numNodes() - 1), n) === Infinity
+ ) {
+ // Only buy nodes up to k. Past that its not really worth it.
+ if (ns.hacknet.numNodes() < k) {
+ ns.hacknet.purchaseNode();
+
+ displayDashBoard(ns);
+ }
+ } else if (
+ /*
+ Or buy the next ns.hacknet Node if the next upgrade is more expensive
+ than buying a new ns.hacknet Node.
+ */
+ ns.hacknet.getLevelUpgradeCost((ns.hacknet.numNodes() - 1), n) > ns.hacknet.getPurchaseNodeCost() &&
+ ns.hacknet.getRamUpgradeCost((ns.hacknet.numNodes() - 1), n) > ns.hacknet.getPurchaseNodeCost() &&
+ ns.hacknet.getCoreUpgradeCost((ns.hacknet.numNodes() - 1), n) > ns.hacknet.getPurchaseNodeCost()
+ ) {
+ if (ns.hacknet.numNodes() < 2) {
+ ns.hacknet.purchaseNode();
+
+ displayDashBoard(ns);
+ }
+ }
+ await ns.sleep(100);
+ }
+ await ns.sleep(100);
+ }
+};
+
+/** @param {import(".").NS } ns */
+function displayDashBoard(ns) {
+
+ ns.clearLog();
+ let nodes = Array(ns.hacknet.numNodes()).fill(0);
+ let maxNodes = ns.hacknet.numNodes() < 2 ? 2 : Infinity
+ ns.print(`Nodes: ${nodes.length} of ${maxNodes}`);
+ ns.print(`Total Production: ${nodes.length === 0 ? "$0 /s" : ns.nFormat(nodes.map((v, i) => ns.hacknet.getNodeStats(i).production).reduce((a, b) => a + b), MoneyFormat)} /s`)
+ ns.print(`Total Produced: ${nodes.length === 0 ? "$0" : ns.nFormat(nodes.map((v, i) => ns.hacknet.getNodeStats(i).totalProduction).reduce((a, b) => a + b), MoneyFormat)}`)
+ ns.print(table(
+ ["Node", "Produced", "Uptime", "Production", "Lv", "RAM", "Cores"],
+ nodes.map((v, i) => ns.hacknet.getNodeStats(i).name),
+ nodes.map((v, i) => ns.nFormat(ns.hacknet.getNodeStats(i).totalProduction, MoneyFormat)),
+ nodes.map((v, i) => ns.nFormat(ns.hacknet.getNodeStats(i).timeOnline, TimeFormat)),
+ nodes.map((v, i) => `${ns.nFormat(ns.hacknet.getNodeStats(i).production, MoneyFormat)} /s`),
+ nodes.map((v, i) => `${ns.hacknet.getNodeStats(i).level}`),
+ nodes.map((v, i) => `${ns.hacknet.getNodeStats(i).ram}`),
+ nodes.map((v, i) => `${ns.hacknet.getNodeStats(i).cores}`),
+ ));
+}
+
+const MaxReducer = (a, b) => a > b ? a : b;
+
+/**
+ * Create a Table display of the provided data
+ * @param {string[]} headers Column Headers
+ * @param {...string[]} columns Column data
+ */
+function table(headers, ...columns) {
+ // Calculate Column Widths
+ let widths = [];
+ // for (let i = 0; i < columns.length; i++) {
+ // widths[i] = columns[i].concat([headers[i]]).map(s => s.length).reduce(MaxReducer);
+ // }
+ columns.forEach((c, i) => {
+ widths[i] = c.concat([headers[i]]).map(s => s.length).reduce(MaxReducer);
+ });
+
+ let output = "\n";
+
+ // Write Headers
+ headers.forEach((h, i) => {
+ output += ` ${h.padEnd(widths[i], " ")} |`;
+ });
+
+ output += "\n";
+
+ // Write Separator
+ headers.forEach((h, i) => {
+ output += `${"".padEnd(widths[i] + 2, "=")}|`;
+ });
+
+ output += "\n";
+
+ let rows = columns[0].length;
+ for (let row = 0; row < rows; row++) {
+ columns.forEach((c, i) => {
+ if (c[row] == "-") {
+ output += ` ${"".padEnd(widths[i], "-")} |`;
+ } else {
+ output += ` ${c[row].padEnd(widths[i], " ")} |`;
+ }
+ });
+
+ output += "\n";
+ }
+
+ return output;
+} \ No newline at end of file
diff --git a/start/home.js b/start/home.js
new file mode 100644
index 0000000..0ace136
--- /dev/null
+++ b/start/home.js
@@ -0,0 +1,35 @@
+var money;
+
+/** @param {NS} ns */
+export async function main(ns) {
+ getmoney(ns);
+
+ ns.tail();
+ ns.moveTail(1050, 525);
+ ns.resizeTail(250, 100);
+
+ let factions = ns.getPlayer().factions;
+ ns.disableLog("disableLog");
+ ns.disableLog("clearLog");
+ ns.disableLog("sleep");
+ ns.disableLog("singularity.getUpgradeHomeRamCost");
+ ns.disableLog("singularity.getUpgradeHomeCoresCost");
+ ns.disableLog("getServerMoneyAvailable");
+ ns.clearLog();
+ while (true) {
+ getmoney(ns);
+ if (money > ns.singularity.getUpgradeHomeRamCost()) {
+ ns.singularity.upgradeHomeRam();
+ } else if (money > ns.singularity.getUpgradeHomeCoresCost()) {
+ ns.singularity.upgradeHomeCores();
+ } else if (ns.singularity.checkFactionInvitations().length > 0) {
+ ns.singularity.joinFaction(ns.singularity.checkFactionInvitations()[0]);
+ }
+ await ns.sleep(1000);
+ }
+}
+
+
+function getmoney(ns) {
+ money = ns.getServerMoneyAvailable("home");
+} \ No newline at end of file
diff --git a/start/milestones.js b/start/milestones.js
new file mode 100644
index 0000000..856900a
--- /dev/null
+++ b/start/milestones.js
@@ -0,0 +1,133 @@
+const HOME = "home";
+
+// You have to run this script once per target
+
+let hacked = [];
+
+/** @param {NS} ns */
+export async function main(ns) {
+
+ ns.tail();
+ ns.moveTail(1650, 725);
+ ns.resizeTail(250, 100);
+
+ ns.disableLog("disableLog");
+ ns.disableLog("clearLog");
+ ns.disableLog("sleep");
+ ns.disableLog("scan");
+ ns.clearLog();
+
+ const targets = [
+ "CSEC",
+ "avmnite-02h",
+ "I.I.I.I",
+ "run4theh111z"//,
+ // "w0r1d_d43m0n"
+ ];
+
+ while (!ns.fileExists("SQLInject.exe")) {
+ await ns.sleep(12000);
+ }
+ for (let i = 0; i < targets.length; i++) {
+ if (targets[i] == "w0rld_d43m0n") {
+ while (!ns.singularity.getOwnedAugmentations().includes("The Red Pill")) {
+ ns.clearLog();
+ ns.print("Waiting for red pill");
+ await ns.sleep(60000);
+ }
+ }
+ await root(ns, targets[i]);
+ }
+}
+function buildRoute(ns, parent, target, route, seen = []) {
+ //first time we run we need to add the parent to the list of servers we've seen
+ if (!seen.includes(parent)) {
+ seen.push(parent);
+ }
+ //add to route
+ route.push(parent);
+ const children = ns.scan(parent);
+ for (const child of children) {
+ if (seen.includes(child)) {
+ //already checked
+ continue;
+ }
+ seen.push(child);
+ if (child == target) {
+ //found target, add it to the route and finish recursion
+ route.push(child);
+ return true;
+ }
+ if (buildRoute(ns, child, target, route, seen)) {
+ //target found, finish recursion
+ return true;
+ }
+ else {
+ //target not found in this branch, remove from route
+ route.pop();
+ }
+ }
+ //didn't find target in this route, reset route
+ route = [];
+ return false;
+}
+async function printRoute(ns, route) {
+ let result = [];
+ for (const node of route) {
+ result.push(node);
+ }
+ return result;
+}
+async function root(ns, target) {
+ if (!ns.hasRootAccess(target)) {
+ ns.brutessh(target);
+ ns.ftpcrack(target);
+ ns.relaysmtp(target);
+ ns.httpworm(target);
+ ns.sqlinject(target);
+ ns.print("Gained root access to ", target);
+ while (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(target)) {
+ await ns.sleep(6000);
+ }
+ ns.nuke(target);
+
+ ns.singularity.connect(HOME);
+ await ns.sleep(100);
+
+ let result = [];
+ let route = [];
+
+ buildRoute(ns, HOME, target, route)
+ result = await printRoute(ns, route);
+
+ for (let n = 0; n < result.length; n++) {
+ ns.singularity.connect(result[n]);
+ await ns.sleep(100);
+ }
+ await ns.singularity.installBackdoor();
+ ns.singularity.connect(HOME);
+ } else if (!ns.getServer(target).backdoorInstalled) {
+ ns.singularity.connect(HOME);
+ await ns.sleep(100);
+
+ let result = [];
+ let route = [];
+
+ buildRoute(ns, HOME, target, route)
+ result = await printRoute(ns, route);
+
+ for (let n = 0; n < result.length; n++) {
+ ns.singularity.connect(result[n]);
+ await ns.sleep(100);
+ }
+ await ns.singularity.installBackdoor();
+ ns.singularity.connect(HOME);
+ }
+ hacked.push(target);
+ ns.clearLog();
+ ns.print("Hacked servers: ", )
+ for (let j = 0; j < hacked.length; j++) {
+ ns.print(hacked[j]);
+ }
+ return 0;
+} \ No newline at end of file
diff --git a/start/root.js b/start/root.js
new file mode 100644
index 0000000..d04449e
--- /dev/null
+++ b/start/root.js
@@ -0,0 +1,358 @@
+const HOME = "home";
+
+/** @param {NS} ns */
+export async function main(ns) {
+ let target = "home";
+ let thread = 1;
+ const scriptRam = 2.4;
+
+ // Determine whether or not to enable logging
+ let debug = ns.args[0];
+ ns.disableLog("ALL");
+
+ // What percentage of our hacking level should a server be before using it
+ let lvlpercent = ns.args[1];
+
+ // List of targets for each level of exe function
+ const targets = [
+ "deltaone",
+ "global-pharm",
+ "rho-construction",
+ "the-hub",
+ "iron-gym",
+ "harakiri-sushi"
+ ];
+
+ // List of exe functions
+ const exes = [
+ "SQLInject.exe",
+ "HTTPWorm.exe",
+ "RelaySMTP.exe",
+ "FTPCrack.exe",
+ "BruteSSH.exe",
+ "NUKE.exe"
+ ];
+
+ // Array of all purchased servers
+ // Varying RAM sizes
+ const pservers = [
+ "pserv-0",
+ "pserv-1",
+ "pserv-2",
+ "pserv-3",
+ "pserv-4",
+ "pserv-5",
+ "pserv-6",
+ "pserv-7",
+ "pserv-8",
+ "pserv-9",
+ "pserv-10",
+ "pserv-11",
+ "pserv-12",
+ "pserv-13",
+ "pserv-14",
+ "pserv-15",
+ "pserv-16",
+ "pserv-17",
+ "pserv-18",
+ "pserv-19",
+ "pserv-20",
+ "pserv-21",
+ "pserv-22",
+ "pserv-23",
+ ];
+
+
+ // Array of all servers that don't need any ports opened
+ // to gain root access. These have GB of RAM
+ const servers0Port = [
+ "n00dles",
+ "foodnstuff",
+ "sigma-cosmetics",
+ "joesguns",
+ "nectar-net",
+ "hong-fang-tea",
+ "harakiri-sushi"
+ ];
+
+
+ // Array of all servers that only need 1 port opened
+ // to gain root access. These have 32 GB of RAM
+ const servers1Port = [
+ "neo-net",
+ "zer0",
+ "max-hardware",
+ "iron-gym",
+ "CSEC"
+ ];
+
+
+ // 2 port servers
+ const servers2Port = [
+ "omega-net",
+ "silver-helix",
+ "phantasy",
+ "johnson-ortho",
+ "crush-fitness",
+ "the-hub",
+ "avmnite-02h"
+ ];
+
+ // 3 port servers
+ const servers3Port = [
+ "netlink",
+ "computek",
+ "I.I.I.I",
+ "summit-uni",
+ "catalyst",
+ "rothman-uni",
+ "millenium-fitness",
+ "rho-construction"
+ ];
+
+ const servers4Port = [
+ "aevum-police",
+ "global-pharm",
+ "syscore",
+ "lexo-corp",
+ "unitalife",
+ "snap-fitness",
+ "alpha-ent",
+ "univ-energy",
+ "nova-med",
+ "zb-def"
+ ];
+
+ // 5 port servers
+ const servers5Port = [
+ "zb-institute",
+ "galactic-cyber",
+ "aerocorp",
+ "omnia",
+ "deltaone",
+ "taiyang-digital",
+ "icarus",
+ "zeus-med",
+ "infocomm",
+ "solaris",
+ "defcomm"
+ ];
+
+ // //decide the target
+ // // Cycle through each .exe file for a match
+ // for (let i = 0; i < exes.length; i++) {
+ // // if the file doens't exist yet, look at the next file
+ // if (ns.fileExists(exes[i]) && (ns.getServerRequiredHackingLevel(targets[i]) <= (ns.getHackingLevel() * lvlpercent))) {
+ // // the file exists, so the target is now the best target of that file
+ // target = targets[i];
+ // break;
+ // }
+ // }
+ // // List the target in the logs
+ // ns.print("target: ", target);
+ // root(ns, target);
+
+ // // Hack from the home server
+ // if (ns.serverExists("home")) {
+ // const serv = "home";
+ // ns.print("Hacking using: ", serv);
+ // thread = threads(ns, serv, scriptRam, thread);
+ // if (thread > 0) {
+ // hax(ns, serv, target, thread, true);
+ // }
+ // }
+
+ // // DEBUGGING: uncomment the following line to find logs for the above code
+ // if (debug) {
+ // await ns.sleep(60000);
+ // }
+ // // Copy our scripts onto each server that requires 0 ports
+ // // to gain root access. Then use nuke() to gain admin access and
+ // // run the scripts.
+ // for (let i = 0; i < servers0Port.length; ++i) {
+ // const serv = servers0Port[i];
+ // ns.print("Hacking using: ", serv);
+ // root(ns, serv);
+ // thread = threads(ns, serv, scriptRam, thread);
+ // if (thread > 0) {
+ // hax(ns, serv, target, thread, debug);
+ // }
+ // }
+
+ // // Wait until we acquire the "BruteSSH.exe" program
+ // if (!ns.fileExists("BruteSSH.exe")) {
+ // ns.print("Waiting for BruteSSH.exe");
+ // ns.exit();
+ // }
+
+ // // Copy our scripts onto each server that requires 1 port
+ // // to gain root access. Then use brutessh() and nuke()
+ // // to gain admin access and run the scripts.
+ // for (let i = 0; i < servers1Port.length; ++i) {
+ // const serv = servers1Port[i];
+
+ // ns.print("Hacking using: ", serv);
+ // root(ns, serv);
+ // thread = threads(ns, serv, scriptRam, thread);
+ // if (thread > 0) {
+ // hax(ns, serv, target, thread, debug);
+ // }
+ // }
+
+ // // Wait until we acquire the "BruteSSH.exe" program
+ // while (!ns.fileExists("FTPCrack.exe")) {
+ // ns.print("Waiting for FTPCrack");
+ // ns.exit();
+ // }
+
+ // // Copy our scripts onto each server that requires 1 port
+ // // to gain root access. Then use brutessh() and nuke()
+ // // to gain admin access and run the scripts.
+ // for (let i = 0; i < servers2Port.length; ++i) {
+ // const serv = servers2Port[i];
+
+ // ns.print("Hacking using: ", serv);
+ // root(ns, serv);
+ // thread = threads(ns, serv, scriptRam, thread);
+ // if (thread > 0) {
+ // hax(ns, serv, target, thread, debug);
+ // }
+ // }
+
+
+ // //Run hack scripts from purchased servers
+ // for (let i = 0; i < pservers.length; ++i) {
+ // while (!ns.serverExists(pservers[i])) {
+ // ns.print("Server ", pservers[i], " doesn't exist yet");
+ // await ns.sleep(60000);
+ // }
+ // const serv = pservers[i];
+
+ // ns.print("Hacking using: ", serv);
+ // thread = threads(ns, serv, scriptRam, thread);
+ // if (thread > 0) {
+ // hax(ns, serv, target, thread, debug);
+ // }
+ // }
+
+ // while (!ns.fileExists("RelaySMTP.exe")) {
+ // ns.print("Waiting for RelaySMTP");
+ // ns.exit();
+ // }
+
+ // for (let i = 0; i < servers3Port.length; ++i) {
+ // const serv = servers3Port[i];
+
+ // ns.print("Hacking using: ", serv);
+ // root(ns, serv);
+ // thread = threads(ns, serv, scriptRam, thread);
+ // if (thread > 0) {
+ // hax(ns, serv, target, thread, debug);
+ // }
+ // }
+
+ const servers = [
+ servers0Port,
+ servers1Port,
+ servers2Port,
+ servers3Port,
+ servers4Port,
+ servers5Port,
+ ];
+
+ let hacked = [];
+
+ ns.clearLog();
+ ns.tail();
+ ns.moveTail(0,0);
+ ns.resizeTail(1350, 600);
+ ns.print("DONT DO ANYTHING DONT DO ANYTHING DONT DO ANYTHING DONT DO ANYTHING \n\n\n\n\n\n\n\n\n\n\n\n");
+ await ns.sleep(1000);
+
+ for (let i = 0; i < servers.length; i++) {
+ for (let j = 0; j < servers[i].length; j++) {
+ if (!ns.hasRootAccess(servers[i][j])) {
+ ns.brutessh(servers[i][j]);
+ ns.ftpcrack(servers[i][j]);
+ ns.relaysmtp(servers[i][j]);
+ ns.httpworm(servers[i][j]);
+ ns.sqlinject(servers[i][j]);
+ while (ns.getHackingLevel() < ns.getServerRequiredHackingLevel(servers[i][j])) {
+ await ns.sleep(6000);
+ }
+ ns.nuke(servers[i][j]);
+ ns.print("Gained root access to ", servers[i][j]);
+ }
+ if (!ns.getServer(servers[i][j]).backdoorInstalled) {
+ ns.singularity.connect(HOME);
+ await ns.sleep(100);
+
+ let result = [];
+ let route = [];
+
+ buildRoute(ns, HOME, servers[i][j], route)
+ result = await printRoute(ns, route);
+
+ for (let n = 0; n < result.length; n++) {
+ ns.singularity.connect(result[n]);
+ await ns.sleep(100);
+ }
+ await ns.singularity.installBackdoor();
+ ns.singularity.connect(HOME);
+ }
+ hacked.push(servers[i][j]);
+ }
+ }
+
+ await ns.sleep(1000);
+ ns.clearLog();
+ ns.moveTail(500, 300);
+ ns.resizeTail(300, 100);
+ ns.print("Backdoors installed");
+
+
+
+}
+
+function buildRoute(ns, parent, target, route, seen = []) {
+ //first time we run we need to add the parent to the list of servers we've seen
+ if (!seen.includes(parent)) {
+ seen.push(parent);
+ }
+ //add to route
+ route.push(parent);
+ const children = ns.scan(parent);
+ for (const child of children) {
+ if (seen.includes(child)) {
+ //already checked
+ continue;
+ }
+ seen.push(child);
+ if (child == target) {
+ //found target, add it to the route and finish recursion
+ route.push(child);
+ return true;
+ }
+ if (buildRoute(ns, child, target, route, seen)) {
+ //target found, finish recursion
+ return true;
+ }
+ else {
+ //target not found in this branch, remove from route
+ route.pop();
+ }
+ }
+ //didn't find target in this route, reset route
+ route = [];
+ return false;
+}
+async function printRoute(ns, route) {
+ let result = [];
+ for (const node of route) {
+ result.push(node);
+ }
+ return result;
+}
+function root(ns, target) {
+
+}
diff --git a/start/tempgrow.js b/start/tempgrow.js
new file mode 100644
index 0000000..3591803
--- /dev/null
+++ b/start/tempgrow.js
@@ -0,0 +1,34 @@
+/** @param {NS} ns */
+export async function main(ns) {
+ // What server will be targeted?
+ let target = ns.args[0];
+ if (target === undefined) {
+ ns.exit();
+ }
+ const securityThresh = ns.getServerMinSecurityLevel(target) + 5;
+ ns.getServerSecurityLevel(target);
+ ns.getServerMaxMoney(target);
+ ns.getServerMoneyAvailable(target);
+
+ while (ns.getServerSecurityLevel(target) > (securityThresh)) {
+ // If the server's security level is above our threshold, weaken it
+ await ns.weaken(target);
+ }
+ while (ns.getServerMoneyAvailable(target) < ns.getServerMaxMoney(target)) {
+ // If the server's security level is above our threshold, weaken it
+ if (ns.getServerSecurityLevel(target) > (securityThresh)) {
+ await ns.weaken(target);
+ } else {
+ await ns.grow(target);
+ }
+ }
+ while (ns.getServerSecurityLevel(target) > (securityThresh)) {
+ // If the server's security level is above our threshold, weaken it
+ await ns.weaken(target);
+ }
+ await ns.sleep(500);
+ ns.getServerMinSecurityLevel(target);
+ ns.getServerSecurityLevel(target);
+ ns.getServerMaxMoney(target);
+ ns.getServerMoneyAvailable(target);
+} \ No newline at end of file
diff --git a/start/temphack.js b/start/temphack.js
new file mode 100644
index 0000000..bd888fa
--- /dev/null
+++ b/start/temphack.js
@@ -0,0 +1,25 @@
+/** @param {NS} ns */
+export async function main(ns) {
+ // What server will be targeted?
+ let target = ns.args[0];
+ if (target === undefined) {
+ ns.exit();
+ }
+
+ ns.print("At min security: ", ns.getServerMinSecurityLevel(target) == ns.getServerSecurityLevel(target));
+ ns.print("At max money: ", ns.getServerMaxMoney(target) == ns.getServerMoneyAvailable(target));
+
+ // while (ns.getServerSecurityLevel(target) > (securityThresh)) {
+ // // If the server's security level is above our threshold, weaken it
+ // await ns.weaken(target);
+ // }
+ await ns.hack(target);
+ // await ns.weaken(target);
+ // await ns.sleep(1000);
+
+ ns.getServerMaxMoney(target);
+ ns.getServerMoneyAvailable(target);
+}
+
+// hacks a server once
+