mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: some protobuf parsing
This commit is contained in:
1 parent
6b175238b2
commit
6ae86a7a70
5 files changed
+364
-10
No files matched your search
@@ -1,10 +0,0 @@
|
||||
import { Parser } from 'pickleparser';
|
||||
import { ReadStream } from '../buffer';
|
||||
|
||||
export class BattleResultsReadStream extends ReadStream {
|
||||
battleResults() {
|
||||
const pickleParser = new Parser();
|
||||
const unpickled = pickleParser.parse(new Uint8Array(this.buffer));
|
||||
const [, battleResultsString] = unpickled as [number, string];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import AdmZip from 'adm-zip';
|
||||
import { readFile } from 'fs/promises';
|
||||
import { Parser } from 'pickleparser';
|
||||
import protobuf from 'protobufjs';
|
||||
import { ReadStream } from './buffer';
|
||||
|
||||
interface WotbReplayMetaJson {
|
||||
version: string;
|
||||
title: string;
|
||||
dbid: string;
|
||||
playerName: string;
|
||||
battleStartTime: string;
|
||||
playerVehicleName: string;
|
||||
mapName: string;
|
||||
arenaUniqueId: string;
|
||||
battleDuration: number;
|
||||
vehicleCompDescriptor: number;
|
||||
camouflageId: number;
|
||||
mapId: number;
|
||||
arenaBonusType: number;
|
||||
}
|
||||
|
||||
export class WotbReplayReadStream extends ReadStream {
|
||||
async wotbReplay() {
|
||||
const pickleParser = new Parser();
|
||||
const zip = new AdmZip(Buffer.from(this.buffer));
|
||||
const metaJsonBuffer = zip.getEntry('meta.json')?.getData();
|
||||
const battleResultsDat = zip.getEntry('battle_results.dat')?.getData();
|
||||
|
||||
if (!metaJsonBuffer || !battleResultsDat)
|
||||
throw new SyntaxError('meta.json not found');
|
||||
|
||||
const metaJson = JSON.parse(
|
||||
metaJsonBuffer.toString(),
|
||||
) as WotbReplayMetaJson;
|
||||
const unpickledBattleResults = pickleParser.parse(battleResultsDat);
|
||||
const [, battleResultsString] = unpickledBattleResults as [number, string];
|
||||
const root = await protobuf.load(
|
||||
`${__dirname}/../../protos/BattleResultsClient.proto`,
|
||||
);
|
||||
const BattleResults = root.lookupType(
|
||||
'BattleResultsGenerated.BattleResultsClient',
|
||||
);
|
||||
|
||||
const decodedBattleResults = BattleResults.decode(
|
||||
Buffer.from(battleResultsString, 'binary'),
|
||||
);
|
||||
console.log(decodedBattleResults.toJSON());
|
||||
}
|
||||
}
|
||||
|
||||
const replay = await readFile('temp/test3.wotbreplay');
|
||||
const stream = new WotbReplayReadStream(replay.buffer);
|
||||
|
||||
stream.wotbReplay();
|
||||
Reference in new issue
Block a user