From 40346cadae39c86008ebc43cbb13f8ff78a552a2 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Sun, 8 Jul 2018 23:38:10 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Allow=20installPatch=20to=20be=20co?= =?UTF-8?q?nfigurable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/inflateFile.ts | 14 -------------- src/installPatch.ts | 28 ++++++++++++++++++++++++++-- src/ssn/decryption/decryptChunk.ts | 6 +++--- 3 files changed, 29 insertions(+), 19 deletions(-) delete mode 100644 src/inflateFile.ts diff --git a/src/inflateFile.ts b/src/inflateFile.ts deleted file mode 100644 index 0cad854..0000000 --- a/src/inflateFile.ts +++ /dev/null @@ -1,14 +0,0 @@ -import * as fs from 'fs'; -import * as zlib from 'zlib'; - -const fileReadStream = fs.createReadStream('/tmp/patcher/Assets/swtor_de-de_area_alderaan_1.tor'); - -const decompressTransform = zlib.createInflateRaw(); -decompressTransform.on('error', (error) => { - //TODO: need to throw error sync, not async - throw new Error(`Error during decompression: ${error.message}`); -}); - -const fileWriteStream = fs.createWriteStream('/tmp/patcher/Assets/swtor_de-de_area_alderaan_1.tor.raw'); - -fileReadStream.pipe(decompressTransform).pipe(fileWriteStream); diff --git a/src/installPatch.ts b/src/installPatch.ts index d69c31a..f954982 100644 --- a/src/installPatch.ts +++ b/src/installPatch.ts @@ -1,7 +1,31 @@ -import getManifest from './ssn/getManifest'; +import failWithError from './failWithError'; +import { Product } from './interfaces/ISettings'; import getPatch from './ssn/getPatch'; +import verifyProductName from './ssn/verify/verifyProductName'; + +const failFunction = failWithError.bind(null, 'node dist/installPatch.js '); + +if (process.argv.length !== 5) { + failFunction(`Expected 3 arguments but ${process.argv.length - 2} arguments were supplied.`); +} + +//Check that product name is valid +const product = process.argv[2]; +if (!verifyProductName(product)) { + failFunction(`"${product.substring(0, 300)}" is not a valid product name.`); +} + +//Check that from and to are valid numbers +const from = process.argv[3]; +const to = process.argv[4]; +if (!from.match(/^(-1|0|[1-9][0-9]{0,2})$/)) { + failFunction(`from value "${from.substring(0, 300)}" is not a valid integer; it must be in range [-1, 999].`); +} +if (!to.match(/^(0|[1-9][0-9]{0,2})$/)) { + failFunction(`to value "${to.substring(0, 300)}" is not a valid integer; it must be in range [0, 999].`); +} (async () => { - const patch = await getPatch('assets_swtor_de_de', -1, 0); + const patch = await getPatch(product as Product, Number(from), Number(to)); //console.log(patch); })(); diff --git a/src/ssn/decryption/decryptChunk.ts b/src/ssn/decryption/decryptChunk.ts index fcab808..4ac5929 100644 --- a/src/ssn/decryption/decryptChunk.ts +++ b/src/ssn/decryption/decryptChunk.ts @@ -12,9 +12,9 @@ export default function getDecryptor(decryptionKeys: [number, number, number]) { let curChar = encryptedChunk.readUInt8(i); //decrypt byte - const keyPart = ((key2 | 2) >>> 0) & 0xFFFF; - const decryptedByte = int32Mul(keyPart, keyPart ^ 1) >>> 8; - curChar = (curChar ^ (decryptedByte & 0xFF)) & 0xFF; + const keyPart = (key2 | 2) & 0xFFFF; + const decryptedByte = (keyPart * (keyPart ^ 1)) >>> 8; + curChar ^= decryptedByte & 0xFF; //update keys [key0, key1, key2] = updateKeys([key0, key1, key2], curChar);