Skip to content

Instantly share code, notes, and snippets.

Created July 2, 2017 12:14
Show Gist options
  • Save anonymous/6a8c3c111cbcc9a09f2dfaaa7ef1e167 to your computer and use it in GitHub Desktop.
Save anonymous/6a8c3c111cbcc9a09f2dfaaa7ef1e167 to your computer and use it in GitHub Desktop.
const path = require('path')
const os = require('os')
const mcPath = require('minecraft-folder-path')
const launcherProfile = require(path.join(mcPath, 'launcher_profiles.json'))
const auth = launcherProfile.authenticationDatabase[launcherProfile.selectedUser]
const version = launcherProfile.profiles[launcherProfile.selectedProfile].lastVersionId
console.log(makeCmd({ version, auth, mcPath, clientToken: launcherProfile.clientToken }))
function makeCmd({version, auth, mcPath, clientToken}) {
const versionPath = path.join(mcPath, 'versions', version)
const jar = path.join(versionPath, version + '.jar')
const versionIndex = loadVersionIndex(version)
const java = 'java'
const javaArgs = ['-Xmx512M', '-Xmn128M']
const args = versionIndex.minecraftArguments
.replace('${version_name}', version)
.replace('${game_directory}', mcPath)
.replace('${auth_player_name}', auth.displayName)
.replace('${auth_access_token}', auth.accessToken)
.replace('${auth_session}', clientToken)
.replace('${auth_uuid}', auth.uuid)
.replace('${user_type}', 'legacy')
.replace('${user_properties}', '{}')
.replace('${version_type}', versionIndex.type)
.replace('${assets_root}', path.join(mcPath, 'assets'))
.replace('${assets_index_name}', versionIndex.assets)
const libs = versionIndex.libraries.map(lib => {
const split = lib.name.split(':')
return path.join(mcPath, 'libraries', ...split[0].split("."), split[1], split[2],`${split[1]}-${split[2]}.jar`)
})
return [
java,
...javaArgs,
`"-Djava.library.path=${path.join(versionPath, version + '-natives')}"`,
'-cp',
`"${[...libs, jar].join(os.platform() === 'win32' ? ';' : ':')}"`,
versionIndex.mainClass,
args
].join(' ')
function loadVersionIndex(version) {
const versionPath = path.join(mcPath, 'versions', version)
const versionIndex = require(path.join(versionPath, version))
if (!versionIndex.inheritsFrom) return versionIndex
versionIndex.libraries.push(...loadVersionIndex(versionIndex.inheritsFrom).libraries)
return versionIndex
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment