feat: add a function to launch the game

This commit is contained in:
HerozDotExe 2025-11-19 12:03:13 +01:00
parent 34f09868f3
commit 3db0007789
5 changed files with 51 additions and 17 deletions

View file

@ -122,7 +122,29 @@ export async function generateLaunchArguments(
p(game, arg);
}
if (options.customJvm !== "") {
for (const arg of options.customJvm.split(" ")) {
jvm.push(arg);
}
}
const log4j = await getArgument(versionManifest, gameRoot);
return `${getJavaExecutable(javaRoot)} ${jvm.join(" ")}${options.customJvm === "" ? "" : ` ${options.customJvm}`} -Xms${options.minRam} -Xmx${options.maxRam} -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M ${log4j} ${versionManifest.mainClass} ${game.join(" ")}`;
return {
command: getJavaExecutable(javaRoot),
args: [
...jvm,
`-Xms${options.minRam}`,
`-Xmx${options.maxRam}`,
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UseG1GC",
"-XX:G1NewSizePercent=20",
"-XX:G1ReservePercent=20",
"-XX:MaxGCPauseMillis=50",
"-XX:G1HeapRegionSize=32M",
log4j,
versionManifest.mainClass,
...game,
],
};
}

View file

@ -1,8 +1,8 @@
export * as version from "./version";
export * as arguments from "./arguments";
export * as log4j from "./log4j";
export { AssetsDownloader } from "./assets";
export { LibrariesDownloader } from "./libraries";
export { NativesDownloader } from "./natives";
export * as java from "./java";
export * as version from "./version";
export * as arguments from "./arguments";
export * as log4j from "./log4j";
export { launch } from "./launch";

15
src/core/launch.ts Normal file
View file

@ -0,0 +1,15 @@
import { spawn } from "child_process";
import { LaunchArguments } from "../utils/types";
export function launch(
launchArguments: LaunchArguments,
gameRoot: string,
detached = false,
) {
console.log(gameRoot)
const process = spawn(launchArguments.command, launchArguments.args, { detached });
console.log(process.spawnargs.join(" "))
return process;
}

View file

@ -175,3 +175,5 @@ export type Auth = {
clientId: string;
};
};
export type LaunchArguments = { command: string; args: string[] }

File diff suppressed because one or more lines are too long