-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode.js
More file actions
39 lines (31 loc) · 1.11 KB
/
encode.js
File metadata and controls
39 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as fs from 'fs';
import { Parser } from "@etothepii/satisfactory-file-parser";
try {
// 1. Load your edited JSON
const blueprintData = JSON.parse(fs.readFileSync('./Myblueprint.json', 'utf8'));
let mainFileHeader;
const mainFileBodyChunks = [];
console.log('Encoding blueprint data...');
// 2. The Wiki Logic: Use callbacks to capture the header and body chunks
const summary = Parser.WriteBlueprintFiles(
blueprintData,
(header) => {
mainFileHeader = header;
},
(chunk) => {
mainFileBodyChunks.push(chunk);
}
);
// 3. Combine the chunks into a single Buffer
// We use Buffer.concat to merge the header and all body parts
const finalSbpBuffer = Buffer.concat([
Buffer.from(mainFileHeader),
...mainFileBodyChunks.map(chunk => Buffer.from(chunk))
]);
// 4. Write the .sbp and .sbpcfg files
fs.writeFileSync('./Myblueprint_MODDED.sbp', finalSbpBuffer);
fs.writeFileSync('./Myblueprint_MODDED.sbpcfg', Buffer.from(summary.configFileBinary));
console.log('✅ Success! Created Myblueprint_MODDED.sbp and .sbpcfg');
} catch (error) {
console.error('❌ Error encoding:', error.message);
}