Satisfactory File Parser
This is an NPM TypeScript Module to parse Satisfactory Files. Satisfactory is a game released by Coffee Stain Studios.
The reporitory is written entirely in TypeScript and comes with Type Definitions.
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. Some bugs might still be present, see Bug Reporting further down.
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.20 |
Installation
npm
npm install @etothepii/satisfactory-file-parser
yarn
yarn add @etothepii/satisfactory-file-parser
Mod Support ✅
By Default, most Mods just reuse Properties and Structs of the base game.
If however a Mod should not be working or have just objects with a lot of trailing unparseable data, Raise an issue or contact me.
Some explicitly tested mods include:
Ficsit-Cam, Structural Solutions, Linear Motion, Container Screens, Conveyor Wall Hole, X3-Signs, X3-Roads
Reading a Save
Reading a Save in Memory.
import * as fs from 'fs';
import { Parser } from '@etothepii/satisfactory-file-parser';
const file = fs.readFileSync('./MySave.sav');
const save = Parser.ParseSave('MySave', file.buffer);
You can also read a Save via stream, to save RAM.
The binary data of the whole save will still be in memory, but the converted JSON can be streamed. (You can of course keep reading the stream in memory).
The returned stream
is a readable WHATWG stream of type string and represents a SatisfactorySave
object. this object can be serialized again.
WHATWG is used by default by browsers. Node js can use them using Writable.toWeb()
and Writable.fromWeb()
for example.
import * as fs from 'fs';
import { Writable } from 'stream';
import { WritableStream } from 'stream/web';
import { ReadableStreamParser } from '@etothepii/satisfactory-file-parser';
const file = fs.readFileSync('./MySave.sav');
const jsonFileStream = fs.createWriteStream('./MySave.json', { highWaterMark: 1024 * 1024 * 200 });
const whatwgWriteStream = Writable.toWeb(jsonFileStream) as WritableStream<string>;
const { stream, startStreaming } = ReadableStreamParser.CreateReadableStreamFromSaveToJson('MySave', file);
stream.pipeTo(whatwgWriteStream);
jsonFileStream.on('close', () => {
});
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 fileHeader: Uint8Array;
const bodyChunks: Uint8Array[] = [];
Parser.WriteSave(save, header => {
console.log('on save header.');
fileHeader = header;
}, chunk => {
console.log('on save body chunk.');
bodyChunks.push(chunk);
});
fs.writeFileSync('./MyModifiedSave.sav', Buffer.concat([fileHeader!, ...bodyChunks]));
Inspecting Save Objects
You can for example loop through players and print their cached names and positions.
import { isSaveEntity, SatisfactorySave, SaveEntity, StrProperty } from '@etothepii/satisfactory-file-parser';
const objects = save.levels.flatMap(level => level.objects);
const players = objects.filter(obj => isSaveEntity(obj) && obj.typePath === '/Game/FactoryGame/Character/Player/Char_Player.Char_Player_C') as SaveEntity[];
for (const player of players) {
const name = (player.properties.mCachedPlayerName as StrProperty).value;
console.log(name, player.transform.translation);
}
Usage of Blueprint Parsing
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');
const configFile = fs.readFileSync('./MyBlueprint.sbpcfg');
const blueprint = 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;
const mainFileBodyChunks: Uint8Array[] = [];
const summary = Parser.WriteBlueprintFiles(blueprint,
header => {
console.log('on main file header.');
mainFileHeader = header;
},
chunk => {
console.log('on main file body chunk.');
mainFileBodyChunks.push(chunk);
}
);
fs.writeFileSync('./MyBlueprint.sbp', Buffer.concat([mainFileHeader!, ...mainFileBodyChunks]));
fs.writeFileSync('./MyBlueprint.sbpcfg', Buffer.from(summary.configFileBinary));
Additional Infos
For every parser call, you can pass optional callbacks to receive additional info.
Like a callback on the decompressed save body. Parsing saves provides a callback for reporting progress [0,1] and an occasional message.
const save = Parser.ParseSave('MySave', file.buffer, {
onDecompressedSaveBody: (body) => console.log('on decompressed body', body.byteLength),
onProgressCallback: (progress, msg) => console.log(progress, msg)
});
const { stream, startStreaming } = ReadableStreamParser.CreateReadableStreamFromSaveToJson(savename, file, {
onProgress: (progress, msg) => console.log(`progress`, progress, msg);
});
const blueprint = Parser.ParseBlueprintFiles('Myblueprint', file, configFile, {
onDecompressedBlueprintBody: (body) => console.log('on decompressed body', body.byteLength),
});
Bug Reports or Feedback
You can always raise an issue on the linked github project or hit me up on the satisfactory discord etothepii
.
License
MIT License
Copyright (c) 2021-2024 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.