mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: move versions
This commit is contained in:
1 parent
4c2f6bea25
commit
af95897bde
2 files changed
+125
-60
No files matched your search
@@ -318,7 +318,12 @@ if (allTargets || targets?.includes('tankModels')) {
|
|||||||
const sc2Data = sc2Stream.consumeSC2();
|
const sc2Data = sc2Stream.consumeSC2();
|
||||||
// const scgData = scgStream.consumeSCG();
|
// const scgData = scgStream.consumeSCG();
|
||||||
|
|
||||||
// writeFile(`dist/assets/models/${id}.json`, JSON.stringify(scgData));
|
// writeFile(
|
||||||
|
// `test.json`,
|
||||||
|
// JSON.stringify(sc2Data, (key, value) =>
|
||||||
|
// typeof value === 'bigint' ? value.toString() : value,
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
+119
-59
@@ -3,34 +3,34 @@ import { readDVPL } from './readDVPL';
|
|||||||
import { readDVPLFile } from './readDVPLFile';
|
import { readDVPLFile } from './readDVPLFile';
|
||||||
|
|
||||||
enum KAType {
|
enum KAType {
|
||||||
NONE,
|
NONE = 0,
|
||||||
BOOLEAN,
|
BOOLEAN = 1,
|
||||||
INT32,
|
INT32 = 2,
|
||||||
FLOAT,
|
FLOAT = 3,
|
||||||
STRING,
|
STRING = 4,
|
||||||
WIDE_STRING,
|
WIDE_STRING = 5,
|
||||||
BYTE_ARRAY,
|
BYTE_ARRAY = 6,
|
||||||
UINT32,
|
UINT32 = 7,
|
||||||
KEYED_ARCHIVE,
|
KEYED_ARCHIVE = 8,
|
||||||
INT64,
|
INT64 = 9,
|
||||||
UINT64,
|
UINT64 = 10,
|
||||||
VECTOR2,
|
VECTOR2 = 11,
|
||||||
VECTOR3,
|
VECTOR3 = 12,
|
||||||
VECTOR4,
|
VECTOR4 = 13,
|
||||||
MATRIX2,
|
MATRIX2 = 14,
|
||||||
MATRIX3,
|
MATRIX3 = 15,
|
||||||
MATRIX4,
|
MATRIX4 = 16,
|
||||||
COLOR,
|
COLOR = 17,
|
||||||
FASTNAME,
|
FASTNAME = 18,
|
||||||
AABBOX3,
|
AABBOX3 = 19,
|
||||||
FILEPATH,
|
FILEPATH = 20,
|
||||||
FLOAT64,
|
FLOAT64 = 21,
|
||||||
INT8,
|
INT8 = 22,
|
||||||
UINT8,
|
UINT8 = 23,
|
||||||
INT16,
|
INT16 = 24,
|
||||||
UINT16,
|
UINT16 = 25,
|
||||||
UNKNOWN1,
|
ARRAY = 27,
|
||||||
ARRAY,
|
TRANSFORM = 29,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum VertexType {
|
enum VertexType {
|
||||||
@@ -186,6 +186,35 @@ export class SCPGStream {
|
|||||||
return this.consume(1).readUInt8() === 1;
|
return this.consume(1).readUInt8() === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
consumeVector2() {
|
||||||
|
return [this.consumeFloat(), this.consumeFloat()];
|
||||||
|
}
|
||||||
|
consumeVector3() {
|
||||||
|
return [...this.consumeVector2(), this.consumeFloat()];
|
||||||
|
}
|
||||||
|
consumeVector4() {
|
||||||
|
return [...this.consumeVector3(), this.consumeFloat()];
|
||||||
|
}
|
||||||
|
|
||||||
|
consumeMatrix2() {
|
||||||
|
return [this.consumeVector2(), this.consumeVector2()];
|
||||||
|
}
|
||||||
|
consumeMatrix3() {
|
||||||
|
return [
|
||||||
|
this.consumeVector3(),
|
||||||
|
this.consumeVector3(),
|
||||||
|
this.consumeVector3(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
consumeMatrix4() {
|
||||||
|
return [
|
||||||
|
this.consumeVector4(),
|
||||||
|
this.consumeVector4(),
|
||||||
|
this.consumeVector4(),
|
||||||
|
this.consumeVector4(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
consumeSCGHeader() {
|
consumeSCGHeader() {
|
||||||
return {
|
return {
|
||||||
name: this.consumeAscii(4),
|
name: this.consumeAscii(4),
|
||||||
@@ -199,7 +228,7 @@ export class SCPGStream {
|
|||||||
const polygonGroupsRaw: PolygonGroupRaw[] = [];
|
const polygonGroupsRaw: PolygonGroupRaw[] = [];
|
||||||
|
|
||||||
for (let index = 0; index < header.nodeCount; index++) {
|
for (let index = 0; index < header.nodeCount; index++) {
|
||||||
const polygonGroupRaw = this.consumeKA<PolygonGroupRaw>();
|
const polygonGroupRaw = this.consumeKA() as PolygonGroupRaw;
|
||||||
polygonGroupsRaw.push(polygonGroupRaw);
|
polygonGroupsRaw.push(polygonGroupRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,9 +305,8 @@ export class SCPGStream {
|
|||||||
return { size, fileType };
|
return { size, fileType };
|
||||||
}
|
}
|
||||||
consumeSC2() {
|
consumeSC2() {
|
||||||
console.log(this.consumeSC2Header());
|
// TODO: HANDLE MORE THAN 1 NODE
|
||||||
|
this.consumeSC2Header();
|
||||||
console.log(this.read(32).toString('ascii'));
|
|
||||||
|
|
||||||
return this.consumeKA();
|
return this.consumeKA();
|
||||||
}
|
}
|
||||||
@@ -290,26 +318,27 @@ export class SCPGStream {
|
|||||||
count: this.consumeUInt32(),
|
count: this.consumeUInt32(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
consumeKAValue<Type>(
|
// TODO: change return type
|
||||||
|
consumeKAValue(
|
||||||
type: KAType = this.consumeUInt8(),
|
type: KAType = this.consumeUInt8(),
|
||||||
stringTable?: Record<number, string>,
|
stringTable?: Record<number, string>,
|
||||||
): Type {
|
): unknown {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case KAType.INT32:
|
case KAType.INT32:
|
||||||
return this.consumeInt32() as Type;
|
return this.consumeInt32();
|
||||||
|
|
||||||
case KAType.STRING: {
|
case (KAType.STRING, KAType.FILEPATH): {
|
||||||
const length = this.consumeUInt32();
|
const length = this.consumeUInt32();
|
||||||
return this.consumeAscii(length) as Type;
|
return this.consumeAscii(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
case KAType.BYTE_ARRAY: {
|
case KAType.BYTE_ARRAY: {
|
||||||
const length = this.consumeUInt32();
|
const length = this.consumeUInt32();
|
||||||
return this.consumeByteArray(length) as Type;
|
return this.consumeByteArray(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
case KAType.FLOAT:
|
case KAType.FLOAT:
|
||||||
return this.consumeFloat() as Type;
|
return this.consumeFloat();
|
||||||
|
|
||||||
case KAType.ARRAY: {
|
case KAType.ARRAY: {
|
||||||
const length = this.consumeUInt32();
|
const length = this.consumeUInt32();
|
||||||
@@ -319,53 +348,86 @@ export class SCPGStream {
|
|||||||
value.push(this.consumeKAValue(undefined, stringTable));
|
value.push(this.consumeKAValue(undefined, stringTable));
|
||||||
}
|
}
|
||||||
|
|
||||||
return value as Type;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
case KAType.KEYED_ARCHIVE: {
|
case KAType.KEYED_ARCHIVE: {
|
||||||
this.skip(4); // UInt32 length of the nested archive in bytes
|
this.skip(4); // UInt32 length of the nested archive in bytes
|
||||||
|
|
||||||
return this.consumeKA<Type>(stringTable);
|
return this.consumeKA(stringTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
case KAType.UINT64:
|
case KAType.INT8:
|
||||||
return this.consumeUInt64() as Type;
|
return this.consumeInt8();
|
||||||
|
case KAType.INT16:
|
||||||
|
return this.consumeInt16();
|
||||||
|
case KAType.INT32:
|
||||||
|
return this.consumeInt32();
|
||||||
|
case KAType.INT64:
|
||||||
|
return this.consumeInt64();
|
||||||
|
case KAType.UINT8:
|
||||||
|
return this.consumeUInt8();
|
||||||
|
case KAType.UINT16:
|
||||||
|
return this.consumeUInt16();
|
||||||
case KAType.UINT32:
|
case KAType.UINT32:
|
||||||
return this.consumeUInt32() as Type;
|
return this.consumeUInt32();
|
||||||
|
case KAType.UINT64:
|
||||||
|
return this.consumeUInt64();
|
||||||
|
|
||||||
case KAType.BOOLEAN:
|
case KAType.BOOLEAN:
|
||||||
return this.consumeBoolean() as Type;
|
return this.consumeBoolean();
|
||||||
|
|
||||||
case KAType.AABBOX3: {
|
case KAType.AABBOX3: {
|
||||||
const minimum = range(3).map(() => this.consumeFloat());
|
const minimum = this.consumeVector3();
|
||||||
const maximum = range(3).map(() => this.consumeFloat());
|
const maximum = this.consumeVector3();
|
||||||
|
|
||||||
return { minimum, maximum } as Type;
|
return { minimum, maximum };
|
||||||
}
|
}
|
||||||
|
|
||||||
case KAType.VECTOR4:
|
case KAType.VECTOR2:
|
||||||
return range(4).map(() => this.consumeFloat()) as Type;
|
return this.consumeVector2();
|
||||||
|
|
||||||
case KAType.VECTOR3:
|
case KAType.VECTOR3:
|
||||||
return range(3).map(() => this.consumeFloat()) as Type;
|
return this.consumeVector3();
|
||||||
|
case KAType.VECTOR4:
|
||||||
|
return this.consumeVector4();
|
||||||
|
|
||||||
|
case KAType.MATRIX2:
|
||||||
|
return this.consumeMatrix2();
|
||||||
|
case KAType.MATRIX3:
|
||||||
|
return this.consumeMatrix3();
|
||||||
|
case KAType.MATRIX4:
|
||||||
|
return this.consumeMatrix4();
|
||||||
|
|
||||||
case KAType.FASTNAME: {
|
case KAType.FASTNAME: {
|
||||||
if (!stringTable) throw new Error('No string table provided');
|
if (!stringTable) throw new Error('No string table provided');
|
||||||
|
|
||||||
const index = this.consumeUInt32();
|
const index = this.consumeUInt32();
|
||||||
|
|
||||||
return stringTable[index] as Type;
|
return stringTable[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case KAType.TRANSFORM: {
|
||||||
|
if (!stringTable) throw new Error('No string table provided');
|
||||||
|
|
||||||
|
const position = this.consumeVector3();
|
||||||
|
const scale = this.consumeVector3();
|
||||||
|
const rotation = this.consumeVector3();
|
||||||
|
const UNCONFIRMED_inset = this.consumeFloat();
|
||||||
|
|
||||||
|
return { position, scale, rotation, UNCONFIRMED_inset };
|
||||||
|
}
|
||||||
|
|
||||||
|
case KAType.NONE:
|
||||||
|
return undefined;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Unknown KA type: ${type} (${KAType[type] ?? 'unknown type'})`,
|
`Unhandled KA type: ${type} (${KAType[type] ?? 'unknown type'})`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
consumeKAV1Pair(stringTable?: Record<number, string>) {
|
consumeKAV1Pair(stringTable?: Record<number, string>) {
|
||||||
const name = this.consumeKAValue<string>(undefined, stringTable);
|
const name = this.consumeKAValue(undefined, stringTable) as string;
|
||||||
const value = this.consumeKAValue(undefined, stringTable);
|
const value = this.consumeKAValue(undefined, stringTable);
|
||||||
|
|
||||||
return { name, value };
|
return { name, value };
|
||||||
@@ -374,8 +436,6 @@ export class SCPGStream {
|
|||||||
const header = this.consumeKAHeader();
|
const header = this.consumeKAHeader();
|
||||||
const pairs: Record<string, any> = {};
|
const pairs: Record<string, any> = {};
|
||||||
|
|
||||||
console.log(header);
|
|
||||||
|
|
||||||
if (header.version === 1) {
|
if (header.version === 1) {
|
||||||
for (let index = 0; index < header.count; index++) {
|
for (let index = 0; index < header.count; index++) {
|
||||||
const { name, value } = this.consumeKAV1Pair();
|
const { name, value } = this.consumeKAV1Pair();
|
||||||
@@ -423,7 +483,7 @@ export class SCPGStream {
|
|||||||
}
|
}
|
||||||
} else throw new SyntaxError(`Unhandled KA version: ${header.version}`);
|
} else throw new SyntaxError(`Unhandled KA version: ${header.version}`);
|
||||||
|
|
||||||
return pairs as Type;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static fromDVPL(buffer: Buffer) {
|
static fromDVPL(buffer: Buffer) {
|
||||||
|
|||||||
Reference in new issue
Block a user