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