diff --git a/package-lock.json b/package-lock.json index aff1930..df5c938 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "BattlyLauncher", - "version": "2.0.3", + "version": "2.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "BattlyLauncher", - "version": "2.0.3", + "version": "2.2.0", "license": "CC0", "dependencies": { "@distube/ytdl-core": "^4.14.4", @@ -34,7 +34,7 @@ }, "devDependencies": { "cross-env": "^7.0.3", - "electron": "^31.3.1", + "electron": "^32.1.2", "electron-builder": "^24.13.3", "nodemon": "^3.1.4" }, @@ -1947,9 +1947,9 @@ } }, "node_modules/electron": { - "version": "31.3.1", - "resolved": "https://registry.npmjs.org/electron/-/electron-31.3.1.tgz", - "integrity": "sha512-9fiuWlRhBfygtcT+auRd/WdBK/f8LZZcrpx0RjpXhH2DPTP/PfnkC4JB1PW55qCbGbh4wAgkYbf4ExIag8oGCA==", + "version": "32.1.2", + "resolved": "https://registry.npmjs.org/electron/-/electron-32.1.2.tgz", + "integrity": "sha512-CXe6doFzhmh1U7daOvUzmF6Cj8hssdYWMeEPRnRO6rB9/bbwMlWctcQ7P8NJXhLQ88/vYUJQrJvlJPh8qM0BRQ==", "dev": true, "hasInstallScript": true, "dependencies": { diff --git a/package.json b/package.json index 619bb75..deb3ae9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "BattlyLauncher", "productname": "Battly Launcher", - "version": "2.1.0", + "version": "2.2.0", "buildVersion": "1003", "description": "El mejor Launcher Personalizado para Minecraft Premium y No premium", "main": "src/app.js", @@ -50,7 +50,7 @@ }, "devDependencies": { "cross-env": "^7.0.3", - "electron": "^31.3.1", + "electron": "^32.1.2", "electron-builder": "^24.13.3", "nodemon": "^3.1.4" }, diff --git a/src/app.js b/src/app.js index a2d0083..7ae1caa 100644 --- a/src/app.js +++ b/src/app.js @@ -16,6 +16,7 @@ const { autoUpdater } = require("electron-updater"); const { io } = require("socket.io-client"); const socket = io("https://api.battlylauncher.com"); //process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0"; +const fetch = require("node-fetch"); const fs = require("fs"); const path = require("path"); const dataDirectory = @@ -623,7 +624,7 @@ ipcMain.handle("update-app", () => { const pkgVersion = async () => { const pkg = { - version: "2.1.0", + version: "2.2.0", buildVersion: 1004 }; return pkg; diff --git a/src/assets/js/index.js b/src/assets/js/index.js index aef2c95..e05133b 100644 --- a/src/assets/js/index.js +++ b/src/assets/js/index.js @@ -59,7 +59,7 @@ class Splash { "ar": "مرحبا!", } - this.message.innerHTML = strings[localStorage.getItem("lang")]; + this.message.innerHTML = strings[localStorage.getItem("lang") ? localStorage.getItem("lang") : "en"]; let sonidoDB = localStorage.getItem("sonido-inicio") ? localStorage.getItem("sonido-inicio") : "start"; let sonido_inicio = new Audio('./assets/audios/' + sonidoDB + '.mp3'); diff --git a/src/assets/js/libs/mc-/Authenticator/AZauth.d.ts b/src/assets/js/libs/mc-/Authenticator/AZauth.d.ts deleted file mode 100644 index e4657f1..0000000 --- a/src/assets/js/libs/mc-/Authenticator/AZauth.d.ts +++ /dev/null @@ -1,83 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class AZauth { - url: string; - constructor(url: string); - login(username: string, password: string, A2F?: any): Promise<{ - A2F: boolean; - error?: undefined; - reason?: undefined; - message?: undefined; - access_token?: undefined; - client_token?: undefined; - uuid?: undefined; - name?: undefined; - user_properties?: undefined; - user_info?: undefined; - meta?: undefined; - } | { - error: boolean; - reason: any; - message: any; - A2F?: undefined; - access_token?: undefined; - client_token?: undefined; - uuid?: undefined; - name?: undefined; - user_properties?: undefined; - user_info?: undefined; - meta?: undefined; - } | { - access_token: any; - client_token: any; - uuid: any; - name: any; - user_properties: string; - user_info: { - banned: any; - money: any; - role: any; - }; - meta: { - online: boolean; - type: string; - }; - A2F?: undefined; - error?: undefined; - reason?: undefined; - message?: undefined; - }>; - verify(user: any): Promise<{ - error: boolean; - reason: any; - message: any; - access_token?: undefined; - client_token?: undefined; - uuid?: undefined; - name?: undefined; - user_properties?: undefined; - user_info?: undefined; - meta?: undefined; - } | { - access_token: any; - client_token: any; - uuid: any; - name: any; - user_properties: string; - user_info: { - banned: any; - money: any; - role: any; - }; - meta: { - online: boolean; - type: string; - }; - error?: undefined; - reason?: undefined; - message?: undefined; - }>; - signout(user: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Authenticator/AZauth.js b/src/assets/js/libs/mc-/Authenticator/AZauth.js deleted file mode 100644 index 379f9a6..0000000 --- a/src/assets/js/libs/mc-/Authenticator/AZauth.js +++ /dev/null @@ -1,101 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const node_fetch_1 = __importDefault(require("node-fetch")); -class AZauth { - constructor(url) { - this.url = `${url}/api/auth`; - } - async login(username, password, A2F = null) { - let response = await (0, node_fetch_1.default)(`${this.url}/authenticate`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - email: username, - password: password, - code: A2F - }), - }).then((res) => res.json()); - if (response.status == 'pending' && response.reason == '2fa') { - return { A2F: true }; - } - if (response.status == 'error') { - return { - error: true, - reason: response.reason, - message: response.message - }; - } - return { - access_token: response.access_token, - client_token: response.uuid, - uuid: response.uuid, - name: response.username, - user_properties: '{}', - user_info: { - banned: response.banned, - money: response.money, - role: response.role - }, - meta: { - online: false, - type: 'AZauth', - } - }; - } - async verify(user) { - let response = await (0, node_fetch_1.default)(`${this.url}/verify`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - access_token: user.access_token - }), - }).then((res) => res.json()); - if (response.status == 'error') { - return { - error: true, - reason: response.reason, - message: response.message - }; - } - return { - access_token: response.access_token, - client_token: response.uuid, - uuid: response.uuid, - name: response.username, - user_properties: '{}', - user_info: { - banned: response.banned, - money: response.money, - role: response.role - }, - meta: { - online: false, - type: 'AZauth', - } - }; - } - async signout(user) { - let auth = await (0, node_fetch_1.default)(`${this.url}/logout`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - access_token: user.access_token - }), - }).then((res) => res.json()); - if (auth.error) - return false; - return true; - } -} -exports.default = AZauth; diff --git a/src/assets/js/libs/mc-/Authenticator/GUI/Electron.d.ts b/src/assets/js/libs/mc-/Authenticator/GUI/Electron.d.ts deleted file mode 100644 index ebccf52..0000000 --- a/src/assets/js/libs/mc-/Authenticator/GUI/Electron.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -declare const path: any; -declare const app: any, BrowserWindow: any, session: any; -declare const defaultProperties: { - width: number; - height: number; - resizable: boolean; - center: boolean; - icon: any; -}; diff --git a/src/assets/js/libs/mc-/Authenticator/GUI/Electron.js b/src/assets/js/libs/mc-/Authenticator/GUI/Electron.js deleted file mode 100644 index 34a5b43..0000000 --- a/src/assets/js/libs/mc-/Authenticator/GUI/Electron.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -const path = require('path'); -const { app, BrowserWindow, session } = require('electron'); -const defaultProperties = { - width: 1000, - height: 650, - resizable: false, - center: true, - icon: path.join(__dirname, '../../../assets/icons', `Microsoft.${(process.platform === 'win32') ? 'ico' : 'png'}`), -}; -module.exports = async function (url) { - await new Promise((resolve) => { - app.whenReady().then(() => { - session.defaultSession.cookies.get({ domain: 'live.com' }).then((cookies) => { - for (let cookie of cookies) { - let urlcookie = `http${cookie.secure ? "s" : ""}://${cookie.domain.replace(/$\./, "") + cookie.path}`; - session.defaultSession.cookies.remove(urlcookie, cookie.name); - } - }); - return resolve(); - }); - }); - return new Promise(resolve => { - app.whenReady().then(() => { - const mainWindow = new BrowserWindow(defaultProperties); - mainWindow.setMenu(null); - mainWindow.loadURL(url); - var loading = false; - mainWindow.on("close", () => { - if (!loading) - resolve("cancel"); - }); - mainWindow.webContents.on("did-finish-load", () => { - const loc = mainWindow.webContents.getURL(); - if (loc.startsWith("https://login.live.com/oauth20_desktop.srf")) { - const urlParams = new URLSearchParams(loc.substr(loc.indexOf("?") + 1)).get("code"); - if (urlParams) { - resolve(urlParams); - loading = true; - } - else { - resolve("cancel"); - } - try { - mainWindow.close(); - } - catch { - console.error("Failed to close window!"); - } - } - }); - }); - }); -}; diff --git a/src/assets/js/libs/mc-/Authenticator/GUI/NW.d.ts b/src/assets/js/libs/mc-/Authenticator/GUI/NW.d.ts deleted file mode 100644 index f4dedb6..0000000 --- a/src/assets/js/libs/mc-/Authenticator/GUI/NW.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export {}; diff --git a/src/assets/js/libs/mc-/Authenticator/GUI/NW.js b/src/assets/js/libs/mc-/Authenticator/GUI/NW.js deleted file mode 100644 index ed93d45..0000000 --- a/src/assets/js/libs/mc-/Authenticator/GUI/NW.js +++ /dev/null @@ -1,58 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -'use strict'; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const path_1 = __importDefault(require("path")); -const defaultProperties = { - width: 1000, - height: 650, - resizable: false, - position: "center", - frame: true, - icon: path_1.default.join(__dirname, '../../../assets/icons/Microsoft.png') -}; -module.exports = async function (url) { - await new Promise((resolve) => { - //@ts-ignore - nw.Window.get().cookies.getAll({ domain: "live.com" }, async (cookies) => { - for await (let cookie of cookies) { - let url = `http${cookie.secure ? "s" : ""}://${cookie.domain.replace(/$\./, "") + cookie.path}`; - //@ts-ignore - nw.Window.get().cookies.remove({ url: url, name: cookie.name }); - } - return resolve(); - }); - }); - let code = await new Promise((resolve) => { - //@ts-ignore - nw.Window.open(url, defaultProperties, (Window) => { - let interval = null; - let code; - interval = setInterval(() => { - if (Window.window.document.location.href.startsWith("https://login.live.com/oauth20_desktop.srf")) { - clearInterval(interval); - try { - code = Window.window.document.location.href.split("code=")[1].split("&")[0]; - } - catch (e) { - code = "cancel"; - } - Window.close(); - } - }, 100); - Window.on('closed', () => { - if (!code) - code = "cancel"; - if (interval) - clearInterval(interval); - resolve(code); - }); - }); - }); - return code; -}; diff --git a/src/assets/js/libs/mc-/Authenticator/GUI/Terminal.d.ts b/src/assets/js/libs/mc-/Authenticator/GUI/Terminal.d.ts deleted file mode 100644 index f4dedb6..0000000 --- a/src/assets/js/libs/mc-/Authenticator/GUI/Terminal.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export {}; diff --git a/src/assets/js/libs/mc-/Authenticator/GUI/Terminal.js b/src/assets/js/libs/mc-/Authenticator/GUI/Terminal.js deleted file mode 100644 index 068a708..0000000 --- a/src/assets/js/libs/mc-/Authenticator/GUI/Terminal.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const prompt_1 = __importDefault(require("prompt")); -module.exports = async function (url) { - console.log(`Open brosser ${url}`); - prompt_1.default.start(); - let result = await prompt_1.default.get(['copy-URL']); - return result['copy-URL'].split("code=")[1].split("&")[0]; -}; diff --git a/src/assets/js/libs/mc-/Authenticator/Microsoft.d.ts b/src/assets/js/libs/mc-/Authenticator/Microsoft.d.ts deleted file mode 100644 index 643efa3..0000000 --- a/src/assets/js/libs/mc-/Authenticator/Microsoft.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class Microsoft { - client_id: string; - type: 'electron' | 'nwjs' | 'terminal'; - constructor(client_id: string); - getAuth(type: string, url: string): Promise; - url(code: string): Promise; - refresh(acc: any): Promise; - getAccount(oauth2: any): Promise; - getProfile(mcLogin: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Authenticator/Microsoft.js b/src/assets/js/libs/mc-/Authenticator/Microsoft.js deleted file mode 100644 index 986e129..0000000 --- a/src/assets/js/libs/mc-/Authenticator/Microsoft.js +++ /dev/null @@ -1,242 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const node_fetch_1 = __importDefault(require("node-fetch")); -const crypto_1 = __importDefault(require("crypto")); -class Microsoft { - constructor(client_id) { - if (client_id === '' || !client_id) - client_id = '00000000402b5328'; - this.client_id = client_id; - if (!!process && !!process.versions && !!process.versions.electron) { - this.type = 'electron'; - } - else if (!!process && !!process.versions && !!process.versions.nw) { - this.type = 'nwjs'; - } - else { - this.type = 'terminal'; - } - } - async getAuth(type, url) { - if (!url) - url = `https://login.live.com/oauth20_authorize.srf?client_id=${this.client_id}&response_type=code&redirect_uri=https://login.live.com/oauth20_desktop.srf&scope=XboxLive.signin%20offline_access&cobrandid=8058f65d-ce06-4c30-9559-473c9275a65d&prompt=select_account`; - if (!type) - type = this.type; - if (type == "electron") { - let usercode = await (require('./GUI/Electron.js'))(url); - if (usercode === "cancel") - return false; - else - return await this.url(usercode); - } - else if (type == "nwjs") { - let usercode = await (require('./GUI/NW.js'))(url); - if (usercode === "cancel") - return false; - else - return await this.url(usercode); - } - else if (type == "terminal") { - let usercode = await (require('./GUI/Terminal.js'))(url); - if (usercode === "cancel") - return false; - else - return await this.url(usercode); - } - } - async url(code) { - let oauth2 = await (0, node_fetch_1.default)("https://login.live.com/oauth20_token.srf", { - method: "POST", - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - }, - body: `client_id=${this.client_id}&code=${code}&grant_type=authorization_code&redirect_uri=https://login.live.com/oauth20_desktop.srf` - }).then(res => res.json()).catch(err => { return { error: err }; }); - ; - if (oauth2.error) - return oauth2; - return await this.getAccount(oauth2); - } - async refresh(acc) { - let timeStamp = Math.floor(Date.now() / 1000); - if (timeStamp < (acc?.meta?.access_token_expires_in - 7200)) { - let profile = await this.getProfile(acc); - acc.profile = { - skins: profile.skins, - capes: profile.capes - }; - return acc; - } - else { - let oauth2 = await (0, node_fetch_1.default)("https://login.live.com/oauth20_token.srf", { - method: "POST", - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - }, - body: `grant_type=refresh_token&client_id=${this.client_id}&refresh_token=${acc.refresh_token}` - }).then(res => res.json()).catch(err => { return { error: err }; }); - ; - if (oauth2.error) { - oauth2.errorType = "oauth2"; - return oauth2; - } - ; - return await this.getAccount(oauth2); - } - } - async getAccount(oauth2) { - let xbl = await (0, node_fetch_1.default)("https://user.auth.xboxlive.com/user/authenticate", { - method: "post", - body: JSON.stringify({ - Properties: { - AuthMethod: "RPS", - SiteName: "user.auth.xboxlive.com", - RpsTicket: "d=" + oauth2.access_token - }, - RelyingParty: "http://auth.xboxlive.com", - TokenType: "JWT" - }), - headers: { "Content-Type": "application/json", Accept: "application/json" }, - }).then(res => res.json()).catch(err => { return { error: err }; }); - ; - if (xbl.error) { - xbl.errorType = "xbl"; - return xbl; - } - let xsts = await (0, node_fetch_1.default)("https://xsts.auth.xboxlive.com/xsts/authorize", { - method: "POST", - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - Properties: { - SandboxId: "RETAIL", - UserTokens: [xbl.Token] - }, - RelyingParty: "rp://api.minecraftservices.com/", - TokenType: "JWT" - }) - }).then(res => res.json()); - if (xsts.error) { - xsts.errorType = "xsts"; - return xsts; - } - let xboxAccount = await (0, node_fetch_1.default)("https://xsts.auth.xboxlive.com/xsts/authorize", { - method: "POST", - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - Properties: { - SandboxId: "RETAIL", - UserTokens: [xbl.Token] - }, - RelyingParty: "http://xboxlive.com", - TokenType: "JWT" - }) - }).then(res => res.json()).catch(err => { return { error: err }; }); - if (xsts.error) { - xsts.errorType = "xboxAccount"; - return xsts; - } - let launch = await (0, node_fetch_1.default)("https://api.minecraftservices.com/launcher/login", { - method: "POST", - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ xtoken: `XBL3.0 x=${xbl.DisplayClaims.xui[0].uhs};${xsts.Token}`, platform: "PC_LAUNCHER" }) - }).then(res => res.json()).catch(err => { return { error: err }; }); - if (launch.error) { - launch.errorType = "launch"; - return launch; - } - let mcLogin = await (0, node_fetch_1.default)("https://api.minecraftservices.com/authentication/login_with_xbox", { - method: "POST", - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ "identityToken": `XBL3.0 x=${xbl.DisplayClaims.xui[0].uhs};${xsts.Token}` }) - }).then(res => res.json()).catch(err => { return { error: err }; }); - if (mcLogin.error) { - mcLogin.errorType = "mcLogin"; - return mcLogin; - } - let hasGame = await (0, node_fetch_1.default)("https://api.minecraftservices.com/entitlements/mcstore", { - method: "GET", - headers: { - 'Authorization': `Bearer ${mcLogin.access_token}` - } - }).then(res => res.json()); - if (!hasGame.items.find(i => i.name == "product_minecraft" || i.name == "game_minecraft")) { - return { - error: "You don't own the game", - errorType: "game" - }; - } - let profile = await this.getProfile(mcLogin); - if (profile.error) { - profile.errorType = "profile"; - return profile; - } - return { - access_token: mcLogin.access_token, - client_token: crypto_1.default.randomBytes(16).toString('hex'), - uuid: profile.id, - name: profile.name, - refresh_token: oauth2.refresh_token, - user_properties: '{}', - meta: { - type: "Xbox", - access_token_expires_in: mcLogin.expires_in + Math.floor(Date.now() / 1000), - demo: profile.error ? true : false - }, - xboxAccount: { - xuid: xboxAccount.DisplayClaims.xui[0].xid, - gamertag: xboxAccount.DisplayClaims.xui[0].gtg, - ageGroup: xboxAccount.DisplayClaims.xui[0].agg - }, - profile: { - skins: profile.skins, - capes: profile.capes - } - }; - } - async getProfile(mcLogin) { - let profile = await (0, node_fetch_1.default)("https://api.minecraftservices.com/minecraft/profile", { - method: "GET", - headers: { - 'Authorization': `Bearer ${mcLogin.access_token}` - } - }).then(res => res.json()).catch(err => { return { error: err }; }); - ; - if (profile.error) - return profile; - let skins = profile.skins; - let capes = profile.capes; - for (let skin of skins) { - skin.base64 = `data:image/png;base64,${await getBass64(skin.url)}`; - } - for (let cape of capes) { - cape.base64 = `data:image/png;base64,${await getBass64(cape.url)}`; - } - return { - id: profile.id, - name: profile.name, - skins: profile.skins || [], - capes: profile.capes || [] - }; - } -} -exports.default = Microsoft; -async function getBass64(url) { - let response = await (0, node_fetch_1.default)(url); - let buffer = await response.buffer(); - return buffer.toString('base64'); -} diff --git a/src/assets/js/libs/mc-/Authenticator/Mojang.d.ts b/src/assets/js/libs/mc-/Authenticator/Mojang.d.ts deleted file mode 100644 index 9b55cc5..0000000 --- a/src/assets/js/libs/mc-/Authenticator/Mojang.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -declare function login(username: string, password?: string): Promise; -declare function refresh(acc: any): Promise; -declare function validate(acc: any): Promise; -declare function signout(acc: any): Promise; -declare function ChangeAuthApi(url: string): void; -export { login as login, refresh as refresh, validate as validate, signout as signout, ChangeAuthApi as ChangeAuthApi }; diff --git a/src/assets/js/libs/mc-/Authenticator/Mojang.js b/src/assets/js/libs/mc-/Authenticator/Mojang.js deleted file mode 100644 index f3c9c12..0000000 --- a/src/assets/js/libs/mc-/Authenticator/Mojang.js +++ /dev/null @@ -1,134 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ChangeAuthApi = exports.signout = exports.validate = exports.refresh = exports.login = void 0; -const crypto_1 = __importDefault(require("crypto")); -const node_fetch_1 = __importDefault(require("node-fetch")); -let api_url = 'https://authserver.mojang.com'; -async function login(username, password) { - let UUID = crypto_1.default.randomBytes(16).toString('hex'); - if (!password) { - return { - access_token: UUID, - client_token: UUID, - uuid: UUID, - name: username, - user_properties: '{}', - meta: { - online: false, - type: 'Mojang' - } - }; - } - let message = await (0, node_fetch_1.default)(`${api_url}/authenticate`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - agent: { - name: "Minecraft", - version: 1 - }, - username, - password, - clientToken: UUID, - requestUser: true - }) - }).then(res => res.json()); - if (message.error) { - return message; - } - ; - let user = { - access_token: message.accessToken, - client_token: message.clientToken, - uuid: message.selectedProfile.id, - name: message.selectedProfile.name, - user_properties: '{}', - meta: { - online: true, - type: 'Mojang' - } - }; - return user; -} -exports.login = login; -async function refresh(acc) { - let message = await (0, node_fetch_1.default)(`${api_url}/refresh`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - accessToken: acc.access_token, - clientToken: acc.client_token, - requestUser: true - }) - }).then(res => res.json()); - if (message.error) { - return message; - } - ; - let user = { - access_token: message.accessToken, - client_token: message.clientToken, - uuid: message.selectedProfile.id, - name: message.selectedProfile.name, - user_properties: '{}', - meta: { - online: true, - type: 'Mojang' - } - }; - return user; -} -exports.refresh = refresh; -async function validate(acc) { - let message = await (0, node_fetch_1.default)(`${api_url}/validate`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - accessToken: acc.access_token, - clientToken: acc.client_token, - }) - }); - if (message.status == 204) { - return true; - } - else { - return false; - } -} -exports.validate = validate; -async function signout(acc) { - let message = await (0, node_fetch_1.default)(`${api_url}/invalidate`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - accessToken: acc.access_token, - clientToken: acc.client_token, - }) - }).then(res => res.text()); - if (message == "") { - return true; - } - else { - return false; - } -} -exports.signout = signout; -function ChangeAuthApi(url) { - api_url = url; -} -exports.ChangeAuthApi = ChangeAuthApi; diff --git a/src/assets/js/libs/mc-/Index.d.ts b/src/assets/js/libs/mc-/Index.d.ts deleted file mode 100644 index 5f97b35..0000000 --- a/src/assets/js/libs/mc-/Index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -import AZauth from './Authenticator/AZauth.js'; -import Launch from './Launch.js'; -import Microsoft from './Authenticator/Microsoft.js'; -import * as Mojang from './Authenticator/Mojang.js'; -import Status from './StatusServer/status.js'; -export { AZauth as AZauth, Launch as Launch, Microsoft as Microsoft, Mojang as Mojang, Status as Status }; diff --git a/src/assets/js/libs/mc-/Index.js b/src/assets/js/libs/mc-/Index.js deleted file mode 100644 index 309a97c..0000000 --- a/src/assets/js/libs/mc-/Index.js +++ /dev/null @@ -1,43 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.Status = exports.Mojang = exports.Microsoft = exports.Launch = exports.AZauth = void 0; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -const AZauth_js_1 = __importDefault(require("./Authenticator/AZauth.js")); -exports.AZauth = AZauth_js_1.default; -const Launch_js_1 = __importDefault(require("./Launch.js")); -exports.Launch = Launch_js_1.default; -const Microsoft_js_1 = __importDefault(require("./Authenticator/Microsoft.js")); -exports.Microsoft = Microsoft_js_1.default; -const Mojang = __importStar(require("./Authenticator/Mojang.js")); -exports.Mojang = Mojang; -const status_js_1 = __importDefault(require("./StatusServer/status.js")); -exports.Status = status_js_1.default; diff --git a/src/assets/js/libs/mc-/Launch.d.ts b/src/assets/js/libs/mc-/Launch.d.ts deleted file mode 100644 index c049269..0000000 --- a/src/assets/js/libs/mc-/Launch.d.ts +++ /dev/null @@ -1,53 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -/// -import { EventEmitter } from 'events'; -type loader = { - path?: string; - type?: string; - build?: string; - enable?: boolean; -}; -type screen = { - width?: number; - height?: number; - fullscreen?: boolean; -}; -type memory = { - min?: string; - max?: string; -}; -type javaOPTS = { - path?: string; - version?: number; - type?: string; -}; -type LaunchOPTS = { - url: string | null; - authenticator: any; - timeout?: number; - path: string; - version: string; - instance?: string; - detached?: boolean; - downloadFileMultiple?: number; - intelEnabledMac?: boolean; - loader: loader; - mcp: any; - verify: boolean; - ignored: string[]; - JVM_ARGS: string[]; - GAME_ARGS: string[]; - java: javaOPTS; - screen: screen; - memory: memory; -}; -export default class Launch extends EventEmitter { - options: LaunchOPTS; - Launch(opt: LaunchOPTS): Promise; - start(): Promise; - DownloadGame(): Promise; -} -export {}; diff --git a/src/assets/js/libs/mc-/Launch.js b/src/assets/js/libs/mc-/Launch.js deleted file mode 100644 index 2235a9a..0000000 --- a/src/assets/js/libs/mc-/Launch.js +++ /dev/null @@ -1,197 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const events_1 = require("events"); -const path_1 = __importDefault(require("path")); -const fs_1 = __importDefault(require("fs")); -const child_process_1 = require("child_process"); -const Minecraft_Json_js_1 = __importDefault(require("./Minecraft/Minecraft-Json.js")); -const Minecraft_Libraries_js_1 = __importDefault(require("./Minecraft/Minecraft-Libraries.js")); -const Minecraft_Assets_js_1 = __importDefault(require("./Minecraft/Minecraft-Assets.js")); -const Minecraft_Loader_js_1 = __importDefault(require("./Minecraft/Minecraft-Loader.js")); -const Minecraft_Java_js_1 = __importDefault(require("./Minecraft/Minecraft-Java.js")); -const Minecraft_Bundle_js_1 = __importDefault(require("./Minecraft/Minecraft-Bundle.js")); -const Minecraft_Arguments_js_1 = __importDefault(require("./Minecraft/Minecraft-Arguments.js")); -const Index_js_1 = require("./utils/Index.js"); -const Downloader_js_1 = __importDefault(require("./utils/Downloader.js")); -class Launch extends events_1.EventEmitter { - async Launch(opt) { - const defaultOptions = { - url: null, - authenticator: null, - timeout: 10000, - path: '.Minecraft', - version: 'latest_release', - instance: null, - detached: false, - intelEnabledMac: false, - downloadFileMultiple: 5, - loader: { - path: './loader', - type: null, - build: 'latest', - enable: false, - }, - mcp: null, - verify: false, - ignored: [], - JVM_ARGS: [], - GAME_ARGS: [], - java: { - path: null, - version: null, - type: 'jre', - }, - screen: { - width: null, - height: null, - fullscreen: false, - }, - memory: { - min: '1G', - max: '2G' - }, - ...opt, - }; - this.options = defaultOptions; - this.options.path = path_1.default.resolve(this.options.path).replace(/\\/g, '/'); - if (this.options.mcp) { - if (this.options.instance) - this.options.mcp = `${this.options.path}/instances/${this.options.instance}/${this.options.mcp}`; - else - this.options.mcp = path_1.default.resolve(`${this.options.path}/${this.options.mcp}`).replace(/\\/g, '/'); - } - if (this.options.loader.type) { - this.options.loader.type = this.options.loader.type.toLowerCase(); - this.options.loader.build = this.options.loader.build.toLowerCase(); - } - if (!this.options.authenticator) - return this.emit("error", { error: "Authenticator not found" }); - if (this.options.downloadFileMultiple < 1) - this.options.downloadFileMultiple = 1; - if (this.options.downloadFileMultiple > 30) - this.options.downloadFileMultiple = 30; - if (typeof this.options.loader.path !== 'string') - this.options.loader.path = `./loader/${this.options.loader.type}`; - this.start(); - } - - async start() { - let data = await this.DownloadGame(); - if (data.error) - return this.emit('error', data); - let { minecraftJson, minecraftLoader, minecraftVersion, minecraftJava } = data; - let minecraftArguments = await new Minecraft_Arguments_js_1.default(this.options).GetArguments(minecraftJson, minecraftLoader); - if (minecraftArguments.error) - return this.emit('error', minecraftArguments); - let loaderArguments = await new Minecraft_Loader_js_1.default(this.options).GetArguments(minecraftLoader, minecraftVersion); - if (loaderArguments.error) - return this.emit('error', loaderArguments); - let Arguments = [ - ...minecraftArguments.jvm, - ...minecraftArguments.classpath, - ...loaderArguments.jvm, - minecraftArguments.mainClass, - ...minecraftArguments.game, - ...loaderArguments.game - ]; - let java = this.options.java.path ? this.options.java.path : minecraftJava.path; - let logs = this.options.instance ? `${this.options.path}/instances/${this.options.instance}` : this.options.path; - if (!fs_1.default.existsSync(logs)) - fs_1.default.mkdirSync(logs, { recursive: true }); - let argumentsLogs = Arguments.join(' '); - argumentsLogs = argumentsLogs.replaceAll(this.options.authenticator.access_token, '????????'); - argumentsLogs = argumentsLogs.replaceAll(this.options.authenticator.client_token, '????????'); - argumentsLogs = argumentsLogs.replaceAll(this.options.authenticator.uuid, '????????'); - argumentsLogs = argumentsLogs.replaceAll(this.options.authenticator.xuid, '????????'); - argumentsLogs = argumentsLogs.replaceAll(`${this.options.path}/`, ''); - this.emit('data', `Launching with arguments ${argumentsLogs}`); - let minecraftDebug = (0, child_process_1.spawn)(java, Arguments, { cwd: logs, detached: this.options.detached }); - minecraftDebug.stdout.on('data', (data) => this.emit('data', data.toString('utf-8'))); - minecraftDebug.stderr.on('data', (data) => this.emit('data', data.toString('utf-8'))); - minecraftDebug.on('close', (code) => this.emit('close', 'Minecraft closed')); - } - async DownloadGame() { - let InfoVersion = await new Minecraft_Json_js_1.default(this.options).GetInfoVersion(); - let loaderJson = null; - if (InfoVersion.error) - return InfoVersion; - let { json, version } = InfoVersion; - let libraries = new Minecraft_Libraries_js_1.default(this.options); - let bundle = new Minecraft_Bundle_js_1.default(this.options); - let java = new Minecraft_Java_js_1.default(this.options); - java.on('progress', (progress, size, element) => { - this.emit('progress', progress, size, element); - }); - java.on('extract', (progress) => { - this.emit('extract', progress); - }); - let gameLibraries = await libraries.Getlibraries(json); - let gameAssetsOther = await libraries.GetAssetsOthers(this.options.url); - let gameAssets = await new Minecraft_Assets_js_1.default(this.options).GetAssets(json); - let gameJava = this.options.java.path ? { files: [] } : await java.getJavaFiles(json); - if (gameJava.error) - return gameJava; - let filesList = await bundle.checkBundle([...gameLibraries, ...gameAssetsOther, ...gameAssets, ...gameJava.files]); - if (filesList.length > 0) { - let downloader = new Downloader_js_1.default(); - let totsize = await bundle.getTotalSize(filesList); - downloader.on("progress", (DL, totDL, element) => { - this.emit("progress", DL, totDL, element); - }); - downloader.on("speed", (speed) => { - this.emit("speed", speed); - }); - downloader.on("estimated", (time) => { - this.emit("estimated", time); - }); - downloader.on("error", (e) => { - this.emit("error", e); - }); - await downloader.downloadFileMultiple(filesList, totsize, this.options.downloadFileMultiple, this.options.timeout); - } - if (this.options.loader.enable === true) { - let loaderInstall = new Minecraft_Loader_js_1.default(this.options); - loaderInstall.on('extract', (extract) => { - this.emit('extract', extract); - }); - loaderInstall.on('progress', (progress, size, element) => { - this.emit('progress', progress, size, element); - }); - loaderInstall.on('check', (progress, size, element) => { - this.emit('check', progress, size, element); - }); - loaderInstall.on('patch', (patch) => { - this.emit('patch', patch); - }); - let jsonLoader = await loaderInstall.GetLoader(version, this.options.java.path ? this.options.java.path : gameJava.path) - .then((data) => data) - .catch((err) => err); - if (jsonLoader.error) - return jsonLoader; - loaderJson = jsonLoader; - } - if (this.options.verify) - await bundle.checkFiles([...gameLibraries, ...gameAssetsOther, ...gameAssets, ...gameJava.files]); - let natives = await libraries.natives(gameLibraries); - if (natives.length === 0) - json.nativesList = false; - else - json.nativesList = true; - if ((0, Index_js_1.isold)(json)) - new Minecraft_Assets_js_1.default(this.options).copyAssets(json); - return { - minecraftJson: json, - minecraftLoader: loaderJson, - minecraftVersion: version, - minecraftJava: gameJava - }; - } -} -exports.default = Launch; diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/index.d.ts b/src/assets/js/libs/mc-/Minecraft-Loader/index.d.ts deleted file mode 100644 index e7a4644..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/index.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -/// -import { EventEmitter } from 'events'; -export default class Loader extends EventEmitter { - options: any; - constructor(options: any); - install(): Promise; - forge(Loader: any): Promise; - neoForge(Loader: any): Promise; - fabric(Loader: any): Promise; - legacyFabric(Loader: any): Promise; - quilt(Loader: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/index.js b/src/assets/js/libs/mc-/Minecraft-Loader/index.js deleted file mode 100644 index d5a944d..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/index.js +++ /dev/null @@ -1,220 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const Index_js_1 = require("../utils/Index.js"); -const forge_js_1 = __importDefault(require("./loader/forge/forge.js")); -const neoForge_js_1 = __importDefault(require("./loader/neoForge/neoForge.js")); -const fabric_js_1 = __importDefault(require("./loader/fabric/fabric.js")); -const legacyFabric_js_1 = __importDefault(require("./loader/legacyfabric/legacyFabric.js")); -const quilt_js_1 = __importDefault(require("./loader/quilt/quilt.js")); -const events_1 = require("events"); -const fs_1 = __importDefault(require("fs")); -const path_1 = __importDefault(require("path")); -class Loader extends events_1.EventEmitter { - constructor(options) { - super(); - this.options = options; - } - async install() { - let Loader = (0, Index_js_1.loader)(this.options.loader.type); - if (!Loader) - return this.emit('error', { error: `Loader ${this.options.loader.type} not found` }); - if (this.options.loader.type === 'forge') { - let forge = await this.forge(Loader); - if (forge.error) - return this.emit('error', forge); - this.emit('json', forge); - } - else if (this.options.loader.type === 'neoforge') { - let neoForge = await this.neoForge(Loader); - if (neoForge.error) - return this.emit('error', neoForge); - this.emit('json', neoForge); - } - else if (this.options.loader.type === 'fabric') { - let fabric = await this.fabric(Loader); - if (fabric.error) - return this.emit('error', fabric); - this.emit('json', fabric); - } - else if (this.options.loader.type === 'legacyfabric') { - let legacyFabric = await this.legacyFabric(Loader); - if (legacyFabric.error) - return this.emit('error', legacyFabric); - this.emit('json', legacyFabric); - } - else if (this.options.loader.type === 'quilt') { - let quilt = await this.quilt(Loader); - if (quilt.error) - return this.emit('error', quilt); - this.emit('json', quilt); - } - else { - return this.emit('error', { error: `Loader ${this.options.loader.type} not found` }); - } - } - async forge(Loader) { - let forge = new forge_js_1.default(this.options); - // set event - forge.on('check', (progress, size, element) => { - this.emit('check', progress, size, element); - }); - forge.on('progress', (progress, size, element) => { - this.emit('progress', progress, size, element); - }); - forge.on('extract', (element) => { - this.emit('extract', element); - }); - forge.on('patch', patch => { - this.emit('patch', patch); - }); - // download installer - let installer = await forge.downloadInstaller(Loader); - if (installer.error) - return installer; - if (installer.ext == 'jar') { - // extract install profile - let profile = await forge.extractProfile(installer.filePath); - if (profile.error) - return profile; - let destination = path_1.default.resolve(this.options.path, 'versions', profile.version.id); - if (!fs_1.default.existsSync(destination)) - fs_1.default.mkdirSync(destination, { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(destination, `${profile.version.id}.json`), JSON.stringify(profile.version, null, 4)); - // extract universal jar - let universal = await forge.extractUniversalJar(profile.install, installer.filePath); - if (universal.error) - return universal; - // download libraries - let libraries = await forge.downloadLibraries(profile, universal); - if (libraries.error) - return libraries; - // patch forge if nessary - let patch = await forge.patchForge(profile.install); - if (patch.error) - return patch; - return profile.version; - } - else { - let profile = await forge.createProfile(installer.id, installer.filePath); - if (profile.error) - return profile; - let destination = path_1.default.resolve(this.options.path, 'versions', profile.id); - if (!fs_1.default.existsSync(destination)) - fs_1.default.mkdirSync(destination, { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(destination, `${profile.id}.json`), JSON.stringify(profile, null, 4)); - return profile; - } - } - async neoForge(Loader) { - let neoForge = new neoForge_js_1.default(this.options); - // set event - neoForge.on('check', (progress, size, element) => { - this.emit('check', progress, size, element); - }); - neoForge.on('progress', (progress, size, element) => { - this.emit('progress', progress, size, element); - }); - neoForge.on('extract', (element) => { - this.emit('extract', element); - }); - neoForge.on('patch', patch => { - this.emit('patch', patch); - }); - // download installer - let installer = await neoForge.downloadInstaller(Loader); - if (installer.error) - return installer; - // extract install profile - let profile = await neoForge.extractProfile(installer.filePath); - if (profile.error) - return profile; - let destination = path_1.default.resolve(this.options.path, 'versions', profile.version.id); - if (!fs_1.default.existsSync(destination)) - fs_1.default.mkdirSync(destination, { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(destination, `${profile.version.id}.json`), JSON.stringify(profile.version, null, 4)); - //extract universal jar - let universal = await neoForge.extractUniversalJar(profile.install, installer.filePath, installer.oldAPI); - if (universal.error) - return universal; - // download libraries - let libraries = await neoForge.downloadLibraries(profile, universal); - if (libraries.error) - return libraries; - // patch forge if nessary - let patch = await neoForge.patchneoForge(profile.install, installer.oldAPI); - if (patch.error) - return patch; - return profile.version; - } - async fabric(Loader) { - let fabric = new fabric_js_1.default(this.options); - // set event - fabric.on('check', (progress, size, element) => { - this.emit('check', progress, size, element); - }); - fabric.on('progress', (progress, size, element) => { - this.emit('progress', progress, size, element); - }); - // download Json - let json = await fabric.downloadJson(Loader); - if (json.error) - return json; - let destination = path_1.default.resolve(this.options.path, 'versions', json.id); - if (!fs_1.default.existsSync(destination)) - fs_1.default.mkdirSync(destination, { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(destination, `${json.id}.json`), JSON.stringify(json, null, 4)); - // download libraries - await fabric.downloadLibraries(json); - return json; - } - async legacyFabric(Loader) { - let legacyFabric = new legacyFabric_js_1.default(this.options); - // set event - legacyFabric.on('check', (progress, size, element) => { - this.emit('check', progress, size, element); - }); - legacyFabric.on('progress', (progress, size, element) => { - this.emit('progress', progress, size, element); - }); - // download Json - let json = await legacyFabric.downloadJson(Loader); - if (json.error) - return json; - let destination = path_1.default.resolve(this.options.path, 'versions', json.id); - if (!fs_1.default.existsSync(destination)) - fs_1.default.mkdirSync(destination, { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(destination, `${json.id}.json`), JSON.stringify(json, null, 4)); - // download libraries - await legacyFabric.downloadLibraries(json); - return json; - } - async quilt(Loader) { - let quilt = new quilt_js_1.default(this.options); - // set event - quilt.on('check', (progress, size, element) => { - this.emit('check', progress, size, element); - }); - quilt.on('progress', (progress, size, element) => { - this.emit('progress', progress, size, element); - }); - // download Json - let json = await quilt.downloadJson(Loader); - if (json.error) - return json; - let destination = path_1.default.resolve(this.options.path, 'versions', json.id); - if (!fs_1.default.existsSync(destination)) - fs_1.default.mkdirSync(destination, { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(destination, `${json.id}.json`), JSON.stringify(json, null, 4)); - // // download libraries - await quilt.downloadLibraries(json); - return json; - } -} -exports.default = Loader; diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/fabric/fabric.d.ts b/src/assets/js/libs/mc-/Minecraft-Loader/loader/fabric/fabric.d.ts deleted file mode 100644 index 66a6eb7..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/fabric/fabric.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -/// -import { EventEmitter } from 'events'; -export default class FabricMC extends EventEmitter { - options: any; - constructor(options?: {}); - downloadJson(Loader: any): Promise; - downloadLibraries(json: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/fabric/fabric.js b/src/assets/js/libs/mc-/Minecraft-Loader/loader/fabric/fabric.js deleted file mode 100644 index b98c4c5..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/fabric/fabric.js +++ /dev/null @@ -1,102 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const Index_js_1 = require("../../../utils/Index.js"); -const Downloader_js_1 = __importDefault(require("../../../utils/Downloader.js")); -const node_fetch_1 = __importDefault(require("node-fetch")); -const fs_1 = __importDefault(require("fs")); -const path_1 = __importDefault(require("path")); -const events_1 = require("events"); -class FabricMC extends events_1.EventEmitter { - constructor(options = {}) { - super(); - this.options = options; - } - async downloadJson(Loader) { - let build; - let metaData; - try { - metaData = await (0, node_fetch_1.default)(Loader.metaData).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'fabric', this.options.loader.version))) { - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'fabric', this.options.loader.version), { recursive: true }); - } - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'fabric', this.options.loader.version, 'metaData.json'), JSON.stringify(metaData)); - } - catch (e) { - metaData = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'fabric', this.options.loader.version, 'metaData.json'), 'utf-8')); - } - let version = metaData.game.find(version => version.version === this.options.loader.version); - let AvailableBuilds = metaData.loader.map(build => build.version); - if (!version) - return { error: `FabricMC doesn't support Minecraft ${this.options.loader.version}` }; - if (this.options.loader.build === 'latest' || this.options.loader.build === 'recommended') { - build = metaData.loader[0]; - } - else { - build = metaData.loader.find(loader => loader.version === this.options.loader.build); - } - if (!build) - return { error: `Fabric Loader ${this.options.loader.build} not found, Available builds: ${AvailableBuilds.join(', ')}` }; - let url = Loader.json.replace('${build}', build.version).replace('${version}', this.options.loader.version); - let json; - try { - json = await (0, node_fetch_1.default)(url).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'fabric', this.options.loader.version, 'fabric.json'))) { - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'fabric', this.options.loader.version, 'fabric.json'), JSON.stringify(json)); - } - } - catch (e) { - json = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'fabric', this.options.loader.version, 'fabric.json'), 'utf-8')); - } - return json; - } - async downloadLibraries(json) { - let { libraries } = json; - let downloader = new Downloader_js_1.default(); - let files = []; - let check = 0; - let size = 0; - for (let lib of libraries) { - if (lib.rules) { - this.emit('check', check++, libraries.length, 'libraries'); - continue; - } - let file = {}; - let libInfo = (0, Index_js_1.getPathLibraries)(lib.name); - let pathLib = path_1.default.resolve(this.options.path, 'libraries', libInfo.path); - let pathLibFile = path_1.default.resolve(pathLib, libInfo.name); - if (!fs_1.default.existsSync(pathLibFile)) { - let url = `${lib.url}${libInfo.path}/${libInfo.name}`; - let sizeFile = 0; - let res = await downloader.checkURL(url); - if (res.status === 200) { - sizeFile = res.size; - size += res.size; - } - file = { - url: url, - folder: pathLib, - path: `${pathLib}/${libInfo.name}`, - name: libInfo.name, - size: sizeFile - }; - files.push(file); - } - this.emit('check', check++, libraries.length, 'libraries'); - } - if (files.length > 0) { - downloader.on("progress", (DL, totDL) => { - this.emit("progress", DL, totDL, 'libraries'); - }); - await downloader.downloadFileMultiple(files, size, this.options.downloadFileMultiple); - } - return libraries; - } -} -exports.default = FabricMC; diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/forge/forge.d.ts b/src/assets/js/libs/mc-/Minecraft-Loader/loader/forge/forge.d.ts deleted file mode 100644 index f788709..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/forge/forge.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -/// -import { EventEmitter } from 'events'; -export default class ForgeMC extends EventEmitter { - options: any; - constructor(options?: {}); - downloadInstaller(Loader: any): Promise<{ - error: string; - filePath?: undefined; - metaData?: undefined; - ext?: undefined; - id?: undefined; - } | { - filePath: string; - metaData: any; - ext: String; - id: string; - error?: undefined; - }>; - extractProfile(pathInstaller: any): Promise; - extractUniversalJar(profile: any, pathInstaller: any): Promise; - downloadLibraries(profile: any, skipForgeFilter: any): Promise; - patchForge(profile: any): Promise; - createProfile(id: any, pathInstaller: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/forge/forge.js b/src/assets/js/libs/mc-/Minecraft-Loader/loader/forge/forge.js deleted file mode 100644 index bde3258..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/forge/forge.js +++ /dev/null @@ -1,298 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const Index_js_1 = require("../../../utils/Index.js"); -const Downloader_js_1 = __importDefault(require("../../../utils/Downloader.js")); -const patcher_js_1 = __importDefault(require("../../patcher.js")); -const node_fetch_1 = __importDefault(require("node-fetch")); -const fs_1 = __importDefault(require("fs")); -const path_1 = __importDefault(require("path")); -const events_1 = require("events"); -const Index_js_2 = require("../../../utils/Index.js"); -let Lib = { win32: "windows", darwin: "osx", linux: "linux" }; -class ForgeMC extends events_1.EventEmitter { - constructor(options = {}) { - super(); - this.options = options; - } - async downloadInstaller(Loader) { - let metaData; - try { - metaData = (await (0, node_fetch_1.default)(Loader.metaData).then(res => res.json()))[this.options.loader.version]; - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version))) { - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version), { recursive: true }); - } - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version, 'metaData.json'), JSON.stringify(metaData)); - } - catch (error) { - metaData = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version, 'metaData.json')).toString()); - } - let AvailableBuilds = metaData; - let forgeURL; - let ext; - let hashFileOrigin; - if (!metaData) - return { error: `Forge ${this.options.loader.version} not supported` }; - let build; - if (this.options.loader.build === 'latest') { - let promotions; - try { - promotions = await (0, node_fetch_1.default)(Loader.promotions).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version))) { - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version), { recursive: true }); - } - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version, 'promotions-latest.json'), JSON.stringify(promotions)); - } - catch (error) { - promotions = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version, 'promotions-latest.json')).toString()); - } - promotions = promotions.promos[`${this.options.loader.version}-latest`]; - build = metaData.find(build => build.includes(promotions)); - } - else if (this.options.loader.build === 'recommended') { - let promotion; - try { - promotion = await (0, node_fetch_1.default)(Loader.promotions).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version))) { - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version), { recursive: true }); - } - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version, 'promotions-recommended.json'), JSON.stringify(promotion)); - } - catch (error) { - promotion = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version, 'promotions-recommended.json')).toString()); - } - let promotions = promotion.promos[`${this.options.loader.version}-recommended`]; - if (!promotions) - promotions = promotion.promos[`${this.options.loader.version}-latest`]; - build = metaData.find(build => build.includes(promotions)); - } - else { - build = this.options.loader.build; - } - metaData = metaData.filter(b => b === build)[0]; - if (!metaData) - return { error: `Build ${build} not found, Available builds: ${AvailableBuilds.join(', ')}` }; - let meta; - try { - meta = await (0, node_fetch_1.default)(Loader.meta.replace(/\${build}/g, metaData)).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version))) { - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version), { recursive: true }); - } - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version, 'meta.json'), JSON.stringify(meta)); - } - catch (error) { - meta = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'forge', this.options.loader.version, 'meta.json')).toString()); - } - let installerType = Object.keys(meta.classifiers).find((key) => key == 'installer'); - let clientType = Object.keys(meta.classifiers).find((key) => key == 'client'); - let universalType = Object.keys(meta.classifiers).find((key) => key == 'universal'); - if (installerType) { - forgeURL = forgeURL = Loader.install.replace(/\${version}/g, metaData); - ext = Object.keys(meta.classifiers.installer)[0]; - hashFileOrigin = meta.classifiers.installer[`${ext}`]; - } - else if (clientType) { - forgeURL = Loader.client.replace(/\${version}/g, metaData); - ext = Object.keys(meta.classifiers.client)[0]; - hashFileOrigin = meta.classifiers.client[`${ext}`]; - } - else if (universalType) { - forgeURL = Loader.universal.replace(/\${version}/g, metaData); - ext = Object.keys(meta.classifiers.universal)[0]; - hashFileOrigin = meta.classifiers.universal[`${ext}`]; - } - else { - return { error: 'Invalid forge installer' }; - } - let pathFolder = path_1.default.resolve(this.options.path, 'forge'); - let filePath = path_1.default.resolve(pathFolder, (`${forgeURL}.${ext}`).split('/').pop()); - if (!fs_1.default.existsSync(filePath)) { - if (!fs_1.default.existsSync(pathFolder)) - fs_1.default.mkdirSync(pathFolder, { recursive: true }); - let downloadForge = new Downloader_js_1.default(); - downloadForge.on('progress', (downloaded, size) => { - this.emit('progress', downloaded, size, (`${forgeURL}.${ext}`).split('/').pop()); - }); - await downloadForge.downloadFile(`${forgeURL}.${ext}`, pathFolder, (`${forgeURL}.${ext}`).split('/').pop()); - } - let hashFileDownload = await (0, Index_js_1.getFileHash)(filePath, 'md5'); - if (hashFileDownload !== hashFileOrigin) { - fs_1.default.rmSync(filePath); - return { error: 'Invalid hash' }; - } - return { filePath, metaData, ext, id: `forge-${build}` }; - } - async extractProfile(pathInstaller) { - let forgeJSON = {}; - let file = await (0, Index_js_1.getFileFromArchive)(pathInstaller, 'install_profile.json'); - let forgeJsonOrigin = JSON.parse(file); - if (!forgeJsonOrigin) - return { error: { message: 'Invalid forge installer' } }; - if (forgeJsonOrigin.install) { - forgeJSON.install = forgeJsonOrigin.install; - forgeJSON.version = forgeJsonOrigin.versionInfo; - } - else { - forgeJSON.install = forgeJsonOrigin; - let file = await (0, Index_js_1.getFileFromArchive)(pathInstaller, path_1.default.basename(forgeJSON.install.json)); - forgeJSON.version = JSON.parse(file); - } - return forgeJSON; - } - async extractUniversalJar(profile, pathInstaller) { - let skipForgeFilter = true; - if (profile.filePath) { - let fileInfo = (0, Index_js_1.getPathLibraries)(profile.path); - this.emit('extract', `Extracting ${fileInfo.name}...`); - let pathFileDest = path_1.default.resolve(this.options.path, 'libraries', fileInfo.path); - if (!fs_1.default.existsSync(pathFileDest)) - fs_1.default.mkdirSync(pathFileDest, { recursive: true }); - let file = await (0, Index_js_1.getFileFromArchive)(pathInstaller, profile.filePath); - fs_1.default.writeFileSync(`${pathFileDest}/${fileInfo.name}`, file, { mode: 0o777 }); - } - else if (profile.path) { - let fileInfo = (0, Index_js_1.getPathLibraries)(profile.path); - let listFile = await (0, Index_js_1.getFileFromArchive)(pathInstaller, null, `maven/${fileInfo.path}`); - await Promise.all(listFile.map(async (files) => { - let fileName = files.split('/'); - this.emit('extract', `Extracting ${fileName[fileName.length - 1]}...`); - let file = await (0, Index_js_1.getFileFromArchive)(pathInstaller, files); - let pathFileDest = path_1.default.resolve(this.options.path, 'libraries', fileInfo.path); - if (!fs_1.default.existsSync(pathFileDest)) - fs_1.default.mkdirSync(pathFileDest, { recursive: true }); - fs_1.default.writeFileSync(`${pathFileDest}/${fileName[fileName.length - 1]}`, file, { mode: 0o777 }); - })); - } - else { - skipForgeFilter = false; - } - if (profile.processors?.length) { - let universalPath = profile.libraries.find(v => { - return (v.name || '').startsWith('net.minecraftforge:forge'); - }); - let client = await (0, Index_js_1.getFileFromArchive)(pathInstaller, 'data/client.lzma'); - let fileInfo = (0, Index_js_1.getPathLibraries)(profile.path || universalPath.name, '-clientdata', '.lzma'); - let pathFile = path_1.default.resolve(this.options.path, 'libraries', fileInfo.path); - if (!fs_1.default.existsSync(pathFile)) - fs_1.default.mkdirSync(pathFile, { recursive: true }); - fs_1.default.writeFileSync(`${pathFile}/${fileInfo.name}`, client, { mode: 0o777 }); - this.emit('extract', `Extracting ${fileInfo.name}...`); - } - return skipForgeFilter; - } - async downloadLibraries(profile, skipForgeFilter) { - let { libraries } = profile.version; - let downloader = new Downloader_js_1.default(); - let check = 0; - let files = []; - let size = 0; - if (profile.install.libraries) - libraries = libraries.concat(profile.install.libraries); - libraries = libraries.filter((library, index, self) => index === self.findIndex(t => t.name === library.name)); - let skipForge = [ - 'net.minecraftforge:forge:', - 'net.minecraftforge:minecraftforge:' - ]; - for (let lib of libraries) { - let natives = null; - if (skipForgeFilter && skipForge.find(libs => lib.name.includes(libs))) { - if (lib.downloads?.artifact?.url == "" || !lib.downloads?.artifact?.url) { - this.emit('check', check++, libraries.length, 'libraries'); - continue; - } - } - if ((0, Index_js_2.skipLibrary)(lib)) { - this.emit('check', check++, libraries.length, 'libraries'); - continue; - } - if (lib.natives) { - natives = lib.natives[Lib[process.platform]]; - } - let file = {}; - let libInfo = (0, Index_js_1.getPathLibraries)(lib.name, natives ? `-${natives}` : ''); - let pathLib = path_1.default.resolve(this.options.path, 'libraries', libInfo.path); - let pathLibFile = path_1.default.resolve(pathLib, libInfo.name); - if (!fs_1.default.existsSync(pathLibFile)) { - let url; - let sizeFile = 0; - let baseURL = natives ? `${libInfo.path}/` : `${libInfo.path}/${libInfo.name}`; - let response = await downloader.checkMirror(baseURL, Index_js_1.mirrors); - if (response?.status === 200) { - size += response.size; - sizeFile = response.size; - url = response.url; - } - else if (lib.downloads?.artifact) { - url = lib.downloads.artifact.url; - size += lib.downloads.artifact.size; - sizeFile = lib.downloads.artifact.size; - } - else { - url = null; - } - if (url == null || !url) { - return { error: `Impossible to download ${libInfo.name}` }; - } - file = { - url: url, - folder: pathLib, - path: `${pathLib}/${libInfo.name}`, - name: libInfo.name, - size: sizeFile - }; - files.push(file); - } - this.emit('check', check++, libraries.length, 'libraries'); - } - if (files.length > 0) { - downloader.on("progress", (DL, totDL) => { - this.emit("progress", DL, totDL, 'libraries'); - }); - await downloader.downloadFileMultiple(files, size, this.options.downloadFileMultiple); - } - return libraries; - } - async patchForge(profile) { - if (profile?.processors?.length) { - let patcher = new patcher_js_1.default(this.options); - let config = {}; - patcher.on('patch', data => { - this.emit('patch', data); - }); - patcher.on('error', data => { - this.emit('error', data); - }); - if (!patcher.check(profile)) { - config = { - java: this.options.loader.config.javaPath, - minecraft: this.options.loader.config.minecraftJar, - minecraftJson: this.options.loader.config.minecraftJson - }; - await patcher.patcher(profile, config); - } - } - return true; - } - async createProfile(id, pathInstaller) { - let forgeFiles = await (0, Index_js_1.getFileFromArchive)(pathInstaller); - let minecraftJar = await (0, Index_js_1.getFileFromArchive)(this.options.loader.config.minecraftJar); - let data = await (0, Index_js_1.createZIP)([...minecraftJar, ...forgeFiles], 'META-INF'); - let destination = path_1.default.resolve(this.options.path, 'versions', id); - let profile = JSON.parse(fs_1.default.readFileSync(this.options.loader.config.minecraftJson, 'utf-8')); - profile.libraries = []; - profile.id = id; - profile.isOldForge = true; - profile.jarPath = path_1.default.resolve(destination, `${id}.jar`); - if (!fs_1.default.existsSync(destination)) - fs_1.default.mkdirSync(destination, { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(destination, `${id}.jar`), data, { mode: 0o777 }); - return profile; - } -} -exports.default = ForgeMC; diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/legacyfabric/legacyFabric.d.ts b/src/assets/js/libs/mc-/Minecraft-Loader/loader/legacyfabric/legacyFabric.d.ts deleted file mode 100644 index 66a6eb7..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/legacyfabric/legacyFabric.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -/// -import { EventEmitter } from 'events'; -export default class FabricMC extends EventEmitter { - options: any; - constructor(options?: {}); - downloadJson(Loader: any): Promise; - downloadLibraries(json: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/legacyfabric/legacyFabric.js b/src/assets/js/libs/mc-/Minecraft-Loader/loader/legacyfabric/legacyFabric.js deleted file mode 100644 index 080914d..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/legacyfabric/legacyFabric.js +++ /dev/null @@ -1,102 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const Index_js_1 = require("../../../utils/Index.js"); -const Downloader_js_1 = __importDefault(require("../../../utils/Downloader.js")); -const node_fetch_1 = __importDefault(require("node-fetch")); -const fs_1 = __importDefault(require("fs")); -const path_1 = __importDefault(require("path")); -const events_1 = require("events"); -class FabricMC extends events_1.EventEmitter { - constructor(options = {}) { - super(); - this.options = options; - } - async downloadJson(Loader) { - let build; - let metaData; - try { - metaData = await (0, node_fetch_1.default)(Loader.metaData).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'legacyfabric', this.options.loader.version))) { - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'legacyfabric', this.options.loader.version), { recursive: true }); - } - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'legacyfabric', this.options.loader.version, 'metaData.json'), JSON.stringify(metaData)); - } - catch (error) { - metaData = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'legacyfabric', this.options.loader.version, 'metaData.json')).toString()); - } - let version = metaData.game.find(version => version.version === this.options.loader.version); - let AvailableBuilds = metaData.loader.map(build => build.version); - if (!version) - return { error: `FabricMC doesn't support Minecraft ${this.options.loader.version}` }; - if (this.options.loader.build === 'latest' || this.options.loader.build === 'recommended') { - build = metaData.loader[0]; - } - else { - build = metaData.loader.find(loader => loader.version === this.options.loader.build); - } - if (!build) - return { error: `Fabric Loader ${this.options.loader.build} not found, Available builds: ${AvailableBuilds.join(', ')}` }; - let url = Loader.json.replace('${build}', build.version).replace('${version}', this.options.loader.version); - let json; - try { - json = await (0, node_fetch_1.default)(url).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'legacyfabric', this.options.loader.version, 'fabric.json'))) { - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'legacyfabric', this.options.loader.version, 'fabric.json'), JSON.stringify(json)); - } - } - catch (e) { - json = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'legacyfabric', this.options.loader.version, 'fabric.json'), 'utf-8')); - } - return json; - } - async downloadLibraries(json) { - let { libraries } = json; - let downloader = new Downloader_js_1.default(); - let files = []; - let check = 0; - let size = 0; - for (let lib of libraries) { - if (lib.rules) { - this.emit('check', check++, libraries.length, 'libraries'); - continue; - } - let file = {}; - let libInfo = (0, Index_js_1.getPathLibraries)(lib.name); - let pathLib = path_1.default.resolve(this.options.path, 'libraries', libInfo.path); - let pathLibFile = path_1.default.resolve(pathLib, libInfo.name); - if (!fs_1.default.existsSync(pathLibFile)) { - let url = `${lib.url}${libInfo.path}/${libInfo.name}`; - let sizeFile = 0; - let res = await downloader.checkURL(url); - if (res.status === 200) { - sizeFile = res.size; - size += res.size; - } - file = { - url: url, - folder: pathLib, - path: `${pathLib}/${libInfo.name}`, - name: libInfo.name, - size: sizeFile - }; - files.push(file); - } - this.emit('check', check++, libraries.length, 'libraries'); - } - if (files.length > 0) { - downloader.on("progress", (DL, totDL) => { - this.emit("progress", DL, totDL, 'libraries'); - }); - await downloader.downloadFileMultiple(files, size, this.options.downloadFileMultiple); - } - return libraries; - } -} -exports.default = FabricMC; diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/neoForge/neoForge.d.ts b/src/assets/js/libs/mc-/Minecraft-Loader/loader/neoForge/neoForge.d.ts deleted file mode 100644 index b611f48..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/neoForge/neoForge.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -/// -import { EventEmitter } from 'events'; -export default class NeoForgeMC extends EventEmitter { - options: any; - constructor(options?: {}); - downloadInstaller(Loader: any): Promise<{ - error: string; - filePath?: undefined; - oldAPI?: undefined; - } | { - filePath: string; - oldAPI: boolean; - error?: undefined; - }>; - extractProfile(pathInstaller: any): Promise; - extractUniversalJar(profile: any, pathInstaller: any, oldAPI: any): Promise; - downloadLibraries(profile: any, skipneoForgeFilter: any): Promise; - patchneoForge(profile: any, oldAPI: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/neoForge/neoForge.js b/src/assets/js/libs/mc-/Minecraft-Loader/loader/neoForge/neoForge.js deleted file mode 100644 index b635a6c..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/neoForge/neoForge.js +++ /dev/null @@ -1,228 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const Index_js_1 = require("../../../utils/Index.js"); -const Downloader_js_1 = __importDefault(require("../../../utils/Downloader.js")); -const patcher_js_1 = __importDefault(require("../../patcher.js")); -const node_fetch_1 = __importDefault(require("node-fetch")); -const fs_1 = __importDefault(require("fs")); -const path_1 = __importDefault(require("path")); -const events_1 = require("events"); -class NeoForgeMC extends events_1.EventEmitter { - constructor(options = {}) { - super(); - this.options = options; - } - async downloadInstaller(Loader) { - let build; - let neoForgeURL; - let oldAPI = true; - let legacyMetaData; - try { - legacyMetaData = await (0, node_fetch_1.default)(Loader.metaData).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'neoforge', this.options.loader.version))) { - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'neoforge', this.options.loader.version), { recursive: true }); - } - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'neoforge', this.options.loader.version, 'metaData-legacy.json'), JSON.stringify(legacyMetaData)); - } - catch (error) { - legacyMetaData = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'neoforge', this.options.loader.version, 'metaData-legacy.json')).toString()); - } - let metaData; - try { - metaData = await (0, node_fetch_1.default)(Loader.metaData).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'neoforge', this.options.loader.version))) { - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'neoforge', this.options.loader.version), { recursive: true }); - } - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'neoforge', this.options.loader.version, 'metaData.json'), JSON.stringify(metaData)); - } - catch (error) { - metaData = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'neoforge', this.options.loader.version, 'metaData.json')).toString()); - } - let versions = legacyMetaData.versions.filter(version => version.includes(`${this.options.loader.version}-`)); - if (!versions.length) { - let minecraftVersion = `${this.options.loader.version.split('.')[1]}.${this.options.loader.version.split('.')[2]}`; - versions = metaData.versions.filter(version => version.startsWith(minecraftVersion)); - oldAPI = false; - } - if (!versions.length) - return { error: `NeoForge doesn't support Minecraft ${this.options.loader.version}` }; - if (this.options.loader.build === 'latest' || this.options.loader.build === 'recommended') { - build = versions[versions.length - 1]; - } - else - build = versions.find(loader => loader === this.options.loader.build); - if (!build) - return { error: `NeoForge Loader ${this.options.loader.build} not found, Available builds: ${versions.join(', ')}` }; - if (oldAPI) - neoForgeURL = Loader.legacyInstall.replaceAll(/\${version}/g, build); - else - neoForgeURL = Loader.install.replaceAll(/\${version}/g, build); - let pathFolder = path_1.default.resolve(this.options.path, 'neoForge'); - let filePath = path_1.default.resolve(pathFolder, `neoForge-${build}-installer.jar`); - if (!fs_1.default.existsSync(filePath)) { - if (!fs_1.default.existsSync(pathFolder)) - fs_1.default.mkdirSync(pathFolder, { recursive: true }); - let downloadForge = new Downloader_js_1.default(); - downloadForge.on('progress', (downloaded, size) => { - this.emit('progress', downloaded, size, `neoForge-${build}-installer.jar`); - }); - await downloadForge.downloadFile(neoForgeURL, pathFolder, `neoForge-${build}-installer.jar`); - } - return { filePath, oldAPI }; - } - async extractProfile(pathInstaller) { - let neoForgeJSON = {}; - let file = await (0, Index_js_1.getFileFromArchive)(pathInstaller, 'install_profile.json'); - let neoForgeJsonOrigin = JSON.parse(file); - if (!neoForgeJsonOrigin) - return { error: { message: 'Invalid neoForge installer' } }; - if (neoForgeJsonOrigin.install) { - neoForgeJSON.install = neoForgeJsonOrigin.install; - neoForgeJSON.version = neoForgeJsonOrigin.versionInfo; - } - else { - neoForgeJSON.install = neoForgeJsonOrigin; - let file = await (0, Index_js_1.getFileFromArchive)(pathInstaller, path_1.default.basename(neoForgeJSON.install.json)); - neoForgeJSON.version = JSON.parse(file); - } - return neoForgeJSON; - } - async extractUniversalJar(profile, pathInstaller, oldAPI) { - let skipneoForgeFilter = true; - if (profile.filePath) { - let fileInfo = (0, Index_js_1.getPathLibraries)(profile.path); - this.emit('extract', `Extracting ${fileInfo.name}...`); - let pathFileDest = path_1.default.resolve(this.options.path, 'libraries', fileInfo.path); - if (!fs_1.default.existsSync(pathFileDest)) - fs_1.default.mkdirSync(pathFileDest, { recursive: true }); - let file = await (0, Index_js_1.getFileFromArchive)(pathInstaller, profile.filePath); - fs_1.default.writeFileSync(`${pathFileDest}/${fileInfo.name}`, file, { mode: 0o777 }); - } - else if (profile.path) { - let fileInfo = (0, Index_js_1.getPathLibraries)(profile.path); - let listFile = await (0, Index_js_1.getFileFromArchive)(pathInstaller, null, `maven/${fileInfo.path}`); - await Promise.all(listFile.map(async (files) => { - let fileName = files.split('/'); - this.emit('extract', `Extracting ${fileName[fileName.length - 1]}...`); - let file = await (0, Index_js_1.getFileFromArchive)(pathInstaller, files); - let pathFileDest = path_1.default.resolve(this.options.path, 'libraries', fileInfo.path); - if (!fs_1.default.existsSync(pathFileDest)) - fs_1.default.mkdirSync(pathFileDest, { recursive: true }); - fs_1.default.writeFileSync(`${pathFileDest}/${fileName[fileName.length - 1]}`, file, { mode: 0o777 }); - })); - } - else { - skipneoForgeFilter = false; - } - if (profile.processors?.length) { - let universalPath = profile.libraries.find(v => { - return (v.name || '').startsWith(oldAPI ? 'net.neoforged:forge' : 'net.neoforged:neoforge'); - }); - let client = await (0, Index_js_1.getFileFromArchive)(pathInstaller, 'data/client.lzma'); - let fileInfo = (0, Index_js_1.getPathLibraries)(profile.path || universalPath.name, '-clientdata', '.lzma'); - let pathFile = path_1.default.resolve(this.options.path, 'libraries', fileInfo.path); - if (!fs_1.default.existsSync(pathFile)) - fs_1.default.mkdirSync(pathFile, { recursive: true }); - fs_1.default.writeFileSync(`${pathFile}/${fileInfo.name}`, client, { mode: 0o777 }); - this.emit('extract', `Extracting ${fileInfo.name}...`); - } - return skipneoForgeFilter; - } - async downloadLibraries(profile, skipneoForgeFilter) { - let { libraries } = profile.version; - let downloader = new Downloader_js_1.default(); - let check = 0; - let files = []; - let size = 0; - if (profile.install.libraries) - libraries = libraries.concat(profile.install.libraries); - libraries = libraries.filter((library, index, self) => index === self.findIndex(t => t.name === library.name)); - let skipneoForge = [ - 'net.minecraftforge:neoforged:', - 'net.minecraftforge:minecraftforge:' - ]; - for (let lib of libraries) { - if (skipneoForgeFilter && skipneoForge.find(libs => lib.name.includes(libs))) { - if (lib.downloads?.artifact?.url == "" || !lib.downloads?.artifact?.url) { - this.emit('check', check++, libraries.length, 'libraries'); - continue; - } - } - if (lib.rules) { - this.emit('check', check++, libraries.length, 'libraries'); - continue; - } - let file = {}; - let libInfo = (0, Index_js_1.getPathLibraries)(lib.name); - let pathLib = path_1.default.resolve(this.options.path, 'libraries', libInfo.path); - let pathLibFile = path_1.default.resolve(pathLib, libInfo.name); - if (!fs_1.default.existsSync(pathLibFile)) { - let url; - let sizeFile = 0; - let baseURL = `${libInfo.path}/${libInfo.name}`; - let response = await downloader.checkMirror(baseURL, Index_js_1.mirrors); - if (response?.status === 200) { - size += response.size; - sizeFile = response.size; - url = response.url; - } - else if (lib.downloads?.artifact) { - url = lib.downloads.artifact.url; - size += lib.downloads.artifact.size; - sizeFile = lib.downloads.artifact.size; - } - else { - url = null; - } - if (url == null || !url) { - return { error: `Impossible to download ${libInfo.name}` }; - } - file = { - url: url, - folder: pathLib, - path: `${pathLib}/${libInfo.name}`, - name: libInfo.name, - size: sizeFile - }; - files.push(file); - } - this.emit('check', check++, libraries.length, 'libraries'); - } - if (files.length > 0) { - downloader.on("progress", (DL, totDL) => { - this.emit("progress", DL, totDL, 'libraries'); - }); - await downloader.downloadFileMultiple(files, size, this.options.downloadFileMultiple); - } - return libraries; - } - async patchneoForge(profile, oldAPI) { - if (profile?.processors?.length) { - let patcher = new patcher_js_1.default(this.options); - let config = {}; - patcher.on('patch', data => { - this.emit('patch', data); - }); - patcher.on('error', data => { - this.emit('error', data); - }); - if (!patcher.check(profile)) { - config = { - java: this.options.loader.config.javaPath, - minecraft: this.options.loader.config.minecraftJar, - minecraftJson: this.options.loader.config.minecraftJson - }; - await patcher.patcher(profile, config, oldAPI); - } - } - return true; - } -} -exports.default = NeoForgeMC; diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/quilt/quilt.d.ts b/src/assets/js/libs/mc-/Minecraft-Loader/loader/quilt/quilt.d.ts deleted file mode 100644 index 2b926c3..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/quilt/quilt.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -/// -import { EventEmitter } from 'events'; -export default class Quilt extends EventEmitter { - options: any; - versionMinecraft: any; - constructor(options?: {}); - downloadJson(Loader: any): Promise; - downloadLibraries(json: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/loader/quilt/quilt.js b/src/assets/js/libs/mc-/Minecraft-Loader/loader/quilt/quilt.js deleted file mode 100644 index 6cde046..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/loader/quilt/quilt.js +++ /dev/null @@ -1,105 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const Index_js_1 = require("../../../utils/Index.js"); -const Downloader_js_1 = __importDefault(require("../../../utils/Downloader.js")); -const node_fetch_1 = __importDefault(require("node-fetch")); -const fs_1 = __importDefault(require("fs")); -const path_1 = __importDefault(require("path")); -const events_1 = require("events"); -class Quilt extends events_1.EventEmitter { - constructor(options = {}) { - super(); - this.options = options; - } - async downloadJson(Loader) { - let build; - let metaData; - try { - metaData = await (0, node_fetch_1.default)(Loader.metaData).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'quilt', this.options.loader.version))) { - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'quilt', this.options.loader.version), { recursive: true }); - } - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'quilt', this.options.loader.version, 'metaData.json'), JSON.stringify(metaData)); - } - catch (error) { - metaData = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'quilt', this.options.loader.version, 'metaData.json')).toString()); - } - let version = metaData.game.find(version => version.version === this.options.loader.version); - let AvailableBuilds = metaData.loader.map(build => build.version); - if (!version) - return { error: `QuiltMC doesn't support Minecraft ${this.options.loader.version}` }; - if (this.options.loader.build === 'latest') { - build = metaData.loader[0]; - } - else if (this.options.loader.build === 'recommended') { - build = metaData.loader.find(build => !build.version.includes('beta')); - } - else { - build = metaData.loader.find(loader => loader.version === this.options.loader.build); - } - if (!build) - return { error: `QuiltMC Loader ${this.options.loader.build} not found, Available builds: ${AvailableBuilds.join(', ')}` }; - let url = Loader.json.replace('${build}', build.version).replace('${version}', this.options.loader.version); - let json; - try { - json = await (0, node_fetch_1.default)(url).then(res => res.json()); - if (!fs_1.default.existsSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'quilt', this.options.loader.version, 'fabric.json'))) { - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'quilt', this.options.loader.version, 'fabric.json'), JSON.stringify(json)); - } - } - catch (e) { - json = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, '..', '..', 'battly', 'launcher', 'quilt', this.options.loader.version, 'fabric.json'), 'utf-8')); - } - return json; - } - async downloadLibraries(json) { - let { libraries } = json; - let downloader = new Downloader_js_1.default(); - let files = []; - let check = 0; - let size = 0; - for (let lib of libraries) { - if (lib.rules) { - this.emit('check', check++, libraries.length, 'libraries'); - continue; - } - let file = {}; - let libInfo = (0, Index_js_1.getPathLibraries)(lib.name); - let pathLib = path_1.default.resolve(this.options.path, 'libraries', libInfo.path); - let pathLibFile = path_1.default.resolve(pathLib, libInfo.name); - if (!fs_1.default.existsSync(pathLibFile)) { - let url = `${lib.url}${libInfo.path}/${libInfo.name}`; - let sizeFile = 0; - let res = await downloader.checkURL(url); - if (res.status === 200) { - sizeFile = res.size; - size += res.size; - } - file = { - url: url, - folder: pathLib, - path: `${pathLib}/${libInfo.name}`, - name: libInfo.name, - size: sizeFile - }; - files.push(file); - } - this.emit('check', check++, libraries.length, 'libraries'); - } - if (files.length > 0) { - downloader.on("progress", (DL, totDL) => { - this.emit("progress", DL, totDL, 'libraries'); - }); - await downloader.downloadFileMultiple(files, size, this.options.downloadFileMultiple); - } - return libraries; - } -} -exports.default = Quilt; diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/patcher.d.ts b/src/assets/js/libs/mc-/Minecraft-Loader/patcher.d.ts deleted file mode 100644 index 8ae7c0a..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/patcher.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -/// -import { EventEmitter } from 'events'; -export default class forgePatcher extends EventEmitter { - options: any; - constructor(options: any); - patcher(profile: any, config: any, neoForgeOld?: boolean): Promise; - check(profile: any): boolean; - setArgument(arg: any, profile: any, config: any, neoForgeOld: any): any; - computePath(arg: any): any; - readJarManifest(jarPath: string): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft-Loader/patcher.js b/src/assets/js/libs/mc-/Minecraft-Loader/patcher.js deleted file mode 100644 index f187673..0000000 --- a/src/assets/js/libs/mc-/Minecraft-Loader/patcher.js +++ /dev/null @@ -1,122 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const child_process_1 = require("child_process"); -const fs_1 = __importDefault(require("fs")); -const path_1 = __importDefault(require("path")); -const events_1 = require("events"); -const Index_js_1 = require("../utils/Index.js"); -class forgePatcher extends events_1.EventEmitter { - constructor(options) { - super(); - this.options = options; - } - async patcher(profile, config, neoForgeOld = true) { - let { processors } = profile; - for (let key in processors) { - if (Object.prototype.hasOwnProperty.call(processors, key)) { - let processor = processors[key]; - if (processor?.sides && !(processor?.sides || []).includes('client')) { - continue; - } - let jar = (0, Index_js_1.getPathLibraries)(processor.jar); - let filePath = path_1.default.resolve(this.options.path, 'libraries', jar.path, jar.name); - let args = processor.args.map(arg => this.setArgument(arg, profile, config, neoForgeOld)).map(arg => this.computePath(arg)); - let classPaths = processor.classpath.map(cp => { - let classPath = (0, Index_js_1.getPathLibraries)(cp); - return `"${path_1.default.join(this.options.path, 'libraries', `${classPath.path}/${classPath.name}`)}"`; - }); - let mainClass = await this.readJarManifest(filePath); - await new Promise((resolve) => { - const ps = (0, child_process_1.spawn)(`"${path_1.default.resolve(config.java)}"`, [ - '-classpath', - [`"${filePath}"`, ...classPaths].join(path_1.default.delimiter), - mainClass, - ...args - ], { shell: true }); - ps.stdout.on('data', data => { - this.emit('patch', data.toString('utf-8')); - }); - ps.stderr.on('data', data => { - this.emit('patch', data.toString('utf-8')); - }); - ps.on('close', code => { - if (code !== 0) { - this.emit('error', `Forge patcher exited with code ${code}`); - resolve(); - } - resolve(); - }); - }); - } - } - } - check(profile) { - let files = []; - let { processors } = profile; - for (let key in processors) { - if (Object.prototype.hasOwnProperty.call(processors, key)) { - let processor = processors[key]; - if (processor?.sides && !(processor?.sides || []).includes('client')) - continue; - processor.args.map(arg => { - let finalArg = arg.replace('{', '').replace('}', ''); - if (profile.data[finalArg]) { - if (finalArg === 'BINPATCH') - return; - files.push(profile.data[finalArg].client); - } - }); - } - } - files = files.filter((item, index) => files.indexOf(item) === index); - for (let file of files) { - let libMCP = (0, Index_js_1.getPathLibraries)(file.replace('[', '').replace(']', '')); - file = `${path_1.default.resolve(this.options.path, 'libraries', `${libMCP.path}/${libMCP.name}`)}`; - if (!fs_1.default.existsSync(file)) - return false; - } - return true; - } - setArgument(arg, profile, config, neoForgeOld) { - let finalArg = arg.replace('{', '').replace('}', ''); - let universalPath = profile.libraries.find(v => { - if (this.options.loader.type === 'forge') - return (v.name || '').startsWith('net.minecraftforge:forge'); - if (this.options.loader.type === 'neoforge') - return (v.name || '').startsWith(neoForgeOld ? 'net.neoforged:forge' : 'net.neoforged:neoforge'); - }); - if (profile.data[finalArg]) { - if (finalArg === 'BINPATCH') { - let clientdata = (0, Index_js_1.getPathLibraries)(profile.path || universalPath.name); - return `"${path_1.default - .join(this.options.path, 'libraries', `${clientdata.path}/${clientdata.name}`) - .replace('.jar', '-clientdata.lzma')}"`; - } - return profile.data[finalArg].client; - } - return arg - .replace('{SIDE}', `client`) - .replace('{ROOT}', `"${path_1.default.dirname(path_1.default.resolve(this.options.path, 'forge'))}"`) - .replace('{MINECRAFT_JAR}', `"${config.minecraft}"`) - .replace('{MINECRAFT_VERSION}', `"${config.minecraftJson}"`) - .replace('{INSTALLER}', `"${this.options.path}/libraries"`) - .replace('{LIBRARY_DIR}', `"${this.options.path}/libraries"`); - } - computePath(arg) { - if (arg[0] === '[') { - let libMCP = (0, Index_js_1.getPathLibraries)(arg.replace('[', '').replace(']', '')); - return `"${path_1.default.join(this.options.path, 'libraries', `${libMCP.path}/${libMCP.name}`)}"`; - } - return arg; - } - async readJarManifest(jarPath) { - let extraction = await (0, Index_js_1.getFileFromArchive)(jarPath, 'META-INF/MANIFEST.MF'); - if (extraction) - return (extraction.toString("utf8")).split('Main-Class: ')[1].split('\r\n')[0]; - return null; - } -} -exports.default = forgePatcher; diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Arguments.d.ts b/src/assets/js/libs/mc-/Minecraft/Minecraft-Arguments.d.ts deleted file mode 100644 index 31117ba..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Arguments.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class MinecraftArguments { - options: any; - authenticator: any; - constructor(options: any); - GetArguments(json: any, loaderJson: any): Promise<{ - game: any; - jvm: string[]; - classpath: any[]; - mainClass: any; - }>; - GetGameArguments(json: any, loaderJson: any): Promise; - GetJVMArguments(json: any): Promise; - GetClassPath(json: any, loaderJson: any): Promise<{ - classpath: any[]; - mainClass: any; - }>; -} diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Arguments.js b/src/assets/js/libs/mc-/Minecraft/Minecraft-Arguments.js deleted file mode 100644 index 029b285..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Arguments.js +++ /dev/null @@ -1,160 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs_1 = __importDefault(require("fs")); -const os_1 = __importDefault(require("os")); -const Index_js_1 = require("../utils/Index.js"); -let MojangLib = { win32: "windows", darwin: "osx", linux: "linux" }; -class MinecraftArguments { - constructor(options) { - this.options = options; - this.authenticator = options.authenticator; - } - async GetArguments(json, loaderJson) { - let game = await this.GetGameArguments(json, loaderJson); - let jvm = await this.GetJVMArguments(json); - let classpath = await this.GetClassPath(json, loaderJson); - return { - game: game, - jvm: jvm, - classpath: classpath.classpath, - mainClass: classpath.mainClass - }; - } - async GetGameArguments(json, loaderJson) { - let game = json.minecraftArguments ? json.minecraftArguments.split(' ') : json.arguments.game; - let userType; - if (loaderJson) { - let gameLoader = loaderJson.minecraftArguments ? loaderJson.minecraftArguments.split(' ') : []; - game = game.concat(gameLoader); - game = game.filter((item, index, self) => index === self.findIndex((res) => res == item)); - } - if (json.id.startsWith('1.16')) - userType = 'Xbox'; - else - userType = this.authenticator.meta.type === 'Xbox' ? 'msa' : this.authenticator.meta.type; - let table = { - '${auth_access_token}': this.authenticator.access_token, - '${auth_session}': this.authenticator.access_token, - '${auth_player_name}': this.authenticator.name, - '${auth_uuid}': this.authenticator.uuid, - '${auth_xuid}': this.authenticator.xboxAccount ? this.authenticator.xboxAccount.xuid || this.authenticator.access_token : null, - '${user_properties}': this.authenticator.user_properties, - '${user_type}': userType, - '${version_name}': loaderJson ? loaderJson.id : json.id, - '${assets_index_name}': json.assetIndex.id, - '${game_directory}': this.options.instance ? `${this.options.path}/instances/${this.options.instance}` : this.options.path, - '${assets_root}': (0, Index_js_1.isold)(json) ? `${this.options.path}/resources` : `${this.options.path}/assets`, - '${game_assets}': (0, Index_js_1.isold)(json) ? `${this.options.path}/resources` : `${this.options.path}/assets`, - '${version_type}': json.type, - '${clientid}': this.authenticator.clientId || (this.authenticator.client_token || this.authenticator.access_token) - }; - for (let i in game) { - if (typeof game[i] == 'object') - game.splice(i, 2); - if (Object.keys(table).includes(game[i])) - game[i] = table[game[i]]; - } - if (this.options.screen) { - if (this.options.screen.width !== null && this.options.screen.height !== null) { - game.push('--width'); - game.push(this.options.screen.width); - game.push('--height'); - game.push(this.options.screen.height); - } - } - game.push(...this.options.GAME_ARGS); - return game.filter((item) => typeof item !== 'object'); - } - async GetJVMArguments(json) { - let opts = { - win32: '-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump', - darwin: '-XstartOnFirstThread', - linux: '-Xss1M' - }; - let jvm = [ - `-Xms${this.options.memory.min}`, - `-Xmx${this.options.memory.max}`, - '-XX:+UnlockExperimentalVMOptions', - '-XX:G1NewSizePercent=20', - '-XX:G1ReservePercent=20', - '-XX:MaxGCPauseMillis=50', - '-XX:G1HeapRegionSize=32M', - '-Dfml.ignoreInvalidMinecraftCertificates=true', - `-Djna.tmpdir=${this.options.path}/versions/${json.id}/natives`, - `-Dorg.lwjgl.system.SharedLibraryExtractPath=${this.options.path}/versions/${json.id}/natives`, - `-Dio.netty.native.workdir=${this.options.path}/versions/${json.id}/natives` - ]; - if (!json.minecraftArguments) { - jvm.push(opts[process.platform]); - } - if (json.nativesList) { - jvm.push(`-Djava.library.path=${this.options.path}/versions/${json.id}/natives`); - } - if (os_1.default.platform() == "darwin") { - let pathAssets = `${this.options.path}/assets/indexes/${json.assets}.json`; - let assets = JSON.parse(fs_1.default.readFileSync(pathAssets, 'utf-8')); - let icon = assets.objects['icons/minecraft.icns'].hash; - jvm.push(`-Xdock:name=Minecraft`); - jvm.push(`-Xdock:icon=${this.options.path}/assets/objects/${icon.substring(0, 2)}/${icon}`); - } - jvm.push(...this.options.JVM_ARGS); - return jvm; - } - async GetClassPath(json, loaderJson) { - let classPath = []; - let libraries = json.libraries; - if (loaderJson?.libraries) - libraries = loaderJson.libraries.concat(libraries); - libraries = libraries.filter((library, index, self) => index === self.findIndex((res) => res.name === library.name)); - for (let lib of libraries) { - if (lib.natives) { - let native = lib.natives[MojangLib[process.platform]]; - if (!native) - native = lib.natives[process.platform]; - if (!native) - continue; - } - else { - if (lib.rules && lib.rules[0].os) { - if (lib.rules[0].os.name !== MojangLib[process.platform]) - continue; - } - } - let path = (0, Index_js_1.getPathLibraries)(lib.name); - if (lib.loader) { - classPath.push(`${lib.loader}/libraries/${path.path}/${path.name}`); - } - else { - classPath.push(`${this.options.path}/libraries/${path.path}/${path.name}`); - } - } - if (loaderJson?.isOldForge) { - classPath.push(loaderJson?.jarPath); - } - else if (this.options.mcp) { - classPath.push(this.options.mcp); - } - else { - classPath.push(`${this.options.path}/versions/${json.id}/${json.id}.jar`); - } - classPath = classPath.filter((url, index, self) => { - let lastSegment = url.substring(url.lastIndexOf('/') + 1); - return self.findIndex((u) => u.substring(u.lastIndexOf('/') + 1) === lastSegment) === index; - }); - return { - classpath: [ - `-cp`, - classPath.join(process.platform === 'win32' ? ';' : ':'), - ], - mainClass: loaderJson ? loaderJson.mainClass : json.mainClass - }; - } -} -exports.default = MinecraftArguments; diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Assets.d.ts b/src/assets/js/libs/mc-/Minecraft/Minecraft-Assets.d.ts deleted file mode 100644 index 579897c..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Assets.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class MinecraftAssets { - assetIndex: any; - options: any; - constructor(options: any); - GetAssets(json: any): Promise; - copyAssets(json: any): void; -} diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Assets.js b/src/assets/js/libs/mc-/Minecraft/Minecraft-Assets.js deleted file mode 100644 index 181daea..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Assets.js +++ /dev/null @@ -1,70 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const node_fetch_1 = __importDefault(require("node-fetch")); -const fs_1 = __importDefault(require("fs")); -class MinecraftAssets { - constructor(options) { - this.options = options; - } - async GetAssets(json) { - this.assetIndex = json.assetIndex; - let assets = []; - let data; - try { - data = await (0, node_fetch_1.default)(this.assetIndex.url).then(res => res.json()); - fs_1.default.mkdirSync(`${this.options.path}/assets/indexes`, { recursive: true }); - fs_1.default.mkdirSync(`${this.options.path}/assets/objects`, { recursive: true }); - fs_1.default.writeFileSync(`${this.options.path}/assets/indexes/${this.assetIndex.id}.json`, JSON.stringify(data)); - } - catch (e) { - data = JSON.parse(fs_1.default.readFileSync(`${this.options.path}/assets/indexes/${this.assetIndex.id}.json`, 'utf-8')); - } - assets.push({ - type: "CFILE", - path: `assets/indexes/${this.assetIndex.id}.json`, - content: JSON.stringify(data) - }); - data = Object.values(data.objects); - for (let asset of data) { - assets.push({ - sha1: asset.hash, - size: asset.size, - type: "Assets", - path: `assets/objects/${asset.hash.substring(0, 2)}/${asset.hash}`, - url: `https://resources.download.minecraft.net/${asset.hash.substring(0, 2)}/${asset.hash}` - }); - } - return assets; - } - copyAssets(json) { - let legacyDirectory = `${this.options.path}/resources`; - if (this.options.instance) - legacyDirectory = `${this.options.path}/instances/${this.options.instance}/resources`; - let pathAssets = `${this.options.path}/assets/indexes/${json.assets}.json`; - if (!fs_1.default.existsSync(pathAssets)) - return; - let assets = JSON.parse(fs_1.default.readFileSync(pathAssets, 'utf-8')); - assets = Object.entries(assets.objects); - for (let [file, hash] of assets) { - let Hash = hash.hash; - let Subhash = Hash.substring(0, 2); - let SubAsset = `${this.options.path}/assets/objects/${Subhash}`; - let legacyAsset = file.split('/'); - legacyAsset.pop(); - if (!fs_1.default.existsSync(`${legacyDirectory}/${legacyAsset.join('/')}`)) { - fs_1.default.mkdirSync(`${legacyDirectory}/${legacyAsset.join('/')}`, { recursive: true }); - } - if (!fs_1.default.existsSync(`${legacyDirectory}/${file}`)) { - fs_1.default.copyFileSync(`${SubAsset}/${Hash}`, `${legacyDirectory}/${file}`); - } - } - } -} -exports.default = MinecraftAssets; diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Bundle.d.ts b/src/assets/js/libs/mc-/Minecraft/Minecraft-Bundle.d.ts deleted file mode 100644 index 99d249e..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Bundle.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class MinecraftBundle { - options: any; - constructor(options: any); - checkBundle(bundle: any): Promise; - getTotalSize(bundle: any): Promise; - checkFiles(bundle: any): Promise; - getFiles(path: any, file?: any[]): any[]; -} diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Bundle.js b/src/assets/js/libs/mc-/Minecraft/Minecraft-Bundle.js deleted file mode 100644 index 4d01c14..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Bundle.js +++ /dev/null @@ -1,115 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs_1 = __importDefault(require("fs")); -const path_1 = __importDefault(require("path")); -const Index_js_1 = require("../utils/Index.js"); -class MinecraftBundle { - constructor(options) { - this.options = options; - } - async checkBundle(bundle) { - let todownload = []; - for (let file of bundle) { - if (!file.path) - continue; - file.path = path_1.default.resolve(this.options.path, file.path).replace(/\\/g, "/"); - file.folder = file.path.split("/").slice(0, -1).join("/"); - if (file.type == "CFILE") { - if (!fs_1.default.existsSync(file.folder)) - fs_1.default.mkdirSync(file.folder, { recursive: true, mode: 0o777 }); - fs_1.default.writeFileSync(file.path, file.content, { encoding: "utf8", mode: 0o755 }); - continue; - } - if (fs_1.default.existsSync(file.path)) { - let replaceName = `${this.options.path}/`; - if (this.options.instance) - replaceName = `${this.options.path}/instances/${this.options.instance}/`; - if (this.options.ignored.find(ignored => ignored == file.path.replaceAll(replaceName, ""))) - continue; - if (file.sha1) { - if (await (0, Index_js_1.getFileHash)(file.path) != file.sha1) - todownload.push(file); - } - } - else - todownload.push(file); - } - return todownload; - } - async getTotalSize(bundle) { - let todownload = 0; - for (let file of bundle) { - todownload += file.size; - } - return todownload; - } - async checkFiles(bundle) { - let instancePath = ''; - if (this.options.instance) { - if (!fs_1.default.existsSync(`${this.options.path}/instances`)) - fs_1.default.mkdirSync(`${this.options.path}/instances`, { recursive: true }); - instancePath = `/instances/${this.options.instance}`; - } - let files = this.options.instance ? this.getFiles(`${this.options.path}/instances/${this.options.instance}`) : this.getFiles(this.options.path); - let ignoredfiles = [...this.getFiles(`${this.options.path}/loader`), ...this.getFiles(`${this.options.path}/runtime`)]; - for (let file of this.options.ignored) { - file = (`${this.options.path}${instancePath}/${file}`); - if (fs_1.default.existsSync(file)) { - if (fs_1.default.statSync(file).isDirectory()) { - ignoredfiles.push(...this.getFiles(file)); - } - else if (fs_1.default.statSync(file).isFile()) { - ignoredfiles.push(file); - } - } - } - ignoredfiles.forEach(file => this.options.ignored.push((file))); - bundle.forEach(file => ignoredfiles.push((file.path))); - files = files.filter(file => ignoredfiles.indexOf(file) < 0); - for (let file of files) { - try { - if (fs_1.default.statSync(file).isDirectory()) { - fs_1.default.rmSync(file, { recursive: true }); - } - else { - fs_1.default.unlinkSync(file); - let folder = file.split("/").slice(0, -1).join("/"); - while (true) { - if (folder == this.options.path) - break; - let content = fs_1.default.readdirSync(folder); - if (content.length == 0) - fs_1.default.rmSync(folder); - folder = folder.split("/").slice(0, -1).join("/"); - } - } - } - catch (e) { - continue; - } - } - } - getFiles(path, file = []) { - if (fs_1.default.existsSync(path)) { - let files = fs_1.default.readdirSync(path); - if (files.length == 0) - file.push(path); - for (let i in files) { - let name = `${path}/${files[i]}`; - if (fs_1.default.statSync(name).isDirectory()) - this.getFiles(name, file); - else - file.push(name); - } - } - return file; - } -} -exports.default = MinecraftBundle; diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Java.d.ts b/src/assets/js/libs/mc-/Minecraft/Minecraft-Java.d.ts deleted file mode 100644 index abd3cf5..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Java.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -/// -import EventEmitter from 'events'; -export default class JavaDownloader extends EventEmitter { - options: any; - constructor(options: any); - getJavaFiles(jsonversion: any): Promise<{ - error: boolean; - message: string; - files?: undefined; - path?: undefined; - } | { - files: any[]; - path: string; - error?: undefined; - message?: undefined; - }>; - getJavaOther(jsonversion: any, versionDownload?: any): Promise<{ - error: boolean; - message: string; - files?: undefined; - path?: undefined; - } | { - files: any[]; - path: string; - error?: undefined; - message?: undefined; - }>; - getPlatformArch(): { - platform: any; - arch: string; - }; - verifyAndDownloadFile({ filePath, pathFolder, fileName, url, checksum, pathExtract }: { - filePath: any; - pathFolder: any; - fileName: any; - url: any; - checksum: any; - pathExtract: any; - }): Promise<{ - error: boolean; - message: string; - }>; - extract(filePath: any, destPath: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Java.js b/src/assets/js/libs/mc-/Minecraft/Minecraft-Java.js deleted file mode 100644 index 0d17e81..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Java.js +++ /dev/null @@ -1,189 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const os_1 = __importDefault(require("os")); -const node_fetch_1 = __importDefault(require("node-fetch")); -const path_1 = __importDefault(require("path")); -const fs_1 = __importDefault(require("fs")); -const events_1 = __importDefault(require("events")); -const node_7z_1 = __importDefault(require("node-7z")); -const _7zip_bin_1 = __importDefault(require("7zip-bin")); -const Index_js_1 = require("../utils/Index.js"); -const Downloader_js_1 = __importDefault(require("../utils/Downloader.js")); -class JavaDownloader extends events_1.default { - constructor(options) { - super(); - this.options = options; - } - async getJavaFiles(jsonversion) { - if (this.options.java.version) - return await this.getJavaOther(jsonversion, this.options.java.version); - const archMapping = { - win32: { x64: 'windows-x64', ia32: 'windows-x86', arm64: 'windows-arm64' }, - darwin: { x64: 'mac-os', arm64: this.options.intelEnabledMac ? "mac-os" : "mac-os-arm64" }, - linux: { x64: 'linux', ia32: 'linux-i386' } - }; - const osPlatform = os_1.default.platform(); - const arch = os_1.default.arch(); - const osArchMapping = archMapping[osPlatform]; - const javaVersion = jsonversion.javaVersion?.component || 'jre-legacy'; - let files = []; - if (!osArchMapping) - return await this.getJavaOther(jsonversion); - const archOs = osArchMapping[arch]; - let javaVersionsJson; - try { - javaVersionsJson = await (0, node_fetch_1.default)(`https://launchermeta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json`).then(res => res.json()); - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, "runtime"), { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, "runtime/java-versions.json"), JSON.stringify(javaVersionsJson)); - } - catch (e) { - javaVersionsJson = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, "runtime/java-versions.json"), 'utf-8')); - } - const versionName = javaVersionsJson[archOs]?.[javaVersion]?.[0]?.version?.name; - if (!versionName) - return await this.getJavaOther(jsonversion); - const manifestUrl = javaVersionsJson[archOs][javaVersion][0]?.manifest?.url; - let manifest; - try { - manifest = await (0, node_fetch_1.default)(manifestUrl).then(res => res.json()); - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, `runtime/jre-${versionName}-${archOs}`), { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, `runtime/jre-${versionName}-${archOs}/java-versions.json`), JSON.stringify(manifest)); - } - catch (e) { - manifest = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, `runtime/jre-${versionName}-${archOs}/java-versions.json`), 'utf-8')); - } - const javaFiles = Object.entries(manifest.files); - const java = javaFiles.find(([path]) => path.endsWith(process.platform === 'win32' ? 'bin/javaw.exe' : 'bin/java'))[0]; - const toDelete = java.replace(process.platform === 'win32' ? 'bin/javaw.exe' : 'bin/java', ''); - for (let [path, info] of javaFiles) { - if (info.type == "directory") - continue; - if (!info.downloads) - continue; - let file = {}; - file.path = `runtime/jre-${versionName}-${archOs}/${path.replace(toDelete, "")}`; - file.executable = info.executable; - file.sha1 = info.downloads.raw.sha1; - file.size = info.downloads.raw.size; - file.url = info.downloads.raw.url; - file.type = "Java"; - files.push(file); - } - return { - files, - path: path_1.default.resolve(this.options.path, `runtime/jre-${versionName}-${archOs}/bin/java`), - }; - } - async getJavaOther(jsonversion, versionDownload) { - const majorVersion = versionDownload || jsonversion.javaVersion?.majorVersion; - const javaVersionURL = `https://api.adoptium.net/v3/assets/latest/${majorVersion ? majorVersion : 8}/hotspot`; - let javaVersions; - try { - javaVersions = await (0, node_fetch_1.default)(javaVersionURL).then(res => res.json()); - fs_1.default.mkdirSync(path_1.default.resolve(this.options.path, "runtime"), { recursive: true }); - fs_1.default.writeFileSync(path_1.default.resolve(this.options.path, "runtime/other-java-versions.json"), JSON.stringify(javaVersions)); - } - catch (e) { - javaVersions = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(this.options.path, "runtime/other-java-versions.json"), 'utf-8')); - } - const { platform, arch } = this.getPlatformArch(); - const java = javaVersions.find(file => file.binary.image_type === this.options.java.type && - file.binary.architecture === arch && - file.binary.os === platform); - if (!java) - return { error: true, message: "No Java found" }; - const { checksum, link: url, name: fileName } = java.binary.package; - const { release_name: version } = java; - const image_type = java.binary.image_type; - const pathFolder = path_1.default.resolve(this.options.path, `runtime/jre-${majorVersion}`); - const filePath = path_1.default.resolve(pathFolder, fileName); - await this.verifyAndDownloadFile({ - filePath, - pathFolder, - fileName, - url, - checksum, - pathExtract: `${pathFolder}/${version}${image_type === 'jre' ? '-jre' : ''}` - }); - let javaPath = `${pathFolder}/${version}${image_type === 'jre' ? '-jre' : ''}/bin/java`; - if (platform == 'mac') - javaPath = `${pathFolder}/${version}${image_type === 'jre' ? '-jre' : ''}/Contents/Home/bin/java`; - if (!fs_1.default.existsSync(javaPath)) { - await this.extract(filePath, pathFolder); - await this.extract(filePath.replace('.gz', ''), pathFolder); - if (fs_1.default.existsSync(filePath.replace('.gz', ''))) - fs_1.default.unlinkSync(filePath.replace('.gz', '')); - if (platform !== 'windows') - fs_1.default.chmodSync(javaPath, 0o755); - } - return { - files: [], - path: javaPath, - }; - } - getPlatformArch() { - return { - platform: { - win32: 'windows', - darwin: 'mac', - linux: 'linux' - }[os_1.default.platform()], - arch: { - x64: 'x64', - ia32: 'x32', - arm64: this.options.intelEnabledMac && os_1.default.platform() == 'darwin' ? "x64" : "aarch64", - arm: 'arm' - }[os_1.default.arch()] - }; - } - async verifyAndDownloadFile({ filePath, pathFolder, fileName, url, checksum, pathExtract }) { - if (fs_1.default.existsSync(filePath)) { - if (await (0, Index_js_1.getFileHash)(filePath, 'sha256') !== checksum) { - fs_1.default.unlinkSync(filePath); - fs_1.default.rmdirSync(pathExtract, { recursive: true }); - } - } - if (!fs_1.default.existsSync(filePath)) { - if (!fs_1.default.existsSync(pathFolder)) - fs_1.default.mkdirSync(pathFolder, { recursive: true }); - let download = new Downloader_js_1.default(); - download.on('progress', (downloaded, size) => { - this.emit('progress', downloaded, size, fileName); - }); - await download.downloadFile(url, pathFolder, fileName); - } - if (await (0, Index_js_1.getFileHash)(filePath, 'sha256') !== checksum) { - return { error: true, message: "Java checksum failed" }; - } - } - async extract(filePath, destPath) { - return await new Promise((resolve, reject) => { - if (os_1.default.platform() !== 'win32') - fs_1.default.chmodSync(_7zip_bin_1.default.path7za, 0o755); - const extract = node_7z_1.default.extractFull(filePath, destPath, { - $bin: _7zip_bin_1.default.path7za, - recursive: true, - $progress: true, - }); - extract.on('end', () => { - resolve(true); - }); - extract.on('error', (err) => { - console.log(err); - reject(err); - }); - extract.on('progress', (progress) => { - if (progress.percent > 0) - this.emit('extract', progress.percent); - }); - }); - } -} -exports.default = JavaDownloader; diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Json.d.ts b/src/assets/js/libs/mc-/Minecraft/Minecraft-Json.d.ts deleted file mode 100644 index bb96e61..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Json.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class Json { - options: any; - constructor(options: any); - GetInfoVersion(): Promise<{ - error: boolean; - message: string; - InfoVersion?: undefined; - json?: undefined; - version?: undefined; - } | { - InfoVersion: any; - json: any; - version: string; - error?: undefined; - message?: undefined; - }>; -} diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Json.js b/src/assets/js/libs/mc-/Minecraft/Minecraft-Json.js deleted file mode 100644 index 7fe673f..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Json.js +++ /dev/null @@ -1,59 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const Minecraft_Lwjgl_Native_js_1 = __importDefault(require("./Minecraft-Lwjgl-Native.js")); -const node_fetch_1 = __importDefault(require("node-fetch")); -const os_1 = __importDefault(require("os")); -const fs_1 = __importDefault(require("fs")); -class Json { - constructor(options) { - this.options = options; - } - async GetInfoVersion() { - let version = this.options.version; - let data; - try { - data = await (0, node_fetch_1.default)(`https://launchermeta.mojang.com/mc/game/version_manifest_v2.json?_t=${new Date().toISOString()}`); - data = await data.json(); - fs_1.default.writeFileSync(`${this.options.path}/battly/launcher/mc-assets/version_manifest_v2.json`, JSON.stringify(data, null, 4)); - } - catch (e) { - data = JSON.parse(fs_1.default.readFileSync(`${this.options.path}/battly/launcher/mc-assets/version_manifest_v2.json`, 'utf-8')); - } - if (version == 'latest_release' || version == 'r' || version == 'lr') { - version = data.latest.release; - } - else if (version == 'latest_snapshot' || version == 's' || version == 'ls') { - version = data.latest.snapshot; - } - data = data.versions.find(v => v.id === version); - if (!data) - return { - error: true, - message: `Minecraft ${version} is not found.` - }; - let json; - try { - json = await (0, node_fetch_1.default)(data.url).then(res => res.json()); - fs_1.default.mkdirSync(`${this.options.path}/versions/${version}`, { recursive: true }); - fs_1.default.writeFileSync(`${this.options.path}/versions/${version}/${version}.json`, JSON.stringify(json, null, 4)); - } - catch (e) { - json = JSON.parse(fs_1.default.readFileSync(`${this.options.path}/versions/${version}/${version}.json`, 'utf-8')); - } - if (os_1.default.platform() == 'linux' && os_1.default.arch().startsWith('arm')) - json = await new Minecraft_Lwjgl_Native_js_1.default(this.options).ProcessJson(json); - return { - InfoVersion: data, - json: json, - version: version - }; - } -} -exports.default = Json; diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Libraries.d.ts b/src/assets/js/libs/mc-/Minecraft/Minecraft-Libraries.d.ts deleted file mode 100644 index e72a87d..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Libraries.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class Libraries { - json: any; - options: any; - constructor(options: any); - Getlibraries(json: any): Promise; - GetAssetsOthers(url: any): Promise; - natives(bundle: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Libraries.js b/src/assets/js/libs/mc-/Minecraft/Minecraft-Libraries.js deleted file mode 100644 index ae230a9..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Libraries.js +++ /dev/null @@ -1,117 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const os_1 = __importDefault(require("os")); -const fs_1 = __importDefault(require("fs")); -const adm_zip_1 = __importDefault(require("adm-zip")); -const node_fetch_1 = __importDefault(require("node-fetch")); -let MojangLib = { win32: "windows", darwin: "osx", linux: "linux" }; -let Arch = { x32: "32", x64: "64", arm: "32", arm64: "64" }; -class Libraries { - constructor(options) { - this.options = options; - } - async Getlibraries(json) { - this.json = json; - let libraries = []; - for (let lib of this.json.libraries) { - let artifact; - let type = "Libraries"; - if (lib.natives) { - let classifiers = lib.downloads.classifiers; - let native = lib.natives[MojangLib[process.platform]]; - if (!native) - native = lib.natives[process.platform]; - type = "Native"; - if (native) - artifact = classifiers[native.replace("${arch}", Arch[os_1.default.arch()])]; - else - continue; - } - else { - if (lib.rules && lib.rules[0].os) { - if (lib.rules[0].os.name !== MojangLib[process.platform]) - continue; - } - artifact = lib.downloads.artifact; - } - if (!artifact) - continue; - libraries.push({ - sha1: artifact.sha1, - size: artifact.size, - path: `libraries/${artifact.path}`, - type: type, - url: artifact.url - }); - } - libraries.push({ - sha1: this.json.downloads.client.sha1, - size: this.json.downloads.client.size, - path: `versions/${this.json.id}/${this.json.id}.jar`, - type: "Libraries", - url: this.json.downloads.client.url - }); - libraries.push({ - path: `versions/${this.json.id}/${this.json.id}.json`, - type: "CFILE", - content: JSON.stringify(this.json) - }); - return libraries; - } - async GetAssetsOthers(url) { - if (!url) - return []; - let data; - try { - data = await (0, node_fetch_1.default)(url).then(res => res.json()); - fs_1.default.writeFileSync(`${this.options.path}/battly/launcher/mc-assets/extra-assets.json`, JSON.stringify(data, null, 4)); - } - catch (e) { - data = []; - } - let assets = []; - for (let asset of data) { - if (!asset.path) - continue; - let path = asset.path; - assets.push({ - sha1: asset.hash, - size: asset.size, - type: path.split("/")[0], - path: this.options.instance ? `instances/${this.options.instance}/${path}` : path, - url: asset.url - }); - } - return assets; - } - async natives(bundle) { - let natives = bundle.filter(mod => mod.type === "Native").map(mod => `${mod.path}`); - if (natives.length === 0) - return natives; - let nativeFolder = (`${this.options.path}/versions/${this.json.id}/natives`).replace(/\\/g, "/"); - if (!fs_1.default.existsSync(nativeFolder)) - fs_1.default.mkdirSync(nativeFolder, { recursive: true, mode: 0o777 }); - for (let native of natives) { - let zip = new adm_zip_1.default(native); - let entries = zip.getEntries(); - for (let entry of entries) { - if (entry.entryName.startsWith("META-INF")) - continue; - if (entry.isDirectory) { - fs_1.default.mkdirSync(`${nativeFolder}/${entry.entryName}`, { recursive: true, mode: 0o777 }); - continue; - } - fs_1.default.writeFile(`${nativeFolder}/${entry.entryName}`, zip.readFile(entry), { encoding: "utf8", mode: 0o777 }, () => { }); - } - } - return natives; - } -} -exports.default = Libraries; diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Loader.d.ts b/src/assets/js/libs/mc-/Minecraft/Minecraft-Loader.d.ts deleted file mode 100644 index 8e1a718..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Loader.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class MinecraftLoader { - options: any; - on: any; - emit: any; - loaderPath: string; - constructor(options: any); - GetLoader(version: any, javaPath: any): Promise; - GetArguments(json: any, version: any): Promise<{ - game: any[]; - jvm: any[]; - mainClass?: undefined; - } | { - game: any; - jvm: any; - mainClass: any; - }>; -} diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Loader.js b/src/assets/js/libs/mc-/Minecraft/Minecraft-Loader.js deleted file mode 100644 index cb5f066..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Loader.js +++ /dev/null @@ -1,88 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const events_1 = require("events"); -const index_js_1 = __importDefault(require("../Minecraft-Loader/index.js")); -class MinecraftLoader { - constructor(options) { - this.options = options; - this.on = events_1.EventEmitter.prototype.on; - this.emit = events_1.EventEmitter.prototype.emit; - this.loaderPath = `${this.options.path}/${this.options.loader.path}`; - } - async GetLoader(version, javaPath) { - let loader = new index_js_1.default({ - path: this.loaderPath, - downloadFileMultiple: this.options.downloadFileMultiple, - loader: { - type: this.options.loader.type, - version: version, - build: this.options.loader.build, - config: { - javaPath: javaPath, - minecraftJar: `${this.options.path}/versions/${version}/${version}.jar`, - minecraftJson: `${this.options.path}/versions/${version}/${version}.json` - } - } - }); - return await new Promise((resolve, reject) => { - loader.install(); - loader.on('json', (json) => { - let loaderJson = json; - loaderJson.libraries = loaderJson.libraries.map((lib) => { - lib.loader = this.loaderPath; - return lib; - }); - resolve(loaderJson); - }); - loader.on('extract', (extract) => { - this.emit('extract', extract); - }); - loader.on('progress', (progress, size, element) => { - this.emit('progress', progress, size, element); - }); - loader.on('check', (progress, size, element) => { - this.emit('check', progress, size, element); - }); - loader.on('patch', (patch) => { - this.emit('patch', patch); - }); - loader.on('error', (err) => { - reject(err); - }); - }); - } - async GetArguments(json, version) { - if (json === null) { - return { - game: [], - jvm: [] - }; - } - let moddeArguments = json.arguments; - if (!moddeArguments) - return { game: [], jvm: [] }; - let Arguments = {}; - if (moddeArguments.game) - Arguments.game = moddeArguments.game; - if (moddeArguments.jvm) - Arguments.jvm = moddeArguments.jvm.map(jvm => { - return jvm - .replace(/\${version_name}/g, version) - .replace(/\${library_directory}/g, `${this.loaderPath}/libraries`) - .replace(/\${classpath_separator}/g, process.platform === 'win32' ? ';' : ':'); - }); - return { - game: Arguments.game || [], - jvm: Arguments.jvm || [], - mainClass: json.mainClass - }; - } -} -exports.default = MinecraftLoader; diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Lwjgl-Native.d.ts b/src/assets/js/libs/mc-/Minecraft/Minecraft-Lwjgl-Native.d.ts deleted file mode 100644 index e2bed8c..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Lwjgl-Native.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class MinecraftLoader { - options: any; - constructor(options: any); - ProcessJson(version: any): Promise; -} diff --git a/src/assets/js/libs/mc-/Minecraft/Minecraft-Lwjgl-Native.js b/src/assets/js/libs/mc-/Minecraft/Minecraft-Lwjgl-Native.js deleted file mode 100644 index 100cac2..0000000 --- a/src/assets/js/libs/mc-/Minecraft/Minecraft-Lwjgl-Native.js +++ /dev/null @@ -1,61 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const path_1 = __importDefault(require("path")); -const fs_1 = __importDefault(require("fs")); -const os_1 = __importDefault(require("os")); -class MinecraftLoader { - constructor(options) { - this.options = options; - } - async ProcessJson(version) { - let archMapping = { arm64: "aarch64", arm: 'aarch' }[os_1.default.arch()]; - let pathLWJGL = path_1.default.join(__dirname, `../../assets/LWJGL/${archMapping}`); - let versionJinput = version.libraries.find((lib) => { - if (lib.name.startsWith("net.java.jinput:jinput-platform:")) { - return true; - } - else if (lib.name.startsWith("net.java.jinput:jinput:")) { - return true; - } - })?.name.split(":").pop(); - let versionLWJGL = version.libraries.find((lib) => { - if (lib.name.startsWith("org.lwjgl:lwjgl:")) { - return true; - } - else if (lib.name.startsWith("org.lwjgl.lwjgl:lwjgl:")) { - return true; - } - })?.name.split(":").pop(); - if (versionJinput) { - version.libraries = version.libraries.filter((lib) => { - if (lib.name.includes("jinput")) - return false; - return true; - }); - } - if (versionLWJGL) { - version.libraries = version.libraries.filter((lib) => { - if (lib.name.includes("lwjgl")) - return false; - return true; - }); - if (versionLWJGL.includes('2.9')) { - let versionLWJGLNatives = JSON.parse(fs_1.default.readFileSync(path_1.default.join(pathLWJGL, '2.9.4.json'), 'utf-8')); - version.libraries.push(...versionLWJGLNatives.libraries); - } - else { - let versionLWJGLNatives = JSON.parse(fs_1.default.readFileSync(path_1.default.join(pathLWJGL, `${versionLWJGL}.json`), 'utf-8')); - version.libraries.push(...versionLWJGLNatives.libraries); - } - } - return version; - } -} -exports.default = MinecraftLoader; diff --git a/src/assets/js/libs/mc-/StatusServer/buffer.d.ts b/src/assets/js/libs/mc-/StatusServer/buffer.d.ts deleted file mode 100644 index cff76fb..0000000 --- a/src/assets/js/libs/mc-/StatusServer/buffer.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -declare function CustomBuffer(existingBuffer?: any): void; -export default CustomBuffer; diff --git a/src/assets/js/libs/mc-/StatusServer/buffer.js b/src/assets/js/libs/mc-/StatusServer/buffer.js deleted file mode 100644 index f8cc3e0..0000000 --- a/src/assets/js/libs/mc-/StatusServer/buffer.js +++ /dev/null @@ -1,56 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function CustomBuffer(existingBuffer = Buffer.alloc(48)) { - let buffer = existingBuffer; - let offset = 0; - this.writeletInt = (val) => { - while (true) { - if ((val & 0xFFFFFF80) == 0) { - return this.writeUByte(val); - } - this.writeUByte(val & 0x7F | 0x80); - val = val >>> 7; - } - }; - this.writeString = (string) => { - this.writeletInt(string.length); - if (offset + string.length >= buffer.length) - Buffer.concat([buffer, new Buffer(string.length)]); - buffer.write(string, offset, string.length, "UTF-8"); - offset += string.length; - }; - this.writeUShort = (val) => { - this.writeUByte(val >> 8); - this.writeUByte(val & 0xFF); - }; - this.writeUByte = (val) => { - if (offset >= buffer.length) { - buffer = Buffer.concat([buffer, new Buffer(50)]); - } - buffer.writeUInt8(val, offset++); - }; - this.readletInt = function () { - let val = 0; - let count = 0; - while (true) { - let i = buffer.readUInt8(offset++); - val |= (i & 0x7F) << count++ * 7; - if ((i & 0x80) != 128) - break; - } - return val; - }; - this.readString = () => { - let length = this.readletInt(); - let str = buffer.toString("UTF-8", offset, offset + length); - offset += length; - return str; - }; - this.buffer = () => { - return buffer.slice(0, offset); - }; - this.offset = () => { - return offset; - }; -} -exports.default = CustomBuffer; diff --git a/src/assets/js/libs/mc-/StatusServer/status.d.ts b/src/assets/js/libs/mc-/StatusServer/status.d.ts deleted file mode 100644 index f64e720..0000000 --- a/src/assets/js/libs/mc-/StatusServer/status.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -export default class status { - ip: string; - port: number; - constructor(ip?: string, port?: number); - getStatus(): Promise; -} diff --git a/src/assets/js/libs/mc-/StatusServer/status.js b/src/assets/js/libs/mc-/StatusServer/status.js deleted file mode 100644 index 07f0fa6..0000000 --- a/src/assets/js/libs/mc-/StatusServer/status.js +++ /dev/null @@ -1,91 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const net_1 = __importDefault(require("net")); -const buffer_js_1 = __importDefault(require("./buffer.js")); -function ping(server, port, callback, timeout, protocol = '') { - let start = new Date(); - let socket = net_1.default.connect({ - port: port, - host: server - }, () => { - let handshakeBuffer = new buffer_js_1.default(); - handshakeBuffer.writeletInt(0); - handshakeBuffer.writeletInt(protocol); - handshakeBuffer.writeString(server); - handshakeBuffer.writeUShort(port); - handshakeBuffer.writeletInt(1); - writePCBuffer(socket, handshakeBuffer); - let setModeBuffer = new buffer_js_1.default(); - setModeBuffer.writeletInt(0); - writePCBuffer(socket, setModeBuffer); - }); - socket.setTimeout(timeout, () => { - if (callback) - callback(new Error("Socket timed out when connecting to " + server + ":" + port), null); - socket.destroy(); - }); - let readingBuffer = Buffer.alloc(0); - socket.on('data', data => { - readingBuffer = Buffer.concat([readingBuffer, data]); - let buffer = new buffer_js_1.default(readingBuffer); - let length; - try { - length = buffer.readletInt(); - } - catch (err) { - return; - } - if (readingBuffer.length < length - buffer.offset()) - return; - buffer.readletInt(); - try { - let end = new Date(); - let json = JSON.parse(buffer.readString()); - callback(null, { - error: false, - ms: Math.round(end - start), - version: json.version.name, - playersConnect: json.players.online, - playersMax: json.players.max - }); - } - catch (err) { - return callback(err, null); - } - socket.destroy(); - }); - socket.once('error', err => { - if (callback) - callback(err, null); - socket.destroy(); - }); -} -; -function writePCBuffer(client, buffer) { - let length = new buffer_js_1.default(); - length.writeletInt(buffer.buffer().length); - client.write(Buffer.concat([length.buffer(), buffer.buffer()])); -} -class status { - constructor(ip = '0.0.0.0', port = 25565) { - this.ip = ip; - this.port = port; - } - async getStatus() { - return await new Promise((resolve, reject) => { - ping(this.ip, this.port, (err, res) => { - if (err) - return reject({ error: err }); - return resolve(res); - }, 3000); - }); - } -} -exports.default = status; diff --git a/src/assets/js/libs/mc-/utils/Downloader.d.ts b/src/assets/js/libs/mc-/utils/Downloader.d.ts deleted file mode 100644 index bcd0c3e..0000000 --- a/src/assets/js/libs/mc-/utils/Downloader.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -/// -import { EventEmitter } from 'events'; -interface downloadOptions { - url: string; - path: string; - length: number; - folder: string; -} -export default class download extends EventEmitter { - downloadFile(url: string, path: string, fileName: string): Promise; - downloadFileMultiple(files: downloadOptions, size: number, limit?: number, timeout?: number): Promise; - checkURL(url: string, timeout?: number): Promise; - checkMirror(baseURL: string, mirrors: any): Promise; -} -export {}; diff --git a/src/assets/js/libs/mc-/utils/Downloader.js b/src/assets/js/libs/mc-/utils/Downloader.js deleted file mode 100644 index eac2d2b..0000000 --- a/src/assets/js/libs/mc-/utils/Downloader.js +++ /dev/null @@ -1,132 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const fs_1 = __importDefault(require("fs")); -const node_fetch_1 = __importDefault(require("node-fetch")); -const events_1 = require("events"); -class download extends events_1.EventEmitter { - async downloadFile(url, path, fileName) { - if (!fs_1.default.existsSync(path)) - fs_1.default.mkdirSync(path, { recursive: true }); - const writer = fs_1.default.createWriteStream(path + '/' + fileName); - const response = await (0, node_fetch_1.default)(url); - let size = response.headers.get('content-length'); - let downloaded = 0; - return new Promise((resolve, reject) => { - response.body.on('data', (chunk) => { - downloaded += chunk.length; - this.emit('progress', downloaded, size); - writer.write(chunk); - }); - response.body.on('end', () => { - writer.end(); - resolve(); - }); - response.body.on('error', (err) => { - this.emit('error', err); - reject(err); - }); - }); - } - async downloadFileMultiple(files, size, limit = 1, timeout = 10000) { - if (limit > files.length) - limit = files.length; - let completed = 0; - let downloaded = 0; - let queued = 0; - let start = new Date().getTime(); - let before = 0; - let speeds = []; - let estimated = setInterval(() => { - let duration = (new Date().getTime() - start) / 1000; - let loaded = (downloaded - before) * 8; - if (speeds.length >= 5) - speeds = speeds.slice(1); - speeds.push((loaded / duration) / 8); - let speed = 0; - for (let s of speeds) - speed += s; - speed /= speeds.length; - this.emit("speed", speed); - let time = (size - downloaded) / (speed); - this.emit("estimated", time); - start = new Date().getTime(); - before = downloaded; - }, 500); - const downloadNext = async () => { - if (queued < files.length) { - let file = files[queued]; - queued++; - if (!fs_1.default.existsSync(file.foler)) - fs_1.default.mkdirSync(file.folder, { recursive: true, mode: 0o777 }); - const writer = fs_1.default.createWriteStream(file.path, { flags: 'w', mode: 0o777 }); - try { - const response = await (0, node_fetch_1.default)(file.url, { timeout: timeout }); - response.body.on('data', (chunk) => { - downloaded += chunk.length; - this.emit('progress', downloaded, size, file.type); - writer.write(chunk); - }); - response.body.on('end', () => { - writer.end(); - completed++; - downloadNext(); - }); - } - catch (e) { - writer.end(); - completed++; - downloadNext(); - this.emit('error', e); - } - } - }; - while (queued < limit) - downloadNext(); - return new Promise((resolve) => { - const interval = setInterval(() => { - if (completed === files.length) { - clearInterval(estimated); - clearInterval(interval); - resolve(); - } - }, 100); - }); - } - async checkURL(url, timeout = 10000) { - return await new Promise(async (resolve, reject) => { - await (0, node_fetch_1.default)(url, { method: 'HEAD', timeout: timeout }).then(res => { - if (res.status === 200) { - resolve({ - size: parseInt(res.headers.get('content-length')), - status: res.status - }); - } - }); - reject(false); - }); - } - async checkMirror(baseURL, mirrors) { - for (let mirror of mirrors) { - let url = `${mirror}/${baseURL}`; - let res = await this.checkURL(url).then(res => res).catch(err => false); - if (res?.status == 200) { - return { - url: url, - size: res.size, - status: res.status - }; - break; - } - continue; - } - return false; - } -} -exports.default = download; diff --git a/src/assets/js/libs/mc-/utils/Index.d.ts b/src/assets/js/libs/mc-/utils/Index.d.ts deleted file mode 100644 index 7c9d146..0000000 --- a/src/assets/js/libs/mc-/utils/Index.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -declare function getPathLibraries(main: any, nativeString?: any, forceExt?: any): { - path: string; - name: string; -}; -declare function getFileHash(filePath: string, algorithm?: string): Promise; -declare function isold(json: any): boolean; -declare function loader(type: string): { - metaData: string; - meta: string; - promotions: string; - install: string; - universal: string; - client: string; - legacyMetaData?: undefined; - legacyInstall?: undefined; - json?: undefined; -} | { - legacyMetaData: string; - metaData: string; - legacyInstall: string; - install: string; - meta?: undefined; - promotions?: undefined; - universal?: undefined; - client?: undefined; - json?: undefined; -} | { - metaData: string; - json: string; - meta?: undefined; - promotions?: undefined; - install?: undefined; - universal?: undefined; - client?: undefined; - legacyMetaData?: undefined; - legacyInstall?: undefined; -}; -declare let mirrors: string[]; -declare function getFileFromArchive(jar: string, file?: string, path?: string): Promise; -declare function createZIP(files: any, ignored?: any): Promise; -declare function skipLibrary(lib: any): boolean; -export { getPathLibraries, isold, getFileHash, mirrors, loader, getFileFromArchive, createZIP, skipLibrary }; diff --git a/src/assets/js/libs/mc-/utils/Index.js b/src/assets/js/libs/mc-/utils/Index.js deleted file mode 100644 index 937d25b..0000000 --- a/src/assets/js/libs/mc-/utils/Index.js +++ /dev/null @@ -1,140 +0,0 @@ -"use strict"; -/** - * @author Luuxis - * @license CC-BY-NC 4.0 - https://creativecommons.org/licenses/by-nc/4.0/ - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.skipLibrary = exports.createZIP = exports.getFileFromArchive = exports.loader = exports.mirrors = exports.getFileHash = exports.isold = exports.getPathLibraries = void 0; -const crypto_1 = __importDefault(require("crypto")); -const fs_1 = __importDefault(require("fs")); -const adm_zip_1 = __importDefault(require("adm-zip")); -function getPathLibraries(main, nativeString, forceExt) { - let libSplit = main.split(':'); - let fileName = libSplit[3] ? `${libSplit[2]}-${libSplit[3]}` : libSplit[2]; - let finalFileName = fileName.includes('@') ? fileName.replace('@', '.') : `${fileName}${nativeString || ''}${forceExt || '.jar'}`; - let pathLib = `${libSplit[0].replace(/\./g, '/')}/${libSplit[1]}/${libSplit[2].split('@')[0]}`; - return { - path: pathLib, - name: `${libSplit[1]}-${finalFileName}` - }; -} -exports.getPathLibraries = getPathLibraries; -async function getFileHash(filePath, algorithm = 'sha1') { - let shasum = crypto_1.default.createHash(algorithm); - let file = fs_1.default.createReadStream(filePath); - file.on('data', data => { - shasum.update(data); - }); - let hash = await new Promise(resolve => { - file.on('end', () => { - resolve(shasum.digest('hex')); - }); - }); - return hash; -} -exports.getFileHash = getFileHash; -function isold(json) { - return json.assets === 'legacy' || json.assets === 'pre-1.6'; -} -exports.isold = isold; -function loader(type) { - if (type === 'forge') { - return { - metaData: 'https://files.minecraftforge.net/net/minecraftforge/forge/maven-metadata.json', - meta: 'https://files.minecraftforge.net/net/minecraftforge/forge/${build}/meta.json', - promotions: 'https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json', - install: 'https://maven.minecraftforge.net/net/minecraftforge/forge/${version}/forge-${version}-installer', - universal: 'https://maven.minecraftforge.net/net/minecraftforge/forge/${version}/forge-${version}-universal', - client: 'https://maven.minecraftforge.net/net/minecraftforge/forge/${version}/forge-${version}-client', - }; - } - else if (type === 'neoforge') { - return { - legacyMetaData: 'https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/forge', - metaData: 'https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/neoforge', - legacyInstall: 'https://maven.neoforged.net/net/neoforged/forge/${version}/forge-${version}-installer.jar', - install: 'https://maven.neoforged.net/net/neoforged/neoforge/${version}/neoforge-${version}-installer.jar' - }; - } - else if (type === 'fabric') { - return { - metaData: 'https://meta.fabricmc.net/v2/versions', - json: 'https://meta.fabricmc.net/v2/versions/loader/${version}/${build}/profile/json' - }; - } - else if (type === 'legacyfabric') { - return { - metaData: 'https://meta.legacyfabric.net/v2/versions', - json: 'https://meta.legacyfabric.net/v2/versions/loader/${version}/${build}/profile/json' - }; - } - else if (type === 'quilt') { - return { - metaData: 'https://meta.quiltmc.org/v3/versions', - json: 'https://meta.quiltmc.org/v3/versions/loader/${version}/${build}/profile/json' - }; - } -} -exports.loader = loader; -let mirrors = [ - "https://maven.minecraftforge.net", - "https://maven.neoforged.net/releases", - "https://maven.creeperhost.net", - "https://libraries.minecraft.net", - "https://repo1.maven.org/maven2" -]; -exports.mirrors = mirrors; -async function getFileFromArchive(jar, file = null, path = null) { - let fileReturn = []; - let zip = new adm_zip_1.default(jar); - let entries = zip.getEntries(); - return await new Promise(resolve => { - for (let entry of entries) { - if (!entry.isDirectory && !path) { - if (entry.entryName == file) - fileReturn = entry.getData(); - if (!file) - fileReturn.push({ name: entry.entryName, data: entry.getData() }); - } - if (!entry.isDirectory && entry.entryName.includes(path) && path) { - fileReturn.push(entry.entryName); - } - } - resolve(fileReturn); - }); -} -exports.getFileFromArchive = getFileFromArchive; -async function createZIP(files, ignored = null) { - let zip = new adm_zip_1.default(); - return await new Promise(resolve => { - for (let entry of files) { - if (ignored && entry.name.includes(ignored)) - continue; - zip.addFile(entry.name, entry.data); - } - resolve(zip.toBuffer()); - }); -} -exports.createZIP = createZIP; -function skipLibrary(lib) { - let Lib = { win32: "windows", darwin: "osx", linux: "linux" }; - let skip = false; - if (lib.rules) { - skip = true; - lib.rules.forEach(({ action, os, features }) => { - if (features) - return true; - if (action === 'allow' && ((os && os.name === Lib[process.platform]) || !os)) { - skip = false; - } - if (action === 'disallow' && ((os && os.name === Lib[process.platform]) || !os)) { - skip = true; - } - }); - } - return skip; -} -exports.skipLibrary = skipLibrary; diff --git a/src/assets/js/libs/mc/Launch.js b/src/assets/js/libs/mc/Launch.js index bb47cac..def70c6 100644 --- a/src/assets/js/libs/mc/Launch.js +++ b/src/assets/js/libs/mc/Launch.js @@ -10,6 +10,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); const events_1 = require("events"); const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); +const node_fetch_1 = __importDefault(require("node-fetch")); +const crypto_1 = __importDefault(require("crypto")); const child_process_1 = require("child_process"); const Minecraft_Json_js_1 = __importDefault(require("./Minecraft/Minecraft-Json.js")); const Minecraft_Libraries_js_1 = __importDefault(require("./Minecraft/Minecraft-Libraries.js")); @@ -260,6 +262,44 @@ class Launch extends events_1.EventEmitter { json.nativesList = true; if ((0, Index_js_1.isold)(json)) new Minecraft_Assets_js_1.default(this.options).copyAssets(json); + function calculateFileHash(filePath) { + return new Promise((resolve, reject) => { + const hash = crypto_1.default.createHash('sha1'); + const stream = fs_1.default.createReadStream(filePath); + stream.on('data', data => hash.update(data)); + stream.on('end', () => resolve(hash.digest('hex'))); + stream.on('error', reject); + }); + } + for (let asset of gameAssetsOther) { + try { + if (fs_1.default.existsSync(asset.path)) { + const fileHash = await calculateFileHash(asset.path); + if (fileHash === asset.hash) { + console.log(`File ${asset.path} already exists and matches hash, skipping download.`); + continue; + } + else { + console.log(`File ${asset.path} exists but hash doesn't match, downloading again.`); + } + } + const res = await (0, node_fetch_1.default)(asset.url); + if (!res.ok) { + throw new Error(`Failed to fetch ${asset.url}: ${res.statusText}`); + } + const dest = fs_1.default.createWriteStream(asset.path); + await new Promise((resolve, reject) => { + res.body.pipe(dest); + res.body.on('error', reject); + dest.on('finish', resolve); + dest.on('error', reject); + }); + console.log(`Downloaded ${asset.path} successfully.`); + } + catch (error) { + console.error(`Error downloading ${asset.path}: ${error.message}`); + } + } return { minecraftJson: json, minecraftLoader: loaderJson, diff --git a/src/assets/js/panels/friends.js b/src/assets/js/panels/friends.js index f105b14..d955d88 100644 --- a/src/assets/js/panels/friends.js +++ b/src/assets/js/panels/friends.js @@ -151,10 +151,11 @@ class Friends { users.innerHTML = ''; - fetch('https://api.battlylauncher.com/api/users/buscarUsuarios', { + fetch('https://api.battlylauncher.com/api/v2/users/buscarUsuarios', { method: 'POST', headers: { - 'Content-Type': 'application/json' + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, }, body: JSON.stringify({ username: input.value @@ -281,14 +282,13 @@ class Friends { }); return; } else { - fetch('https://api.battlylauncher.com/api/users/enviarSolicitud', { + fetch('https://api.battlylauncher.com/api/v2/users/enviarSolicitud', { method: 'POST', headers: { - 'Content-Type': 'application/json' + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, }, body: JSON.stringify({ - username: account.name, - password: account.password, amigo: user, }) }).then(res => res.json()).then(res => { @@ -387,14 +387,13 @@ class Friends { }); return; } else { - fetch('https://api.battlylauncher.com/api/users/enviarSolicitud', { + fetch('https://api.battlylauncher.com/api/v2/users/enviarSolicitud', { method: 'POST', headers: { - 'Content-Type': 'application/json' + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, }, body: JSON.stringify({ - username: account.name, - password: account.password, amigo: user }) }).then(res => res.json()).then(res => { @@ -472,15 +471,12 @@ class Friends { const modalBody = document.createElement('section'); modalBody.className = 'modal-card-body'; - fetch('https://api.battlylauncher.com/api/users/obtenerSolicitudes', { + fetch('https://api.battlylauncher.com/api/v2/users/obtenerSolicitudes', { method: 'POST', headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - username: account.name, - password: account.password - }) + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, + } }).then(res => res.json()).then(async res => { if (res.error) { console.error(res.error); @@ -611,15 +607,14 @@ class Friends { }); acceptButton1.addEventListener('click', () => { - fetch('https://api.battlylauncher.com/api/users/aceptarSolicitud', { + fetch('https://api.battlylauncher.com/api/v2/users/aceptarSolicitud', { method: 'POST', headers: { - 'Content-Type': 'application/json' + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, }, body: JSON.stringify({ - username: account.name, solicitud: solicitud, - password: account.password }) }).then(res => res.json()).then(res => { if (res.error) { @@ -641,14 +636,13 @@ class Friends { }); rejectButton1.addEventListener('click', () => { - fetch('https://api.battlylauncher.com/api/users/rechazarSolicitud', { + fetch('https://api.battlylauncher.com/v2/api/users/rechazarSolicitud', { method: 'POST', headers: { - 'Content-Type': 'application/json' + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, }, body: JSON.stringify({ - username: account.name, - password: account.password, amigo: solicitud }) }).then(res => res.json()).then(res => { @@ -752,15 +746,14 @@ class Friends { }); acceptButton1.addEventListener('click', () => { - fetch('https://api.battlylauncher.com/api/users/aceptarSolicitud', { + fetch('https://api.battlylauncher.com/api/v2/users/aceptarSolicitud', { method: 'POST', headers: { - 'Content-Type': 'application/json' + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, }, body: JSON.stringify({ - username: account.name, solicitud: solicitud, - password: account.password }) }).then(res => res.json()).then(res => { if (res.error) { @@ -787,14 +780,13 @@ class Friends { }); rejectButton1.addEventListener('click', () => { - fetch('https://api.battlylauncher.com/api/users/rechazarSolicitud', { + fetch('https://api.battlylauncher.com/v2/api/users/rechazarSolicitud', { method: 'POST', headers: { - 'Content-Type': 'application/json' + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, }, body: JSON.stringify({ - username: account.name, - password: account.password, amigo: solicitud }) }).then(res => res.json()).then(res => { @@ -880,6 +872,34 @@ class Friends { modalBody.appendChild(box2); img2.style.backgroundImage = "url('https://api.battlylauncher.com/api/skin/" + solicitud + ".png')"; + + rejectButton2.addEventListener('click', () => { + fetch('https://api.battlylauncher.com/api/v2/users/cancelarSolicitud', { + method: 'POST', + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, + }, + body: JSON.stringify({ + amigo: solicitud + }) + }).then(res => res.json()).then(res => { + if (res.error) { + console.error(res.error); + + new Alert().ShowAlert({ + icon: "error", + title: lang.error_cancelling_request + }); + } else { + + new Alert().ShowAlert({ + icon: "success", + title: lang.request_cancelled + }); + } + }); + }); } catch (error) { console.log(`❌ Error al obtener la skin de ${solicitud}.`); // Crear el segundo cuadro de solicitud @@ -939,6 +959,34 @@ class Friends { modalBody.appendChild(box2); img2.style.backgroundImage = "url('https://minotar.net/skin/MHF_Steve.png')"; + + rejectButton2.addEventListener('click', () => { + fetch('https://api.battlylauncher.com/api/v2/users/cancelarSolicitud', { + method: 'POST', + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, + }, + body: JSON.stringify({ + amigo: solicitud + }) + }).then(res => res.json()).then(res => { + if (res.error) { + console.error(res.error); + + new Alert().ShowAlert({ + icon: "error", + title: lang.error_cancelling_request + }); + } else { + + new Alert().ShowAlert({ + icon: "success", + title: lang.request_cancelled + }); + } + }); + }); } } } @@ -983,15 +1031,12 @@ class Friends { const loadingText = document.getElementById("loading-text"); loadingText.innerHTML = lang.loading_friends; - fetch('https://api.battlylauncher.com/api/users/obtenerAmigos', { + fetch('https://api.battlylauncher.com/api/v2/users/obtenerAmigos', { method: 'POST', headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - username: account.name, - password: account.password - }) + "Content-Type": "application/json", + Authorization: `Bearer ${account.token}`, + } }).then(res => res.json()).then(async res => { if (res.error) { console.error(res.error); diff --git a/src/assets/js/panels/home.js b/src/assets/js/panels/home.js index f93f3cd..3b95723 100644 --- a/src/assets/js/panels/home.js +++ b/src/assets/js/panels/home.js @@ -83,16 +83,14 @@ class Home { let account = this.database .getAccounts() .find((account) => account.uuid === uuid.selected); + console.log(account) - fetch("https://api.battlylauncher.com/api/users/obtenerAmigos", { + fetch("https://api.battlylauncher.com/api/v2/users/obtenerAmigos", { method: "POST", headers: { "Content-Type": "application/json", - }, - body: JSON.stringify({ - username: account.name, - password: account.password, - }), + Authorization: `Bearer ${account.token}`, + } }) .then((res) => res.json()) .then(async (res) => { @@ -3014,6 +3012,15 @@ class Home { LoadMinecraftNews(); } }); + + document.getElementById("header-text-to-add").addEventListener("click", () => { + const os = require("os"); + if (os.platform() === "win32") { + shell.openExternal("https://battlylauncher.com/premium?utm_source=launcher&utm_medium=header&utm_campaign=premium"); + } else { + window.open("https://battlylauncher.com/premium", "_blank"); + } + }); } async initLaunch() { @@ -3079,10 +3086,10 @@ class Home { ); let data = this.BattlyConfig; - let new_version = data.new_version; - let new_version_message = data.new_version_message; - let new_version_news = data.new_version_news; - let new_version_html = data.new_version_html; + let new_version = data.new_version_v2; + let new_version_message = data.new_version_message_v2; + let new_version_news = data.new_version_news_v2; + let new_version_html = data.new_version_html_v2; if (new_version == true) { const Swal_ = require("./assets/js/libs/sweetalert/sweetalert2.all.min"); @@ -3461,7 +3468,7 @@ class Home { enable: loaderEnable, }, verify: false, - ignored: ["loader", "libraries"], + ignored: ["libraries/com/mojang/authlib"], java: false, memory: memory, }; @@ -3937,16 +3944,10 @@ class Home { launch_core.on("error", (err) => { consoleOutput_ += `[ERROR] ${JSON.stringify(err, null, 2)}\n`; - console.log(JSON.stringify(err, null, 2)); + console.error(error.message); progressBar1.style.display = "none"; info.style.display = "none"; playBtn.style.display = ""; - return new Alert().ShowAlert({ - title: "Error", - text: `Error al iniciar Minecraft. Error desconocido. Vuelve a iniciar Minecraft. [ERROR: 7] \nError: ${err.error}`, - icon: "error", - button: "Aceptar", - }); }); launch_core.on("close", (code) => { @@ -7438,6 +7439,10 @@ class Home { document.getElementById("settings-btn").addEventListener("click", () => { changePanel("settings"); }); + + document.getElementById("servers-btn").addEventListener("click", () => { + changePanel("servers"); + }); } async getdate(e) { diff --git a/src/assets/js/panels/mods.js b/src/assets/js/panels/mods.js index b2884e2..a0c1741 100644 --- a/src/assets/js/panels/mods.js +++ b/src/assets/js/panels/mods.js @@ -16,6 +16,7 @@ const path = require('path'); const unzipper = require('unzipper'); const toml = require('toml'); const { shell } = require('electron'); +const marked = require('marked'); const Swal = require('./assets/js/libs/sweetalert/sweetalert2.all.min.js'); const preloadContent = document.querySelector('.preload-content'); @@ -1716,7 +1717,7 @@ class Mods { ${lang.followers}: ${mod_data.followers}

- ${mod_data.body.replace(/\*\*(.*?)\*\*/g, '$1').replace(/!\[(.*?)\]\((.*?)\)/g, '$1').replace(/### (.*?)\n/g, '

$1

\n').replace(/## (.*?)\n/g, '

$1

\n').replace(/# (.*?)\n/g, '

$1

\n').replace(/\[(.*?)\]\((.*?)\)/g, '$1').replace(/- (.*)\n/g, '
  • $1
  • \n').replace(/\n---\n/g, '\n
    \n').replace(//g, '').replace(/__(.*?)__/g, '$1').replace(/_(.*?)_/g, '$1').replace(/\*(.*?)\*/g, '$1')} + ${marked.parse(mod_data.body)}

    diff --git a/src/assets/js/update.js b/src/assets/js/update.js index 11118c0..b48157c 100644 --- a/src/assets/js/update.js +++ b/src/assets/js/update.js @@ -14,7 +14,7 @@ let lang; const pkgVersion = async () => { const pkg = { - version: "2.1.0", + version: "2.2.0", buildVersion: 1004 }; return pkg; diff --git a/src/assets/js/utils/lang.js b/src/assets/js/utils/lang.js index 63e6659..908cb97 100644 --- a/src/assets/js/utils/lang.js +++ b/src/assets/js/utils/lang.js @@ -2,46 +2,86 @@ const fetch = require("node-fetch"); const fs = require("fs"); const path = require("path"); -const dataDirectory = process.env.APPDATA || (process.platform == "darwin" ? `${process.env.HOME}/Library/Application Support` : process.env.HOME); +const dataDirectory = process.env.APPDATA || (process.platform === "darwin" ? `${process.env.HOME}/Library/Application Support` : process.env.HOME); let stringsCache; let isLoadingCache = false; class Lang { GetLang() { - return new Promise((resolve, reject) => { - const langLocalStorage = localStorage.getItem("lang") ? localStorage.getItem("lang") : "en"; + const readLangFromFile = (langLocalStorage) => { + return new Promise((resolve, reject) => { + const filePath = path.join(dataDirectory, ".battly", "battly", "launcher", "langs", `${langLocalStorage}.json`); + + fs.readFile(filePath, "utf8", (err, data) => { + if (err) { + console.error("Error reading language file:", err); + return reject(err); + } + + try { + const parsedData = JSON.parse(data); + resolve(parsedData); + } catch (parseError) { + console.error("Error parsing JSON file:", parseError); + reject(parseError); + } + }); + }); + }; + + return new Promise(async (resolve, reject) => { + const langLocalStorage = localStorage.getItem("lang") || "en"; if (!stringsCache && !isLoadingCache) { isLoadingCache = true; + console.log("Cache doesn't exist, fetching from API..."); - fetch(`https://api.battlylauncher.com/launcher/langs/${langLocalStorage}`) - .then(res => res.json()) - .then(data => { - const { strings, version } = data; - const localStorageLangVersion = localStorage.getItem("langVersion") ? localStorage.getItem("langVersion") : 0; + if (localStorage.getItem("offline-mode") === "true") { + try { + const fileData = await readLangFromFile(langLocalStorage); + stringsCache = fileData; + isLoadingCache = false; + resolve(stringsCache); + } catch (error) { + isLoadingCache = false; + reject(error); + } + } else { + fetch(`https://api.battlylauncher.com/launcher/langs/${langLocalStorage}`) + .then(res => res.json()) + .then(data => { + const { strings, version } = data; + const localStorageLangVersion = localStorage.getItem("langVersion") || 0; + if (version !== localStorageLangVersion) { + localStorage.setItem("langVersion", version); - if (version !== localStorageLangVersion) { - localStorage.setItem("langVersion", version); + const langDir = path.join(dataDirectory, ".battly", "battly", "launcher", "langs"); + if (!fs.existsSync(langDir)) { + fs.mkdirSync(langDir, { recursive: true }); + } - if (!fs.existsSync(path.join(dataDirectory, ".battly", "battly", "launcher", "langs"))) { - fs.mkdirSync(path.join(dataDirectory, ".battly", "battly", "launcher", "langs"), { recursive: true }); + fs.writeFileSync(path.join(langDir, `${langLocalStorage}.json`), JSON.stringify(strings), "utf8"); } - fs.writeFileSync(path.join(dataDirectory, ".battly", "battly", "launcher", "langs", `${langLocalStorage}.json`), JSON.stringify(strings), "utf8"); - } - - stringsCache = strings; - isLoadingCache = false; - resolve(stringsCache); - }) - .catch(error => { - console.error("Error fetching from API:", error); - this.readLangFromFile(langLocalStorage, resolve, reject); - }); + stringsCache = strings; + isLoadingCache = false; + resolve(stringsCache); + }) + .catch(async error => { + console.error("Error fetching from API:", error); + try { + const fileData = await readLangFromFile(langLocalStorage); + resolve(fileData); + } catch (fileError) { + reject(fileError); + } finally { + isLoadingCache = false; + } + }); + } } else if (stringsCache && !isLoadingCache) { console.log("Cache exists, returning it..."); - console.log(stringsCache); resolve(stringsCache); } else { console.log("Cache is loading, waiting..."); @@ -54,17 +94,6 @@ class Lang { } }); } - - readLangFromFile(langLocalStorage, resolve, reject) { - fs.readFile(path.join(dataDirectory, ".battly", "battly", "launcher", "langs", `${langLocalStorage}.json`), "utf8", (err, data) => { - if (err) { - console.error(err); - reject(err); - return; - } - resolve(JSON.parse(data)); - }); - } } module.exports = { Lang }; diff --git a/src/launcher.html b/src/launcher.html index 127a3c8..724b368 100644 --- a/src/launcher.html +++ b/src/launcher.html @@ -197,6 +197,7 @@ .header-text-to-add { margin-left: 5px; + transition: color 0.3s ease; } .header-text-to-add:hover { @@ -206,7 +207,7 @@
    -
    Battly Launcher 2.1.0 Battly Launcher 2.2.0
    diff --git a/src/panels/home.html b/src/panels/home.html index ace91f8..5f34df9 100644 --- a/src/panels/home.html +++ b/src/panels/home.html @@ -15,15 +15,6 @@ -
    -
    Battly Launcher 2.1.0 build - 1003
    -
    -
    -
    -
    -
    -