2022-01-05 16:32:28 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
2022-04-07 01:30:08 +02:00
|
|
|
const fs = require("fs").promises;
|
|
|
|
const path = require("path");
|
2024-03-28 05:08:09 +01:00
|
|
|
const { isBinaryFormat } = require("../electron/saveDataBinaryFormat");
|
2022-01-05 16:32:28 +01:00
|
|
|
|
|
|
|
async function getSave(file) {
|
2024-03-28 05:08:09 +01:00
|
|
|
const data = await fs.readFile(file);
|
2022-01-05 16:32:28 +01:00
|
|
|
|
2024-03-28 05:08:09 +01:00
|
|
|
let jsonSaveString;
|
|
|
|
if (isBinaryFormat(data)) {
|
|
|
|
const decompressedReadableStream = new Blob([data]).stream().pipeThrough(new DecompressionStream("gzip"));
|
|
|
|
jsonSaveString = await new Response(decompressedReadableStream).text();
|
|
|
|
} else {
|
|
|
|
jsonSaveString = decodeURIComponent(escape(atob(data)));
|
|
|
|
}
|
|
|
|
|
|
|
|
const save = JSON.parse(jsonSaveString);
|
2022-01-05 16:32:28 +01:00
|
|
|
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),
|
|
|
|
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),
|
2022-04-07 01:30:08 +02:00
|
|
|
SaveTimestamp: new Date(parseInt(saveData.SaveTimestamp ?? "0", 10)).toLocaleString(),
|
|
|
|
};
|
2022-01-05 16:32:28 +01:00
|
|
|
|
|
|
|
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) {
|
2022-04-07 01:30:08 +02:00
|
|
|
const result = await getSave(input);
|
2022-01-05 16:32:28 +01:00
|
|
|
await fs.writeFile(output, JSON.stringify(result, null, 2));
|
2022-04-07 01:30:08 +02:00
|
|
|
return result;
|
2022-01-05 16:32:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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(() => {
|
2022-04-07 01:30:08 +02:00
|
|
|
console.log("Done!");
|
|
|
|
});
|