@etothepii/satisfactory-file-parser 0.0.33 → 0.0.34

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.
Files changed (34) hide show
  1. package/build/index.js +41 -51
  2. package/build/parser/byte/alignment.enum.js +8 -18
  3. package/build/parser/byte/binary-operable.interface.js +2 -12
  4. package/build/parser/byte/binary-readable.interface.js +2 -12
  5. package/build/parser/byte/byte-reader.class.js +122 -132
  6. package/build/parser/byte/byte-writer.class.js +133 -143
  7. package/build/parser/error/parser.error.js +40 -50
  8. package/build/parser/file.types.js +2 -12
  9. package/build/parser/parser.js +85 -95
  10. package/build/parser/satisfactory/blueprint/blueprint-reader.js +109 -119
  11. package/build/parser/satisfactory/blueprint/blueprint-writer.js +56 -66
  12. package/build/parser/satisfactory/blueprint/blueprint.types.js +2 -12
  13. package/build/parser/satisfactory/objects/DataFields.js +297 -307
  14. package/build/parser/satisfactory/objects/ObjectReference.js +14 -24
  15. package/build/parser/satisfactory/objects/Property.js +967 -977
  16. package/build/parser/satisfactory/objects/SaveComponent.js +28 -38
  17. package/build/parser/satisfactory/objects/SaveEntity.js +65 -75
  18. package/build/parser/satisfactory/objects/SaveObject.js +26 -36
  19. package/build/parser/satisfactory/save/asynchronous-level.class.js +60 -70
  20. package/build/parser/satisfactory/save/level.class.js +122 -132
  21. package/build/parser/satisfactory/save/satisfactory-save.js +10 -20
  22. package/build/parser/satisfactory/save/save-reader.js +158 -168
  23. package/build/parser/satisfactory/save/save-writer.js +97 -107
  24. package/build/parser/satisfactory/save/save.types.js +2 -12
  25. package/build/parser/satisfactory/structs/util.types.js +89 -99
  26. package/build/parser/stream/byte-stream-reader.class.js +217 -227
  27. package/build/parser/stream/json-stream-state-writer.js +15 -25
  28. package/build/parser/stream/json-stream-writable.js +72 -82
  29. package/build/parser/stream/json-stream-writer.js +122 -132
  30. package/build/parser/stream/save-stream-json-stringifier.js +29 -39
  31. package/build/parser/stream/save-stream-reader.class.js +106 -116
  32. package/build/parser/stream/save-stream-writer.class.js +90 -100
  33. package/build/parser/stream/stream-level.class.js +93 -103
  34. package/package.json +1 -1
@@ -1,134 +1,124 @@
1
+ "use strict";
1
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
2
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
3
4
  };
4
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.BlueprintConfigReader = exports.BlueprintReader = void 0;
7
+ const pako_1 = __importDefault(require("pako"));
8
+ const alignment_enum_1 = require("../../byte/alignment.enum");
9
+ const byte_reader_class_1 = require("../../byte/byte-reader.class");
10
+ const parser_error_1 = require("../../error/parser.error");
11
+ const level_class_1 = require("../save/level.class");
12
+ const util_types_1 = require("../structs/util.types");
13
+ class BlueprintReader extends byte_reader_class_1.ByteReader {
14
+ constructor(bluePrintBuffer) {
15
+ super(bluePrintBuffer, alignment_enum_1.Alignment.LITTLE_ENDIAN);
16
+ this.compressionInfo = {
17
+ packageFileTag: 0,
18
+ maxChunkContentSize: 0,
19
+ chunkHeaderSize: 48
20
+ };
8
21
  }
9
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "pako", "../../byte/alignment.enum", "../../byte/byte-reader.class", "../../error/parser.error", "../save/level.class", "../structs/util.types"], factory);
11
- }
12
- })(function (require, exports) {
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.BlueprintConfigReader = exports.BlueprintReader = void 0;
16
- const pako_1 = __importDefault(require("pako"));
17
- const alignment_enum_1 = require("../../byte/alignment.enum");
18
- const byte_reader_class_1 = require("../../byte/byte-reader.class");
19
- const parser_error_1 = require("../../error/parser.error");
20
- const level_class_1 = require("../save/level.class");
21
- const util_types_1 = require("../structs/util.types");
22
- class BlueprintReader extends byte_reader_class_1.ByteReader {
23
- constructor(bluePrintBuffer) {
24
- super(bluePrintBuffer, alignment_enum_1.Alignment.LITTLE_ENDIAN);
25
- this.compressionInfo = {
26
- packageFileTag: 0,
27
- maxChunkContentSize: 0,
28
- chunkHeaderSize: 48
29
- };
22
+ static ReadHeader(reader) {
23
+ const unk = reader.readBytes(3 * 4);
24
+ const positionThingOrWhat = (0, util_types_1.ParseVec3)(reader);
25
+ let itemTypeCount = reader.readInt32();
26
+ const itemCosts = new Array(itemTypeCount).fill(['', 0]);
27
+ for (let i = 0; i < itemTypeCount; i++) {
28
+ let indexOrWhat = reader.readInt32();
29
+ let itemPathName = reader.readString();
30
+ let itemCount = reader.readInt32();
31
+ itemCosts[i] = [itemPathName, itemCount];
32
+ }
33
+ let recipeCount = reader.readInt32();
34
+ const recipeRefs = new Array(recipeCount).fill('');
35
+ for (let i = 0; i < recipeCount; i++) {
36
+ let indexOrWhat = reader.readInt32();
37
+ const recipeName = reader.readString();
38
+ recipeRefs[i] = recipeName;
30
39
  }
31
- static ReadHeader(reader) {
32
- const unk = reader.readBytes(3 * 4);
33
- const positionThingOrWhat = (0, util_types_1.ParseVec3)(reader);
34
- let itemTypeCount = reader.readInt32();
35
- const itemCosts = new Array(itemTypeCount).fill(['', 0]);
36
- for (let i = 0; i < itemTypeCount; i++) {
37
- let indexOrWhat = reader.readInt32();
38
- let itemPathName = reader.readString();
39
- let itemCount = reader.readInt32();
40
- itemCosts[i] = [itemPathName, itemCount];
40
+ return {
41
+ recipeReferences: recipeRefs,
42
+ itemCosts
43
+ };
44
+ }
45
+ inflateChunks() {
46
+ this.fileBuffer = this.fileBuffer.slice(this.currentByte);
47
+ this.handledByte = 0;
48
+ this.currentByte = 0;
49
+ this.maxByte = this.fileBuffer.byteLength;
50
+ let currentChunks = [];
51
+ let totalUncompressedBodySize = 0;
52
+ while (this.handledByte < this.maxByte) {
53
+ let chunkHeader = new DataView(this.fileBuffer.slice(0, this.compressionInfo.chunkHeaderSize));
54
+ this.currentByte = this.compressionInfo.chunkHeaderSize;
55
+ this.handledByte += this.compressionInfo.chunkHeaderSize;
56
+ if (this.compressionInfo.packageFileTag <= 0) {
57
+ this.compressionInfo.packageFileTag = chunkHeader.getUint32(0, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
41
58
  }
42
- let recipeCount = reader.readInt32();
43
- const recipeRefs = new Array(recipeCount).fill('');
44
- for (let i = 0; i < recipeCount; i++) {
45
- let indexOrWhat = reader.readInt32();
46
- const recipeName = reader.readString();
47
- recipeRefs[i] = recipeName;
59
+ if (this.compressionInfo.maxChunkContentSize <= 0) {
60
+ this.compressionInfo.maxChunkContentSize = chunkHeader.getInt32(8, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
48
61
  }
49
- return {
50
- recipeReferences: recipeRefs,
51
- itemCosts
52
- };
53
- }
54
- inflateChunks() {
62
+ const chunkCompressedLength = chunkHeader.getInt32(32, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
63
+ const chunkUncompressedLength = chunkHeader.getInt32(40, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
64
+ totalUncompressedBodySize += chunkUncompressedLength;
65
+ const currentChunkSize = chunkCompressedLength;
66
+ let currentChunk = this.fileBuffer.slice(this.currentByte, this.currentByte + currentChunkSize);
67
+ this.handledByte += currentChunkSize;
68
+ this.currentByte += currentChunkSize;
55
69
  this.fileBuffer = this.fileBuffer.slice(this.currentByte);
56
- this.handledByte = 0;
57
70
  this.currentByte = 0;
58
- this.maxByte = this.fileBuffer.byteLength;
59
- let currentChunks = [];
60
- let totalUncompressedBodySize = 0;
61
- while (this.handledByte < this.maxByte) {
62
- let chunkHeader = new DataView(this.fileBuffer.slice(0, this.compressionInfo.chunkHeaderSize));
63
- this.currentByte = this.compressionInfo.chunkHeaderSize;
64
- this.handledByte += this.compressionInfo.chunkHeaderSize;
65
- if (this.compressionInfo.packageFileTag <= 0) {
66
- this.compressionInfo.packageFileTag = chunkHeader.getUint32(0, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
67
- }
68
- if (this.compressionInfo.maxChunkContentSize <= 0) {
69
- this.compressionInfo.maxChunkContentSize = chunkHeader.getInt32(8, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
70
- }
71
- const chunkCompressedLength = chunkHeader.getInt32(32, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
72
- const chunkUncompressedLength = chunkHeader.getInt32(40, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
73
- totalUncompressedBodySize += chunkUncompressedLength;
74
- const currentChunkSize = chunkCompressedLength;
75
- let currentChunk = this.fileBuffer.slice(this.currentByte, this.currentByte + currentChunkSize);
76
- this.handledByte += currentChunkSize;
77
- this.currentByte += currentChunkSize;
78
- this.fileBuffer = this.fileBuffer.slice(this.currentByte);
79
- this.currentByte = 0;
80
- try {
81
- let currentInflatedChunk = null;
82
- currentInflatedChunk = pako_1.default.inflate(currentChunk);
83
- currentChunks.push(currentInflatedChunk);
84
- }
85
- catch (err) {
86
- throw new parser_error_1.ParserError('ParserError', 'An error occurred while calling pako inflate.' + err);
87
- }
71
+ try {
72
+ let currentInflatedChunk = null;
73
+ currentInflatedChunk = pako_1.default.inflate(currentChunk);
74
+ currentChunks.push(currentInflatedChunk);
88
75
  }
89
- let newChunkLength = currentChunks.map(cc => cc.length).reduce((prev, cur) => prev + cur);
90
- const bigWholeChunk = new Uint8Array(newChunkLength);
91
- let currentLength = 0;
92
- for (let i = 0; i < currentChunks.length; i++) {
93
- bigWholeChunk.set(currentChunks[i], currentLength);
94
- currentLength += currentChunks[i].length;
76
+ catch (err) {
77
+ throw new parser_error_1.ParserError('ParserError', 'An error occurred while calling pako inflate.' + err);
95
78
  }
96
- this.currentByte = 0;
97
- this.maxByte = bigWholeChunk.buffer.byteLength;
98
- this.bufferView = new DataView(bigWholeChunk.buffer);
99
- return {
100
- newChunkLength,
101
- numChunks: currentChunks.length,
102
- inflatedData: bigWholeChunk
103
- };
104
79
  }
105
- static ParseObjects(reader) {
106
- const totalBodyRestSize = reader.readInt32();
107
- const objectHeadersBinarySize = reader.readInt32();
108
- let objects = [];
109
- level_class_1.Level.ReadObjectHeaders(reader, objects, () => { });
110
- level_class_1.Level.ReadObjectContents(reader, objects, 0, () => { });
111
- return objects;
80
+ let newChunkLength = currentChunks.map(cc => cc.length).reduce((prev, cur) => prev + cur);
81
+ const bigWholeChunk = new Uint8Array(newChunkLength);
82
+ let currentLength = 0;
83
+ for (let i = 0; i < currentChunks.length; i++) {
84
+ bigWholeChunk.set(currentChunks[i], currentLength);
85
+ currentLength += currentChunks[i].length;
112
86
  }
87
+ this.currentByte = 0;
88
+ this.maxByte = bigWholeChunk.buffer.byteLength;
89
+ this.bufferView = new DataView(bigWholeChunk.buffer);
90
+ return {
91
+ newChunkLength,
92
+ numChunks: currentChunks.length,
93
+ inflatedData: bigWholeChunk
94
+ };
113
95
  }
114
- exports.BlueprintReader = BlueprintReader;
115
- class BlueprintConfigReader extends byte_reader_class_1.ByteReader {
116
- constructor(bluePrintConfigBuffer) {
117
- super(bluePrintConfigBuffer, alignment_enum_1.Alignment.LITTLE_ENDIAN);
118
- this.bluePrintConfigBuffer = bluePrintConfigBuffer;
119
- this.parse = () => BlueprintConfigReader.ParseConfig(this);
120
- }
121
- static ParseConfig(reader) {
122
- const unk = reader.readInt32();
123
- const description = reader.readString();
124
- const unk3 = reader.readInt32();
125
- const colorMaybe = (0, util_types_1.ParseCol4RGBA)(reader);
126
- return {
127
- description,
128
- color: colorMaybe,
129
- iconID: unk3
130
- };
131
- }
96
+ static ParseObjects(reader) {
97
+ const totalBodyRestSize = reader.readInt32();
98
+ const objectHeadersBinarySize = reader.readInt32();
99
+ let objects = [];
100
+ level_class_1.Level.ReadObjectHeaders(reader, objects, () => { });
101
+ level_class_1.Level.ReadObjectContents(reader, objects, 0, () => { });
102
+ return objects;
103
+ }
104
+ }
105
+ exports.BlueprintReader = BlueprintReader;
106
+ class BlueprintConfigReader extends byte_reader_class_1.ByteReader {
107
+ constructor(bluePrintConfigBuffer) {
108
+ super(bluePrintConfigBuffer, alignment_enum_1.Alignment.LITTLE_ENDIAN);
109
+ this.bluePrintConfigBuffer = bluePrintConfigBuffer;
110
+ this.parse = () => BlueprintConfigReader.ParseConfig(this);
111
+ }
112
+ static ParseConfig(reader) {
113
+ const unk = reader.readInt32();
114
+ const description = reader.readString();
115
+ const unk3 = reader.readInt32();
116
+ const colorMaybe = (0, util_types_1.ParseCol4RGBA)(reader);
117
+ return {
118
+ description,
119
+ color: colorMaybe,
120
+ iconID: unk3
121
+ };
132
122
  }
133
- exports.BlueprintConfigReader = BlueprintConfigReader;
134
- });
123
+ }
124
+ exports.BlueprintConfigReader = BlueprintConfigReader;
@@ -1,73 +1,63 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlueprintConfigWriter = exports.BlueprintWriter = void 0;
4
+ const alignment_enum_1 = require("../../byte/alignment.enum");
5
+ const byte_writer_class_1 = require("../../byte/byte-writer.class");
6
+ const parser_error_1 = require("../../error/parser.error");
7
+ const level_class_1 = require("../save/level.class");
8
+ const save_writer_1 = require("../save/save-writer");
9
+ const util_types_1 = require("../structs/util.types");
10
+ class BlueprintWriter extends byte_writer_class_1.ByteWriter {
11
+ constructor() {
12
+ super(alignment_enum_1.Alignment.LITTLE_ENDIAN);
5
13
  }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../../byte/alignment.enum", "../../byte/byte-writer.class", "../../error/parser.error", "../save/level.class", "../save/save-writer", "../structs/util.types"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.BlueprintConfigWriter = exports.BlueprintWriter = void 0;
13
- const alignment_enum_1 = require("../../byte/alignment.enum");
14
- const byte_writer_class_1 = require("../../byte/byte-writer.class");
15
- const parser_error_1 = require("../../error/parser.error");
16
- const level_class_1 = require("../save/level.class");
17
- const save_writer_1 = require("../save/save-writer");
18
- const util_types_1 = require("../structs/util.types");
19
- class BlueprintWriter extends byte_writer_class_1.ByteWriter {
20
- constructor() {
21
- super(alignment_enum_1.Alignment.LITTLE_ENDIAN);
22
- }
23
- static SerializeHeader(writer, header) {
24
- writer.writeInt32(2);
25
- writer.writeInt32(36);
26
- writer.writeInt32(211839);
27
- writer.writeInt32(4);
28
- writer.writeInt32(4);
29
- writer.writeInt32(4);
30
- writer.writeInt32(header.itemCosts.length);
31
- for (const itemCost of header.itemCosts) {
32
- writer.writeInt32(0);
33
- writer.writeString(itemCost[0]);
34
- writer.writeInt32(itemCost[1]);
35
- }
36
- writer.writeInt32(header.recipeReferences.length);
37
- for (const recipeReference of header.recipeReferences) {
38
- writer.writeInt32(0);
39
- writer.writeString(recipeReference);
40
- }
41
- }
42
- generateChunks(compressionInfo, posAfterHeader, onBinaryBeforeCompressing, onHeader, onChunk) {
43
- if (posAfterHeader <= 0) {
44
- throw new parser_error_1.ParserError('ParserError', 'seems like this buffer has no header. Please write the header first before you can generate chunks.');
45
- }
46
- const header = new Uint8Array(this.bufferArray.slice(0, posAfterHeader));
47
- onHeader(header);
48
- this.bufferArray = this.bufferArray.slice(posAfterHeader);
49
- const chunkSummary = save_writer_1.SaveWriter.GenerateCompressedChunksFromData(this.bufferArray, compressionInfo, onBinaryBeforeCompressing, onChunk, this.alignment);
50
- return chunkSummary;
14
+ static SerializeHeader(writer, header) {
15
+ writer.writeInt32(2);
16
+ writer.writeInt32(36);
17
+ writer.writeInt32(211839);
18
+ writer.writeInt32(4);
19
+ writer.writeInt32(4);
20
+ writer.writeInt32(4);
21
+ writer.writeInt32(header.itemCosts.length);
22
+ for (const itemCost of header.itemCosts) {
23
+ writer.writeInt32(0);
24
+ writer.writeString(itemCost[0]);
25
+ writer.writeInt32(itemCost[1]);
51
26
  }
52
- static SerializeObjects(writer, objects) {
53
- const headersLenIndicator = writer.getBufferPosition();
27
+ writer.writeInt32(header.recipeReferences.length);
28
+ for (const recipeReference of header.recipeReferences) {
54
29
  writer.writeInt32(0);
55
- level_class_1.Level.SerializeObjectHeaders(writer, objects);
56
- writer.writeBinarySizeFromPosition(headersLenIndicator, headersLenIndicator + 4);
57
- level_class_1.Level.SerializeObjectContents(writer, objects, 0, '');
30
+ writer.writeString(recipeReference);
58
31
  }
59
32
  }
60
- exports.BlueprintWriter = BlueprintWriter;
61
- class BlueprintConfigWriter extends byte_writer_class_1.ByteWriter {
62
- constructor() {
63
- super(alignment_enum_1.Alignment.LITTLE_ENDIAN);
64
- }
65
- static SerializeConfig(writer, config) {
66
- writer.writeInt32(2);
67
- writer.writeString(config.description);
68
- writer.writeInt32(config.iconID);
69
- (0, util_types_1.SerializeCol4RGBA)(writer, config.color);
33
+ generateChunks(compressionInfo, posAfterHeader, onBinaryBeforeCompressing, onHeader, onChunk) {
34
+ if (posAfterHeader <= 0) {
35
+ throw new parser_error_1.ParserError('ParserError', 'seems like this buffer has no header. Please write the header first before you can generate chunks.');
70
36
  }
37
+ const header = new Uint8Array(this.bufferArray.slice(0, posAfterHeader));
38
+ onHeader(header);
39
+ this.bufferArray = this.bufferArray.slice(posAfterHeader);
40
+ const chunkSummary = save_writer_1.SaveWriter.GenerateCompressedChunksFromData(this.bufferArray, compressionInfo, onBinaryBeforeCompressing, onChunk, this.alignment);
41
+ return chunkSummary;
42
+ }
43
+ static SerializeObjects(writer, objects) {
44
+ const headersLenIndicator = writer.getBufferPosition();
45
+ writer.writeInt32(0);
46
+ level_class_1.Level.SerializeObjectHeaders(writer, objects);
47
+ writer.writeBinarySizeFromPosition(headersLenIndicator, headersLenIndicator + 4);
48
+ level_class_1.Level.SerializeObjectContents(writer, objects, 0, '');
49
+ }
50
+ }
51
+ exports.BlueprintWriter = BlueprintWriter;
52
+ class BlueprintConfigWriter extends byte_writer_class_1.ByteWriter {
53
+ constructor() {
54
+ super(alignment_enum_1.Alignment.LITTLE_ENDIAN);
55
+ }
56
+ static SerializeConfig(writer, config) {
57
+ writer.writeInt32(2);
58
+ writer.writeString(config.description);
59
+ writer.writeInt32(config.iconID);
60
+ (0, util_types_1.SerializeCol4RGBA)(writer, config.color);
71
61
  }
72
- exports.BlueprintConfigWriter = BlueprintConfigWriter;
73
- });
62
+ }
63
+ exports.BlueprintConfigWriter = BlueprintConfigWriter;
@@ -1,12 +1,2 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });