@etothepii/satisfactory-file-parser
TypeScript icon, indicating that this package has built-in type declarations

0.4.12 • Public • Published

Satisfactory File Parser

This is an NPM TypeScript Module to parse Satisfactory Files. Satisfactory is a game released by Coffee Stain Studios.

The Module is written entirely in TypeScript and comes with Type Definitions. Currently, only the built JavaScript and Type Definitions are available. But if needed, the TypeScript source can be provided as well in future versions.

This parser can read, modify and write:

  • Save Files .sav
  • Blueprint Files .sbp, .sbpcfg

Supported Versions

The version support of the packages is indicated below.

Game Version Files of U5 and below are NOT supported.

Game Version Package
<= U5
U6 + U7 ✅ 0.0.1 - 0.0.34
U8 ✅ 0.1.20 - 0.3.7
U1.0 ✅ >= 0.4.12

Installation via npm

npm install @etothepii/satisfactory-file-parser

Usage of Save Parsing

I recommend parsing via stream, to save RAM. The binary data of the whole save will still be in memory, but the converted JSON won't. The returned stream is a readable WHATWG stream of type string. WHATWG is used by default by browsers. Node js can use them using Writable.toWeb() and Writable.fromWeb() for example.

const jsonFileStream = fs.createWriteStream(outJsonPath, { highWaterMark: 1024 * 1024 * 200 });  // your outgoing JSON stream. In this case directly to file.
const whatwgWriteStream = Writable.toWeb(outJsonStream) as WritableStream<string>;               // convert the file stream to WHATWG-compliant stream

const { stream, startStreaming } = ReadableStreamParser.CreateReadableStreamFromSaveToJson(savename, file, decompressedBody => {
    console.log('on binary body data.');
}, (progress: number, msg: string | undefined) => {
    // a callback for reporting progress as number [0,1]. Sometimes has a message.
    console.log(`${new Date().toString()}: progress`, progress, msg);
});

stream.pipeTo(whatwgWriteStream);
whatwgWriteStream.on('close', () => {
    // write stream finished
});

startStreaming();

Consequently, writing a parsed save file back is just as easy. The SaveParser has callbacks to assist during syncing on different occasions during the process. For example, when writing the header or when writing a chunk of the save body. The splitting in individual chunks enables you to more easily stream the binary data to somewhere else.

import * as fs from 'fs';
import { Parser } from "@etothepii/satisfactory-file-parser";

let header: Uint8Array, bodyChunks: Uint8Array[] = [];
Parser.WriteSave(save, binaryBeforeCompressed => {
    console.log('on binary data before being compressed.');
}, header => {
    console.log('on save header.');
    header = header;
}, chunk => {
    console.log('on save body chunk.');
    bodyChunks.push(chunk);
});

// write complete sav file back to disk
fs.writeFileSync('./MyModifiedSave.sav', Buffer.concat([header!, ...bodyChunks]));

Old Usage of Save Parsing. Deprecated.

For reading a save file (.sav) and parse In-Memory, just pass a Buffer to the parser with the file content.

import * as fs from 'fs';
import { Parser } from "@etothepii/satisfactory-file-parser";

const file = fs.readFileSync('./MySave.sav') as Buffer;
const parsedSave = Parser.ParseSaveFile(file);

Usage of Blueprint Parsing

Blueprint parsing works very similiar. Note, that blueprints consist of 2 files. The .sbp main file and the config file .sbpcfg.

import * as fs from 'fs';
import { Parser } from "@etothepii/satisfactory-file-parser";

const mainFile = fs.readFileSync('./MyBlueprint.sbp') as Buffer;
const configFile = fs.readFileSync('./MyBlueprint.sbpcfg') as Buffer;
const parsedBlueprint = Parser.ParseBlueprintFiles('MyBlueprint', mainFile, configFile);

Consequently, writing a blueprint into binary data works the same way with getting callbacks in the same style as the save parsing.

import * as fs from 'fs';
import { Parser } from "@etothepii/satisfactory-file-parser";

let mainFileHeader: Uint8Array, mainFileBodyChunks: Uint8Array[] = [];
const summary = Parser.WriteBlueprintFiles(blueprint, mainFileBinaryBeforeCompressed => {
    console.log('on main file binary data before being compressed.');
}, header => {
    console.log('on main file blueprint header.');
    mainFileHeader = header;
}, chunk => {
    console.log('on main file blueprint body chunk.');
    mainFileBodyChunks.push(chunk);
});

// write complete .sbp file back to disk
fs.writeFileSync('./MyModifiedBlueprint.sbp', Buffer.concat([mainFileHeader!, ...mainFileBodyChunks]));

// write .sbpcfg file back to disk, we get that data from the result of WriteBlueprintFiles
fs.writeFileSync('./MyModifiedSave.sbpcfg', Buffer.from(summary.configFileBinary));

License

MIT License

Copyright (c) 2023 etothepii

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Dependents (0)

Package Sidebar

Install

npm i @etothepii/satisfactory-file-parser

Weekly Downloads

187

Version

0.4.12

License

MIT

Unpacked Size

659 kB

Total Files

137

Last publish

Collaborators

  • etothepii