@etothepii/satisfactory-file-parser 0.4.10 → 0.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -7
- package/build/parser/satisfactory/objects/DataFields.js +3 -2
- package/build/parser/satisfactory/objects/property/generic/StructProperty.js +5 -1
- package/build/parser/satisfactory/objects/property/special/SpecialAnyProperty.d.ts +1 -0
- package/build/parser/satisfactory/save/level.class.js +0 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,24 +18,39 @@ Game Version Files of U5 and below are NOT supported.
|
|
|
18
18
|
| <= U5 | ❌ |
|
|
19
19
|
| U6 + U7 | ✅ 0.0.1 - 0.0.34 |
|
|
20
20
|
| U8 | ✅ 0.1.20 - 0.3.7 |
|
|
21
|
-
| U1.0 | ✅ >= 0.4.
|
|
21
|
+
| U1.0 | ✅ >= 0.4.12 |
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
## Installation via npm
|
|
25
25
|
`npm install @etothepii/satisfactory-file-parser`
|
|
26
26
|
|
|
27
27
|
## Usage of Save Parsing
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
The returned `stream` is a readable WHATWG stream of type string.
|
|
31
|
+
WHATWG is used by default by browsers. Node js can use them using `Writable.toWeb()` and `Writable.fromWeb()` for example.
|
|
32
|
+
|
|
29
33
|
```js
|
|
30
|
-
|
|
31
|
-
|
|
34
|
+
const jsonFileStream = fs.createWriteStream(outJsonPath, { highWaterMark: 1024 * 1024 * 200 }); // your outgoing JSON stream. In this case directly to file.
|
|
35
|
+
const whatwgWriteStream = Writable.toWeb(outJsonStream) as WritableStream<string>; // convert the file stream to WHATWG-compliant stream
|
|
36
|
+
|
|
37
|
+
const { stream, startStreaming } = ReadableStreamParser.CreateReadableStreamFromSaveToJson(savename, file, decompressedBody => {
|
|
38
|
+
console.log('on binary body data.');
|
|
39
|
+
}, (progress: number, msg: string | undefined) => {
|
|
40
|
+
// a callback for reporting progress as number [0,1]. Sometimes has a message.
|
|
41
|
+
console.log(`${new Date().toString()}: progress`, progress, msg);
|
|
42
|
+
});
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
stream.pipeTo(whatwgWriteStream);
|
|
45
|
+
whatwgWriteStream.on('close', () => {
|
|
46
|
+
// write stream finished
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
startStreaming();
|
|
35
50
|
```
|
|
36
51
|
|
|
37
52
|
Consequently, writing a parsed save file back is just as easy.
|
|
38
|
-
The SaveParser has callbacks to assist
|
|
53
|
+
The SaveParser has callbacks to assist during syncing on different occasions during the process.
|
|
39
54
|
For example, when writing the header or when writing a chunk of the save body.
|
|
40
55
|
The splitting in individual chunks enables you to more easily stream the binary data to somewhere else.
|
|
41
56
|
```js
|
|
@@ -57,6 +72,18 @@ Parser.WriteSave(save, binaryBeforeCompressed => {
|
|
|
57
72
|
fs.writeFileSync('./MyModifiedSave.sav', Buffer.concat([header!, ...bodyChunks]));
|
|
58
73
|
```
|
|
59
74
|
|
|
75
|
+
|
|
76
|
+
### Old Usage of Save Parsing. Deprecated.
|
|
77
|
+
For reading a save file (`.sav`) and parse In-Memory, just pass a Buffer to the parser with the file content.
|
|
78
|
+
```js
|
|
79
|
+
import * as fs from 'fs';
|
|
80
|
+
import { Parser } from "@etothepii/satisfactory-file-parser";
|
|
81
|
+
|
|
82
|
+
const file = fs.readFileSync('./MySave.sav') as Buffer;
|
|
83
|
+
const parsedSave = Parser.ParseSaveFile(file);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
|
|
60
87
|
## Usage of Blueprint Parsing
|
|
61
88
|
Blueprint parsing works very similiar. Note, that blueprints consist of 2 files. The `.sbp` main file and the config file `.sbpcfg`.
|
|
62
89
|
|
|
@@ -172,7 +172,7 @@ class DataFields {
|
|
|
172
172
|
reader.readInt32();
|
|
173
173
|
reader.readBytes(1);
|
|
174
174
|
const recipeTypePath = reader.readString();
|
|
175
|
-
|
|
175
|
+
const blueprintProxy = ObjectReference_1.ObjectReference.read(reader);
|
|
176
176
|
instances.push({
|
|
177
177
|
transform,
|
|
178
178
|
unknownUseNumbers,
|
|
@@ -180,6 +180,7 @@ class DataFields {
|
|
|
180
180
|
paintFinishPath,
|
|
181
181
|
recipeTypePath,
|
|
182
182
|
patternPath,
|
|
183
|
+
blueprintProxy
|
|
183
184
|
});
|
|
184
185
|
}
|
|
185
186
|
property.buildables.push({
|
|
@@ -383,7 +384,7 @@ class DataFields {
|
|
|
383
384
|
writer.writeInt32(0);
|
|
384
385
|
writer.writeByte(0);
|
|
385
386
|
writer.writeString(instance.recipeTypePath);
|
|
386
|
-
writer.
|
|
387
|
+
ObjectReference_1.ObjectReference.write(writer, instance.blueprintProxy);
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
390
|
}
|
|
@@ -34,7 +34,11 @@ class StructProperty extends BasicProperty_1.AbstractBaseProperty {
|
|
|
34
34
|
struct.value = StructProperty.ParseValue(reader, struct.subtype, size);
|
|
35
35
|
const readBytes = reader.getBufferPosition() - before;
|
|
36
36
|
if (readBytes !== size) {
|
|
37
|
-
|
|
37
|
+
if (size - readBytes === 4 && reader.readInt32() === 0) {
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new Error(`possibly corrupt. Read ${readBytes} for StructProperty Content of ${struct.subtype}, but ${size} were indicated.`);
|
|
41
|
+
}
|
|
38
42
|
}
|
|
39
43
|
return struct;
|
|
40
44
|
}
|
|
@@ -152,9 +152,6 @@ class Level {
|
|
|
152
152
|
const collectable = ObjectReference_1.ObjectReference.read(reader);
|
|
153
153
|
collected.push(collectable);
|
|
154
154
|
}
|
|
155
|
-
if (process.env.NODE_ENV === 'debug' && countSmthing > 0) {
|
|
156
|
-
console.log(printSmthWhenItsCollectables, countSmthing, collected.map(coll => coll.pathName).join(', '));
|
|
157
|
-
}
|
|
158
155
|
}
|
|
159
156
|
return collected;
|
|
160
157
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etothepii/satisfactory-file-parser",
|
|
3
3
|
"author": "etothepii",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.12",
|
|
5
5
|
"description": "A file parser for satisfactory files. Includes save files and blueprint files.",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
7
7
|
"main": "./build/index.js",
|