OptiFine & UUID fix

Allows OptiFine properly install and for forge clients to launch in offline mode. Addresses #84
This commit is contained in:
Pierce 2022-03-01 18:52:06 -08:00
parent 756caa260b
commit 86d42246f1
4 changed files with 169 additions and 148 deletions

View file

@ -1,14 +1,17 @@
const request = require('request')
const uuid = require('uuid').v1
const { v3 } = require('uuid')
let uuid
let api_url = 'https://authserver.mojang.com'
module.exports.getAuth = function (username, password, client_token = null) {
return new Promise((resolve, reject) => {
getUUID(username)
if (!password) {
const user = {
access_token: uuid(),
client_token: client_token || uuid(),
uuid: uuid(),
access_token: uuid,
client_token: client_token || uuid,
uuid,
name: username,
user_properties: '{}'
}
@ -23,9 +26,9 @@ module.exports.getAuth = function (username, password, client_token = null) {
name: 'Minecraft',
version: 1
},
username: username,
password: password,
clientToken: uuid(),
username,
password,
clientToken: uuid,
requestUser: true
}
}
@ -50,13 +53,13 @@ module.exports.getAuth = function (username, password, client_token = null) {
})
}
module.exports.validate = function (access_token, client_token) {
module.exports.validate = function (accessToken, clientToken) {
return new Promise((resolve, reject) => {
const requestObject = {
url: api_url + '/validate',
json: {
accessToken: access_token,
clientToken: client_token
accessToken,
clientToken
}
}
@ -74,8 +77,8 @@ module.exports.refreshAuth = function (accessToken, clientToken) {
const requestObject = {
url: api_url + '/refresh',
json: {
accessToken: accessToken,
clientToken: clientToken,
accessToken,
clientToken,
requestUser: true
}
}
@ -88,13 +91,13 @@ module.exports.refreshAuth = function (accessToken, clientToken) {
const userProfile = {
access_token: body.accessToken,
client_token: uuid(),
client_token: getUUID(body.selectedProfile.name),
uuid: body.selectedProfile.id,
name: body.selectedProfile.name,
user_properties: parsePropts(body.user.properties)
}
resolve(userProfile)
return resolve(userProfile)
})
})
}
@ -104,16 +107,16 @@ module.exports.invalidate = function (accessToken, clientToken) {
const requestObject = {
url: api_url + '/invalidate',
json: {
accessToken: accessToken,
clientToken: clientToken
accessToken,
clientToken
}
}
request.post(requestObject, function (error, response, body) {
if (error) return reject(error)
if (!body) resolve(true)
else reject(body)
if (!body) return resolve(true)
else return reject(body)
})
})
}
@ -123,16 +126,16 @@ module.exports.signOut = function (username, password) {
const requestObject = {
url: api_url + '/signout',
json: {
username: username,
password: password
username,
password
}
}
request.post(requestObject, function (error, response, body) {
if (error) return reject(error)
if (!body) resolve(true)
else reject(body)
if (!body) return resolve(true)
else return reject(body)
})
})
}
@ -156,3 +159,10 @@ function parsePropts (array) {
return '{}'
}
}
function getUUID (value) {
if (!uuid) {
uuid = v3(value, v3.DNS)
}
return uuid
}

View file

@ -458,7 +458,7 @@ class Handler {
runInstaller (path) {
return new Promise(resolve => {
const installer = child.exec(path)
installer.on('close', (code) => resolve())
installer.on('close', (code) => resolve(code))
})
}

View file

@ -6,6 +6,7 @@ const EventEmitter = require('events').EventEmitter
class MCLCore extends EventEmitter {
async launch (options) {
try {
this.options = { ...options }
this.options.root = path.resolve(this.options.root)
this.options.overrides = {
@ -51,8 +52,14 @@ class MCLCore extends EventEmitter {
if (this.options.installer) {
// So installers that create a profile in launcher_profiles.json can run without breaking.
const profilePath = path.join(this.options.root, 'launcher_profiles.json')
if (!fs.existsSync(profilePath)) { fs.writeFileSync(profilePath, JSON.stringify({}, null, 4)) }
await this.handler.runInstaller(this.options.installer)
if (!fs.existsSync(profilePath) || !JSON.parse(fs.readFileSync(profilePath)).profiles) {
fs.writeFileSync(profilePath, JSON.stringify({ profiles: {} }, null, 4))
}
const code = await this.handler.runInstaller(this.options.installer)
if (!this.options.version.custom && code === 0) {
this.emit('debug', '[MCLC]: Installer successfully ran, but no custom version was provided')
}
this.emit('debug', `[MCLC]: Installer closed with code ${code}`)
}
const directory = this.options.overrides.directory || path.join(this.options.root, 'versions', this.options.version.custom ? this.options.version.custom : this.options.version.number)
@ -133,6 +140,10 @@ class MCLCore extends EventEmitter {
this.emit('debug', `[MCLC]: Launching with arguments ${launchArguments.join(' ')}`)
return this.startMinecraft(launchArguments)
} catch (e) {
this.emit('debug', `[MCLC]: Failed to start due to ${e}, closing...`)
return null
}
}
printVersion () {

View file

@ -1,6 +1,6 @@
{
"name": "minecraft-launcher-core",
"version": "3.16.11",
"version": "3.16.12",
"description": "Lightweight module that downloads and runs Minecraft using javascript / NodeJS",
"main": "index.js",
"dependencies": {