From 1cc15f64b0a787e1646998794bedcd103c2b42fd 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 12:58:19 -0600 Subject: [PATCH] feat: augment --- bun.lock | 5 ++- packages/core/package.json | 1 + packages/core/src/steam/vfs.ts | 42 ++++++++++++++++--- packages/scripts/src/buildAssets/constants.ts | 39 ++++------------- packages/scripts/src/buildAssets/index.ts | 21 ++++++---- .../scripts/src/core/blitz/readStringDVPL.ts | 6 --- .../scripts/src/core/blitz/readXMLDVPL.ts | 9 ---- packages/scripts/src/core/blitz/readYAML.ts | 7 ---- .../scripts/src/core/blitz/readYAMLDVPL.ts | 8 ---- 9 files changed, 63 insertions(+), 75 deletions(-) delete mode 100644 packages/scripts/src/core/blitz/readStringDVPL.ts delete mode 100644 packages/scripts/src/core/blitz/readXMLDVPL.ts delete mode 100644 packages/scripts/src/core/blitz/readYAML.ts delete mode 100644 packages/scripts/src/core/blitz/readYAMLDVPL.ts diff --git a/bun.lock b/bun.lock index 4f3bf2c3e..068d732a4 100644 --- a/bun.lock +++ b/bun.lock @@ -74,6 +74,7 @@ "adm-zip": "^0.5.16", "crc": "^4.3.2", "dotenv": "^17.2.2", + "fast-xml-parser": "^5.3.2", "lodash-es": "^4.17.21", "lz4js": "^0.2.0", "pickleparser": "^0.2.1", @@ -1438,7 +1439,7 @@ "fast-uri": ["fast-uri@3.1.0", "", {}, "sha512-iPeeDKJSWf4IEOasVVrknXpaBV0IApz/gp7S2bb7Z4Lljbl2MGJRqInZiUrQwV16cpzw/D3S5j5Julj/gT52AA=="], - "fast-xml-parser": ["fast-xml-parser@5.2.5", "", { "dependencies": { "strnum": "^2.1.0" }, "bin": { "fxparser": "src/cli/cli.js" } }, "sha512-pfX9uG9Ki0yekDHx2SiuRIyFdyAr1kMIMitPvb0YBo8SUfKvia7w7FIyd/l6av85pFYRhZscS75MwMnbvY+hcQ=="], + "fast-xml-parser": ["fast-xml-parser@5.3.2", "", { "dependencies": { "strnum": "^2.1.0" }, "bin": { "fxparser": "src/cli/cli.js" } }, "sha512-n8v8b6p4Z1sMgqRmqLJm3awW4NX7NkaKPfb3uJIBTSH7Pdvufi3PQ3/lJLQrvxcMYl7JI2jnDO90siPEpD8JBA=="], "fastq": ["fastq@1.19.1", "", { "dependencies": { "reusify": "^1.0.4" } }, "sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ=="], @@ -2614,6 +2615,8 @@ "@blitzkit/scripts/@types/bun": ["@types/bun@1.3.0", "", { "dependencies": { "bun-types": "1.3.0" } }, "sha512-+lAGCYjXjip2qY375xX/scJeVRmZ5cY0wyHYyCYxNcdEXrQ4AOe3gACgd4iQ8ksOslJtW4VNxBJ8llUwc3a6AA=="], + "@blitzkit/scripts/fast-xml-parser": ["fast-xml-parser@5.2.5", "", { "dependencies": { "strnum": "^2.1.0" }, "bin": { "fxparser": "src/cli/cli.js" } }, "sha512-pfX9uG9Ki0yekDHx2SiuRIyFdyAr1kMIMitPvb0YBo8SUfKvia7w7FIyd/l6av85pFYRhZscS75MwMnbvY+hcQ=="], + "@blitzkit/website/vite": ["vite@7.1.9", "", { "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", "picomatch": "^4.0.3", "postcss": "^8.5.6", "rollup": "^4.43.0", "tinyglobby": "^0.2.15" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "jiti": ">=1.21.0", "less": "^4.0.0", "lightningcss": "^1.21.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "jiti", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-4nVGliEpxmhCL8DslSAUdxlB6+SMrhB0a1v5ijlh1xB1nEPuy1mxaHxysVucLHuWryAxLWg6a5ei+U4TLn/rFg=="], "@discordjs/rest/@discordjs/collection": ["@discordjs/collection@2.1.1", "", {}, "sha512-LiSusze9Tc7qF03sLCujF5iZp7K+vRNEDBZ86FT9aQAv3vxMLihUvKvpsCWiQ2DJq1tVckopKm1rxomgNUc9hg=="], diff --git a/packages/core/package.json b/packages/core/package.json index 8dcf1c344..fd9e69734 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -18,6 +18,7 @@ "adm-zip": "^0.5.16", "crc": "^4.3.2", "dotenv": "^17.2.2", + "fast-xml-parser": "^5.3.2", "lodash-es": "^4.17.21", "lz4js": "^0.2.0", "pickleparser": "^0.2.1", diff --git a/packages/core/src/steam/vfs.ts b/packages/core/src/steam/vfs.ts index 01516af6c..a4f77d279 100644 --- a/packages/core/src/steam/vfs.ts +++ b/packages/core/src/steam/vfs.ts @@ -1,4 +1,6 @@ +import { XMLParser } from "fast-xml-parser"; import SteamUser, { EConnectionProtocol } from "steam-user"; +import { parse } from "yaml"; interface SteamManifestFile { chunks: { @@ -31,6 +33,8 @@ interface SteamManifest { export class SteamVFS { private steam = new SteamUser({ protocol: EConnectionProtocol.TCP }); + private textDecoder = new TextDecoder(); + private xmlParser = new XMLParser(); private manifest: Map = new Map(); @@ -75,13 +79,26 @@ export class SteamVFS { return this; } - async file(path: string) { - if (!this.manifest.has(path)) { - throw new Error(`File not found: ${path}`); - } + has(path: string) { + const dvplPath = `${path}.dvpl`; + return ( + (this.manifest.has(dvplPath) && dvplPath) || + (this.manifest.has(path) && path) + ); + } + + assert(requested: string) { + const path = this.has(requested); + + if (!path) throw new Error(`File not found: ${path}`); + + return path; + } + + async file(requested: string) { + const path = this.assert(requested); const fileManifest = this.manifest.get(path)!; - const downloaded: { type: "complete"; file: Buffer } = // @ts-expect-error await this.steam.downloadFile(this.app, this.depot, fileManifest); @@ -89,6 +106,21 @@ export class SteamVFS { return new Uint8Array(downloaded.file); } + async text(path: string) { + const file = await this.file(path); + return this.textDecoder.decode(file); + } + + async yaml(path: string) { + const file = await this.text(path); + return parse(file) as Type; + } + + async xml(path: string) { + const file = await this.text(path); + return this.xmlParser.parse(file) as Type; + } + dispose() { this.steam.logOff(); } diff --git a/packages/scripts/src/buildAssets/constants.ts b/packages/scripts/src/buildAssets/constants.ts index 850946d67..e5cba2859 100644 --- a/packages/scripts/src/buildAssets/constants.ts +++ b/packages/scripts/src/buildAssets/constants.ts @@ -1,32 +1,11 @@ -import { readdir } from "fs/promises"; -import { argv } from "process"; +import { assertSecret, SteamVFS } from "@blitzkit/core"; -const WINDOWS_APPS = "C:/Program Files/WindowsApps"; -const wotbPackageRegex = /7458BE2C\..+_\d+(\.\d+)+_x64__.+/; +const APP = 444200; +const DEPOT = 444202; -const isManual = argv.includes("--manual"); - -let data: string; -let compressed: boolean; - -if (isManual) { - data = "../../temp/game/Data"; - compressed = true; -} else { - const directories = await readdir(WINDOWS_APPS).then((files) => - files.filter((file) => wotbPackageRegex.test(file)) - ); - - if (directories.length !== 1) { - throw new Error( - `Expected 1 directory for WoTB Windows App, got ${directories.length}.` - ); - } - - const [windowsApp] = directories; - data = `${WINDOWS_APPS}/${windowsApp}/Data`; - compressed = false; -} - -export const DATA = data; -export const DATA_COMPRESSED = compressed; +export const vfs = new SteamVFS( + assertSecret(import.meta.env.STEAM_USERNAME), + assertSecret(import.meta.env.STEAM_PASSWORD), + APP, + DEPOT +); diff --git a/packages/scripts/src/buildAssets/index.ts b/packages/scripts/src/buildAssets/index.ts index 323d601a4..495765e0c 100644 --- a/packages/scripts/src/buildAssets/index.ts +++ b/packages/scripts/src/buildAssets/index.ts @@ -1,16 +1,8 @@ import { config } from "dotenv"; import { argv } from "process"; - -config(); - -const allTargets = argv.includes("--all-targets"); -const targets = argv - .find((argument) => argument.startsWith("--target")) - ?.split("=")[1] - .split(","); - import { boosterIcons } from "./boosterIcons"; import { camouflageIcons } from "./camouflageIcons"; +import { vfs } from "./constants"; import { consumableProvisionIcons } from "./consumableProvisionIcons"; import { currencies } from "./currencies"; import { definitions } from "./definitions"; @@ -27,6 +19,14 @@ import { tankArmors } from "./tankArmors"; import { tankIcons } from "./tankIcons"; import { tankModels } from "./tankModels"; +config(); + +const allTargets = argv.includes("--all-targets"); +const targets = argv + .find((argument) => argument.startsWith("--target")) + ?.split("=")[1] + .split(","); + if (!targets && !allTargets) throw new Error("No target(s) specified"); const methods = [ @@ -59,3 +59,6 @@ for (const method of methods) { } } } + +vfs.dispose(); +process.exit(0); diff --git a/packages/scripts/src/core/blitz/readStringDVPL.ts b/packages/scripts/src/core/blitz/readStringDVPL.ts deleted file mode 100644 index 46c799be9..000000000 --- a/packages/scripts/src/core/blitz/readStringDVPL.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { readDVPLFile } from './readDVPLFile'; - -export async function readStringDVPL(file: string) { - const buffer = await readDVPLFile(file); - return buffer.toString(); -} diff --git a/packages/scripts/src/core/blitz/readXMLDVPL.ts b/packages/scripts/src/core/blitz/readXMLDVPL.ts deleted file mode 100644 index 9ace498ad..000000000 --- a/packages/scripts/src/core/blitz/readXMLDVPL.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { XMLParser } from 'fast-xml-parser'; -import { readStringDVPL } from './readStringDVPL'; - -export async function readXMLDVPL(file: string) { - const parser = new XMLParser(); - const xml = await readStringDVPL(file); - - return parser.parse(xml) as Type; -} diff --git a/packages/scripts/src/core/blitz/readYAML.ts b/packages/scripts/src/core/blitz/readYAML.ts deleted file mode 100644 index e459e5426..000000000 --- a/packages/scripts/src/core/blitz/readYAML.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { readFile } from 'fs/promises'; -import { parse } from 'yaml'; - -export async function readYAML(file: string) { - const yaml = (await readFile(file)).toString(); - return parse(yaml) as Type; -} diff --git a/packages/scripts/src/core/blitz/readYAMLDVPL.ts b/packages/scripts/src/core/blitz/readYAMLDVPL.ts deleted file mode 100644 index c95623225..000000000 --- a/packages/scripts/src/core/blitz/readYAMLDVPL.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { parse } from 'yaml'; -import { readStringDVPL } from './readStringDVPL'; - -export async function readYAMLDVPL(file: string) { - const yaml = await readStringDVPL(file); - - return parse(yaml) as Type; -}