@etothepii/satisfactory-file-parser 0.0.32 → 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 (35) 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.d.ts +0 -9
  10. package/build/parser/parser.js +84 -192
  11. package/build/parser/satisfactory/blueprint/blueprint-reader.js +109 -119
  12. package/build/parser/satisfactory/blueprint/blueprint-writer.js +56 -66
  13. package/build/parser/satisfactory/blueprint/blueprint.types.js +2 -12
  14. package/build/parser/satisfactory/objects/DataFields.js +297 -307
  15. package/build/parser/satisfactory/objects/ObjectReference.js +14 -24
  16. package/build/parser/satisfactory/objects/Property.js +967 -977
  17. package/build/parser/satisfactory/objects/SaveComponent.js +28 -38
  18. package/build/parser/satisfactory/objects/SaveEntity.js +65 -75
  19. package/build/parser/satisfactory/objects/SaveObject.js +26 -36
  20. package/build/parser/satisfactory/save/asynchronous-level.class.js +60 -70
  21. package/build/parser/satisfactory/save/level.class.js +122 -133
  22. package/build/parser/satisfactory/save/satisfactory-save.js +10 -20
  23. package/build/parser/satisfactory/save/save-reader.js +158 -168
  24. package/build/parser/satisfactory/save/save-writer.js +97 -107
  25. package/build/parser/satisfactory/save/save.types.js +2 -12
  26. package/build/parser/satisfactory/structs/util.types.js +89 -99
  27. package/build/parser/stream/byte-stream-reader.class.js +217 -227
  28. package/build/parser/stream/json-stream-state-writer.js +15 -25
  29. package/build/parser/stream/json-stream-writable.js +72 -82
  30. package/build/parser/stream/json-stream-writer.js +122 -132
  31. package/build/parser/stream/save-stream-json-stringifier.js +29 -39
  32. package/build/parser/stream/save-stream-reader.class.js +106 -116
  33. package/build/parser/stream/save-stream-writer.class.js +90 -100
  34. package/build/parser/stream/stream-level.class.js +93 -103
  35. package/package.json +1 -1
@@ -1,149 +1,139 @@
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", "./alignment.enum"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ByteWriter = void 0;
13
- const alignment_enum_1 = require("./alignment.enum");
14
- class ByteWriter {
15
- constructor(alignment, bufferSize = 500) {
16
- this.getBufferPosition = () => this.currentByte;
17
- this.getBufferSlice = (start, end) => this.bufferArray.slice(start, end);
18
- this.alignment = alignment;
19
- this.bufferArray = new ArrayBuffer(bufferSize);
20
- this.bufferView = new DataView(this.bufferArray);
21
- this.currentByte = 0;
22
- }
23
- skipBytes(count = 1) {
24
- this.extendBufferIfNeeded(count);
25
- this.currentByte += count;
26
- }
27
- jumpTo(pos) {
28
- const count = pos - this.getBufferPosition();
29
- this.skipBytes(count);
30
- }
31
- writeByte(value) {
32
- this.extendBufferIfNeeded(1);
33
- this.bufferView.setUint8(this.currentByte, value);
34
- this.currentByte += 1;
35
- }
36
- writeBytesArray(bytes) {
37
- this.writeBytes(new Uint8Array(bytes));
38
- }
39
- writeBytes(bytes) {
40
- this.extendBufferIfNeeded(bytes.length);
41
- bytes.forEach(byte => this.bufferView.setUint8(this.currentByte++, byte));
42
- }
43
- writeInt8(value) {
44
- this.extendBufferIfNeeded(1);
45
- this.bufferView.setInt8(this.currentByte, value);
46
- this.currentByte += 1;
47
- }
48
- writeUint8(value) {
49
- this.writeByte(value);
50
- }
51
- writeInt16(value) {
52
- this.extendBufferIfNeeded(2);
53
- this.bufferView.setInt16(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
54
- this.currentByte += 2;
55
- }
56
- writeUint16(value) {
57
- this.extendBufferIfNeeded(2);
58
- this.bufferView.setUint16(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
59
- this.currentByte += 2;
60
- }
61
- writeInt32(value) {
62
- this.extendBufferIfNeeded(4);
63
- this.bufferView.setInt32(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
64
- this.currentByte += 4;
65
- }
66
- writeUint32(value) {
67
- this.extendBufferIfNeeded(4);
68
- this.bufferView.setUint32(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
69
- this.currentByte += 4;
70
- }
71
- writeInt64(value) {
72
- this.extendBufferIfNeeded(8);
73
- this.bufferView.setBigInt64(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
74
- this.currentByte += 8;
75
- }
76
- writeUint64(value) {
77
- this.extendBufferIfNeeded(8);
78
- this.bufferView.setBigUint64(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
79
- this.currentByte += 8;
80
- }
81
- writeFloat(value) {
82
- this.extendBufferIfNeeded(4);
83
- this.bufferView.setFloat32(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
84
- this.currentByte += 4;
85
- }
86
- writeDouble(value) {
87
- this.extendBufferIfNeeded(8);
88
- this.bufferView.setFloat64(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
89
- this.currentByte += 8;
90
- }
91
- writeString(value) {
92
- if (value.length === 0) {
93
- this.writeInt32(0);
94
- return;
95
- }
96
- if (ByteWriter.IsASCIICompatible(value)) {
97
- this.writeInt32(value.length + 1);
98
- for (let i = 0; i < value.length; i++) {
99
- this.writeByte(value.charCodeAt(i));
100
- }
101
- this.writeUint8(0);
102
- }
103
- else {
104
- this.writeInt32(-value.length - 1);
105
- for (let i = 0; i < value.length; i++) {
106
- this.writeUint16(value.charCodeAt(i));
107
- }
108
- this.writeUint16(0);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ByteWriter = void 0;
4
+ const alignment_enum_1 = require("./alignment.enum");
5
+ class ByteWriter {
6
+ constructor(alignment, bufferSize = 500) {
7
+ this.getBufferPosition = () => this.currentByte;
8
+ this.getBufferSlice = (start, end) => this.bufferArray.slice(start, end);
9
+ this.alignment = alignment;
10
+ this.bufferArray = new ArrayBuffer(bufferSize);
11
+ this.bufferView = new DataView(this.bufferArray);
12
+ this.currentByte = 0;
13
+ }
14
+ skipBytes(count = 1) {
15
+ this.extendBufferIfNeeded(count);
16
+ this.currentByte += count;
17
+ }
18
+ jumpTo(pos) {
19
+ const count = pos - this.getBufferPosition();
20
+ this.skipBytes(count);
21
+ }
22
+ writeByte(value) {
23
+ this.extendBufferIfNeeded(1);
24
+ this.bufferView.setUint8(this.currentByte, value);
25
+ this.currentByte += 1;
26
+ }
27
+ writeBytesArray(bytes) {
28
+ this.writeBytes(new Uint8Array(bytes));
29
+ }
30
+ writeBytes(bytes) {
31
+ this.extendBufferIfNeeded(bytes.length);
32
+ bytes.forEach(byte => this.bufferView.setUint8(this.currentByte++, byte));
33
+ }
34
+ writeInt8(value) {
35
+ this.extendBufferIfNeeded(1);
36
+ this.bufferView.setInt8(this.currentByte, value);
37
+ this.currentByte += 1;
38
+ }
39
+ writeUint8(value) {
40
+ this.writeByte(value);
41
+ }
42
+ writeInt16(value) {
43
+ this.extendBufferIfNeeded(2);
44
+ this.bufferView.setInt16(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
45
+ this.currentByte += 2;
46
+ }
47
+ writeUint16(value) {
48
+ this.extendBufferIfNeeded(2);
49
+ this.bufferView.setUint16(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
50
+ this.currentByte += 2;
51
+ }
52
+ writeInt32(value) {
53
+ this.extendBufferIfNeeded(4);
54
+ this.bufferView.setInt32(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
55
+ this.currentByte += 4;
56
+ }
57
+ writeUint32(value) {
58
+ this.extendBufferIfNeeded(4);
59
+ this.bufferView.setUint32(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
60
+ this.currentByte += 4;
61
+ }
62
+ writeInt64(value) {
63
+ this.extendBufferIfNeeded(8);
64
+ this.bufferView.setBigInt64(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
65
+ this.currentByte += 8;
66
+ }
67
+ writeUint64(value) {
68
+ this.extendBufferIfNeeded(8);
69
+ this.bufferView.setBigUint64(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
70
+ this.currentByte += 8;
71
+ }
72
+ writeFloat(value) {
73
+ this.extendBufferIfNeeded(4);
74
+ this.bufferView.setFloat32(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
75
+ this.currentByte += 4;
76
+ }
77
+ writeDouble(value) {
78
+ this.extendBufferIfNeeded(8);
79
+ this.bufferView.setFloat64(this.currentByte, value, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
80
+ this.currentByte += 8;
81
+ }
82
+ writeString(value) {
83
+ if (value.length === 0) {
84
+ this.writeInt32(0);
85
+ return;
86
+ }
87
+ if (ByteWriter.IsASCIICompatible(value)) {
88
+ this.writeInt32(value.length + 1);
89
+ for (let i = 0; i < value.length; i++) {
90
+ this.writeByte(value.charCodeAt(i));
109
91
  }
92
+ this.writeUint8(0);
110
93
  }
111
- writeBinarySizeFromPosition(lenIndicatorPos, start) {
112
- const after = this.getBufferPosition();
113
- const writtenBytes = after - start;
114
- this.jumpTo(lenIndicatorPos);
115
- this.writeInt32(writtenBytes);
116
- this.jumpTo(after);
117
- }
118
- extendBufferIfNeeded(countNeededBytes, factor = 1.5) {
119
- if (this.currentByte + countNeededBytes > this.bufferView.byteLength) {
120
- this.bufferArray = ByteWriter.AppendBuffer(this.bufferArray, new ArrayBuffer(factor * this.bufferArray.byteLength));
121
- this.bufferView = new DataView(this.bufferArray);
94
+ else {
95
+ this.writeInt32(-value.length - 1);
96
+ for (let i = 0; i < value.length; i++) {
97
+ this.writeUint16(value.charCodeAt(i));
122
98
  }
99
+ this.writeUint16(0);
123
100
  }
124
- truncateBuffer() {
125
- this.bufferArray = this.bufferArray.slice(0, this.currentByte);
126
- }
127
- endWriting() {
128
- this.truncateBuffer();
129
- return this.bufferArray;
130
- }
131
- static ToInt32(num) {
132
- return new Uint8Array([
133
- (num & 0xff000000) >> 24,
134
- (num & 0x00ff0000) >> 16,
135
- (num & 0x0000ff00) >> 8,
136
- (num & 0x000000ff)
137
- ]);
138
- }
139
- static AppendBuffer(buffer1, buffer2) {
140
- var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
141
- tmp.set(new Uint8Array(buffer1), 0);
142
- tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
143
- return tmp.buffer;
101
+ }
102
+ writeBinarySizeFromPosition(lenIndicatorPos, start) {
103
+ const after = this.getBufferPosition();
104
+ const writtenBytes = after - start;
105
+ this.jumpTo(lenIndicatorPos);
106
+ this.writeInt32(writtenBytes);
107
+ this.jumpTo(after);
108
+ }
109
+ extendBufferIfNeeded(countNeededBytes, factor = 1.5) {
110
+ if (this.currentByte + countNeededBytes > this.bufferView.byteLength) {
111
+ this.bufferArray = ByteWriter.AppendBuffer(this.bufferArray, new ArrayBuffer(factor * this.bufferArray.byteLength));
112
+ this.bufferView = new DataView(this.bufferArray);
144
113
  }
145
- ;
146
114
  }
147
- ByteWriter.IsASCIICompatible = (value) => /^[\x00-\x7F]*$/.test(value);
148
- exports.ByteWriter = ByteWriter;
149
- });
115
+ truncateBuffer() {
116
+ this.bufferArray = this.bufferArray.slice(0, this.currentByte);
117
+ }
118
+ endWriting() {
119
+ this.truncateBuffer();
120
+ return this.bufferArray;
121
+ }
122
+ static ToInt32(num) {
123
+ return new Uint8Array([
124
+ (num & 0xff000000) >> 24,
125
+ (num & 0x00ff0000) >> 16,
126
+ (num & 0x0000ff00) >> 8,
127
+ (num & 0x000000ff)
128
+ ]);
129
+ }
130
+ static AppendBuffer(buffer1, buffer2) {
131
+ var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
132
+ tmp.set(new Uint8Array(buffer1), 0);
133
+ tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
134
+ return tmp.buffer;
135
+ }
136
+ ;
137
+ }
138
+ ByteWriter.IsASCIICompatible = (value) => /^[\x00-\x7F]*$/.test(value);
139
+ exports.ByteWriter = ByteWriter;
@@ -1,50 +1,40 @@
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
- exports.UnimplementedError = exports.TimeoutError = exports.CompressionLibraryError = exports.CorruptSaveError = exports.UnsupportedVersionError = exports.ParserError = void 0;
13
- class ParserError extends Error {
14
- constructor(name, message) {
15
- super(message);
16
- this.name = name;
17
- }
18
- }
19
- exports.ParserError = ParserError;
20
- class UnsupportedVersionError extends ParserError {
21
- constructor(message) {
22
- super('UnsupportedVersionError', message ?? 'This save version is not supported.');
23
- }
24
- }
25
- exports.UnsupportedVersionError = UnsupportedVersionError;
26
- class CorruptSaveError extends ParserError {
27
- constructor(message) {
28
- super('CorruptSaveError', message ?? 'This save data is most likely corrupt.');
29
- }
30
- }
31
- exports.CorruptSaveError = CorruptSaveError;
32
- class CompressionLibraryError extends ParserError {
33
- constructor(message) {
34
- super('CompressionLibraryError', message ?? 'Failed to compress/decompress save data.');
35
- }
36
- }
37
- exports.CompressionLibraryError = CompressionLibraryError;
38
- class TimeoutError extends ParserError {
39
- constructor(message) {
40
- super('TimeoutError', message ?? 'Operation timed out.');
41
- }
42
- }
43
- exports.TimeoutError = TimeoutError;
44
- class UnimplementedError extends ParserError {
45
- constructor(message) {
46
- super('UnimplementedError', message ?? 'Unimplemented Operation.');
47
- }
48
- }
49
- exports.UnimplementedError = UnimplementedError;
50
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnimplementedError = exports.TimeoutError = exports.CompressionLibraryError = exports.CorruptSaveError = exports.UnsupportedVersionError = exports.ParserError = void 0;
4
+ class ParserError extends Error {
5
+ constructor(name, message) {
6
+ super(message);
7
+ this.name = name;
8
+ }
9
+ }
10
+ exports.ParserError = ParserError;
11
+ class UnsupportedVersionError extends ParserError {
12
+ constructor(message) {
13
+ super('UnsupportedVersionError', message ?? 'This save version is not supported.');
14
+ }
15
+ }
16
+ exports.UnsupportedVersionError = UnsupportedVersionError;
17
+ class CorruptSaveError extends ParserError {
18
+ constructor(message) {
19
+ super('CorruptSaveError', message ?? 'This save data is most likely corrupt.');
20
+ }
21
+ }
22
+ exports.CorruptSaveError = CorruptSaveError;
23
+ class CompressionLibraryError extends ParserError {
24
+ constructor(message) {
25
+ super('CompressionLibraryError', message ?? 'Failed to compress/decompress save data.');
26
+ }
27
+ }
28
+ exports.CompressionLibraryError = CompressionLibraryError;
29
+ class TimeoutError extends ParserError {
30
+ constructor(message) {
31
+ super('TimeoutError', message ?? 'Operation timed out.');
32
+ }
33
+ }
34
+ exports.TimeoutError = TimeoutError;
35
+ class UnimplementedError extends ParserError {
36
+ constructor(message) {
37
+ super('UnimplementedError', message ?? 'Unimplemented Operation.');
38
+ }
39
+ }
40
+ exports.UnimplementedError = UnimplementedError;
@@ -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 });
@@ -1,20 +1,11 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { TransformStream, WritableStream } from "stream/web";
4
2
  import { ChunkSummary } from "./file.types";
5
3
  import { Blueprint } from "./satisfactory/blueprint/blueprint.types";
6
4
  import { SatisfactorySave } from "./satisfactory/save/satisfactory-save";
7
5
  import { SaveProjectionConfig } from "./satisfactory/save/save-reader";
8
- export declare class PassthroughWebTransform extends TransformStream<Uint8Array, Uint8Array> {
9
- constructor();
10
- }
11
6
  export declare class Parser {
12
7
  static WriteSave(save: SatisfactorySave, onBinaryBeforeCompressing: (buffer: ArrayBuffer) => void, onHeader: (header: Uint8Array) => void, onChunk: (chunk: Uint8Array) => void): ChunkSummary[];
13
- private static ParseSaveFileStream;
14
- private static ParseStreamSave;
15
- private static DecompressStreamSave;
16
8
  static ParseSaveFile(file: Buffer, onDecompressedSaveBody?: (buffer: ArrayBuffer) => void, onProgress?: (progress: number, message?: string) => void): SatisfactorySave;
17
- static ParseSaveFileAsynchronousToOutput(file: Buffer, outputJson: WritableStream<string>, onDecompressedSaveBody?: (buffer: ArrayBuffer) => void, onProgress?: (progress: number, message?: string) => void): Promise<SatisfactorySave>;
18
9
  static WriteBlueprintFiles(blueprint: Blueprint, onMainFileBinaryBeforeCompressing?: (binary: ArrayBuffer) => void, onMainFileHeader?: (header: Uint8Array) => void, onMainFileChunk?: (chunk: Uint8Array) => void): {
19
10
  mainFileChunkSummary: ChunkSummary[];
20
11
  configFileBinary: ArrayBuffer;