2021-09-09 05:47:34 +02:00
|
|
|
import { loadAliases, loadGlobalAliases, Aliases, GlobalAliases } from "./Alias";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { Companies, loadCompanies } from "./Company/Companies";
|
|
|
|
import { CONSTANTS } from "./Constants";
|
|
|
|
import { Factions, loadFactions } from "./Faction/Factions";
|
2021-06-16 06:28:20 +02:00
|
|
|
import { loadAllGangs, AllGangs } from "./Gang/AllGangs";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { Player, loadPlayer } from "./Player";
|
2022-05-19 08:09:00 +02:00
|
|
|
import {
|
|
|
|
saveAllServers,
|
|
|
|
loadAllServers,
|
|
|
|
GetAllServers,
|
|
|
|
createUniqueRandomIp,
|
|
|
|
AddToAllServers,
|
|
|
|
GetServer,
|
|
|
|
} from "./Server/AllServers";
|
2019-04-11 10:37:40 +02:00
|
|
|
import { Settings } from "./Settings/Settings";
|
|
|
|
import { loadStockMarket, StockMarket } from "./StockMarket/StockMarket";
|
2021-09-25 23:21:50 +02:00
|
|
|
import { staneksGift, loadStaneksGift } from "./CotMG/Helper";
|
2019-02-20 09:42:27 +01:00
|
|
|
|
2022-04-13 07:50:35 +02:00
|
|
|
import { SnackbarEvents, ToastVariant } from "./ui/React/Snackbar";
|
2017-08-30 19:44:29 +02:00
|
|
|
|
2021-05-18 05:59:45 +02:00
|
|
|
import * as ExportBonus from "./ExportBonus";
|
2019-04-11 10:37:40 +02:00
|
|
|
|
2021-09-25 20:42:57 +02:00
|
|
|
import { dialogBoxCreate } from "./ui/React/DialogBox";
|
|
|
|
import { Reviver, Generic_toJSON, Generic_fromJSON } from "./utils/JSONReviver";
|
2021-09-21 22:49:38 +02:00
|
|
|
import { save } from "./db";
|
2021-11-03 03:11:22 +01:00
|
|
|
import { v1APIBreak } from "./utils/v1APIBreak";
|
2021-11-10 05:42:36 +01:00
|
|
|
import { AugmentationNames } from "./Augmentation/data/AugmentationNames";
|
|
|
|
import { PlayerOwnedAugmentation } from "./Augmentation/PlayerOwnedAugmentation";
|
2022-01-02 18:13:01 +01:00
|
|
|
import { LocationName } from "./Locations/data/LocationNames";
|
2022-01-25 14:16:48 +01:00
|
|
|
import { SxProps } from "@mui/system";
|
2022-01-18 17:53:30 +01:00
|
|
|
import { PlayerObject } from "./PersonObjects/Player/PlayerObject";
|
2022-01-18 18:21:53 +01:00
|
|
|
import { pushGameSaved } from "./Electron";
|
2022-04-18 18:44:00 +02:00
|
|
|
import { defaultMonacoTheme } from "./ScriptEditor/ui/themes";
|
2022-04-22 21:30:49 +02:00
|
|
|
import { FactionNames } from "./Faction/data/FactionNames";
|
|
|
|
import { Faction } from "./Faction/Faction";
|
2022-05-19 08:09:00 +02:00
|
|
|
import { safetlyCreateUniqueServer } from "./Server/ServerHelpers";
|
|
|
|
import { SpecialServers } from "./Server/data/SpecialServers";
|
2019-04-11 10:37:40 +02:00
|
|
|
|
2017-07-25 16:39:56 +02:00
|
|
|
/* SaveObject.js
|
|
|
|
* Defines the object used to save/load games
|
2017-05-05 03:08:44 +02:00
|
|
|
*/
|
|
|
|
|
2022-01-18 18:21:53 +01:00
|
|
|
export interface SaveData {
|
|
|
|
playerIdentifier: string;
|
|
|
|
fileName: string;
|
|
|
|
save: string;
|
|
|
|
savedOn: number;
|
|
|
|
}
|
|
|
|
|
2022-01-18 17:53:30 +01:00
|
|
|
export interface ImportData {
|
|
|
|
base64: string;
|
|
|
|
parsed: any;
|
|
|
|
playerData?: ImportPlayerData;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ImportPlayerData {
|
|
|
|
identifier: string;
|
|
|
|
lastSave: number;
|
|
|
|
totalPlaytime: number;
|
|
|
|
|
|
|
|
money: number;
|
|
|
|
hacking: number;
|
|
|
|
|
|
|
|
augmentations: number;
|
|
|
|
factions: number;
|
|
|
|
achievements: number;
|
|
|
|
|
|
|
|
bitNode: number;
|
|
|
|
bitNodeLevel: number;
|
|
|
|
sourceFiles: number;
|
|
|
|
}
|
|
|
|
|
2021-09-25 00:40:17 +02:00
|
|
|
class BitburnerSaveObject {
|
|
|
|
PlayerSave = "";
|
|
|
|
AllServersSave = "";
|
|
|
|
CompaniesSave = "";
|
|
|
|
FactionsSave = "";
|
|
|
|
AliasesSave = "";
|
|
|
|
GlobalAliasesSave = "";
|
|
|
|
StockMarketSave = "";
|
|
|
|
SettingsSave = "";
|
|
|
|
VersionSave = "";
|
|
|
|
AllGangsSave = "";
|
|
|
|
LastExportBonus = "";
|
2021-09-25 23:21:50 +02:00
|
|
|
StaneksGiftSave = "";
|
2021-09-25 00:40:17 +02:00
|
|
|
|
2022-01-11 22:48:00 +01:00
|
|
|
getSaveString(excludeRunningScripts = false): string {
|
2021-09-25 00:40:17 +02:00
|
|
|
this.PlayerSave = JSON.stringify(Player);
|
|
|
|
|
2022-01-11 22:48:00 +01:00
|
|
|
this.AllServersSave = saveAllServers(excludeRunningScripts);
|
2021-09-25 00:40:17 +02:00
|
|
|
this.CompaniesSave = JSON.stringify(Companies);
|
|
|
|
this.FactionsSave = JSON.stringify(Factions);
|
|
|
|
this.AliasesSave = JSON.stringify(Aliases);
|
|
|
|
this.GlobalAliasesSave = JSON.stringify(GlobalAliases);
|
|
|
|
this.StockMarketSave = JSON.stringify(StockMarket);
|
|
|
|
this.SettingsSave = JSON.stringify(Settings);
|
2021-11-03 03:49:46 +01:00
|
|
|
this.VersionSave = JSON.stringify(CONSTANTS.VersionNumber);
|
2021-09-25 00:40:17 +02:00
|
|
|
this.LastExportBonus = JSON.stringify(ExportBonus.LastExportBonus);
|
2021-09-25 23:21:50 +02:00
|
|
|
this.StaneksGiftSave = JSON.stringify(staneksGift);
|
2022-01-07 14:58:12 +01:00
|
|
|
|
2021-09-25 00:40:17 +02:00
|
|
|
if (Player.inGang()) {
|
|
|
|
this.AllGangsSave = JSON.stringify(AllGangs);
|
2017-10-12 04:00:22 +02:00
|
|
|
}
|
2021-09-25 07:26:03 +02:00
|
|
|
const saveString = btoa(unescape(encodeURIComponent(JSON.stringify(this))));
|
2021-09-25 00:40:17 +02:00
|
|
|
|
|
|
|
return saveString;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 17:53:30 +01:00
|
|
|
saveGame(emitToastEvent = true): Promise<void> {
|
2022-01-18 18:21:53 +01:00
|
|
|
const savedOn = new Date().getTime();
|
|
|
|
Player.lastSave = savedOn;
|
2022-01-11 22:48:00 +01:00
|
|
|
const saveString = this.getSaveString(Settings.ExcludeRunningScriptsFromSave);
|
2022-01-18 17:53:30 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
save(saveString)
|
|
|
|
.then(() => {
|
2022-01-18 18:21:53 +01:00
|
|
|
const saveData: SaveData = {
|
|
|
|
playerIdentifier: Player.identifier,
|
|
|
|
fileName: this.getSaveFileName(),
|
|
|
|
save: saveString,
|
|
|
|
savedOn,
|
|
|
|
};
|
|
|
|
pushGameSaved(saveData);
|
|
|
|
|
2022-01-18 17:53:30 +01:00
|
|
|
if (emitToastEvent) {
|
2022-04-13 07:50:35 +02:00
|
|
|
SnackbarEvents.emit("Game Saved!", ToastVariant.INFO, 2000);
|
2022-01-18 17:53:30 +01:00
|
|
|
}
|
|
|
|
return resolve();
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
return reject();
|
|
|
|
});
|
|
|
|
});
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
2022-01-18 17:53:30 +01:00
|
|
|
getSaveFileName(isRecovery = false): string {
|
2021-09-25 00:40:17 +02:00
|
|
|
// Save file name is based on current timestamp and BitNode
|
|
|
|
const epochTime = Math.round(Date.now() / 1000);
|
|
|
|
const bn = Player.bitNodeN;
|
2022-04-14 07:22:50 +02:00
|
|
|
let filename = `bitburnerSave_${epochTime}_BN${bn}x${Player.sourceFileLvl(bn) + 1}.json`;
|
2022-01-18 17:53:30 +01:00
|
|
|
if (isRecovery) filename = "RECOVERY" + filename;
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
exportGame(): void {
|
|
|
|
const saveString = this.getSaveString(Settings.ExcludeRunningScriptsFromSave);
|
|
|
|
const filename = this.getSaveFileName();
|
2021-11-12 05:28:08 +01:00
|
|
|
download(filename, saveString);
|
2021-09-25 00:40:17 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2022-01-18 17:53:30 +01:00
|
|
|
importGame(base64Save: string, reload = true): Promise<void> {
|
|
|
|
if (!base64Save || base64Save === "") throw new Error("Invalid import string");
|
|
|
|
return save(base64Save).then(() => {
|
|
|
|
if (reload) setTimeout(() => location.reload(), 1000);
|
|
|
|
return Promise.resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getImportStringFromFile(files: FileList | null): Promise<string> {
|
|
|
|
if (files === null) return Promise.reject(new Error("No file selected"));
|
|
|
|
const file = files[0];
|
|
|
|
if (!file) return Promise.reject(new Error("Invalid file selected"));
|
|
|
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
const promise: Promise<string> = new Promise((resolve, reject) => {
|
|
|
|
reader.onload = function (this: FileReader, e: ProgressEvent<FileReader>) {
|
|
|
|
const target = e.target;
|
|
|
|
if (target === null) {
|
|
|
|
return reject(new Error("Error importing file"));
|
|
|
|
}
|
|
|
|
const result = target.result;
|
2022-03-01 20:37:47 +01:00
|
|
|
if (typeof result !== "string") {
|
2022-01-18 17:53:30 +01:00
|
|
|
return reject(new Error("FileReader event was not type string"));
|
|
|
|
}
|
|
|
|
const contents = result;
|
|
|
|
resolve(contents);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
reader.readAsText(file);
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getImportDataFromString(base64Save: string): Promise<ImportData> {
|
|
|
|
if (!base64Save || base64Save === "") throw new Error("Invalid import string");
|
|
|
|
|
|
|
|
let newSave;
|
|
|
|
try {
|
|
|
|
newSave = window.atob(base64Save);
|
|
|
|
newSave = newSave.trim();
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error); // We'll handle below
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newSave || newSave === "") {
|
|
|
|
return Promise.reject(new Error("Save game had not content or was not base64 encoded"));
|
|
|
|
}
|
|
|
|
|
|
|
|
let parsedSave;
|
|
|
|
try {
|
|
|
|
parsedSave = JSON.parse(newSave);
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error); // We'll handle below
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parsedSave || parsedSave.ctor !== "BitburnerSaveObject" || !parsedSave.data) {
|
|
|
|
return Promise.reject(new Error("Save game did not seem valid"));
|
|
|
|
}
|
|
|
|
|
|
|
|
const data: ImportData = {
|
|
|
|
base64: base64Save,
|
|
|
|
parsed: parsedSave,
|
|
|
|
};
|
|
|
|
|
|
|
|
const importedPlayer = PlayerObject.fromJSON(JSON.parse(parsedSave.data.PlayerSave));
|
|
|
|
|
|
|
|
const playerData: ImportPlayerData = {
|
|
|
|
identifier: importedPlayer.identifier,
|
|
|
|
lastSave: importedPlayer.lastSave,
|
|
|
|
totalPlaytime: importedPlayer.totalPlaytime,
|
|
|
|
|
|
|
|
money: importedPlayer.money,
|
|
|
|
hacking: importedPlayer.hacking,
|
|
|
|
|
|
|
|
augmentations: importedPlayer.augmentations?.reduce<number>((total, current) => (total += current.level), 0) ?? 0,
|
|
|
|
factions: importedPlayer.factions?.length ?? 0,
|
|
|
|
achievements: importedPlayer.achievements?.length ?? 0,
|
|
|
|
|
|
|
|
bitNode: importedPlayer.bitNodeN,
|
|
|
|
bitNodeLevel: importedPlayer.sourceFileLvl(Player.bitNodeN) + 1,
|
|
|
|
sourceFiles: importedPlayer.sourceFiles?.reduce<number>((total, current) => (total += current.lvl), 0) ?? 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
data.playerData = playerData;
|
|
|
|
return Promise.resolve(data);
|
|
|
|
}
|
|
|
|
|
2021-09-25 00:40:17 +02:00
|
|
|
toJSON(): any {
|
|
|
|
return Generic_toJSON("BitburnerSaveObject", this);
|
|
|
|
}
|
2017-09-19 20:38:03 +02:00
|
|
|
|
2021-09-25 00:40:17 +02:00
|
|
|
static fromJSON(value: { data: any }): BitburnerSaveObject {
|
|
|
|
return Generic_fromJSON(BitburnerSaveObject, value.data);
|
|
|
|
}
|
|
|
|
}
|
2017-05-05 03:08:44 +02:00
|
|
|
|
2018-11-16 04:45:03 +01:00
|
|
|
// Makes necessary changes to the loaded/imported data to ensure
|
|
|
|
// the game stills works with new versions
|
2021-11-03 03:11:22 +01:00
|
|
|
function evaluateVersionCompatibility(ver: string | number): void {
|
2021-09-25 00:40:17 +02:00
|
|
|
// We have to do this because ts won't let us otherwise
|
|
|
|
const anyPlayer = Player as any;
|
2021-11-03 03:11:22 +01:00
|
|
|
if (typeof ver === "string") {
|
|
|
|
// This version refactored the Company/job-related code
|
|
|
|
if (ver <= "0.41.2") {
|
|
|
|
// Player's company position is now a string
|
|
|
|
if (anyPlayer.companyPosition != null && typeof anyPlayer.companyPosition !== "string") {
|
|
|
|
anyPlayer.companyPosition = anyPlayer.companyPosition.data.positionName;
|
|
|
|
if (anyPlayer.companyPosition == null) {
|
|
|
|
anyPlayer.companyPosition = "";
|
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2019-01-15 04:34:04 +01:00
|
|
|
|
2021-11-03 03:11:22 +01:00
|
|
|
// The "companyName" property of all Companies is renamed to "name"
|
2022-01-16 01:45:03 +01:00
|
|
|
for (const companyName of Object.keys(Companies)) {
|
2021-11-03 03:11:22 +01:00
|
|
|
const company: any = Companies[companyName];
|
|
|
|
if (company.name == 0 && company.companyName != null) {
|
|
|
|
company.name = company.companyName;
|
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2021-11-03 03:11:22 +01:00
|
|
|
if (company.companyPositions instanceof Array) {
|
|
|
|
const pos: any = {};
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2021-11-03 03:11:22 +01:00
|
|
|
for (let i = 0; i < company.companyPositions.length; ++i) {
|
|
|
|
pos[company.companyPositions[i]] = true;
|
|
|
|
}
|
|
|
|
company.companyPositions = pos;
|
2019-01-15 04:34:04 +01:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2019-01-15 04:34:04 +01:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2021-11-03 03:11:22 +01:00
|
|
|
// This version allowed players to hold multiple jobs
|
|
|
|
if (ver < "0.43.0") {
|
|
|
|
if (anyPlayer.companyName !== "" && anyPlayer.companyPosition != null && anyPlayer.companyPosition !== "") {
|
|
|
|
anyPlayer.jobs[anyPlayer.companyName] = anyPlayer.companyPosition;
|
2021-10-12 06:29:16 +02:00
|
|
|
}
|
2021-11-03 03:11:22 +01:00
|
|
|
|
|
|
|
delete anyPlayer.companyPosition;
|
2021-10-12 06:29:16 +02:00
|
|
|
}
|
2021-11-03 03:11:22 +01:00
|
|
|
if (ver < "0.56.0") {
|
|
|
|
for (const q of anyPlayer.queuedAugmentations) {
|
|
|
|
if (q.name === "Graphene BranchiBlades Upgrade") {
|
|
|
|
q.name = "Graphene BrachiBlades Upgrade";
|
|
|
|
}
|
2021-10-12 06:29:16 +02:00
|
|
|
}
|
2021-11-03 03:11:22 +01:00
|
|
|
for (const q of anyPlayer.augmentations) {
|
|
|
|
if (q.name === "Graphene BranchiBlades Upgrade") {
|
|
|
|
q.name = "Graphene BrachiBlades Upgrade";
|
|
|
|
}
|
2021-10-12 06:29:16 +02:00
|
|
|
}
|
|
|
|
}
|
2021-11-03 03:11:22 +01:00
|
|
|
if (ver < "0.56.1") {
|
|
|
|
if (anyPlayer.bladeburner === 0) {
|
|
|
|
anyPlayer.bladeburner = null;
|
|
|
|
}
|
|
|
|
if (anyPlayer.gang === 0) {
|
|
|
|
anyPlayer.gang = null;
|
|
|
|
}
|
|
|
|
if (anyPlayer.corporation === 0) {
|
|
|
|
anyPlayer.corporation = null;
|
|
|
|
}
|
|
|
|
// convert all Messages to just filename to save space.
|
|
|
|
const home = anyPlayer.getHomeComputer();
|
|
|
|
for (let i = 0; i < home.messages.length; i++) {
|
|
|
|
if (home.messages[i].filename) {
|
|
|
|
home.messages[i] = home.messages[i].filename;
|
|
|
|
}
|
2021-10-27 21:16:16 +02:00
|
|
|
}
|
2021-10-13 01:23:36 +02:00
|
|
|
}
|
2021-11-03 03:11:22 +01:00
|
|
|
if (ver < "0.58.0") {
|
|
|
|
const changes: [RegExp, string][] = [
|
|
|
|
[/getStockSymbols/g, "stock.getSymbols"],
|
|
|
|
[/getStockPrice/g, "stock.getPrice"],
|
|
|
|
[/getStockAskPrice/g, "stock.getAskPrice"],
|
|
|
|
[/getStockBidPrice/g, "stock.getBidPrice"],
|
|
|
|
[/getStockPosition/g, "stock.getPosition"],
|
|
|
|
[/getStockMaxShares/g, "stock.getMaxShares"],
|
|
|
|
[/getStockPurchaseCost/g, "stock.getPurchaseCost"],
|
|
|
|
[/getStockSaleGain/g, "stock.getSaleGain"],
|
|
|
|
[/buyStock/g, "stock.buy"],
|
|
|
|
[/sellStock/g, "stock.sell"],
|
|
|
|
[/shortStock/g, "stock.short"],
|
|
|
|
[/sellShort/g, "stock.sellShort"],
|
|
|
|
[/placeOrder/g, "stock.placeOrder"],
|
|
|
|
[/cancelOrder/g, "stock.cancelOrder"],
|
|
|
|
[/getOrders/g, "stock.getOrders"],
|
|
|
|
[/getStockVolatility/g, "stock.getVolatility"],
|
|
|
|
[/getStockForecast/g, "stock.getForecast"],
|
|
|
|
[/purchase4SMarketData/g, "stock.purchase4SMarketData"],
|
|
|
|
[/purchase4SMarketDataTixApi/g, "stock.purchase4SMarketDataTixApi"],
|
|
|
|
];
|
|
|
|
function convert(code: string): string {
|
|
|
|
for (const change of changes) {
|
|
|
|
code = code.replace(change[0], change[1]);
|
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
for (const server of GetAllServers()) {
|
|
|
|
for (const script of server.scripts) {
|
|
|
|
script.code = convert(script.code);
|
|
|
|
}
|
2021-10-27 21:16:16 +02:00
|
|
|
}
|
2021-10-13 01:23:36 +02:00
|
|
|
}
|
2021-11-03 03:11:22 +01:00
|
|
|
v1APIBreak();
|
2021-11-10 05:42:36 +01:00
|
|
|
ver = 1;
|
|
|
|
}
|
|
|
|
if (typeof ver === "number") {
|
|
|
|
if (ver < 2) {
|
|
|
|
// Give 10 neuroflux because v1 API break.
|
|
|
|
const nf = Player.augmentations.find((a) => a.name === AugmentationNames.NeuroFluxGovernor);
|
|
|
|
if (nf) {
|
|
|
|
nf.level += 10;
|
|
|
|
} else {
|
|
|
|
const nf = new PlayerOwnedAugmentation(AugmentationNames.NeuroFluxGovernor);
|
|
|
|
nf.level = 10;
|
|
|
|
Player.augmentations.push(nf);
|
|
|
|
}
|
|
|
|
Player.reapplyAllAugmentations(true);
|
|
|
|
Player.reapplyAllSourceFiles();
|
2021-10-13 01:23:36 +02:00
|
|
|
}
|
2021-11-12 04:43:40 +01:00
|
|
|
if (ver < 3) {
|
|
|
|
anyPlayer.money = parseFloat(anyPlayer.money);
|
|
|
|
if (anyPlayer.corporation) {
|
|
|
|
anyPlayer.corporation.funds = parseFloat(anyPlayer.corporation.funds);
|
|
|
|
anyPlayer.corporation.revenue = parseFloat(anyPlayer.corporation.revenue);
|
|
|
|
anyPlayer.corporation.expenses = parseFloat(anyPlayer.corporation.expenses);
|
|
|
|
|
|
|
|
for (let i = 0; i < anyPlayer.corporation.divisions.length; ++i) {
|
|
|
|
const ind = anyPlayer.corporation.divisions[i];
|
|
|
|
ind.lastCycleRevenue = parseFloat(ind.lastCycleRevenue);
|
|
|
|
ind.lastCycleExpenses = parseFloat(ind.lastCycleExpenses);
|
|
|
|
ind.thisCycleRevenue = parseFloat(ind.thisCycleRevenue);
|
|
|
|
ind.thisCycleExpenses = parseFloat(ind.thisCycleExpenses);
|
|
|
|
}
|
2021-10-14 08:07:05 +02:00
|
|
|
}
|
|
|
|
}
|
2022-01-02 18:13:01 +01:00
|
|
|
if (ver < 9) {
|
|
|
|
if (StockMarket.hasOwnProperty("Joes Guns")) {
|
|
|
|
const s = StockMarket["Joes Guns"];
|
|
|
|
delete StockMarket["Joes Guns"];
|
|
|
|
StockMarket[LocationName.Sector12JoesGuns] = s;
|
|
|
|
}
|
|
|
|
}
|
2022-01-09 11:57:50 +01:00
|
|
|
if (ver < 10) {
|
|
|
|
// Augmentation name was changed in 0.56.0 but sleeves aug list was missed.
|
|
|
|
if (anyPlayer.sleeves && anyPlayer.sleeves.length > 0) {
|
|
|
|
for (const sleeve of anyPlayer.sleeves) {
|
|
|
|
if (!sleeve.augmentations || sleeve.augmentations.length === 0) continue;
|
|
|
|
for (const augmentation of sleeve.augmentations) {
|
|
|
|
if (augmentation.name !== "Graphene BranchiBlades Upgrade") continue;
|
|
|
|
augmentation.name = "Graphene BrachiBlades Upgrade";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-29 20:09:17 +02:00
|
|
|
if (ver < 12) {
|
|
|
|
if (anyPlayer.resleeves !== undefined) {
|
|
|
|
delete anyPlayer.resleeves;
|
|
|
|
}
|
|
|
|
}
|
2022-04-18 18:44:00 +02:00
|
|
|
if (ver < 15) {
|
|
|
|
(Settings as any).EditorTheme = { ...defaultMonacoTheme };
|
2022-04-13 23:50:01 +02:00
|
|
|
}
|
2022-04-26 03:12:46 +02:00
|
|
|
//Fix contract names
|
|
|
|
if (ver < 16) {
|
2022-04-22 21:30:49 +02:00
|
|
|
Factions[FactionNames.ShadowsOfAnarchy] = new Faction(FactionNames.ShadowsOfAnarchy);
|
2022-04-26 03:12:46 +02:00
|
|
|
//Iterate over all contracts on all servers
|
|
|
|
for (const server of GetAllServers()) {
|
|
|
|
for (const contract of server.contracts) {
|
|
|
|
//Rename old "HammingCodes: Integer to encoded Binary" contracts
|
|
|
|
//to "HammingCodes: Integer to Encoded Binary"
|
|
|
|
if (contract.type == "HammingCodes: Integer to encoded Binary") {
|
|
|
|
contract.type = "HammingCodes: Integer to Encoded Binary";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-05 03:16:23 +02:00
|
|
|
|
|
|
|
// Fix bugged NFG accumulation in owned augmentations
|
|
|
|
if (ver < 17) {
|
|
|
|
let ownedNFGs = [...Player.augmentations];
|
|
|
|
ownedNFGs = ownedNFGs.filter((aug) => aug.name === AugmentationNames.NeuroFluxGovernor);
|
|
|
|
const newNFG = new PlayerOwnedAugmentation(AugmentationNames.NeuroFluxGovernor);
|
|
|
|
newNFG.level = 0;
|
|
|
|
|
|
|
|
for (const nfg of ownedNFGs) {
|
|
|
|
newNFG.level += nfg.level;
|
|
|
|
}
|
|
|
|
|
|
|
|
Player.augmentations = [
|
|
|
|
...Player.augmentations.filter((aug) => aug.name !== AugmentationNames.NeuroFluxGovernor),
|
|
|
|
newNFG,
|
|
|
|
];
|
2022-05-05 08:02:05 +02:00
|
|
|
|
|
|
|
Player.reapplyAllAugmentations(true);
|
|
|
|
Player.reapplyAllSourceFiles();
|
2022-05-05 03:16:23 +02:00
|
|
|
}
|
2022-05-21 05:50:28 +02:00
|
|
|
if (ver < 20) {
|
2022-05-19 08:09:00 +02:00
|
|
|
// Create the darkweb for everyone but it won't be linked
|
|
|
|
const dw = GetServer(SpecialServers.DarkWeb);
|
|
|
|
if (!dw) {
|
|
|
|
const darkweb = safetlyCreateUniqueServer({
|
|
|
|
ip: createUniqueRandomIp(),
|
|
|
|
hostname: SpecialServers.DarkWeb,
|
|
|
|
organizationName: "",
|
|
|
|
isConnectedTo: false,
|
|
|
|
adminRights: false,
|
|
|
|
purchasedByPlayer: false,
|
|
|
|
maxRam: 1,
|
|
|
|
});
|
|
|
|
AddToAllServers(darkweb);
|
|
|
|
}
|
|
|
|
}
|
2021-10-13 01:23:36 +02:00
|
|
|
}
|
2018-11-16 04:45:03 +01:00
|
|
|
}
|
|
|
|
|
2021-09-25 00:40:17 +02:00
|
|
|
function loadGame(saveString: string): boolean {
|
2022-01-21 05:53:33 +01:00
|
|
|
createScamUpdateText();
|
2021-09-21 23:36:42 +02:00
|
|
|
if (!saveString) return false;
|
2021-09-21 22:49:38 +02:00
|
|
|
saveString = decodeURIComponent(escape(atob(saveString)));
|
2017-10-12 04:00:22 +02:00
|
|
|
|
2021-09-21 22:49:38 +02:00
|
|
|
const saveObj = JSON.parse(saveString, Reviver);
|
2017-07-25 16:39:56 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
loadPlayer(saveObj.PlayerSave);
|
|
|
|
loadAllServers(saveObj.AllServersSave);
|
|
|
|
loadCompanies(saveObj.CompaniesSave);
|
|
|
|
loadFactions(saveObj.FactionsSave);
|
2017-07-25 16:39:56 +02:00
|
|
|
|
2021-09-25 23:21:50 +02:00
|
|
|
if (saveObj.hasOwnProperty("StaneksGiftSave")) {
|
|
|
|
loadStaneksGift(saveObj.StaneksGiftSave);
|
|
|
|
} else {
|
|
|
|
console.warn(`Could not load Staneks Gift from save`);
|
|
|
|
loadStaneksGift("");
|
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
if (saveObj.hasOwnProperty("AliasesSave")) {
|
|
|
|
try {
|
|
|
|
loadAliases(saveObj.AliasesSave);
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(`Could not load Aliases from save`);
|
|
|
|
loadAliases("");
|
2017-05-23 18:15:17 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
} else {
|
|
|
|
console.warn(`Save file did not contain an Aliases property`);
|
|
|
|
loadAliases("");
|
|
|
|
}
|
|
|
|
if (saveObj.hasOwnProperty("GlobalAliasesSave")) {
|
|
|
|
try {
|
|
|
|
loadGlobalAliases(saveObj.GlobalAliasesSave);
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(`Could not load GlobalAliases from save`);
|
|
|
|
loadGlobalAliases("");
|
2017-06-30 18:44:03 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
} else {
|
|
|
|
console.warn(`Save file did not contain a GlobalAliases property`);
|
|
|
|
loadGlobalAliases("");
|
|
|
|
}
|
|
|
|
if (saveObj.hasOwnProperty("StockMarketSave")) {
|
|
|
|
try {
|
|
|
|
loadStockMarket(saveObj.StockMarketSave);
|
|
|
|
} catch (e) {
|
|
|
|
loadStockMarket("");
|
2017-07-03 21:42:11 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
} else {
|
|
|
|
loadStockMarket("");
|
|
|
|
}
|
|
|
|
if (saveObj.hasOwnProperty("SettingsSave")) {
|
|
|
|
try {
|
|
|
|
Settings.load(saveObj.SettingsSave);
|
|
|
|
} catch (e) {
|
2021-09-09 05:47:34 +02:00
|
|
|
console.error("ERROR: Failed to parse Settings. Re-initing default values");
|
2021-09-05 01:09:30 +02:00
|
|
|
Settings.init();
|
2017-07-25 16:39:56 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
} else {
|
|
|
|
Settings.init();
|
|
|
|
}
|
|
|
|
if (saveObj.hasOwnProperty("LastExportBonus")) {
|
|
|
|
try {
|
|
|
|
ExportBonus.setLastExportBonus(JSON.parse(saveObj.LastExportBonus));
|
|
|
|
} catch (err) {
|
|
|
|
ExportBonus.setLastExportBonus(new Date().getTime());
|
2021-09-21 04:30:11 +02:00
|
|
|
console.error("ERROR: Failed to parse last export bonus Settings " + err);
|
2021-05-18 05:59:45 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
2021-10-07 22:56:01 +02:00
|
|
|
if (Player.inGang() && saveObj.hasOwnProperty("AllGangsSave")) {
|
|
|
|
try {
|
|
|
|
loadAllGangs(saveObj.AllGangsSave);
|
|
|
|
} catch (e) {
|
|
|
|
console.error("ERROR: Failed to parse AllGangsSave: " + e);
|
|
|
|
}
|
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
if (saveObj.hasOwnProperty("VersionSave")) {
|
|
|
|
try {
|
2021-09-25 07:26:03 +02:00
|
|
|
const ver = JSON.parse(saveObj.VersionSave, Reviver);
|
2021-09-05 01:09:30 +02:00
|
|
|
evaluateVersionCompatibility(ver);
|
|
|
|
if (window.location.href.toLowerCase().includes("bitburner-beta")) {
|
|
|
|
// Beta branch, always show changes
|
|
|
|
createBetaUpdateText();
|
2021-11-03 03:49:46 +01:00
|
|
|
} else if (ver !== CONSTANTS.VersionNumber) {
|
2017-06-07 02:28:20 +02:00
|
|
|
createNewUpdateText();
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
createNewUpdateText();
|
2017-06-07 02:04:18 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
} else {
|
|
|
|
createNewUpdateText();
|
|
|
|
}
|
|
|
|
return true;
|
2017-05-05 03:08:44 +02:00
|
|
|
}
|
|
|
|
|
2022-01-21 05:43:19 +01:00
|
|
|
function createScamUpdateText(): void {
|
|
|
|
if (navigator.userAgent.indexOf("wv") !== -1 && navigator.userAgent.indexOf("Chrome/") !== -1) {
|
2022-01-21 05:53:33 +01:00
|
|
|
setInterval(() => {
|
|
|
|
dialogBoxCreate("SCAM ALERT. This app is not official and you should uninstall it.");
|
|
|
|
}, 1000);
|
2022-01-21 05:43:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-25 14:16:48 +01:00
|
|
|
const resets: SxProps = {
|
|
|
|
"& h1, & h2, & h3, & h4, & p, & a, & ul": {
|
|
|
|
margin: 0,
|
|
|
|
color: Settings.theme.primary,
|
|
|
|
whiteSpace: "initial",
|
|
|
|
},
|
|
|
|
"& ul": {
|
|
|
|
paddingLeft: "1.5em",
|
|
|
|
lineHeight: 1.5,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-09-25 07:26:03 +02:00
|
|
|
function createNewUpdateText(): void {
|
2021-11-08 15:27:11 +01:00
|
|
|
setTimeout(
|
|
|
|
() =>
|
|
|
|
dialogBoxCreate(
|
|
|
|
"New update!<br>" +
|
2022-06-04 02:10:52 +02:00
|
|
|
"Please report any bugs/issues through the GitHub repository " +
|
2021-11-08 15:27:11 +01:00
|
|
|
"or the Bitburner subreddit (reddit.com/r/bitburner).<br><br>" +
|
|
|
|
CONSTANTS.LatestUpdate,
|
2022-01-25 14:16:48 +01:00
|
|
|
resets,
|
2021-11-08 15:27:11 +01:00
|
|
|
),
|
|
|
|
1000,
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
2017-06-07 02:28:20 +02:00
|
|
|
}
|
|
|
|
|
2021-09-25 07:26:03 +02:00
|
|
|
function createBetaUpdateText(): void {
|
2021-09-05 01:09:30 +02:00
|
|
|
dialogBoxCreate(
|
|
|
|
"You are playing on the beta environment! This branch of the game " +
|
|
|
|
"features the latest developments in the game. This version may be unstable.<br>" +
|
|
|
|
"Please report any bugs/issues through the github repository (https://github.com/danielyxie/bitburner/issues) " +
|
|
|
|
"or the Bitburner subreddit (reddit.com/r/bitburner).<br><br>" +
|
|
|
|
CONSTANTS.LatestUpdate,
|
2022-01-25 14:16:48 +01:00
|
|
|
resets,
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
2018-07-19 04:23:49 +02:00
|
|
|
}
|
|
|
|
|
2021-11-12 05:28:08 +01:00
|
|
|
function download(filename: string, content: string): void {
|
|
|
|
const file = new Blob([content], { type: "text/plain" });
|
|
|
|
const navigator = window.navigator as any;
|
|
|
|
if (navigator.msSaveOrOpenBlob) {
|
|
|
|
// IE10+
|
|
|
|
navigator.msSaveOrOpenBlob(file, filename);
|
|
|
|
} else {
|
|
|
|
// Others
|
|
|
|
const a = document.createElement("a"),
|
|
|
|
url = URL.createObjectURL(file);
|
|
|
|
a.href = url;
|
|
|
|
a.download = filename;
|
|
|
|
document.body.appendChild(a);
|
|
|
|
a.click();
|
|
|
|
setTimeout(function () {
|
|
|
|
document.body.removeChild(a);
|
|
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-08 06:57:40 +02:00
|
|
|
Reviver.constructors.BitburnerSaveObject = BitburnerSaveObject;
|
|
|
|
|
2021-11-12 05:28:08 +01:00
|
|
|
export { saveObject, loadGame, download };
|
2021-09-25 00:40:17 +02:00
|
|
|
|
2021-09-25 07:26:03 +02:00
|
|
|
const saveObject = new BitburnerSaveObject();
|