2023-01-06 02:30:34 +01:00
|
|
|
import type React from "react";
|
2022-10-11 22:07:45 +02:00
|
|
|
import { Player } from "../Player";
|
2021-10-05 04:25:21 +02:00
|
|
|
import { Exploit } from "../Exploits/Exploit";
|
2022-03-16 19:34:05 +01:00
|
|
|
import * as bcrypt from "bcryptjs";
|
2022-04-13 19:47:48 +02:00
|
|
|
import { Apr1Events as devMenu } from "../ui/Apr1";
|
2022-10-12 14:49:27 +02:00
|
|
|
import { InternalAPI } from "../Netscript/APIWrapper";
|
2022-08-08 19:43:41 +02:00
|
|
|
import { helpers } from "../Netscript/NetscriptHelpers";
|
2022-10-12 03:02:04 +02:00
|
|
|
import { Terminal } from "../Terminal";
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2023-01-06 02:41:24 +01:00
|
|
|
export type INetscriptExtra = {
|
2021-10-05 04:25:21 +02:00
|
|
|
heart: {
|
|
|
|
break(): number;
|
|
|
|
};
|
2022-04-13 19:47:48 +02:00
|
|
|
openDevMenu(): void;
|
2021-10-05 04:25:21 +02:00
|
|
|
exploit(): void;
|
|
|
|
bypass(doc: Document): void;
|
2021-10-27 05:02:46 +02:00
|
|
|
alterReality(): void;
|
2022-03-16 19:34:05 +01:00
|
|
|
rainbow(guess: string): void;
|
2022-10-12 03:02:04 +02:00
|
|
|
iKnowWhatImDoing(): void;
|
2023-01-06 02:30:34 +01:00
|
|
|
printRaw(value: React.ReactNode): void;
|
2023-01-06 02:41:24 +01:00
|
|
|
};
|
2021-10-05 04:25:21 +02:00
|
|
|
|
2022-08-09 21:41:47 +02:00
|
|
|
export function NetscriptExtra(): InternalAPI<INetscriptExtra> {
|
2021-10-05 04:25:21 +02:00
|
|
|
return {
|
|
|
|
heart: {
|
2023-02-28 01:54:04 +01:00
|
|
|
break: () => () => Player.karma,
|
2022-10-11 22:07:45 +02:00
|
|
|
},
|
2023-02-28 01:54:04 +01:00
|
|
|
openDevMenu: () => () => devMenu.emit(),
|
|
|
|
exploit: () => () => Player.giveExploit(Exploit.UndocumentedFunctionCall),
|
2022-10-12 14:49:27 +02:00
|
|
|
bypass: (ctx) => (doc) => {
|
2022-10-11 22:07:45 +02:00
|
|
|
// reset both fields first
|
|
|
|
type temporary = { completely_unused_field: unknown };
|
|
|
|
const d = doc as temporary;
|
|
|
|
d.completely_unused_field = undefined;
|
|
|
|
const real_document = document as unknown as temporary;
|
|
|
|
real_document.completely_unused_field = undefined;
|
|
|
|
// set one to true and check that it affected the other.
|
|
|
|
real_document.completely_unused_field = true;
|
|
|
|
if (d.completely_unused_field && ctx.workerScript.ramUsage === 1.6) {
|
|
|
|
Player.giveExploit(Exploit.Bypass);
|
|
|
|
}
|
|
|
|
d.completely_unused_field = undefined;
|
|
|
|
real_document.completely_unused_field = undefined;
|
2021-10-05 04:25:21 +02:00
|
|
|
},
|
2022-10-12 14:49:27 +02:00
|
|
|
alterReality: () => () => {
|
2021-11-13 01:28:52 +01:00
|
|
|
// We need to trick webpack into not optimizing a variable that is guaranteed to be false (and doesn't use prototypes)
|
|
|
|
let x = false;
|
|
|
|
const recur = function (depth: number): void {
|
|
|
|
if (depth === 0) return;
|
|
|
|
x = !x;
|
|
|
|
recur(depth - 1);
|
|
|
|
};
|
|
|
|
recur(2);
|
2021-10-27 21:55:11 +02:00
|
|
|
console.warn("I am sure that this variable is false.");
|
2021-10-27 05:02:46 +02:00
|
|
|
if (x !== false) {
|
|
|
|
console.warn("Reality has been altered!");
|
2022-10-11 22:07:45 +02:00
|
|
|
Player.giveExploit(Exploit.RealityAlteration);
|
2021-10-27 05:02:46 +02:00
|
|
|
}
|
|
|
|
},
|
2023-02-28 01:54:04 +01:00
|
|
|
rainbow: (ctx) => (_guess) => {
|
|
|
|
const guess = helpers.string(ctx, "guess", _guess);
|
|
|
|
const verified = bcrypt.compareSync(guess, "$2a$10$aertxDEkgor8baVtQDZsLuMwwGYmkRM/ohcA6FjmmzIHQeTCsrCcO");
|
|
|
|
if (!verified) return false;
|
|
|
|
Player.giveExploit(Exploit.INeedARainbow);
|
|
|
|
return true;
|
2022-10-11 22:07:45 +02:00
|
|
|
},
|
2022-10-12 03:02:04 +02:00
|
|
|
iKnowWhatImDoing: (ctx) => () => {
|
|
|
|
helpers.log(ctx, () => "Unlocking unsupported feature: window.tprintRaw");
|
|
|
|
// @ts-ignore window has no tprintRaw property defined
|
|
|
|
window.tprintRaw = Terminal.printRaw.bind(Terminal);
|
|
|
|
},
|
2023-01-06 02:30:34 +01:00
|
|
|
printRaw: (ctx) => (value) => {
|
|
|
|
// Using this voids the warranty on your tail log
|
|
|
|
ctx.workerScript.print(value as React.ReactNode);
|
|
|
|
},
|
2021-10-05 04:25:21 +02:00
|
|
|
};
|
|
|
|
}
|