Compare commits

...

5 Commits

Author SHA1 Message Date
Tianpao
9afbc993ba feat:hash优化筛选模组 2025-09-07 17:42:56 +08:00
Tianpao
f65dea29f5 feat:使用mcim镜像源 统一UA 2025-08-14 13:44:53 +08:00
Tianpao
9d77fa53c7 feat:fabric启动脚本,垃圾回收,rubbish改名 fix:json解析失败崩溃 2025-07-26 16:27:14 +08:00
Tianpao
d8d8c4051a feat:更新fabric安装器 2025-07-26 15:11:44 +08:00
Tianpao
32f7473533 fix:DEP无法正常抛出错误 2025-07-26 13:29:47 +08:00
8 changed files with 96 additions and 118 deletions

View File

@@ -1,3 +1,15 @@
import toml from 'smol-toml'
const t = `\nmodLoader = "javafml"\nloaderVersion = "[4,)"\n\nlicense = "Supplementaries Team License v.1.2"\nissueTrackerURL = "https://github.com/MehVahdJukaar/supplementaries/issues"\n\n[[mixins]]\n config = "supplementaries.mixins.json"\n[[mixins]]\n config = "supplementaries-common.mixins.json"\n\n[[mods]]\n modId = "supplementaries"\n version = "1.20-3.1.20"\n displayName = "Supplementaries"\n logoFile = "icon.png"\n authors = "MehVahdJukaar, Plantkillable"\n credits = "Put a book named 'credi…1.20.1,1.20.2)"\n ordering = "NONE"\n side = "CLIENT"\n\n[[dependencies.supplementaries]]\n modId = "moonlight"\n mandatory = true\n versionRange = "[1.20-2.13.65,]"\n ordering = "NONE"\n side = "BOTH"\n\n[[dependencies.supplementaries]]\n modId = "quark"\n mandatory = false\n versionRange = "[1.19-3.4-404,]"\n ordering = "AFTER"\n side = "BOTH"\n\n["lithium:options"]\n mixin.block.moving_block_shapes = false\n\n["canary:options"]\n mixin.block.moving_block_shapes = false\n\n`
console.log(toml.parse(t))
import got from 'got';
const res = await got.post('https://api.modrinth.com/v2/version_files', {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0',
},
json: {
hashes: [
"ea0f38408102e4d2efd53c2cc11b88b711996b48d8922f76ea6abf731219c5bd1efe39ddf9cce77c54d49a62ff10fb685c00d2e4c524ab99d20f6296677ab2c4",
"925a5c4899affa4098d997dfa4a4cb52c636d539e94bc489d1fa034218cb96819a70eb8b01647a39316a59fcfe223c1a8c05ed2e2ae5f4c1e75fa48f6af1c961"
],
algorithm: 'sha512',
}
}).json()
console.log(res)

View File

@@ -5,7 +5,7 @@ import fs from "node:fs";
import fse from "fs-extra";
import { join, basename, dirname } from "node:path";
import { platform, what_platform } from "./platform/index.js";
import { isDevelopment, isInstallJava, readzipentry } from "./utils/utils.js";
import { type ForgeInfo, isDevelopment, isInstallJava, readzipentry } from "./utils/utils.js";
import fabric from "./ml_install/fabric.js";
import forge from "./ml_install/forge.js";
import neoforge from "./ml_install/neoforge.js";
@@ -39,7 +39,7 @@ if (!argv) {
function initdir() {
if (!fs.existsSync(unzip_path)) {
fse.ensureDirSync(join(unzip_path, "rubbish"));
fse.ensureDirSync(join(unzip_path, ".rubbish"));
}
}
@@ -54,6 +54,7 @@ async function main(modpack_path: string) {
yauzl.open(modpack_path, { lazyEntries: true }, (err, zipfile) => {
zipfile.readEntry(); //首次读取
zipfile.on("entry", async (entry) => {
const name: string = entry.fileName;
if (/\/$/.test(name)) {
} else if (name.includes("overrides/")) {
@@ -88,12 +89,13 @@ async function main(modpack_path: string) {
const plat = platform(what_platform(dud_files));
const info = await plat.getinfo(pack_info);
await plat.downloadfile(pack_info, dirx);
await DeEarthMain(join(dirx, "mods"), join(unzip_path, "rubbish"));
await DeEarthMain(join(dirx, "mods"), join(unzip_path, ".rubbish"));
await install(info.loader, info.minecraft, info.loader_version, dirx);
fs.writeFileSync(
join(dirx, "eula.txt"),
"#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).\n#This serverpack created by DeEarthX(QQ_Group:559349662)\neula=true"
);
await garcol(dirx,{minecraft_verison: info.minecraft, forge_verison: info.loader_version}).catch((e)=>{});
LOGGER.info("DeEarthX已将服务端制作完成");
zipfile.close();
});
@@ -116,6 +118,9 @@ async function install(
break;
case "fabric-loader":
await fabric(minecraft, loaderver, path);
const com = "java -jar fabric-server-launch.jar"
fs.writeFileSync(join(path,'run.bat'),com)
fs.writeFileSync(join(path,'run.sh'),com)
break;
case "forge":
await forge(minecraft, loaderver, path);
@@ -126,6 +131,24 @@ async function install(
}
}
async function garcol(p:string,fi:ForgeInfo): Promise<void> {
return new Promise((resolve,reject)=>{
try{
LOGGER.info("正在删除垃圾文件......")
const x = [`Forge-${fi.minecraft_verison}-${fi.forge_verison}.jar`,`installer.log`,`installer.jar`,`fabric-installer-1.0.3.jar`,`options.txt`,`shaderpacks/`,`resourcepacks/`,'essential/']
for (let i=0;i<x.length;i++){
try{
fs.rmSync(join(p, x[i]),{recursive: true, force: true})
}catch(e){}
}
resolve()
}catch(err){
reject(err)
}
})
}
function getCurrnetDir() {
const url = new URL(".", import.meta.url);
return fileURLToPath(url);

View File

@@ -1,6 +1,7 @@
import cp from "child_process";
import fsExtra from "fs-extra";
import got from "got";
import { usemirror } from "../utils/utils.js";
export default async function install(
mcver: string,
fabricver: string,
@@ -8,12 +9,12 @@ export default async function install(
) {
const data = (
await got.get(
`https://maven.fabricmc.net/net/fabricmc/fabric-installer/1.0.1/fabric-installer-1.0.1.jar`
`https://maven.fabricmc.net/net/fabricmc/fabric-installer/1.0.3/fabric-installer-1.0.3.jar`
)
).rawBody;
fsExtra.outputFileSync(path+"/fabric-installer-1.0.1.jar", data);
fsExtra.outputFileSync(path+"/fabric-installer-1.0.3.jar", data);
cp.execSync(
`java -jar fabric-installer-1.0.1.jar server -mcver ${mcver} -loader ${fabricver}`,
`java -jar fabric-installer-1.0.3.jar server -mcver ${mcver} -loader ${fabricver}`,
{ cwd: path, stdio: "ignore" }
);
}

View File

@@ -9,7 +9,7 @@ import { LOGGER } from "../utils/logger.js";
const gotx = got.extend({
prefixUrl: "https://bmclapi2.bangbang93.com",
headers: { "User-Agent": "DeEarthX V2" },
headers: { "User-Agent": "DeEarthX" },
});
interface mcinfoX {
@@ -24,12 +24,12 @@ export default async function install(
) {
//instance
const mcinfo = (await gotx
.get(`version/${minecraftversion}/json`)
.get(`version/${minecraftversion}/json`,{ headers: { "User-Agent": "DeEarthX" } })
.json()) as mcinfoX; //获取Minecraft版本JSON
const forgepath = path;
const forgedata = (
await gotx.get(
`forge/download?mcversion=${minecraftversion}&version=${loaderversion}&category=installer&format=jar`
`forge/download?mcversion=${minecraftversion}&version=${loaderversion}&category=installer&format=jar`,
)
).rawBody;
fse.outputFileSync(

View File

@@ -6,7 +6,7 @@ import { LOGGER } from "../utils/logger.js";
import cp from "child_process";
const got = gotx.extend({
prefixUrl: "https://bmclapi2.bangbang93.com",
headers: { "User-Agent": "DeEarthX V2" },
headers: { "User-Agent": "DeEarthX" },
});
interface mcinfoX {

View File

@@ -46,6 +46,7 @@ export class CurseForge implements XPlatform {
"Content-Type": "application/json",
"x-api-key":
"$2a$10$ydk0TLDG/Gc6uPMdz7mad.iisj2TaMDytVcIW4gcVP231VKngLBKy",
"User-Agent": "DeEarthX",
},
})
.json()

View File

@@ -7,9 +7,11 @@
import AdmZip from "adm-zip";
import got from "got";
import fs from "fs";
import crypto from "crypto";
import toml from 'smol-toml'
import path from 'path';
import pMap from "p-map";
import { usemirror } from "./utils.js";
import { LOGGER } from "./logger.js";
import { MultiBar } from "cli-progress";
@@ -19,7 +21,7 @@ export async function DeEarthMain(modspath: string, movepath: any) {
}
LOGGER.info(`DeEarth V1.0.0`)
LOGGER.info(`如有无法筛选的mods请前往 https://dearth.0771010.xyz/ 提交未成功筛选的模组的modid`)
LOGGER.info(`Probejs 7.0.0以上版本为非客户端mod如rubbish中有请自行添加回去`)
LOGGER.info(`Probejs 7.0.0以上版本为非客户端mod.rubbish中有请自行添加回去`)
const resaddr = fs.readdirSync(modspath)
LOGGER.info(`获取目录列表,一共${resaddr.length}个jar文件。`)
const totalBar = multibar.create(resaddr.length, 0, { filename: '总文件数' })
@@ -33,111 +35,29 @@ export async function DeEarthMain(modspath: string, movepath: any) {
}
multibar.stop()
}
/*
export async function DeEarth(modpath: string, movepath: string) {
try {
const zip = new AdmZip(modpath).getEntries();
//for (let i = 0; i < zip.length; i++) {
//const e = zip[i]
try { //Modrinth
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
if (isForge(e.entryName)) { //Forge,NeoForge
const modid = toml.parse(e.getData().toString('utf-8')).mods[0].modId
//const body = await got.get(`https://api.modrinth.com/v2/project/${modid}`, { headers: { "User-Agent": "DeEarth" } }).json()
const body = JSON.parse(await FastGot(`https://api.modrinth.com/v2/project/${modid}`))
if (body.client_side == "required" && body.server_side !== "required") {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else if (e.entryName == "fabric.mod.json") { //Fabric
const modid = JSON.parse(e.getData().toString('utf-8')).id
//const body = await got.get(`https://api.modrinth.com/v2/project/${modid}`, { headers: { "User-Agent": "DeEarth" } }).json()
const body = JSON.parse(await FastGot(`https://api.modrinth.com/v2/project/${modid}`))
if (body.client_side == "required" && body.server_side !== "required") {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
}
console.log("Modrinth")
}
} catch (error) { //mods.toml或fabric.mod.json判断
for (let i = 0; i < zip.length; i++) {
try {
const e = zip[i]
if (isForge(e.entryName)) { //Forge,Neoforge
const modid = toml.parse(e.getData().toString('utf-8')).mods[0].modId
const body = JSON.parse(await FastGot(`https://dearth.0771010.xyz/api/modid?modid=${modid}`))
if (body.isClient) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else if (e.entryName == "fabric.mod.json") { //Fabric
const modid = JSON.parse(e.getData().toString('utf-8')).id
const body = JSON.parse(await FastGot(`https://dearth.0771010.xyz/api/modid?modid=${modid}`))
if (body.isClient) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
}
console.log("DeEarth")
} catch (errorr) {
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
try {
if (isForge(e.entryName)) { //Forge,Neoforge
const tr = toml.parse(e.getData().toString('utf-8'))
const mcside = tr.dependencies[tr.mods[0].modId].find((mod: { modId: string; }) => mod.modId === "minecraft").side
if (mcside == "CLIENT") { //从Minecraft判断
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
const forgeside = tr.dependencies[tr.mods[0].modId].find((mod: { modId: string; }) => mod.modId === "forge").side
if (forgeside == "CLIENT") { //从Forge判断
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
const neoside = tr.dependencies[tr.mods[0].modId].find((mod: { modId: string; }) => mod.modId === "neoforge").side
if (neoside == "CLIENT") { //从NeoForge判断
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else if (e.entryName == "fabric.mod.json") { //Fabric
const fmj = JSON.parse(e.getData().toString('utf-8')).environment
if (fmj == "client") {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
}
} catch (erro) {//从Mixin判断 但是可能为不准确
for (let i = 0; i < zip.length; i++) {
const e = zip[i]
try {
if (isMixinFile(e.entryName)) {
LOGGER.info(e.entryName)
const resx = JSON.parse(e.getData().toString('utf-8'))
if (e.entryName.includes("common.mixins.json")) { //第一步从common mixins文件判断判断失败后再使用modid.mixins.json进行判断
if (isMixin(resx)) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
} else {
if (isMixin(resx)) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
}
}
} catch (err: any) {//避免有傻逼JSON写注释虽然GSON可以这样 但是这样一点也不人道)
if (err.errno !== -4058) {
LOGGER.error(`大天才JSON写注释了估计模组路径:${modpath},过滤失败`)
}
}
}
}
}
}
}
}
} catch (error) {
LOGGER.error("DeEarth: " + error)
}
}
*/
export async function DeEarth(modpath: string, movepath: string) {
let mrurl = "https://api.modrinth.com"
if (usemirror){
mrurl = "https://mod.mcimirror.top/modrinth"
}
let pid:string|undefined = undefined
try {
const data = fs.readFileSync(modpath)
const hash = crypto.createHash('sha1').update(data).digest('hex')
const pjson = await got.get(`${mrurl}/v2/version_file/${hash}?algorithm=sha1`,{
headers:{
"User-Agent": "DeEarth"
}
}).json<{project_id:string}>()
pid = pjson.project_id
//console.log("哈希命中成功正在查询Modrinth")
}catch(e){}
const zipinfo = ZipInfo(modpath)
let modid:string = ""
if(zipinfo){
if(zipinfo.modinfo.type === "forge"){
modid = zipinfo.modinfo.data.mods[0].modId
}else if(zipinfo.modinfo.type === "fabric"){
@@ -145,7 +65,12 @@ export async function DeEarth(modpath: string, movepath: string) {
}
try { //Modrinth
const body = JSON.parse(await FastGot(`https://api.modrinth.com/v2/project/${modid}`))
let body:any
if (pid){
body = JSON.parse(await FastGot(`${mrurl}/v2/project/${pid}`))
}else{
body = JSON.parse(await FastGot(`${mrurl}/v2/project/${modid}`))
}
if(body.client_side == "required" && body.server_side !== "required"){
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}
@@ -153,6 +78,8 @@ export async function DeEarth(modpath: string, movepath: string) {
try {
if (JSON.parse(await FastGot(`https://dearth.0771010.xyz/api/modid?modid=${modid}`)).isClient) {
fs.renameSync(modpath, `${movepath}/${path.basename(modpath)}`)
}else{
throw new Error("DeEarthPublic Not Found This Mod")
}
} catch (error) { //mods.toml或fabric.mod.json判断
try{
@@ -187,6 +114,7 @@ export async function DeEarth(modpath: string, movepath: string) {
}catch(error){
LOGGER.error(`大天才JSON写注释了估计模组路径:${modpath},过滤失败`)
}
}
}
}
}
@@ -197,6 +125,7 @@ function ZipInfo(modpath: string) {
mixins: { filename: string, info: string }[]
modinfo: {type:string,data:any};
}
try{
let zipinfo: ZipInfo = { mixins: [], modinfo: {type: "",data: {}} }
const zip = new AdmZip(modpath).getEntries();
for (let i = 0; i < zip.length; i++) {
@@ -212,6 +141,9 @@ function ZipInfo(modpath: string) {
}
}
return zipinfo;
}catch(error){
LOGGER.error(error)
}
}
async function FastGot(url: string) {
@@ -221,7 +153,7 @@ async function FastGot(url: string) {
try {
if (e[0] !== null) { //防止URL为空
//if(isChinaIpAddress((await got.get("https://4.ipw.cn/")).body)){
return (await got.get(e[0], { headers: { "User-Agent": "DeEarth" } })).body
return (await got.get(e[0], { headers: { "User-Agent": "DeEarthX" } })).body
//}else{
//return (await got.get(`https://mod.mcimirror.top/modrinth/${new URL(e[0]).pathname}`, { headers: { "User-Agent": "DeEarth" } })).body //MCIM源
//}

View File

@@ -10,6 +10,11 @@ import { URL, fileURLToPath } from "node:url";
import { LOGGER } from "./logger.js";
import { exec } from "node:child_process";
export interface ForgeInfo{
minecraft_verison: string,
forge_verison: string
}
export async function readzipentry(
zipfile: yauzl.ZipFile,
entry: yauzl.Entry
@@ -148,7 +153,11 @@ export async function xfastdownload(
path !== null &&
!fs.existsSync(e[1])
) {
const res = (await got.get(e[0])).rawBody; //下载文件
const res = (await got.get(e[0],{
headers: {
"user-agent": "DeEarthX"
}
})).rawBody; //下载文件
await fse.outputFile(e[1], res); //保存文件
}
},