mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 22:22:26 +01:00
Merge pull request #3082 from CrafterKolyan/patch-3
Fix Static Ram Circumventing for all NS functions
This commit is contained in:
commit
5865f8a1ea
@ -550,6 +550,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return calculatePercentMoneyHacked(server, Player);
|
||||
},
|
||||
hackAnalyzeSecurity: function (threads: any): number {
|
||||
updateDynamicRam("hackAnalyzeSecurity", getRamCost(Player, "hackAnalyzeSecurity"));
|
||||
return CONSTANTS.ServerFortifyAmount * threads;
|
||||
},
|
||||
hackAnalyzeChance: function (hostname: any): any {
|
||||
@ -564,6 +565,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return calculateHackingChance(server, Player);
|
||||
},
|
||||
sleep: function (time: any): any {
|
||||
updateDynamicRam("sleep", getRamCost(Player, "sleep"));
|
||||
if (time === undefined) {
|
||||
throw makeRuntimeErrorMsg("sleep", "Takes 1 argument.");
|
||||
}
|
||||
@ -573,6 +575,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
});
|
||||
},
|
||||
asleep: function (time: any): any {
|
||||
updateDynamicRam("asleep", getRamCost(Player, "asleep"));
|
||||
if (time === undefined) {
|
||||
throw makeRuntimeErrorMsg("asleep", "Takes 1 argument.");
|
||||
}
|
||||
@ -650,6 +653,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return numCycleForGrowth(server, Number(growth), Player, cores);
|
||||
},
|
||||
growthAnalyzeSecurity: function (threads: any): number {
|
||||
updateDynamicRam("growthAnalyzeSecurity", getRamCost(Player, "growthAnalyzeSecurity"));
|
||||
return 2 * CONSTANTS.ServerFortifyAmount * threads;
|
||||
},
|
||||
weaken: function (hostname: any, { threads: requestedThreads }: any = {}): any {
|
||||
@ -701,10 +705,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
});
|
||||
},
|
||||
weakenAnalyze: function (threads: any, cores: any = 1): number {
|
||||
updateDynamicRam("weakenAnalyze", getRamCost(Player, "weakenAnalyze"));
|
||||
const coreBonus = 1 + (cores - 1) / 16;
|
||||
return CONSTANTS.ServerWeakenAmount * threads * coreBonus * BitNodeMultipliers.ServerWeakenRate;
|
||||
},
|
||||
share: function (): Promise<void> {
|
||||
updateDynamicRam("share", getRamCost(Player, "share"));
|
||||
workerScript.log("share", () => "Sharing this computer.");
|
||||
const end = StartSharing(workerScript.scriptRef.threads * calculateIntelligenceBonus(Player.intelligence, 2));
|
||||
return netscriptDelay(10000, workerScript).finally(function () {
|
||||
@ -713,21 +719,25 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
});
|
||||
},
|
||||
getSharePower: function (): number {
|
||||
updateDynamicRam("getSharePower", getRamCost(Player, "getSharePower"));
|
||||
return CalculateShareMult();
|
||||
},
|
||||
print: function (...args: any[]): void {
|
||||
updateDynamicRam("print", getRamCost(Player, "print"));
|
||||
if (args.length === 0) {
|
||||
throw makeRuntimeErrorMsg("print", "Takes at least 1 argument.");
|
||||
}
|
||||
workerScript.print(argsToString(args));
|
||||
},
|
||||
printf: function (format: string, ...args: any[]): void {
|
||||
updateDynamicRam("printf", getRamCost(Player, "printf"));
|
||||
if (typeof format !== "string") {
|
||||
throw makeRuntimeErrorMsg("printf", "First argument must be string for the format.");
|
||||
}
|
||||
workerScript.print(vsprintf(format, args));
|
||||
},
|
||||
tprint: function (...args: any[]): void {
|
||||
updateDynamicRam("tprint", getRamCost(Player, "tprint"));
|
||||
if (args.length === 0) {
|
||||
throw makeRuntimeErrorMsg("tprint", "Takes at least 1 argument.");
|
||||
}
|
||||
@ -751,6 +761,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
Terminal.print(`${workerScript.scriptRef.filename}: ${str}`);
|
||||
},
|
||||
tprintf: function (format: any, ...args: any): any {
|
||||
updateDynamicRam("tprintf", getRamCost(Player, "tprintf"));
|
||||
if (typeof format !== "string") {
|
||||
throw makeRuntimeErrorMsg("tprintf", "First argument must be string for the format.");
|
||||
}
|
||||
@ -775,9 +786,11 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
Terminal.print(`${str}`);
|
||||
},
|
||||
clearLog: function (): any {
|
||||
updateDynamicRam("clearLog", getRamCost(Player, "clearLog"));
|
||||
workerScript.scriptRef.clearLog();
|
||||
},
|
||||
disableLog: function (fn: any): any {
|
||||
updateDynamicRam("disableLog", getRamCost(Player, "disableLog"));
|
||||
if (fn === "ALL") {
|
||||
for (fn of Object.keys(possibleLogs)) {
|
||||
workerScript.disableLogs[fn] = true;
|
||||
@ -791,6 +804,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
},
|
||||
enableLog: function (fn: any): any {
|
||||
updateDynamicRam("enableLog", getRamCost(Player, "enableLog"));
|
||||
if (fn === "ALL") {
|
||||
for (fn of Object.keys(possibleLogs)) {
|
||||
delete workerScript.disableLogs[fn];
|
||||
@ -803,12 +817,14 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
workerScript.log("enableLog", () => `Enabled logging for ${fn}`);
|
||||
},
|
||||
isLogEnabled: function (fn: any): any {
|
||||
updateDynamicRam("isLogEnabled", getRamCost(Player, "isLogEnabled"));
|
||||
if (possibleLogs[fn] === undefined) {
|
||||
throw makeRuntimeErrorMsg("isLogEnabled", `Invalid argument: ${fn}.`);
|
||||
}
|
||||
return !workerScript.disableLogs[fn];
|
||||
},
|
||||
getScriptLogs: function (fn: any, hostname: any, ...scriptArgs: any): any {
|
||||
updateDynamicRam("getScriptLogs", getRamCost(Player, "getScriptLogs"));
|
||||
const runningScriptObj = getRunningScript(fn, hostname, "getScriptLogs", scriptArgs);
|
||||
if (runningScriptObj == null) {
|
||||
workerScript.log("getScriptLogs", () => getCannotFindRunningScriptErrorMessage(fn, hostname, scriptArgs));
|
||||
@ -818,6 +834,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return runningScriptObj.logs.slice();
|
||||
},
|
||||
tail: function (fn: any, hostname: any = workerScript.hostname, ...scriptArgs: any): any {
|
||||
updateDynamicRam("tail", getRamCost(Player, "tail"));
|
||||
let runningScriptObj;
|
||||
if (arguments.length === 0) {
|
||||
runningScriptObj = workerScript.scriptRef;
|
||||
@ -1084,6 +1101,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return scriptsRunning;
|
||||
},
|
||||
exit: function (): any {
|
||||
updateDynamicRam("exit", getRamCost(Player, "exit"));
|
||||
workerScript.running = false; // Prevent workerScript from "finishing execution naturally"
|
||||
if (killWorkerScript(workerScript)) {
|
||||
workerScript.log("exit", () => "Exiting...");
|
||||
@ -1769,6 +1787,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return res;
|
||||
},
|
||||
writePort: function (port: any, data: any = ""): any {
|
||||
updateDynamicRam("writePort", getRamCost(Player, "writePort"));
|
||||
if (typeof data !== "string" && typeof data !== "number") {
|
||||
throw makeRuntimeErrorMsg(
|
||||
"writePort",
|
||||
@ -1857,6 +1876,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
},
|
||||
readPort: function (port: any): any {
|
||||
updateDynamicRam("readPort", getRamCost(Player, "readPort"));
|
||||
// Read from port
|
||||
const iport = helper.getValidPort("readPort", port);
|
||||
const x = iport.read();
|
||||
@ -1916,6 +1936,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return 0;
|
||||
},
|
||||
clearPort: function (port: any): any {
|
||||
updateDynamicRam("clearPort", getRamCost(Player, "clearPort"));
|
||||
// Clear port
|
||||
const iport = helper.getValidPort("clearPort", port);
|
||||
return iport.clear();
|
||||
@ -1964,6 +1985,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return suc;
|
||||
},
|
||||
getScriptName: function (): any {
|
||||
updateDynamicRam("getScriptName", getRamCost(Player, "getScriptName"));
|
||||
return workerScript.name;
|
||||
},
|
||||
getScriptRam: function (scriptname: any, hostname: any = workerScript.hostname): any {
|
||||
@ -2095,6 +2117,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
}
|
||||
},
|
||||
nFormat: function (n: any, format: any): any {
|
||||
updateDynamicRam("nFormat", getRamCost(Player, "nFormat"));
|
||||
if (isNaN(n) || isNaN(parseFloat(n)) || typeof format !== "string") {
|
||||
return "";
|
||||
}
|
||||
@ -2102,6 +2125,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return numeralWrapper.format(parseFloat(n), format);
|
||||
},
|
||||
tFormat: function (milliseconds: any, milliPrecision: any = false): any {
|
||||
updateDynamicRam("tFormat", getRamCost(Player, "tFormat"));
|
||||
return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision);
|
||||
},
|
||||
getTimeSinceLastAug: function (): any {
|
||||
@ -2109,10 +2133,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return Player.playtimeSinceLastAug;
|
||||
},
|
||||
alert: function (message: any): void {
|
||||
updateDynamicRam("alert", getRamCost(Player, "alert"));
|
||||
message = argsToString([message]);
|
||||
dialogBoxCreate(message);
|
||||
},
|
||||
toast: function (message: any, variant: any = "success", duration: any = 2000): void {
|
||||
updateDynamicRam("toast", getRamCost(Player, "toast"));
|
||||
if (!["success", "info", "warning", "error"].includes(variant))
|
||||
throw new Error(`variant must be one of "success", "info", "warning", or "error"`);
|
||||
|
||||
@ -2120,6 +2146,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
SnackbarEvents.emit(message, variant, duration);
|
||||
},
|
||||
prompt: function (txt: any): any {
|
||||
updateDynamicRam("prompt", getRamCost(Player, "prompt"));
|
||||
if (!isString(txt)) {
|
||||
txt = JSON.stringify(txt);
|
||||
}
|
||||
@ -2132,6 +2159,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
});
|
||||
},
|
||||
wget: async function (url: any, target: any, hostname: any = workerScript.hostname): Promise<boolean> {
|
||||
updateDynamicRam("wget", getRamCost(Player, "wget"));
|
||||
if (!isScriptFilename(target) && !target.endsWith(".txt")) {
|
||||
workerScript.log("wget", () => `Invalid target file: '${target}'. Must be a script or text file.`);
|
||||
return Promise.resolve(false);
|
||||
@ -2173,7 +2201,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return Math.floor(CONSTANTS.BaseFavorToDonate * BitNodeMultipliers.RepToDonateToFaction);
|
||||
},
|
||||
getOwnedSourceFiles: function (): SourceFileLvl[] {
|
||||
helper.updateDynamicRam("getOwnedSourceFiles", getRamCost(Player, "getOwnedSourceFiles"));
|
||||
updateDynamicRam("getOwnedSourceFiles", getRamCost(Player, "getOwnedSourceFiles"));
|
||||
const res: SourceFileLvl[] = [];
|
||||
for (let i = 0; i < Player.sourceFiles.length; ++i) {
|
||||
res.push({
|
||||
@ -2184,7 +2212,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return res;
|
||||
},
|
||||
getPlayer: function (): INetscriptPlayer {
|
||||
helper.updateDynamicRam("getPlayer", getRamCost(Player, "getPlayer"));
|
||||
updateDynamicRam("getPlayer", getRamCost(Player, "getPlayer"));
|
||||
|
||||
const data = {
|
||||
hacking: Player.hacking,
|
||||
@ -2280,6 +2308,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
||||
return data;
|
||||
},
|
||||
atExit: function (f: any): void {
|
||||
updateDynamicRam("atExit", getRamCost(Player, "atExit"));
|
||||
if (typeof f !== "function") {
|
||||
throw makeRuntimeErrorMsg("atExit", "argument should be function");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user