mirror of
https://github.com/dscalzi/HeliosLauncher.git
synced 2024-12-22 03:32:12 -08:00
Successfully launched vanilla minecraft, however much code cleanup is pending.
This commit is contained in:
parent
b01f652d8c
commit
d4caf1ad22
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
/node_modules/
|
/node_modules/
|
||||||
/.vs/
|
/.vs/
|
||||||
/.vscode/
|
/.vscode/
|
||||||
/mcfiles/
|
/mcfiles/
|
||||||
|
/logs/
|
@ -4,6 +4,7 @@ const path = require('path')
|
|||||||
const mkpath = require('mkdirp');
|
const mkpath = require('mkdirp');
|
||||||
const async = require('async')
|
const async = require('async')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
|
const libary = require('./library.js')
|
||||||
|
|
||||||
function Asset(from, to, size, hash){
|
function Asset(from, to, size, hash){
|
||||||
this.from = from
|
this.from = from
|
||||||
@ -93,7 +94,7 @@ exports.downloadLibraries = function(versionData, basePath){
|
|||||||
const libArr = versionData['libraries']
|
const libArr = versionData['libraries']
|
||||||
const libPath = path.join(basePath, 'libraries')
|
const libPath = path.join(basePath, 'libraries')
|
||||||
async.eachLimit(libArr, 1, function(lib, cb){
|
async.eachLimit(libArr, 1, function(lib, cb){
|
||||||
if(validateRules(lib['rules'])){
|
if(library.validateRules(lib['rules'])){
|
||||||
if(lib['natives'] == null){
|
if(lib['natives'] == null){
|
||||||
const dlInfo = lib['downloads']
|
const dlInfo = lib['downloads']
|
||||||
const artifact = dlInfo['artifact']
|
const artifact = dlInfo['artifact']
|
||||||
@ -119,7 +120,7 @@ exports.downloadLibraries = function(versionData, basePath){
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const natives = lib['natives']
|
const natives = lib['natives']
|
||||||
const opSys = mojangFriendlyOS()
|
const opSys = library.mojangFriendlyOS()
|
||||||
const indexId = natives[opSys]
|
const indexId = natives[opSys]
|
||||||
const dlInfo = lib['downloads']
|
const dlInfo = lib['downloads']
|
||||||
const classifiers = dlInfo['classifiers']
|
const classifiers = dlInfo['classifiers']
|
||||||
@ -238,41 +239,4 @@ validateLocalIntegrity = function(filePath, algo, hash){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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';
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,6 +2,10 @@ const mojang = require('mojang')
|
|||||||
const uuidV4 = require('uuid/v4')
|
const uuidV4 = require('uuid/v4')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const child_process = require('child_process')
|
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){
|
exports.launchMinecraft = function(versionData, basePath){
|
||||||
const authPromise = mojang.auth('EMAIL', 'PASS', uuidV4(), {
|
const authPromise = mojang.auth('EMAIL', 'PASS', uuidV4(), {
|
||||||
@ -11,8 +15,9 @@ exports.launchMinecraft = function(versionData, basePath){
|
|||||||
authPromise.then(function(data){
|
authPromise.then(function(data){
|
||||||
const hardcodedargs = ''
|
const hardcodedargs = ''
|
||||||
const args = finalizeArguments(versionData, data, basePath)
|
const args = finalizeArguments(versionData, data, basePath)
|
||||||
console.log(args)
|
//console.log(args)
|
||||||
const child = child_process.execFile(basePath)
|
//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 mcArgs = versionData['minecraftArguments']
|
||||||
const regex = new RegExp('\\${*(.*)}')
|
const regex = new RegExp('\\${*(.*)}')
|
||||||
const argArr = mcArgs.split(' ')
|
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++){
|
for(let i=0; i<argArr.length; i++){
|
||||||
if(regex.test(argArr[i])){
|
if(regex.test(argArr[i])){
|
||||||
const identifier = argArr[i].match(regex)[1]
|
const identifier = argArr[i].match(regex)[1]
|
||||||
@ -28,7 +42,7 @@ finalizeArguments = function(versionData, authData, basePath){
|
|||||||
switch(identifier){
|
switch(identifier){
|
||||||
case 'auth_player_name':
|
case 'auth_player_name':
|
||||||
//TODO make this DYNAMIC
|
//TODO make this DYNAMIC
|
||||||
newVal = 'NAME'
|
newVal = 'iPepsiHD'
|
||||||
break
|
break
|
||||||
case 'version_name':
|
case 'version_name':
|
||||||
newVal = versionData['id']
|
newVal = versionData['id']
|
||||||
@ -44,7 +58,7 @@ finalizeArguments = function(versionData, authData, basePath){
|
|||||||
break
|
break
|
||||||
case 'auth_uuid':
|
case 'auth_uuid':
|
||||||
//TODO make this DYNAMIC
|
//TODO make this DYNAMIC
|
||||||
newVal = 'UUID'
|
newVal = '48f0a3d02ae14ca4aa0011bb8bc4f39e'
|
||||||
break
|
break
|
||||||
case 'auth_access_token':
|
case 'auth_access_token':
|
||||||
newVal = authData['accessToken']
|
newVal = authData['accessToken']
|
||||||
@ -60,5 +74,64 @@ finalizeArguments = function(versionData, authData, basePath){
|
|||||||
argArr[i] = newVal
|
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
37
app/assets/js/library.js
Normal 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
|
||||||
|
}
|
14
index.js
14
index.js
@ -18,16 +18,16 @@ function createWindow() {
|
|||||||
win.setMenu(null)
|
win.setMenu(null)
|
||||||
|
|
||||||
//Code for testing, marked for removal one it's properly implemented.
|
//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 basePath = path.join(__dirname, 'mcfiles')
|
||||||
const dataPromise = assetdl.parseVersionData('1.11.2', basePath)
|
const dataPromise = assetdl.parseVersionData('1.11.2', basePath)
|
||||||
dataPromise.then(function(data){
|
dataPromise.then(function(data){
|
||||||
assetdl.downloadAssets(data, basePath)
|
//assetdl.downloadAssets(data, basePath)
|
||||||
assetdl.downloadClient(data, basePath)
|
//assetdl.downloadClient(data, basePath)
|
||||||
assetdl.downloadLogConfig(data, basePath)
|
//assetdl.downloadLogConfig(data, basePath)
|
||||||
assetdl.downloadLibraries(data, basePath)
|
//assetdl.downloadLibraries(data, basePath)
|
||||||
//require('./app/assets/js/launchprocess.js').launchMinecraft(data, basePath)
|
require('./app/assets/js/launchprocess.js').launchMinecraft(data, basePath)
|
||||||
})*/
|
})
|
||||||
|
|
||||||
win.on('closed', () => {
|
win.on('closed', () => {
|
||||||
win = null
|
win = null
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
"electron": "^1.6.5",
|
"electron": "^1.6.5",
|
||||||
"mojang": "^0.4.0",
|
"mojang": "^0.4.0",
|
||||||
"promise": "^7.1.1",
|
"promise": "^7.1.1",
|
||||||
|
"unzip": "^0.1.11",
|
||||||
"uuid": "^3.0.1"
|
"uuid": "^3.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user