added support for forge installer. "Merged" #15 and #13. arg length set to 11

This commit is contained in:
Pierce 2019-07-19 06:30:34 -04:00
parent fafd82856f
commit a21fe5036b
3 changed files with 23 additions and 7 deletions

View file

@ -4,6 +4,7 @@ const path = require('path');
const request = require('request'); const request = require('request');
const checksum = require('checksum'); const checksum = require('checksum');
const zip = require('adm-zip'); const zip = require('adm-zip');
const child = require('child_process');
class Handler { class Handler {
constructor(client) { constructor(client) {
@ -19,6 +20,7 @@ class Handler {
const _request = request(url, {timeout: this.options.timeout || 10000}); const _request = request(url, {timeout: this.options.timeout || 10000});
_request.on('error', function(error) { _request.on('error', function(error) {
this.client.emit('debug', `[MCLC]: Failed to download asset to ${path.join(directory, name)} due to\n${e}`);
resolve({ resolve({
failed: true, failed: true,
asset: { asset: {
@ -70,8 +72,8 @@ class Handler {
getVersion() { getVersion() {
return new Promise(resolve => { return new Promise(resolve => {
if(fs.existsSync(path.join(this.options.directory, 'versions', this.options.version.number, `${this.options.version.number}.json`))) { if(fs.existsSync(path.join(this.options.directory, `${this.options.version.number}.json`))) {
this.version = require(path.join(this.options.directory, 'versions', this.options.version.number, `${this.options.version.number}.json`)); this.version = require(path.join(this.options.directory, `${this.options.version.number}.json`));
resolve(this.version); resolve(this.version);
return; return;
} }
@ -197,7 +199,7 @@ class Handler {
}); });
} }
async getForgeDependencies() { async getForgeDependenciesLegacy() {
if(!fs.existsSync(path.join(this.options.root, 'forge'))) { if(!fs.existsSync(path.join(this.options.root, 'forge'))) {
shelljs.mkdir('-p', path.join(this.options.root, 'forge')); shelljs.mkdir('-p', path.join(this.options.root, 'forge'));
} }
@ -243,6 +245,13 @@ class Handler {
return {paths, forge}; return {paths, forge};
} }
runInstaller(path) {
return new Promise(resolve => {
const installer = child.exec(path);
installer.on('close', (code) => resolve());
})
}
getClasses() { getClasses() {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
const libs = []; const libs = [];
@ -308,7 +317,7 @@ class Handler {
let args = type.minecraftArguments ? type.minecraftArguments.split(' ') : type.arguments.game; let args = type.minecraftArguments ? type.minecraftArguments.split(' ') : type.arguments.game;
const assetPath = this.version.assets === "legacy" || this.version.assets === "pre-1.6" ? path.join(this.options.root, 'assets', 'legacy') : path.join(this.options.root, 'assets'); const assetPath = this.version.assets === "legacy" || this.version.assets === "pre-1.6" ? path.join(this.options.root, 'assets', 'legacy') : path.join(this.options.root, 'assets');
if(args.length < 5) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game); if(args.length < 11) args = args.concat(this.version.minecraftArguments ? this.version.minecraftArguments.split(' ') : this.version.arguments.game);
if({}.toString.call(this.options.authorization) === "[object Promise]") { if({}.toString.call(this.options.authorization) === "[object Promise]") {
this.options.authorization = await this.options.authorization; this.options.authorization = await this.options.authorization;

View file

@ -25,6 +25,12 @@ class MCLCore extends EventEmitter {
await packager.extractPackage(this.options.root, this.options.clientPackage); await packager.extractPackage(this.options.root, this.options.clientPackage);
} }
if(this.options.installer) {
// So the forge installer can run without breaking :)
fs.writeFileSync(path.join(this.options.root, 'launcher_profiles.json'), JSON.stringify({}, null, 4));
await this.handler.runInstaller(this.options.installer)
}
const directory = path.join(this.options.root, 'versions', this.options.version.number); const directory = path.join(this.options.root, 'versions', this.options.version.number);
this.options.directory = directory; this.options.directory = directory;
@ -43,7 +49,7 @@ class MCLCore extends EventEmitter {
let custom = null; let custom = null;
if(this.options.forge) { if(this.options.forge) {
this.emit('debug', '[MCLC]: Detected Forge in options, getting dependencies'); this.emit('debug', '[MCLC]: Detected Forge in options, getting dependencies');
forge = await this.handler.getForgeDependencies(); forge = await this.handler.getForgeDependenciesLegacy();
} }
if(this.options.version.custom) { if(this.options.version.custom) {
this.emit('debug', '[MCLC]: Detected custom in options, setting custom version file'); this.emit('debug', '[MCLC]: Detected custom in options, setting custom version file');
@ -75,7 +81,8 @@ class MCLCore extends EventEmitter {
classPaths.push(forge.forge.mainClass) classPaths.push(forge.forge.mainClass)
} else { } else {
const file = custom || versionFile; const file = custom || versionFile;
classPaths.push(`${mcPath}${separator}${classes.join(separator)}`); const jar = fs.existsSync(mcPath) ? `${mcPath}${separator}` : '';
classPaths.push(`${jar}${classes.join(separator)}`);
classPaths.push(file.mainClass); classPaths.push(file.mainClass);
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "minecraft-launcher-core", "name": "minecraft-launcher-core",
"version": "3.5.3", "version": "3.6.0",
"description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS", "description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS",
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {