mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 20:26:22 +03:00
77 lines
No EOL
2.8 KiB
JavaScript
77 lines
No EOL
2.8 KiB
JavaScript
const child = require('child_process');
|
|
const event = require('./events');
|
|
const path = require('path');
|
|
const handler = require('./handler');
|
|
const fs = require('fs');
|
|
|
|
|
|
module.exports = async function (options) {
|
|
if(!fs.existsSync(options.root)) fs.mkdirSync(options.root);
|
|
|
|
if(options.clientPackage) {
|
|
await handler.extractPackage(options.root, options.clientPackage);
|
|
}
|
|
|
|
const directory = path.join(options.root, 'versions', options.version.number);
|
|
options.directory = directory;
|
|
const versionFile = await handler.getVersion(options.version.number, options.directory);
|
|
const mcPath = path.join(directory, `${options.version.number}.jar`);
|
|
const nativePath = await handler.getNatives(options.root, versionFile, options.os);
|
|
|
|
if (!fs.existsSync(mcPath)) {
|
|
await handler.getJar(versionFile, options.version.number, directory);
|
|
}
|
|
|
|
let forge = null;
|
|
if(options.forge) {
|
|
forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path);
|
|
}
|
|
|
|
const args = [];
|
|
|
|
// Jvm
|
|
let jvm = [
|
|
'-XX:-UseAdaptiveSizePolicy',
|
|
'-XX:-OmitStackTraceInFastThrow',
|
|
'-Dfml.ignorePatchDiscrepancies=true',
|
|
'-Dfml.ignoreInvalidMinecraftCertificates=true',
|
|
`-Djava.library.path=${nativePath}`,
|
|
`-Xmx${options.memory.max}M`,
|
|
'-Xincgc'
|
|
];
|
|
jvm.push(await handler.getJVM(versionFile, options));
|
|
if(options.customArgs) jvm = jvm.concat(options.customArgs);
|
|
|
|
let mainClass;
|
|
const classes = await handler.getClasses(options.root, versionFile);
|
|
const classPaths = [];
|
|
if(forge) {
|
|
classPaths.push(`${options.forge.path};${forge.paths.join(';')};${classes.join(';')};${mcPath}`);
|
|
mainClass = forge.forge.mainClass
|
|
} else {
|
|
classPaths.push('-cp');
|
|
classPaths.push(`${mcPath};${classes.join(";")}`);
|
|
classPaths.push(versionFile.mainClass);
|
|
}
|
|
|
|
// Download version's assets
|
|
await handler.getAssets(options.root, versionFile);
|
|
|
|
// Launch options
|
|
let launchOptions;
|
|
if(forge) {
|
|
launchOptions = await handler.getLaunchOptions(versionFile, forge.forge, options);
|
|
} else {
|
|
launchOptions = await handler.getLaunchOptions(versionFile, null, options);
|
|
}
|
|
|
|
// NOTE: Hacky way of setting up launch options, will rework this next update.
|
|
let launchArguments = args.concat(jvm, classPaths, launchOptions);
|
|
if(forge) launchArguments = `${jvm.join(' ')} -cp ${classPaths} ${mainClass} ${launchOptions.join(' ')}`.split(' ');
|
|
|
|
const minecraft = child.spawn(`java`, launchArguments);
|
|
event.emit('start', null);
|
|
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));
|
|
}; |