diff --git a/client/client.py b/client/client.py index 9ceab95..730f499 100644 --- a/client/client.py +++ b/client/client.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 -import os, sys, shutil, requests, tempfile, glob +import os, sys, shutil, requests, tempfile, glob, subprocess from termcolor import cprint from typing import Any OS = sys.platform -MOD_DOWNLOADER_URL = "https://github.com/North-West-Wind/CurseForge-CLI/releases/latest/download/curseforge.zip" +MOD_DOWNLOADER_URL = "https://github.com/Advik-B/CMPDL/releases/download/v3.0.0/CMPDL-raw.ZipApp.zip" MODPACK_RELEASES_URL = "https://git.233hfd.com/api/v1/repos/joey/FishPogPixelmon/releases?limit=1" @@ -33,24 +33,71 @@ INSTANCE_DIR = f"{MULTIMC_DIR}/instances/FishPogPixelmon" def __main__(): header() multimc() + needs_mods = instance() + if needs_mods: + mods() + run_mmc() + + +# run +def run_mmc(): + cprint("ready to go! starting multimc!", "green") + os.chdir(MULTIMC_DIR) + + if OS == "windows": + subprocess.Popen(["MultiMC.exe"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + if OS == "linux": + subprocess.Popen(["./MultiMC"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + +# mods +def mods(): + os.chdir(INSTANCE_DIR) + + if not os.path.exists(f"{INSTANCE_DIR}/downloader.zip"): + cprint("downloader.zip not found - downloading", "yellow") + r = requests.get(MOD_DOWNLOADER_URL, allow_redirects=True) + open("downloader.zip", "wb").write(r.content) + + cprint("downloading mods. this may take a while, please wait.", "green") + subprocess.run(["python", "downloader.zip", "manifest.json"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + + for file in glob.glob(f"{INSTANCE_DIR}/mods/*"): + name = os.path.basename(file) + shutil.move(file, os.path.join(f"{INSTANCE_DIR}/.minecraft/mods", name)) + + shutil.rmtree(f"{INSTANCE_DIR}/mods") + + cprint("mods downloaded successfully", "green") # multimc def instance(): + unclean = False release = most_recent_release() if not os.path.exists(INSTANCE_DIR): + unclean = True + cprint("instance not found - downloading", "yellow") download_instance(release) - f = open(".version", "r") - version = f.read() + version = "" + if os.path.exists(f"{INSTANCE_DIR}/.version"): + f = open(f"{INSTANCE_DIR}/.version", "r") + version = f.read() if version != release["tag_name"]: + unclean = True + cprint("new update available! - downloading", "green") download_instance(release) + cprint("instance is up to date", "green") + return unclean + def download_instance(release: dict[str, Any]): - os.makedirs(f"{INSTANCE_DIR}/.minecraft") + os.makedirs(f"{INSTANCE_DIR}/.minecraft", exist_ok=True) TMP = tempfile.mkdtemp() os.chdir(TMP) @@ -58,19 +105,28 @@ def download_instance(release: dict[str, Any]): download_url = get_release_asset(release) r = requests.get(download_url, allow_redirects=True) open("instance.zip", "wb").write(r.content) - shutil.unpack_archive("multimc.zip", ".") - os.remove("multimc.zip") + shutil.unpack_archive("instance.zip", ".") + os.remove("instance.zip") for file in glob.glob(f"{TMP}/overrides/*"): - shutil.move(file, f"INSTANCE_DIR/.minecraft") + if file == f"{TMP}/overrides/options.txt" and os.path.exists(f"{INSTANCE_DIR}/.minecraft/options.txt"): + continue + name = os.path.basename(file) + shutil.move(file, os.path.join(f"{INSTANCE_DIR}/.minecraft", name)) shutil.rmtree(f"{TMP}/overrides") for file in glob.glob(f"{TMP}/*"): - shutil.move(file, INSTANCE_DIR) + name = os.path.basename(file) + shutil.move(file, os.path.join(INSTANCE_DIR, name)) shutil.rmtree(TMP) + os.chdir(INSTANCE_DIR) + shutil.copy( + os.path.join(INSTANCE_DIR, "fishpog_pixelmon.png"), os.path.join(MULTIMC_DIR, "icons", "fishpog_pixelmon.png") + ) + f = open(".version", "w") f.write(release["tag_name"]) f.close() @@ -81,10 +137,10 @@ def multimc(): return if OS != "windows": - cprint("multimc is not installed - please install it", "yellow") + cprint("multimc is not installed - please install it", "red") exit(1) - os.makedirs(MULTIMC_PARENT_DIR) + os.makedirs(MULTIMC_PARENT_DIR, exist_ok=True) os.chdir(MULTIMC_PARENT_DIR) cprint("multimc is not installed - installing", "yellow") diff --git a/modpack/icon.png b/modpack/fishpog_pixelmon.png similarity index 100% rename from modpack/icon.png rename to modpack/fishpog_pixelmon.png diff --git a/modpack/instance.cfg b/modpack/instance.cfg index e971fe9..dbefb99 100644 --- a/modpack/instance.cfg +++ b/modpack/instance.cfg @@ -1,3 +1,6 @@ InstanceType=OneSix -iconKey=icon name=FishPog Pixelmon +JoinServerOnLaunch=true +JoinServerOnLaunchAddress=minecraft.233hfd.com +JoinWorldOnLaunch=true +iconKey=fishpog_pixelmon diff --git a/modpack/mmc-pack.json b/modpack/mmc-pack.json new file mode 100644 index 0000000..d548a70 --- /dev/null +++ b/modpack/mmc-pack.json @@ -0,0 +1,38 @@ +{ + "components": [ + { + "cachedName": "LWJGL 3", + "cachedVersion": "3.2.2", + "cachedVolatile": true, + "dependencyOnly": true, + "uid": "org.lwjgl3", + "version": "3.2.2" + }, + { + "cachedName": "Minecraft", + "cachedRequires": [ + { + "equals": "3.2.2", + "suggests": "3.2.2", + "uid": "org.lwjgl3" + } + ], + "cachedVersion": "1.16.5", + "uid": "net.minecraft", + "version": "1.16.5" + }, + { + "cachedName": "Forge", + "cachedRequires": [ + { + "equals": "1.16.5", + "uid": "net.minecraft" + } + ], + "cachedVersion": "36.2.34", + "uid": "net.minecraftforge", + "version": "36.2.34" + } + ], + "formatVersion": 1 +}