From 9cb1d0cb3f1186527c5bd7667ecf82a4aeb362b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Wed, 26 Nov 2025 13:25:46 -0600 Subject: [PATCH] fix: read dvpl files --- packages/core/src/blitz/index.ts | 65 ++++++++++--------- .../src/core => core/src}/blitz/readDVPL.ts | 24 +++---- packages/core/src/steam/vfs.ts | 8 ++- packages/scripts/src/buildAssets/constants.ts | 4 +- packages/scripts/tsconfig.json | 2 +- 5 files changed, 54 insertions(+), 49 deletions(-) rename packages/{scripts/src/core => core/src}/blitz/readDVPL.ts (75%) diff --git a/packages/core/src/blitz/index.ts b/packages/core/src/blitz/index.ts index d1bd1b37d..6b8193288 100644 --- a/packages/core/src/blitz/index.ts +++ b/packages/core/src/blitz/index.ts @@ -1,32 +1,33 @@ -export * from './canSplash'; -export * from './clans'; -export * from './classes'; -export * from './constants'; -export * from './equipmentPrice'; -export * from './fetchBlitz'; -export * from './fetchGlossary'; -export * from './generateStats'; -export * from './getAccountAchievements'; -export * from './getAccountInfo'; -export * from './getClanAccountInfo'; -export * from './getClanInfo'; -export * from './getLeagueFromScore'; -export * from './getRatingInfo'; -export * from './getRatingLeague'; -export * from './getRatingNeighbors'; -export * from './getTankStats'; -export * from './idToRegion'; -export * from './isOnGoingRatingSeason'; -export * from './isValidBlitzId'; -export * from './nations'; -export * from './normalizeExtra'; -export * from './normalizeIds'; -export * from './permanentSkills'; -export * from './rating'; -export * from './regions'; -export * from './regionSubdomainToRegion'; -export * from './regionToRegionSubdomain'; -export * from './searchClansAcrossRegions'; -export * from './searchCurrentRatingPlayers'; -export * from './searchPlayersAcrossRegions'; -export * from './toUniqueId'; +export * from "./canSplash"; +export * from "./clans"; +export * from "./classes"; +export * from "./constants"; +export * from "./equipmentPrice"; +export * from "./fetchBlitz"; +export * from "./fetchGlossary"; +export * from "./generateStats"; +export * from "./getAccountAchievements"; +export * from "./getAccountInfo"; +export * from "./getClanAccountInfo"; +export * from "./getClanInfo"; +export * from "./getLeagueFromScore"; +export * from "./getRatingInfo"; +export * from "./getRatingLeague"; +export * from "./getRatingNeighbors"; +export * from "./getTankStats"; +export * from "./idToRegion"; +export * from "./isOnGoingRatingSeason"; +export * from "./isValidBlitzId"; +export * from "./nations"; +export * from "./normalizeExtra"; +export * from "./normalizeIds"; +export * from "./permanentSkills"; +export * from "./rating"; +export * from "./readDVPL"; +export * from "./regions"; +export * from "./regionSubdomainToRegion"; +export * from "./regionToRegionSubdomain"; +export * from "./searchClansAcrossRegions"; +export * from "./searchCurrentRatingPlayers"; +export * from "./searchPlayersAcrossRegions"; +export * from "./toUniqueId"; diff --git a/packages/scripts/src/core/blitz/readDVPL.ts b/packages/core/src/blitz/readDVPL.ts similarity index 75% rename from packages/scripts/src/core/blitz/readDVPL.ts rename to packages/core/src/blitz/readDVPL.ts index a7dea2f2e..856bc0cd5 100644 --- a/packages/scripts/src/core/blitz/readDVPL.ts +++ b/packages/core/src/blitz/readDVPL.ts @@ -1,5 +1,5 @@ -import { crc32 } from 'crc'; -import { decompressBlock } from 'lz4js'; +import { crc32 } from "crc"; +import { decompressBlock } from "lz4js"; /** * Thanks Maddoxkkm! Modified heavily to be modern. @@ -9,10 +9,10 @@ export function readDVPL(buffer: Buffer) { const footerBuffer = buffer.subarray(buffer.length - 20, buffer.length); if ( - footerBuffer.toString('utf8', 16, 20) !== 'DVPL' || + footerBuffer.toString("utf8", 16, 20) !== "DVPL" || footerBuffer.length !== 20 ) { - throw new SyntaxError('Invalid DVPL footer'); + throw new SyntaxError("Invalid DVPL footer"); } const footerData = { @@ -24,15 +24,15 @@ export function readDVPL(buffer: Buffer) { const targetBlock = buffer.subarray(0, buffer.length - 20); if (targetBlock.length !== footerData.cSize) { - throw new RangeError('DVPL size mismatch'); + throw new RangeError("DVPL size mismatch"); } if (crc32(targetBlock) !== footerData.crc32) { - throw new TypeError('DVPL CRC32 mismatch'); + throw new TypeError("DVPL CRC32 mismatch"); } if (footerData.type === 0) { if (!(footerData.oSize === footerData.cSize && footerData.type === 0)) { - throw new RangeError('DVPL type and size mismatch'); + throw new RangeError("DVPL type and size mismatch"); } return targetBlock; @@ -44,17 +44,17 @@ export function readDVPL(buffer: Buffer) { destination, 0, source.length, - 0, + 0 ); - + if (decompressedSize !== footerData.oSize) { throw new RangeError( - `Decompressed DVPL size mismatch (${decompressedSize} vs ${footerData.oSize})`, + `Decompressed DVPL size mismatch (${decompressedSize} vs ${footerData.oSize})` ); } - + return Buffer.from(destination); } else { - throw new SyntaxError('Unknown DVPL format'); + throw new SyntaxError("Unknown DVPL format"); } } diff --git a/packages/core/src/steam/vfs.ts b/packages/core/src/steam/vfs.ts index 789f8e440..88a1949db 100644 --- a/packages/core/src/steam/vfs.ts +++ b/packages/core/src/steam/vfs.ts @@ -1,6 +1,7 @@ import { XMLParser } from "fast-xml-parser"; import SteamUser, { EConnectionProtocol } from "steam-user"; import { parse } from "yaml"; +import { readDVPL } from "../blitz"; interface SteamManifestFile { chunks: { @@ -91,7 +92,7 @@ export class SteamVFS { assert(requested: string) { const path = this.has(requested); - if (!path) throw new Error(`File not found: ${path}`); + if (!path) throw new Error(`File not found: ${requested}`); return path; } @@ -120,8 +121,11 @@ export class SteamVFS { const downloaded: { type: "complete"; file: Buffer } = // @ts-expect-error await this.steam.downloadFile(this.app, this.depot, fileManifest); + let buffer = downloaded.file; - return new Uint8Array(downloaded.file); + if (path.endsWith(".dvpl")) buffer = readDVPL(downloaded.file); + + return new Uint8Array(buffer); } async text(path: string) { diff --git a/packages/scripts/src/buildAssets/constants.ts b/packages/scripts/src/buildAssets/constants.ts index e5cba2859..e9013f625 100644 --- a/packages/scripts/src/buildAssets/constants.ts +++ b/packages/scripts/src/buildAssets/constants.ts @@ -3,9 +3,9 @@ import { assertSecret, SteamVFS } from "@blitzkit/core"; const APP = 444200; const DEPOT = 444202; -export const vfs = new SteamVFS( +export const vfs = await new SteamVFS( assertSecret(import.meta.env.STEAM_USERNAME), assertSecret(import.meta.env.STEAM_PASSWORD), APP, DEPOT -); +).init(); diff --git a/packages/scripts/tsconfig.json b/packages/scripts/tsconfig.json index 52d43eaaa..6dd4197cd 100644 --- a/packages/scripts/tsconfig.json +++ b/packages/scripts/tsconfig.json @@ -1,4 +1,4 @@ { "extends": "../../tsconfig.json", - "include": ["src/**/*"] + "include": ["src/**/*", "../core/src/blitz/readDVPL.ts"] }