-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
215 lines (166 loc) · 5.96 KB
/
index.js
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
// Minecraft Imports
const { Client, Authenticator } = require('minecraft-launcher-core');
const launcher = new Client();
//Import the auth class
const { auth } = require("msmc");
// Electron Implementation
const { shell } = require('electron');
const links = document.querySelectorAll('a');
links.forEach(link => {
link.addEventListener('click', (event) => {
event.preventDefault();
const href = link.getAttribute('href');
if (href.startsWith('http://') || href.startsWith('https://')) {
shell.openExternal(href);
}
});
});
// Login Button
var loginBtn = document.getElementById("loginBtn");
var crackedBtn = document.getElementById("crackedBtn");
var loginOption = document.getElementById("loginOption");
var crackedOption = document.getElementById("crackedOption");
loginBtn.addEventListener("click", function () {
// Hide cracked option and show login option
loginOption.style.display = "block";
crackedOption.style.display = "none";
});
crackedBtn.addEventListener("click", function () {
// Hide login option and show cracked option
crackedOption.style.display = "block";
loginOption.style.display = "none";
});
// Get DOM elements
const playBtn = document.getElementById('play-btn');
const progressBar = document.getElementById('progressBar');
const status = document.getElementById('status');
// Get DOM Elements Login Option Cracked Player.
const usernameInput = document.getElementById("username");
// Get DOM Elements Game Options
const versionSelect = document.getElementById("version");
const rammin = document.getElementById("ram_min");
const rammax = document.getElementById("ram_max");
const directorySelect = document.getElementById("directory");
// Add event listener
playBtn.addEventListener('click', () => {
//playBtn.disabled = true;
//progressBar.value = 0;
//status.innerText = 'Starting...';
const defaultDirectory = "C:/Minecraft-Node-V1/.minecraft"; // Defaul Directory
const directory = directorySelect.value || defaultDirectory; // use Custom Directory or Default Directory
// Default Verions
const defaultVersions = [
'1.8.9',
'1.12.2',
'1.16.5',
'1.17', '1.17.1',
'1.18', '1.18.1', '1.18.2',
'1.19', '1.19.1', '1.19.2', '1.19.3', '1.19.4'
];
// Snapshot Versions
const snapshotVersions = [
'1.20-pre5'
];
// Version Selected
const selectedVersion = versionSelect.value;
// Version opts
//type: defaultVersions.includes(selectedVersion) ? "release" : "custom"
let versionOpts = {
number: selectedVersion,
type: defaultVersions.includes(selectedVersion) ? "release" : snapshotVersions.includes(selectedVersion) ? "snapshot" : "unknown"
};
const defaultRAMMin = "1G";
const defaultRAMMax = "3G";
const ramMin = rammin.value || defaultRAMMin;
const ramMax = rammax.value || defaultRAMMax;
let memoryOpts = {
max: ramMax,
min: ramMin
};
// Check if the cracked option is selected
if (crackedOption.style.display == "block") {
// Cracked option is selected
const username = usernameInput.value;
if (username == null || username == "") {
alert("Please enter a username");
return;
}
launchGameCracked(username, versionOpts, memoryOpts, directory);
}
// Check if the login option is selected
if (loginOption.style.display == "block") {
// Login option is selected
const token = loginMicrosoft()
if (token == null) {
alert("Please login with your Microsoft Account");
return;
} else {
launchGamePremium(token, versionOpts, memoryOpts, directory);
}
}
});
// Launch the game
async function launchGamePremium(token, versionOpts, memoryOpts, directory) {
console.log("Starting!");
launcher.launch({
authorization: token.mclc(),
root: directory,
version: versionOpts,
memory: memoryOpts,
});
launcher.on('debug', (e) => console.log(e));
launcher.on('data', (e) => console.log(e));
/*launcher.on('progress', (e) => {
progressBar.value = e;
status.innerText = `Downloading ${e}%`;
});*/
}
async function launchGameCracked(username, versionOpts, memoryOpts, directory) {
console.log("Starting!");
launcher.launch({
authorization: Authenticator.getAuth(username),
root: directory,
version: versionOpts,
memory: memoryOpts,
});
launcher.on('debug', (e) => console.log(e));
launcher.on('data', (e) => console.log(e));
/*launcher.on('progress', (e) => {
progressBar.value = e;
status.innerText = `Downloading ${e}%`;
});*/
}
// Login with Microsoft Account
async function loginMicrosoft() {
try {
console.log('Calling loginMicrosoft function');
const authManager = new auth("select_account");
console.log('authManager:', authManager);
console.log('XboxManager is launching...');
const xboxManager = await authManager.launch("raw");
console.log('xboxManager:', xboxManager);
const token = await xboxManager.getMinecraft();
console.log('token:', token);
if (token === null || token === "") {
alert("Please login with your Microsoft Account");
return null;
}
if (token === "Error") {
alert("Error logging in with your Microsoft Account");
return null;
}
return token;
} catch (error) {
console.error('Error in loginMicrosoft function:', error);
}
}
/*async function loginMicrosoft() {
//try {
const authManager = new auth("select_account");
const xboxManager = await authManager.launch("electron")
const token = await xboxManager.getMinecraft();
return token.mclc();
//} catch (error) {
// console.error(error);
//}
}*/