feat:模组加载器更改
This commit is contained in:
@@ -25,6 +25,8 @@ export class Dex {
|
||||
this._unzip(buffer,mpname),
|
||||
platform(plat).downloadfile(this.in,`./instance/${mpname}`)
|
||||
])
|
||||
this.ws.send(JSON.stringify({ status: "changed", result: undefined })); //改变状态
|
||||
|
||||
//await this._unzip(buffer);
|
||||
}
|
||||
|
||||
@@ -64,6 +66,5 @@ export class Dex {
|
||||
index++
|
||||
}
|
||||
/* 解压完成 */
|
||||
this.ws.send(JSON.stringify({ status: "changed", result: undefined }));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import { DeEarth } from "./utils/DeEarth.js";
|
||||
import { version_compare } from "./utils/utils.js";
|
||||
import { Forge } from "./modloader/forge.js";
|
||||
import { Minecraft } from "./modloader/minecraft.js";
|
||||
import { Fabric } from "./modloader/fabric.js";
|
||||
|
||||
const core = new Core(config);
|
||||
|
||||
@@ -21,4 +22,6 @@ core.start();
|
||||
|
||||
// }
|
||||
// new Forge("1.20.1","47.3.10").setup()
|
||||
await new Minecraft("forge","1.20.1").setup()
|
||||
//await new Minecraft("forge","1.20.1","0").setup()
|
||||
// await new Minecraft("forge","1.16.5","0").setup()
|
||||
await new Fabric("1.20.1","0.17.2").setup()
|
||||
@@ -0,0 +1,73 @@
|
||||
import got, { Got } from "got";
|
||||
import { fastdownload, xfastdownload } from "../utils/utils.js";
|
||||
|
||||
interface ILatestLoader{
|
||||
url:string,
|
||||
stable:boolean
|
||||
}
|
||||
|
||||
interface IServer{
|
||||
libraries:{
|
||||
name:string
|
||||
}[]
|
||||
}
|
||||
|
||||
export class Fabric{
|
||||
minecraft: string;
|
||||
loaderVersion: string;
|
||||
got:Got
|
||||
constructor(minecraft:string,loaderVersion:string) {
|
||||
this.minecraft = minecraft;
|
||||
this.loaderVersion = loaderVersion;
|
||||
this.got = got.extend({
|
||||
prefixUrl:"https://bmclapi2.bangbang93.com/",
|
||||
headers:{
|
||||
"User-Agent": "DeEarthX"
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async setup(){
|
||||
await this.libraries()
|
||||
}
|
||||
|
||||
async libraries(){
|
||||
const res = await this.got.get(`fabric-meta/v2/versions/loader/${this.minecraft}/${this.loaderVersion}/server/json`).json<IServer>()
|
||||
const _downlist: [string,string][]= []
|
||||
res.libraries.forEach(e=>{
|
||||
const path = this.MTP(e.name)
|
||||
_downlist.push([`https://bmclapi2.bangbang93.com/maven/${path}`,`./fabric/libraries/${path}`])
|
||||
})
|
||||
await xfastdownload(_downlist)
|
||||
}
|
||||
|
||||
async getLaestLoader(){
|
||||
let downurl = ""
|
||||
const res = await this.got.get("fabric-meta/v2/versions/installer").json<ILatestLoader[]>()
|
||||
res.forEach(e=>{
|
||||
if(e.stable){
|
||||
downurl = `https://bmclapi2.bangbang93.com/maven/${new URL(e.url).pathname.slice(1)}`
|
||||
return;
|
||||
}
|
||||
})
|
||||
await fastdownload([downurl,`./fabric/fabric-installer.jar`])
|
||||
}
|
||||
|
||||
private MTP(string:string){
|
||||
const mjp = string.replace(/^\[|\]$/g, '')
|
||||
const OriginalName = mjp.split("@")[0]
|
||||
const x = OriginalName.split(":")
|
||||
const _mappingType = mjp.split('@')[1];
|
||||
let mappingType = ""
|
||||
if (_mappingType){
|
||||
mappingType = _mappingType
|
||||
}else{
|
||||
mappingType = "jar"
|
||||
}
|
||||
if(x[3]){
|
||||
return `${x[0].replace(/\./g, '/')}/${x[1]}/${x[2]}/${x[1]}-${x[2]}-${x[3]}.${mappingType}`
|
||||
}else{
|
||||
return `${x[0].replace(/\./g, '/')}/${x[1]}/${x[2]}/${x[1]}-${x[2]}.${mappingType}`
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import got, { Got } from "got";
|
||||
import fs from "node:fs"
|
||||
import fse from "fs-extra"
|
||||
import { xfastdownload } from "../utils/utils.js";
|
||||
import { version_compare, xfastdownload } from "../utils/utils.js";
|
||||
import { yauzl_promise } from "../utils/yauzl.promise.js";
|
||||
|
||||
interface Iforge{
|
||||
@@ -39,13 +39,14 @@ export class Forge {
|
||||
async setup(){
|
||||
await this.installer()
|
||||
await this.library()
|
||||
// if (this.minecraft.startsWith("1.18")){
|
||||
// }
|
||||
if (version_compare(this.minecraft,"1.18") === -1){
|
||||
await this.wshell()
|
||||
}
|
||||
}
|
||||
|
||||
async library(){
|
||||
const _downlist: [string,string][]= []
|
||||
const data = await fs.promises.readFile(`./forge/Forge-${this.minecraft}-${this.loaderVersion}.jar`)
|
||||
const data = await fs.promises.readFile(`./forge/forge-${this.minecraft}-${this.loaderVersion}-installer.jar`)
|
||||
const zip = await yauzl_promise(data)
|
||||
for await(const entry of zip){
|
||||
if(entry.fileName === "version.json" || entry.fileName === "install_profile.json"){ //Libraries
|
||||
@@ -76,9 +77,14 @@ export class Forge {
|
||||
|
||||
async installer(){
|
||||
const res = (await this.got.get(`forge/download?mcversion=${this.minecraft}&version=${this.loaderVersion}&category=installer&format=jar`)).rawBody;
|
||||
await fse.outputFile(`./forge/Forge-${this.minecraft}-${this.loaderVersion}.jar`,res);
|
||||
await fse.outputFile(`./forge/forge-${this.minecraft}-${this.loaderVersion}-installer.jar`,res);
|
||||
}
|
||||
|
||||
private async wshell(){
|
||||
const cmd = `java -jar forge-${this.minecraft}-${this.loaderVersion}.jar`
|
||||
await fs.promises.writeFile("./forge/run.bat",`@echo off\n${cmd}`) //Windows
|
||||
await fs.promises.writeFile("./forge/run.sh",`#!/bin/bash\n${cmd}`) //Linux
|
||||
}
|
||||
|
||||
private MTP(string:string){
|
||||
const mjp = string.replace(/^\[|\]$/g, '')
|
||||
|
||||
@@ -17,9 +17,11 @@ interface ILInfo{
|
||||
export class Minecraft{
|
||||
loader: string;
|
||||
minecraft: string;
|
||||
constructor(loader:string,minecraft:string,){
|
||||
loaderVersion: string;
|
||||
constructor(loader:string,minecraft:string,lv:string){
|
||||
this.loader = loader;
|
||||
this.minecraft = minecraft;
|
||||
this.loaderVersion = lv;
|
||||
}
|
||||
|
||||
async setup(){
|
||||
@@ -31,19 +33,12 @@ export class Minecraft{
|
||||
}
|
||||
|
||||
async forge_setup(){
|
||||
if(version_compare(this.minecraft,"1.18") === 1){
|
||||
// 1.18.x + MC依赖解压
|
||||
const mcpath = `./forge/libraries/net/minecraft/server/${this.minecraft}/server-${this.minecraft}.jar`
|
||||
await fastdownload([`https://bmclapi2.bangbang93.com/version/${this.minecraft}/server`,mcpath])
|
||||
if(version_compare(this.minecraft,"1.18") === 1){
|
||||
// 1.18.x + 依赖解压
|
||||
const zip = await yauzl_promise(await fs.promises.readFile(mcpath))
|
||||
for await(const entry of zip){
|
||||
//console.log(entry.fileName.replace("META-INF/libraries/",""))
|
||||
if(entry.fileName.endsWith("/")){
|
||||
const dirPath = entry.fileName.replace("META-INF/libraries/","./forge/libraries/")
|
||||
if (!fs.existsSync(dirPath)){
|
||||
await fs.promises.mkdir(dirPath, { recursive: true });
|
||||
}
|
||||
}
|
||||
if(entry.fileName.startsWith("META-INF/libraries/")&&!entry.fileName.endsWith("/")){
|
||||
console.log(entry.fileName)
|
||||
const stream = await entry.openReadStream;
|
||||
@@ -53,13 +48,24 @@ export class Minecraft{
|
||||
}
|
||||
// 1.18.x + 依赖解压
|
||||
}else{
|
||||
//1.18.x - 依赖下载
|
||||
const json = await got.get(`https://bmclapi2.bangbang93.com/version/${this.minecraft}/json`)
|
||||
.json<ILInfo>()
|
||||
//1.18.x - MC依赖下载
|
||||
const lowv = `./forge/minecraft_server.${this.minecraft}.jar`
|
||||
const dmc = fastdownload([`https://bmclapi2.bangbang93.com/version/${this.minecraft}/server`,lowv])
|
||||
const download:Promise<void> = new Promise(async (resolve)=>{
|
||||
console.log("并行")
|
||||
const json = await got.get(`https://bmclapi2.bangbang93.com/version/${this.minecraft}/json`,{
|
||||
headers:{
|
||||
"User-Agent": "DeEarthX"
|
||||
}
|
||||
})
|
||||
.json<ILInfo>()
|
||||
json.libraries.forEach(async e=>{
|
||||
const path = e.downloads.artifact.path
|
||||
await fastdownload([`https://bmclapi2.bangbang93.com/maven/${path}`,`./forge/libraries/${path}`])
|
||||
})
|
||||
resolve()
|
||||
})
|
||||
await Promise.all([dmc,download])
|
||||
//1.18.x - 依赖下载
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import fse from "fs-extra"
|
||||
import { Forge } from "./forge.js";
|
||||
|
||||
class NeoForge extends Forge{
|
||||
constructor(minecraft:string,loaderVersion:string){
|
||||
super(minecraft,loaderVersion); //子承父业
|
||||
}
|
||||
|
||||
async setup(){
|
||||
await this.installer();
|
||||
await this.library();
|
||||
}
|
||||
|
||||
async installer(){
|
||||
const res = (await this.got.get(`neoforge/version/${this.loaderVersion}/download/installer.jar`)).rawBody;
|
||||
await fse.outputFile(`./forge/forge-${this.minecraft}-${this.loaderVersion}-installer.jar`,res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user