From 555a5ea0995c50e6c7c03d09e5e14ce6a21ca3f8 Mon Sep 17 00:00:00 2001 From: claude-bot Date: Wed, 6 May 2026 05:11:36 +0900 Subject: [PATCH] Support vanilla profile launches --- app/assets/js/processbuilder.js | 119 +++++++++++++++++-------------- app/assets/js/scripts/landing.js | 15 +++- app/assets/js/vanillapatch.js | 23 ++++++ 3 files changed, 103 insertions(+), 54 deletions(-) create mode 100644 app/assets/js/vanillapatch.js diff --git a/app/assets/js/processbuilder.js b/app/assets/js/processbuilder.js index cc94b9c..4377d9a 100644 --- a/app/assets/js/processbuilder.js +++ b/app/assets/js/processbuilder.js @@ -63,14 +63,23 @@ function resolveServerAddressOverride(address, fallbackPort) { */ class ProcessBuilder { - constructor(distroServer, vanillaManifest, modManifest, authUser, launcherVersion){ - this.gameDir = path.join(ConfigManager.getInstanceDirectory(), distroServer.rawServer.id) - this.commonDir = ConfigManager.getCommonDirectory() - this.server = distroServer - this.vanillaManifest = vanillaManifest - this.modManifest = modManifest - this.authUser = authUser - this.launcherVersion = launcherVersion + constructor(distroServer, vanillaManifest, modManifest, authUser, launcherVersion){ + this.gameDir = path.join(ConfigManager.getInstanceDirectory(), distroServer.rawServer.id) + this.commonDir = ConfigManager.getCommonDirectory() + this.server = distroServer + this.vanillaManifest = vanillaManifest + this.usingModLoader = modManifest != null + this.modManifest = modManifest ?? { + id: vanillaManifest.id, + mainClass: vanillaManifest.mainClass, + arguments: { + jvm: [], + game: [] + }, + minecraftArguments: vanillaManifest.minecraftArguments ?? '' + } + this.authUser = authUser + this.launcherVersion = launcherVersion this.forgeModListFile = path.join(this.gameDir, 'forgeMods.list') // 1.13+ this.fmlDir = path.join(this.gameDir, 'forgeModList.json') this.llDir = path.join(this.gameDir, 'liteloaderModList.json') @@ -90,26 +99,26 @@ class ProcessBuilder { process.throwDeprecation = true this.setupLiteLoader() logger.info('Using liteloader:', this.usingLiteLoader) - this.usingFabricLoader = this.server.modules.some(mdl => mdl.rawModule.type === Type.Fabric) - logger.info('Using fabric loader:', this.usingFabricLoader) - const modObj = this.resolveModConfiguration(ConfigManager.getModConfiguration(this.server.rawServer.id).mods, this.server.modules) - - // Mod list below 1.13 - // Fabric only supports 1.14+ - if(!mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){ - this.constructJSONModList('forge', modObj.fMods, true) - if(this.usingLiteLoader){ - this.constructJSONModList('liteloader', modObj.lMods, true) - } - } + this.usingFabricLoader = this.usingModLoader && this.server.modules.some(mdl => mdl.rawModule.type === Type.Fabric) + logger.info('Using fabric loader:', this.usingFabricLoader) + const modObj = this.resolveModConfiguration(ConfigManager.getModConfiguration(this.server.rawServer.id).mods, this.server.modules) + + // Mod list below 1.13 + // Fabric only supports 1.14+ + if(this.usingModLoader && !mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){ + this.constructJSONModList('forge', modObj.fMods, true) + if(this.usingLiteLoader){ + this.constructJSONModList('liteloader', modObj.lMods, true) + } + } const uberModArr = modObj.fMods.concat(modObj.lMods) let args = this.constructJVMArguments(uberModArr, tempNativePath) - if(mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){ - //args = args.concat(this.constructModArguments(modObj.fMods)) - args = args.concat(this.constructModList(modObj.fMods)) - } + if(this.usingModLoader && mcVersionAtLeast('1.13', this.server.rawServer.minecraftVersion)){ + //args = args.concat(this.constructModArguments(modObj.fMods)) + args = args.concat(this.constructModList(modObj.fMods)) + } // Hide access token const loggableArgs = [...args] @@ -456,7 +465,7 @@ class ProcessBuilder { args.push('-Djava.library.path=' + tempNativePath) // Main Java Class - args.push(this.modManifest.mainClass) + args.push(this.modManifest.mainClass) // Forge Arguments args = args.concat(this._resolveForgeArgs()) @@ -484,10 +493,10 @@ class ProcessBuilder { // Debug securejarhandler // args.push('-Dbsl.debug=true') - if(this.modManifest.arguments.jvm != null) { - for(const argStr of this.modManifest.arguments.jvm) { - args.push(argStr - .replaceAll('${library_directory}', this.libPath) + if(this.usingModLoader && this.modManifest.arguments.jvm != null) { + for(const argStr of this.modManifest.arguments.jvm) { + args.push(argStr + .replaceAll('${library_directory}', this.libPath) .replaceAll('${classpath_separator}', ProcessBuilder.getClasspathSeparator()) .replaceAll('${version_name}', this.modManifest.id) ) @@ -621,7 +630,9 @@ class ProcessBuilder { // Forge Specific Arguments - args = args.concat(this.modManifest.arguments.game) + if(this.usingModLoader){ + args = args.concat(this.modManifest.arguments.game) + } // Filter null values args = args.filter(arg => { @@ -637,7 +648,10 @@ class ProcessBuilder { * @returns {Array.} An array containing the arguments required by forge. */ _resolveForgeArgs(){ - const mcArgs = this.modManifest.minecraftArguments.split(' ') + const baseMinecraftArguments = this.usingModLoader + ? this.modManifest.minecraftArguments + : (this.vanillaManifest.minecraftArguments ?? '') + const mcArgs = baseMinecraftArguments.split(' ') const argDiscovery = /\${*(.*)}/ // Replace the declared variables with their proper values. @@ -699,23 +713,24 @@ class ProcessBuilder { } // Mod List File Argument - mcArgs.push('--modListFile') - if(this._lteMinorVersion(9)) { - mcArgs.push(path.basename(this.fmlDir)) - } else { - mcArgs.push('absolute:' + this.fmlDir) - } - - - // 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') - } + if(this.usingModLoader){ + mcArgs.push('--modListFile') + if(this._lteMinorVersion(9)) { + mcArgs.push(path.basename(this.fmlDir)) + } else { + mcArgs.push('absolute:' + this.fmlDir) + } + + // 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 } @@ -750,10 +765,10 @@ class ProcessBuilder { classpathArg(mods, tempNativePath){ let cpArgs = [] - if(!mcVersionAtLeast('1.17', this.server.rawServer.minecraftVersion) || this.usingFabricLoader) { - // Add the version.jar to the classpath. - // Must not be added to the classpath for Forge 1.17+. - const version = this.vanillaManifest.id + if(!mcVersionAtLeast('1.17', this.server.rawServer.minecraftVersion) || this.usingFabricLoader || !this.usingModLoader) { + // Add the version.jar to the classpath. + // Must not be added to the classpath for Forge 1.17+. + const version = this.vanillaManifest.id cpArgs.push(path.join(this.commonDir, 'versions', version, version + '.jar')) } diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index 74db9dd..e0ba0f2 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -3,6 +3,9 @@ */ (() => { // Requirements +require('./assets/js/vanillapatch') + +const path = require('path') const { URL } = require('url') const { MojangRestAPI @@ -689,7 +692,15 @@ async function dlAsync(login = true) { DistroAPI.isDevMode() ) - fullRepairModule.spawnReceiver() + const receiverPatchPath = path.join(__dirname, '..', 'vanillapatch.js') + const existingNodeOptions = process.env.NODE_OPTIONS?.trim() + const receiverNodeOptions = `--require=\"${receiverPatchPath}\"` + + fullRepairModule.spawnReceiver({ + NODE_OPTIONS: existingNodeOptions != null && existingNodeOptions.length > 0 + ? `${existingNodeOptions} ${receiverNodeOptions}` + : receiverNodeOptions + }) fullRepairModule.childProcess.on('error', (err) => { loggerLaunchSuite.error('Error during launch', err) @@ -751,7 +762,7 @@ async function dlAsync(login = true) { serv.rawServer.id ) - const modLoaderData = await distributionIndexProcessor.loadModLoaderVersionJson(serv) + const modLoaderData = await distributionIndexProcessor.loadModLoaderVersionJson() const versionData = await mojangIndexProcessor.getVersionJson() if(login) { diff --git a/app/assets/js/vanillapatch.js b/app/assets/js/vanillapatch.js new file mode 100644 index 0000000..ed335b0 --- /dev/null +++ b/app/assets/js/vanillapatch.js @@ -0,0 +1,23 @@ +const { DistributionIndexProcessor } = require('helios-core/dl') +const { Type } = require('helios-distribution-types') + +if(!DistributionIndexProcessor.prototype.__mrsVanillaPatchApplied){ + const originalLoadModLoaderVersionJson = DistributionIndexProcessor.prototype.loadModLoaderVersionJson + + DistributionIndexProcessor.prototype.loadModLoaderVersionJson = async function(...args){ + const server = this.distribution?.getServerById?.(this.serverId) + const hasModLoader = server?.modules?.some(({ rawModule }) => { + return rawModule?.type === Type.ForgeHosted + || rawModule?.type === Type.Forge + || rawModule?.type === Type.Fabric + }) === true + + if(!hasModLoader){ + return null + } + + return originalLoadModLoaderVersionJson.apply(this, args) + } + + DistributionIndexProcessor.prototype.__mrsVanillaPatchApplied = true +}