import subprocess
import os
import platform
import shutil
max_ram = 2048
username = os.getenv("null", "cons0leweb")
uuid = os.getenv("MINECRAFT_UUID", "b3f9358c5fc04a42bf5834cb0c940a70")
access_token = os.getenv("MINECRAFT_ACCESS_TOKEN", "") #токен доступа
user_type = os.getenv("MINECRAFT_USER_TYPE", "mojang")
version = os.getenv("MINECRAFT_VERSION", "ff")
game_dir = os.path.expandvars("%APPDATA%/.minecraft")
assets_dir = os.path.join(game_dir, "assets")
asset_index = os.getenv("MINECRAFT_ASSET_INDEX", "1.16")
if not os.path.exists(game_dir):
print(f"Директория игры {game_dir} не существует.")
exit(1)
if not os.path.exists(assets_dir):
print(f"Директория ассетов {assets_dir} не существует.")
exit(1)
version_dir = os.path.join(game_dir, "versions", version)
if not os.path.exists(version_dir):
print(f"Директория версии {version_dir} не существует.")
exit(1)
version_jar = os.path.join(version_dir, f"{version}.jar")
if not os.path.exists(version_jar):
print(f"Файл версии {version_jar} не существует.")
exit(1)
java_path = shutil.which("java")
if not java_path:
print("Java не найдена. Убедитесь, что Java установлена и добавлена в PATH.")
exit(1)
classpath_separator = ":" if platform.system() != "Windows" else ";"
command = [
java_path,
"-XX:+UnlockExperimentalVMOptions",
"-XX:+UseG1GC",
"-XX:G1NewSizePercent=20",
"-XX:G1ReservePercent=20",
"-XX:MaxGCPauseMillis=50",
"-XX:G1HeapRegionSize=32M",
"-XX:+DisableExplicitGC",
"-XX:+AlwaysPreTouch",
"-XX:+ParallelRefProcEnabled",
f"-Xms694M",
f"-Xmx{max_ram}M",
"-Dfile.encoding=UTF-8",
f"-Dlog4j.configurationFile={os.path.join(game_dir, 'assets', 'log_configs', 'patched-variant-2.7.xml')}",
f"-Djava.library.path={os.path.join(game_dir, 'versions', version, 'natives')}",
"-Dminecraft.launcher.brand=java-minecraft-launcher",
"-Dminecraft.launcher.version=1.6.84-j",
"-cp",
classpath_separator.join([
f"{os.path.join(game_dir, 'libraries', 'com', 'turikhay', 'ca-fixer', '1.0', 'ca-fixer-1.0.jar')}",
f"{os.path.join(game_dir, 'libraries', 'optifine', 'OptiFine', '1.16.5_HD_U_G8', 'OptiFine-1.16.5_HD_U_G8.jar')}",
f"{os.path.join(game_dir, 'libraries', 'optifine', 'launchwrapper', '2.2', 'launchwrapper-2.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'ru', 'tlauncher', 'patchy', '1.0.0', 'patchy-1.0.0.jar')}",
f"{os.path.join(game_dir, 'libraries', 'oshi-project', 'oshi-core', '1.1', 'oshi-core-1.1.jar')}",
f"{os.path.join(game_dir, 'libraries', 'net', 'java', 'dev', 'jna', 'jna', '4.4.0', 'jna-4.4.0.jar')}",
f"{os.path.join(game_dir, 'libraries', 'net', 'java', 'dev', 'jna', 'platform', '3.4.0', 'platform-3.4.0.jar')}",
f"{os.path.join(game_dir, 'libraries', 'com', 'ibm', 'icu', 'icu4j', '66.1', 'icu4j-66.1.jar')}",
f"{os.path.join(game_dir, 'libraries', 'com', 'mojang', 'javabridge', '1.0.22', 'javabridge-1.0.22.jar')}",
f"{os.path.join(game_dir, 'libraries', 'net', 'sf', 'jopt-simple', 'jopt-simple', '5.0.3', 'jopt-simple-5.0.3.jar')}",
f"{os.path.join(game_dir, 'libraries', 'io', 'netty', 'netty-all', '4.1.25.Final', 'netty-all-4.1.25.Final.jar')}",
f"{os.path.join(game_dir, 'libraries', 'com', 'google', 'guava', 'guava', '21.0', 'guava-21.0.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'apache', 'commons', 'commons-lang3', '3.5', 'commons-lang3-3.5.jar')}",
f"{os.path.join(game_dir, 'libraries', 'commons-io', 'commons-io', '2.5', 'commons-io-2.5.jar')}",
f"{os.path.join(game_dir, 'libraries', 'commons-codec', 'commons-codec', '1.10', 'commons-codec-1.10.jar')}",
f"{os.path.join(game_dir, 'libraries', 'net', 'java', 'jinput', 'jinput', '2.0.5', 'jinput-2.0.5.jar')}",
f"{os.path.join(game_dir, 'libraries', 'net', 'java', 'jutils', 'jutils', '1.0.0', 'jutils-1.0.0.jar')}",
f"{os.path.join(game_dir, 'libraries', 'com', 'mojang', 'brigadier', '1.0.17', 'brigadier-1.0.17.jar')}",
f"{os.path.join(game_dir, 'libraries', 'com', 'mojang', 'datafixerupper', '4.0.26', 'datafixerupper-4.0.26.jar')}",
f"{os.path.join(game_dir, 'libraries', 'com', 'google', 'code', 'gson', 'gson', '2.8.0', 'gson-2.8.0.jar')}",
f"{os.path.join(game_dir, 'libraries', 'by', 'ely', 'authlib', '3.11.49.2', 'authlib-3.11.49.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'apache', 'commons', 'commons-compress', '1.8.1', 'commons-compress-1.8.1.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'apache', 'httpcomponents', 'httpclient', '4.3.3', 'httpclient-4.3.3.jar')}",
f"{os.path.join(game_dir, 'libraries', 'commons-logging', 'commons-logging', '1.1.3', 'commons-logging-1.1.3.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'apache', 'httpcomponents', 'httpcore', '4.3.2', 'httpcore-4.3.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'it', 'unimi', 'dsi', 'fastutil', '8.2.1', 'fastutil-8.2.1.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'apache', 'logging', 'log4j', 'log4j-api', '2.8.1', 'log4j-api-2.8.1.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'apache', 'logging', 'log4j', 'log4j-core', '2.8.1', 'log4j-core-2.8.1.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'lwjgl', 'lwjgl', '3.2.2', 'lwjgl-3.2.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'lwjgl', 'lwjgl-jemalloc', '3.2.2', 'lwjgl-jemalloc-3.2.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'lwjgl', 'lwjgl-openal', '3.2.2', 'lwjgl-openal-3.2.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'lwjgl', 'lwjgl-opengl', '3.2.2', 'lwjgl-opengl-3.2.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'lwjgl', 'lwjgl-glfw', '3.2.2', 'lwjgl-glfw-3.2.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'lwjgl', 'lwjgl-stb', '3.2.2', 'lwjgl-stb-3.2.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'org', 'lwjgl', 'lwjgl-tinyfd', '3.2.2', 'lwjgl-tinyfd-3.2.2.jar')}",
f"{os.path.join(game_dir, 'libraries', 'com', 'mojang', 'text2speech', '1.11.3', 'text2speech-1.11.3.jar')}",
f"{version_jar}",
]),
"-Xss2M",
"net.minecraft.launchwrapper.Launch",
"-noverify",
"--username", username,
"--version", version,
"--gameDir", game_dir,
"--assetsDir", assets_dir,
"--assetIndex", asset_index,
"--uuid", uuid,
"--accessToken", access_token,
"--userType", user_type,
"--versionType", "modified",
"--width", "925",
"--height", "530",
"--tweakClass", "optifine.OptiFineTweaker"
]
print("Команда запуска:")
print(" ".join(command))
try:
process = subprocess.run(command, capture_output=True, text=True)
print("Вывод процесса:")
print(process.stdout)
print("Ошибки процесса:")
print(process.stderr)
except Exception as e:
print(f"Ошибка при запуске процесса: {e}")