Successfully launched vanilla minecraft, however much code cleanup is pending.

This commit is contained in:
Daniel Scalzi 2017-04-29 20:33:32 -04:00
parent b01f652d8c
commit d4caf1ad22
6 changed files with 128 additions and 52 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
/node_modules/
/.vs/
/.vscode/
/mcfiles/
/mcfiles/
/logs/

View File

@ -4,6 +4,7 @@ const path = require('path')
const mkpath = require('mkdirp');
const async = require('async')
const crypto = require('crypto')
const libary = require('./library.js')
function Asset(from, to, size, hash){
this.from = from
@ -93,7 +94,7 @@ exports.downloadLibraries = function(versionData, basePath){
const libArr = versionData['libraries']
const libPath = path.join(basePath, 'libraries')
async.eachLimit(libArr, 1, function(lib, cb){
if(validateRules(lib['rules'])){
if(library.validateRules(lib['rules'])){
if(lib['natives'] == null){
const dlInfo = lib['downloads']
const artifact = dlInfo['artifact']
@ -119,7 +120,7 @@ exports.downloadLibraries = function(versionData, basePath){
}
} else {
const natives = lib['natives']
const opSys = mojangFriendlyOS()
const opSys = library.mojangFriendlyOS()
const indexId = natives[opSys]
const dlInfo = lib['downloads']
const classifiers = dlInfo['classifiers']
@ -238,41 +239,4 @@ validateLocalIntegrity = function(filePath, algo, hash){
}
}
return false;
}
validateRules = function(rules){
if(rules == null) return true
let result = true
rules.forEach(function(rule){
const action = rule['action']
const osProp = rule['os']
if(action != null){
if(osProp != null){
const osName = osProp['name']
const osMoj = mojangFriendlyOS()
if(action === 'allow'){
result = osName === osMoj
return
} else if(action === 'disallow'){
result = osName !== osMoj
return
}
}
}
})
return result
}
mojangFriendlyOS = function(){
const opSys = process.platform
if (opSys === 'darwin') {
return 'osx';
} else if (opSys === 'win32'){
return 'windows';
} else if (opSys === 'linux'){
return 'linux';
} else {
return 'unknown_os';
}
}

View File

@ -2,6 +2,10 @@ const mojang = require('mojang')
const uuidV4 = require('uuid/v4')
const path = require('path')
const child_process = require('child_process')
const library = require('./library.js')
const fs = require('fs')
const unzip = require('unzip')
const mkpath = require('mkdirp');
exports.launchMinecraft = function(versionData, basePath){
const authPromise = mojang.auth('EMAIL', 'PASS', uuidV4(), {
@ -11,8 +15,9 @@ exports.launchMinecraft = function(versionData, basePath){
authPromise.then(function(data){
const hardcodedargs = ''
const args = finalizeArguments(versionData, data, basePath)
console.log(args)
const child = child_process.execFile(basePath)
//console.log(args)
//TODO make this dynamic
const child = child_process.spawn('C:\\Program Files\\Java\\jre1.8.0_131\\bin\\javaw.exe', args)
})
}
@ -20,6 +25,15 @@ finalizeArguments = function(versionData, authData, basePath){
const mcArgs = versionData['minecraftArguments']
const regex = new RegExp('\\${*(.*)}')
const argArr = mcArgs.split(' ')
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')
for(let i=0; i<argArr.length; i++){
if(regex.test(argArr[i])){
const identifier = argArr[i].match(regex)[1]
@ -28,7 +42,7 @@ finalizeArguments = function(versionData, authData, basePath){
switch(identifier){
case 'auth_player_name':
//TODO make this DYNAMIC
newVal = 'NAME'
newVal = 'iPepsiHD'
break
case 'version_name':
newVal = versionData['id']
@ -44,7 +58,7 @@ finalizeArguments = function(versionData, authData, basePath){
break
case 'auth_uuid':
//TODO make this DYNAMIC
newVal = 'UUID'
newVal = '48f0a3d02ae14ca4aa0011bb8bc4f39e'
break
case 'auth_access_token':
newVal = authData['accessToken']
@ -60,5 +74,64 @@ finalizeArguments = function(versionData, authData, basePath){
argArr[i] = newVal
}
}
return argArr.join(' ')
return argArr
}
classpathArg = function(versionData, basePath){
const libArr = versionData['libraries']
const libPath = path.join(basePath, 'libraries')
const nativePath = path.join(basePath, 'natives')
//TODO make this dynamic
const cpArgs = ['C:\\Users\\Asus\\Desktop\\LauncherElectron\\mcfiles\\versions\\1.11.2\\1.11.2.jar']
libArr.forEach(function(lib){
if(library.validateRules(lib['rules'])){
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']
const opSys = library.mojangFriendlyOS()
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(';')
}

37
app/assets/js/library.js Normal file
View File

@ -0,0 +1,37 @@
exports.mojangFriendlyOS = function(){
const opSys = process.platform
if (opSys === 'darwin') {
return 'osx';
} else if (opSys === 'win32'){
return 'windows';
} else if (opSys === 'linux'){
return 'linux';
} else {
return 'unknown_os';
}
}
exports.validateRules = function(rules){
if(rules == null) return true
let result = true
rules.forEach(function(rule){
const action = rule['action']
const osProp = rule['os']
if(action != null){
if(osProp != null){
const osName = osProp['name']
const osMoj = exports.mojangFriendlyOS()
if(action === 'allow'){
result = osName === osMoj
return
} else if(action === 'disallow'){
result = osName !== osMoj
return
}
}
}
})
return result
}

View File

@ -18,16 +18,16 @@ function createWindow() {
win.setMenu(null)
//Code for testing, marked for removal one it's properly implemented.
/*const assetdl = require('./app/assets/js/assetdownload.js')
const assetdl = require('./app/assets/js/assetdownload.js')
const basePath = path.join(__dirname, 'mcfiles')
const dataPromise = assetdl.parseVersionData('1.11.2', basePath)
dataPromise.then(function(data){
assetdl.downloadAssets(data, basePath)
assetdl.downloadClient(data, basePath)
assetdl.downloadLogConfig(data, basePath)
assetdl.downloadLibraries(data, basePath)
//require('./app/assets/js/launchprocess.js').launchMinecraft(data, basePath)
})*/
//assetdl.downloadAssets(data, basePath)
//assetdl.downloadClient(data, basePath)
//assetdl.downloadLogConfig(data, basePath)
//assetdl.downloadLibraries(data, basePath)
require('./app/assets/js/launchprocess.js').launchMinecraft(data, basePath)
})
win.on('closed', () => {
win = null

View File

@ -21,6 +21,7 @@
"electron": "^1.6.5",
"mojang": "^0.4.0",
"promise": "^7.1.1",
"unzip": "^0.1.11",
"uuid": "^3.0.1"
}
}