From d18cf625d0e952d93287c6aeda6bdcf342fb1b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Sun, 10 Dec 2023 17:03:01 -0600 Subject: [PATCH] feat: final compatibility --- scripts/buildAssets.ts | 36 +++++++++------------------------- src/core/blitz/SCPGStream.ts | 38 +++++++++++++++++------------------- 2 files changed, 27 insertions(+), 47 deletions(-) diff --git a/scripts/buildAssets.ts b/scripts/buildAssets.ts index 4551d3d72..dd428e460 100644 --- a/scripts/buildAssets.ts +++ b/scripts/buildAssets.ts @@ -298,43 +298,25 @@ if (allTargets || targets?.includes('tankModels')) { const nationVehicleId = tank.id; const id = (nationVehicleId << 8) + (NATION_IDS[nation] << 4) + 1; - // if (id !== 817) continue; - // console.log(`Building model ${id} @ ${nation}/${tankIndex}`); + console.log(`Building model ${id} @ ${nation}/${tankIndex}`); const parameters = await readYAMLDVPL( `${DATA}/${DOI.tankParameters}/${nation}/${tankIndex}.yaml.dvpl`, ); const sc2Path = parameters.resourcesPath.blitzModelPath; - // const scgPath = parameters.resourcesPath.blitzModelPath.replace( - // /\.sc2$/, - // '.scg', - // ); + const scgPath = parameters.resourcesPath.blitzModelPath.replace( + /\.sc2$/, + '.scg', + ); const sc2Stream = await SCPGStream.fromDVPLFile( `${DATA}/${DOI['3d']}/${sc2Path}.dvpl`, ); - // const scgStream = await SCPGStream.fromDVPLFile( - // `${DATA}/${DOI['3d']}/${scgPath}.dvpl`, - // ); + const scgStream = await SCPGStream.fromDVPLFile( + `${DATA}/${DOI['3d']}/${scgPath}.dvpl`, + ); const sc2Data = sc2Stream.consumeSC2(); - // const scgData = scgStream.consumeSCG(); - - // writeFile( - // `test.json`, - // JSON.stringify(sc2Data, (key, value) => - // typeof value === 'bigint' ? value.toString() : value, - // ), - // ); + const scgData = scgStream.consumeSCG(); } }), ); - - // console.log('Committing tank icons...'); - // await commitMultipleFiles( - // 'tresabhi', - // 'blitzkrieg-assets', - // 'main', - // 'tank icons', - // changes, - // true, - // ); } diff --git a/src/core/blitz/SCPGStream.ts b/src/core/blitz/SCPGStream.ts index 0b8f8cd41..ae6e5cb0b 100644 --- a/src/core/blitz/SCPGStream.ts +++ b/src/core/blitz/SCPGStream.ts @@ -123,6 +123,9 @@ export class SCPGStream { skip(size: number) { this.index += size; } + back(size: number) { + this.skip(-size); + } read(size: number) { return this.buffer.subarray(this.index, this.index + size); } @@ -147,9 +150,6 @@ export class SCPGStream { consumeAscii(size: number) { return this.consume(size).toString('ascii'); } - consumeUtf16(size: number) { - return this.consume(size).toString('utf16le'); - } consumeInt8() { return this.consume(1).readInt8(); @@ -290,12 +290,12 @@ export class SCPGStream { version: this.consumeUInt32(), nodeCount: this.consumeUInt32(), }; - const version = this.consumeKA(); - const descriptor = this.consumeSC2Descriptor(header.version); + const versionTags = this.consumeKA(); + const descriptor = this.consumeSC2Descriptor(); - return { header, version, descriptor }; + return { header, versionTags, descriptor }; } - consumeSC2Descriptor(version: number) { + consumeSC2Descriptor() { const size = this.consumeUInt32(); const fileType = this.consumeUInt32(); @@ -309,7 +309,6 @@ export class SCPGStream { return this.consumeKA(); } - // TODO: change return type consumeKAValue( type: KAType = this.consumeUInt8(), stringTable?: Record, @@ -320,8 +319,13 @@ export class SCPGStream { case KAType.FILEPATH: case KAType.STRING: { - const length = this.consumeUInt32(); - return this.consumeAscii(length); + if (stringTable) { + const id = this.consumeUInt32(); + return stringTable[id]; + } else { + const length = this.consumeUInt32(); + return this.consumeAscii(length); + } } case KAType.BYTE_ARRAY: { @@ -395,9 +399,7 @@ export class SCPGStream { case KAType.FASTNAME: { if (!stringTable) throw new Error('No string table provided'); - const index = this.consumeUInt32(); - return stringTable[index]; } @@ -423,14 +425,8 @@ export class SCPGStream { ); } } - consumeKAV1Pair(stringTable?: Record) { - const name = this.consumeKAValue(undefined, stringTable) as string; - const value = this.consumeKAValue(undefined, stringTable); - - return { name, value }; - } consumeKA(stringTable?: Record) { - this.consumeAscii(2); // "KA" + this.skip(2); // "KA" const version = this.consumeUInt16(); const pairs: Record = {}; @@ -438,7 +434,9 @@ export class SCPGStream { const count = this.consumeUInt32(); for (let index = 0; index < count; index++) { - const { name, value } = this.consumeKAV1Pair(); + const name = this.consumeKAValue(undefined, stringTable) as string; + const value = this.consumeKAValue(undefined, stringTable); + pairs[name] = value; } } else if (version === 0x0002) {