From f958f3598a95eb816c0e96e3bc3b36fb317f6151 Mon Sep 17 00:00:00 2001 From: HerozDotExe Date: Fri, 12 Dec 2025 17:25:17 +0100 Subject: [PATCH] feat: separate instance data from shared folders --- src/core/arguments.ts | 26 ++++++++++++++----------- src/instance/instance.ts | 42 +++++++++++++++++++++++++--------------- src/utils/types.ts | 28 +++++++++++++-------------- 3 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/core/arguments.ts b/src/core/arguments.ts index bea7c07..a52a713 100644 --- a/src/core/arguments.ts +++ b/src/core/arguments.ts @@ -9,20 +9,21 @@ import { getArgument } from "./log4j"; function fillArguments( arg: string, versionManifest: Version, - gameRoot: string, + assetsPath: string, + instancePath: string, classPaths: PoolFile[], auth: Auth, ) { const argumentsToFill = { - "${natives_directory}": path.join(gameRoot, "natives"), + "${natives_directory}": path.join(instancePath, "natives"), "${launcher_name}": "nlk", "${launcher_version}": packageVersion, "${classpath}": classPaths, - "${game_directory}": gameRoot, + "${game_directory}": instancePath, "${version_name}": versionManifest.id, "${version_type}": versionManifest.type, "${assets_index_name}": versionManifest.assets, - "${assets_root}": path.join(gameRoot, "assets"), + "${assets_root}": assetsPath, "${auth_access_token}": auth.access_token, "${auth_session}": auth.access_token, "${auth_player_name}": auth.name, @@ -48,23 +49,24 @@ function parseArg( this: string[], arg: Argument, versionManifest: Version, - gameRoot: string, + assetsPath: string, + instancePath: string, classPaths: PoolFile[], auth: Auth, ) { if (isNeeded(arg)) { if (typeof arg === "string") { this.push( - fillArguments(arg, versionManifest, gameRoot, classPaths, auth), + fillArguments(arg, versionManifest, assetsPath, instancePath, classPaths, auth), ); } else if (typeof arg.value === "string") { this.push( - fillArguments(arg.value, versionManifest, gameRoot, classPaths, auth), + fillArguments(arg.value, versionManifest, assetsPath, instancePath, classPaths, auth), ); } else if (arg.value.length > 1) { for (const e of arg.value) { this.push( - fillArguments(e, versionManifest, gameRoot, classPaths, auth), + fillArguments(e, versionManifest, assetsPath, instancePath, classPaths, auth), ); } } @@ -90,7 +92,9 @@ function generateClassPaths( export async function generateLaunchArguments( versionManifest: Version, javaRoot: string, - gameRoot: string, + instancePath: string, + librariesPath: string, + assetsPath: string, versionRoot: string, auth: Auth, options: { @@ -108,12 +112,12 @@ export async function generateLaunchArguments( const classPaths = generateClassPaths( versionManifest, - path.join(gameRoot, "libraries"), + librariesPath, path.join(versionRoot, `${versionManifest.id}.jar`), ); function p(args: string[], arg: Argument) { - parseArg.apply(args, [arg, versionManifest, gameRoot, classPaths, auth]); + parseArg.apply(args, [arg, versionManifest, assetsPath, instancePath, classPaths, auth]); } for (const arg of versionManifest.arguments.jvm) { diff --git a/src/instance/instance.ts b/src/instance/instance.ts index 6459944..788c7e0 100644 --- a/src/instance/instance.ts +++ b/src/instance/instance.ts @@ -55,7 +55,9 @@ export class Instance extends EventEmitter { paths: Paths; args: { java: string; game: string }; versionManifest: Version; - javaLocation?: string; + javaLocation: string; + versionLocation: string; + instanceLocation: string; ready: boolean; constructor() { @@ -78,21 +80,20 @@ export class Instance extends EventEmitter { if (typeof paths === "string") { this.paths = { root: paths, - version: path.join(paths, "version", this.version), + versions: path.join(paths, "versions"), assets: path.join(paths, "assets"), javaRoot: path.join(paths, "java"), libraries: path.join(paths, "libraries"), - natives: path.join(paths, "natives"), + instances: path.join(paths, "instances"), }; } else { this.paths = { root: paths.root, - version: - paths.version || path.join(paths.root, "version", this.version), + versions: paths.versions || path.join(paths.root, "versions"), assets: paths.assets || path.join(paths.root, "assets"), javaRoot: paths.javaRoot || path.join(paths.root, "java"), libraries: paths.libraries || path.join(paths.root, "libraries"), - natives: paths.natives || path.join(paths.root, "natives"), + instances: paths.instances || path.join(paths.root, "instances"), }; } } @@ -107,9 +108,12 @@ export class Instance extends EventEmitter { } async initialize() { + this.versionLocation = path.join(this.paths.versions, this.version); + this.instanceLocation = path.join(this.paths.instances, this.version); + this.versionManifest = await core.version.getVersionManifest( this.version, - this.paths.version, + this.versionLocation, ); this.javaLocation = path.join( @@ -122,7 +126,10 @@ export class Instance extends EventEmitter { try { await this.initialize(); this.ready = true; - await core.version.downloadJar(this.versionManifest, this.paths.version); + await core.version.downloadJar( + this.versionManifest, + this.versionLocation, + ); } catch (original) { const error = new InstallError("version", original); error.throw(); @@ -173,7 +180,7 @@ export class Instance extends EventEmitter { try { const nativesDownloader = await core.NativesDownloader( - this.paths.natives, + this.instanceLocation, this.versionManifest, ); nativesDownloader.on("completed", () => { @@ -227,25 +234,28 @@ export class Instance extends EventEmitter { } const args = await core.arguments.generateLaunchArguments( - await core.version.getVersionManifest(this.version, this.paths.version), + await core.version.getVersionManifest( + this.version, + this.versionLocation, + ), this.javaLocation, - this.paths.root, - this.paths.version, + this.instanceLocation, + this.paths.libraries, + this.paths.assets, + this.versionLocation, this.auth, { customGameArgs: this.args.game, customJvmArgs: this.args.java }, ); - const process = core.launch(args, this.paths.root); + const process = core.launch(args, this.instanceLocation); return process; } catch (original) { const error = new LaunchError( { version: this.version, - versionPath: this.paths.version, - javaLocation: this.javaLocation, - rootPath: this.paths.root, auth: this.auth, + paths: this.paths, customGameArgs: this.args.game, customJvmArgs: this.args.java, }, diff --git a/src/utils/types.ts b/src/utils/types.ts index 3cebca3..19af5cf 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -179,20 +179,18 @@ export type Auth = { export type LaunchArguments = { command: string; args: string[] }; export type Paths = { - root: string - version?: string - assets?: string - libraries?: string - natives?: string - javaRoot?: string -} + root: string; + versions?: string; + assets?: string; + libraries?: string; + instances?: string; + javaRoot?: string; +}; export type LaunchErrorInfos = { - version: string; - versionPath: string; - javaLocation: string; - rootPath: string; - auth: Auth; - customGameArgs: string; - customJvmArgs: string; - } \ No newline at end of file + version: string; + paths: Paths; + auth: Auth; + customGameArgs: string; + customJvmArgs: string; +};