@etothepii/satisfactory-file-parser 0.4.13 → 0.4.14

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 (55) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +43 -22
  3. package/build/parser/byte/binary-readable.interface.d.ts +0 -3
  4. package/build/parser/byte/binary-writable.interface.d.ts +20 -0
  5. package/build/parser/byte/binary-writable.interface.js +2 -0
  6. package/build/parser/byte/byte-reader.class.d.ts +0 -3
  7. package/build/parser/byte/byte-reader.class.js +0 -8
  8. package/build/parser/byte/byte-writer.class.d.ts +6 -3
  9. package/build/parser/byte/byte-writer.class.js +3 -1
  10. package/build/parser/satisfactory/blueprint/blueprint-reader.js +8 -8
  11. package/build/parser/satisfactory/edit/edit-constants.d.ts +2 -0
  12. package/build/parser/satisfactory/edit/edit-constants.js +82 -158
  13. package/build/parser/satisfactory/objects/DataFields.js +9 -9
  14. package/build/parser/satisfactory/objects/SaveObject.d.ts +1 -1
  15. package/build/parser/satisfactory/objects/SaveObject.js +1 -1
  16. package/build/parser/satisfactory/objects/property/generic/FloatProperty.js +1 -1
  17. package/build/parser/satisfactory/objects/property/generic/StructProperty.js +11 -4
  18. package/build/parser/satisfactory/save/level.class.d.ts +1 -2
  19. package/build/parser/satisfactory/save/level.class.js +10 -15
  20. package/build/parser/satisfactory/save/save-reader.js +8 -4
  21. package/build/parser/satisfactory/save/save.types.d.ts +0 -25
  22. package/build/parser/satisfactory/structs/util.types.js +8 -8
  23. package/build/parser/stream/reworked/readable-stream-parser.d.ts +1 -0
  24. package/build/parser/stream/reworked/readable-stream-parser.js +28 -3
  25. package/package.json +1 -1
  26. package/build/parser/satisfactory/objects/ObjectReference.d.ts +0 -10
  27. package/build/parser/satisfactory/objects/ObjectReference.js +0 -17
  28. package/build/parser/satisfactory/objects/Property.d.ts +0 -272
  29. package/build/parser/satisfactory/objects/Property.js +0 -1177
  30. package/build/parser/satisfactory/objects/ue/FMD5Hash.d.ts +0 -7
  31. package/build/parser/satisfactory/objects/ue/FMD5Hash.js +0 -19
  32. package/build/parser/satisfactory/objects/ue/GUID.d.ts +0 -6
  33. package/build/parser/satisfactory/objects/ue/GUID.js +0 -21
  34. package/build/parser/satisfactory/save/asynchronous-level.class.d.ts +0 -9
  35. package/build/parser/satisfactory/save/asynchronous-level.class.js +0 -66
  36. package/build/parser/stream/byte-stream-reader.class.d.ts +0 -57
  37. package/build/parser/stream/byte-stream-reader.class.js +0 -241
  38. package/build/parser/stream/json-stream-state-writer.d.ts +0 -12
  39. package/build/parser/stream/json-stream-state-writer.js +0 -18
  40. package/build/parser/stream/json-stream-writable.d.ts +0 -20
  41. package/build/parser/stream/json-stream-writable.js +0 -83
  42. package/build/parser/stream/json-stream-writer.d.ts +0 -22
  43. package/build/parser/stream/json-stream-writer.js +0 -127
  44. package/build/parser/stream/reworked/stream-parser.d.ts +0 -6
  45. package/build/parser/stream/reworked/stream-parser.js +0 -31
  46. package/build/parser/stream/save-stream-json-stringifier.d.ts +0 -6
  47. package/build/parser/stream/save-stream-json-stringifier.js +0 -35
  48. package/build/parser/stream/save-stream-reader.class.d.ts +0 -15
  49. package/build/parser/stream/save-stream-reader.class.js +0 -121
  50. package/build/parser/stream/save-stream-writer.class.d.ts +0 -25
  51. package/build/parser/stream/save-stream-writer.class.js +0 -119
  52. package/build/parser/stream/stream-level.class.d.ts +0 -12
  53. package/build/parser/stream/stream-level.class.js +0 -103
  54. package/build/parser/stream/stream-parser.d.ts +0 -40
  55. package/build/parser/stream/stream-parser.js +0 -225
@@ -1,225 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamParserReader = void 0;
4
- const alignment_enum_1 = require("../byte/alignment.enum");
5
- class StreamParserReader {
6
- constructor(minBufferSize) {
7
- this.minBufferSize = minBufferSize;
8
- this.alignment = alignment_enum_1.Alignment.LITTLE_ENDIAN;
9
- this.getAmountLeftToRead = () => {
10
- return this.view.byteLength - this.currentByte;
11
- };
12
- this.parseLogic = async () => {
13
- console.log('before allocate 1', this.getAmountLeftToRead(), this.inputBuffer.length);
14
- await this.allocate(100000);
15
- const unknownStuff = [
16
- this.readInt32(),
17
- this.readInt32(),
18
- this.readString(),
19
- this.readInt32(),
20
- this.readInt32(),
21
- this.readInt32(),
22
- this.readString()
23
- ];
24
- console.log('before allocate 2', unknownStuff, this.getAmountLeftToRead(), this.inputBuffer.length);
25
- await this.allocate(10000);
26
- };
27
- this.allocate = async (amount) => {
28
- if (amount > this.minBufferSize) {
29
- throw new Error(`Can not attempt to allocate (${amount}) more than the size of the buffer (${this.minBufferSize}) is.`);
30
- }
31
- if (this.getAmountLeftToRead() >= amount) {
32
- return Promise.resolve();
33
- }
34
- return new Promise((resolve, reject) => {
35
- console.log('Waiting for allocate', amount, this.getAmountLeftToRead());
36
- this.readTilBufferFullOrInputEmpty();
37
- console.log('shift?', this.inputBuffer.length);
38
- if (this.inputBuffer.length > 0 && this.inputBuffer.length + this.getAmountLeftToRead() >= amount) {
39
- this.shiftBufferIntoOperatingDataView();
40
- return resolve();
41
- }
42
- this.onInputDataAvailableCallback = () => {
43
- console.log('on available callback.', this.inputBuffer.length, this.getAmountLeftToRead(), amount);
44
- if (this.inputBuffer.length > 0 && this.inputBuffer.length + this.getAmountLeftToRead() >= amount) {
45
- this.shiftBufferIntoOperatingDataView();
46
- console.log(this.getAmountLeftToRead());
47
- this.onInputDataAvailableCallback = undefined;
48
- return resolve();
49
- }
50
- };
51
- });
52
- };
53
- this.waitForAmountLeftToRead = async (amount, callback = () => { }) => {
54
- while (this.getAmountLeftToRead() < amount) {
55
- if (this.hasInputStreamEnded) {
56
- throw new Error(`Unexpected end of stream. Waited to read ${amount} but stream ended prematurely.`);
57
- }
58
- console.log('###waiting... for ', amount);
59
- this.readTilBufferFullOrInputEmpty();
60
- if (this.inputBuffer.length > 0) {
61
- console.log('###shift.');
62
- this.shiftBufferIntoOperatingDataView();
63
- }
64
- await this.wait(20);
65
- }
66
- console.log('amount left to read is no longer smaller than', amount, this.getAmountLeftToRead());
67
- callback();
68
- };
69
- this.wait = (ms) => new Promise((resolve, reject) => {
70
- setTimeout(() => {
71
- return resolve(ms);
72
- }, ms);
73
- });
74
- this.shiftBufferIntoOperatingDataView = (amountOfTrailingBytesToKeep = 300) => {
75
- const resultingTrailingBytes = Math.min(this.currentByte, amountOfTrailingBytesToKeep);
76
- const trailingPlusLeftToRead = new Uint8Array(this.buffer.slice(this.currentByte - resultingTrailingBytes));
77
- const { length, ...chunks } = this.inputBuffer;
78
- const inBuffer = new Uint8Array(Buffer.concat(Object.values(chunks)));
79
- this.inputBuffer = { length: 0 };
80
- this.buffer = new Uint8Array(trailingPlusLeftToRead.byteLength + inBuffer.byteLength);
81
- this.buffer.set(trailingPlusLeftToRead, 0);
82
- this.buffer.set(inBuffer, trailingPlusLeftToRead.byteLength);
83
- this.currentByte = resultingTrailingBytes;
84
- this.view = new DataView(this.buffer.buffer);
85
- };
86
- this.readTilBufferFullOrInputEmpty = () => {
87
- let chunk;
88
- console.log(this.hasDataToRead, this.inputBuffer.length, this.minBufferSize);
89
- while (this.hasDataToRead && this.inputBuffer.length < this.minBufferSize && (chunk = this.input.read()) != null) {
90
- console.log('reading chunk', chunk);
91
- this.inputBuffer[chunk.byteLength] = chunk;
92
- this.inputBuffer.length += chunk.length;
93
- }
94
- if (chunk === null) {
95
- console.log('chunk is null, input empty for now.');
96
- this.hasDataToRead = false;
97
- }
98
- else if (this.inputBuffer.length >= this.minBufferSize) {
99
- console.log('buffer is full, ignoring for now.', this.inputBuffer.length);
100
- }
101
- console.log('data available callback?', this.onInputDataAvailableCallback);
102
- if (this.onInputDataAvailableCallback) {
103
- this.onInputDataAvailableCallback();
104
- }
105
- };
106
- this.buffer = new Uint8Array(0);
107
- this.view = new DataView(this.buffer.buffer);
108
- this.currentByte = 0;
109
- this.hasInputStreamEnded = false;
110
- this.inputBuffer = { length: 0 };
111
- this.hasDataToRead = false;
112
- }
113
- startReading(input) {
114
- this.input = input;
115
- this.input.pause();
116
- this.input.on('readable', () => {
117
- console.log('on readable. Reading til buffer full or input empty.');
118
- this.hasDataToRead = true;
119
- this.readTilBufferFullOrInputEmpty();
120
- });
121
- this.input.on('end', () => {
122
- this.hasDataToRead = false;
123
- this.hasInputStreamEnded = true;
124
- });
125
- this.input.on('close', () => {
126
- this.hasDataToRead = false;
127
- this.hasInputStreamEnded = true;
128
- });
129
- }
130
- skipBytes(byteLength = 1) {
131
- this.currentByte += byteLength;
132
- return;
133
- }
134
- readByte() {
135
- return parseInt(this.view.getUint8(this.currentByte++).toString());
136
- }
137
- readBytes(count) {
138
- return new Uint8Array(new Array(count).fill(0).map(pl => this.view.getUint8(this.currentByte++)));
139
- }
140
- readHex(hexLength) {
141
- let hexPart = [];
142
- for (let i = 0; i < hexLength; i++) {
143
- let currentHex = String.fromCharCode(this.view.getUint8(this.currentByte++));
144
- hexPart.push(currentHex);
145
- }
146
- return hexPart.join('');
147
- }
148
- readInt8() {
149
- let data = this.view.getInt8(this.currentByte++);
150
- return data;
151
- }
152
- readUint8() {
153
- let data = this.view.getUint8(this.currentByte++);
154
- return data;
155
- }
156
- readInt16() {
157
- let data = this.view.getInt16(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
158
- this.currentByte += 2;
159
- return data;
160
- }
161
- readUint16() {
162
- let data = this.view.getUint16(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
163
- this.currentByte += 2;
164
- return data;
165
- }
166
- readInt32() {
167
- let data = this.view.getInt32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
168
- this.currentByte += 4;
169
- return data;
170
- }
171
- readUint32() {
172
- let data = this.view.getUint32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
173
- this.currentByte += 4;
174
- return data;
175
- }
176
- readLong() {
177
- let data = this.view.getBigInt64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
178
- this.currentByte += 8;
179
- return data;
180
- }
181
- readInt64() {
182
- return this.readLong();
183
- }
184
- readUint64() {
185
- let data = this.view.getBigUint64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
186
- this.currentByte += 8;
187
- return data;
188
- }
189
- readFloat32() {
190
- let data = this.view.getFloat32(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
191
- this.currentByte += 4;
192
- return data;
193
- }
194
- readDouble() {
195
- let data = this.view.getFloat64(this.currentByte, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
196
- this.currentByte += 8;
197
- return data;
198
- }
199
- readString() {
200
- let strLength = this.readInt32();
201
- if (strLength === 0) {
202
- return '';
203
- }
204
- if (strLength > (this.view.buffer.byteLength - this.currentByte)) {
205
- let errorMessage = `Cannot read string of length ${strLength} at position ${this.currentByte} as it exceeds the end at ${this.view.buffer.byteLength}`;
206
- throw new Error(errorMessage);
207
- }
208
- if (strLength < 0) {
209
- const string = new Array(-strLength - 1).fill('').map(c => String.fromCharCode(this.readUint16()));
210
- this.currentByte += 2;
211
- return string.join('');
212
- }
213
- try {
214
- const string = new Array(strLength - 1).fill('').map(c => String.fromCharCode(this.readUint8()));
215
- this.currentByte += 1;
216
- return string.join('');
217
- }
218
- catch (error) {
219
- let errorMessage = `Cannot read UTF8 string of length ${strLength} at position ${this.currentByte}.`;
220
- console.log(errorMessage, error);
221
- throw error;
222
- }
223
- }
224
- }
225
- exports.StreamParserReader = StreamParserReader;