2017-04-28 07:59:28 +00:00
|
|
|
const mojang = require('mojang')
|
|
|
|
const uuidV4 = require('uuid/v4')
|
|
|
|
const path = require('path')
|
|
|
|
const child_process = require('child_process')
|
2017-05-14 08:37:38 +00:00
|
|
|
const ag = require('./assetguard.js')
|
2017-04-30 00:33:32 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
const mkpath = require('mkdirp');
|
2017-04-28 07:59:28 +00:00
|
|
|
|
2017-05-16 06:12:28 +00:00
|
|
|
/* TODO - convert native extraction to use adm-zip. Currently not functional due to removal of unzip module (it was bad) */
|
2017-05-14 08:37:38 +00:00
|
|
|
launchMinecraft = function(versionData, basePath){
|
2017-05-09 04:56:08 +00:00
|
|
|
const authPromise = mojang.auth('EMAIL', 'PASS', uuidV4(), {
|
2017-04-28 07:59:28 +00:00
|
|
|
name: 'Minecraft',
|
|
|
|
version: 1
|
|
|
|
})
|
|
|
|
authPromise.then(function(data){
|
|
|
|
const args = finalizeArguments(versionData, data, basePath)
|
2017-04-30 00:33:32 +00:00
|
|
|
//TODO make this dynamic
|
|
|
|
const child = child_process.spawn('C:\\Program Files\\Java\\jre1.8.0_131\\bin\\javaw.exe', args)
|
2017-04-28 07:59:28 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
finalizeArguments = function(versionData, authData, basePath){
|
|
|
|
const mcArgs = versionData['minecraftArguments']
|
2017-04-30 22:28:43 +00:00
|
|
|
const gameProfile = authData['selectedProfile']
|
2017-04-28 07:59:28 +00:00
|
|
|
const regex = new RegExp('\\${*(.*)}')
|
|
|
|
const argArr = mcArgs.split(' ')
|
2017-04-30 00:33:32 +00:00
|
|
|
argArr.unshift('net.minecraft.client.main.Main')
|
|
|
|
argArr.unshift(classpathArg(versionData, basePath))
|
|
|
|
argArr.unshift('-cp')
|
|
|
|
argArr.unshift('-Djava.library.path=' + path.join(basePath, 'natives'))
|
|
|
|
argArr.unshift('-Xmn128M')
|
|
|
|
argArr.unshift('-XX:-UseAdaptiveSizePolicy')
|
|
|
|
argArr.unshift('-XX:+CMSIncrementalMode')
|
|
|
|
argArr.unshift('-XX:+UseConcMarkSweepGC')
|
|
|
|
argArr.unshift('-Xmx1G')
|
2017-04-28 07:59:28 +00:00
|
|
|
for(let i=0; i<argArr.length; i++){
|
|
|
|
if(regex.test(argArr[i])){
|
|
|
|
const identifier = argArr[i].match(regex)[1]
|
|
|
|
let newVal = argArr[i]
|
|
|
|
switch(identifier){
|
|
|
|
case 'auth_player_name':
|
2017-04-30 22:28:43 +00:00
|
|
|
newVal = gameProfile['name']
|
2017-04-28 07:59:28 +00:00
|
|
|
break
|
|
|
|
case 'version_name':
|
|
|
|
newVal = versionData['id']
|
|
|
|
break
|
|
|
|
case 'game_directory':
|
|
|
|
newVal = basePath
|
|
|
|
break
|
|
|
|
case 'assets_root':
|
|
|
|
newVal = path.join(basePath, 'assets')
|
|
|
|
break
|
|
|
|
case 'assets_index_name':
|
|
|
|
newVal = versionData['assets']
|
|
|
|
break
|
|
|
|
case 'auth_uuid':
|
2017-04-30 22:28:43 +00:00
|
|
|
newVal = gameProfile['id']
|
2017-04-28 07:59:28 +00:00
|
|
|
break
|
|
|
|
case 'auth_access_token':
|
|
|
|
newVal = authData['accessToken']
|
|
|
|
break
|
|
|
|
case 'user_type':
|
|
|
|
newVal = 'MOJANG'
|
|
|
|
break
|
|
|
|
case 'version_type':
|
|
|
|
newVal = versionData['type']
|
|
|
|
break
|
|
|
|
}
|
|
|
|
argArr[i] = newVal
|
|
|
|
}
|
|
|
|
}
|
2017-04-30 00:33:32 +00:00
|
|
|
|
|
|
|
return argArr
|
|
|
|
}
|
|
|
|
|
|
|
|
classpathArg = function(versionData, basePath){
|
|
|
|
const libArr = versionData['libraries']
|
|
|
|
const libPath = path.join(basePath, 'libraries')
|
|
|
|
const nativePath = path.join(basePath, 'natives')
|
2017-04-30 22:28:43 +00:00
|
|
|
const version = versionData['id']
|
|
|
|
const cpArgs = [path.join(basePath, 'versions', version, version + '.jar')]
|
2017-04-30 00:33:32 +00:00
|
|
|
libArr.forEach(function(lib){
|
2017-05-14 08:37:38 +00:00
|
|
|
if(ag.Library.validateRules(lib['rules'])){
|
2017-04-30 00:33:32 +00:00
|
|
|
if(lib['natives'] == null){
|
|
|
|
const dlInfo = lib['downloads']
|
|
|
|
const artifact = dlInfo['artifact']
|
|
|
|
const to = path.join(libPath, artifact['path'])
|
|
|
|
cpArgs.push(to)
|
|
|
|
} else {
|
|
|
|
//Now we need to extract natives.
|
|
|
|
const natives = lib['natives']
|
|
|
|
const extractInst = lib['extract']
|
|
|
|
const exclusionArr = extractInst['exclude']
|
2017-05-14 08:37:38 +00:00
|
|
|
const opSys = ag.Library.mojangFriendlyOS()
|
2017-04-30 00:33:32 +00:00
|
|
|
const indexId = natives[opSys]
|
|
|
|
const dlInfo = lib['downloads']
|
|
|
|
const classifiers = dlInfo['classifiers']
|
|
|
|
const artifact = classifiers[indexId]
|
|
|
|
|
|
|
|
const to = path.join(libPath, artifact['path'])
|
|
|
|
|
|
|
|
fs.createReadStream(to).pipe(unzip.Parse()).on('entry', function(entry){
|
|
|
|
const fileName = entry.path
|
|
|
|
const type = entry.type
|
|
|
|
const size = entry.size
|
|
|
|
|
|
|
|
console.log(fileName)
|
|
|
|
|
|
|
|
let shouldExclude = false
|
|
|
|
|
|
|
|
exclusionArr.forEach(function(exclusion){
|
|
|
|
if(exclusion.indexOf(fileName) > -1){
|
|
|
|
shouldExclude = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if(shouldExclude){
|
|
|
|
entry.autodrain()
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mkpath.sync(path.join(nativePath, fileName, '..'))
|
|
|
|
entry.pipe(fs.createWriteStream(path.join(nativePath, fileName)))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
cpArgs.push(to)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return cpArgs.join(';')
|
2017-05-14 08:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
launchMinecraft
|
2017-04-28 07:59:28 +00:00
|
|
|
}
|