2019-11-16 14:17:55 -08:00
|
|
|
const AdmZip = require('adm-zip')
|
|
|
|
const child_process = require('child_process')
|
|
|
|
const crypto = require('crypto')
|
|
|
|
const fs = require('fs-extra')
|
2022-12-24 19:17:30 -08:00
|
|
|
const { LoggerUtil } = require('helios-core')
|
2023-02-24 18:02:18 -08:00
|
|
|
const { getMojangOS, isLibraryCompatible, mcVersionAtLeast } = require('helios-core/common')
|
|
|
|
const { Type } = require('helios-distribution-types')
|
2019-11-16 14:17:55 -08:00
|
|
|
const os = require('os')
|
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
const ConfigManager = require('./configmanager')
|
|
|
|
|
2022-12-24 19:17:30 -08:00
|
|
|
const logger = LoggerUtil.getLogger('ProcessBuilder')
|
2019-11-16 14:17:55 -08:00
|
|
|
|
2023-12-03 15:02:57 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Only forge and fabric are top level mod loaders.
|
|
|
|
*
|
|
|
|
* Forge 1.13+ launch logic is similar to fabrics, for now using usingFabricLoader flag to
|
|
|
|
* change minor details when needed.
|
|
|
|
*
|
|
|
|
* Rewrite of this module may be needed in the future.
|
|
|
|
*/
|
2019-11-16 14:17:55 -08:00
|
|
|
class ProcessBuilder {
|
|
|
|
|
2023-12-03 15:02:57 -08:00
|
|
|
constructor(distroServer, vanillaManifest, modManifest, authUser, launcherVersion){
|
2023-02-25 00:09:22 -08:00
|
|
|
this.gameDir = path.join(ConfigManager.getInstanceDirectory(), distroServer.rawServer.id)
|
2019-11-16 14:17:55 -08:00
|
|
|
this.commonDir = ConfigManager.getCommonDirectory()
|
|
|
|
this.server = distroServer
|
2023-12-03 15:02:57 -08:00
|
|
|
this.vanillaManifest = vanillaManifest
|
|
|
|
this.modManifest = modManifest
|
2019-11-16 14:17:55 -08:00
|
|
|
this.authUser = authUser
|
|
|
|
this.launcherVersion = launcherVersion
|
2020-09-05 19:43:09 -07:00
|
|
|
this.forgeModListFile = path.join(this.gameDir, 'forgeMods.list') // 1.13+
|
2019-11-16 14:17:55 -08:00
|
|
|
this.fmlDir = path.join(this.gameDir, 'forgeModList.json')
|
|
|
|
this.llDir = path.join(this.gameDir, 'liteloaderModList.json')
|
|
|
|
this.libPath = path.join(this.commonDir, 'libraries')
|
|
|
|
|
|
|
|
this.usingLiteLoader = false
|
2023-12-03 15:02:57 -08:00
|
|
|
this.usingFabricLoader = false
|
2019-11-16 14:17:55 -08:00
|
|
|
this.llPath = null
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convienence method to run the functions typically used to build a process.
|
|
|
|
*/
|
|
|
|
build(){
|
|
|
|
fs.ensureDirSync(this.gameDir)
|
|
|
|
const tempNativePath = path.join(os.tmpdir(), ConfigManager.getTempNativeFolder(), crypto.pseudoRandomBytes(16).toString('hex'))
|
|
|
|
process.throwDeprecation = true
|
|
|
|
this.setupLiteLoader()
|
2022-12-24 19:17:30 -08:00
|
|
|
logger.info('Using liteloader:', this.usingLiteLoader)
|
2023-12-03 15:02:57 -08:00
|
|
|
this.usingFabricLoader = this.server.modules.some(mdl => mdl.rawModule.type === Type.Fabric)
|
|
|
|
logger.info('Using fabric loader:', this.usingFabricLoader)
|
2023-02-25 00:09:22 -08:00
|
|
|
const modObj = this.resolveModConfiguration(ConfigManager.getModConfiguration(this.server.rawServer.id).mods, this.server.modules)
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
// Mod list below 1.13
|
2023-12-03 15:02:57 -08:00
|
|
|
// Fabric only supports 1.14+
|
2023-02-25 00:09:22 -08:00
|
|
|
if(!mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){
|
2020-09-05 19:43:09 -07:00
|
|
|
this.constructJSONModList('forge', modObj.fMods, true)
|
2019-11-16 14:17:55 -08:00
|
|
|
if(this.usingLiteLoader){
|
2020-09-05 19:43:09 -07:00
|
|
|
this.constructJSONModList('liteloader', modObj.lMods, true)
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const uberModArr = modObj.fMods.concat(modObj.lMods)
|
|
|
|
let args = this.constructJVMArguments(uberModArr, tempNativePath)
|
|
|
|
|
2023-02-25 00:09:22 -08:00
|
|
|
if(mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){
|
2020-09-05 19:43:09 -07:00
|
|
|
//args = args.concat(this.constructModArguments(modObj.fMods))
|
|
|
|
args = args.concat(this.constructModList(modObj.fMods))
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
|
2022-12-24 19:17:30 -08:00
|
|
|
logger.info('Launch Arguments:', args)
|
2019-11-16 14:17:55 -08:00
|
|
|
|
2023-02-25 00:09:22 -08:00
|
|
|
const child = child_process.spawn(ConfigManager.getJavaExecutable(this.server.rawServer.id), args, {
|
2019-11-16 14:17:55 -08:00
|
|
|
cwd: this.gameDir,
|
|
|
|
detached: ConfigManager.getLaunchDetached()
|
|
|
|
})
|
|
|
|
|
|
|
|
if(ConfigManager.getLaunchDetached()){
|
|
|
|
child.unref()
|
|
|
|
}
|
|
|
|
|
|
|
|
child.stdout.setEncoding('utf8')
|
|
|
|
child.stderr.setEncoding('utf8')
|
|
|
|
|
|
|
|
child.stdout.on('data', (data) => {
|
2022-12-24 19:17:30 -08:00
|
|
|
data.trim().split('\n').forEach(x => console.log(`\x1b[32m[Minecraft]\x1b[0m ${x}`))
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
})
|
|
|
|
child.stderr.on('data', (data) => {
|
2022-12-24 19:17:30 -08:00
|
|
|
data.trim().split('\n').forEach(x => console.log(`\x1b[31m[Minecraft]\x1b[0m ${x}`))
|
2019-11-16 14:17:55 -08:00
|
|
|
})
|
|
|
|
child.on('close', (code, signal) => {
|
2022-12-24 19:17:30 -08:00
|
|
|
logger.info('Exited with code', code)
|
2019-11-16 14:17:55 -08:00
|
|
|
fs.remove(tempNativePath, (err) => {
|
|
|
|
if(err){
|
|
|
|
logger.warn('Error while deleting temp dir', err)
|
|
|
|
} else {
|
2022-12-24 19:17:30 -08:00
|
|
|
logger.info('Temp dir deleted successfully.')
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
return child
|
|
|
|
}
|
|
|
|
|
2022-11-27 15:13:50 -08:00
|
|
|
/**
|
|
|
|
* Get the platform specific classpath separator. On windows, this is a semicolon.
|
|
|
|
* On Unix, this is a colon.
|
|
|
|
*
|
|
|
|
* @returns {string} The classpath separator for the current operating system.
|
|
|
|
*/
|
|
|
|
static getClasspathSeparator() {
|
|
|
|
return process.platform === 'win32' ? ';' : ':'
|
|
|
|
}
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
/**
|
|
|
|
* Determine if an optional mod is enabled from its configuration value. If the
|
|
|
|
* configuration value is null, the required object will be used to
|
|
|
|
* determine if it is enabled.
|
|
|
|
*
|
|
|
|
* A mod is enabled if:
|
|
|
|
* * The configuration is not null and one of the following:
|
|
|
|
* * The configuration is a boolean and true.
|
|
|
|
* * The configuration is an object and its 'value' property is true.
|
|
|
|
* * The configuration is null and one of the following:
|
|
|
|
* * The required object is null.
|
|
|
|
* * The required object's 'def' property is null or true.
|
|
|
|
*
|
|
|
|
* @param {Object | boolean} modCfg The mod configuration object.
|
|
|
|
* @param {Object} required Optional. The required object from the mod's distro declaration.
|
|
|
|
* @returns {boolean} True if the mod is enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
static isModEnabled(modCfg, required = null){
|
2023-02-24 18:02:18 -08:00
|
|
|
return modCfg != null ? ((typeof modCfg === 'boolean' && modCfg) || (typeof modCfg === 'object' && (typeof modCfg.value !== 'undefined' ? modCfg.value : true))) : required != null ? required.def : true
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function which performs a preliminary scan of the top level
|
|
|
|
* mods. If liteloader is present here, we setup the special liteloader
|
|
|
|
* launch options. Note that liteloader is only allowed as a top level
|
|
|
|
* mod. It must not be declared as a submodule.
|
|
|
|
*/
|
|
|
|
setupLiteLoader(){
|
2023-02-24 18:02:18 -08:00
|
|
|
for(let ll of this.server.modules){
|
|
|
|
if(ll.rawModule.type === Type.LiteLoader){
|
|
|
|
if(!ll.getRequired().value){
|
|
|
|
const modCfg = ConfigManager.getModConfiguration(this.server.rawServer.id).mods
|
|
|
|
if(ProcessBuilder.isModEnabled(modCfg[ll.getVersionlessMavenIdentifier()], ll.getRequired())){
|
2023-02-25 00:09:22 -08:00
|
|
|
if(fs.existsSync(ll.getPath())){
|
2019-11-16 14:17:55 -08:00
|
|
|
this.usingLiteLoader = true
|
2023-02-25 00:09:22 -08:00
|
|
|
this.llPath = ll.getPath()
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2023-02-25 00:09:22 -08:00
|
|
|
if(fs.existsSync(ll.getPath())){
|
2019-11-16 14:17:55 -08:00
|
|
|
this.usingLiteLoader = true
|
2023-02-25 00:09:22 -08:00
|
|
|
this.llPath = ll.getPath()
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve an array of all enabled mods. These mods will be constructed into
|
|
|
|
* a mod list format and enabled at launch.
|
|
|
|
*
|
|
|
|
* @param {Object} modCfg The mod configuration object.
|
|
|
|
* @param {Array.<Object>} mdls An array of modules to parse.
|
|
|
|
* @returns {{fMods: Array.<Object>, lMods: Array.<Object>}} An object which contains
|
|
|
|
* a list of enabled forge mods and litemods.
|
|
|
|
*/
|
|
|
|
resolveModConfiguration(modCfg, mdls){
|
|
|
|
let fMods = []
|
|
|
|
let lMods = []
|
|
|
|
|
|
|
|
for(let mdl of mdls){
|
2023-02-24 18:02:18 -08:00
|
|
|
const type = mdl.rawModule.type
|
2023-12-03 15:02:57 -08:00
|
|
|
if(type === Type.ForgeMod || type === Type.LiteMod || type === Type.LiteLoader || type === Type.FabricMod){
|
2023-02-24 18:02:18 -08:00
|
|
|
const o = !mdl.getRequired().value
|
|
|
|
const e = ProcessBuilder.isModEnabled(modCfg[mdl.getVersionlessMavenIdentifier()], mdl.getRequired())
|
2019-11-16 14:17:55 -08:00
|
|
|
if(!o || (o && e)){
|
2023-02-24 18:02:18 -08:00
|
|
|
if(mdl.subModules.length > 0){
|
|
|
|
const v = this.resolveModConfiguration(modCfg[mdl.getVersionlessMavenIdentifier()].mods, mdl.subModules)
|
2019-11-16 14:17:55 -08:00
|
|
|
fMods = fMods.concat(v.fMods)
|
|
|
|
lMods = lMods.concat(v.lMods)
|
2023-03-18 16:01:22 -07:00
|
|
|
if(type === Type.LiteLoader){
|
2019-11-16 14:17:55 -08:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
2023-12-03 15:02:57 -08:00
|
|
|
if(type === Type.ForgeMod || type === Type.FabricMod){
|
2019-11-16 14:17:55 -08:00
|
|
|
fMods.push(mdl)
|
|
|
|
} else {
|
|
|
|
lMods.push(mdl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
fMods,
|
|
|
|
lMods
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 12:03:17 -07:00
|
|
|
_lteMinorVersion(version) {
|
2023-12-03 15:02:57 -08:00
|
|
|
return Number(this.modManifest.id.split('-')[0].split('.')[1]) <= Number(version)
|
2020-01-18 09:02:00 -08:00
|
|
|
}
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
/**
|
|
|
|
* Test to see if this version of forge requires the absolute: prefix
|
|
|
|
* on the modListFile repository field.
|
|
|
|
*/
|
|
|
|
_requiresAbsolute(){
|
|
|
|
try {
|
2020-06-23 12:03:17 -07:00
|
|
|
if(this._lteMinorVersion(9)) {
|
2020-01-18 09:02:00 -08:00
|
|
|
return false
|
|
|
|
}
|
2023-12-03 15:02:57 -08:00
|
|
|
const ver = this.modManifest.id.split('-')[2]
|
2019-11-16 14:17:55 -08:00
|
|
|
const pts = ver.split('.')
|
|
|
|
const min = [14, 23, 3, 2655]
|
|
|
|
for(let i=0; i<pts.length; i++){
|
|
|
|
const parsed = Number.parseInt(pts[i])
|
|
|
|
if(parsed < min[i]){
|
|
|
|
return false
|
|
|
|
} else if(parsed > min[i]){
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
// We know old forge versions follow this format.
|
|
|
|
// Error must be caused by newer version.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Equal or errored
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a mod list json object.
|
|
|
|
*
|
|
|
|
* @param {'forge' | 'liteloader'} type The mod list type to construct.
|
|
|
|
* @param {Array.<Object>} mods An array of mods to add to the mod list.
|
|
|
|
* @param {boolean} save Optional. Whether or not we should save the mod list file.
|
|
|
|
*/
|
2020-09-05 19:43:09 -07:00
|
|
|
constructJSONModList(type, mods, save = false){
|
2019-11-16 14:17:55 -08:00
|
|
|
const modList = {
|
|
|
|
repositoryRoot: ((type === 'forge' && this._requiresAbsolute()) ? 'absolute:' : '') + path.join(this.commonDir, 'modstore')
|
|
|
|
}
|
|
|
|
|
|
|
|
const ids = []
|
|
|
|
if(type === 'forge'){
|
|
|
|
for(let mod of mods){
|
2023-03-18 16:01:22 -07:00
|
|
|
ids.push(mod.getExtensionlessMavenIdentifier())
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(let mod of mods){
|
2023-03-18 16:01:22 -07:00
|
|
|
ids.push(mod.getMavenIdentifier())
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
modList.modRef = ids
|
|
|
|
|
|
|
|
if(save){
|
|
|
|
const json = JSON.stringify(modList, null, 4)
|
|
|
|
fs.writeFileSync(type === 'forge' ? this.fmlDir : this.llDir, json, 'UTF-8')
|
|
|
|
}
|
|
|
|
|
|
|
|
return modList
|
|
|
|
}
|
|
|
|
|
2020-09-05 19:43:09 -07:00
|
|
|
// /**
|
|
|
|
// * Construct the mod argument list for forge 1.13
|
|
|
|
// *
|
|
|
|
// * @param {Array.<Object>} mods An array of mods to add to the mod list.
|
|
|
|
// */
|
|
|
|
// constructModArguments(mods){
|
|
|
|
// const argStr = mods.map(mod => {
|
2023-03-18 16:01:22 -07:00
|
|
|
// return mod.getExtensionlessMavenIdentifier()
|
2020-09-05 19:43:09 -07:00
|
|
|
// }).join(',')
|
|
|
|
|
|
|
|
// if(argStr){
|
|
|
|
// return [
|
|
|
|
// '--fml.mavenRoots',
|
|
|
|
// path.join('..', '..', 'common', 'modstore'),
|
|
|
|
// '--fml.mods',
|
|
|
|
// argStr
|
|
|
|
// ]
|
|
|
|
// } else {
|
|
|
|
// return []
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
/**
|
2023-12-03 15:02:57 -08:00
|
|
|
* Construct the mod argument list for forge 1.13 and Fabric
|
2019-11-16 14:17:55 -08:00
|
|
|
*
|
|
|
|
* @param {Array.<Object>} mods An array of mods to add to the mod list.
|
|
|
|
*/
|
2020-09-05 19:43:09 -07:00
|
|
|
constructModList(mods) {
|
|
|
|
const writeBuffer = mods.map(mod => {
|
2023-12-03 15:02:57 -08:00
|
|
|
return this.usingFabricLoader ? mod.getPath() : mod.getExtensionlessMavenIdentifier()
|
2020-09-05 19:43:09 -07:00
|
|
|
}).join('\n')
|
2019-11-16 14:17:55 -08:00
|
|
|
|
2020-09-05 19:43:09 -07:00
|
|
|
if(writeBuffer) {
|
|
|
|
fs.writeFileSync(this.forgeModListFile, writeBuffer, 'UTF-8')
|
2023-12-03 15:02:57 -08:00
|
|
|
return this.usingFabricLoader ? [
|
|
|
|
'--fabric.addMods',
|
|
|
|
`@${this.forgeModListFile}`
|
|
|
|
] : [
|
2019-11-16 14:17:55 -08:00
|
|
|
'--fml.mavenRoots',
|
|
|
|
path.join('..', '..', 'common', 'modstore'),
|
2020-09-05 19:43:09 -07:00
|
|
|
'--fml.modLists',
|
|
|
|
this.forgeModListFile
|
2019-11-16 14:17:55 -08:00
|
|
|
]
|
|
|
|
} else {
|
|
|
|
return []
|
|
|
|
}
|
2020-09-05 19:43:09 -07:00
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
|
2020-06-09 10:10:06 -07:00
|
|
|
_processAutoConnectArg(args){
|
2023-02-25 00:09:22 -08:00
|
|
|
if(ConfigManager.getAutoConnect() && this.server.rawServer.autoconnect){
|
2023-11-25 15:29:09 -08:00
|
|
|
if(mcVersionAtLeast('1.20', this.server.rawServer.minecraftVersion)){
|
|
|
|
args.push('--quickPlayMultiplayer')
|
|
|
|
args.push(`${this.server.hostname}:${this.server.port}`)
|
|
|
|
} else {
|
|
|
|
args.push('--server')
|
|
|
|
args.push(this.server.hostname)
|
|
|
|
args.push('--port')
|
|
|
|
args.push(this.server.port)
|
|
|
|
}
|
2020-06-09 10:10:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
/**
|
|
|
|
* Construct the argument array that will be passed to the JVM process.
|
|
|
|
*
|
|
|
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
|
|
|
* @param {string} tempNativePath The path to store the native libraries.
|
|
|
|
* @returns {Array.<string>} An array containing the full JVM arguments for this process.
|
|
|
|
*/
|
|
|
|
constructJVMArguments(mods, tempNativePath){
|
2023-02-25 00:09:22 -08:00
|
|
|
if(mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){
|
2019-11-16 14:17:55 -08:00
|
|
|
return this._constructJVMArguments113(mods, tempNativePath)
|
|
|
|
} else {
|
|
|
|
return this._constructJVMArguments112(mods, tempNativePath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the argument array that will be passed to the JVM process.
|
|
|
|
* This function is for 1.12 and below.
|
|
|
|
*
|
|
|
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
|
|
|
* @param {string} tempNativePath The path to store the native libraries.
|
|
|
|
* @returns {Array.<string>} An array containing the full JVM arguments for this process.
|
|
|
|
*/
|
|
|
|
_constructJVMArguments112(mods, tempNativePath){
|
|
|
|
|
|
|
|
let args = []
|
|
|
|
|
|
|
|
// Classpath Argument
|
|
|
|
args.push('-cp')
|
2022-11-27 15:13:50 -08:00
|
|
|
args.push(this.classpathArg(mods, tempNativePath).join(ProcessBuilder.getClasspathSeparator()))
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
// Java Arguments
|
|
|
|
if(process.platform === 'darwin'){
|
2024-02-11 01:13:31 -08:00
|
|
|
args.push('-Xdock:name=MRSLauncher')
|
2019-11-16 14:17:55 -08:00
|
|
|
args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
|
|
|
|
}
|
2023-02-25 00:09:22 -08:00
|
|
|
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.rawServer.id))
|
|
|
|
args.push('-Xms' + ConfigManager.getMinRAM(this.server.rawServer.id))
|
|
|
|
args = args.concat(ConfigManager.getJVMOptions(this.server.rawServer.id))
|
2019-11-16 14:17:55 -08:00
|
|
|
args.push('-Djava.library.path=' + tempNativePath)
|
|
|
|
|
|
|
|
// Main Java Class
|
2023-12-03 15:02:57 -08:00
|
|
|
args.push(this.modManifest.mainClass)
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
// Forge Arguments
|
|
|
|
args = args.concat(this._resolveForgeArgs())
|
|
|
|
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the argument array that will be passed to the JVM process.
|
|
|
|
* This function is for 1.13+
|
|
|
|
*
|
|
|
|
* Note: Required Libs https://github.com/MinecraftForge/MinecraftForge/blob/af98088d04186452cb364280340124dfd4766a5c/src/fmllauncher/java/net/minecraftforge/fml/loading/LibraryFinder.java#L82
|
|
|
|
*
|
|
|
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
|
|
|
* @param {string} tempNativePath The path to store the native libraries.
|
|
|
|
* @returns {Array.<string>} An array containing the full JVM arguments for this process.
|
|
|
|
*/
|
|
|
|
_constructJVMArguments113(mods, tempNativePath){
|
|
|
|
|
|
|
|
const argDiscovery = /\${*(.*)}/
|
|
|
|
|
|
|
|
// JVM Arguments First
|
2023-12-03 15:02:57 -08:00
|
|
|
let args = this.vanillaManifest.arguments.jvm
|
2019-11-16 14:17:55 -08:00
|
|
|
|
2022-11-27 15:13:50 -08:00
|
|
|
// Debug securejarhandler
|
|
|
|
// args.push('-Dbsl.debug=true')
|
|
|
|
|
2023-12-03 15:02:57 -08:00
|
|
|
if(this.modManifest.arguments.jvm != null) {
|
|
|
|
for(const argStr of this.modManifest.arguments.jvm) {
|
2022-11-27 15:13:50 -08:00
|
|
|
args.push(argStr
|
|
|
|
.replaceAll('${library_directory}', this.libPath)
|
|
|
|
.replaceAll('${classpath_separator}', ProcessBuilder.getClasspathSeparator())
|
2023-12-03 15:02:57 -08:00
|
|
|
.replaceAll('${version_name}', this.modManifest.id)
|
2022-11-27 15:13:50 -08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
//args.push('-Dlog4j.configurationFile=D:\\WesterosCraft\\game\\common\\assets\\log_configs\\client-1.12.xml')
|
|
|
|
|
|
|
|
// Java Arguments
|
|
|
|
if(process.platform === 'darwin'){
|
|
|
|
args.push('-Xdock:name=HeliosLauncher')
|
|
|
|
args.push('-Xdock:icon=' + path.join(__dirname, '..', 'images', 'minecraft.icns'))
|
|
|
|
}
|
2023-02-25 00:09:22 -08:00
|
|
|
args.push('-Xmx' + ConfigManager.getMaxRAM(this.server.rawServer.id))
|
|
|
|
args.push('-Xms' + ConfigManager.getMinRAM(this.server.rawServer.id))
|
|
|
|
args = args.concat(ConfigManager.getJVMOptions(this.server.rawServer.id))
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
// Main Java Class
|
2023-12-03 15:02:57 -08:00
|
|
|
args.push(this.modManifest.mainClass)
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
// Vanilla Arguments
|
2023-12-03 15:02:57 -08:00
|
|
|
args = args.concat(this.vanillaManifest.arguments.game)
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
for(let i=0; i<args.length; i++){
|
|
|
|
if(typeof args[i] === 'object' && args[i].rules != null){
|
|
|
|
|
|
|
|
let checksum = 0
|
|
|
|
for(let rule of args[i].rules){
|
|
|
|
if(rule.os != null){
|
2023-02-24 18:02:18 -08:00
|
|
|
if(rule.os.name === getMojangOS()
|
2019-11-16 14:17:55 -08:00
|
|
|
&& (rule.os.version == null || new RegExp(rule.os.version).test(os.release))){
|
|
|
|
if(rule.action === 'allow'){
|
|
|
|
checksum++
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(rule.action === 'disallow'){
|
|
|
|
checksum++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(rule.features != null){
|
|
|
|
// We don't have many 'features' in the index at the moment.
|
|
|
|
// This should be fine for a while.
|
|
|
|
if(rule.features.has_custom_resolution != null && rule.features.has_custom_resolution === true){
|
|
|
|
if(ConfigManager.getFullscreen()){
|
2020-06-08 11:00:07 -07:00
|
|
|
args[i].value = [
|
2019-11-16 14:17:55 -08:00
|
|
|
'--fullscreen',
|
|
|
|
'true'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
checksum++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO splice not push
|
|
|
|
if(checksum === args[i].rules.length){
|
|
|
|
if(typeof args[i].value === 'string'){
|
|
|
|
args[i] = args[i].value
|
|
|
|
} else if(typeof args[i].value === 'object'){
|
|
|
|
//args = args.concat(args[i].value)
|
|
|
|
args.splice(i, 1, ...args[i].value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decrement i to reprocess the resolved value
|
|
|
|
i--
|
|
|
|
} else {
|
|
|
|
args[i] = null
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(typeof args[i] === 'string'){
|
|
|
|
if(argDiscovery.test(args[i])){
|
|
|
|
const identifier = args[i].match(argDiscovery)[1]
|
|
|
|
let val = null
|
|
|
|
switch(identifier){
|
|
|
|
case 'auth_player_name':
|
|
|
|
val = this.authUser.displayName.trim()
|
|
|
|
break
|
|
|
|
case 'version_name':
|
2023-12-03 15:02:57 -08:00
|
|
|
//val = vanillaManifest.id
|
2023-02-25 00:09:22 -08:00
|
|
|
val = this.server.rawServer.id
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
case 'game_directory':
|
|
|
|
val = this.gameDir
|
|
|
|
break
|
|
|
|
case 'assets_root':
|
|
|
|
val = path.join(this.commonDir, 'assets')
|
|
|
|
break
|
|
|
|
case 'assets_index_name':
|
2023-12-03 15:02:57 -08:00
|
|
|
val = this.vanillaManifest.assets
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
case 'auth_uuid':
|
|
|
|
val = this.authUser.uuid.trim()
|
|
|
|
break
|
|
|
|
case 'auth_access_token':
|
|
|
|
val = this.authUser.accessToken
|
|
|
|
break
|
|
|
|
case 'user_type':
|
2022-04-03 14:08:55 -07:00
|
|
|
val = this.authUser.type === 'microsoft' ? 'msa' : 'mojang'
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
case 'version_type':
|
2023-12-03 15:02:57 -08:00
|
|
|
val = this.vanillaManifest.type
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
case 'resolution_width':
|
|
|
|
val = ConfigManager.getGameWidth()
|
|
|
|
break
|
|
|
|
case 'resolution_height':
|
|
|
|
val = ConfigManager.getGameHeight()
|
|
|
|
break
|
|
|
|
case 'natives_directory':
|
|
|
|
val = args[i].replace(argDiscovery, tempNativePath)
|
|
|
|
break
|
|
|
|
case 'launcher_name':
|
2024-02-11 01:13:31 -08:00
|
|
|
val = args[i].replace(argDiscovery, 'MRS-Launcher')
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
case 'launcher_version':
|
|
|
|
val = args[i].replace(argDiscovery, this.launcherVersion)
|
|
|
|
break
|
|
|
|
case 'classpath':
|
2022-11-27 15:13:50 -08:00
|
|
|
val = this.classpathArg(mods, tempNativePath).join(ProcessBuilder.getClasspathSeparator())
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
if(val != null){
|
|
|
|
args[i] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 10:10:06 -07:00
|
|
|
// Autoconnect
|
2023-12-03 15:02:57 -08:00
|
|
|
this._processAutoConnectArg(args)
|
2020-06-12 16:56:57 -07:00
|
|
|
|
2020-06-09 10:10:06 -07:00
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
// Forge Specific Arguments
|
2023-12-03 15:02:57 -08:00
|
|
|
args = args.concat(this.modManifest.arguments.game)
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
// Filter null values
|
|
|
|
args = args.filter(arg => {
|
|
|
|
return arg != null
|
|
|
|
})
|
|
|
|
|
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the arguments required by forge.
|
|
|
|
*
|
|
|
|
* @returns {Array.<string>} An array containing the arguments required by forge.
|
|
|
|
*/
|
|
|
|
_resolveForgeArgs(){
|
2023-12-03 15:02:57 -08:00
|
|
|
const mcArgs = this.modManifest.minecraftArguments.split(' ')
|
2019-11-16 14:17:55 -08:00
|
|
|
const argDiscovery = /\${*(.*)}/
|
|
|
|
|
|
|
|
// Replace the declared variables with their proper values.
|
|
|
|
for(let i=0; i<mcArgs.length; ++i){
|
|
|
|
if(argDiscovery.test(mcArgs[i])){
|
|
|
|
const identifier = mcArgs[i].match(argDiscovery)[1]
|
|
|
|
let val = null
|
|
|
|
switch(identifier){
|
|
|
|
case 'auth_player_name':
|
|
|
|
val = this.authUser.displayName.trim()
|
|
|
|
break
|
|
|
|
case 'version_name':
|
2023-12-03 15:02:57 -08:00
|
|
|
//val = vanillaManifest.id
|
2023-02-25 00:09:22 -08:00
|
|
|
val = this.server.rawServer.id
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
case 'game_directory':
|
|
|
|
val = this.gameDir
|
|
|
|
break
|
|
|
|
case 'assets_root':
|
|
|
|
val = path.join(this.commonDir, 'assets')
|
|
|
|
break
|
|
|
|
case 'assets_index_name':
|
2023-12-03 15:02:57 -08:00
|
|
|
val = this.vanillaManifest.assets
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
case 'auth_uuid':
|
|
|
|
val = this.authUser.uuid.trim()
|
|
|
|
break
|
|
|
|
case 'auth_access_token':
|
|
|
|
val = this.authUser.accessToken
|
|
|
|
break
|
|
|
|
case 'user_type':
|
2022-04-03 14:08:55 -07:00
|
|
|
val = this.authUser.type === 'microsoft' ? 'msa' : 'mojang'
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
case 'user_properties': // 1.8.9 and below.
|
|
|
|
val = '{}'
|
|
|
|
break
|
|
|
|
case 'version_type':
|
2023-12-03 15:02:57 -08:00
|
|
|
val = this.vanillaManifest.type
|
2019-11-16 14:17:55 -08:00
|
|
|
break
|
|
|
|
}
|
|
|
|
if(val != null){
|
|
|
|
mcArgs[i] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Autoconnect to the selected server.
|
2020-06-09 10:10:06 -07:00
|
|
|
this._processAutoConnectArg(mcArgs)
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
// Prepare game resolution
|
|
|
|
if(ConfigManager.getFullscreen()){
|
|
|
|
mcArgs.push('--fullscreen')
|
|
|
|
mcArgs.push(true)
|
|
|
|
} else {
|
|
|
|
mcArgs.push('--width')
|
|
|
|
mcArgs.push(ConfigManager.getGameWidth())
|
|
|
|
mcArgs.push('--height')
|
|
|
|
mcArgs.push(ConfigManager.getGameHeight())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mod List File Argument
|
|
|
|
mcArgs.push('--modListFile')
|
2020-06-23 12:03:17 -07:00
|
|
|
if(this._lteMinorVersion(9)) {
|
2020-01-18 09:02:00 -08:00
|
|
|
mcArgs.push(path.basename(this.fmlDir))
|
|
|
|
} else {
|
|
|
|
mcArgs.push('absolute:' + this.fmlDir)
|
|
|
|
}
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
// LiteLoader
|
|
|
|
if(this.usingLiteLoader){
|
|
|
|
mcArgs.push('--modRepo')
|
|
|
|
mcArgs.push(this.llDir)
|
|
|
|
|
|
|
|
// Set first arg to liteloader tweak class
|
|
|
|
mcArgs.unshift('com.mumfrey.liteloader.launch.LiteLoaderTweaker')
|
|
|
|
mcArgs.unshift('--tweakClass')
|
|
|
|
}
|
|
|
|
|
|
|
|
return mcArgs
|
|
|
|
}
|
|
|
|
|
2020-03-08 18:10:43 -07:00
|
|
|
/**
|
|
|
|
* Ensure that the classpath entries all point to jar files.
|
|
|
|
*
|
|
|
|
* @param {Array.<String>} list Array of classpath entries.
|
|
|
|
*/
|
|
|
|
_processClassPathList(list) {
|
|
|
|
|
|
|
|
const ext = '.jar'
|
|
|
|
const extLen = ext.length
|
|
|
|
for(let i=0; i<list.length; i++) {
|
|
|
|
const extIndex = list[i].indexOf(ext)
|
|
|
|
if(extIndex > -1 && extIndex !== list[i].length - extLen) {
|
|
|
|
list[i] = list[i].substring(0, extIndex + extLen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
/**
|
|
|
|
* Resolve the full classpath argument list for this process. This method will resolve all Mojang-declared
|
|
|
|
* libraries as well as the libraries declared by the server. Since mods are permitted to declare libraries,
|
|
|
|
* this method requires all enabled mods as an input
|
|
|
|
*
|
|
|
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
|
|
|
* @param {string} tempNativePath The path to store the native libraries.
|
|
|
|
* @returns {Array.<string>} An array containing the paths of each library required by this process.
|
|
|
|
*/
|
|
|
|
classpathArg(mods, tempNativePath){
|
|
|
|
let cpArgs = []
|
|
|
|
|
2023-12-03 15:02:57 -08:00
|
|
|
if(!mcVersionAtLeast('1.17', this.server.rawServer.minecraftVersion) || this.usingFabricLoader) {
|
2022-11-27 15:13:50 -08:00
|
|
|
// Add the version.jar to the classpath.
|
|
|
|
// Must not be added to the classpath for Forge 1.17+.
|
2023-12-03 15:02:57 -08:00
|
|
|
const version = this.vanillaManifest.id
|
2022-11-27 15:13:50 -08:00
|
|
|
cpArgs.push(path.join(this.commonDir, 'versions', version, version + '.jar'))
|
|
|
|
}
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
|
|
|
|
if(this.usingLiteLoader){
|
|
|
|
cpArgs.push(this.llPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resolve the Mojang declared libraries.
|
|
|
|
const mojangLibs = this._resolveMojangLibraries(tempNativePath)
|
|
|
|
|
|
|
|
// Resolve the server declared libraries.
|
|
|
|
const servLibs = this._resolveServerLibraries(mods)
|
2020-01-18 09:02:00 -08:00
|
|
|
|
|
|
|
// Merge libraries, server libs with the same
|
|
|
|
// maven identifier will override the mojang ones.
|
|
|
|
// Ex. 1.7.10 forge overrides mojang's guava with newer version.
|
|
|
|
const finalLibs = {...mojangLibs, ...servLibs}
|
|
|
|
cpArgs = cpArgs.concat(Object.values(finalLibs))
|
2019-11-16 14:17:55 -08:00
|
|
|
|
2020-03-08 18:10:43 -07:00
|
|
|
this._processClassPathList(cpArgs)
|
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
return cpArgs
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the libraries defined by Mojang's version data. This method will also extract
|
|
|
|
* native libraries and point to the correct location for its classpath.
|
|
|
|
*
|
|
|
|
* TODO - clean up function
|
|
|
|
*
|
|
|
|
* @param {string} tempNativePath The path to store the native libraries.
|
2020-01-18 09:02:00 -08:00
|
|
|
* @returns {{[id: string]: string}} An object containing the paths of each library mojang declares.
|
2019-11-16 14:17:55 -08:00
|
|
|
*/
|
|
|
|
_resolveMojangLibraries(tempNativePath){
|
2022-11-27 15:13:50 -08:00
|
|
|
const nativesRegex = /.+:natives-([^-]+)(?:-(.+))?/
|
2020-01-18 09:02:00 -08:00
|
|
|
const libs = {}
|
2019-11-16 14:17:55 -08:00
|
|
|
|
2023-12-03 15:02:57 -08:00
|
|
|
const libArr = this.vanillaManifest.libraries
|
2019-11-16 14:17:55 -08:00
|
|
|
fs.ensureDirSync(tempNativePath)
|
|
|
|
for(let i=0; i<libArr.length; i++){
|
|
|
|
const lib = libArr[i]
|
2023-02-24 18:02:18 -08:00
|
|
|
if(isLibraryCompatible(lib.rules, lib.natives)){
|
2022-11-27 15:13:50 -08:00
|
|
|
|
|
|
|
// Pre-1.19 has a natives object.
|
|
|
|
if(lib.natives != null) {
|
2019-11-16 14:17:55 -08:00
|
|
|
// Extract the native library.
|
|
|
|
const exclusionArr = lib.extract != null ? lib.extract.exclude : ['META-INF/']
|
2023-02-24 18:02:18 -08:00
|
|
|
const artifact = lib.downloads.classifiers[lib.natives[getMojangOS()].replace('${arch}', process.arch.replace('x', ''))]
|
2022-11-27 15:13:50 -08:00
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
// Location of native zip.
|
|
|
|
const to = path.join(this.libPath, artifact.path)
|
2022-11-27 15:13:50 -08:00
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
let zip = new AdmZip(to)
|
|
|
|
let zipEntries = zip.getEntries()
|
2022-11-27 15:13:50 -08:00
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
// Unzip the native zip.
|
|
|
|
for(let i=0; i<zipEntries.length; i++){
|
|
|
|
const fileName = zipEntries[i].entryName
|
2022-11-27 15:13:50 -08:00
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
let shouldExclude = false
|
|
|
|
|
|
|
|
// Exclude noted files.
|
|
|
|
exclusionArr.forEach(function(exclusion){
|
|
|
|
if(fileName.indexOf(exclusion) > -1){
|
|
|
|
shouldExclude = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// Extract the file.
|
|
|
|
if(!shouldExclude){
|
|
|
|
fs.writeFile(path.join(tempNativePath, fileName), zipEntries[i].getData(), (err) => {
|
|
|
|
if(err){
|
|
|
|
logger.error('Error while extracting native library:', err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-11-27 15:13:50 -08:00
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
}
|
2022-11-27 15:13:50 -08:00
|
|
|
// 1.19+ logic
|
|
|
|
else if(lib.name.includes('natives-')) {
|
|
|
|
|
|
|
|
const regexTest = nativesRegex.exec(lib.name)
|
|
|
|
// const os = regexTest[1]
|
|
|
|
const arch = regexTest[2] ?? 'x64'
|
|
|
|
|
|
|
|
if(arch != process.arch) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the native library.
|
|
|
|
const exclusionArr = lib.extract != null ? lib.extract.exclude : ['META-INF/', '.git', '.sha1']
|
|
|
|
const artifact = lib.downloads.artifact
|
|
|
|
|
|
|
|
// Location of native zip.
|
|
|
|
const to = path.join(this.libPath, artifact.path)
|
|
|
|
|
|
|
|
let zip = new AdmZip(to)
|
|
|
|
let zipEntries = zip.getEntries()
|
|
|
|
|
|
|
|
// Unzip the native zip.
|
|
|
|
for(let i=0; i<zipEntries.length; i++){
|
|
|
|
if(zipEntries[i].isDirectory) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
const fileName = zipEntries[i].entryName
|
|
|
|
|
|
|
|
let shouldExclude = false
|
|
|
|
|
|
|
|
// Exclude noted files.
|
|
|
|
exclusionArr.forEach(function(exclusion){
|
|
|
|
if(fileName.indexOf(exclusion) > -1){
|
|
|
|
shouldExclude = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const extractName = fileName.includes('/') ? fileName.substring(fileName.lastIndexOf('/')) : fileName
|
|
|
|
|
|
|
|
// Extract the file.
|
|
|
|
if(!shouldExclude){
|
|
|
|
fs.writeFile(path.join(tempNativePath, extractName), zipEntries[i].getData(), (err) => {
|
|
|
|
if(err){
|
|
|
|
logger.error('Error while extracting native library:', err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// No natives
|
|
|
|
else {
|
|
|
|
const dlInfo = lib.downloads
|
|
|
|
const artifact = dlInfo.artifact
|
|
|
|
const to = path.join(this.libPath, artifact.path)
|
|
|
|
const versionIndependentId = lib.name.substring(0, lib.name.lastIndexOf(':'))
|
|
|
|
libs[versionIndependentId] = to
|
|
|
|
}
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return libs
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve the libraries declared by this server in order to add them to the classpath.
|
|
|
|
* This method will also check each enabled mod for libraries, as mods are permitted to
|
|
|
|
* declare libraries.
|
|
|
|
*
|
|
|
|
* @param {Array.<Object>} mods An array of enabled mods which will be launched with this process.
|
2020-01-18 09:02:00 -08:00
|
|
|
* @returns {{[id: string]: string}} An object containing the paths of each library this server requires.
|
2019-11-16 14:17:55 -08:00
|
|
|
*/
|
|
|
|
_resolveServerLibraries(mods){
|
2023-02-25 00:09:22 -08:00
|
|
|
const mdls = this.server.modules
|
2020-01-18 09:02:00 -08:00
|
|
|
let libs = {}
|
2019-11-16 14:17:55 -08:00
|
|
|
|
2023-12-03 15:02:57 -08:00
|
|
|
// Locate Forge/Fabric/Libraries
|
2019-11-16 14:17:55 -08:00
|
|
|
for(let mdl of mdls){
|
2023-02-25 00:09:22 -08:00
|
|
|
const type = mdl.rawModule.type
|
2023-12-03 15:02:57 -08:00
|
|
|
if(type === Type.ForgeHosted || type === Type.Fabric || type === Type.Library){
|
2023-02-25 00:09:22 -08:00
|
|
|
libs[mdl.getVersionlessMavenIdentifier()] = mdl.getPath()
|
|
|
|
if(mdl.subModules.length > 0){
|
2019-11-16 14:17:55 -08:00
|
|
|
const res = this._resolveModuleLibraries(mdl)
|
|
|
|
if(res.length > 0){
|
2020-01-18 09:02:00 -08:00
|
|
|
libs = {...libs, ...res}
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check for any libraries in our mod list.
|
|
|
|
for(let i=0; i<mods.length; i++){
|
|
|
|
if(mods.sub_modules != null){
|
|
|
|
const res = this._resolveModuleLibraries(mods[i])
|
|
|
|
if(res.length > 0){
|
2020-01-18 09:02:00 -08:00
|
|
|
libs = {...libs, ...res}
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return libs
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recursively resolve the path of each library required by this module.
|
|
|
|
*
|
|
|
|
* @param {Object} mdl A module object from the server distro index.
|
|
|
|
* @returns {Array.<string>} An array containing the paths of each library this module requires.
|
|
|
|
*/
|
|
|
|
_resolveModuleLibraries(mdl){
|
2023-02-25 00:09:22 -08:00
|
|
|
if(!mdl.subModules.length > 0){
|
2019-11-16 14:17:55 -08:00
|
|
|
return []
|
|
|
|
}
|
|
|
|
let libs = []
|
2023-02-25 00:09:22 -08:00
|
|
|
for(let sm of mdl.subModules){
|
|
|
|
if(sm.rawModule.type === Type.Library){
|
2022-11-27 15:13:50 -08:00
|
|
|
|
2023-02-25 00:09:22 -08:00
|
|
|
if(sm.rawModule.classpath ?? true) {
|
|
|
|
libs.push(sm.getPath())
|
2022-11-27 15:13:50 -08:00
|
|
|
}
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
// If this module has submodules, we need to resolve the libraries for those.
|
|
|
|
// To avoid unnecessary recursive calls, base case is checked here.
|
2023-02-25 00:09:22 -08:00
|
|
|
if(mdl.subModules.length > 0){
|
2019-11-16 14:17:55 -08:00
|
|
|
const res = this._resolveModuleLibraries(sm)
|
|
|
|
if(res.length > 0){
|
|
|
|
libs = libs.concat(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return libs
|
|
|
|
}
|
2020-03-08 18:10:43 -07:00
|
|
|
|
2019-11-16 14:17:55 -08:00
|
|
|
}
|
|
|
|
|
2017-11-19 00:48:21 -08:00
|
|
|
module.exports = ProcessBuilder
|