Skip to content

Commit

Permalink
fix: Forge launch fail due to missing DlibraryDirectory & some assets…
Browse files Browse the repository at this point in the history
… decompression
  • Loading branch information
ci010 committed Feb 26, 2024
1 parent 3cd7d19 commit 4c53061
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions packages/core/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { EventEmitter } from 'events'
import { createWriteStream, existsSync } from 'fs'
import { link, mkdir, readFile, writeFile } from 'fs/promises'
import { EOL } from 'os'
import { delimiter, dirname, isAbsolute, join, resolve } from 'path'
import { basename, delimiter, dirname, isAbsolute, join, resolve } from 'path'
import { pipeline } from 'stream'
import { promisify } from 'util'
import { MinecraftFolder } from './folder'
Expand Down Expand Up @@ -301,7 +301,7 @@ export namespace LaunchPrecheck {
await mkdir(native, { recursive: true }).catch((e) => {
if (e.code !== 'EEXIST') { throw e }
})
const natives = version.libraries.filter((lib) => lib.isNative)
const natives = version.libraries.filter((lib) => lib.isNative || lib.classifier.startsWith('natives'))
const checksumFile = join(native, '.json')
const includedLibs = natives.map((n) => n.name).sort()

Expand All @@ -324,25 +324,36 @@ export namespace LaunchPrecheck {
if (!n) { return }
const excluded: string[] = n.extractExclude || []

const platform = option.platform || getPlatform()
const containsExcludes = (p: string) => excluded.filter((s) => p.startsWith(s)).length === 0
const notInMetaInf = (p: string) => p.indexOf('META-INF/') === -1
const notSha1AndNotGit = (p: string) => !(p.endsWith('.sha1') || p.endsWith('.git'))
const isSatisfyPlaform = (p: string) => {
if (p.indexOf('/') === -1) { return true }
const [os, arch] = p.split('/')
const platformArch = arch === 'ia32' ? 'x86' : arch
return os === platform.name && platformArch === platform.arch
}

const from = resource.getLibraryByPath(n.download.path)
const promises: Promise<void>[] = []
const zip = await open(from, { lazyEntries: true, autoClose: false })
for await (const entry of walkEntriesGenerator(zip)) {
if (containsExcludes(entry.fileName) && notInMetaInf(entry.fileName) && notSha1AndNotGit(entry.fileName)) {
if (entry.fileName.endsWith('/')) {
continue
}
const dest = join(native, entry.fileName)
if (entry.fileName.indexOf('/') !== -1) {
if (
containsExcludes(entry.fileName) &&
notInMetaInf(entry.fileName) &&
notSha1AndNotGit(entry.fileName) &&
!entry.fileName.endsWith('/') &&
isSatisfyPlaform(entry.fileName)
) {
const fileName = basename(entry.fileName)
const dest = join(native, fileName)
if (fileName.indexOf('/') !== -1) {
await mkdir(dirname(dest), {
recursive: true,
}).catch((e) => {})
}
extractedNatives.push({ file: entry.fileName, name: n.name, sha1: '' })
extractedNatives.push({ file: fileName, name: n.name, sha1: '' })
promises.push(promisify(pipeline)(await openEntryReadStream(zip, entry), createWriteStream(dest)))
}
}
Expand Down Expand Up @@ -670,6 +681,8 @@ export async function generateArguments(options: LaunchOption) {
}
}

cmd.push('-DlibraryDirectory=' + mc.getPath('libraries'))

const jvmOptions = {
natives_directory: nativeRoot,
launcher_name: launcherName,
Expand Down

0 comments on commit 4c53061

Please sign in to comment.