This repository was archived by the owner on Mar 21, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
322 lines (274 loc) · 10.8 KB
/
main.js
File metadata and controls
322 lines (274 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
const fs = require('fs');
const path = require('path');
const cliProgress = require('cli-progress');
const { exit } = require('process');
const axios = require('axios');
const downloadFile = require('./modules/download');
const verifyChecksum = require('./modules/checksum');
const extractZip = require('./modules/extract');
const fetchVersion = require('./modules/version');
const { deleteFolderRecursive } = require('./modules/fileutils');
const { folderMappings, AppSettings } = require('./modules/constants');
const logger = require('./modules/logger');
const fetchPreviousVersion = require('./modules/fpv');
const CONFIG_FILE_PATH = './config.json';
const DEFAULT_CONFIG = {
deleteExistingFolders: false,
forceUpdate: false,
};
let config = { ...DEFAULT_CONFIG };
const colors = {
RESET: "\x1b[0m",
RED: "\x1b[31m",
GREEN: "\x1b[32m",
YELLOW: "\x1b[33m",
BLUE: "\x1b[34m",
MAGENTA: "\x1b[35m",
CYAN: "\x1b[36m",
};
const clearTerminal = () => {
console.clear();
};
const asciiArt = `
██████ ██████ ██ ██ ██████ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██
██████ ██████ ███ ██ ██ ██
██ ██ ██ ██ ██ ██ ██ ██ ██
██ ██ ██████ ██ ██ ██████ ███████ ██ v1.0.6
Download and launch Roblox versions using just the command line.
`;
const mainMenu = `
${colors.BLUE}${asciiArt}${colors.RESET}
${colors.CYAN}1. Download latest version/update${colors.RESET}
${colors.CYAN}2. Download the last LIVE version (downgrade)${colors.RESET}
${colors.CYAN}3. Download a custom version hash${colors.RESET}
${colors.CYAN}4. Download from a specific channel${colors.RESET}
${colors.CYAN}5. Launch Roblox${colors.RESET}
${colors.CYAN}6. Launch Roblox with args${colors.RESET}
${colors.GREEN}7. Settings${colors.RESET}
${colors.RED}8. Exit${colors.RESET}
`;
const loadConfig = () => {
if (fs.existsSync(CONFIG_FILE_PATH)) {
const rawData = fs.readFileSync(CONFIG_FILE_PATH);
config = JSON.parse(rawData);
} else {
saveConfig();
}
};
const saveConfig = () => {
fs.writeFileSync(CONFIG_FILE_PATH, JSON.stringify(config, null, 2));
};
const showSettingsMenu = async () => {
clearTerminal();
console.log(`${colors.MAGENTA}Settings Menu${colors.RESET}`);
console.log(`${colors.GREEN}1. Toggle delete existing folders (Current: ${config.deleteExistingFolders})${colors.RESET}`);
console.log(`${colors.YELLOW}2. Toggle force update (Current: ${config.forceUpdate})${colors.RESET}`);
console.log(`${colors.RED}3. Back to main menu${colors.RESET}`);
const choice = await prompt('Select an option: ');
switch (choice) {
case '1':
config.deleteExistingFolders = !config.deleteExistingFolders;
console.log(`${colors.BLUE}Delete existing folders set to: ${config.deleteExistingFolders}${colors.RESET}`);
saveConfig();
await prompt('Press Enter to continue...');
showSettingsMenu();
break;
case '2':
config.forceUpdate = !config.forceUpdate;
console.log(`${colors.BLUE}Force update set to: ${config.forceUpdate}${colors.RESET}`);
saveConfig();
await prompt('Press Enter to continue...');
showSettingsMenu();
break;
case '3':
main();
break;
default:
console.log(colors.RED + 'Invalid option selected. Please try again.' + colors.RESET);
showSettingsMenu();
break;
}
};
const main = async () => {
clearTerminal();
console.log(mainMenu);
const choice = await prompt('Select an option: ');
switch (choice) {
case '1':
clearTerminal();
await downloadLatestVersion();
break;
case '2':
clearTerminal();
const previousVersion = await fetchPreviousVersion();
if (previousVersion) {
await downloadVersion(previousVersion);
}
break;
case '3':
clearTerminal();
const versionHash = await prompt('Enter the custom version hash: ');
await downloadCustomVersion(versionHash);
break;
case '4':
clearTerminal();
const channel = await prompt('Enter the channel name: ');
await downloadFromChannel(channel);
break;
case '5':
clearTerminal();
await launchRoblox();
break;
case '6':
clearTerminal();
await launchRoblox(true);
break;
case '7':
clearTerminal();
await showSettingsMenu();
break;
case '8':
clearTerminal();
console.log(colors.BLUE + 'Exiting...' + colors.RESET);
exit(0);
break;
default:
clearTerminal();
console.log(colors.RED + 'Invalid option selected. Please try again.' + colors.RESET);
main();
break;
}
};
const downloadLatestVersion = async () => {
logger.info('Fetching the latest version of Roblox from LIVE Channel...');
logger.info('--> https://clientsettingscdn.roblox.com/v2/client-version/WindowsPlayer/channel/live/');
const version = await fetchVersion();
logger.info(`Version: ${version}`);
await downloadVersion(version);
};
const downloadCustomVersion = async (version) => {
logger.info(`Fetching the custom version: ${version}`);
await downloadVersion(version);
};
const downloadFromChannel = async (channel) => {
logger.info(`Fetching the latest version of Roblox from channel: ${channel}`);
const versionUrl = `https://clientsettingscdn.roblox.com/v2/client-version/WindowsPlayer/channel/${channel}/`;
try {
const response = await axios.get(versionUrl);
const version = response.data.clientVersionUpload;
logger.info(`Version from channel ${channel}: ${version}`);
await downloadVersion(version);
} catch (error) {
logger.error(`Failed to fetch version from channel ${channel}: ${error.message}`);
}
};
const downloadVersion = async (version) => {
clearTerminal();
const versionFolder = version.startsWith('version-') ? version : `version-${version}`;
const dumpDir = path.join(__dirname, versionFolder);
if (fs.existsSync(dumpDir) && !config.forceUpdate) {
logger.info(`Version ${version} is already downloaded.`);
exit(0);
}
if (fs.existsSync(dumpDir) && config.deleteExistingFolders) {
logger.info(`Deleting existing folder: ${dumpDir}`);
deleteFolderRecursive(dumpDir);
}
const baseUrl = `https://setup.rbxcdn.com/${version}-`;
const manifestUrl = `${baseUrl}rbxPkgManifest.txt`;
fs.mkdirSync(dumpDir, { recursive: true });
logger.info(`Fetching manifest from ${manifestUrl}...`);
const response = await axios.get(manifestUrl);
const manifestContent = response.data.trim().split('\n');
const firstLine = manifestContent[0].trim();
if (firstLine !== 'v0') {
logger.error(`Unexpected manifest version: ${firstLine}. Expected 'v0'.`);
return;
} else {
logger.info(`Manifest version: ${firstLine}`);
}
const progressBar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
for (let i = 1; i < manifestContent.length; i += 4) {
const fileName = manifestContent[i].trim();
const checksum = manifestContent[i + 1].trim();
const compressedSize = parseInt(manifestContent[i + 2], 10);
const uncompressedSize = parseInt(manifestContent[i + 3], 10);
if (fileName.endsWith('.zip') || fileName.endsWith('.exe')) {
const packageUrl = `${baseUrl}${fileName}`;
const filePath = `${dumpDir}/${fileName}`;
logger.info(`Downloading ${fileName} from ${packageUrl}...`);
await downloadFile(packageUrl, filePath, progressBar);
logger.info(`Verifying ${fileName}...`);
const isChecksumValid = await verifyChecksum(filePath, checksum);
if (isChecksumValid) {
logger.info(`${fileName} downloaded and verified successfully.`);
if (fileName.endsWith('.zip')) {
logger.info(`Extracting ${fileName}...`);
const extractPath = await extractZip(filePath, dumpDir, folderMappings);
logger.info(`Cleaning up ${fileName}...`);
fs.unlinkSync(filePath);
logger.info(`Deleted ${fileName}.`);
}
} else {
logger.error(`Checksum mismatch for ${fileName}. Deleting file.`);
fs.unlinkSync(filePath);
}
} else {
logger.info(`Skipping entry: ${fileName}`);
}
}
logger.info(`Creating AppSettings.xml...`);
fs.writeFileSync(`${dumpDir}/AppSettings.xml`, AppSettings);
logger.info(`AppSettings.xml created at root.`);
logger.info(`Roblox ${version} has been successfully downloaded and extracted to ${dumpDir}.`);
exit(0);
};
const launchRoblox = async (withArgs = false) => {
const versions = fs.readdirSync(__dirname).filter(f => f.startsWith('version-'));
if (versions.length === 0) {
console.log(colors.RED + 'No Roblox versions found in the current directory.' + colors.RESET);
return;
}
console.log(`${colors.MAGENTA}Available Versions:${colors.RESET}`);
versions.forEach((version, index) => {
console.log(`${colors.CYAN}${index + 1}. ${version}${colors.RESET}`);
});
const versionChoice = await prompt('Select a version (1/2/3...): ');
const versionIndex = parseInt(versionChoice) - 1;
if (versionIndex < 0 || versionIndex >= versions.length) {
console.log(colors.RED + 'Invalid version selected.' + colors.RESET);
return;
}
const selectedVersion = versions[versionIndex];
const robloxPlayerPath = path.join(__dirname, selectedVersion, 'RobloxPlayerBeta.exe');
if (!fs.existsSync(robloxPlayerPath)) {
console.log(colors.RED + `RobloxPlayerBeta.exe not found in ${selectedVersion}` + colors.RESET);
return;
}
let launchArgs = '';
if (withArgs) {
launchArgs = await prompt('Enter the launch arguments (e.g., roblox://...): ');
}
const childProcess = require('child_process');
const command = `"${robloxPlayerPath}"`;
const args = launchArgs.split(' ');
console.log(colors.GREEN + `Launching Roblox with command: ${command} ${launchArgs}` + colors.RESET);
const process = childProcess.spawn(command, args, { shell: true, detached: true, stdio: 'ignore' });
process.unref();
console.log(colors.GREEN + 'Roblox launched successfully.' + colors.RESET);
};
const prompt = (query) => {
return new Promise((resolve) => {
const rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question(query, (answer) => {
rl.close();
resolve(answer);
});
});
};
loadConfig();
main().catch(err => logger.error(err));