diff --git a/components/handler.js b/components/handler.js index 85f83d0..eae0ab6 100644 --- a/components/handler.js +++ b/components/handler.js @@ -95,9 +95,12 @@ class Handler { checkSum (hash, file) { return new Promise((resolve, reject) => { checksum.file(file, (err, sum) => { - err - ? reject(new Error(err)) - : resolve(hash === sum) + if (err) { + this.client.emit('debug', `[MCLC]: Failed to check file hash due to ${err}`) + resolve(false) + } else { + resolve(hash === sum) + } }) }) } @@ -107,8 +110,7 @@ class Handler { const versionJsonPath = this.options.overrides.versionJson || path.join(this.options.directory, `${this.options.version.number}.json`) if (fs.existsSync(versionJsonPath)) { this.version = JSON.parse(fs.readFileSync(versionJsonPath)) - resolve(this.version) - return + return resolve(this.version) } const manifest = `${this.options.overrides.url.meta}/mc/game/version_manifest.json` @@ -124,7 +126,7 @@ class Handler { this.client.emit('debug', '[MCLC]: Parsed version from version manifest') this.version = JSON.parse(body) - resolve(this.version) + return resolve(this.version) }) } } @@ -370,10 +372,17 @@ class Handler { const launchArgs = `"${this.options.javaPath ? this.options.javaPath : 'java'}" -jar ${path.resolve(this.options.forgeWrapper.jar)}` + ` --installer=${this.options.forge} --instance=${this.options.root} ` + `--saveTo=${path.join(this.options.root, 'libraries', 'io', 'github', 'zekerzhayard', 'ForgeWrapper', this.options.forgeWrapper.version)}` + const fw = child.exec(launchArgs) + const forgeJson = path.join(this.options.root, 'forge', this.version.id, 'version.json') fw.on('close', (e) => { - resolve(JSON.parse(fs.readFileSync(path.join(this.options.root, 'forge', this.version.id, 'version.json'), { encoding: 'utf8' }))) + if (!fs.existsSync(forgeJson)) { + this.client.emit('debug', '[MCLC]: ForgeWrapper did not produce a version file, using Vanilla') + resolve(null) + } else { + resolve(JSON.parse(fs.readFileSync(forgeJson, { encoding: 'utf8' }))) + } }) }) } @@ -548,17 +557,14 @@ class Handler { } async extractPackage (options = this.options) { - return new Promise(async resolve => { - if (options.clientPackage.startsWith('http')) { - await this.downloadAsync(options.clientPackage, options.root, 'clientPackage.zip', true, 'client-package') - options.clientPackage = path.join(options.root, 'clientPackage.zip') - } - new Zip(options.clientPackage).extractAllTo(options.root, true) - this.client.emit('package-extract', true) - if (options.removePackage) shelljs.rm(options.clientPackage) + if (options.clientPackage.startsWith('http')) { + await this.downloadAsync(options.clientPackage, options.root, 'clientPackage.zip', true, 'client-package') + options.clientPackage = path.join(options.root, 'clientPackage.zip') + } + new Zip(options.clientPackage).extractAllTo(options.root, true) + if (options.removePackage) shelljs.rm(options.clientPackage) - resolve() - }) + return this.client.emit('package-extract', true) } } diff --git a/components/launcher.js b/components/launcher.js index afa65dc..6c51451 100644 --- a/components/launcher.js +++ b/components/launcher.js @@ -5,7 +5,7 @@ const fs = require('fs') const EventEmitter = require('events').EventEmitter class MCLCore extends EventEmitter { - async launch (options = this.options) { + async launch (options) { this.options = options this.options.root = path.resolve(this.options.root) this.options.overrides = { @@ -81,7 +81,7 @@ class MCLCore extends EventEmitter { if (forge === false) custom = await this.handler.getForgedWrapped() } if (this.options.version.custom || custom) { - this.emit('debug', '[MCLC]: Detected custom in options, setting custom version file') + if (!custom) this.emit('debug', '[MCLC]: Detected custom in options, setting custom version file') custom = custom || JSON.parse(fs.readFileSync(path.join(this.options.root, 'versions', this.options.version.custom, `${this.options.version.custom}.json`), { encoding: 'utf8' })) } @@ -93,9 +93,9 @@ class MCLCore extends EventEmitter { '-XX:-OmitStackTraceInFastThrow', '-Dfml.ignorePatchDiscrepancies=true', '-Dfml.ignoreInvalidMinecraftCertificates=true', - `-Djava.library.path=${nativePath}`, - `-Xmx${this.options.memory.max}M`, - `-Xms${this.options.memory.min}M` + `-Djava.library.path=${nativePath}`, + `-Xmx${this.options.memory.max}M`, + `-Xms${this.options.memory.min}M` ] if (this.handler.getOS() === 'osx') { if (parseInt(versionFile.id.split('.')[1]) > 12) jvm.push(await this.handler.getJVM()) diff --git a/package.json b/package.json index 4447acf..b081da1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "minecraft-launcher-core", - "version": "3.14.1", + "version": "3.14.2", "description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS", "main": "index.js", "dependencies": {