Adds in support for custom jars like optifine

This commit is contained in:
Pierce 2019-04-05 21:15:12 -04:00
parent d523d6563c
commit c767fb0685
4 changed files with 34 additions and 12 deletions

View file

@ -43,6 +43,7 @@ launcher.authenticator.getAuth("email", "password").then(auth => {
| `options.javaPath` | String | Path to the JRE executable file, will default to `java` if not entered. | False |
| `options.version.number` | String | Minecraft version that is going to be launched. | True |
| `options.version.type` | String | Any string. The actual Minecraft launcher uses `release` and `snapshot`. | True |
| `options.version.custom` | String | Name of the jar, json, and folder of the custom client you are launching with. (Optifine) | False |
| `options.memory.max` | String | Max amount of memory being used by Minectaft | True |
| `options.memory.min` | String | Min amount of memory being used by Minectaft | True |
| `options.forge.path` | String | Path to Universal Forge Jar | False |
@ -54,6 +55,9 @@ launcher.authenticator.getAuth("email", "password").then(auth => {
| `options.proxy.username` | String | Username for the proxy. | False |
| `options.proxy.password` | String | Password for the proxy. | False |
##### Note
If you are loading up a client outside of vanilla Minecraft and Forge (Optifine for an example), you'll need to download the needed files yourself.
#### launcher.authenticator Functions
##### getAuth

View file

@ -169,7 +169,7 @@ module.exports.getForgeDependencies = async function(root, version, forgeJarPath
if(!fs.existsSync(path.join(root, 'forge'))) {
shelljs.mkdir('-p', path.join(root, 'forge'));
}
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 forge = require(path.join(root, 'forge', `${version.id}`, 'version.json'));
const forgeLibs = forge.libraries;
@ -212,16 +212,28 @@ module.exports.getForgeDependencies = async function(root, version, forgeJarPath
return {paths, forge};
};
module.exports.getClasses = function (root, version) {
module.exports.getClasses = function (options, version) {
return new Promise(async (resolve) => {
const libs = [];
if(options.version.custom) {
const customJarJson = require(path.join(options.root, 'versions', options.version.custom, `${options.version.custom}.json`));
customJarJson.libraries.map(library => {
const lib = library.name.split(':');
const jarPath = path.join(options.root, 'libraries', `${lib[0].replace(/\./g, '/')}/${lib[1]}/${lib[2]}`);
const name = `${lib[1]}-${lib[2]}.jar`;
libs.push(`${jarPath}\\${name}`);
})
}
const libraries = version.libraries.map(async (_lib) => {
if(!_lib.downloads.artifact) return;
const libraryPath = _lib.downloads.artifact.path;
const libraryUrl = _lib.downloads.artifact.url;
const libraryDirectory = path.join(root, 'libraries', libraryPath);
const libraryDirectory = path.join(options.root, 'libraries', libraryPath);
if(!fs.existsSync(libraryDirectory)) {
let directory = libraryDirectory.split('\\');
@ -240,9 +252,10 @@ module.exports.getClasses = function (root, version) {
});
};
module.exports.getLaunchOptions = function (version, forge, options) {
module.exports.getLaunchOptions = function (version, modification, options) {
return new Promise(resolve => {
const type = forge || version;
let type = modification || version;
const arguments = type.minecraftArguments ? type.minecraftArguments.split(' ') : type.arguments.game;
const assetPath = version.assets === "legacy" || version.assets === "pre-1.6" ? path.join(options.root, 'assets', 'legacy') : path.join(options.root, 'assets');

View file

@ -15,7 +15,8 @@ module.exports = async function (options) {
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 mcPath = options.version.custom ? path.join(options.root, 'versions', options.version.custom , `${options.version.custom}.jar`):
path.join(directory, `${options.version.number}.jar`);
const nativePath = await handler.getNatives(options.root, versionFile, options.os);
if (!fs.existsSync(mcPath)) {
@ -23,9 +24,9 @@ module.exports = async function (options) {
}
let forge = null;
if(options.forge) {
forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path);
}
let custom = null;
if(options.forge) forge = await handler.getForgeDependencies(options.root, versionFile, options.forge.path);
if(options.version.custom) custom = require(path.join(options.root, 'versions', options.version.custom, `${options.version.custom}.json`));
const args = [];
@ -43,11 +44,14 @@ module.exports = async function (options) {
jvm.push(await handler.getJVM(versionFile, options));
if(options.customArgs) jvm = jvm.concat(options.customArgs);
const classes = await handler.getClasses(options.root, versionFile);
const classes = await handler.getClasses(options, versionFile);
const classPaths = ['-cp'];
if(forge) {
classPaths.push(`${options.forge.path};${forge.paths.join(';')};${classes.join(';')};${mcPath}`);
classPaths.push(forge.forge.mainClass)
} else if(custom) {
classPaths.push(`${classes.join(";")};${mcPath}`);
classPaths.push(custom.mainClass);
} else {
classPaths.push(`${mcPath};${classes.join(";")}`);
classPaths.push(versionFile.mainClass);
@ -57,7 +61,8 @@ module.exports = async function (options) {
await handler.getAssets(options.root, versionFile);
// Launch options. Thank you Lyrus for the reformat <3
const launchOptions = await handler.getLaunchOptions(versionFile, forge ? forge.forge : null, options);
const modification = forge ? forge.forge : null || custom ? custom : null;
const launchOptions = await handler.getLaunchOptions(versionFile, modification, options);
const launchArguments = args.concat(jvm, classPaths, launchOptions);

View file

@ -1,6 +1,6 @@
{
"name": "minecraft-launcher-core",
"version": "2.4.2",
"version": "2.5.0",
"description": "Module that downloads Minecraft assets and runs Minecraft. Also Supports Forge",
"main": "index.js",
"dependencies": {