@etothepii/satisfactory-file-parser 0.0.24 → 0.0.26
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/LICENCE.md +21 -0
- package/README.md +22 -4
- package/dist/index.d.ts +774 -0
- package/dist/index.js +1 -0
- package/package.json +13 -8
- package/build/index.d.ts +0 -19
- package/build/index.js +0 -52
- package/build/parser/byte/alignment.enum.d.ts +0 -4
- package/build/parser/byte/alignment.enum.js +0 -8
- package/build/parser/byte/byte-reader.class.d.ts +0 -34
- package/build/parser/byte/byte-reader.class.js +0 -121
- package/build/parser/byte/byte-writer.class.d.ts +0 -33
- package/build/parser/byte/byte-writer.class.js +0 -139
- package/build/parser/error/parser.error.d.ts +0 -12
- package/build/parser/error/parser.error.js +0 -28
- package/build/parser/file.types.d.ts +0 -9
- package/build/parser/file.types.js +0 -2
- package/build/parser/parser.d.ts +0 -16
- package/build/parser/parser.js +0 -88
- package/build/parser/satisfactory/blueprint/blueprint-reader.d.ts +0 -18
- package/build/parser/satisfactory/blueprint/blueprint-reader.js +0 -124
- package/build/parser/satisfactory/blueprint/blueprint-writer.d.ts +0 -15
- package/build/parser/satisfactory/blueprint/blueprint-writer.js +0 -63
- package/build/parser/satisfactory/blueprint/blueprint.types.d.ts +0 -20
- package/build/parser/satisfactory/blueprint/blueprint.types.js +0 -2
- package/build/parser/satisfactory/objects/DataFields.d.ts +0 -13
- package/build/parser/satisfactory/objects/DataFields.js +0 -224
- package/build/parser/satisfactory/objects/ObjectReference.d.ts +0 -9
- package/build/parser/satisfactory/objects/ObjectReference.js +0 -17
- package/build/parser/satisfactory/objects/Property.d.ts +0 -270
- package/build/parser/satisfactory/objects/Property.js +0 -1001
- package/build/parser/satisfactory/objects/SaveComponent.d.ts +0 -16
- package/build/parser/satisfactory/objects/SaveComponent.js +0 -31
- package/build/parser/satisfactory/objects/SaveEntity.d.ts +0 -25
- package/build/parser/satisfactory/objects/SaveEntity.js +0 -70
- package/build/parser/satisfactory/objects/SaveObject.d.ts +0 -14
- package/build/parser/satisfactory/objects/SaveObject.js +0 -29
- package/build/parser/satisfactory/save/level.class.d.ts +0 -21
- package/build/parser/satisfactory/save/level.class.js +0 -138
- package/build/parser/satisfactory/save/satisfactory-save.d.ts +0 -11
- package/build/parser/satisfactory/save/satisfactory-save.js +0 -11
- package/build/parser/satisfactory/save/save-reader.d.ts +0 -44
- package/build/parser/satisfactory/save/save-reader.js +0 -233
- package/build/parser/satisfactory/save/save-writer.d.ts +0 -12
- package/build/parser/satisfactory/save/save-writer.js +0 -112
- package/build/parser/satisfactory/save/save.types.d.ts +0 -49
- package/build/parser/satisfactory/save/save.types.js +0 -2
- package/build/parser/satisfactory/structs/util.types.d.ts +0 -40
- package/build/parser/satisfactory/structs/util.types.js +0 -95
|
@@ -1,139 +0,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));
|
|
91
|
-
}
|
|
92
|
-
this.writeUint8(0);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this.writeInt32(-value.length - 1);
|
|
96
|
-
for (let i = 0; i < value.length; i++) {
|
|
97
|
-
this.writeUint16(value.charCodeAt(i));
|
|
98
|
-
}
|
|
99
|
-
this.writeUint16(0);
|
|
100
|
-
}
|
|
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);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
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,12 +0,0 @@
|
|
|
1
|
-
export declare class ParserError extends Error {
|
|
2
|
-
constructor(name: string, message: string);
|
|
3
|
-
}
|
|
4
|
-
export declare class UnsupportedVersionError extends ParserError {
|
|
5
|
-
constructor(message?: string);
|
|
6
|
-
}
|
|
7
|
-
export declare class CorruptSaveError extends ParserError {
|
|
8
|
-
constructor(message?: string);
|
|
9
|
-
}
|
|
10
|
-
export declare class CompressionLibraryError extends ParserError {
|
|
11
|
-
constructor(message?: string);
|
|
12
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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;
|
package/build/parser/parser.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { ChunkSummary } from "./file.types";
|
|
3
|
-
import { Blueprint } from "./satisfactory/blueprint/blueprint.types";
|
|
4
|
-
import { SatisfactorySave } from "./satisfactory/save/satisfactory-save";
|
|
5
|
-
import { SaveProjectionConfig } from "./satisfactory/save/save-reader";
|
|
6
|
-
export declare class Parser {
|
|
7
|
-
static WriteSave(save: SatisfactorySave, onBinaryBeforeCompressing: (buffer: ArrayBuffer) => void, onHeader: (header: Uint8Array) => void, onChunk: (chunk: Uint8Array) => void): ChunkSummary[];
|
|
8
|
-
static ParseSaveFile(file: Buffer, onDecompressedSaveBody?: (buffer: ArrayBuffer) => void, onProgress?: (progress: number, message?: string) => void): SatisfactorySave;
|
|
9
|
-
static WriteBlueprintFiles(blueprint: Blueprint, onMainFileBinaryBeforeCompressing?: (binary: ArrayBuffer) => void, onMainFileHeader?: (header: Uint8Array) => void, onMainFileChunk?: (chunk: Uint8Array) => void): {
|
|
10
|
-
mainFileChunkSummary: ChunkSummary[];
|
|
11
|
-
configFileBinary: ArrayBuffer;
|
|
12
|
-
};
|
|
13
|
-
static ParseBlueprintFiles(name: string, blueprintFile: Buffer, blueprintConfigFile: Buffer, onDecompressedBlueprintBody?: (buffer: ArrayBuffer) => void): Blueprint;
|
|
14
|
-
static ProjectSave(save: SatisfactorySave, config: SaveProjectionConfig): SatisfactorySave;
|
|
15
|
-
static JSONStringifyModified: (obj: any, indent?: number) => string;
|
|
16
|
-
}
|
package/build/parser/parser.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Parser = void 0;
|
|
4
|
-
const blueprint_reader_1 = require("./satisfactory/blueprint/blueprint-reader");
|
|
5
|
-
const blueprint_writer_1 = require("./satisfactory/blueprint/blueprint-writer");
|
|
6
|
-
const level_class_1 = require("./satisfactory/save/level.class");
|
|
7
|
-
const satisfactory_save_1 = require("./satisfactory/save/satisfactory-save");
|
|
8
|
-
const save_reader_1 = require("./satisfactory/save/save-reader");
|
|
9
|
-
const save_writer_1 = require("./satisfactory/save/save-writer");
|
|
10
|
-
class Parser {
|
|
11
|
-
static WriteSave(save, onBinaryBeforeCompressing, onHeader, onChunk) {
|
|
12
|
-
const writer = new save_writer_1.SaveWriter();
|
|
13
|
-
save_writer_1.SaveWriter.WriteHeader(writer, save.header);
|
|
14
|
-
const posAfterHeader = writer.getBufferPosition();
|
|
15
|
-
save_writer_1.SaveWriter.WriteLevels(writer, save, save.header.buildVersion);
|
|
16
|
-
writer.endWriting();
|
|
17
|
-
const chunkSummary = writer.generateChunks(save.compressionInfo, posAfterHeader, onBinaryBeforeCompressing, onHeader, onChunk);
|
|
18
|
-
return chunkSummary;
|
|
19
|
-
}
|
|
20
|
-
static ParseSaveFile(file, onDecompressedSaveBody = () => { }, onProgress = () => { }) {
|
|
21
|
-
const reader = new save_reader_1.SaveReader(new Uint8Array(file).buffer, onProgress);
|
|
22
|
-
const header = reader.readHeader();
|
|
23
|
-
const save = new satisfactory_save_1.SatisfactorySave(header);
|
|
24
|
-
const inflateResult = reader.inflateChunks();
|
|
25
|
-
onDecompressedSaveBody(reader.getBuffer());
|
|
26
|
-
const levelParseResult = reader.readLevels();
|
|
27
|
-
save.levels = reader.levels;
|
|
28
|
-
save.compressionInfo = reader.compressionInfo;
|
|
29
|
-
save.trailingCollectedObjects = reader.trailingCollectedObjects;
|
|
30
|
-
return save;
|
|
31
|
-
}
|
|
32
|
-
static WriteBlueprintFiles(blueprint, onMainFileBinaryBeforeCompressing = () => { }, onMainFileHeader = () => { }, onMainFileChunk = () => { }) {
|
|
33
|
-
const blueprintWriter = new blueprint_writer_1.BlueprintWriter();
|
|
34
|
-
blueprint_writer_1.BlueprintWriter.SerializeHeader(blueprintWriter, blueprint.header);
|
|
35
|
-
const saveBodyPos = blueprintWriter.getBufferPosition();
|
|
36
|
-
blueprint_writer_1.BlueprintWriter.SerializeObjects(blueprintWriter, blueprint.objects);
|
|
37
|
-
blueprintWriter.endWriting();
|
|
38
|
-
let binaryChunks = [];
|
|
39
|
-
let binaryHeader;
|
|
40
|
-
const mainFileChunkSummary = blueprintWriter.generateChunks(blueprint.compressionInfo, saveBodyPos, onMainFileBinaryBeforeCompressing, onMainFileHeader, onMainFileChunk);
|
|
41
|
-
const configWriter = new blueprint_writer_1.BlueprintConfigWriter();
|
|
42
|
-
blueprint_writer_1.BlueprintConfigWriter.SerializeConfig(configWriter, blueprint.config);
|
|
43
|
-
const configFileBinary = configWriter.endWriting();
|
|
44
|
-
return {
|
|
45
|
-
mainFileChunkSummary,
|
|
46
|
-
configFileBinary
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
static ParseBlueprintFiles(name, blueprintFile, blueprintConfigFile, onDecompressedBlueprintBody = () => { }) {
|
|
50
|
-
const blueprintConfigReader = new blueprint_reader_1.BlueprintConfigReader(new Uint8Array(blueprintConfigFile).buffer);
|
|
51
|
-
const config = blueprint_reader_1.BlueprintConfigReader.ParseConfig(blueprintConfigReader);
|
|
52
|
-
const blueprintReader = new blueprint_reader_1.BlueprintReader(new Uint8Array(blueprintFile).buffer);
|
|
53
|
-
const header = blueprint_reader_1.BlueprintReader.ReadHeader(blueprintReader);
|
|
54
|
-
const inflateResult = blueprintReader.inflateChunks();
|
|
55
|
-
onDecompressedBlueprintBody(inflateResult.inflatedData);
|
|
56
|
-
const blueprintObjects = blueprint_reader_1.BlueprintReader.ParseObjects(blueprintReader);
|
|
57
|
-
const blueprint = {
|
|
58
|
-
name,
|
|
59
|
-
compressionInfo: blueprintReader.compressionInfo,
|
|
60
|
-
header: header,
|
|
61
|
-
config,
|
|
62
|
-
objects: blueprintObjects
|
|
63
|
-
};
|
|
64
|
-
return blueprint;
|
|
65
|
-
}
|
|
66
|
-
static ProjectSave(save, config) {
|
|
67
|
-
return {
|
|
68
|
-
header: save.header,
|
|
69
|
-
trailingCollectedObjects: save.trailingCollectedObjects,
|
|
70
|
-
levels: save.levels.map(level => {
|
|
71
|
-
const lvl = new level_class_1.Level(level.name);
|
|
72
|
-
lvl.collectables = level.collectables;
|
|
73
|
-
lvl.objects = level.objects.filter(obj => (0, save_reader_1.projectionFilterApplies)(config, obj));
|
|
74
|
-
return lvl;
|
|
75
|
-
})
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
Parser.JSONStringifyModified = (obj, indent = 0) => JSON.stringify(obj, (key, value) => {
|
|
80
|
-
if (typeof value === 'bigint') {
|
|
81
|
-
return value.toString();
|
|
82
|
-
}
|
|
83
|
-
else if (value === 0 && 1 / value < 0) {
|
|
84
|
-
return '-0';
|
|
85
|
-
}
|
|
86
|
-
return value;
|
|
87
|
-
}, indent);
|
|
88
|
-
exports.Parser = Parser;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ByteReader } from "../../byte/byte-reader.class";
|
|
2
|
-
import { ChunkCompressionInfo } from "../../file.types";
|
|
3
|
-
import { SaveComponent } from "../objects/SaveComponent";
|
|
4
|
-
import { SaveEntity } from "../objects/SaveEntity";
|
|
5
|
-
import { BlueprintConfig, BlueprintHeader } from "./blueprint.types";
|
|
6
|
-
export declare class BlueprintReader extends ByteReader {
|
|
7
|
-
compressionInfo: ChunkCompressionInfo;
|
|
8
|
-
constructor(bluePrintBuffer: ArrayBuffer);
|
|
9
|
-
static ReadHeader(reader: ByteReader): BlueprintHeader;
|
|
10
|
-
inflateChunks(): any;
|
|
11
|
-
static ParseObjects(reader: ByteReader): (SaveEntity | SaveComponent)[];
|
|
12
|
-
}
|
|
13
|
-
export declare class BlueprintConfigReader extends ByteReader {
|
|
14
|
-
bluePrintConfigBuffer: ArrayBuffer;
|
|
15
|
-
constructor(bluePrintConfigBuffer: ArrayBuffer);
|
|
16
|
-
parse: () => BlueprintConfig;
|
|
17
|
-
static ParseConfig(reader: ByteReader): BlueprintConfig;
|
|
18
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
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
|
-
};
|
|
21
|
-
}
|
|
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;
|
|
39
|
-
}
|
|
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);
|
|
58
|
-
}
|
|
59
|
-
if (this.compressionInfo.maxChunkContentSize <= 0) {
|
|
60
|
-
this.compressionInfo.maxChunkContentSize = chunkHeader.getInt32(8, this.alignment === alignment_enum_1.Alignment.LITTLE_ENDIAN);
|
|
61
|
-
}
|
|
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;
|
|
69
|
-
this.fileBuffer = this.fileBuffer.slice(this.currentByte);
|
|
70
|
-
this.currentByte = 0;
|
|
71
|
-
try {
|
|
72
|
-
let currentInflatedChunk = null;
|
|
73
|
-
currentInflatedChunk = pako_1.default.inflate(currentChunk);
|
|
74
|
-
currentChunks.push(currentInflatedChunk);
|
|
75
|
-
}
|
|
76
|
-
catch (err) {
|
|
77
|
-
throw new parser_error_1.ParserError('ParserError', 'An error occurred while calling pako inflate.' + err);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
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;
|
|
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
|
-
};
|
|
95
|
-
}
|
|
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
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
exports.BlueprintConfigReader = BlueprintConfigReader;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ByteWriter } from "../../byte/byte-writer.class";
|
|
2
|
-
import { ChunkCompressionInfo, ChunkSummary } from "../../file.types";
|
|
3
|
-
import { SaveComponent } from "../objects/SaveComponent";
|
|
4
|
-
import { SaveEntity } from "../objects/SaveEntity";
|
|
5
|
-
import { BlueprintConfig, BlueprintHeader } from "./blueprint.types";
|
|
6
|
-
export declare class BlueprintWriter extends ByteWriter {
|
|
7
|
-
constructor();
|
|
8
|
-
static SerializeHeader(writer: ByteWriter, header: BlueprintHeader): void;
|
|
9
|
-
generateChunks(compressionInfo: ChunkCompressionInfo, posAfterHeader: number, onBinaryBeforeCompressing: (binary: ArrayBuffer) => void, onHeader: (header: Uint8Array) => void, onChunk: (chunk: Uint8Array) => void): ChunkSummary[];
|
|
10
|
-
static SerializeObjects(writer: ByteWriter, objects: (SaveEntity | SaveComponent)[]): void;
|
|
11
|
-
}
|
|
12
|
-
export declare class BlueprintConfigWriter extends ByteWriter {
|
|
13
|
-
constructor();
|
|
14
|
-
static SerializeConfig(writer: ByteWriter, config: BlueprintConfig): void;
|
|
15
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
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);
|
|
13
|
-
}
|
|
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]);
|
|
26
|
-
}
|
|
27
|
-
writer.writeInt32(header.recipeReferences.length);
|
|
28
|
-
for (const recipeReference of header.recipeReferences) {
|
|
29
|
-
writer.writeInt32(0);
|
|
30
|
-
writer.writeString(recipeReference);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
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.');
|
|
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);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.BlueprintConfigWriter = BlueprintConfigWriter;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ChunkCompressionInfo } from "../../file.types";
|
|
2
|
-
import { SaveComponent } from "../objects/SaveComponent";
|
|
3
|
-
import { SaveEntity } from "../objects/SaveEntity";
|
|
4
|
-
import { col4 } from "../structs/util.types";
|
|
5
|
-
export interface BlueprintConfig {
|
|
6
|
-
description: string;
|
|
7
|
-
color: col4;
|
|
8
|
-
iconID: number;
|
|
9
|
-
}
|
|
10
|
-
export type BlueprintHeader = {
|
|
11
|
-
itemCosts: [string, number][];
|
|
12
|
-
recipeReferences: string[];
|
|
13
|
-
};
|
|
14
|
-
export interface Blueprint {
|
|
15
|
-
name: string;
|
|
16
|
-
compressionInfo: ChunkCompressionInfo;
|
|
17
|
-
header: BlueprintHeader;
|
|
18
|
-
config: BlueprintConfig;
|
|
19
|
-
objects: (SaveEntity | SaveComponent)[];
|
|
20
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ByteReader } from "../../byte/byte-reader.class";
|
|
2
|
-
import { SaveWriter } from "../save/save-writer";
|
|
3
|
-
import { AbstractBaseProperty } from "./Property";
|
|
4
|
-
export declare class DataFields {
|
|
5
|
-
properties: any[];
|
|
6
|
-
trailingData: number[];
|
|
7
|
-
shouldBeNulled: boolean;
|
|
8
|
-
constructor();
|
|
9
|
-
static Parse(length: number, reader: ByteReader, buildVersion: number): DataFields;
|
|
10
|
-
static ParseProperty(reader: ByteReader, buildVersion: number, propertyName: string): AbstractBaseProperty | null;
|
|
11
|
-
static Serialize(writer: SaveWriter, fields: DataFields, buildVersion: number): void;
|
|
12
|
-
static SerializeProperty(writer: SaveWriter, property: AbstractBaseProperty, propertyName: string, buildVersion: number): void;
|
|
13
|
-
}
|