Skip to content

Commit

Permalink
Add option to disable wav patching
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabwhy committed Jun 30, 2022
1 parent 20e8da4 commit bef50a2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "tfvpktool",
"version": "0.1.2",
"version": "0.2.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"postinstall": "cd src && node-gyp configure build",
"cli": "ts-node cli_test.ts",
"compile": "tsc && xcopy /Y src\\build\\Release\\lzham.node dist\\build\\Release\\ && xcopy /Y LICENSE.md dist\\",
"compile": "tsc && xcopy /Y .\\src\\build\\Release\\lzham.node dist\\build\\Release\\ && xcopy /Y .\\LICENSE.md dist\\",
"watch": "tsc -w",
"start": "ts-node ."
},
Expand Down
11 changes: 7 additions & 4 deletions src/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ class CopyWorker extends EventEmitter {

vpkPath: string;

constructor(vpkPath: string) {
constructor(vpkPath: string, patchWav: boolean = true) {
super();

this.vpkPath = vpkPath;

this.self = new Worker(__dirname+'/worker.js', {
workerData: {
vpkPath
vpkPath,
patchWav
}
});
this.self.on("message", (msg: any) => { this.emit("message", msg) })
Expand Down Expand Up @@ -49,19 +50,21 @@ export class VPKCopy extends EventEmitter {
files: string[] = [];
fileCount: number = 0;
threads: number;
patchWav: boolean;

mode: VPKCopyMode = VPKCopyMode.NONE;
taskResolve: Function | null = null;

constructor(vpkPath: string, threads: number = 8) {
constructor(vpkPath: string, threads: number = 8, patchWav: boolean = true) {
super();

this.vpkPath = vpkPath;
this.threads = threads;
this.patchWav = patchWav;

this.workers = [];
for(let i = 0; i < threads; i++) {
let worker = new CopyWorker(vpkPath);
let worker = new CopyWorker(vpkPath, patchWav);
worker.on("message", (msg: any) => { this.handleWorkerMsg(i, msg) })
this.workers.push(worker);
}
Expand Down
6 changes: 3 additions & 3 deletions src/vpk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class VPK {
.then(() => { this.readHandles = {} })
}

async readFile(path: string): Promise<Buffer | null> {
async readFile(path: string, patchWav: boolean = true): Promise<Buffer | null> {
if(!this.isValid())
throw new Error('VPK isn\'t valid')

Expand Down Expand Up @@ -336,7 +336,7 @@ export class VPK {
}

// Add wav headers
if(path.endsWith('.wav') && camEntry) {
if(patchWav && path.endsWith('.wav') && camEntry) {
let checksum = file.subarray(4, 12);

let firstByteIdx = 12;
Expand Down Expand Up @@ -379,7 +379,7 @@ export class VPK {

file = Buffer.concat([wavHeader, file]);

} else if (crc32(file) !== entry.crc) {
} else if (!path.endsWith('.wav') && crc32(file) !== entry.crc) {
throw new Error('CRC does not match');
}

Expand Down
2 changes: 1 addition & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ parentPort.on("message", async (msg: any) => {
} else {
if(msg.task == "copyFile") {
const { file, destination } = msg;
const data = await vpk.readFile(file)
const data = await vpk.readFile(file, workerData.patchWav)
await fs.mkdir(destination.substring(0,destination.lastIndexOf("/")+1), { recursive: true });
await fs.writeFile(destination, data);
parentPort.postMessage({ type: 1 });
Expand Down

0 comments on commit bef50a2

Please sign in to comment.