Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------
- cron.js
- ---------
- /** @param {NS} ns */
- export async function main(ns) {
- while (true) {
- // Runs a recursive scan of the whole network
- ns.run("h4xc4n.js", { threads: 1, preventDuplicates: true });
- await ns.sleep(5000);
- // Buys and upgrades servers
- ns.run("upgradeServers.js", { threads: 1, preventDuplicates: true });
- await ns.sleep(1000);
- // Kills ramsharing on keks
- ns.run("kekmultikill.js", 1, "1", "24", "share.js", "silent");
- // Runs a script on HOME that spawns scripts on target hacking itself
- ns.run("invexec.js", { threads: 1, preventDuplicates: true }, "--silent", "--script", "/hackself.js", "--ram", "--args", "++host", "<host>");
- // Runs a singular hackex on keks targeting the "rich" inventory - 1 kek per host
- //ns.run("invexec.js", { threads: 1, preventDuplicates: true }, "--silent", "--script", "/kekhack.js", "--reverse", "--richOnly", "--args", "<i>", "<i>", "<host>", "silent");
- // Runs many hackexes on keks targeting the "rich" inventory - 1 kek per host
- ns.run("invexec.js", { threads: 1, preventDuplicates: true }, "--silent", "--script", "/multikekhack.js", "--reverse", "--richOnly", "--args", "<i>", "<i>", "<host>", "silent");
- // Runs ramsharing on proxycontrol
- ns.run("proxyshare.js", { threads: 1, preventDuplicates: true }, "proxycontrol");
- // Runs omegagrow from idle keks on the rich inventory
- await ns.sleep(1000);
- ns.run("invexec.js", { threads: 1, preventDuplicates: true }, "--silent", "--script", "/omegagrow.js", "--await", "--richOnly", "--args", "1", "24", "<host>");
- // Runs ramsharing on keks
- ns.run("kekshare.js", 1, "3", "24", "silent");
- // Runs hackex on home targeting everything but "useless", with allocated ram (allocating doesnt really work lol)
- ns.run("invexec.js", { threads: 1, preventDuplicates: true }, "--silent", "--script", "/hackex.js", "--args", "++host", "<host>", "++allocateRam", "8192", "++leaveRam", "10240");
- // Runs many hackexes on home targeting "richest" inventory
- ns.run("invexec.js", { threads: 1, preventDuplicates: true }, "--silent", "--richest", "--script", "/spawnhackex.js", "--args", "/hackex.js", 0.4, 2000, "<host>", "silent");
- //ns.tprint("##################");
- ns.tprint(ns.tFormat(Date.now() - ns.getResetInfo().lastAugReset).split(" ").splice(0,4).join(" ")," --- #!# cron was ran #!#");
- //ns.tprint("##################");
- // Wait for 10 min
- await ns.sleep(1000 * 60 * 10);
- }
- }
- ------------
- invexec.js
- ------------
- /** @param {NS} ns */
- export async function main(ns) {
- var active = []
- var inventory = [
- "n00dles",
- "foodnstuff",
- "sigma-cosmetics",
- "joesguns",
- "hong-fang-tea",
- "harakiri-sushi",
- "iron-gym",
- "max-hardware",
- "silver-helix",
- "neo-net",
- "zer0",
- "omega-net",
- "phantasy",
- "nectar-net",
- "crush-fitness", // 0 ram
- "the-hub",
- "johnson-ortho", // 0 ram
- "netlink",
- "computek", // 0 ram
- "catalyst",
- "summit-uni",
- "rothman-uni",
- "aevum-police",
- "millenium-fitness",
- "alpha-ent",
- "rho-construction",
- "syscore", // 0 ram
- "snap-fitness", // 0 ram
- "lexo-corp",
- "zb-institute",
- "global-pharm",
- "unitalife",
- "zb-def", // 0 ram
- "applied-energetics", // 0 ram
- "zeus-med", // 0 ram
- "titan-labs",
- "microdyne",
- "nova-med", // 0 ram
- "vitalife",
- "solaris",
- "deltaone", // 0 ram
- "omnia",
- "icarus", // 0 ram
- "univ-energy",
- "helios",
- "galactic-cyber", // 0 ram
- "aerocorp", // 0 ram
- "taiyang-digital", // 0 ram
- "infocomm", // 0 ram
- "kuai-gong", // 0 ram
- "b-and-a", // 0 ram
- "fulcrumtech",
- "omnitek",
- "stormtech", // 0 ram
- "nwo", // 0 ram
- "ecorp", // 0 ram
- "clarkinc", // 0 ram
- "blade",
- "powerhouse-fitness",
- "4sigma", // 0 ram
- "defcomm", // 0 ram
- "megacorp", // 0 ram
- ];
- active = [];
- for (const invEntry of inventory) {
- if (ns.fileExists("/inventory/root." + invEntry + ".txt")) {
- active.push(invEntry);
- }
- }
- inventory = active;
- var inventoryRam = [
- "n00dles",
- "foodnstuff",
- "sigma-cosmetics",
- "joesguns",
- "hong-fang-tea",
- "harakiri-sushi",
- "iron-gym",
- "max-hardware",
- "silver-helix",
- "neo-net",
- "zer0",
- "omega-net",
- "phantasy",
- "nectar-net",
- "the-hub",
- "netlink",
- "catalyst",
- "aevum-police",
- "rothman-uni",
- "summit-uni",
- "millenium-fitness",
- "alpha-ent",
- "rho-construction",
- "lexo-corp",
- "zb-institute",
- "global-pharm",
- "unitalife",
- "titan-labs",
- "microdyne",
- "vitalife",
- "solaris",
- "omnia",
- "univ-energy",
- "helios",
- "fulcrumtech",
- "omnitek",
- "blade",
- "powerhouse-fitness",
- ];
- active = [];
- for (const invEntry of inventoryRam) {
- if (ns.fileExists("/inventory/root." + invEntry + ".txt")) {
- active.push(invEntry);
- }
- }
- inventoryRam = active;
- var inventoryNoRam = [
- "crush-fitness", // 0 ram
- "johnson-ortho", // 0 ram
- "computek", // 0 ram
- "syscore", // 0 ram
- "snap-fitness", // 0 ram
- "zb-def", // 0 ram
- "applied-energetics", // 0 ram
- "zeus-med", // 0 ram
- "nova-med", // 0 ram
- "deltaone", // 0 ram
- "icarus", // 0 ram
- "galactic-cyber", // 0 ram
- "aerocorp", // 0 ram
- "taiyang-digital", // 0 ram
- "infocomm", // 0 ram
- "kuai-gong", // 0 ram
- "b-and-a", // 0 ram
- "stormtech", // 0 ram
- "nwo", // 0 ram
- "ecorp", // 0 ram
- "clarkinc", // 0 ram
- "4sigma", // 0 ram
- "defcomm", // 0 ram
- "megacorp", // 0 ram
- ];
- active = [];
- for (const invEntry of inventoryNoRam) {
- if (ns.fileExists("/inventory/root." + invEntry + ".txt")) {
- active.push(invEntry);
- }
- }
- inventoryNoRam = active;
- var inventoryRich = [
- //"the-hub",
- //"netlink",
- //"computek", // 0 ram
- //"catalyst",
- //"summit-uni",
- //"rothman-uni",
- //"millenium-fitness",
- //"alpha-ent",
- //"rho-construction",
- //"syscore", // 0 ram
- //"snap-fitness", // 0 ram
- //"lexo-corp",
- //"titan-labs",
- //"microdyne",
- //"vitalife",
- //"omnia",
- //"helios",
- //"aerocorp", // 0 ram
- //"infocomm", // 0 ram
- //"stormtech", // 0 ram
- //"powerhouse-fitness",
- //"solaris",
- //"deltaone", // 0 ram
- "zb-institute",
- "global-pharm",
- "unitalife",
- "zb-def", // 0 ram
- "applied-energetics", // 0 ram
- "zeus-med", // 0 ram
- "nova-med", // 0 ram
- "icarus", // 0 ram
- "univ-energy",
- "galactic-cyber", // 0 ram
- "taiyang-digital", // 0 ram
- "kuai-gong", // 0 ram
- "b-and-a", // 0 ram
- "fulcrumtech",
- "omnitek",
- "nwo", // 0 ram
- "ecorp", // 0 ram
- "clarkinc", // 0 ram
- "blade",
- "4sigma", // 0 ram
- "megacorp",
- ];
- active = [];
- for (const invEntry of inventoryRich) {
- if (ns.fileExists("/inventory/root." + invEntry + ".txt")) {
- active.push(invEntry);
- }
- }
- inventoryRich = active;
- if (inventoryRich.length > 22) {
- ns.tprint("WARNING, too many servers in 'rich' inventory to keep omegagrow running");
- }
- if (inventoryRich.length > 24) {
- ns.tprint("ERROR, more servers in 'rich' inventory than keks");
- }
- var inventoryRichest = [
- "kuai-gong",
- "b-and-a",
- "omnitek",
- //"nwo", // 0 ram
- "ecorp", // 0 ram
- "clarkinc", // 0 ram
- //"blade",
- "4sigma", // 0 ram
- "megacorp",
- ];
- active = [];
- for (const invEntry of inventoryRichest) {
- if (ns.fileExists("/inventory/root." + invEntry + ".txt")) {
- active.push(invEntry);
- }
- }
- inventoryRichest = active;
- var inventoryUseless = [
- "avmnite-02h",
- "I.I.I.I",
- "CSEC",
- "run4theh111z",
- ".",
- "The-Cave", // 0 ram
- "fulcrumassets",
- ];
- active = [];
- for (const invEntry of inventoryUseless) {
- if (ns.fileExists("/inventory/root." + invEntry + ".txt")) {
- active.push(invEntry);
- }
- }
- inventoryUseless = active;
- const dat = ns.flags([
- ["ram", false],
- ["noRam", false],
- ["richOnly", false],
- ["richest", false],
- ["useless", false],
- ["silent", false],
- ["script", ""],
- ["threads", 1],
- ["forceDupes", false],
- ["check", false],
- ["await", false],
- ["reverse", false],
- ["24invOnly", false],
- ["kekLimiter", 24],
- ["args", false],
- ]);
- if (dat['ram'] && !dat['noRam']) {
- inventory = inventoryRam;
- }
- if (!dat['ram'] && dat['noRam']) {
- inventory = inventoryNoRam;
- }
- if (dat['richOnly']) {
- inventory = inventory.filter(value => inventoryRich.includes(value));
- }
- if (dat['richest']) {
- inventory = inventoryRichest;
- }
- if (dat['useless']) {
- inventory = inventory.concat(inventoryUseless);
- }
- if (dat['args']) {
- var arg = ns.args.slice(ns.args.indexOf("--args") + 1);
- for (const i in inventory) {
- if (i > 24 && dat['24invOnly']) { break; }
- arg = ns.args.slice(ns.args.indexOf("--args") + 1);
- for (const x in arg) {
- if (typeof arg[x] == "string") {
- arg[x] = arg[x].replaceAll('+', '-');
- arg[x] = arg[x].replaceAll('<host>', inventory[i]);
- if (dat['reverse']) {
- arg[x] = arg[x].replaceAll('<i>', dat['kekLimiter'] - i);
- } else {
- const limitedI = parseInt(i) + 25 - dat['kekLimiter'];
- arg[x] = arg[x].replaceAll('<i>', limitedI.toString());
- }
- }
- }
- if (!dat['silent']) {
- ns.tprint(inventory[i], " - ", dat['threads'], " thread(s) - ", dat['script'], " ", arg);
- }
- if (!dat['check']) {
- ns.run(dat['script'], { threads: dat['threads'], preventDuplicates: !dat['forceDupes'] }, ...arg);
- if (dat['await']) {
- while (ns.scriptRunning(dat['script'], ns.getHostname())) {
- await ns.sleep(10000);
- }
- }
- }
- }
- } else {
- ns.tprint("###########");
- ns.tprint("You forgor the '--args' flag, it needs to be the last flag and args after it with + instead of - i.e. '++force'");
- return 1
- }
- if (!dat['silent'] && dat['await']) {
- ns.tprint("##################");
- ns.tprint("## invExec done ##");
- ns.tprint("##################");
- }
- return 0
- }
- ---------
- spawnhackex.js
- ---------
- /** @param {NS} ns */
- export async function main(ns) {
- const script = ns.args[0];
- const target = ns.args[3];
- const ramFraction = ns.args[1];
- const delay = ns.args[2];
- const me = ns.getHostname();
- var maxRam = ns.getServerMaxRam(me);
- if (typeof ns.args[4] == "undefined" || ns.args[4] != "silent") {
- ns.tprint("Multi-", script + " '" + me + "' targeting: '" + target + "'");
- }
- var ramRemaining = maxRam - ns.getServerUsedRam(me);
- var spawned = 0;
- var inrow = 0;
- while (inrow < 3600000 / delay) {
- inrow += 1;
- if (ramRemaining / maxRam > ramFraction) {
- if (typeof ns.args[5] == "undefined") {
- ns.run(script, { threads: 1, preventDuplicates: false }, "--host", target);
- } else {
- ns.run(script, { threads: 1, preventDuplicates: false }, "--host", target, "--hackLimiter", ns.args[5]);
- }
- spawned += 1;
- inrow = 0;
- }
- await ns.asleep(delay);
- maxRam = ns.getServerMaxRam(me);
- ramRemaining = maxRam - ns.getServerUsedRam(me);
- }
- if (spawned > 10) {
- ns.tprint("multi-", script + " '" + me + "' targeting: '" + target + "' has SPAWNED: ", spawned);
- }
- }
- -----------
- hackex.js
- -----------
- /** @param {NS} ns */
- export async function main(ns) {
- const selfver = ns.getHostname();
- const dat = ns.flags([
- ['host', ""],
- ['moneyDiff', 500000.0],
- ['securityDiff', 0.200],
- ['hackScript', "/hack.js"],
- ['growScript', "/grow.js"],
- ['weakScript', "/weak.js"],
- ['hackDivider', 2],
- ['leaveRam', 0],
- ['allocateRam', 999999999],
- ]);
- if (ns.getHostname() !== "home") {
- const scriptuples = [[dat['hackScript'], "/hack.js"], [dat['growScript'], "/grow.js"], [dat['weakScript'], "/weak.js"]];
- for (const script in scriptuples) {
- ns.mv(selfver, scriptuples[script][0], scriptuples[script][1]);
- }
- }
- const hackRam = ns.getScriptRam("/hack.js");
- const growRam = ns.getScriptRam("/grow.js");
- const weakRam = ns.getScriptRam("/weak.js");
- const securityMin = ns.getServerMinSecurityLevel(dat['host']);
- const moneyMax = ns.getServerMaxMoney(dat['host']);
- const myRam = ns.getScriptRam(ns.getScriptName())
- var maxRam = ns.getServerMaxRam(selfver) - myRam - dat['leaveRam'];
- var secFlag = false;
- var freeRam = Math.min(maxRam - ns.getServerUsedRam(selfver), dat['allocateRam']);
- var runWhat = "";
- var securityCur = 0.0;
- var moneyCur = 0.0;
- var maxThreads = Math.floor(ns.hackAnalyzeThreads(dat['host'], moneyMax / dat['hackDivider']));
- var runThreads = 0;
- var runWait = 0;
- var weakEff = 0.0;
- while (true) {
- securityCur = ns.getServerSecurityLevel(dat['host']);
- moneyCur = ns.getServerMoneyAvailable(dat['host']);
- weakEff = ns.weakenAnalyze(1);
- //hackThreadsRunning =
- switch (true) {
- case (secFlag):
- secFlag = false;
- runWhat = "weak";
- maxThreads = Math.floor(freeRam / weakRam);
- runThreads = Math.ceil((securityCur - securityMin) / weakEff);
- if (Math.max(runThreads, maxThreads) > 0) {
- runWait = Math.max(ns.getWeakenTime(dat['host']), ns.getGrowTime(dat['host'])) + 20;
- } else {
- runWait = ns.getGrowTime(dat['host']) + 20;
- }
- break;
- case (securityCur - securityMin) > dat['securityDiff'] && (moneyMax - moneyCur) > dat['moneyDiff']:
- secFlag = true;
- runWhat = "grow";
- maxThreads = Math.floor(Math.min(maxRam / growRam, (maxRam / weakRam) * 2 - ((securityCur - securityMin) / weakEff)));
- if (ns.fileExists("Formulas.exe", "home")) {
- runThreads = ns.formulas.hacking.growThreads(ns.getServer(dat['host']), ns.getPlayer(), moneyMax);
- } else {
- runThreads = Math.floor((moneyMax - moneyCur) / dat['moneyDiff']);
- }
- runWait = 1;
- break;
- case (securityCur - securityMin) > dat['securityDiff']:
- runWhat = "weak";
- maxThreads = Math.floor(maxRam / weakRam);
- runThreads = Math.ceil((securityCur - securityMin) / weakEff);
- runWait = ns.getWeakenTime(dat['host']) + 20;
- break;
- case (moneyMax - moneyCur) > dat['moneyDiff']:
- runWhat = "grow";
- maxThreads = Math.floor(maxRam / growRam);
- if (ns.fileExists("Formulas.exe", "home")) {
- runThreads = ns.formulas.hacking.growThreads(ns.getServer(dat['host']), ns.getPlayer(), moneyMax);
- } else {
- runThreads = Math.floor((moneyMax - moneyCur) / dat['moneyDiff']);
- } runWait = ns.getGrowTime(dat['host']) + 20;
- break;
- default:
- runWhat = "hack";
- runWait = ns.getHackTime(dat['host']) + 20;
- break;
- }
- //if (runWhat != "hack" || Math.floor(freeRam / hackRam) > 0) {
- if (runWhat != "hack") {
- /** Oh boy, here i go killing again */
- ns.scriptKill("/hack.js", selfver);
- maxRam = ns.getServerMaxRam(selfver) - myRam - dat['leaveRam'];
- freeRam = Math.min(maxRam - ns.getServerUsedRam(selfver), dat['allocateRam']);
- }
- ns.print(runWhat, " Needed:", runThreads, " Available:", maxThreads);
- /** The exec loop */
- while (runWhat != "wait") {
- if (runWhat == "hack") {
- runThreads = Math.floor(freeRam / hackRam);
- maxThreads = ns.hackAnalyzeThreads(dat['host'], moneyMax / dat['hackDivider']);
- }
- runWhat = "/" + runWhat + ".js";
- runThreads = Math.floor(Math.min(runThreads, maxThreads));
- //ns.print(runWhat, dat['host'], " - " , runThreads);
- if (runThreads > 0) {
- ns.run(runWhat, { threads: runThreads, preventDuplicates: false }, dat['host']);
- }
- if (secFlag == false) {
- if (!runWhat.includes("hack")) {
- runWhat = "hack";
- } else {
- runWhat = "wait";
- }
- } else {
- runWhat = "wait";
- }
- maxRam = ns.getServerMaxRam(selfver) - myRam - dat['leaveRam'];
- freeRam = Math.min(maxRam - ns.getServerUsedRam(selfver), dat['allocateRam']);
- }
- await ns.sleep(runWait);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment