forked from Isma/mods
1
0
Fork 0
mccom2023/manifest

228 lines
7.0 KiB
Plaintext

// This variables can be changed :)
global._ = {
pack_id: "mccom2023",
version: "1.5.0",
author: "MCommunity",
name: "MCommunity",
description: "MCommunity official modpack.",
icon: "https://storage.ragestudio.net/gose-uploads/mccom/MCx128.png",
gitSource: "https://git.ragestudio.net/srgooglo/mccom2023",
mcVersion: "1.20.1",
forgeVersion: "47.2.0",
installForge: false,
}
const os = require("node:os")
const path = require("node:path")
const fs = require("node:fs")
const child_process = require("node:child_process")
async function readImageToB64(_path) {
const image = fs.readFileSync(_path)
const extension = path.extname(_path)
return `data:image/${extension};base64,${image.toString("base64")}`
}
function resolveMcPath() {
let minecraftGameFolder = null
switch (os.type()) {
case "Darwin":
minecraftGameFolder = path.join(
os.homedir(),
"/Library",
"Application Support",
"minecraft"
)
break
case "win32":
case "Windows_NT":
minecraftGameFolder = path.join(
process.env.APPDATA ||
path.join(os.homedir(), "AppData", "Roaming"),
".minecraft"
)
break
default:
minecraftGameFolder = path.join(os.homedir(), ".minecraft")
break
}
return minecraftGameFolder
}
function resolveMinecraftLauncher(args, cwd) {
let _path = null
switch (os.type()) {
case "Windows_NT": {
_path = path.resolve(cwd, "runwin.bat")
break
}
case "Darwin": {
_path = "/Applications/Minecraft.app/Contents/MacOS/launcher"
break
}
default: {
_path = null
}
}
if (_path && Array.isArray(args) && os.type() !== "Windows_NT") {
_path = [_path, ...args].join(" ")
}
return _path
}
module.exports = {
id: global._.pack_id,
version: global._.version,
icon: global._.icon,
pack_name: global._.name,
description: global._.description,
author: global._.author,
configs: {
assignedRam: 4096,
},
executable: true,
init: ({ pack_dir, tmp_dir }) => {
const data = {
git_update: [
{
path: pack_dir,
branch: "main",
url: global._.gitSource
}
],
git_clones_steps: [
{
path: pack_dir,
branch: "main",
url: global._.gitSource
}
],
http_downloads: [
{
path: `${pack_dir}/icon/mc.png`,
url: global._.icon,
}
]
}
if (global._.installForge) {
data.http_downloads.push({
path: `${pack_dir}/tmp/forge-installer.jar`,
url: `https://maven.minecraftforge.net/net/minecraftforge/forge/${global._.mcVersion}/forge-${global._.forgeVersion}-installer.jar`,
})
}
return data
},
after_install: async ({ manifest, pack_dir, tmp_dir }) => {
if (global._.forgeVersion) {
console.log("Installing forge...")
await new Promise((resolve, reject) => {
const process = child_process.execFile("java", ["-jar", `${pack_dir}/tmp/forge-installer.jar`, "-installClient"], {
cwd: pack_dir,
shell: true,
})
process.on("exit", resolve)
process.on("error", reject)
})
}
const minecraftGameFolder = resolveMcPath()
const legacy_ProfilesFilePath = path.resolve(minecraftGameFolder, "launcher_profiles.json")
const profilesFilePath = path.resolve(pack_dir, "launcher_profiles.json")
let profiles_json = {
version: 3,
settings: {
"crashAssistance": true,
"enableAdvanced": false,
"enableAnalytics": true,
"enableHistorical": false,
"enableReleases": true,
"enableSnapshots": false,
"keepLauncherOpen": false,
"profileSorting": "ByLastPlayed",
"showGameLog": false,
"showMenu": false,
"soundOn": false
},
profiles: {},
}
let legacy_profiles_json = JSON.parse(fs.readFileSync(legacy_ProfilesFilePath))
const profileData = {
name: manifest.pack_name,
gameDir: pack_dir,
created: "2023-00-00T00:00:00.002Z",
javaArgs: `-Xmx${manifest.configs.assignedRam}M -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M`,
lastVersionId: `${global._.mcVersion}-forge-${global._.forgeVersion}`,
version: `${global._.mcVersion}-forge-${global._.forgeVersion}`,
type: "custom",
icon: await readImageToB64(`${pack_dir}/icon/mc.png`),
}
legacy_profiles_json.profiles[manifest.id] = profileData
profiles_json.profiles[manifest.id] = profileData
fs.writeFileSync(profilesFilePath, JSON.stringify(profiles_json, null, 2))
fs.writeFileSync(legacy_ProfilesFilePath, JSON.stringify(legacy_profiles_json, null, 2))
if (os.type() === "Windows_NT") {
const runwinBat = path.resolve(pack_dir, "runwin.bat")
fs.writeFileSync(runwinBat, `
@echo off
cd "%ProgramFiles(x86)%/Minecraft Launcher"
start MinecraftLauncher.exe --workDir "${pack_dir}"
`, { encoding: 'utf8' })
}
},
uninstall: async ({ manifest, pack_dir, tmp_dir }) => {
const minecraftGameFolder = resolveMcPath()
const profilesFilePath = path.join(minecraftGameFolder, "launcher_profiles.json")
if (fs.existsSync(profilesFilePath)) {
let launcherJSON = fs.readFileSync(profilesFilePath, "utf8")
launcherJSON = JSON.parse(launcherJSON)
delete launcherJSON.profiles[manifest.id]
fs.writeFileSync(profilesFilePath, JSON.stringify(launcherJSON, null, 2))
}
},
execute: async ({ manifest, pack_dir, tmp_dir }) => {
const launcherBin = resolveMinecraftLauncher([`--workDir ${pack_dir}`], os.type() === "Windows_NT" ? pack_dir : undefined)
console.log(`Launching at >`, launcherBin)
if (!launcherBin) {
throw new Error("Minecraft Launcher binary not found")
}
await new Promise((resolve, reject) => {
const process = child_process.execFile(launcherBin, [], {
shell: true,
})
process.on("exit", resolve)
process.on("error", reject)
})
}
}