all: refactor. main.js: fix call to `void_kill_script_named_server_named`.
[?]
Apr 27, 2020, 7:11 PM
HSNSECD5D3ACWDKZNIEV7RZZ54IE5K33WS3DR37ABHM5QP5JJPIACDependencies
- [2]
DJDWBCCQadd missing "nop.js". killall.js: rename to kill.js. add `--script` and `--server` options. - [3]
Y5OWMCQRall: remove unecessary uses of `exec`. refactor. main.js: add RAM reservation logic. lib_ram.js: renamed to lib_ram_server.js. README.js: update. - [4]
3NFCZ6IPfixed the ram utilisation logic. added flags to `main.js` that can prevent the execution of helpers. - [5]
44JNP7VZfix schedule making and running logic. - [6]
V4DMWF25remove redundant preparation steps in "hacker.js". - [7]
AXGQ7FMLsplit and refactor hacking logic to "hacker.js" and argument parsing and script execution logic to "main.js". update "README.md". - [8]
VMXI7PS4added action cap. improved scoring system. fixed parts of security and cash predictors. made lshw loopable. - [9]
EYKBOK3Ooptimised the scheduling logic by ensuring that cycles start and finish at minimum security of target. - [10]
NQ22FUSWadd more options to `main.js`. update `README.md`. - [11]
2BKHJI2Sinit - [12]
SLSWBNYTadded ram utilisation logic to `ram.js` and `servers.js`. split and refactored redundant code into separate library files. - [13]
7SRULDRFminor refactoring.
Change contents
- replacement in sbin/tor.js at line 2
export const main = async function(ns) {const float_period_check = ns.args[0] * 1000;while (true) {if (ns.scan("home").includes("darkweb")) {break;}export const main = async function (ns) {const float_period_check = 1e3 * ns.args[0];for (; !ns.scan("home").includes("darkweb"); ) { - replacement in sbin/servers.js at line 34
const object_get_constants = function(ns) {const object_constants = {const object_get_constants = function () {return object_constants = { - edit in sbin/servers.js at line 45
return object_constants; - replacement in sbin/servers.js at line 48
const boolean_servers_bought_all_max = function(ns) {const boolean_servers_bought_all_max = function (ns) { - replacement in sbin/servers.js at line 51
let boolean_tripwire = true;for (let integer_indices_0 = 0; integer_indices_0 < array_servers_bought.length; ++integer_indices_0) {if (float_get_server_ram_total(ns, array_servers_bought[integer_indices_0]) < object_get_constants(ns).PurchasedServerMaxRam) {boolean_tripwire = false;}}let boolean_tripwire = !0;for (let integer_indices_0 = 0;integer_indices_0 < array_servers_bought.length;++integer_indices_0)float_get_server_ram_total(ns, array_servers_bought[integer_indices_0]) <object_get_constants().PurchasedServerMaxRam && (boolean_tripwire = !1); - replacement in sbin/servers.js at line 64
const string_get_server_bought_smallest = function(ns) {const string_get_server_bought_smallest = function (ns) { - replacement in sbin/servers.js at line 67
let string_server_smallest;let integer_size_smallest = object_get_constants(ns).PurchasedServerMaxRam;for (let integer_indices_0 = 0; integer_indices_0 < array_servers_bought.length; ++integer_indices_0) {let integer_server_ram_total = float_get_server_ram_total(ns, array_servers_bought[integer_indices_0]);if (integer_server_ram_total < integer_size_smallest) {string_server_smallest = array_servers_bought[integer_indices_0];integer_size_smallest = integer_server_ram_total;}let string_server_smallest,integer_size_smallest = object_get_constants().PurchasedServerMaxRam;for (let integer_indices_0 = 0;integer_indices_0 < array_servers_bought.length;++integer_indices_0) {let integer_server_ram_total = float_get_server_ram_total(ns,array_servers_bought[integer_indices_0]);integer_server_ram_total < integer_size_smallest &&((string_server_smallest = array_servers_bought[integer_indices_0]),(integer_size_smallest = integer_server_ram_total)); - replacement in sbin/servers.js at line 87
const string_get_server_bought_biggest = function(ns) {const string_get_server_bought_biggest = function (ns) { - replacement in sbin/servers.js at line 90
let string_server_biggest;let integer_size_biggest = object_get_constants(ns).integer_server_ram_min;for (let integer_indices_0 = 0; integer_indices_0 < array_servers_bought.length; ++integer_indices_0) {let integer_server_ram_total = float_get_server_ram_total(ns, array_servers_bought[integer_indices_0]);if (integer_server_ram_total > integer_size_biggest) {string_server_biggest = array_servers_bought[integer_indices_0];integer_size_biggest = integer_server_ram_total;}let string_server_biggest,integer_size_biggest = object_get_constants().integer_server_ram_min;for (let integer_indices_0 = 0;integer_indices_0 < array_servers_bought.length;++integer_indices_0) {let integer_server_ram_total = float_get_server_ram_total(ns,array_servers_bought[integer_indices_0]);integer_server_ram_total > integer_size_biggest &&((string_server_biggest = array_servers_bought[integer_indices_0]),(integer_size_biggest = integer_server_ram_total)); - replacement in sbin/servers.js at line 105
return string_server_biggest;return string_server_biggest; - replacement in sbin/servers.js at line 110
const integer_get_server_ram_biggest_afforded = function(ns) {const object_constants = object_get_constants(ns);let integer_server_ram_biggest_afforded = Math.pow(2, Math.trunc(Math.log2(ns.getServerMoneyAvailable("home") / object_constants.BaseCostFor1GBOfRamServer) / Math.log2(2)));if (integer_server_ram_biggest_afforded > object_constants.PurchasedServerMaxRam) {integer_server_ram_biggest_afforded = object_constants.PurchasedServerMaxRam;}return integer_server_ram_biggest_afforded;const integer_get_server_ram_biggest_afforded = function (ns) {const object_constants = object_get_constants();let integer_server_ram_biggest_afforded = Math.pow(2,Math.trunc(Math.log2(ns.getServerMoneyAvailable("home") /object_constants.BaseCostFor1GBOfRamServer) / Math.log2(2)));return (integer_server_ram_biggest_afforded >object_constants.PurchasedServerMaxRam &&(integer_server_ram_biggest_afforded =object_constants.PurchasedServerMaxRam),integer_server_ram_biggest_afforded); - replacement in sbin/servers.js at line 130
const boolean_conditions_server_purchase_1 = function(ns) {const integer_server_ram_biggest_afforded = integer_get_server_ram_biggest_afforded(ns);const object_constants = object_get_constants(ns);if (// you have no bought servers yet(ns.getPurchasedServers().length === 0) &&const boolean_conditions_server_purchase_1 = function (ns) {const integer_server_ram_biggest_afforded = integer_get_server_ram_biggest_afforded(ns),object_constants = object_get_constants();if (// you have no bought servers yet0 === ns.getPurchasedServers().length && - replacement in sbin/servers.js at line 139
(integer_server_ram_biggest_afforded >= object_constants.integer_server_ram_min) &&integer_server_ram_biggest_afforded >=object_constants.integer_server_ram_min && - replacement in sbin/servers.js at line 142
(integer_server_ram_biggest_afforded >= float_get_server_ram_total(ns, "home") ||integer_server_ram_biggest_afforded >= object_constants.PurchasedServerMaxRam)) {return true;}(integer_server_ram_biggest_afforded >=float_get_server_ram_total(ns, "home") ||integer_server_ram_biggest_afforded >=object_constants.PurchasedServerMaxRam))return !0; - replacement in sbin/servers.js at line 150
const boolean_conditions_server_purchase_2 = function(ns) {const integer_servers_bought_amount = ns.getPurchasedServers().length;const object_constants = object_get_constants(ns);if (// you have one or more servers already(integer_servers_bought_amount > 0) &&const boolean_conditions_server_purchase_2 = function (ns) {const integer_servers_bought_amount = ns.getPurchasedServers().length,object_constants = object_get_constants();if (// you have one or more servers alreadyinteger_servers_bought_amount > 0 && - replacement in sbin/servers.js at line 157
(integer_servers_bought_amount < object_constants.PurchasedServerLimit)integer_servers_bought_amount < object_constants.PurchasedServerLimit - replacement in sbin/servers.js at line 159
const float_ram_server_bought_biggest = float_get_server_ram_total(ns, string_get_server_bought_biggest(ns));const float_ram_server_bought_biggest = float_get_server_ram_total(ns,string_get_server_bought_biggest(ns));// you dont own a server with max RAM yet, buy a server with RAM greater than the RAM of your biggest bought server - replacement in sbin/servers.js at line 165[3.5673]→[3.5673:5968](∅→∅),[3.5968]→[3.9787:9814](∅→∅),[3.9787]→[3.9787:9814](∅→∅),[3.9851]→[3.9851:9857](∅→∅)
// you dont own a server with max RAM yet, buy a server with RAM greater than the RAM of your biggest bought server(float_ram_server_bought_biggest != object_constants.PurchasedServerMaxRam) &&(float_ram_server_bought_biggest < integer_get_server_ram_biggest_afforded(ns))) {return true;}float_ram_server_bought_biggest !=object_constants.PurchasedServerMaxRam &&float_ram_server_bought_biggest <integer_get_server_ram_biggest_afforded(ns))return !0; - replacement in sbin/servers.js at line 174
const boolean_conditions_server_purchase_3 = function(ns) {const integer_servers_bought_amount = ns.getPurchasedServers().length;const object_constants = object_get_constants(ns);const float_ram_server_bought_maximum = object_constants.PurchasedServerMaxRam;if (// you have one or more servers already(integer_servers_bought_amount > 0) &&const boolean_conditions_server_purchase_3 = function (ns) {const integer_servers_bought_amount = ns.getPurchasedServers().length,object_constants = object_get_constants(),float_ram_server_bought_maximum = object_constants.PurchasedServerMaxRam;if (// you have one or more servers alreadyinteger_servers_bought_amount > 0 && - replacement in sbin/servers.js at line 182[3.6417]→[3.6417:6794](∅→∅),[3.6794]→[3.10301:10309](∅→∅),[3.10301]→[3.10301:10309](∅→∅),[3.10309]→[3.6795:6814](∅→∅),[3.6814]→[3.10407:10413](∅→∅),[3.10407]→[3.10407:10413](∅→∅),[3.10413]→[3.6815:6819](∅→∅)
(integer_servers_bought_amount < object_constants.PurchasedServerLimit)) {if (// you already bought a server with max ram, buy another server the max possible ram(float_get_server_ram_total(ns, string_get_server_bought_biggest(ns)) == float_ram_server_bought_maximum) &&(integer_get_server_ram_biggest_afforded(ns) >= float_ram_server_bought_maximum)) {return true;}}integer_servers_bought_amount < object_constants.PurchasedServerLimit &&// you already bought a server with max ram, buy another server the max possible ramfloat_get_server_ram_total(ns, string_get_server_bought_biggest(ns)) ==float_ram_server_bought_maximum &&integer_get_server_ram_biggest_afforded(ns) >=float_ram_server_bought_maximum)return !0; - replacement in sbin/servers.js at line 192
const boolean_conditions_server_delete_purchase = function(ns) {const object_constants = object_get_constants(ns);if (// you currently own the maximum amount of purchased servers allowed(ns.getPurchasedServers().length == object_constants.PurchasedServerLimit) &&const boolean_conditions_server_delete_purchase = function (ns) {const object_constants = object_get_constants();return (// you currently own the maximum amount of purchased servers allowedns.getPurchasedServers().length == object_constants.PurchasedServerLimit && - replacement in sbin/servers.js at line 198
!(boolean_servers_bought_all_max(ns, object_constants.PurchasedServerMaxRam)) &&!boolean_servers_bought_all_max(ns,object_constants.PurchasedServerMaxRam) && - replacement in sbin/servers.js at line 203
(ns.getServerMoneyAvailable("home") >= 3 * object_constants.BaseCostFor1GBOfRamServer * float_get_server_ram_total(ns, string_get_server_bought_smallest(ns)))) {return true;}else {return false;}ns.getServerMoneyAvailable("home") >=3 *object_constants.BaseCostFor1GBOfRamServer *float_get_server_ram_total(ns, string_get_server_bought_smallest(ns))); - replacement in sbin/ram.js at line 2
import {float_get_network_ram_utilisation}from "lib_ram_server.js";import { float_get_network_ram_utilisation } from "lib_ram_server.js";export const main = async function (ns) {const float_period_check = 1e3 * ns.args[0],float_ram_utilisation_threshold = ns.args[1];for (;;) {for (;float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold; - replacement in sbin/ram.js at line 11[3.7946]→[3.10583:10672](∅→∅),[3.10583]→[3.10583:10672](∅→∅),[3.10672]→[3.7947:8001](∅→∅),[3.8001]→[3.10672:10688](∅→∅),[3.10672]→[3.10672:10688](∅→∅),[3.10688]→[3.8002:8087](∅→∅)
export const main = async function(ns) {const float_period_check = ns.args[0] * 1000;const float_ram_utilisation_threshold = ns.args[1];while(true) {while(float_get_network_ram_utilisation(ns) > float_ram_utilisation_threshold) {) - replacement in sbin/ram.js at line 13[3.8099]→[3.8099:8213](∅→∅),[3.8213]→[3.7:53](∅→∅),[3.53]→[3.8213:8223](∅→∅),[3.8213]→[3.8213:8223](∅→∅),[3.8223]→[3.10808:10816](∅→∅),[3.10808]→[3.10808:10816](∅→∅),[3.10816]→[3.8224:8287](∅→∅),[3.8287]→[3.54:98](∅→∅)
while (ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost()) {ns.upgradeHomeRam();await ns.sleep(float_period_check);}}catch (error) {ns.print(JSON.stringify(error));await ns.sleep(float_period_check);for (;ns.getServerMoneyAvailable("home") >= ns.getUpgradeHomeRamCost();)ns.upgradeHomeRam(), await ns.sleep(float_period_check);} catch (error) {ns.print(JSON.stringify(error)), await ns.sleep(float_period_check); - edit in sbin/ram.js at line 22
} - replacement in sbin/programs.js at line 2
export const main = async function(ns) {const float_period_check = ns.args[0] * 1000;const array_programs = ns.args[1];let boolean_has_all_programs = false;while (true) {if (boolean_has_all_programs) {break;}let boolean_program_missing = false;for (let integer_indices_0 = 0; integer_indices_0 < array_programs.length; ++integer_indices_0) {export const main = async function (ns) {const float_period_check = 1e3 * ns.args[0],array_programs = ns.args[1];let boolean_has_all_programs = !1;for (; !boolean_has_all_programs; ) {let boolean_program_missing = !1;for (let integer_indices_0 = 0;integer_indices_0 < array_programs.length;++integer_indices_0) { - replacement in sbin/programs.js at line 14
if (!ns.fileExists(string_program, "home")) {boolean_program_missing = true;}ns.fileExists(string_program, "home") || (boolean_program_missing = !0); - edit in sbin/programs.js at line 20
}if (!boolean_program_missing) {boolean_has_all_programs = true; - replacement in sbin/programs.js at line 21
await ns.sleep(float_period_check);boolean_program_missing || (boolean_has_all_programs = !0),await ns.sleep(float_period_check); - replacement in sbin/hacker.js at line 6
import { array_get_servers_rooted } from "lib_root.js"; - edit in sbin/hacker.js at line 8
array_get_servers_rooted}from "lib_root.js";import { - replacement in sbin/hacker.js at line 9
array_get_servers_rooted_sorted_by_ram}from "lib_ram_server.js";array_get_servers_rooted_sorted_by_ram,} from "lib_ram_server.js";import { boolean_can_server_run_script_threads } from "lib_ram_script.js"; - edit in sbin/hacker.js at line 13
import {boolean_can_server_run_script_threads}from "lib_ram_script.js"; - replacement in sbin/hacker.js at line 14
export const main = async function(ns) {export const main = async function (ns) { - edit in sbin/hacker.js at line 16
// main loop - replacement in sbin/hacker.js at line 17[3.15746]→[3.15746:15810](∅→∅),[3.15810]→[3.170:259](∅→∅),[3.259]→[3.15905:16111](∅→∅),[3.15905]→[3.15905:16111](∅→∅)
while (true) {if (integer_time_finishes <= Date.now()) {integer_time_finishes = void_runner(ns, ...array_arguments.slice(1)) + Date.now();}// arbitrarily check every float_period_check_seconds to see if the current time is greater than the time that the runner is supposed to finish.await ns.sleep(array_arguments[0] * 1000);}for (;;)integer_time_finishes <= Date.now() &&(integer_time_finishes =void_runner(ns, ...array_arguments.slice(1)) + Date.now()),await ns.sleep(1e3 * array_arguments[0]); - edit in sbin/hacker.js at line 25
- replacement in sbin/hacker.js at line 169
// object_constants are from https://github.com/danielyxie/bitburner/blob/master/src/Constants.jsconst object_constants = {// object_constants are from https://github.com/danielyxie/bitburner/blob/master/src/Constants.jsreturn { - edit in sbin/hacker.js at line 188[3.21173]→[3.21173:36913](∅→∅),[3.37263]→[3.37263:37267](∅→∅),[3.37280]→[3.37280:37675](∅→∅),[3.37928]→[3.37928:41659](∅→∅),[3.41659]→[3.11:146](∅→∅),[3.146]→[3.260:367](∅→∅),[3.367]→[3.270:315](∅→∅),[3.270]→[3.270:315](∅→∅),[3.315]→[3.41659:41857](∅→∅),[3.41659]→[3.41659:41857](∅→∅),[3.41857]→[3.316:449](∅→∅),[3.449]→[3.41996:42352](∅→∅),[3.41996]→[3.41996:42352](∅→∅),[3.42448]→[3.42448:42473](∅→∅),[3.42473]→[3.368:482](∅→∅),[3.482]→[3.42604:44105](∅→∅),[3.42604]→[3.42604:44105](∅→∅),[3.44105]→[3.483:595](∅→∅),[3.595]→[3.44234:46227](∅→∅),[3.44234]→[3.44234:46227](∅→∅),[3.46227]→[3.596:708](∅→∅),[3.708]→[3.46356:48896](∅→∅),[3.46356]→[3.46356:48896](∅→∅),[3.48896]→[3.450:501](∅→∅),[3.501]→[3.48942:49005](∅→∅),[3.48942]→[3.48942:49005](∅→∅),[3.49005]→[3.502:658](∅→∅),[3.658]→[3.49066:49180](∅→∅),[3.49066]→[3.49066:49180](∅→∅),[3.49180]→[3.659:827](∅→∅),[3.827]→[3.49243:49501](∅→∅),[3.49243]→[3.49243:49501](∅→∅),[3.49516]→[3.49516:49597](∅→∅),[3.49597]→[3.828:937](∅→∅),[3.937]→[3.49597:49615](∅→∅),[3.49597]→[3.49597:49615](∅→∅),[3.49615]→[3.938:1046](∅→∅),[3.1046]→[3.49673:49755](∅→∅),[3.49673]→[3.49673:49755](∅→∅),[3.49755]→[3.709:769](∅→∅),[3.769]→[3.49821:50755](∅→∅),[3.49821]→[3.49821:50755](∅→∅),[3.50755]→[3.770:902](∅→∅),[3.902]→[3.50893:50963](∅→∅),[3.50893]→[3.50893:50963](∅→∅),[3.50963]→[3.903:1043](∅→∅),[3.1043]→[3.11:411](∅→∅),[3.51109]→[3.11:411](∅→∅),[3.411]→[3.1044:1088](∅→∅),[3.1088]→[3.461:618](∅→∅),[3.461]→[3.461:618](∅→∅)
return object_constants;};// targetting// returns the score of a server which is calculated by taking into account its max cash, growth, and required hacking level. adapted from `calculatePercentMoneyHacked` in Hacking.jsconst float_get_server_score = function(ns, string_server_target) {const float_player_hacking_level = ns.getHackingLevel();return ns.getServerMaxMoney(string_server_target) * ns.getServerGrowth(string_server_target) * ((float_player_hacking_level - (ns.getServerRequiredHackingLevel(string_server_target) - 1)) * Math.pow(float_player_hacking_level, -1));};// sort an array of servers by their score, from lowest to highestconst void_sort_by_server_scores = function(ns, array_servers) {return array_servers.sort((string_element_0, string_element_1) => float_get_server_score(ns, string_element_0) - float_get_server_score(ns, string_element_1));};// weaken, grow, hack// returns integer_threads_required if it's less than or equal to integer_threads_available, otherwise returns integer_threads_availableconst integer_get_corrected_threads = function(ns, integer_threads_required, integer_threads_available) {if (integer_threads_required > integer_threads_available) {return integer_threads_available;}else {return integer_threads_required;}};// weaken stuff// the threads required for weaken to cause string_server_target's security to decrease by float_weaken_amount. adapted from `weaken` in NetscriptFunctions.js and `weaken` in Server.tsconst integer_get_threads_required_for_weaken = function(ns, float_weaken_amount) {const object_constants = object_get_constants(ns);return float_weaken_amount * Math.pow(object_constants.ServerWeakenAmount, -1) * Math.pow(object_constants.object_bitnode_multipliers.ServerWeakenRate, -1);};// returns the threads required for weaken to cause string_server_target's security to reach minimumconst integer_get_threads_required_for_weaken_minimum_security = function(ns, string_server_target, float_server_target_security) {return Math.ceil(integer_get_threads_required_for_weaken(ns, float_server_target_security - ns.getServerMinSecurityLevel(string_server_target)));};// returns the threads required for weaken to cause string_server_target's security to reach minimum if possible, otherwise, return max threads that string_server_used can provideconst integer_get_threads_weaken = function(ns, float_server_used_ram_free, string_server_target, float_server_target_security) {const string_weaken = object_get_constants(ns).array_workers[0];const integer_threads_available = Math.trunc(float_server_used_ram_free / ns.getScriptRam(string_weaken));const integer_threads_required = integer_get_threads_required_for_weaken_minimum_security(ns, string_server_target, float_server_target_security);return integer_get_corrected_threads(ns, integer_threads_required, integer_threads_available);};// returns the security decrease from the weaken threads used. Adapted from `weaken` in NetscriptFunctions.js and `weaken` in Server.tsconst float_get_security_decrease_from_weaken = function(ns, integer_threads_weaken) {return integer_threads_weaken * object_get_constants(ns).ServerWeakenAmount;};// grow stuff// returns the number of threads of `grow` needed to grow `string_server_target` by the percentage `float_growth` when it has security of `float_server_security`. float_growth = How much the server is being grown by, in DECIMAL form (e.g. 1.5 rather than 50). adapted from `numCycleForGrowth` in https://github.com/danielyxie/bitburner/blob/master/src/Server/ServerHelpers.tsconst integer_get_threads_for_growth = function(ns, string_server_target, float_server_target_security, float_growth) {const object_constants = object_get_constants(ns);let ajdGrowthRate = 1 + (object_constants.ServerBaseGrowthRate - 1) / float_server_target_security;if (ajdGrowthRate > object_constants.ServerMaxGrowthRate) {ajdGrowthRate = object_constants.ServerMaxGrowthRate;}const serverGrowthPercentage = ns.getServerGrowth(string_server_target) / 100;const cycles = Math.log(float_growth)/(Math.log(ajdGrowthRate) * object_constants.object_hacking_multipliers.growth * serverGrowthPercentage * object_constants.object_bitnode_multipliers.ServerGrowthRate);return Math.ceil(cycles);};// Inverse function of integer_get_threads_for_growth. Returns the percentage growth in decimal form (e.g., 2 = 100% growth).const float_get_growth_from_threads = function(ns, string_server_target, float_server_target_security, integer_threads) {const object_constants = object_get_constants(ns);let ajdGrowthRate = 1 + (object_constants.ServerBaseGrowthRate - 1) / float_server_target_security;if (ajdGrowthRate > object_constants.ServerMaxGrowthRate) {ajdGrowthRate = object_constants.ServerMaxGrowthRate;}const serverGrowthPercentage = ns.getServerGrowth(string_server_target) / 100;const float_growth = Math.pow(ajdGrowthRate, integer_threads * object_constants.object_hacking_multipliers.growth * serverGrowthPercentage * object_constants.object_bitnode_multipliers.ServerGrowthRate);return float_growth;};// returns the threads required by grow to grow string_server_target's cash to its maximum when security is at float_server_target_security and current cash is at float_server_target_cashconst integer_get_threads_required_for_grow_maximum_cash = function(ns, string_server_target, float_server_target_security, float_server_target_cash) {return integer_get_threads_for_growth(ns, string_server_target, float_server_target_security, ns.getServerMaxMoney(string_server_target) / float_server_target_cash);};// returns the threads required by grow to grow string_server_target's cash to its maximum if possible, otherwise, return max threads that string_server_used can provideconst integer_get_threads_grow = function(ns, float_server_used_ram_free, string_server_target, float_server_target_security, float_server_target_cash) {const string_grow = object_get_constants(ns).array_workers[1];const integer_threads_available = Math.trunc(float_server_used_ram_free / ns.getScriptRam(string_grow));const integer_threads_required = integer_get_threads_required_for_grow_maximum_cash(ns, string_server_target, float_server_target_security, float_server_target_cash);return integer_get_corrected_threads(ns, integer_threads_required, integer_threads_available);};// returns the security increase from the growth threads used. Adapted from `processSingleServerGrowth` in ServerHelpers.ts and `fortify` in Server.tsconst float_get_security_increase_from_grow = function(ns, integer_threads_grow) {return 2 * object_get_constants(ns).ServerFortifyAmount * integer_threads_grow;};// hack stuff// returns the percentage of the available cash in string_server_target that is stolen when it is hacked when it has float_server_target_security. adapted from calculatePercentMoneyHacked() in https://github.com/danielyxie/bitburner/blob/master/src/Hacking.js . See also `hackDifficulty` in https://github.com/danielyxie/bitburner/blob/master/src/Server.jsconst float_get_percentage_of_cash_from_available_per_hack = function(ns, string_server_target, float_server_target_security) {const object_constants = object_get_constants(ns);const balanceFactor = 240;const difficultyMult = (100 - float_server_target_security) / 100;const skillMult = (ns.getHackingLevel() - (ns.getServerRequiredHackingLevel(string_server_target) - 1)) / ns.getHackingLevel();const percentMoneyHacked = difficultyMult * skillMult * object_constants.object_hacking_multipliers.money / balanceFactor;if (percentMoneyHacked < 0) { return 0; }if (percentMoneyHacked > 1) { return 1; }return percentMoneyHacked * object_constants.object_bitnode_multipliers.ScriptHackMoney;};// returns the threads required to steal "float_percentage_to_steal" of available money in string_server_targetconst integer_get_threads_required_to_hack_percentage = function(ns, string_server_target, float_server_target_security, float_percentage_to_steal) {return Math.ceil(float_percentage_to_steal / float_get_percentage_of_cash_from_available_per_hack(ns, string_server_target, float_server_target_security));};// returns the threads required to steal "float_percentage_to_steal" of available money in string_server_target if possible, otherwise, return max threads that string_server_used can provideconst integer_get_threads_hack = function(ns, float_server_used_ram_free, string_server_target, float_server_target_security, float_percentage_to_steal) {const string_hack = object_get_constants(ns).array_workers[2];const integer_threads_available = Math.trunc(float_server_used_ram_free / ns.getScriptRam(string_hack));const integer_threads_required = integer_get_threads_required_to_hack_percentage(ns, string_server_target, float_server_target_security, float_percentage_to_steal);return integer_get_corrected_threads(ns, integer_threads_required, integer_threads_available);};// returns the security increase from the hack threads. adapted from `hack` in NetscriptFunctions.js and `fortify` in Server.tsconst float_get_security_increase_from_hack = function(ns, string_server_target, float_server_target_security, float_server_target_cash, integer_threads_hack) {let maxThreadNeeded = Math.ceil(1/float_get_percentage_of_cash_from_available_per_hack(ns, string_server_target, float_server_target_security)*(float_server_target_cash/ns.getServerMaxMoney(string_server_target)));if (isNaN(maxThreadNeeded)) {// Server has a 'max money' of 0 (probably). We'll set this to an arbitrarily large valuemaxThreadNeeded = 1e6;}return object_get_constants(ns).ServerFortifyAmount * Math.min(integer_threads_hack, maxThreadNeeded);};// percentage to steal stuff// returns the threads required by grow to grow a string_server_target's money back to its original value after stealing float_percentage_to_steal of it, and assuming security is at float_server_target_securityconst integer_get_threads_required_for_cash_grow_after_percentage_stolen = function(ns, string_server_target, float_server_target_security, float_percentage_to_steal) {return integer_get_threads_for_growth(ns, string_server_target, float_server_target_security, Math.pow(1 - float_percentage_to_steal, -1));};// should return true if there is enough ram to provide the threads required by weaken to weaken to minimum security, then by grow to grow string_server_target's cash back to maximum after stealing float_percentage_to_steal of the cash, then by weaken to weaken to minimum security again if possible, otherwise, returns false. assumes security is at float_server_target_securityconst boolean_is_ram_enough_after_hack_percentage = function(ns, float_server_used_ram_free, string_server_target, float_server_target_cash, float_server_target_security, float_percentage_to_steal) {const string_weaken = object_get_constants(ns).array_workers[0];const string_grow = object_get_constants(ns).array_workers[1];const float_server_target_security_after_hack = float_server_target_security + float_get_security_increase_from_hack(ns, string_server_target, float_server_target_security, float_server_target_cash, integer_get_threads_hack(ns, float_server_used_ram_free, string_server_target, float_server_target_security, float_percentage_to_steal));const integer_threads_required_for_weaken_minimum_security_after_hack = integer_get_threads_required_for_weaken_minimum_security(ns, string_server_target, float_server_target_security_after_hack);const float_server_target_security_after_weaken = float_server_target_security_after_hack - float_get_security_decrease_from_weaken(ns, integer_threads_required_for_weaken_minimum_security_after_hack);const integer_threads_required_for_cash_grow_after_percentage_stolen = integer_get_threads_required_for_cash_grow_after_percentage_stolen(ns, string_server_target, float_server_target_security_after_weaken, float_percentage_to_steal);const float_server_target_security_after_grow = float_server_target_security_after_weaken + float_get_security_increase_from_grow(ns,integer_threads_required_for_cash_grow_after_percentage_stolen);const integer_threads_required_for_weaken_minimum_security_after_grow = integer_get_threads_required_for_weaken_minimum_security(ns, string_server_target, float_server_target_security_after_grow);const float_ram_required = (integer_threads_required_for_weaken_minimum_security_after_hack * ns.getScriptRam(string_weaken)) + (integer_threads_required_for_cash_grow_after_percentage_stolen * ns.getScriptRam(string_grow)) + (integer_threads_required_for_weaken_minimum_security_after_grow * ns.getScriptRam(string_weaken));if (float_ram_required < float_server_used_ram_free) {return true;}else {return false;}};// returns the number of cycles of bisection to be done to reach a certain precision, rounded up to the nearest integerconst integer_get_cycles_for_bisection_precision = function(ns, float_precision) {return Math.ceil(Math.log(Math.pow(float_precision, -1)) * Math.pow(Math.log(2), -1));};// this should return optimum percentage to steal such that cash stolen at most is as high as float_steal_cap and string_server_target's security is able to be weakened to minimum with one weaken after the hack, its cash grown to 100% after one grow after the weaken, then its security weakened again to minimum with one weaken, all with the ram it has remaining after the hack by using a binary search algorithmconst float_get_percentage_to_steal = function(ns, float_server_used_ram_free, string_server_target, float_server_target_cash, float_server_target_security, float_precision, float_steal_cap) {const integer_cycles_for_bisection_precision = integer_get_cycles_for_bisection_precision(ns, float_precision);let float_ceiling = 1;let float_floor = 0;let float_percentage_to_steal = (float_ceiling + float_floor) * 0.5;for (let integer_indices_0 = 0; integer_indices_0 < integer_cycles_for_bisection_precision; ++integer_indices_0) {if (boolean_is_ram_enough_after_hack_percentage(ns, float_server_used_ram_free, string_server_target, float_server_target_cash, float_server_target_security, float_percentage_to_steal)) {float_floor = float_percentage_to_steal;}else {float_ceiling = float_percentage_to_steal;}float_percentage_to_steal = (float_ceiling + float_floor) * 0.5;if (float_percentage_to_steal > float_steal_cap) {break;}}// cap which can be used so not all money is stolen, which can be bad because it's harder to grow from 0 in most casesif (float_percentage_to_steal > float_steal_cap) {return float_steal_cap;}else {return float_percentage_to_steal;}};// schedulingconst array_get_servers_rooted_sorted_by_score = function(ns) {let array_servers_rooted = array_get_servers_rooted(ns);void_sort_by_server_scores(ns, array_servers_rooted);return array_servers_rooted;};const string_get_server_rooted_hackable_with_score_biggest = function(ns) {const array_servers_rooted_sorted_by_score = array_get_servers_rooted_sorted_by_score(ns);// iterate through array in reversefor (let integer_indices_0 = array_servers_rooted_sorted_by_score.length - 1; integer_indices_0 >= 0; --integer_indices_0) {const string_server_target = array_servers_rooted_sorted_by_score[integer_indices_0];if (ns.getHackingLevel() >= ns.getServerRequiredHackingLevel(string_server_target)) {return string_server_target;}}};const string_job_decider = function(ns, string_server_target, float_server_target_security, float_server_target_cash) {if (float_server_target_security > ns.getServerMinSecurityLevel(string_server_target)) {return "weaken";}else {if (float_server_target_cash < ns.getServerMaxMoney(string_server_target)) {return "grow";}else {return "hack";}}};// Returns time it takes to complete a hack on a server, in seconds. Adapted from `calculateHackingTime` in Hacking.jsconst float_get_time_hack = function(ns, string_server_target, float_server_target_security) {const object_constants = object_get_constants(ns);const difficultyMult = ns.getServerRequiredHackingLevel(string_server_target) * float_server_target_security;const baseDiff = 500;const baseSkill = 50;const diffFactor = 2.5;const intFactor = 0.1;const hack_stat = object_constants.object_stats.hacking;const int = object_constants.object_stats.intelligence;var skillFactor = (diffFactor * difficultyMult + baseDiff);// tslint:disable-next-lineskillFactor /= (hack_stat + baseSkill + (intFactor * int));const hackTimeMultiplier = 5;const hackingTime = hackTimeMultiplier * skillFactor / object_constants.object_hacking_multipliers.speed;return hackingTime;};// Returns time it takes to complete a grow operation on a server, in seconds. Adapted from `calculateGrowTime` in Hacking.jsconst float_get_time_grow = function(ns, string_server_target, float_server_target_security) {const growTimeMultiplier = 3.2; // Relative to hacking time. 16/5 = 3.2return growTimeMultiplier * float_get_time_hack(ns, string_server_target, float_server_target_security);};// Returns time it takes to complete a weaken operation on a server, in seconds. Adapted from `calculateHackingTime` in Hacking.jsconst float_get_time_weaken = function(ns, string_server_target, float_server_target_security) {const weakenTimeMultiplier = 4; // Relative to hacking timereturn weakenTimeMultiplier * float_get_time_hack(ns, string_server_target, float_server_target_security);};// makes a scheduleconst array_make_schedule = function(ns, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target, string_decider) {const array_workers = object_get_constants(ns).array_workers;const string_weaken = array_workers[0];const string_grow = array_workers[1];const string_hack = array_workers[2];const array_servers_rooted_sorted_by_ram = array_get_servers_rooted_sorted_by_ram(ns);const float_server_target_security_minimum = ns.getServerMinSecurityLevel(string_server_target);const float_server_target_cash_maximum = ns.getServerMaxMoney(string_server_target);const float_time_weaken = float_get_time_weaken(ns, string_server_target, ns.getServerSecurityLevel(string_server_target));const float_time_grow = float_get_time_grow(ns, string_server_target, ns.getServerSecurityLevel(string_server_target));const float_time_hack = float_get_time_hack(ns, string_server_target, ns.getServerSecurityLevel(string_server_target));// tripwireslet boolean_end_loop_array_servers = false;let boolean_end_loop_server = false;let float_server_target_security_current = ns.getServerSecurityLevel(string_server_target);let float_server_target_cash_current = ns.getServerMoneyAvailable(string_server_target);let array_schedule = [];let integer_array_schedule_length = 0;let integer_time_job_finishes_seconds = Math.max(float_time_weaken, float_time_grow, float_time_hack);// iterate through servers in reverse to use servers with the biggest rams firstfor (let integer_indices_0 = array_servers_rooted_sorted_by_ram.length - 1; integer_indices_0 >= 0; --integer_indices_0) {if (integer_array_schedule_length >= integer_job_cap ||boolean_end_loop_array_servers) {break;}const string_server_used = array_servers_rooted_sorted_by_ram[integer_indices_0];let float_server_used_ram_free_current = float_get_server_ram_free(ns, string_server_used);let string_job = string_decider(ns, string_server_target, float_server_target_security_current, float_server_target_cash_current);if (boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, string_weaken, 1)) {boolean_end_loop_server = false;}while (float_server_used_ram_free_current > 0 &&integer_array_schedule_length < integer_job_cap &&!boolean_end_loop_array_servers &&!boolean_end_loop_server) {string_job = string_decider(ns, string_server_target, float_server_target_security_current, float_server_target_cash_current);const schedule_item = {string_job: string_job,string_server_used: string_server_used,string_server_target: string_server_target,float_server_target_security_before: float_server_target_security_current,float_server_target_cash_before: float_server_target_cash_current};switch (string_job) {case "weaken": {if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, string_weaken, 1)) {// start using a server with more ramboolean_end_loop_server = true;break;}const integer_threads_weaken = integer_get_threads_weaken(ns, float_server_used_ram_free_current, string_server_target, float_server_target_security_current);float_server_used_ram_free_current -= integer_threads_weaken * ns.getScriptRam(string_weaken);const float_server_target_security_uncorrected = float_server_target_security_current - float_get_security_decrease_from_weaken(ns, integer_threads_weaken);if (float_server_target_security_uncorrected < float_server_target_security_minimum) {float_server_target_security_current = float_server_target_security_minimum;}else {float_server_target_security_current = float_server_target_security_uncorrected;}schedule_item.float_server_target_security_current = float_server_target_security_current;schedule_item.float_delay_seconds = integer_time_job_finishes_seconds - float_time_weaken + float_padding_seconds;integer_time_job_finishes_seconds += float_padding_seconds;schedule_item.integer_time_job_finishes_seconds = integer_time_job_finishes_seconds;schedule_item.integer_threads = integer_threads_weaken;array_schedule.push(schedule_item);++integer_array_schedule_length;break;}case "grow": {if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, string_grow, 1)) {// start using a server with more ramboolean_end_loop_server = true;break;}if (float_server_target_cash_current === 0) {float_server_target_cash_current = 1; // counts 0 cash as 1 so it can still grow. taken from `grow` in NetscriptFunctions.js}const integer_threads_grow = integer_get_threads_grow(ns, float_server_used_ram_free_current, string_server_target, float_server_target_security_current, float_server_target_cash_current);float_server_used_ram_free_current -= integer_threads_grow * ns.getScriptRam(string_grow);const float_server_target_cash_current_uncorrected = float_server_target_cash_current * float_get_growth_from_threads(ns, string_server_target, float_server_target_security_current, integer_threads_grow);if (float_server_target_cash_current_uncorrected > float_server_target_cash_maximum) {float_server_target_cash_current = float_server_target_cash_maximum;}else {float_server_target_cash_current = float_server_target_cash_current_uncorrected;}// the following is adapted from `processSingleServerGrowth` in ServerHelpers.ts and `fortify` in Server.tsfloat_server_target_security_current += float_get_security_increase_from_grow(ns, integer_threads_grow);schedule_item.float_server_target_security_current = float_server_target_security_current;schedule_item.float_delay_seconds = integer_time_job_finishes_seconds - float_time_grow + float_padding_seconds;integer_time_job_finishes_seconds += float_padding_seconds;schedule_item.integer_time_job_finishes_seconds = integer_time_job_finishes_seconds;schedule_item.integer_threads = integer_threads_grow;array_schedule.push(schedule_item);++integer_array_schedule_length;break;}case "hack": {if (!boolean_can_server_run_script_threads(ns, float_server_used_ram_free_current, string_hack, 1)) {// start using a server with more ramboolean_end_loop_server = true;break;}const integer_threads_hack = integer_get_threads_hack(ns, float_server_used_ram_free_current, string_server_target, float_server_target_security_current, float_get_percentage_to_steal(ns, float_server_used_ram_free_current, string_server_target, float_server_target_cash_current, float_server_target_security_current, float_precision, float_steal_cap));float_server_used_ram_free_current -= integer_threads_hack * ns.getScriptRam(string_hack);// the following is adapted from `hack` in NetscriptFunctions.js and `fortify` in Server.tsconst float_server_target_cash_before = float_server_target_cash_current;const float_server_target_cash_current_uncorrected = float_server_target_cash_current - Math.floor(float_server_target_cash_current * float_get_percentage_of_cash_from_available_per_hack(ns, string_server_target, float_server_target_security_current)) * integer_threads_hack;if (float_server_target_cash_current_uncorrected < 0) {float_server_target_cash_current = 0;}else {float_server_target_cash_current = float_server_target_cash_current_uncorrected;}float_server_target_security_current += float_get_security_increase_from_hack(ns, string_server_target, float_server_target_security_current, float_server_target_cash_before, integer_threads_hack);schedule_item.float_server_target_security_current = float_server_target_security_current;schedule_item.float_delay_seconds = integer_time_job_finishes_seconds - float_time_hack + float_padding_seconds;integer_time_job_finishes_seconds += float_padding_seconds;schedule_item.integer_time_job_finishes_seconds = integer_time_job_finishes_seconds;schedule_item.integer_threads = integer_threads_hack;array_schedule.push(schedule_item);++integer_array_schedule_length;break;}}}}// remove jobs near the end that cause security to not equal minimum. in other words, the target should have minimum security when the schedule finishes. this is to make the jobs in the next schedule run as quick as possible. TODO: make it so that we don't have to do this deleting step, instead, the array making steps above should already take into this into account and don't make more items than is needed.let array_schedule_edited = [...array_schedule];let boolean_have_not_seen_item_with_security_minimum = true;let boolean_end_loop_schedule_edit = false;while (boolean_have_not_seen_item_with_security_minimum &&!boolean_end_loop_schedule_edit) {for (let integer_indices_1 = array_schedule_edited.length - 1; integer_indices_1 >= 0; --integer_indices_1) {if (!boolean_have_not_seen_item_with_security_minimum ||boolean_end_loop_schedule_edit) {boolean_end_loop_schedule_edit = true;break;}const object_job = array_schedule_edited[integer_indices_1];if (object_job.float_server_target_security_current === float_server_target_security_minimum) {boolean_have_not_seen_item_with_security_minimum = false;}else {array_schedule_edited.splice(integer_indices_1, 1);if (array_schedule_edited.length === 0) {boolean_end_loop_schedule_edit = true;}}}}if (boolean_have_not_seen_item_with_security_minimum ||array_schedule_edited.length === 0) {return array_schedule;}else {return array_schedule_edited;}};const void_schedule_runner = function(ns, array_schedule) {const array_workers = object_get_constants(ns).array_workers;for (let integer_indices_0 = 0; integer_indices_0 < array_schedule.length; ++integer_indices_0) {const string_job = array_schedule[integer_indices_0].string_job;const string_server_used = array_schedule[integer_indices_0].string_server_used;const string_server_target = array_schedule[integer_indices_0].string_server_target;const integer_threads = array_schedule[integer_indices_0].integer_threads;const float_delay = array_schedule[integer_indices_0].float_delay_seconds * 1000;const identifier = integer_indices_0;let string_script = "";switch (string_job) {case "weaken": {string_script = array_workers[0];break;}case "grow": {string_script = array_workers[1];break;}case "hack": {string_script = array_workers[2];break;}}ns.exec(string_script, string_server_used, integer_threads, string_server_used, string_server_target, float_delay, identifier);}};// returns the the time it'll take to finish in milliseconds.const void_runner = function(ns, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target_argument) {let integer_time_start = Date.now();let string_server_target = string_server_target_argument;if (string_server_target_argument === "") {string_server_target = string_get_server_rooted_hackable_with_score_biggest(ns);}const array_schedule = array_make_schedule(ns, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target, string_job_decider);void_schedule_runner(ns, array_schedule);return ((array_schedule[array_schedule.length - 1].integer_time_job_finishes_seconds + float_padding_seconds) * 1000) - integer_time_start + Date.now();}; - replacement in sbin/botnet.js at line 2[3.8482]→[3.8482:8543](∅→∅),[3.8543]→[3.53714:53804](∅→∅),[3.53714]→[3.53714:53804](∅→∅),[3.53804]→[3.8544:8704](∅→∅),[3.8704]→[3.54259:54267](∅→∅),[3.54259]→[3.54259:54267](∅→∅),[3.55454]→[3.55454:55556](∅→∅),[3.55556]→[3.8705:8756](∅→∅),[3.8756]→[3.55624:55956](∅→∅),[3.55624]→[3.55624:55956](∅→∅)
import {array_get_servers_unrooted}from "lib_root.js";export const main = async function(ns) {const float_period_check = ns.args[0] * 1000;const array_get_exploits = function(ns) {return [ns.brutessh,ns.ftpcrack,ns.relaysmtp,ns.httpworm,ns.sqlinject];};// tries to open ports of serverconst void_open_ports_try = function(ns, string_server_target) {const array_exploits = array_get_exploits(ns);for (let integer_indices_0 = 0; integer_indices_0 < array_exploits.length; ++integer_indices_0) {const string_exploit_function = array_exploits[integer_indices_0];try {string_exploit_function(string_server_target);}catch (error) {ns.print(JSON.stringify(error));}}};import { array_get_servers_unrooted } from "lib_root.js"; - replacement in sbin/botnet.js at line 4
while(true) {// mainexport const main = async function (ns) {const float_period_check = 1e3 * ns.args[0];for (;;) { - replacement in sbin/botnet.js at line 9
if (array_servers_unrooted.length === 0) {break;}for (let integer_indices_0 = 0; integer_indices_0 < array_servers_unrooted.length; ++integer_indices_0) {if (0 === array_servers_unrooted.length) break;for (let integer_indices_0 = 0;integer_indices_0 < array_servers_unrooted.length;++integer_indices_0) { - edit in sbin/botnet.js at line 25
};// functionsconst array_get_exploits = function (ns) {return [ns.brutessh,ns.ftpcrack,ns.relaysmtp,ns.httpworm,ns.sqlinject];};// tries to open ports of serverconst void_open_ports_try = function (ns, string_server_target) {const array_exploits = array_get_exploits(ns);for (let integer_indices_0 = 0;integer_indices_0 < array_exploits.length;++integer_indices_0) {const string_exploit_function = array_exploits[integer_indices_0];try {string_exploit_function(string_server_target);} catch (error) {ns.print(JSON.stringify(error));}} - replacement in lib/lib_ram_server.js at line 18
export const float_get_server_ram_free = function(ns, string_server) {return float_get_server_ram_total(ns, string_server) - float_get_server_ram_used(ns, string_server);export const float_get_server_ram_free = function (ns, string_server) {return (float_get_server_ram_total(ns, string_server) -float_get_server_ram_used(ns, string_server)); - edit in bin/main.js at line 9
import { array_get_servers } from "lib_servers.js";import { array_get_files_to_copy } from "lib_ls.js"; - edit in bin/main.js at line 12
array_get_servers}from "lib_servers.js";import {array_get_files_to_copy}from "lib_ls.js";import { - replacement in bin/main.js at line 13
array_get_servers_rooted_sorted_by_ram}from "lib_ram_server.js";array_get_servers_rooted_sorted_by_ram,} from "lib_ram_server.js";import { boolean_can_server_run_script_threads } from "lib_ram_script.js";import { void_kill_script_named_server_named } from "lib_kill.js";import { object_parse_arguments } from "lib_minimist.js"; - edit in bin/main.js at line 19
import {boolean_can_server_run_script_threads}from "lib_ram_script.js";import {void_kill_script_named_server_named}from "lib_kill.js";import {object_parse_arguments}from "lib_minimist.js"; - replacement in bin/main.js at line 27
if (!boolean_can_server_run_script_threads(ns, float_get_server_ram_free(ns, ns.getHostname()), object_helpers.string_nop, integer_threads_nop)) {const string_message_error = `This server has insufficient RAM to run \"${object_helpers.string_nop}\" with \"${integer_threads_nop}\" thread(s).`;ns.tprint(`ERROR: ${string_message_error}`);throw new Error(string_message_error);if (!boolean_can_server_run_script_threads(ns,float_get_server_ram_free(ns, ns.getHostname()),object_helpers.string_nop,integer_threads_nop)) {const string_message_error = `This server has insufficient RAM to run "${object_helpers.string_nop}" with "${integer_threads_nop}" thread(s).`;throw (ns.tprint(`ERROR: `), new Error(string_message_error)); - replacement in bin/main.js at line 54
// argument parsing// optionsconst object_arguments = object_parse_arguments(ns.args);for (const string_argument in object_arguments) {if (object_arguments.hasOwnProperty(string_argument)) {const argument_value = object_arguments[string_argument];switch (string_argument) {// optionscase "c":// fall-throughcase "check-delay":float_period_check_seconds = argument_value;break;case "d":// fall-throughcase "job-delay":float_padding_seconds = argument_value;break;case "i":// fall-throughcase "target":string_server_target = argument_value;break;case "j":// fall-throughcase "job-cap":integer_job_cap = argument_value;break;case "n":// fall-throughcase "server-name":string_servers_bought_name = argument_value;break;case "p":// fall-throughcase "precision":float_precision = argument_value;break;case "r":// fall-throughcase "ram-utilisation":float_ram_utilisation_threshold = argument_value;break;case "s":// fall-throughcase "steal-cap":float_steal_cap = argument_value;break;}}}>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - replacement in bin/main.js at line 59
args: [float_period_check_seconds, float_ram_utilisation_threshold]args: [float_period_check_seconds, float_ram_utilisation_threshold], - replacement in bin/main.js at line 64
args: [float_period_check_seconds, string_servers_bought_name, float_ram_utilisation_threshold]args: [float_period_check_seconds,string_servers_bought_name,float_ram_utilisation_threshold,], - replacement in bin/main.js at line 73
args: [float_period_check_seconds]args: [float_period_check_seconds], - replacement in bin/main.js at line 78
args: [float_period_check_seconds, ["BruteSSH.exe", "FTPCrack.exe", "relaySMTP.exe", "HTTPWorm.exe", "SQLInject.exe", "DeepscanV1.exe", "DeepscanV2.exe", "Autolink.exe"]]args: [float_period_check_seconds,["BruteSSH.exe","FTPCrack.exe","relaySMTP.exe","HTTPWorm.exe","SQLInject.exe","DeepscanV1.exe","DeepscanV2.exe","Autolink.exe",],], - replacement in bin/main.js at line 95
args: [float_period_check_seconds]}args: [float_period_check_seconds],}, - replacement in bin/main.js at line 100
for (const string_argument in object_arguments) {for (const string_argument in object_arguments) - replacement in bin/main.js at line 103
if ((string_argument === "a" && argument_value) ||(string_argument === "ram" && !argument_value)) {array_helpers.splice(integer_get_index_of_file(array_helpers, object_helpers.string_ram), 1);}if ((string_argument === "e" && argument_value) ||(string_argument === "servers" && !argument_value)) {array_helpers.splice(integer_get_index_of_file(array_helpers, object_helpers.string_servers), 1);}if ((string_argument === "o" && argument_value) ||(string_argument === "tor" && !argument_value)) {array_helpers.splice(integer_get_index_of_file(array_helpers, object_helpers.string_tor), 1);}if ((string_argument === "g" && argument_value) ||(string_argument === "programs" && !argument_value)) {array_helpers.splice(integer_get_index_of_file(array_helpers, object_helpers.string_programs), 1);}if ((string_argument === "b" && argument_value) ||(string_argument === "botnet" && !argument_value)) {array_helpers.splice(integer_get_index_of_file(array_helpers, object_helpers.string_botnet), 1);}(("a" === string_argument && argument_value) ||("ram" === string_argument && !argument_value)) &&array_helpers.splice(integer_get_index_of_file(array_helpers, object_helpers.string_ram),1),(("e" === string_argument && argument_value) ||("servers" === string_argument && !argument_value)) &&array_helpers.splice(integer_get_index_of_file(array_helpers,object_helpers.string_servers),1),(("o" === string_argument && argument_value) ||("tor" === string_argument && !argument_value)) &&array_helpers.splice(integer_get_index_of_file(array_helpers, object_helpers.string_tor),1),(("g" === string_argument && argument_value) ||("programs" === string_argument && !argument_value)) &&array_helpers.splice(integer_get_index_of_file(array_helpers,object_helpers.string_programs),1),(("b" === string_argument && argument_value) ||("botnet" === string_argument && !argument_value)) &&array_helpers.splice(integer_get_index_of_file(array_helpers,object_helpers.string_botnet),1); - edit in bin/main.js at line 143
} - replacement in bin/main.js at line 150
void_kill_script_named_server_named(ns, object_helpers.string_nop, ns.getHostname());ns.spawn(object_helpers.string_hacker, 1, float_period_check_seconds, integer_job_cap, float_precision, float_steal_cap, float_padding_seconds, string_server_target);void_kill_script_named_server_named(ns,ns.getHostname(),object_helpers.string_nop);ns.spawn(object_helpers.string_hacker,1,float_period_check_seconds,integer_job_cap,float_precision,float_steal_cap,float_padding_seconds,string_server_target); - replacement in bin/main.js at line 189
const integer_get_threads_nop = function(ns, string_script_0, string_script_1) {return Math.ceil(float_get_ram_difference(ns, string_script_0, string_script_1) / ns.getScriptRam(object_get_constants().object_helpers.string_nop));const integer_get_threads_nop = function (ns,string_script_0,string_script_1) {return Math.ceil(float_get_ram_difference(ns, string_script_0, string_script_1) /ns.getScriptRam(object_get_constants().object_helpers.string_nop)); - replacement in bin/main.js at line 201
const void_copy_scripts = function(ns) {const string_host = ns.getHostname();const array_script_extensions = [".js", ".ns", ".script"];for (let integer_indices_0 = 0; integer_indices_0 < array_script_extensions.length; ++integer_indices_0) {const void_copy_scripts = function (ns) {const string_host = ns.getHostname(),array_script_extensions = [".js", ".ns", ".script"];for (let integer_indices_0 = 0;integer_indices_0 < array_script_extensions.length;++integer_indices_0) { - replacement in bin/main.js at line 210
void_copy_files_to_servers(ns, array_get_files_to_copy(ns, string_host, string_extension), string_host);void_copy_files_to_servers(ns,array_get_files_to_copy(ns, string_host, string_extension),string_host); - replacement in bin/main.js at line 219
const integer_get_index_of_file = function(array_scripts, string_file) {for (let integer_indices_0 = 0; integer_indices_0 < array_scripts.length; ++integer_indices_0) {const object_script = array_scripts[integer_indices_0];const string_script_file = object_script.file;if (string_script_file === string_file) {return integer_indices_0;}const integer_get_index_of_file = function (array_scripts, string_file) {for (let integer_indices_0 = 0;integer_indices_0 < array_scripts.length;++integer_indices_0) {const object_script = array_scripts[integer_indices_0],string_script_file = object_script.file;if (string_script_file === string_file) return integer_indices_0;}};// returns true if a script is running on any serverconst boolean_script_running = function (ns, string_script) {const array_servers = array_get_servers(ns);for (let integer_indices_0 = 0;integer_indices_0 < array_servers.length;++integer_indices_0) {const string_server = array_servers[integer_indices_0],array_scripts_running = ns.ps(string_server);if (array_scripts_running.length > 0)for (let integer_indices_1 = 0;integer_indices_1 < array_scripts_running.length;++integer_indices_1) {const object_script = array_scripts_running[integer_indices_1],string_script_to_check = object_script.filename;if (string_script_to_check == string_script) return !0;}}return !1;};// copies files to all rooted serversconst void_copy_files_to_servers = function (ns, array_files, string_source) {const array_servers = array_get_servers(ns);for (let integer_indices_0 = 0;integer_indices_0 < array_servers.length;++integer_indices_0)for (let integer_indices_1 = 0;integer_indices_1 < array_files.length;++integer_indices_1)ns.scp(array_files[integer_indices_1],string_source,array_servers[integer_indices_0]);};// runs scripts on any server that has enough available RAMconst void_script_executor = function (ns, array_scripts) {const array_servers_rooted_sorted_by_ram = array_get_servers_rooted_sorted_by_ram(ns);for (let integer_indices_0 = 0;integer_indices_0 < array_scripts.length;++integer_indices_0) {const object_script = array_scripts[integer_indices_0],string_file = object_script.file,float_ram = ns.getScriptRam(string_file),integer_threads = object_script.threads,array_arguments = object_script.args;if (!boolean_script_running(ns, string_file))// use servers with the biggest rams firstfor (let integer_indices_1 = array_servers_rooted_sorted_by_ram.length - 1;integer_indices_1 >= 0;--integer_indices_1) {const string_server_used =array_servers_rooted_sorted_by_ram[integer_indices_1];let float_server_used_ram_free_current;if (float_get_server_ram_free(ns, string_server_used) >=float_ram * integer_threads) {try {ns.exec(string_file,string_server_used,integer_threads,...array_arguments);} catch (error) {ns.tprint(JSON.stringify(error));}break;}0 === integer_indices_1 &&ns.tprint(`WARNING: Unable to find a server with sufficient RAM to run \"${string_file}\".`);} - edit in bin/main.js at line 322[2.9615]
};================================// argument parsing// optionsconst object_arguments = object_parse_arguments(ns.args);for (const string_argument in object_arguments)if (object_arguments.hasOwnProperty(string_argument)) {const argument_value = object_arguments[string_argument];switch (string_argument) {case "c":// fall-throughcase "check-delay":float_period_check_seconds = argument_value;break;case "d":// fall-throughcase "job-delay":float_padding_seconds = argument_value;break;case "i":// fall-throughcase "target":string_server_target = argument_value;break;case "j":// fall-throughcase "job-cap":integer_job_cap = argument_value;break;case "n":// fall-throughcase "server-name":string_servers_bought_name = argument_value;break;case "p":// fall-throughcase "precision":float_precision = argument_value;break;case "r":// fall-throughcase "ram-utilisation":float_ram_utilisation_threshold = argument_value;break;case "s":// fall-throughcase "steal-cap":float_steal_cap = argument_value;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - edit in bin/lshw.js at line 1
// lshw.js - 2.45GB - Display information about one or more servers.// mainexport const main = async function (ns) {let array_arguments = ns.args,float_sleep_duration = 0;for (;;) {for (let integer_indices_0 = 0;integer_indices_0 < array_arguments.length;++integer_indices_0) {const string_argument = array_arguments[integer_indices_0];("--delay" !== string_argument && "-d" !== string_argument) ||((float_sleep_duration = 1e3 * array_arguments[integer_indices_0 + 1]),array_arguments.splice(integer_indices_0, 2));try {void_print_information(ns, string_argument);} catch (error) {ns.tprint(JSON.stringify(error));}}if (float_sleep_duration < 1) break;await ns.sleep(float_sleep_duration);}};// functions - replacement in bin/lshw.js at line 32
const float_security_current = Math.round(ns.getServerSecurityLevel(string_server));const float_security_current = Math.round(ns.getServerSecurityLevel(string_server)); - replacement in bin/lshw.js at line 39
const string_server_information =// comment out unneeded info`const string_server_information =// comment out unneeded info` - replacement in bin/lshw.js at line 47
Current cash (%): ${(float_cash_current * 100 / float_cash_max).toFixed(2)}Current cash (%): ${((float_cash_current * 100) / float_cash_max).toFixed(2)} - replacement in bin/lshw.js at line 50
Current security (x): ${(float_security_current / float_security_minimum).toFixed(2)}Current security (x): ${(float_security_current / float_security_minimum).toFixed(2)} - replacement in bin/lshw.js at line 58
RAM used (%): ${(float_ram_used * 100 / float_ram_total).toFixed(2)}RAM used (%): ${((float_ram_used * 100) / float_ram_total).toFixed(2)} - replacement in bin/lshw.js at line 60
RAM free (%): ${(float_ram_free * 100 / float_ram_total).toFixed(2)}RAM free (%): ${((float_ram_free * 100) / float_ram_total).toFixed(2)} - replacement in bin/lshw.js at line 63[3.13470]→[3.13470:13474](∅→∅),[3.13474]→[3.3795204:3795246](∅→∅),[3.3795203]→[3.3795204:3795246](∅→∅),[3.3795246]→[3.13475:13737](∅→∅),[3.13737]→[3.2932:3010](∅→∅),[3.3010]→[3.13815:13825](∅→∅),[3.13815]→[3.13815:13825](∅→∅),[3.13825]→[3.4580:4658](∅→∅),[3.4658]→[3.13896:14225](∅→∅),[3.13896]→[3.13896:14225](∅→∅),[3.14225]→[3.3797079:3797086](∅→∅),[3.3797079]→[3.3797079:3797086](∅→∅)
};export const main = async function (ns) {let array_arguments = ns.args;let float_sleep_duration = 0;while (true) {for (let integer_indices_0 = 0; integer_indices_0 < array_arguments.length; ++integer_indices_0) {const string_argument = array_arguments[integer_indices_0];if ((string_argument === "--delay") ||(string_argument === "-d")) {float_sleep_duration = array_arguments[integer_indices_0 + 1] * 1000;array_arguments.splice(integer_indices_0, 2);}try {void_print_information(ns, string_argument);}catch (error) {ns.tprint(JSON.stringify(error));}}if (float_sleep_duration < 1) {break;}else {await ns.sleep(float_sleep_duration);}}};[3.13470]}; - replacement in bin/cp.js at line 2
import {array_get_servers}from "lib_servers.js";import { array_get_servers } from "lib_servers.js";import { array_get_files_to_copy } from "lib_ls.js"; - replacement in bin/cp.js at line 5
import {array_get_files_to_copy}from "lib_ls.js";// mainexport const main = async function (ns) {const array_arguments = ns.args;for (let integer_indices_0 = 0;integer_indices_0 < array_arguments.length;++integer_indices_0) {const string_substring = array_arguments[integer_indices_0];void_copy_files_with_to_current(ns, string_substring);}}; - edit in bin/cp.js at line 18
// functions - replacement in bin/cp.js at line 20
const void_copy_to_current = function(ns, string_server_source, string_file_to_copy) {const void_copy_to_current = function (ns,string_server_source,string_file_to_copy) { - replacement in bin/cp.js at line 27[3.3803347]→[3.7319:7427](∅→∅),[3.7427]→[3.3803347:3803486](∅→∅),[3.3803347]→[3.3803347:3803486](∅→∅)
ns.tprint(`Copied the file "${string_file_to_copy}" located in the server "${string_server_source}".`);} catch (error) {ns.tprint(`Attempted to copy the file "${string_file_to_copy}" located in the server "${string_server_source}".`);ns.tprint(`Copied the file "${string_file_to_copy}" located in the server "${string_server_source}".`);}catch (error) {ns.tprint(`Attempted to copy the file "${string_file_to_copy}" located in the server "${string_server_source}".`); - replacement in bin/cp.js at line 40
const void_copy_files_with_to_current = function(ns, string_substring) {const void_copy_files_with_to_current = function (ns, string_substring) { - replacement in bin/cp.js at line 42
for (let integer_indices_0 = 0; integer_indices_0 < array_servers.length; ++integer_indices_0) {const string_server_source = array_servers[integer_indices_0];const array_files_to_copy = array_get_files_to_copy(ns, string_server_source, string_substring);for (let integer_indices_1 = 0; integer_indices_1 < array_files_to_copy.length; ++integer_indices_1) {for (let integer_indices_0 = 0;integer_indices_0 < array_servers.length;++integer_indices_0) {const string_server_source = array_servers[integer_indices_0],array_files_to_copy = array_get_files_to_copy(ns,string_server_source,string_substring);for (let integer_indices_1 = 0;integer_indices_1 < array_files_to_copy.length;++integer_indices_1) { - edit in bin/cp.js at line 62
};export const main = async function (ns) {const array_arguments = ns.args;for (let integer_indices_0 = 0; integer_indices_0 < array_arguments.length; ++integer_indices_0) {const string_substring = array_arguments[integer_indices_0];void_copy_files_with_to_current(ns, string_substring);}