BUGFIX: Crash in b1tflum3 and destroyW0r1dD43m0n API (#1619)

This commit is contained in:
catloversg 2024-08-24 11:06:53 +07:00 committed by GitHub
parent 329d8ca8e6
commit be515cc195
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 5 deletions

@ -30,7 +30,7 @@ export function knowAboutBitverse(): boolean {
export function getDefaultBitNodeOptions(): BitNodeOptions { export function getDefaultBitNodeOptions(): BitNodeOptions {
return { return {
sourceFileOverrides: new Map<number, number>(), sourceFileOverrides: new JSONMap<number, number>(),
intelligenceOverride: undefined, intelligenceOverride: undefined,
restrictHomePCUpgrade: false, restrictHomePCUpgrade: false,
disableGang: false, disableGang: false,

@ -761,7 +761,7 @@ function validateBitNodeOptions(ctx: NetscriptContext, bitNodeOptions: unknown):
result.sourceFileOverrides = new JSONMap(options.sourceFileOverrides); result.sourceFileOverrides = new JSONMap(options.sourceFileOverrides);
if (options.intelligenceOverride !== undefined) { if (options.intelligenceOverride !== undefined) {
result.intelligenceOverride = number(ctx, "intelligenceOverride", options.intelligenceOverride); result.intelligenceOverride = positiveInteger(ctx, "intelligenceOverride", options.intelligenceOverride);
} else { } else {
result.intelligenceOverride = undefined; result.intelligenceOverride = undefined;
} }

@ -8,7 +8,7 @@ import { dialogBoxCreate } from "./ui/React/DialogBox";
import { Router } from "./ui/GameRoot"; import { Router } from "./ui/GameRoot";
import { Page } from "./ui/Router"; import { Page } from "./ui/Router";
import { prestigeSourceFile } from "./Prestige"; import { prestigeSourceFile } from "./Prestige";
import { setBitNodeOptions } from "./BitNode/BitNodeUtils"; import { getDefaultBitNodeOptions, setBitNodeOptions } from "./BitNode/BitNodeUtils";
function giveSourceFile(bitNodeNumber: number): void { function giveSourceFile(bitNodeNumber: number): void {
const sourceFileKey = "SourceFile" + bitNodeNumber.toString(); const sourceFileKey = "SourceFile" + bitNodeNumber.toString();
@ -69,12 +69,26 @@ export function enterBitNode(
Player.bitNodeN = newBitNode; Player.bitNodeN = newBitNode;
// Set BitNode options // Set BitNode options
setBitNodeOptions(bitNodeOptions); try {
setBitNodeOptions(bitNodeOptions);
} catch (error) {
dialogBoxCreate(
<>
Invalid BitNode options. This is a bug. Please report it to developers.
<br />
<br />
{error instanceof Error ? error.stack : String(error)}
</>,
);
// Use default options
setBitNodeOptions(getDefaultBitNodeOptions());
}
prestigeSourceFile(isFlume);
if (newBitNode === 6) { if (newBitNode === 6) {
Router.toPage(Page.BladeburnerCinematic); Router.toPage(Page.BladeburnerCinematic);
} else { } else {
Router.toPage(Page.Terminal); Router.toPage(Page.Terminal);
} }
prestigeSourceFile(isFlume);
} }