@kzheart_/mc-pilot 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { mkdirSync, openSync } from "node:fs";
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { MctError } from "../util/errors.js";
|
|
5
6
|
import { getListeningPids, isProcessRunning, killProcessTree } from "../util/process.js";
|
|
6
7
|
import { WebSocketClient } from "./WebSocketClient.js";
|
|
8
|
+
function getLaunchScriptPath() {
|
|
9
|
+
const thisFile = fileURLToPath(import.meta.url);
|
|
10
|
+
// dist/client/ClientManager.js -> scripts/launch-fabric-client.mjs
|
|
11
|
+
return path.resolve(path.dirname(thisFile), "..", "..", "scripts", "launch-fabric-client.mjs");
|
|
12
|
+
}
|
|
7
13
|
const CLIENT_STATE_FILE = "clients.json";
|
|
8
14
|
function getDefaultSnapshot() {
|
|
9
15
|
return {
|
|
@@ -46,11 +52,13 @@ export class ClientManager {
|
|
|
46
52
|
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
47
53
|
}
|
|
48
54
|
}
|
|
49
|
-
const launchCommand = configured.
|
|
55
|
+
const launchCommand = configured.launchArgs
|
|
56
|
+
? [process.execPath, getLaunchScriptPath(), ...configured.launchArgs]
|
|
57
|
+
: configured.launchCommand;
|
|
50
58
|
if (!launchCommand || launchCommand.length === 0) {
|
|
51
59
|
throw new MctError({
|
|
52
60
|
code: "INVALID_PARAMS",
|
|
53
|
-
message: `Client ${options.name} requires launchCommand in config`
|
|
61
|
+
message: `Client ${options.name} requires launchArgs (or launchCommand) in config`
|
|
54
62
|
}, 4);
|
|
55
63
|
}
|
|
56
64
|
const cwd = configured.workingDir
|
|
@@ -36,7 +36,7 @@ export declare function downloadClientMod(context: CommandContext, options: Down
|
|
|
36
36
|
jar: string;
|
|
37
37
|
cachePath: string;
|
|
38
38
|
clientName: string;
|
|
39
|
-
|
|
39
|
+
launchArgsConfigured: boolean;
|
|
40
40
|
runtimeRootDir: string | undefined;
|
|
41
41
|
runtimeVersionId: string | undefined;
|
|
42
42
|
}>;
|
|
@@ -114,10 +114,8 @@ function resolveLaunchRuntimePaths(context, options) {
|
|
|
114
114
|
: {})
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
|
-
function
|
|
117
|
+
function buildLaunchArgs(runtimePaths, variant) {
|
|
118
118
|
return [
|
|
119
|
-
process.execPath,
|
|
120
|
-
getLaunchScriptPath(),
|
|
121
119
|
"--instance-dir",
|
|
122
120
|
runtimePaths.instanceDir,
|
|
123
121
|
"--meta-dir",
|
|
@@ -133,10 +131,8 @@ function buildLaunchCommand(context, runtimePaths, variant) {
|
|
|
133
131
|
variant.fabricLoaderVersion ?? "0.16.10"
|
|
134
132
|
];
|
|
135
133
|
}
|
|
136
|
-
function
|
|
134
|
+
function buildManagedLaunchArgs(runtimeRootDir, versionId, gameDir) {
|
|
137
135
|
return [
|
|
138
|
-
process.execPath,
|
|
139
|
-
getLaunchScriptPath(),
|
|
140
136
|
"--runtime-root",
|
|
141
137
|
runtimeRootDir,
|
|
142
138
|
"--version-id",
|
|
@@ -202,21 +198,22 @@ export async function downloadClientMod(context, options, dependencies = {}) {
|
|
|
202
198
|
const managedRuntime = runtimePaths
|
|
203
199
|
? undefined
|
|
204
200
|
: await prepareManagedRuntimeImpl(variant, clientRootDir, { fetchImpl });
|
|
205
|
-
const
|
|
206
|
-
?
|
|
207
|
-
:
|
|
201
|
+
const generatedLaunchArgs = runtimePaths
|
|
202
|
+
? buildLaunchArgs(runtimePaths, variant)
|
|
203
|
+
: buildManagedLaunchArgs(managedRuntime.runtimeRootDir, managedRuntime.versionId, managedRuntime.gameDir);
|
|
208
204
|
latestConfig.clients[clientName] = {
|
|
209
205
|
...configuredClient,
|
|
210
206
|
version: variant.minecraftVersion,
|
|
211
207
|
wsPort: options.wsPort ?? configuredClient.wsPort ?? DEFAULT_WS_PORT_BASE,
|
|
212
208
|
server: options.server ?? configuredClient.server ?? "localhost:25565",
|
|
213
209
|
workingDir: path.relative(context.cwd, minecraftDir) || ".",
|
|
210
|
+
launchCommand: undefined,
|
|
211
|
+
launchArgs: generatedLaunchArgs,
|
|
214
212
|
env: {
|
|
215
213
|
...configuredClient.env,
|
|
216
214
|
MCT_CLIENT_MOD_VARIANT: variant.id,
|
|
217
215
|
MCT_CLIENT_MOD_JAR: path.relative(context.cwd, targetJarPath)
|
|
218
216
|
},
|
|
219
|
-
...(generatedLaunchCommand ? { launchCommand: generatedLaunchCommand } : {})
|
|
220
217
|
};
|
|
221
218
|
await writeConfig(context.configPath, context.cwd, latestConfig);
|
|
222
219
|
return {
|
|
@@ -232,7 +229,7 @@ export async function downloadClientMod(context, options, dependencies = {}) {
|
|
|
232
229
|
jar: targetJarPath,
|
|
233
230
|
cachePath: artifact.cachePath,
|
|
234
231
|
clientName,
|
|
235
|
-
|
|
232
|
+
launchArgsConfigured: Boolean(generatedLaunchArgs),
|
|
236
233
|
runtimeRootDir: managedRuntime?.runtimeRootDir,
|
|
237
234
|
runtimeVersionId: managedRuntime?.versionId
|
|
238
235
|
};
|
package/dist/util/config.d.ts
CHANGED