From dd7ae6bf56bc9b838934d60c1b8439c1ff8f70f9 Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Sun, 19 Nov 2017 03:48:21 -0500 Subject: [PATCH] Massive progress on implementing the new forge modlist format. I have been able to rewrite much of the launch process code to use this new method, and was able to successfully log into the game. Several bugs need to be worked on, however everything is in a good state so far. --- app/assets/js/assetguard.js | 9 +- app/assets/js/launchprocess.js | 5 + app/assets/js/processbuider.js | 104 ---------- app/assets/js/processbuilder.js | 327 ++++++++++++++++++++++++++++++++ app/assets/js/script.js | 17 +- app/assets/westeroscraft.json | 38 ++++ 6 files changed, 391 insertions(+), 109 deletions(-) delete mode 100644 app/assets/js/processbuider.js create mode 100644 app/assets/js/processbuilder.js diff --git a/app/assets/js/assetguard.js b/app/assets/js/assetguard.js index fbcbe12b..1d9e88be 100644 --- a/app/assets/js/assetguard.js +++ b/app/assets/js/assetguard.js @@ -705,6 +705,13 @@ function validateLogConfig(versionData, basePath){ }) } +/** + * Validate the distribution. + * + * @param {String} serverpackid - The id of the server to validate. + * @param {String} basePath - the absolute file path which will be prepended to the given relative paths. + * @returns {Promise.} - A promise which resolves to the server distribution object. + */ function validateDistribution(serverpackid, basePath){ return new Promise(function(fulfill, reject){ _chainValidateDistributionIndex(basePath).then((value) => { @@ -729,7 +736,7 @@ function validateDistribution(serverpackid, basePath){ } } instance.totaldlsize += instance.forge.dlsize*1 - fulfill() + fulfill(serv) }) }) } diff --git a/app/assets/js/launchprocess.js b/app/assets/js/launchprocess.js index 468695d0..11bc0497 100644 --- a/app/assets/js/launchprocess.js +++ b/app/assets/js/launchprocess.js @@ -1,3 +1,8 @@ +/** + * File is officially deprecated in favor of processbuilder.js, + * will be removed once the new module is 100% complete and this + * is no longer needed for reference. + */ const mojang = require('mojang') const uuidV4 = require('uuid/v4') const path = require('path') diff --git a/app/assets/js/processbuider.js b/app/assets/js/processbuider.js deleted file mode 100644 index 88fb70cb..00000000 --- a/app/assets/js/processbuider.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Work in progress - */ - -const path = require('path') -const fs = require('fs') - -class ProcessBuilder { - - constructor(gameDirectory, distroServer, versionData, forgeData, authUser){ - this.dir = gameDirectory - this.server = server - this.versionData = versionData - this.forgeData = forgeData - this.authUser = authUser - this.fmlDir = path.join(this.dir, 'versions', this.server.id) - } - - static shouldInclude(mdle){ - //If the module should be included by default - return mdle.required == null || mdle.required.value == null || mdle.required.value === true || (mdle.required.value === false && mdle.required.def === true) - } - - resolveDefaultMods(options = {type: 'forgemod'}){ - //Returns array of default forge mods to load. - const mods = [] - const mdles = this.server.modules - - for(let i=0; i { + console.log('Minecraft:', data.toString('utf8')) + }) + child.stderr.on('data', (data) => { + console.log('Minecraft:', data.toString('utf8')) + }) + child.on('close', (code, signal) => { + console.log('Exited with code', code) + }) + + return child + } + + resolveDefaultMods(options = {type: 'forgemod'}){ + //Returns array of default forge mods to load. + const mods = [] + const mdles = this.server.modules + + for(let i=0; i} mods - An array of enabled mods which will be launched with this process. + * @returns {Array.} - An array containing the full JVM arguments for this process. + */ + constructJVMArguments(mods){ + + let args = ['-Xmx4G', + '-XX:+UseConcMarkSweepGC', + '-XX:+CMSIncrementalMode', + '-XX:-UseAdaptiveSizePolicy', + '-Xmn128M', + '-Djava.library.path=' + path.join(this.dir, 'natives'), + '-cp', + this.classpathArg(mods).join(';'), + this.forgeData.mainClass] + + args = args.concat(this._resolveForgeArgs()) + + return args + } + + /** + * Resolve the arguments required by forge. + * + * @returns {Array.} - An array containing the arguments required by forge. + */ + _resolveForgeArgs(){ + const mcArgs = this.forgeData.minecraftArguments.split(' ') + const argDiscovery = /\${*(.*)}/ + + // Replace the declared variables with their proper values. + for(let i=0; i} mods - An array of enabled mods which will be launched with this process. + * @returns {Array.} - An array containing the paths of each library required by this process. + */ + classpathArg(mods){ + let cpArgs = [] + + // Add the version.jar to the classpath. + const version = this.versionData.id + cpArgs.push(path.join(this.dir, 'versions', version, version + '.jar')) + + // Resolve the Mojang declared libraries. + const mojangLibs = this._resolveMojangLibraries() + cpArgs = cpArgs.concat(mojangLibs) + + // Resolve the server declared libraries. + const servLibs = this._resolveServerLibraries(mods) + cpArgs = cpArgs.concat(servLibs) + + 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 + * + * @returns {Array.} - An array containing the paths of each library mojang declares. + */ + _resolveMojangLibraries(){ + const libs = [] + + const libArr = this.versionData.libraries + const nativePath = path.join(this.dir, 'natives') + for(let i=0; i -1){ + shouldExclude = true + } + }) + + // Extract the file. + if(!shouldExclude){ + mkpath.sync(path.join(nativePath, fileName, '..')) + fs.writeFile(path.join(nativePath, fileName), zipEntries[i].getData()) + } + + } + + libs.push(to) + } + } + } + + 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.} mods - An array of enabled mods which will be launched with this process. + * @returns {Array.} - An array containing the paths of each library this server requires. + */ + _resolveServerLibraries(mods){ + const mdles = this.server.modules + let libs = [] + + // Locate Forge Libraries + for(let i=0; i 0){ + libs = libs.concat(res) + } + break + } + } + + //Check for any libraries in our mod list. + for(let i=0; i 0){ + libs = libs.concat(res) + } + } + } + + return libs + } + + /** + * Recursively resolve the path of each library required by this module. + * + * @param {Object} mdle - A module object from the server distro index. + * @returns {Array.} - An array containing the paths of each library this module requires. + */ + _resolveModuleLibraries(mdle){ + if(mdle.sub_modules == null){ + return [] + } + let libs = [] + for(let i=0; i 0){ + libs = libs.concat(res) + } + } + } + return libs + } +} + +module.exports = ProcessBuilder \ No newline at end of file diff --git a/app/assets/js/script.js b/app/assets/js/script.js index 421cc0a4..b9e5781e 100644 --- a/app/assets/js/script.js +++ b/app/assets/js/script.js @@ -4,6 +4,9 @@ const shell = require('electron').shell const path = require('path') const os = require('os'); const ag = require(path.join(__dirname, 'assets', 'js', 'assetguard.js')) +const ProcessBuilder = require(path.join(__dirname, 'assets', 'js', 'processbuilder.js')) +const mojang = require('mojang') +const uuidV4 = require('uuid/v4') $(document).on('ready', function(){ console.log('okay'); @@ -48,7 +51,7 @@ $(document).on('click', 'a[href^="http"]', function(event) { }) testdownloads = async function(){ - const lp = require(path.join(__dirname, 'assets', 'js', 'launchprocess.js')) + //const lp = require(path.join(__dirname, 'assets', 'js', 'launchprocess.js')) const basePath = path.join(__dirname, '..', 'target', 'test', 'mcfiles') let versionData = await ag.loadVersionData('1.11.2', basePath) await ag.validateAssets(versionData, basePath) @@ -57,12 +60,18 @@ testdownloads = async function(){ console.log('libs done') await ag.validateMiscellaneous(versionData, basePath) console.log('files done') - await ag.validateDistribution('WesterosCraft-1.11.2', basePath) + const serv = await ag.validateDistribution('WesterosCraft-1.11.2', basePath) console.log('forge stuff done') ag.instance.on('dlcomplete', async function(){ - let forgeData = await ag.loadForgeData('WesterosCraft-1.11.2', basePath) - lp.launchMinecraft(versionData, forgeData, basePath) + const forgeData = await ag.loadForgeData('WesterosCraft-1.11.2', basePath) + const authUser = await mojang.auth('EMAIL', 'PASS', uuidV4(), { + name: 'Minecraft', + version: 1 + }) + //lp.launchMinecraft(versionData, forgeData, basePath) //lp.launchMinecraft(versionData, basePath) + let pb = new ProcessBuilder(basePath, serv, versionData, forgeData, authUser) + const proc = pb.build() }) ag.processDlQueues() } diff --git a/app/assets/westeroscraft.json b/app/assets/westeroscraft.json index 4ed44545..752e9a14 100644 --- a/app/assets/westeroscraft.json +++ b/app/assets/westeroscraft.json @@ -313,6 +313,44 @@ } ] }, + { + "id": "org.blockartistry:dynsurround:1.11.2-3.4.6.2", + "name": "DynamicSurroundings (1.11.2-3.4.6.2)", + "type": "forgemod", + "required": { + "value": false + }, + "artifact": { + "size": 21853035, + "MD5": "82a6aac5420151960b8dd709deee5423", + "extension": ".jar", + "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/prod-1.11.2/mods/DynamicSurroundings.jar" + }, + "sub_modules": [ + { + "id": "dsurround.cfg", + "name": "DynamicSurroundings General Configuration File", + "type": "file", + "artifact": { + "size": 19736, + "MD5": "4c64fc6cbbb83b18012ed4820b0b496e", + "path": "/config/dsurround/dsurround.cfg", + "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/prod-1.11.2/config/dsurround/dsurround.cfg" + } + }, + { + "id": "westeros.json", + "name": "DynamicSurroundings WesterosCraft Configuration File", + "type": "file", + "artifact": { + "size": 608, + "MD5": "44eab112ff24d0bd29974c270de868ba", + "path": "/config/dsurround/westeros.json", + "url": "http://mc.westeroscraft.com/WesterosCraftLauncher/prod-1.11.2/config/dsurround/westeros.json" + } + } + ] + }, { "id": "com.westeroscraft:westerosblocks:3.0.0-beta-6-133", "name": "WesterosBlocks (3.0.0-beta-6-133)",