mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +02:00
feat: ka 0xff02 handling
This commit is contained in:
1 parent
5471c7fa32
commit
dc01eff812
2 files changed
+21
-27
No files matched your search
@@ -315,7 +315,7 @@ if (allTargets || targets?.includes('tankModels')) {
|
|||||||
// const scgStream = await SCPGStream.fromDVPLFile(
|
// const scgStream = await SCPGStream.fromDVPLFile(
|
||||||
// `${DATA}/${DOI['3d']}/${scgPath}.dvpl`,
|
// `${DATA}/${DOI['3d']}/${scgPath}.dvpl`,
|
||||||
// );
|
// );
|
||||||
// const sc2Data = sc2Stream.consumeSC2();
|
const sc2Data = sc2Stream.consumeSC2();
|
||||||
// const scgData = scgStream.consumeSCG();
|
// const scgData = scgStream.consumeSCG();
|
||||||
|
|
||||||
// writeFile(
|
// writeFile(
|
||||||
@@ -324,14 +324,6 @@ if (allTargets || targets?.includes('tankModels')) {
|
|||||||
// typeof value === 'bigint' ? value.toString() : value,
|
// typeof value === 'bigint' ? value.toString() : value,
|
||||||
// ),
|
// ),
|
||||||
// );
|
// );
|
||||||
|
|
||||||
try {
|
|
||||||
sc2Stream.consumeSC2();
|
|
||||||
} catch (error) {
|
|
||||||
if (!(error as Error).message.startsWith('Unhandled KA version')) {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -309,20 +309,11 @@ export class SCPGStream {
|
|||||||
return this.consumeKA();
|
return this.consumeKA();
|
||||||
}
|
}
|
||||||
|
|
||||||
consumeKAHeader() {
|
|
||||||
return {
|
|
||||||
name: this.consumeAscii(2),
|
|
||||||
version: this.consumeUInt16(),
|
|
||||||
count: this.consumeUInt32(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// TODO: change return type
|
// TODO: change return type
|
||||||
consumeKAValue(
|
consumeKAValue(
|
||||||
type: KAType = this.consumeUInt8(),
|
type: KAType = this.consumeUInt8(),
|
||||||
stringTable?: Record<number, string>,
|
stringTable?: Record<number, string>,
|
||||||
): unknown {
|
): unknown {
|
||||||
console.log(KAType[type]);
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case KAType.NONE:
|
case KAType.NONE:
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -439,30 +430,36 @@ export class SCPGStream {
|
|||||||
return { name, value };
|
return { name, value };
|
||||||
}
|
}
|
||||||
consumeKA(stringTable?: Record<number, string>) {
|
consumeKA(stringTable?: Record<number, string>) {
|
||||||
const header = this.consumeKAHeader();
|
this.consumeAscii(2); // "KA"
|
||||||
|
const version = this.consumeUInt16();
|
||||||
const pairs: Record<string, any> = {};
|
const pairs: Record<string, any> = {};
|
||||||
|
|
||||||
if (header.version === 1) {
|
if (version === 0x0001) {
|
||||||
for (let index = 0; index < header.count; index++) {
|
const count = this.consumeUInt32();
|
||||||
|
|
||||||
|
for (let index = 0; index < count; index++) {
|
||||||
const { name, value } = this.consumeKAV1Pair();
|
const { name, value } = this.consumeKAV1Pair();
|
||||||
pairs[name] = value;
|
pairs[name] = value;
|
||||||
}
|
}
|
||||||
} else if (header.version === 2) {
|
} else if (version === 0x0002) {
|
||||||
|
const count = this.consumeUInt32();
|
||||||
const strings: string[] = [];
|
const strings: string[] = [];
|
||||||
const stringTable: Record<number, string> = {};
|
const stringTable: Record<number, string> = {};
|
||||||
for (let index = 0; index < header.count; index++) {
|
|
||||||
|
for (let index = 0; index < count; index++) {
|
||||||
const length = this.consumeUInt16();
|
const length = this.consumeUInt16();
|
||||||
const string = this.consumeAscii(length);
|
const string = this.consumeAscii(length);
|
||||||
|
|
||||||
strings.push(string);
|
strings.push(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let index = 0; index < header.count; index++) {
|
for (let index = 0; index < count; index++) {
|
||||||
const id = this.consumeUInt32();
|
const id = this.consumeUInt32();
|
||||||
stringTable[id] = strings[index];
|
stringTable[id] = strings[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeCount = this.consumeUInt32();
|
const nodeCount = this.consumeUInt32();
|
||||||
|
|
||||||
for (let index = 0; index < nodeCount; index++) {
|
for (let index = 0; index < nodeCount; index++) {
|
||||||
const keyId = this.consumeUInt32();
|
const keyId = this.consumeUInt32();
|
||||||
const value = this.consumeKAValue(undefined, stringTable);
|
const value = this.consumeKAValue(undefined, stringTable);
|
||||||
@@ -470,10 +467,12 @@ export class SCPGStream {
|
|||||||
|
|
||||||
pairs[key] = value;
|
pairs[key] = value;
|
||||||
}
|
}
|
||||||
} else if (header.version === 258) {
|
} else if (version === 0x0102) {
|
||||||
if (!stringTable) throw new Error('No string table provided');
|
if (!stringTable) throw new Error('No string table provided');
|
||||||
|
|
||||||
for (let index = 0; index < header.count; index++) {
|
const count = this.consumeUInt32();
|
||||||
|
|
||||||
|
for (let index = 0; index < count; index++) {
|
||||||
const keyIndex = this.consumeUInt32();
|
const keyIndex = this.consumeUInt32();
|
||||||
const key = stringTable[keyIndex];
|
const key = stringTable[keyIndex];
|
||||||
const valueType = this.consumeUInt8();
|
const valueType = this.consumeUInt8();
|
||||||
@@ -487,7 +486,10 @@ export class SCPGStream {
|
|||||||
pairs[key] = value;
|
pairs[key] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else throw new RangeError(`Unhandled KA version: ${header.version}`);
|
} else if (version === 0xff02) {
|
||||||
|
// same as 0x0102 but empty and with no count
|
||||||
|
return {};
|
||||||
|
} else throw new RangeError(`Unhandled KA version: ${version}`);
|
||||||
|
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user