Files
blitzkit/scripts/applyPatches.ts
T

78 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-03-13 00:17:30 -05:00
import { mkdir, writeFile } from 'fs/promises';
import { parse as parsePath } from 'path';
2024-08-12 13:31:06 -05:00
import ProgressBar from 'progress';
import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
2024-03-13 00:17:30 -05:00
import { readStringDVPL } from '../src/core/blitz/readStringDVPL';
2024-08-12 13:31:06 -05:00
import { readYAMLDVPL } from '../src/core/blitz/readYAMLDVPL';
2024-03-13 00:17:30 -05:00
import { writeDVPL } from '../src/core/blitz/writeDVPL';
2024-08-27 14:55:43 -05:00
import { assertSecret } from '../src/core/blitzkit/secret';
2024-04-23 16:08:13 -05:00
import { dvp } from '../submodules/blitzkit-closed/src/dvp';
2024-03-13 00:17:30 -05:00
import { DATA } from './buildAssets/constants';
const versionTextFile = await readStringDVPL(`${DATA}/version.txt.dvpl`);
2024-08-12 13:31:33 -05:00
const currentVersion = versionTextFile
.split(' ')[0]
.split('.')
.slice(0, 3)
.join('.');
2024-03-13 00:17:30 -05:00
2024-03-13 00:22:54 -05:00
console.log(`Installing patches for ${currentVersion}...`);
2024-03-13 00:17:30 -05:00
let patchIndex = 1;
while (true) {
const response = await fetch(
2024-08-27 14:55:43 -05:00
`${assertSecret(process.env.WOTB_DLC_CDN)}/dlc/s${currentVersion}_${patchIndex}.yaml`,
2024-03-13 00:17:30 -05:00
);
if (response.status === 200) {
2024-03-13 00:22:54 -05:00
console.log(`Applying patch ${patchIndex}...`);
2024-03-13 00:17:30 -05:00
const data = parseYaml(await response.text());
2024-08-27 14:40:43 -05:00
const dvpm = await fetch(
2024-08-27 14:55:43 -05:00
`${assertSecret(process.env.WOTB_DLC_CDN)}/dlc/${data.dx11}`,
2024-08-27 14:40:43 -05:00
).then((response) => response.arrayBuffer());
2024-03-13 00:17:30 -05:00
const dvpd = await fetch(
2024-08-27 14:55:43 -05:00
`${assertSecret(process.env.WOTB_DLC_CDN)}/dlc/${data.dx11.replace('.dvpm', '.dvpd')}`,
2024-03-13 00:17:30 -05:00
).then((response) => response.arrayBuffer());
const files = await dvp(dvpm, dvpd);
2024-08-12 13:31:06 -05:00
const bar = new ProgressBar(
`Patching ${files.length} files :bar`,
files.length,
);
2024-03-13 00:17:30 -05:00
await Promise.all(
files.map(async ({ path, data }) => {
const { dir } = parsePath(path);
await mkdir(`${DATA}/${dir}`, { recursive: true });
2024-08-27 14:40:43 -05:00
await writeFile(
`${DATA}/${path}.dvpl`,
new Uint8Array(writeDVPL(Buffer.from(data))),
);
2024-08-12 13:31:06 -05:00
bar.tick();
2024-03-13 00:17:30 -05:00
}),
);
2024-08-12 13:31:06 -05:00
if ('dynamicContentLocalizationsDir' in data) {
console.log('Found dynamic content localizations; patching...');
const localizationsResponse = await fetch(
2024-08-27 14:55:43 -05:00
`${assertSecret(process.env.WOTB_DLC_CDN)}/dlc/${data.dynamicContentLocalizationsDir}/en.yaml`,
2024-08-12 13:31:06 -05:00
);
const newStrings = parseYaml(await localizationsResponse.text());
const oldStrings = await readYAMLDVPL<Record<string, string>>(
`${DATA}/Strings/en.yaml.dvpl`,
);
const patchedStrings = { ...oldStrings, ...newStrings };
const patchedContent = stringifyYaml(patchedStrings);
await writeFile(
`${DATA}/Strings/en.yaml.dvpl`,
2024-08-27 14:40:43 -05:00
new Uint8Array(writeDVPL(Buffer.from(patchedContent))),
2024-08-12 13:31:06 -05:00
);
}
2024-03-13 00:17:30 -05:00
patchIndex++;
} else break;
}