2021-10-05 04:25:21 +02:00
|
|
|
import { IPlayer } from "../PersonObjects/IPlayer";
|
|
|
|
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-05-25 00:34:00 +02:00
|
|
|
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
2021-10-05 04:25:21 +02:00
|
|
|
|
|
|
|
export interface INetscriptExtra {
|
|
|
|
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;
|
2021-10-05 04:25:21 +02:00
|
|
|
}
|
|
|
|
|
2022-05-25 00:34:00 +02:00
|
|
|
export function NetscriptExtra(player: IPlayer): InternalAPI<INetscriptExtra> {
|
2021-10-05 04:25:21 +02:00
|
|
|
return {
|
|
|
|
heart: {
|
|
|
|
// Easter egg function
|
2022-05-25 00:34:00 +02:00
|
|
|
break: () => (): number => {
|
2021-10-05 04:25:21 +02:00
|
|
|
return player.karma;
|
|
|
|
},
|
|
|
|
},
|
2022-05-25 00:34:00 +02:00
|
|
|
openDevMenu: () => (): void => {
|
2022-04-13 19:47:48 +02:00
|
|
|
devMenu.emit();
|
|
|
|
},
|
2022-05-25 00:34:00 +02:00
|
|
|
exploit: () => (): void => {
|
2021-10-05 04:25:21 +02:00
|
|
|
player.giveExploit(Exploit.UndocumentedFunctionCall);
|
|
|
|
},
|
2022-05-25 00:34:00 +02:00
|
|
|
bypass:
|
|
|
|
(ctx: NetscriptContext) =>
|
|
|
|
(doc: unknown): void => {
|
|
|
|
// reset both fields first
|
|
|
|
const d = doc as any;
|
|
|
|
d.completely_unused_field = undefined;
|
|
|
|
const real_document: any = document;
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
alterReality: () => (): void => {
|
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!");
|
|
|
|
player.giveExploit(Exploit.RealityAlteration);
|
|
|
|
}
|
|
|
|
},
|
2022-05-25 00:34:00 +02:00
|
|
|
rainbow:
|
|
|
|
(ctx: NetscriptContext) =>
|
|
|
|
(guess: unknown): boolean => {
|
|
|
|
function tryGuess(): boolean {
|
|
|
|
// eslint-disable-next-line no-sync
|
|
|
|
const verified = bcrypt.compareSync(
|
|
|
|
ctx.helper.string("guess", guess),
|
|
|
|
"$2a$10$aertxDEkgor8baVtQDZsLuMwwGYmkRM/ohcA6FjmmzIHQeTCsrCcO",
|
|
|
|
);
|
|
|
|
if (verified) {
|
|
|
|
player.giveExploit(Exploit.INeedARainbow);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2022-03-16 19:34:05 +01:00
|
|
|
}
|
2022-05-25 00:34:00 +02:00
|
|
|
return tryGuess();
|
|
|
|
},
|
2021-10-05 04:25:21 +02:00
|
|
|
};
|
|
|
|
}
|