mirror of
https://github.com/artegoser/pimi-launcher-core.git
synced 2024-11-22 20:26:22 +03:00
Forge Support
This commit is contained in:
parent
05daffc033
commit
f9fc29ee67
3 changed files with 47 additions and 22 deletions
|
@ -143,31 +143,45 @@ module.exports.getForgeDependencies = async function(root, version, forgeJarPath
|
||||||
}
|
}
|
||||||
await new zip(forgeJarPath).extractEntryTo('version.json', path.join(root, 'forge', `${version.id}`), false, true)
|
await new zip(forgeJarPath).extractEntryTo('version.json', path.join(root, 'forge', `${version.id}`), false, true)
|
||||||
|
|
||||||
const forgeLibs = require(path.join(root, 'forge', `${version.id}`, 'version.json')).libraries;
|
const forge = require(path.join(root, 'forge', `${version.id}`, 'version.json'));
|
||||||
const marvenUrl = 'http://files.minecraftforge.net/maven/';
|
const forgeLibs = forge.libraries;
|
||||||
|
const mavenUrl = 'http://files.minecraftforge.net/maven/';
|
||||||
|
const defaultRepo = 'https://libraries.minecraft.net/';
|
||||||
const paths = [];
|
const paths = [];
|
||||||
|
|
||||||
const download = forgeLibs.map(async library => {
|
const download = forgeLibs.map(async library => {
|
||||||
const lib = library.name.split(':');
|
const lib = library.name.split(':');
|
||||||
|
|
||||||
if(lib[0] === 'net.minecraftforge' && lib[1].includes('forge')) return;
|
if(lib[0] === 'net.minecraftforge' && lib[1].includes('forge')) return;
|
||||||
if(!library.url) return;
|
|
||||||
|
|
||||||
const url = `${marvenUrl}${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}/${lib[1]}-${lib[2]}.jar`;
|
let url = mavenUrl;
|
||||||
const jarPath = path.join(root, 'libraries', `${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}`);
|
const jarPath = path.join(root, 'libraries', `${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}`);
|
||||||
const name = `${lib[1]}-${lib[2]}.jar`;
|
const name = `${lib[1]}-${lib[2]}.jar`;
|
||||||
|
|
||||||
if(fs.existsSync(path.join(jarPath, name))) return;
|
if(!library.url) {
|
||||||
|
if(library.serverreq || library.clientreq) {
|
||||||
|
url = defaultRepo;
|
||||||
|
} else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const downloadLink = `${url}${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}/${lib[1]}-${lib[2]}.jar`;
|
||||||
|
|
||||||
|
if(fs.existsSync(path.join(jarPath, name))) {
|
||||||
|
paths.push(`${jarPath}\\${name}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!fs.existsSync(jarPath)) shelljs.mkdir('-p', jarPath);
|
if(!fs.existsSync(jarPath)) shelljs.mkdir('-p', jarPath);
|
||||||
|
|
||||||
await downloadAsync(url, jarPath, name);
|
await downloadAsync(downloadLink, jarPath, name);
|
||||||
|
|
||||||
paths.push(`${jarPath}//${name}`);
|
paths.push(`${jarPath}\\${name}`);
|
||||||
})
|
})
|
||||||
|
|
||||||
await Promise.all(download);
|
await Promise.all(download);
|
||||||
|
|
||||||
return paths;
|
return {paths, forge};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.getClasses = function (root, version) {
|
module.exports.getClasses = function (root, version) {
|
||||||
|
|
|
@ -22,13 +22,12 @@ module.exports = async function (options) {
|
||||||
await handler.getJar(versionFile, options.version.number, directory);
|
await handler.getJar(versionFile, options.version.number, directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = [];
|
let forge = null;
|
||||||
|
if(options.forge) {
|
||||||
|
forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path);
|
||||||
|
}
|
||||||
|
|
||||||
// CGC
|
const args = []
|
||||||
args.push('-Xincgc');
|
|
||||||
|
|
||||||
// Memory
|
|
||||||
const memory = [`-Xmx${options.memory.max}M`];
|
|
||||||
|
|
||||||
// Jvm
|
// Jvm
|
||||||
let jvm = [
|
let jvm = [
|
||||||
|
@ -36,24 +35,36 @@ module.exports = async function (options) {
|
||||||
'-XX:-OmitStackTraceInFastThrow',
|
'-XX:-OmitStackTraceInFastThrow',
|
||||||
'-Dfml.ignorePatchDiscrepancies=true',
|
'-Dfml.ignorePatchDiscrepancies=true',
|
||||||
'-Dfml.ignoreInvalidMinecraftCertificates=true',
|
'-Dfml.ignoreInvalidMinecraftCertificates=true',
|
||||||
`-Djava.library.path=${nativePath}`
|
`-Djava.library.path=${nativePath}`,
|
||||||
|
`-Xmx${options.memory.max}M`,
|
||||||
|
'-Xincgc'
|
||||||
];
|
];
|
||||||
jvm.push(await handler.getJVM(versionFile, options));
|
jvm.push(await handler.getJVM(versionFile, options));
|
||||||
|
|
||||||
const classes = await handler.getClasses(options.root, versionFile);
|
const classes = await handler.getClasses(options.root, versionFile);
|
||||||
const classPaths = ['-cp'];
|
let mainClass;
|
||||||
classPaths.push(`${mcPath}; ${classes.join(";")}`);
|
const classPaths = [];
|
||||||
classPaths.push(versionFile.mainClass);
|
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
|
// Download version's assets
|
||||||
await handler.getAssets(options.root, versionFile);
|
await handler.getAssets(options.root, versionFile);
|
||||||
|
|
||||||
// Launch options
|
// Launch options
|
||||||
const launchOptions = await handler.getLaunchOptions(versionFile, options);
|
const launchOptions = await handler.getLaunchOptions(versionFile, options);
|
||||||
|
if(forge) launchOptions.push('--tweakClass net.minecraftforge.fml.common.launcher.FMLTweaker');
|
||||||
|
|
||||||
const arguments = args.concat(memory, jvm, classPaths, launchOptions);
|
// NOTE: Hacky way of setting up launch options, will rework this next update.
|
||||||
const minecraft = child.spawn("java", arguments);
|
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);
|
event.emit('start', null);
|
||||||
minecraft.stdout.on('data', (data) => event.emit('data', data));
|
minecraft.stdout.on('data', (data) => event.emit('data', data));
|
||||||
minecraft.stderr.on('data', (data) => event.emit('error', data));
|
minecraft.stderr.on('data', (data) => event.emit('error', data));
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "minecraft-launcher-core",
|
"name": "minecraft-launcher-core",
|
||||||
"version": "1.2.1",
|
"version": "2.0.0",
|
||||||
"description": "Module that downloads Minecraft assets and runs Minecraft.",
|
"description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"adm-zip": "^0.4.13",
|
"adm-zip": "^0.4.13",
|
||||||
|
|
Loading…
Add table
Reference in a new issue