From 40843e35434d56e883655e4377994ac76746b184 Mon Sep 17 00:00:00 2001 From: AlmightyMiau Date: Wed, 13 Nov 2024 10:56:53 -0800 Subject: Organized scripts into folders --- misc/autoinfiltrate.js | 803 +++++++++++++++++++++++++++++++++++++++++++++++++ misc/delete.js | 11 + misc/install.js | 4 + misc/monitor.js | 63 ++++ misc/route.js | 57 ++++ misc/run.js | 12 + misc/servers.txt | 97 ++++++ misc/target.js | 178 +++++++++++ misc/targets.js | 45 +++ misc/targets.txt | 6 + misc/test.js | 4 + misc/threads.js | 13 + 12 files changed, 1293 insertions(+) create mode 100644 misc/autoinfiltrate.js create mode 100644 misc/delete.js create mode 100644 misc/install.js create mode 100644 misc/monitor.js create mode 100644 misc/route.js create mode 100644 misc/run.js create mode 100644 misc/servers.txt create mode 100644 misc/target.js create mode 100644 misc/targets.js create mode 100644 misc/targets.txt create mode 100644 misc/test.js create mode 100644 misc/threads.js (limited to 'misc') diff --git a/misc/autoinfiltrate.js b/misc/autoinfiltrate.js new file mode 100644 index 0000000..eb7717f --- /dev/null +++ b/misc/autoinfiltrate.js @@ -0,0 +1,803 @@ +// This script is awesome and will autocomplete the infiltrate tasks in bitburner. +// It does not always run properly, it could be a browser issue and works 95% with game running on edge browser. +// This was copied from https://pastebin.com/7DuFYDpJ and modified to work with shadows of anarchy augments. +// Type "wget https://raw.githubusercontent.com/5p0ng3b0b/bitburner-scripts/main/autoinfiltrate.js autoinfiltrate.js" from you home terminal to download. +// Type 'run autoinfiltrate.js' from home terminal. options are --start --stop --quiet although the --start option is not required. +// Try always running it via an alias eg 'alias autoinfil="run autoinfiltrate.js --stop --quiet; run autoinfiltrate.js --quiet"" +// Once the script is running, It will activate when you visit any company and click the infiltrate button. +// You can use infiltrate to quickly get alot of money early in the game or quickly earn rep for any faction. +// ecorp in Aevum is the highest earner followed by megacorp in sector-12 and then KuaiGong International in Chongqing. + + +const state = { + // Name of the company that's infiltrated. + company: "", + + // Whether infiltration started. False means, we're + // waiting to arrive on the infiltration screen. + started: false, + + // Details/state of the current mini game. + // Is reset after every game. + game: {}, +}; + +// Speed of game actions, in milliseconds. Default 22 +const speed = 25; + +// Small hack to save RAM. +// This will work smoothly, because the script does not use +// any "ns" functions, it's a pure browser automation tool. +const wnd = eval("window"); +const doc = wnd["document"]; + +// List of all games and an automated solver. +const infiltrationGames = [ + { + name: "type it", + init: function (screen) { + const lines = getLines(getEl(screen, "p")); + state.game.data = lines[0].split(""); + }, + play: function (screen) { + if (!state.game.data || !state.game.data.length) { + delete state.game.data; + return; + } + + pressKey(state.game.data.shift()); + }, + }, + { + name: "type it backward", + init: function (screen) { + const lines = getLines(getEl(screen, "p")); + state.game.data = lines[0].split(""); + }, + play: function (screen) { + if (!state.game.data || !state.game.data.length) { + delete state.game.data; + return; + } + + pressKey(state.game.data.shift()); + }, + }, + { + // name: "enter the code", + init: function (screen) { }, + play: function (screen) { + const h4 = getEl(screen, "h4"); + const spanElements = h4[1].querySelectorAll("span"); + const code = Array.from(spanElements) + .filter(span => span.textContent !== "?") + .map(span => span.textContent) + .pop(); + + switch (code) { + case "↑": + pressKey("w"); + break; + case "↓": + pressKey("s"); + break; + case "←": + pressKey("a"); + break; + case "→": + pressKey("d"); + break; + } + }, + }, + { + name: "close the brackets", + init: function (screen) { + const data = getLines(getEl(screen, "p")); + const brackets = data.join("").split(""); + state.game.data = []; + + for (let i = brackets.length - 1; i >= 0; i--) { + const char = brackets[i]; + + if ("<" == char) { + state.game.data.push(">"); + } else if ("(" == char) { + state.game.data.push(")"); + } else if ("{" == char) { + state.game.data.push("}"); + } else if ("[" == char) { + state.game.data.push("]"); + } + } + }, + play: function (screen) { + if (!state.game.data || !state.game.data.length) { + delete state.game.data; + return; + } + + pressKey(state.game.data.shift()); + }, + }, + { + name: "Attack after the guard drops his guard and is distracted. Do not alert him!", + init: function (screen) { + state.game.data = "wait"; + }, + play: function (screen) { + const data = getLines(getEl(screen, "h4")); + + if ("Distracted!" === state.game.data) { + pressKey(" "); + state.game.data = "done"; + } + + // Attack in next frame - instant attack sometimes + // ends in failure. + if ('wait' === state.game.data && -1 !== data.indexOf("Alerted!")) { + state.game.data = "attack"; + } + }, + }, + { + name: "say something nice about the guard", + init: function (screen) { }, + play: function (screen) { + const correct = [ + "affectionate", + "agreeable", + "bright", + "charming", + "creative", + "determined", + "energetic", + "friendly", + "funny", + "generous", + "polite", + "likable", + "diplomatic", + "helpful", + "giving", + "kind", + "hardworking", + "patient", + "dynamic", + "loyal", + "based", + "straightforward" + ]; + const word = getLines(getEl(screen, "h5"))[1]; + + if (-1 !== correct.indexOf(word)) { + pressKey(" "); + } else { + pressKey("w"); + } + }, + }, + { + name: "remember all the mines", + init: function (screen) { + const rows = getEl(screen, "p"); + let gridSize = null; + switch (rows.length) { + case 9: + gridSize = [3, 3]; + break; + case 12: + gridSize = [3, 4]; + break; + case 16: + gridSize = [4, 4]; + break; + case 20: + gridSize = [4, 5]; + break; + case 25: + gridSize = [5, 5]; + break; + case 30: + gridSize = [5, 6]; + break; + case 36: + gridSize = [6, 6]; + break; + } + if (gridSize == null) { + return; + } + //12 20 30 42 + state.game.data = []; + let index = 0; + //for each row + for (let y = 0; y < gridSize[1]; y++) { + //initialize array data + state.game.data[y] = []; + for (let x = 0; x < gridSize[0]; x++) { + //for each column in the row add to state data if it has a child + if (rows[index].children.length > 0) { + state.game.data[y].push(true); + } else state.game.data[y].push(false); + index += 1; + } + } + }, + play: function (screen) { }, + }, + { + name: "mark all the mines", + init: function (screen) { + state.game.x = 0; + state.game.y = 0; + state.game.cols = state.game.data[0].length; + state.game.dir = 1; + }, + play: function (screen) { + let { data, x, y, cols, dir } = state.game; + + if (data[y][x]) { + pressKey(" "); + data[y][x] = false; + } + + x += dir; + + if (x < 0 || x >= cols) { + x = Math.max(0, Math.min(cols - 1, x)); + y++; + dir *= -1; + pressKey("s"); + } else { + pressKey(dir > 0 ? "d" : "a"); + } + + state.game.data = data; + state.game.x = x; + state.game.y = y; + state.game.dir = dir; + }, + }, + { + name: "match the symbols", + init: function (screen) { + const data = getLines(getEl(screen, "h5 span")); + const rows = getLines(getEl(screen, "p")); + const keypad = []; + const targets = []; + let gridSize = null; + switch (rows.length) { + case 9: + gridSize = [3, 3]; + break; + case 12: + gridSize = [3, 4]; + break; + case 16: + gridSize = [4, 4]; + break; + case 20: + gridSize = [4, 5]; + break; + case 25: + gridSize = [5, 5]; + break; + case 30: + gridSize = [5, 6]; + break; + case 36: + gridSize = [6, 6]; + break; + } + if (gridSize == null) { + return; + } + //build the keypad grid. + let index = 0; + for (let i = 0; i < gridSize[1]; i++) { + keypad[i] = []; + for (let y = 0; y < gridSize[0]; y++) { + + keypad[i].push(rows[index]); + index += 1; + } + } + //foreach data get coords of keypad entry + for (let i = 0; i < data.length; i++) { + const symbol = data[i].trim(); + //for each keypad entry + for (let j = 0; j < keypad.length; j++) { + const k = keypad[j].indexOf(symbol); + + if (-1 !== k) { + targets.push([j, k]); + break; + } + } + } + state.game.data = targets; + state.game.x = 0; + state.game.y = 0; + }, + play: function (screen) { + const target = state.game.data[0]; + let { x, y } = state.game; + + if (!target) { + return; + } + + const to_y = target[0]; + const to_x = target[1]; + + if (to_y < y) { + y--; + pressKey("w"); + } else if (to_y > y) { + y++; + pressKey("s"); + } else if (to_x < x) { + x--; + pressKey("a"); + } else if (to_x > x) { + x++; + pressKey("d"); + } else { + pressKey(" "); + state.game.data.shift(); + } + + state.game.x = x; + state.game.y = y; + }, + }, + { + name: "cut the wires with the following properties", + init: function (screen) { + let numberHack = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]; + const colors = { + red: "red", + white: "white", + blue: "blue", + "rgb(255, 193, 7)": "yellow", + }; + const wireColor = { + red: [], + white: [], + blue: [], + yellow: [], + }; + //gather the instructions + var instructions = [] + for (let child of screen.children) instructions.push(child); + var wiresData = instructions.pop(); + instructions.shift(); + instructions = getLines(instructions); + //get the wire information + const samples = getEl(wiresData, "p"); + const wires = []; + //get the amount of wires + let wireCount = 0; + for (let i = wireCount; i < samples.length; i++) { + if (numberHack.includes(samples[i].innerText)) wireCount += 1; + else break; + } + let index = 0; + //get just the first 3 rows of wires. + for (let i = 0; i < 3; i++) { + //for each row + for (let j = 0; j < wireCount; j++) { + const node = samples[index]; + const color = colors[node.style.color]; + if (!color) { + index += 1; + continue; + } + wireColor[color].push(j + 1); + index += 1; + } + } + + for (let i = 0; i < instructions.length; i++) { + const line = instructions[i].trim().toLowerCase(); + + if (!line || line.length < 10) { + continue; + } + if (-1 !== line.indexOf("cut wires number")) { + const parts = line.split(/(number\s*|\.)/); + wires.push(parseInt(parts[2])); + } + if (-1 !== line.indexOf("cut all wires colored")) { + const parts = line.split(/(colored\s*|\.)/); + const color = parts[2]; + + if (!wireColor[color]) { + // should never happen. + continue; + } + + wireColor[color].forEach((num) => wires.push(num)); + } + } + + // new Set() removes duplicate elements. + state.game.data = [...new Set(wires)]; + }, + play: function (screen) { + const wire = state.game.data; + //state.game.data.shift(); + if (!wire) { + return; + } + for (let i = 0; i < wire.length; i++) { + pressKey(wire[i].toString()); + } + }, + }, +]; + +/** @param {NS} ns **/ +export async function main(ns) { + const args = ns.flags([ + ["start", false], + ["stop", false], + ["status", false], + ["quiet", false], + ]); + + function print(msg) { + if (!args.quiet) { + ns.tprint(`\n${msg}\n`); + } + } + + if (args.status) { + if (wnd.tmrAutoInf) { + print("Automated infiltration is active"); + } else { + print("Automated infiltration is inactive"); + } + return; + } + + if (wnd.tmrAutoInf) { + print("Stopping automated infiltration..."); + clearInterval(wnd.tmrAutoInf); + delete wnd.tmrAutoInf; + } + + if (args.stop) { + return; + } + + print( + "Automated infiltration is enabled...\nVWhen you visit the infiltration screen of any company, all tasks are completed automatically." + ); + + endInfiltration(); + + // Monitor the current screen and start infiltration once a + // valid screen is detected. + wnd.tmrAutoInf = setInterval(infLoop, speed); + + // Modify the addEventListener logic. + wrapEventListeners(); +} + +/** + * The infiltration loop, which is called at a rapid interval + */ +function infLoop() { + if (!state.started) { + waitForStart(); + } else { + playGame(); + } +} + +/** + * Returns a list of DOM elements from the main game + * container. + */ +function getEl(parent, selector) { + let prefix = ":scope"; + + if ("string" === typeof parent) { + selector = parent; + parent = doc; + + prefix = ".MuiBox-root>.MuiBox-root>.MuiBox-root"; + + if (!doc.querySelectorAll(prefix).length) { + prefix = ".MuiBox-root>.MuiBox-root>.MuiGrid-root"; + } + if (!doc.querySelectorAll(prefix).length) { + prefix = ".MuiContainer-root>.MuiPaper-root"; + } + if (!doc.querySelectorAll(prefix).length) { + return []; + } + } + + selector = selector.split(","); + selector = selector.map((item) => `${prefix} ${item}`); + selector = selector.join(","); + + return parent.querySelectorAll(selector); +} + +/** + * Returns the first element with matching text content. + */ +function filterByText(elements, text) { + text = text.toLowerCase(); + + for (let i = 0; i < elements.length; i++) { + const content = elements[i].textContent.toLowerCase(); + + if (-1 !== content.indexOf(text)) { + return elements[i]; + } + } + + return null; +} + +/** + * Returns an array with the text-contents of the given elements. + * + * @param {NodeList} elements + * @returns {string[]} + */ +function getLines(elements) { + const lines = []; + elements.forEach((el) => lines.push(el.textContent)); + + return lines; +} + +/** + * Reset the state after infiltration is done. + */ +function endInfiltration() { + unwrapEventListeners(); + state.company = ""; + state.started = false; +} + +/** + * Simulate a keyboard event (keydown + keyup). + * + * @param {string|int} keyOrCode A single letter (string) or key-code to send. + */ +function pressKey(keyOrCode) { + let keyCode = 0; + let key = ""; + + if ("string" === typeof keyOrCode && keyOrCode.length > 0) { + key = keyOrCode.toLowerCase().substr(0, 1); + keyCode = key.charCodeAt(0); + } else if ("number" === typeof keyOrCode) { + keyCode = keyOrCode; + key = String.fromCharCode(keyCode); + } + + if (!keyCode || key.length !== 1) { + return; + } + + function sendEvent(event) { + const keyboardEvent = new KeyboardEvent(event, { + key, + keyCode, + }); + + doc.dispatchEvent(keyboardEvent); + } + + sendEvent("keydown"); +} + +/** + * Infiltration monitor to start automatic infiltration. + * + * This function runs asynchronously, after the "main" function ended, + * so we cannot use any "ns" function here! + */ +function waitForStart() { + if (state.started) { + return; + } + + const h4 = getEl("h4"); + + if (!h4.length) { + return; + } + const title = h4[0].textContent; + if (0 !== title.indexOf("Infiltrating")) { + return; + } + + const btnStart = filterByText(getEl("button"), "Start"); + if (!btnStart) { + return; + } + + state.company = title.substr(13); + state.started = true; + wrapEventListeners(); + + console.log("Start automatic infiltration of", state.company); + btnStart.click(); +} + +/** + * Identify the current infiltration game. + */ +function playGame() { + const screens = doc.querySelectorAll(".MuiContainer-root"); + + if (!screens.length) { + endInfiltration(); + return; + } + if (screens[0].children.length < 3) { + return; + } + + const screen = screens[0].children[2]; + const h4 = getEl(screen, "h4"); + + if (!h4.length) { + endInfiltration(); + return; + } + + const title = h4[0].textContent.trim().toLowerCase().split(/[!.(]/)[0]; + + if ("infiltration successful" === title) { + endInfiltration(); + return; + } + + if ("get ready" === title) { + return; + } + + const game = infiltrationGames.find((game) => game.name === title); + + if (game) { + if (state.game.current !== title) { + state.game.current = title; + game.init(screen); + } + + game.play(screen); + } else { + console.error("Unknown game:", title); + } +} + +/** + * Wrap all event listeners with a custom function that injects + * the "isTrusted" flag. + * + * Is this cheating? Or is it real hacking? Don't care, as long + * as it's working :) + */ +function wrapEventListeners() { + if (!doc._addEventListener) { + doc._addEventListener = doc.addEventListener; + + doc.addEventListener = function (type, callback, options) { + if ("undefined" === typeof options) { + options = false; + } + let handler = false; + + // For this script, we only want to modify "keydown" events. + if ("keydown" === type) { + handler = function (...args) { + if (!args[0].isTrusted) { + const hackedEv = {}; + + for (const key in args[0]) { + if ("isTrusted" === key) { + hackedEv.isTrusted = true; + } else if ("function" === typeof args[0][key]) { + hackedEv[key] = args[0][key].bind(args[0]); + } else { + hackedEv[key] = args[0][key]; + } + } + + args[0] = hackedEv; + } + + return callback.apply(callback, args); + }; + + for (const prop in callback) { + if ("function" === typeof callback[prop]) { + handler[prop] = callback[prop].bind(callback); + } else { + handler[prop] = callback[prop]; + } + } + } + + if (!this.eventListeners) { + this.eventListeners = {}; + } + if (!this.eventListeners[type]) { + this.eventListeners[type] = []; + } + this.eventListeners[type].push({ + listener: callback, + useCapture: options, + wrapped: handler, + }); + + return this._addEventListener( + type, + handler ? handler : callback, + options + ); + }; + } + + if (!doc._removeEventListener) { + doc._removeEventListener = doc.removeEventListener; + + doc.removeEventListener = function (type, callback, options) { + if ("undefined" === typeof options) { + options = false; + } + + if (!this.eventListeners) { + this.eventListeners = {}; + } + if (!this.eventListeners[type]) { + this.eventListeners[type] = []; + } + + for (let i = 0; i < this.eventListeners[type].length; i++) { + if ( + this.eventListeners[type][i].listener === callback && + this.eventListeners[type][i].useCapture === options + ) { + if (this.eventListeners[type][i].wrapped) { + callback = this.eventListeners[type][i].wrapped; + } + + this.eventListeners[type].splice(i, 1); + break; + } + } + + if (this.eventListeners[type].length == 0) { + delete this.eventListeners[type]; + } + + return this._removeEventListener(type, callback, options); + }; + } +} + +/** + * Revert the "wrapEventListeners" changes. + */ +function unwrapEventListeners() { + if (doc._addEventListener) { + doc.addEventListener = doc._addEventListener; + delete doc._addEventListener; + } + if (doc._removeEventListener) { + doc.removeEventListener = doc._removeEventListener; + delete doc._removeEventListener; + } + delete doc.eventListeners; +} diff --git a/misc/delete.js b/misc/delete.js new file mode 100644 index 0000000..0ba3232 --- /dev/null +++ b/misc/delete.js @@ -0,0 +1,11 @@ +/** @param {NS} ns */ +export async function main(ns) { + let serv = ns.args[0]; + if (!(serv === undefined)) { + ns.deleteServer(serv); + } else { + ns.tprint("Server does not exist"); + } +} + +// Take argument for which server name to delete \ No newline at end of file diff --git a/misc/install.js b/misc/install.js new file mode 100644 index 0000000..ecbe449 --- /dev/null +++ b/misc/install.js @@ -0,0 +1,4 @@ +/** @param {NS} ns */ +export async function main(ns) { + ns.singularity.installAugmentations("start.js"); +} \ No newline at end of file diff --git a/misc/monitor.js b/misc/monitor.js new file mode 100644 index 0000000..50cf4a4 --- /dev/null +++ b/misc/monitor.js @@ -0,0 +1,63 @@ +import { setOfObjects } from "/batch/batcher.js" + +// Monitors the specified server, process, or the player's cash +// [Server] monitors the server's security level and available cash +// "money" or "cash" does nothing :3 +// "batcher" displays the maximum cash for the servers found in Arr, rounded to multiples of 1 billion + + +/** @param {NS} ns */ +export async function main(ns) { + ns.tail(); + + ns.disableLog("ALL"); + + const target = ns.args[0]; + + if (target === undefined) { + ns.print("No target specified\nExiting..."); + ns.exit(); + } + + if (target == "deltaone") { + + // let server = ns.getServer(); + while (true) { + ns.clearLog(); + + ns.print("Security: ", Math.round(ns.getServerSecurityLevel(target)), " / ", ns.getServerMinSecurityLevel(target)); + ns.print("Money: ", Math.round(ns.getServerMoneyAvailable(target)), " / ", Math.round(ns.getServerMaxMoney(target))); + await ns.sleep(500); + } + } else if (target == "money" || target == "cash") { + let last = ns.getPlayer().money; + await ns.sleep(1000); + let total = ns.getPlayer().money; + while (true) { + ns.clearLog(); + + await ns.sleep(1000); + } + } else if (target == "batcher") { + while (true) { + ns.clearLog(); + let arr = [ + 'zb-institute', + 'galactic-cyber', + 'aerocorp', + 'omnia', + 'deltaone', + 'taiyang-digital', + 'icarus', + 'zeus-med', + 'infocomm', + 'solaris', + 'defcomm' + ]; + for (let i = 0; i < arr.length; i++) { + ns.print(arr[i], ": ", (ns.getServerMaxMoney(arr[i]) / 1e9).toFixed(3)); + } + await ns.sleep(1000); + } + } +} \ No newline at end of file diff --git a/misc/route.js b/misc/route.js new file mode 100644 index 0000000..97d814a --- /dev/null +++ b/misc/route.js @@ -0,0 +1,57 @@ +const HOME = "home"; +let target; +export async function main(ns) { + let result = []; + let route = []; + let seen = []; + target = ns.args[0]; // The target server + let backdoor = ns.args[1]; // True for connecting to the server and backdooring + if (target === undefined) { + ns.tprint("No target server specified"); + ns.exit(); + } + if (buildRoute(ns, HOME, route, seen)) { + result = await printRoute(ns, route); + } +} +function buildRoute(ns, parent, 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 add it to the route and finish recursion + route.push(child); + return true; + } + if (buildRoute(ns, child, 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); + } + result.push('backdoor'); + // await navigator.clipboard.writeText(result); + ns.tprint(result); + return result; +} \ No newline at end of file diff --git a/misc/run.js b/misc/run.js new file mode 100644 index 0000000..31c70cd --- /dev/null +++ b/misc/run.js @@ -0,0 +1,12 @@ +/** @param {NS} ns */ +export async function main(ns) { + const target = ns.args[0]; + const script = ns.args[1]; + const scriptRam = ns.getScriptRam(script); + ns.exec(script, "home", threads(ns, scriptRam), target); + await ns.sleep(4000); +} + +function threads(ns, scriptRam) { + return Math.floor(((ns.getServerMaxRam("home") - ns.getServerUsedRam("home")) * 0.95) / scriptRam); +} \ No newline at end of file diff --git a/misc/servers.txt b/misc/servers.txt new file mode 100644 index 0000000..9c25673 --- /dev/null +++ b/misc/servers.txt @@ -0,0 +1,97 @@ +home +n00dles +foodnstuff +sigma-cosmetics +joesguns +hong-fang-tea +harakiri-sushi +iron-gym +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 +pserv-24 +darkweb +CSEC +nectar-net +max-hardware +zer0 +neo-net +phantasy +silver-helix +omega-net +netlink +johnson-ortho +crush-fitness +the-hub +computek +avmnite-02h +syscore +catalyst +zb-institute +I.I.I.I +summit-uni +rothman-uni +lexo-corp +aevum-police +rho-construction +alpha-ent +millenium-fitness +global-pharm +snap-fitness +galactic-cyber +aerocorp +omnia +deltaone +unitalife +defcomm +solaris +zeus-med +icarus +univ-energy +infocomm +taiyang-digital +nova-med +zb-def +titan-labs +run4theh111z +applied-energetics +microdyne +fulcrumtech +stormtech +helios +vitalife +. +omnitek +kuai-gong +4sigma +b-and-a +nwo +blade +clarkinc +powerhouse-fitness +ecorp +megacorp +fulcrumassets +The-Cave +w0r1d_d43m0n diff --git a/misc/target.js b/misc/target.js new file mode 100644 index 0000000..c2872a2 --- /dev/null +++ b/misc/target.js @@ -0,0 +1,178 @@ +/** @param {NS} ns */ +export async function main(ns) { + let target = "home"; + let thread = 1; + const scriptRam = 2.4; + + // 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" + ]; + + + // 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" + ]; + + // 4 port serves + 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 + + for (let i = 0; i < servers0Port.length; ++i) { + const serv = servers0Port[i]; + if (ns.getServerMaxMoney(serv) > ns.getServerMaxMoney(target)) { + target = serv; + } + } + ns.print("Weak target acquired"); + ns.write("targets.txt", "Weak target: " + target, "w"); + + + for (let i = 0; i < servers1Port.length; ++i) { + const serv = servers1Port[i]; + if (ns.getServerMaxMoney(serv) > ns.getServerMaxMoney(target)) { + target = serv; + } + } + ns.print("SSH target acquired"); + ns.write("targets.txt", "\nSSH target: " + target, "a"); + + + for (let i = 0; i < servers2Port.length; ++i) { + const serv = servers2Port[i]; + if (ns.getServerMaxMoney(serv) > ns.getServerMaxMoney(target)) { + target = serv; + } + } + ns.print("FTP target acquired"); + ns.write("targets.txt", "\nFTP target: " + target, "a"); + + + for (let i = 0; i < servers3Port.length; ++i) { + const serv = servers3Port[i]; + if (ns.getServerMaxMoney(serv) > ns.getServerMaxMoney(target)) { + target = serv; + } + } + ns.print("SMTP target acquired"); + ns.write("targets.txt", "\nSMTP target: " + target, "a"); + + + for (let i = 0; i < servers4Port.length; ++i) { + const serv = servers4Port[i]; + + if (ns.getServerMaxMoney(serv) > ns.getServerMaxMoney(target)) { + target = serv; + } + } + ns.print("HTTP target acquired"); + ns.write("targets.txt", "\nHTTP target: " + target, "a"); + + + for (let i = 0; i < servers5Port.length; ++i) { + const serv = servers5Port[i]; + + if (ns.getServerMaxMoney(serv) > ns.getServerMaxMoney(target)) { + target = serv; + } + } + ns.print("SQL target acquired"); + ns.write("targets.txt", "\nSQL target: " + target, "a"); + + + ns.tprint("targets found. Ending process."); + ns.exit(); +} \ No newline at end of file diff --git a/misc/targets.js b/misc/targets.js new file mode 100644 index 0000000..9dc9c02 --- /dev/null +++ b/misc/targets.js @@ -0,0 +1,45 @@ +/** @param {NS} ns */ +export async function main(ns) { + ns.clear("moneyServers.txt"); + const servers = netscan(ns); + for (let i = 0; i < servers.length; i++) { + if (ns.getServer(servers[i]).moneyMax > 0) { + ns.write("moneyServers.txt", servers[i], "a"); + ns.write("moneyServers.txt", "\n", "a"); + } + } + +} + +/** @param {NS} ns */ +function netscan(ns) { + //Initialize the set and seed it with the a host so that the next line + //has something to work with. + let hosts = new Set(["home"]); + + //Sets have the useful property that when elements are added to them in + //their own forEach loop, they will iterate over those new elements as + //well. Be careful about this with other data structures and languages! + //It is somewhat uncommon for data structures to tolerate manipulation + //during iteration. + //Anyway, because of this, we can add new neighbors to the set as we + //find them, and they will be scanned as well. + //We also don't have to check if the set already contains the host, + //because sets are sets of unique elements. The underlying structure of + //a set typically makes it impossible to add duplicate elements at all. + hosts.forEach(h => { ns.scan(h).forEach(n => hosts.add(n)); }); + + //Sets are irritating to work with in list contexts, because concepts + //like sorting are inapplicable to them (e.g. you might want to sort + //these servers by difficulty). So we convert it back to a list. + //If you look at the printed output, you might notice that the order + //appears to be similar to the order in which the servers were scanned. + //Do not rely on this behavior! It is purely a side effect of the + //implementation of the set. A set has no concept of "order" and a + //change in its implementation (or a new compiler optimization) could + //produce a different order. + //Of course, you might ask how it is the above "forEach" loop works if + //the set has no order. The answer is... uh oh, something is wrong with + //the b1^n&de... do you feel it? Run... save yourself... + return Array.from(hosts); +} \ No newline at end of file diff --git a/misc/targets.txt b/misc/targets.txt new file mode 100644 index 0000000..2898eb9 --- /dev/null +++ b/misc/targets.txt @@ -0,0 +1,6 @@ +Weak target: harakiri-sushi +SSH target: iron-gym +FTP target: the-hub +SMTP target: rho-construction +HTTP target: global-pharm +SQL target: deltaone \ No newline at end of file diff --git a/misc/test.js b/misc/test.js new file mode 100644 index 0000000..c9483b6 --- /dev/null +++ b/misc/test.js @@ -0,0 +1,4 @@ +/** @param {NS} ns */ +export async function main(ns) { + ns.singularity.upgradeHomeRam(); +} \ No newline at end of file diff --git a/misc/threads.js b/misc/threads.js new file mode 100644 index 0000000..51729fe --- /dev/null +++ b/misc/threads.js @@ -0,0 +1,13 @@ +/** @param {NS} ns */ +export async function main(ns) { + //const call = ns.args[0]; + const call = "hack"; + const server = ns.args[0]; + // if (ns.args[0] === undefined || ns.args[1] === undefined || ns.args[0] == "help") { + // ns.tprint("1st arg is the call type; ie. hack, weaken, or grow\n2nd arg is the server name"); + // } + + if (call == "hack") { + ns.tprint(ns.hackAnalyzeThreads(server, ns.getServerMoneyAvailable(server))); + } +} \ No newline at end of file -- cgit v1.2.3