forked from LordRain0/VengefulRealms-Launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
816 lines (697 loc) · 31.1 KB
/
Copy pathscript.js
File metadata and controls
816 lines (697 loc) · 31.1 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
// ========== VENGEFUL REALMS - PROFESSIONAL LAUNCHER UI ==========
// Frontend-only prototype. Connect triggerLauncherAction() to your executable/backend.
// Beta tester accounts. Frontend credential gate (no backend auth yet) —
// passwords are stored as hashPassword() values, not plaintext.
// Hand one email+password pair to each tester. Replace with MongoDB auth later.
const users = [
{ email: "ragnar@vengefulrealms.com", password: "ZXNkdTJyTldEd0duOnZlbmdlZnVsLXJlYWxtcy1sYXVuY2hlcg==" },
{ email: "freydis@vengefulrealms.com", password: "UVhGV1VKV1FoYnBIOnZlbmdlZnVsLXJlYWxtcy1sYXVuY2hlcg==" },
{ email: "bjorn@vengefulrealms.com", password: "Ujg2Q05EN0VFZ2ZOOnZlbmdlZnVsLXJlYWxtcy1sYXVuY2hlcg==" },
{ email: "sigrid@vengefulrealms.com", password: "WVZ6Zk5YVlJHN0Z6OnZlbmdlZnVsLXJlYWxtcy1sYXVuY2hlcg==" },
{ email: "ulfric@vengefulrealms.com", password: "UnFrcmpxS0hmdm5WOnZlbmdlZnVsLXJlYWxtcy1sYXVuY2hlcg==" },
{ email: "astrid@vengefulrealms.com", password: "eHhjRmFtN1hXWUFDOnZlbmdlZnVsLXJlYWxtcy1sYXVuY2hlcg==" },
];
let currentUser = null;
let selectedServer = null;
let downloadProgress = 100;
let updateInterval = null;
const authModal = document.getElementById("authModal");
const settingsModal = document.getElementById("settingsModal");
const settingsBtn = document.getElementById("settingsBtn");
const loginHeaderBtn = document.getElementById("loginHeaderBtn");
const logoutHeaderBtn = document.getElementById("logoutHeaderBtn");
function triggerLauncherAction(action, payload = {}) {
console.log("[Vengeful Realms Launcher]", action, payload);
// TODO: connect this to your launcher executable / backend bridge.
// Examples:
// - launch_game: start Skyrim/SkyMP with arguments
// - check_updates: contact patch server
// - verify_files: compare local files against manifest
// - open_folder: open install/mod folder
}
function hashPassword(password) {
return btoa(`${password}:vengeful-realms-launcher`);
}
function isValidEmail(email) {
return /^[^\s@]+@([^\s@]+\.)+[^\s@]+$/.test(email);
}
function showToast(message, isError = false) {
const container = document.getElementById("toastContainer");
if (!container) return;
const toast = document.createElement("div");
toast.className = isError ? "toast error" : "toast";
toast.textContent = message;
container.appendChild(toast);
setTimeout(() => {
toast.style.opacity = "0";
setTimeout(() => toast.remove(), 220);
}, 2600);
}
function openAuthModal() {
if (!authModal) return;
showLoginFormModal();
authModal.classList.add("show");
authModal.setAttribute("aria-hidden", "false");
}
function closeAuthModal() {
if (!authModal) return;
authModal.classList.remove("show");
authModal.setAttribute("aria-hidden", "true");
clearAuthInputs();
}
function openSettingsModal() {
if (!settingsModal) return;
settingsModal.classList.add("show");
settingsModal.setAttribute("aria-hidden", "false");
triggerLauncherAction("open_settings");
}
function closeSettingsModal() {
if (!settingsModal) return;
settingsModal.classList.remove("show");
settingsModal.setAttribute("aria-hidden", "true");
}
function clearAuthInputs() {
[
"loginEmailModal",
"loginPasswordModal",
"signupEmailModal",
"signupPasswordModal",
"signupConfirmModal"
].forEach((id) => {
const input = document.getElementById(id);
if (input) input.value = "";
});
}
function showLoginFormModal() {
const loginForm = document.getElementById("loginFormModal");
const signupForm = document.getElementById("signupFormModal");
if (loginForm) loginForm.style.display = "flex";
if (signupForm) signupForm.style.display = "none";
}
function showSignupFormModal() {
const loginForm = document.getElementById("loginFormModal");
const signupForm = document.getElementById("signupFormModal");
if (loginForm) loginForm.style.display = "none";
if (signupForm) signupForm.style.display = "flex";
}
function signup(email, password, confirm) {
const normalisedEmail = email.trim().toLowerCase();
if (!normalisedEmail || !password || !confirm) {
showToast("All account fields are required", true);
return false;
}
if (!isValidEmail(normalisedEmail)) {
showToast("Enter a valid email address", true);
return false;
}
if (password.length < 6) {
showToast("Password must be at least 6 characters", true);
return false;
}
if (password !== confirm) {
showToast("Passwords do not match", true);
return false;
}
if (users.some((user) => user.email === normalisedEmail)) {
showToast("An account with this email already exists", true);
return false;
}
users.push({ email: normalisedEmail, password: hashPassword(password) });
showToast("Account created. Login to continue");
triggerLauncherAction("account_created", { email: normalisedEmail });
return true;
}
function login(email, password, remember = true) {
const normalisedEmail = email.trim().toLowerCase();
if (!normalisedEmail || !password) {
showToast("Enter email and password", true);
return false;
}
if (!isValidEmail(normalisedEmail)) {
showToast("Enter a valid email address", true);
return false;
}
const hashedInput = hashPassword(password);
const matched = users.some((user) => user.email === normalisedEmail && user.password === hashedInput);
if (!matched) {
showToast("Invalid account details", true);
return false;
}
currentUser = { email: normalisedEmail };
updateHeaderUI();
updateReadyState();
closeAuthModal();
showToast(`Welcome, ${normalisedEmail.split("@")[0]}`);
triggerLauncherAction("login", { email: normalisedEmail });
// Securely store credentials via OS-encrypted safeStorage so the next
// launch can auto-login with REAL validation (not just trust an email).
// Pass remember=null from auto-login to skip the persist side-effect.
if (remember === true) {
try { window.vgf_functions.saveCredentials(normalisedEmail, password); } catch (_) {}
} else if (remember === false) {
try { window.vgf_functions.clearCredentials(); } catch (_) {}
}
// remember === null/undefined → don't touch credential storage
return true;
}
function logout() {
currentUser = null;
selectedServer = null;
updateHeaderUI();
clearServerSelection();
updateReadyState();
showToast("Signed out");
triggerLauncherAction("logout");
try { window.vgf_functions.clearCredentials(); } catch (_) {}
}
function updateHeaderUI() {
const userNameDisplay = document.getElementById("userNameDisplay");
const userAccessText = document.getElementById("userAccessText");
if (currentUser) {
const displayName = currentUser.email.split("@")[0];
if (userNameDisplay) userNameDisplay.textContent = displayName;
if (userAccessText) userAccessText.textContent = "Account connected";
if (loginHeaderBtn) loginHeaderBtn.style.display = "none";
if (logoutHeaderBtn) logoutHeaderBtn.style.display = "inline-flex";
} else {
if (userNameDisplay) userNameDisplay.textContent = "Not signed in";
if (userAccessText) userAccessText.textContent = "Login required to launch";
if (loginHeaderBtn) loginHeaderBtn.style.display = "inline-flex";
if (logoutHeaderBtn) logoutHeaderBtn.style.display = "none";
}
}
function setupNavigation() {
const navButtons = document.querySelectorAll(".nav-item");
const panels = document.querySelectorAll(".section-panel");
navButtons.forEach((button) => {
button.addEventListener("click", () => {
const section = button.dataset.section;
navButtons.forEach((item) => item.classList.remove("active"));
button.classList.add("active");
panels.forEach((panel) => panel.classList.remove("active"));
const activePanel = document.getElementById(`section-${section}`);
if (activePanel) activePanel.classList.add("active");
});
});
}
function setupServerCards() {
const serverCards = document.querySelectorAll(".server-card");
serverCards.forEach((card) => {
card.addEventListener("click", () => {
if (card.dataset.serverId === "testing" && !currentUser) {
showToast("Login required for restricted realms", true);
openAuthModal();
return;
}
serverCards.forEach((serverCard) => serverCard.classList.remove("selected"));
card.classList.add("selected");
selectedServer = {
id: card.dataset.serverId,
name: card.dataset.serverName
};
const selectedRealmTitle = document.getElementById("selectedRealmTitle");
const selectedServerInfo = document.getElementById("selectedServerInfo");
if (selectedRealmTitle) selectedRealmTitle.textContent = selectedServer.name;
if (selectedServerInfo) selectedServerInfo.textContent = selectedServer.name;
updateReadyState();
showToast(`Realm selected: ${selectedServer.name}`);
triggerLauncherAction("select_realm", selectedServer);
});
});
}
function clearServerSelection() {
document.querySelectorAll(".server-card").forEach((card) => card.classList.remove("selected"));
const selectedRealmTitle = document.getElementById("selectedRealmTitle");
const selectedServerInfo = document.getElementById("selectedServerInfo");
if (selectedRealmTitle) selectedRealmTitle.textContent = "No realm selected";
if (selectedServerInfo) selectedServerInfo.textContent = "No server selected";
}
function updateReadyState() {
const joinBtn = document.getElementById("joinGameBtn");
const readyTitle = document.getElementById("readyStateTitle");
const readyDescription = document.getElementById("readyStateDescription");
const ready = Boolean(currentUser && selectedServer && downloadProgress >= 100);
if (joinBtn) {
joinBtn.disabled = !ready;
joinBtn.classList.toggle("enabled", ready);
}
if (!currentUser) {
if (readyTitle) readyTitle.textContent = "Login required";
if (readyDescription) readyDescription.textContent = "Sign into your Vengeful Realms account before launching.";
return;
}
if (!selectedServer) {
if (readyTitle) readyTitle.textContent = "Choose a realm";
if (readyDescription) readyDescription.textContent = "Select a server from the realms screen before launching.";
return;
}
if (downloadProgress < 100) {
if (readyTitle) readyTitle.textContent = "Updating files";
if (readyDescription) readyDescription.textContent = "Wait for the mod pack update to finish before launching.";
return;
}
if (readyTitle) readyTitle.textContent = "Ready to launch";
if (readyDescription) readyDescription.textContent = `Prepared for ${selectedServer.name}.`;
}
function onJoinGame() {
if (!currentUser) {
showToast("Login before launching", true);
openAuthModal();
return;
}
if (!selectedServer) {
showToast("Select a realm before launching", true);
setActiveSection("realms");
return;
}
if (downloadProgress < 100) {
showToast("Update in progress", true);
setActiveSection("mods");
return;
}
showLaunchDialog();
}
function setActiveSection(section) {
const navButton = document.querySelector(`.nav-item[data-section="${section}"]`);
if (navButton) navButton.click();
}
function setDownloadProgress(percent, label = "Updating mod pack") {
const value = Math.max(0, Math.min(100, Number(percent) || 0));
downloadProgress = value;
const fill = document.getElementById("downloadProgressFill");
const percentText = document.getElementById("downloadPercentText");
const stateLabel = document.getElementById("downloadStateLabel");
const modpackStatusText = document.getElementById("modpackStatusText");
if (fill) fill.style.width = `${value}%`;
if (percentText) percentText.textContent = `${Math.round(value)}%`;
if (stateLabel) stateLabel.textContent = value >= 100 ? "Files verified and ready" : label;
if (modpackStatusText) modpackStatusText.textContent = value >= 100 ? "Mod Pack Current" : "Update Required";
updateReadyState();
}
function simulateUpdate() {
if (updateInterval) clearInterval(updateInterval);
setActiveSection("mods");
setDownloadProgress(0, "Checking manifest");
showToast("Checking for updates");
triggerLauncherAction("check_updates");
let progress = 0;
updateInterval = setInterval(() => {
progress += Math.floor(Math.random() * 9) + 6;
if (progress >= 100) {
progress = 100;
clearInterval(updateInterval);
updateInterval = null;
setDownloadProgress(progress, "Files verified and ready");
showToast("Launcher files are current");
triggerLauncherAction("update_complete");
return;
}
const label = progress < 35 ? "Checking manifest" : progress < 75 ? "Updating collection" : "Verifying files";
setDownloadProgress(progress, label);
}, 260);
}
function setupButtons() {
const loginBtnModal = document.getElementById("loginBtnModal");
const signupBtnModal = document.getElementById("signupBtnModal");
const showSignupBtnModal = document.getElementById("showSignupBtnModal");
const showLoginBtnModal = document.getElementById("showLoginBtnModal");
const closeAuthModalBtn = document.getElementById("closeAuthModalBtn");
const closeSettingsModalBtn = document.getElementById("closeSettingsModalBtn");
const joinBtn = document.getElementById("joinGameBtn");
const checkUpdatesBtn = document.getElementById("checkUpdatesBtn");
const repairBtn = document.getElementById("repairBtn");
const openFolderBtn = document.getElementById("openFolderBtn");
const saveSettingsBtn = document.getElementById("saveSettingsBtn");
const resetSettingsBtn = document.getElementById("resetSettingsBtn");
if (loginHeaderBtn) loginHeaderBtn.addEventListener("click", openAuthModal);
if (logoutHeaderBtn) logoutHeaderBtn.addEventListener("click", logout);
if (settingsBtn) settingsBtn.addEventListener("click", openSettingsModal);
if (closeAuthModalBtn) closeAuthModalBtn.addEventListener("click", closeAuthModal);
if (closeSettingsModalBtn) closeSettingsModalBtn.addEventListener("click", closeSettingsModal);
if (showSignupBtnModal) showSignupBtnModal.addEventListener("click", showSignupFormModal);
if (showLoginBtnModal) showLoginBtnModal.addEventListener("click", showLoginFormModal);
if (joinBtn) joinBtn.addEventListener("click", onJoinGame);
if (checkUpdatesBtn) checkUpdatesBtn.addEventListener("click", simulateUpdate);
if (repairBtn) {
repairBtn.addEventListener("click", () => {
showToast("Verifying files");
triggerLauncherAction("verify_files");
simulateUpdate();
});
}
if (openFolderBtn) {
openFolderBtn.addEventListener("click", () => {
showToast("Folder action sent to backend");
triggerLauncherAction("open_folder");
});
}
const uninstallBtn = document.getElementById("uninstallBtn");
if (uninstallBtn) {
uninstallBtn.addEventListener("click", async () => {
if (!launcherSettings?.gameDir) {
showToast('Game directory not set.', true);
return;
}
const confirmed = confirm(
'This will remove every file the launcher installed into your Skyrim folder, ' +
'restoring it to its pre-launcher state. Your vanilla game and any other mods ' +
'are NOT touched.\n\nContinue?'
);
if (!confirmed) return;
showToast('Removing VGR files…');
const result = await window.vgf_functions.uninstallSkymp(launcherSettings.gameDir);
if (result.success) {
const msg = `Uninstalled — ${result.removed} item(s) removed` +
(result.missing ? `, ${result.missing} already absent` : '');
showToast(msg);
} else {
// Loud, blocking dialog instead of an easy-to-miss toast.
// Lists exactly what couldn't be removed so the user can act.
const failed = (result.errors || []);
const shownFailures = failed.slice(0, 8).map(e => `• ${e}`).join('\n');
const moreCount = Math.max(0, failed.length - 8);
const summary =
`Uninstall partially failed.\n\n` +
`Removed: ${result.removed || 0} item(s)\n` +
`Could NOT remove: ${failed.length} item(s)\n\n` +
`Cause is usually a Windows file lock (the launcher itself, an open ` +
`Explorer window into your Skyrim folder, or antivirus scanning a file).\n\n` +
`What didn't get removed:\n${shownFailures}` +
(moreCount > 0 ? `\n... and ${moreCount} more` : '') +
`\n\nFix: close the launcher and any Explorer windows showing your ` +
`Skyrim folder, then click "Uninstall VGR Files" again. ` +
`Or delete the listed paths manually.`;
alert(summary);
// Also keep a toast so it doesn't get fully lost if they dismiss the alert too quickly
showToast(`Uninstall partial — ${failed.length} item(s) could not be removed`, true);
}
});
}
if (saveSettingsBtn) {
saveSettingsBtn.addEventListener("click", () => {
const gameDir = document.getElementById("gamePathInput")?.value?.trim() || "";
if (launcherSettings) launcherSettings.gameDir = gameDir;
window.vgf_functions.saveSettings(
gameDir,
launcherSettings?.profileID || 1,
launcherSettings?.serverIP || '141.195.99.135'
);
showToast("Settings saved");
closeSettingsModal();
});
}
const browseBtn = document.getElementById("browseFolderBtn");
if (browseBtn) {
browseBtn.addEventListener("click", async () => {
const chosen = await window.vgf_functions.browseFolder();
if (chosen) {
const gamePathInput = document.getElementById("gamePathInput");
if (gamePathInput) gamePathInput.value = chosen;
}
});
}
if (resetSettingsBtn) {
resetSettingsBtn.addEventListener("click", () => {
const launchArgsInput = document.getElementById("launchArgsInput");
if (launchArgsInput) launchArgsInput.value = "-vrp -noborder";
showToast("Settings reset");
});
}
if (loginBtnModal) {
loginBtnModal.addEventListener("click", () => {
login(
document.getElementById("loginEmailModal")?.value || "",
document.getElementById("loginPasswordModal")?.value || "",
document.getElementById("rememberMeModal")?.checked ?? true
);
});
}
if (signupBtnModal) {
signupBtnModal.addEventListener("click", () => {
const created = signup(
document.getElementById("signupEmailModal")?.value || "",
document.getElementById("signupPasswordModal")?.value || "",
document.getElementById("signupConfirmModal")?.value || ""
);
if (created) {
clearAuthInputs();
showLoginFormModal();
}
});
}
[authModal, settingsModal].forEach((modal) => {
if (!modal) return;
modal.addEventListener("click", (event) => {
if (event.target === modal) {
modal === authModal ? closeAuthModal() : closeSettingsModal();
}
});
});
document.addEventListener("keydown", (event) => {
if (event.key === "Escape") {
closeAuthModal();
closeSettingsModal();
}
if (event.key === "Enter" && authModal?.classList.contains("show")) {
const signupVisible = document.getElementById("signupFormModal")?.style.display !== "none";
if (signupVisible) {
signupBtnModal?.click();
} else {
loginBtnModal?.click();
}
}
});
}
function initLauncher() {
setupNavigation();
setupServerCards();
setupButtons();
updateHeaderUI();
setDownloadProgress(100, "Files verified and ready");
updateReadyState();
loadLauncherSettings();
setTimeout(() => {
if (!currentUser) showToast("Sign in with your Vengeful Realms beta credentials");
}, 700);
}
// Hide launcher shell until wizard completes, then run wizard
document.getElementById('launcherShell').style.display = 'none';
runWizard().then(() => initLauncher());
window.VengefulLauncher = {
setDownloadProgress,
setActiveSection,
selectServer(serverId) {
const card = document.querySelector(`.server-card[data-server-id="${serverId}"]`);
if (card) card.click();
},
setUser(email) {
currentUser = email ? { email } : null;
updateHeaderUI();
updateReadyState();
},
triggerLauncherAction
};
let promptResolve = null;
function showPrompt(message, defaultValue = '') {
return new Promise((resolve) => {
promptResolve = resolve;
document.getElementById('promptTitle').innerText = message;
document.getElementById('promptInput').value = defaultValue;
document.getElementById('promptModal').style.display = 'block';
document.getElementById('promptOverlay').style.display = 'block';
document.getElementById('promptInput').focus();
});
}
function resolvePrompt() {
const value = document.getElementById('promptInput').value;
document.getElementById('promptModal').style.display = 'none';
document.getElementById('promptOverlay').style.display = 'none';
if (promptResolve) promptResolve(value);
}
function rejectPrompt() {
document.getElementById('promptModal').style.display = 'none';
document.getElementById('promptOverlay').style.display = 'none';
if (promptResolve) promptResolve(null);
}
// ── Setup Wizard ──────────────────────────────────────────────────────────────
function openExternal(url) {
// Electron opens links via shell — wired through preload if needed, safe default
window.open(url);
}
async function runWizard() {
const backdrop = document.getElementById('wizardBackdrop');
const continueBtn = document.getElementById('wizContinueBtn');
const noteEl = document.getElementById('wizardNote');
const pathBtn = document.getElementById('wizBrowseBtn');
const pathLabel = document.getElementById('wizGamePath');
// Load or detect game directory
let settings = await window.vgf_functions.loadSettings();
let gameDir = settings?.gameDir || '';
if (!gameDir) {
gameDir = await window.vgf_functions.findSkyrim() || '';
// Save detected path immediately so it persists
if (gameDir) {
settings = settings || { profileID: 1, serverIP: '141.195.99.135' };
settings.gameDir = gameDir;
window.vgf_functions.saveFullSettings(settings);
}
}
pathLabel.textContent = gameDir || 'Not found — click to browse';
// Skip wizard if already verified and all prerequisites still valid
if (settings?.wizardComplete && gameDir) {
const checks = await window.vgf_functions.checkPrerequisites(gameDir);
if (checks.skyrim.ok && checks.skse.ok && checks.skymp.ok) {
backdrop.classList.add('hidden');
document.getElementById('launcherShell').style.display = '';
return;
}
// Something changed — fall through to show wizard again
}
async function runChecks() {
if (!gameDir) {
setRow('skyrim', false, 'Not found — click Browse below');
setRow('skse', false, 'Skyrim path required first');
setRow('skymp', false, 'Skyrim path required first');
continueBtn.disabled = true;
return;
}
const checks = await window.vgf_functions.checkPrerequisites(gameDir);
// Skyrim
setRow('skyrim', checks.skyrim.ok,
checks.skyrim.ok ? `Detected — ${gameDir}` : 'SkyrimSE.exe not found in selected folder');
// SKSE64
const skseText = checks.skse.ok
? `Detected — version ${checks.skse.version} (build 2.2.6)`
: 'Not found — download and place 3 files in your Skyrim folder';
setRow('skse', checks.skse.ok, skseText);
document.getElementById('wiz-skse-link').style.display = checks.skse.ok ? 'none' : 'inline-block';
// SkyMP
setRow('skymp', checks.skymp.ok,
checks.skymp.ok ? 'VengefulRealms files detected' : 'Will be installed automatically on first launch');
// Note if SKSE missing
if (!checks.skse.ok) {
noteEl.style.display = 'block';
noteEl.textContent = 'SKSE64 is required. Download it from skse.silverlock.org, then extract skse64_loader.exe, skse64_1_6_1170.dll, and skse64_steam_loader.dll into your Skyrim Special Edition folder.';
} else {
noteEl.style.display = 'none';
}
const canContinue = checks.skyrim.ok && checks.skse.ok;
continueBtn.disabled = !canContinue;
}
function setRow(key, ok, text) {
const row = document.getElementById(`wiz-${key}`);
const icon = document.getElementById(`wiz-${key}-icon`);
const span = document.getElementById(`wiz-${key}-text`);
row.className = `wizard-row ${ok ? 'ok' : 'error'}`;
icon.textContent = ok ? '✅' : '❌';
span.textContent = text;
}
// Browse button
pathBtn.addEventListener('click', async () => {
const chosen = await window.vgf_functions.browseFolder();
if (chosen) {
gameDir = chosen;
pathLabel.textContent = gameDir;
await runChecks();
}
});
// Continue button
continueBtn.addEventListener('click', () => {
if (settings) {
settings.gameDir = gameDir;
settings.wizardComplete = true;
} else {
settings = { gameDir, profileID: 1, serverIP: '141.195.99.135', wizardComplete: true };
}
window.vgf_functions.saveSettings(settings.gameDir, settings.profileID, settings.serverIP);
// Save wizardComplete flag separately since saveSettings only takes 3 args
window.vgf_functions.saveFullSettings(settings);
backdrop.classList.add('hidden');
document.getElementById('launcherShell').style.display = '';
});
await runChecks();
}
// ── Launcher state ────────────────────────────────────────────────────────────
let launcherSettings = null;
async function loadLauncherSettings() {
launcherSettings = await window.vgf_functions.loadSettings();
if (!launcherSettings) {
// First run: try to auto-detect Skyrim
const found = await window.vgf_functions.findSkyrim();
launcherSettings = {
gameDir: found || '',
profileID: 1,
serverIP: '141.195.99.135'
};
}
const gamePathInput = document.getElementById('gamePathInput');
if (gamePathInput && launcherSettings.gameDir) {
gamePathInput.value = launcherSettings.gameDir;
}
if (launcherSettings.gameDir) {
const clientStatusText = document.getElementById('clientStatusText');
if (clientStatusText) clientStatusText.textContent = 'Skyrim SE detected';
} else {
const clientStatusText = document.getElementById('clientStatusText');
if (clientStatusText) clientStatusText.textContent = 'Skyrim not found — open Settings';
showToast('Skyrim not found. Open Settings to set the path.', true);
}
// Auto-login: try the OS-encrypted credential blob first (real validation),
// then fall back to the old email-only behavior for older settings files.
if (!currentUser) {
try {
const creds = await window.vgf_functions.loadCredentials();
if (creds && creds.ok && creds.email && creds.password) {
// Re-run normal login() so the credential is actually validated
// (matches an entry in the users array). `null` = don't touch storage.
login(creds.email, creds.password, null);
} else if (launcherSettings.rememberedEmail) {
// Legacy fallback: pre-credential settings only had the email.
currentUser = { email: launcherSettings.rememberedEmail };
updateHeaderUI();
updateReadyState();
showToast(`Welcome back, ${launcherSettings.rememberedEmail.split("@")[0]}`);
}
} catch (_) { /* swallow — leave as not-signed-in */ }
}
}
async function showLaunchDialog() {
if (!launcherSettings) {
launcherSettings = await window.vgf_functions.loadSettings();
}
if (!launcherSettings?.gameDir) {
showToast('Set your Skyrim directory in Settings first.', true);
openSettingsModal();
return;
}
const profileID = await showPrompt('Enter your Profile ID (any unique number):', String(launcherSettings.profileID || ''));
if (!profileID) return;
const idNum = parseInt(profileID, 10);
if (isNaN(idNum) || idNum <= 0) {
showToast('Profile ID must be a positive whole number.', true);
return;
}
// Save updated settings
launcherSettings.profileID = idNum;
window.vgf_functions.saveSettings(launcherSettings.gameDir, idNum, launcherSettings.serverIP);
// Install SkyMP files into Skyrim folder if needed
showToast('Installing SkyMP files…');
const skymp = await window.vgf_functions.installSkymp(launcherSettings.gameDir);
if (!skymp.success) {
showToast('SkyMP install failed: ' + (skymp.error || 'unknown error'), true);
return;
}
// Write skymp5-client-settings.txt and clean conflicting files
showToast('Preparing game files…');
const result = await window.vgf_functions.updateClientCfg(launcherSettings.gameDir, idNum, launcherSettings.serverIP);
if (!result.success) {
showToast(result.error || 'Setup failed.', true);
return;
}
const exePath = launcherSettings.gameDir.replace(/\\/g, '/') + '/skse64_loader.exe';
showToast(`Launching — profile ${idNum}`);
const launch = await window.vgf_functions.launchGame(exePath.replace(/\//g, '\\'));
if (!launch.success) {
showToast('Launch failed: ' + (launch.error || 'unknown error'), true);
}
}