Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SK3Artemis authored Oct 30, 2024
1 parent c512046 commit 160049c
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 32 deletions.
14 changes: 14 additions & 0 deletions 1ks1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// run 1000 scripts at once Achievement
export async function main(ns) {
let script = "export async function main(ns) { while(true){ await ns.sleep(100000); } }";
let pids = [];
for (let i = 0; i < 1000; i++) {
await ns.write(`/k/script${i}.js`, script, "w");
pids.push(ns.run(`/k/script${i}.js`));
}
await ns.sleep(2*60*1000);
for (let i = 0; i < 1000; i++) {
ns.kill(pids[i]);
ns.rm(`/k/script${i}.js`);
}
}
4 changes: 4 additions & 0 deletions React1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @param {NS} ns */ //Secret....
export async function main(ns) {
ns.tprint(React)
}
12 changes: 12 additions & 0 deletions apr1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @param {NS} ns */
export async function main(ns) {
// Exploit to enter and run the command on the terminal, must be on the terminal tab to work
try {
const terminalInput = eval('document').getElementById("terminal-input");
terminalInput.value = "apr1"; // whatever command you want to run here
const handler = Object.keys(terminalInput)[1];
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
}
catch { }
}
8 changes: 8 additions & 0 deletions bypass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @param {NS} ns */
export async function main(ns) {
let doc = eval("document");
// ns.tprint("args: "+ns.args);
// let doc = ns.args[0];
ns.bypass(doc);
ns.tprint(doc);
}
8 changes: 8 additions & 0 deletions click1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @param {NS} ns **/
export async function main(ns) {
const doc = eval("document");
doc.getElementById('unclickable').style = "display: block;position: absolute;top: 50%;left: 50%;width: 100px;height: 100px;z-index: 10000;background: red;";
doc.getElementById('unclickable').parentNode.addEventListener('click', () => {
doc.getElementById('unclickable').style = "display: none; visibility: hidden;";
}, true);
}
12 changes: 12 additions & 0 deletions ex-run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @param {NS} ns */
export async function main(ns) {
// Exploit to enter and run the command on the terminal, must be on the terminal tab to work
try {
const terminalInput = eval('document').getElementById("terminal-input");
terminalInput.value = "nano ex-run.js"; // whatever command you want to run here
const handler = Object.keys(terminalInput)[1];
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
}
catch { }
}
77 changes: 77 additions & 0 deletions fns1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* Free NetScript!
*/
export class FNS {
/** @param {NS} ns */
constructor(ns, path="ns.") {
return new Proxy(this, {
get: function (target, property) {
property = property.replace("$", "");

let cost = NaN;
try {
cost = ns.getFunctionRamCost(path.slice(3) + property);
} catch (e) {
if (!(e.message && e.message.endsWith("invalid type"))) {
if (typeof e === "string") {
throw new Error(e);
} else {
throw e;
}
}
}

if (cost >= 0) { // this is a valid ns function
return async (...args) => {
return await runGhostScript(ns, path + property, args);
}
} else { // this is a valid ns object
return new FNS(ns, path + property + ".");
}
}
});
}
}

/** @param {NS} ns */
async function runGhostScript(ns, func, args) {
const expr = `${func}(${args.map(a => JSON.stringify(a))})`

const resultPid = ns.run("fns/fns.js", {ramOverride: 1.6 + ns.getFunctionRamCost(func.slice(3))}, expr);
if (resultPid === 0) {
throw new Error("Unable to run ghost script!");
} else {
await ns.getPortHandle(resultPid).nextWrite();
}

const result = JSON.parse(ns.readPort(resultPid));
if (typeof result === "number") {
return result;
} else if (result.error === null) {
return JSON.parse(result.result);
} else {
const error = new Error("An error was thrown when handling a ghost script!");
error.stack += "\n" + result.error.stack;
throw error;
}
}

/** @param {NS} ns */
export async function main(ns) {
const expr = ns.args[0];

let result = null, error = null;
try {
result = await eval(expr);
} catch (e) {
error = JSON.parse(JSON.stringify(e, Object.getOwnPropertyNames(e)));
}

ns.atExit(() => {
if (typeof result === "number") {
ns.writePort(ns.pid, result);
} else {
ns.writePort(ns.pid, JSON.stringify({result: JSON.stringify(result), error: error}));
}
})
}
12 changes: 8 additions & 4 deletions git-pull.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let options;
const argsSchema = [
['github', 'alainbryden'],
['github', 'SK3Artemis'],
['repository', 'bitburner-scripts'],
['branch', 'main'],
['download', []], // By default, all supported files in the repository will be downloaded. Override with just a subset of files here
Expand Down Expand Up @@ -40,8 +40,12 @@ export async function main(ns) {
else
ns.tprint(`WARNING: "${fullLocalFilePath}" was not updated. (Currently running, or not located at ${remoteFilePath}?)`)
}
ns.tprint(`INFO: Pull complete. If you have any questions or issues, head over to the Bitburner #alains-scripts Discord channel: ` +
`https://discord.com/channels/415207508303544321/935667531111342200`);
ns.tprint(`[Edit by SK_] ` +

`INFO: Pull complete. If you have any questions or issues, head over to the Bitburner #alains-scripts Discord channel: ` +
`https://discord.com/channels/415207508303544321/935667531111342200` +

`To start, type: "run autopilot.js" `);
// Remove any temp files / scripts from the prior version
ns.run(pathJoin(options.subfolder, `cleanup.js`));
}
Expand Down Expand Up @@ -103,4 +107,4 @@ async function repositoryListing(ns, folder = '') {
return ns.ls('home').filter(name => options.extension.some(ext => f.endsWith(ext)) &&
!options['omit-folder'].some(dir => name.startsWith(dir)));
}
}
}
21 changes: 21 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>bb</title>
<link rel="stylesheet" href="styles.css">
<style>
body {
margin: 0;
background: grey;
}
p {
color: green;
}
</style>
</head>
<body>
<p>wget https://raw.githubusercontent.com/sk3artemis/bitburner-scripts/master/git-pull.js git-pull.js</p> <!-- (wget url) -->
</body>
</html>
8 changes: 8 additions & 0 deletions k/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// delete these 1000 scripts if they remain....
export async function main(ns) {
let pids = [];
for (let i = 0; i < 1000; i++) {
ns.kill(pids[i]);
ns.rm(`/k/script${i}.js`);
}
}
12 changes: 12 additions & 0 deletions k/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @param {NS} ns */
export async function main(ns) {
// Exploit to enter and run the command on the terminal, must be on the terminal tab to work
try {
const terminalInput = eval('document').getElementById("terminal-input");
terminalInput.value = "run 1ks1.js"; // whatever command you want to run here
const handler = Object.keys(terminalInput)[1];
terminalInput[handler].onChange({ target: terminalInput });
terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });
}
catch { }
}
55 changes: 55 additions & 0 deletions noodles1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
function makeWayToNoodleBar() {
let doc = eval('document');
const mainGameButtons = doc.getElementsByClassName('MuiButtonBase-root');
for (const button of mainGameButtons) { if (button.outerText === 'Travel') { button.click(); break; } }
doc = eval('document');
const travelPageSpans = doc.getElementsByTagName("SPAN")
for (const span of travelPageSpans) { if (span.outerText === 'N') { span.click(); break; } }
for (const button of mainGameButtons) { if (button.outerText === 'City') { button.click(); break; } }
doc = eval('document');
const newTokyoCityPageSpans = doc.getElementsByTagName("SPAN")
for (const span of newTokyoCityPageSpans) { if (span.ariaLabel === "Noodle Bar") { span.click(); break; } }
}

function isNoodlesButton(){
const doc = eval('document');
const buttonsByTagName = doc.getElementsByClassName('MuiButtonBase-root');
for (const button of buttonsByTagName) {
if (button.textContent === 'Eat noodles') { return true; }
}
return false;
}

function eatNoodles() {
const doc = eval('document');
const buttonsByTagName = doc.getElementsByClassName('MuiButtonBase-root');
for (const button of buttonsByTagName) {
if (button.textContent === 'Eat noodles') { button.click(); return; }
}
}

/** @param {NS} ns */
export async function main(ns) {
ns.tail();
makeWayToNoodleBar();
const startTime = Date.now();
let lastSleep = startTime;
let lastFocus = startTime;
let fundsHistory = [];
while (true) {
if (isNoodlesButton()){
eatNoodles(ns);
if (Date.now() > lastSleep + 100) { // every 100ms...
await ns.asleep(0);
lastSleep = Date.now();
}
if (Date.now() > lastFocus + (1000 * 60 * 60)) { // every hour...
makeWayToNoodleBar();
await ns.asleep(0);
lastFocus = Date.now();
}
} else {
await ns.asleep(1000);
}
}
}
109 changes: 109 additions & 0 deletions os-install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
let options;
const argsSchema = [
['github', 'SK3Artemis'],
['repository', 'Bitburner_os'],
['branch', 'main'],
['download', []], // By default, all supported files in the repository will be downloaded. Override with just a subset of files here
['new-file', []], // If a repository listing fails, only files returned by ns.ls() will be downloaded. You can add additional files to seek out here.
['subfolder', ''], // Can be set to download to a sub-folder that is not part of the remote repository structure
['extension', ['.js', '.ns', '.txt', '.script']], // Files to download by extension
['omit-folder', ['Temp/']], // Folders to omit when getting a list of files to update (TODO: This may be obsolete now that we get a list of files from github itself.)
];

export function autocomplete(data, args) {
data.flags(argsSchema);
const lastFlag = args.length > 1 ? args[args.length - 2] : null;
if (["--download", "--subfolder", "--omit-folder"].includes(lastFlag))
return data.scripts;
return [];
}

/** @param {NS} ns
* Will try to download a fresh version of every file on the current server.
* You are responsible for:
* - Backing up your save / scripts first (try `download *` in the terminal)
* - Ensuring you have no local changes that you don't mind getting overwritten **/
export async function main(ns) {
options = ns.flags(argsSchema);
// Once upon a time, the game API required folders to have a leading slash
// As of 2.3.1, not only is this no longer needed, but it can break the game.
options.subfolder = options.subfolder ? trimSlash(options.subfolder) : // Remove leading slash from any user-specified folder
ns.getScriptName().substring(0, ns.getScriptName().lastIndexOf('/')); // Default to the current folder
const baseUrl = `raw.githubusercontent.com/${options.github}/${options.repository}/${options.branch}/`;
const filesToDownload = options['new-file'].concat(options.download.length > 0 ? options.download : await repositoryListing(ns));
for (const localFilePath of filesToDownload) {
let fullLocalFilePath = pathJoin(options.subfolder, localFilePath);
const remoteFilePath = `https://` + pathJoin(baseUrl, localFilePath);
ns.print(`Trying to update "${fullLocalFilePath}" from ${remoteFilePath} ...`);
if (await ns.wget(`${remoteFilePath}?ts=${new Date().getTime()}`, fullLocalFilePath) && rewriteFileForSubfolder(ns, fullLocalFilePath))
ns.tprint(`SUCCESS: Updated "${fullLocalFilePath}" to the latest from ${remoteFilePath}`);
else
ns.tprint(`WARNING: "${fullLocalFilePath}" was not updated. (Currently running, or not located at ${remoteFilePath}?)`)
}
ns.tprint(`[Edit by SK_Artemis] ` +

`INFO: Pull complete. To start, type: "run os/main.js" ` +

`To Install bb-vue type: "run install.js" `);
// Remove any temp files / scripts from the prior version
ns.run(pathJoin(options.subfolder, `cleanup.js`));
}

/** Removes leading and trailing slashes from the specified string */
function trimSlash(s) {
// Once upon a time, the game API required folders to have a leading slash
// As of 2.3.1, not only is this no longer needed, but it can break the game.
if (s.startsWith('/'))
s = s.slice(1);
if (s.endsWith('/'))
s = s.slice(0, -1);
return s;
}

/** Joins all arguments as components in a path, e.g. pathJoin("foo", "bar", "/baz") = "foo/bar/baz" **/
function pathJoin(...args) {
return trimSlash(args.filter(s => !!s).join('/').replace(/\/\/+/g, '/'));
}

/** @param {NS} ns
* Rewrites a file with path substitions to handle downloading to a subfolder. **/
export function rewriteFileForSubfolder(ns, path) {
if (!options.subfolder || path.includes('git-pull.js'))
return true;
let contents = ns.read(path);
// Replace subfolder reference in helpers.js getFilePath:
contents = contents.replace(`const subfolder = ''`, `const subfolder = '${options.subfolder}/'`);
// Replace any imports, which can't use getFilePath, but only if they don't specify a relative path (../)
contents = contents.replace(/from '(\.\/)?((?!\.\.\/).*)'/g, `from '${pathJoin(options.subfolder, '$2')}'`);
ns.write(path, contents, 'w');
return true;
}

/** @param {NS} ns
* Gets a list of files to download, either from the github repository (if supported), or using a local directory listing **/
async function repositoryListing(ns, folder = '') {
// Note: Limit of 60 free API requests per day, don't over-do it
const listUrl = `https://api.github.com/repos/${options.github}/${options.repository}/contents/${folder}?ref=${options.branch}`
let response = null;
try {
response = await fetch(listUrl); // Raw response
// Expect an array of objects: [{path:"", type:"[file|dir]" },{...},...]
response = await response.json(); // Deserialized
// Sadly, we must recursively retrieve folders, which eats into our 60 free API requests per day.
const folders = response.filter(f => f.type == "dir").map(f => f.path);
let files = response.filter(f => f.type == "file").map(f => f.path)
.filter(f => options.extension.some(ext => f.endsWith(ext)));
ns.print(`The following files exist at ${listUrl}\n${files.join(", ")}`);
for (const folder of folders)
files = files.concat((await repositoryListing(ns, folder))
.map(f => `/${f}`)); // Game requires folders to have a leading slash
return files;
} catch (error) {
if (folder !== '') throw error; // Propagate the error if this was a recursive call.
ns.tprint(`WARNING: Failed to get a repository listing (GitHub API request limit of 60 reached?): ${listUrl}` +
`\nResponse Contents (if available): ${JSON.stringify(response ?? '(N/A)')}\nError: ${String(error)}`);
// Fallback, assume the user already has a copy of all files in the repo, and use it as a directory listing
return ns.ls('home').filter(name => options.extension.some(ext => f.endsWith(ext)) &&
!options['omit-folder'].some(dir => name.startsWith(dir)));
}
}
10 changes: 10 additions & 0 deletions speed1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @param {NS} ns */
export async function main(ns) {
let win = eval("window");
win.st = win.setTimeout;
win.si = win.setInterval;
win.setTimeout = (a, b) => win.st(a, 1);
win.setInterval = (a, b) => win.si(a, 1);
ns.atExit(() => {win.setTimeout = win.st; win.setInterval = win.si;});
while (true) {await ns.sleep(1000);}
}
Loading

0 comments on commit 160049c

Please sign in to comment.