Files
blitzkit/packages/core/src/steam/vfs.ts
T

99 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-11-25 22:14:09 -06:00
import SteamUser, { EConnectionProtocol } from "steam-user";
2025-11-25 21:37:31 -06:00
2025-11-25 22:16:39 -06:00
interface SteamManifestFile {
chunks: {
sha: string;
crc: number;
offset: string;
cb_original: number;
cb_compressed: number;
2025-11-25 22:14:09 -06:00
}[];
2025-11-25 22:16:39 -06:00
filename: string;
size: string;
flags: number;
sha_filename: string;
sha_content: string;
linktarget: unknown;
}
interface SteamManifest {
files: SteamManifestFile[];
2025-11-25 22:20:46 -06:00
depot_id: number;
gid_manifest: string;
creation_time: number;
filenames_encrypted: boolean;
cb_disk_original: string;
cb_disk_compressed: string;
unique_chunks: number;
crc_encrypted: number;
crc_clear: number;
2025-11-25 22:14:09 -06:00
}
2025-11-25 21:37:31 -06:00
2025-11-25 22:14:09 -06:00
export class SteamVFS {
private steam = new SteamUser({ protocol: EConnectionProtocol.TCP });
2025-11-25 22:16:39 -06:00
private manifest: Map<string, SteamManifestFile> = new Map();
2025-11-25 22:14:09 -06:00
constructor(
private username: string,
private password: string,
private app: number,
private depot: number
) {}
async init() {
this.steam.logOn({
accountName: this.username,
password: this.password,
2025-11-25 21:37:31 -06:00
});
2025-11-25 22:14:09 -06:00
await new Promise((resolve) => this.steam.once("loggedOn", resolve));
2025-11-25 21:37:31 -06:00
2025-11-25 22:14:09 -06:00
const productInfo = await this.steam.getProductInfo([this.app], []);
2025-11-25 22:16:39 -06:00
const manifest: SteamManifest = await new Promise((resolve) => {
2025-11-26 12:46:03 -06:00
// @ts-expect-error
2025-11-25 22:14:09 -06:00
this.steam.getManifest(
this.app,
this.depot,
productInfo.apps[this.app].appinfo.depots[this.depot].manifests.public
.gid,
"public",
2025-11-26 12:46:03 -06:00
// @ts-expect-error
2025-11-25 22:14:09 -06:00
(_, response) => {
resolve(response);
}
);
});
2025-11-25 22:21:58 -06:00
const paths: string[] = [];
2025-11-25 22:16:39 -06:00
for (const file of manifest.files) {
2025-11-25 22:21:58 -06:00
const path = file.filename.replaceAll("\\", "/");
paths.push(path);
2025-11-25 22:20:46 -06:00
this.manifest.set(path, file);
2025-11-25 22:16:39 -06:00
}
2025-11-26 12:46:03 -06:00
return this;
}
2025-11-25 22:16:39 -06:00
2025-11-26 12:46:03 -06:00
async file(path: string) {
if (!this.manifest.has(path)) {
throw new Error(`File not found: ${path}`);
}
const fileManifest = this.manifest.get(path)!;
const downloaded: { type: "complete"; file: Buffer } =
// @ts-expect-error
await this.steam.downloadFile(this.app, this.depot, fileManifest);
return new Uint8Array(downloaded.file);
}
dispose() {
this.steam.logOff();
}
[Symbol.dispose]() {
this.dispose();
2025-11-25 21:37:31 -06:00
}
}