Skip to content

Instantly share code, notes, and snippets.

@RanolP
Last active November 7, 2022 14:03
Show Gist options
  • Save RanolP/a066622a46bc01f61473b1e5e4acfe05 to your computer and use it in GitHub Desktop.
Save RanolP/a066622a46bc01f61473b1e5e4acfe05 to your computer and use it in GitHub Desktop.
Prism 런처의 기기묘묘한 .index 폴더와 mmc-pack.json을 잘 탐구해서 Curseforge 모드팩을 만들어보자
import { promises as fs } from 'node:fs';
import { join } from 'node:path';
const MODPACK_VERSION = '';
const MODPACK_AUTHOR = '';
const MODPACK_NAME = '';
const mmcPack = JSON.parse(
await fs.readFile('mmc-pack.json', { encoding: 'utf8' })
);
const minecraftVersion = mmcPack.components.find(c => c.uid == 'net.minecraft').version;
const forgeVersion = mmcPack.components.find(c => c.uid == 'net.minecraftforge').version;
const manifest = {
minecraft: {
version: minecraftVersion,
modLoaders: [
{
id: `forge-${forgeVersion}`,
primary: true
}
],
},
manifestType: "minecraftModpack",
overrides: "overrides",
manifestVersion: 1,
version: MODPACK_VERSION,
author: MODPACK_AUTHOR,
name: MODPACK_NAME,
files: [],
};
const ProjectIdRegex = /project-id\s+=\s+([0-9]+)\n/;
const FileIdRegex = /file-id = ([0-9]+)\n/;
const modsIndexDir = '.minecraft/mods/.index';
for (const filename of await fs.readdir(modsIndexDir)) {
const filepath = join(modsIndexDir, filename);
const data = await fs.readFile(filepath, { encoding: 'utf8' });
const [projectID, fileID] = [ProjectIdRegex, FileIdRegex].map(r => r.exec(data)[1]);
manifest.files.push({
projectID,
fileID,
required: true,
});
}
const modInfo = [];
for (const { projectID } of manifest.files) {
const resp = await fetch(`https://api.curse.tools/v1/cf/mods/${projectID}`);
const json = await resp.json();
const data = json.data;
console.log(`Fetched ${data.name}`);
modInfo.push(`<li><a href="${data.links.websiteUrl}">${data.name}(${data.authors[0].name})</a></li>`);
}
try {
await fs.stat('dist');
} catch {
await fs.mkdir('dist');
}
await fs.writeFile('dist/manifest.json', JSON.stringify(manifest));
await fs.writeFile('dist/modlist.html', `<ul>${modInfo.join('')}</ul>`);
@RanolP
Copy link
Author

RanolP commented Nov 7, 2022

📂 your-project
└─📄 mmc-pack.json
└─📄 prism2curse.mjs
└─📂 .minecraft
  └─📂 mods
    └─📂 .index
      └─ 📄 mod-slug1.pw.toml
      └─ 📄 mod-slug2.pw.toml
      └─ 📄 ...

위와 같이 prism2curse.mjs를 넣었을 때 your-project 폴더에서 터미널 열고 Node.js v18로 실행하면 dist/ 폴더에 manifest.json 파일이랑 modlist.html 파일을 만들어준다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment