2018-10-29 18:13:58 -04:00
|
|
|
const child = require('child_process');
|
2019-01-12 21:39:22 -05:00
|
|
|
const event = require('./events');
|
2018-10-29 18:13:58 -04:00
|
|
|
const path = require('path');
|
|
|
|
const handler = require('./handler');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = async function (options) {
|
2019-04-26 20:13:38 -04:00
|
|
|
options.root = path.resolve(options.root);
|
2019-04-28 17:52:37 -04:00
|
|
|
if(!fs.existsSync(options.root)) {
|
|
|
|
event.emit('debug', '[MCLC]: Attempting to create root folder');
|
|
|
|
fs.mkdirSync(options.root);
|
|
|
|
}
|
2018-10-29 18:13:58 -04:00
|
|
|
|
2018-12-01 13:26:15 -05:00
|
|
|
if(options.clientPackage) {
|
2019-04-28 17:52:37 -04:00
|
|
|
event.emit('debug', `[MCLC]: Extracting client package to ${options.root}`);
|
2018-12-01 13:26:15 -05:00
|
|
|
await handler.extractPackage(options.root, options.clientPackage);
|
|
|
|
}
|
|
|
|
|
2018-10-29 18:13:58 -04:00
|
|
|
const directory = path.join(options.root, 'versions', options.version.number);
|
|
|
|
options.directory = directory;
|
2018-12-01 13:26:15 -05:00
|
|
|
const versionFile = await handler.getVersion(options.version.number, options.directory);
|
2019-04-05 21:15:12 -04:00
|
|
|
const mcPath = options.version.custom ? path.join(options.root, 'versions', options.version.custom , `${options.version.custom}.jar`):
|
|
|
|
path.join(directory, `${options.version.number}.jar`);
|
2018-10-29 18:13:58 -04:00
|
|
|
const nativePath = await handler.getNatives(options.root, versionFile, options.os);
|
|
|
|
|
|
|
|
if (!fs.existsSync(mcPath)) {
|
2019-04-28 17:52:37 -04:00
|
|
|
event.emit('debug', '[MCLC]: Attempting to download Minecraft version jar');
|
2018-10-29 18:13:58 -04:00
|
|
|
await handler.getJar(versionFile, options.version.number, directory);
|
|
|
|
}
|
|
|
|
|
2019-02-08 12:19:54 -05:00
|
|
|
let forge = null;
|
2019-04-05 21:15:12 -04:00
|
|
|
let custom = null;
|
2019-04-28 17:52:37 -04:00
|
|
|
if(options.forge) {
|
2019-05-04 22:03:53 -04:00
|
|
|
if(options.forge.path) process.emitWarning('\'options.forge.path\' is deprecated and will be removed. Use \'options.forge\' instead');
|
2019-04-28 17:52:37 -04:00
|
|
|
event.emit('debug', '[MCLC]: Detected Forge in options, getting dependencies');
|
2019-05-04 21:57:12 -04:00
|
|
|
forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path || options.forge);
|
2019-04-28 17:52:37 -04:00
|
|
|
}
|
|
|
|
if(options.version.custom) {
|
|
|
|
event.emit('debug', '[MCLC]: Detected custom in options, setting custom version file');
|
|
|
|
custom = require(path.join(options.root, 'versions', options.version.custom, `${options.version.custom}.json`));
|
|
|
|
}
|
2018-10-29 18:13:58 -04:00
|
|
|
|
2019-02-08 15:18:07 -05:00
|
|
|
const args = [];
|
2018-10-29 18:13:58 -04:00
|
|
|
|
|
|
|
// Jvm
|
|
|
|
let jvm = [
|
|
|
|
'-XX:-UseAdaptiveSizePolicy',
|
|
|
|
'-XX:-OmitStackTraceInFastThrow',
|
|
|
|
'-Dfml.ignorePatchDiscrepancies=true',
|
|
|
|
'-Dfml.ignoreInvalidMinecraftCertificates=true',
|
2019-02-08 12:19:54 -05:00
|
|
|
`-Djava.library.path=${nativePath}`,
|
|
|
|
`-Xmx${options.memory.max}M`,
|
2019-04-18 17:35:39 -04:00
|
|
|
`-Xms${options.memory.min}M`
|
2018-10-29 18:13:58 -04:00
|
|
|
];
|
|
|
|
jvm.push(await handler.getJVM(versionFile, options));
|
2019-02-08 15:18:07 -05:00
|
|
|
if(options.customArgs) jvm = jvm.concat(options.customArgs);
|
2018-10-29 18:13:58 -04:00
|
|
|
|
2019-04-05 21:15:12 -04:00
|
|
|
const classes = await handler.getClasses(options, versionFile);
|
2019-05-04 21:57:12 -04:00
|
|
|
let classPaths = ['-cp'];
|
2019-04-26 20:18:18 -04:00
|
|
|
const separator = options.os === "windows" ? ";" : ":";
|
2019-04-28 17:52:37 -04:00
|
|
|
event.emit('debug', `[MCLC]: Using ${separator} to separate class paths`);
|
2019-02-08 12:19:54 -05:00
|
|
|
if(forge) {
|
2019-04-28 17:52:37 -04:00
|
|
|
event.emit('debug', '[MCLC]: Setting Forge class paths');
|
2019-05-04 21:57:12 -04:00
|
|
|
classPaths.push(`${options.forge.path || options.forge}${separator}${forge.paths.join(separator)}${separator}${classes.join(separator)};${mcPath}`);
|
2019-02-08 18:37:05 -05:00
|
|
|
classPaths.push(forge.forge.mainClass)
|
2019-02-08 12:19:54 -05:00
|
|
|
} else {
|
2019-04-26 20:18:18 -04:00
|
|
|
classPaths.push(`${mcPath}${separator}${classes.join(separator)}`);
|
2019-04-25 08:57:46 -04:00
|
|
|
classPaths.push(versionFile.mainClass || custom.mainClass);
|
2019-02-08 12:19:54 -05:00
|
|
|
}
|
2019-05-04 21:57:12 -04:00
|
|
|
classPaths = await handler.cleanUp(classPaths);
|
2018-10-29 18:13:58 -04:00
|
|
|
|
|
|
|
// Download version's assets
|
2019-04-28 17:52:37 -04:00
|
|
|
event.emit('debug', '[MCLC]: Attempting to download assets');
|
2018-10-29 18:13:58 -04:00
|
|
|
await handler.getAssets(options.root, versionFile);
|
|
|
|
|
2019-03-10 20:18:49 -04:00
|
|
|
// Launch options. Thank you Lyrus for the reformat <3
|
2019-04-05 21:15:12 -04:00
|
|
|
const modification = forge ? forge.forge : null || custom ? custom : null;
|
|
|
|
const launchOptions = await handler.getLaunchOptions(versionFile, modification, options);
|
2018-10-29 18:13:58 -04:00
|
|
|
|
2019-02-08 18:37:05 -05:00
|
|
|
const launchArguments = args.concat(jvm, classPaths, launchOptions);
|
2019-04-26 13:03:39 -04:00
|
|
|
event.emit('arguments', launchArguments);
|
2019-04-28 17:52:37 -04:00
|
|
|
event.emit('debug', launchArguments.join(' '));
|
2018-10-29 18:13:58 -04:00
|
|
|
|
2019-04-26 12:47:39 -04:00
|
|
|
const minecraft = child.spawn(options.javaPath ? options.javaPath : 'java', launchArguments);
|
2019-01-12 21:39:22 -05:00
|
|
|
minecraft.stdout.on('data', (data) => event.emit('data', data));
|
|
|
|
minecraft.stderr.on('data', (data) => event.emit('error', data));
|
|
|
|
minecraft.on('close', (code) => event.emit('close', code));
|
2018-10-29 18:13:58 -04:00
|
|
|
};
|