From f64516975297135e6d667ddc0ed9bd5f6226a962 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Wed, 5 Jan 2022 10:32:28 -0500 Subject: [PATCH] Add dev script to prettify save games Useful to analyze & debug a player's save game for anomalies. --- tools/README.md | 12 ++++++++++ tools/pretty-save.js | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tools/README.md create mode 100644 tools/pretty-save.js diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 000000000..f29ebd87e --- /dev/null +++ b/tools/README.md @@ -0,0 +1,12 @@ +# Tools + +## Pretty Save + +Useful to analyze a player's save game for anomalies. + +It decodes the save and prettifies the output. Canno be used to modify a save game directly since it drops some properties. + +**Usage** +```sh +node ./pretty-save.js 'C:\\Users\\martin\\Desktop\\bitburnerSave_1641395736_BN12x14.json' 'C:\\Users\\martin\\Desktop\\pretty.json' +``` diff --git a/tools/pretty-save.js b/tools/pretty-save.js new file mode 100644 index 000000000..6cdc974ab --- /dev/null +++ b/tools/pretty-save.js @@ -0,0 +1,53 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ +const fs = require('fs').promises; +const path = require('path'); + +async function getSave(file) { + const data = await fs.readFile(file, 'utf8'); + + const save = JSON.parse(decodeURIComponent(escape(atob(data)))); + const saveData = save.data; + let gameSave = { + PlayerSave: JSON.parse(saveData.PlayerSave), + CompaniesSave: JSON.parse(saveData.CompaniesSave), + FactionsSave: JSON.parse(saveData.FactionsSave), + AliasesSave: JSON.parse(saveData.AliasesSave), + GlobalAliasesSave: JSON.parse(saveData.GlobalAliasesSave), + MessagesSave: JSON.parse(saveData.MessagesSave), + StockMarketSave: JSON.parse(saveData.StockMarketSave), + SettingsSave: JSON.parse(saveData.SettingsSave), + VersionSave: JSON.parse(saveData.VersionSave), + LastExportBonus: JSON.parse(saveData.LastExportBonus), + StaneksGiftSave: JSON.parse(saveData.StaneksGiftSave), + } + + const serverStrings = JSON.parse(saveData.AllServersSave); + const servers = {}; + for (const [key, value] of Object.entries(serverStrings)) { + servers[key] = value.data; + } + + gameSave.AllServersSave = servers; + + if (saveData.AllGangsSave) { + gameSave.AllGangsSave = JSON.parse(saveData.AllGangsSave); + } + + return gameSave; +} + +async function main(input, output) { + const result = await getSave(input) + await fs.writeFile(output, JSON.stringify(result, null, 2)); + return result +} + +const input = path.resolve(process.argv[2]); +const output = path.resolve(process.argv[3]); + +console.log(`Input: ${input}`); +console.log(`Output: ${output}`); + +main(input, output).then(() => { + console.log('Done!'); +})