Search in sources :

Example 1 with Library

use of net.technicpack.minecraftcore.mojang.version.io.Library in project LauncherV3 by TechnicPack.

the class MinecraftLauncher method buildClassPath.

private String buildClassPath(ModpackModel pack, MojangVersion version) {
    StringBuilder result = new StringBuilder();
    String separator = System.getProperty("path.separator");
    // if MC < 1.6, we inject LegacyWrapper
    // HACK
    boolean isLegacy = MojangUtils.isLegacyVersion(version.getId());
    final boolean hasModernForge = MojangUtils.hasModernForge(version);
    final String[] versionIdParts = version.getId().split("-");
    final boolean is1_12_2 = versionIdParts[0].equals("1.12.2");
    // Add all the libraries to the classpath.
    for (Library library : version.getLibrariesForOS()) {
        if (library.getNatives() != null) {
            continue;
        }
        // or at least only do it if the users are sticking with modpack.jar
        if (library.isForge()) {
            if (hasModernForge) {
                if (!is1_12_2 && !library.getName().endsWith(":launcher")) {
                    continue;
                } else if (is1_12_2 && !library.getName().endsWith(":universal")) {
                    continue;
                }
            } else {
                continue;
            }
        }
        if (isLegacy && library.getName().startsWith("net.minecraft:launchwrapper")) {
            continue;
        }
        File file = new File(directories.getCacheDirectory(), library.getArtifactPath().replace("${arch}", JavaUtils.getJavaBitness()));
        if (!file.isFile() || !file.exists()) {
            throw new RuntimeException("Library " + library.getName() + " not found.");
        }
        if (result.length() > 1) {
            result.append(separator);
        }
        result.append(file.getAbsolutePath());
    }
    // Add the modpack.jar to the classpath, if it exists and minecraftforge is not a library already
    if (!(MojangUtils.hasModernForge(version))) {
        File modpack = new File(pack.getBinDir(), "modpack.jar");
        if (modpack.exists()) {
            if (result.length() > 1) {
                result.append(separator);
            }
            result.append(modpack.getAbsolutePath());
        }
    }
    // Add the minecraft jar to the classpath
    File minecraft = new File(pack.getBinDir(), "minecraft.jar");
    if (!minecraft.exists()) {
        throw new RuntimeException("Minecraft not installed for this pack: " + pack);
    }
    if (result.length() > 1) {
        result.append(separator);
    }
    result.append(minecraft.getAbsolutePath());
    return result.toString();
}
Also used : Library(net.technicpack.minecraftcore.mojang.version.io.Library) File(java.io.File)

Example 2 with Library

use of net.technicpack.minecraftcore.mojang.version.io.Library in project LauncherV3 by TechnicPack.

the class HandleVersionFileTask method runTask.

@Override
public void runTask(InstallTasksQueue queue) throws IOException, InterruptedException {
    MojangVersion version = versionBuilder.buildVersionFromKey(null);
    if (version == null) {
        throw new DownloadException("The version.json file was invalid.");
    }
    // if MC < 1.6, we inject LegacyWrapper
    // HACK
    boolean isLegacy = MojangUtils.isLegacyVersion(version.getId());
    if (isLegacy) {
        Library legacyWrapper = new Library();
        legacyWrapper.setName("net.technicpack:legacywrapper:1.2.1");
        legacyWrapper.setUrl("https://mirror.technicpack.net/Technic/lib/");
        version.addLibrary(legacyWrapper);
        version.setMainClass("net.technicpack.legacywrapper.Launch");
    }
    // In Forge 1.13+ and 1.12.2 > 2847, there's an installer jar, and the universal jar can't be used since it
    // doesn't have the required dependencies to actually launch the game.
    // So, for Forge 1.13+ we need to use ForgeWrapper to install Forge (it performs deobfuscation at install time).
    // For Forge 1.12.2 it launches directly, as long as we inject the universal jar (it won't launch at all if
    // you try running it through ForgeWrapper).
    final boolean hasModernForge = MojangUtils.hasModernForge(version);
    if (hasModernForge) {
        File profileJson = new File(pack.getBinDir(), "install_profile.json");
        ZipFileRetriever zipVersionRetriever = new ZipFileRetriever(new File(pack.getBinDir(), "modpack.jar"));
        MojangVersion profileVersion = new FileVersionBuilder(profileJson, zipVersionRetriever, null).buildVersionFromKey("install_profile");
        final String[] versionIdParts = version.getId().split("-", 3);
        final boolean is1_12_2 = versionIdParts[0].equals("1.12.2");
        for (Library library : profileVersion.getLibrariesForOS()) {
            if (library.isForge()) {
                // For Forge 1.12.2 > 2847, we have to inject the universal jar as a dependency
                if (is1_12_2) {
                    library.setName(library.getName() + ":universal");
                    library.setUrl("https://files.minecraftforge.net/maven/");
                    // Add the mutated library
                    version.addLibrary(library);
                    checkLibraryQueue.addTask(new InstallVersionLibTask(library, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
                }
                // We normally skip Forge because Forge specifies itself as a dependency, for some reason
                continue;
            }
            checkLibraryQueue.addTask(new InstallVersionLibTask(library, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
        }
        // For Forge 1.13+, we inject our ForgeWrapper as a dependency and launch it through that
        if (!is1_12_2) {
            Library forgeWrapper = new Library();
            // TODO: add hash validation
            forgeWrapper.setName("io.github.zekerzhayard:ForgeWrapper:1.5.1");
            version.addLibrary(forgeWrapper);
            version.setMainClass("io.github.zekerzhayard.forgewrapper.installer.Main");
            for (Library library : version.getLibrariesForOS()) {
                if (library.isForge()) {
                    Library forgeLauncher = new Library();
                    forgeLauncher.setName(library.getName() + ":launcher");
                    forgeLauncher.setUrl("https://files.minecraftforge.net/maven/");
                    version.addLibrary(forgeLauncher);
                    checkLibraryQueue.addTask(new InstallVersionLibTask(forgeLauncher, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
                    Library forgeUniversal = new Library();
                    forgeUniversal.setName(library.getName() + ":universal");
                    forgeUniversal.setUrl("https://files.minecraftforge.net/maven/");
                    checkLibraryQueue.addTask(new InstallVersionLibTask(forgeUniversal, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
                    break;
                }
            }
        }
    }
    for (Library library : version.getLibrariesForOS()) {
        // or at least only do it if the users are sticking with modpack.jar
        if (library.isForge()) {
            continue;
        }
        if (isLegacy && library.getName().startsWith("net.minecraft:launchwrapper")) {
            continue;
        }
        // And version 2.16.0 for >= 1.12
        if (library.isLog4j()) {
            final String[] libNameParts = library.getName().split(":");
            // org.apache.logging.log4j:log4j-core:2.0-beta9
            // org.apache.logging.log4j    log4j-core        2.0-beta9
            // Determine what version we need
            String log4jVersion = "2.16.0";
            if (libNameParts[2].equals("2.0-beta9")) {
                log4jVersion = "2.0-beta9-fixed";
            }
            String sha1;
            int size;
            String artifactName = libNameParts[1];
            switch(log4jVersion) {
                case "2.16.0":
                    switch(artifactName) {
                        case "log4j-api":
                            sha1 = "f821a18687126c2e2f227038f540e7953ad2cc8c";
                            size = 301892;
                            break;
                        case "log4j-core":
                            sha1 = "539a445388aee52108700f26d9644989e7916e7c";
                            size = 1789565;
                            break;
                        case "log4j-slf4j18-impl":
                            sha1 = "0c880a059056df5725f5d8d1035276d9749eba6d";
                            size = 21249;
                            break;
                        default:
                            throw new RuntimeException("Unknown log4j artifact " + artifactName + ", cannot continue");
                    }
                    break;
                case "2.0-beta9-fixed":
                    switch(artifactName) {
                        case "log4j-api":
                            sha1 = "b61eaf2e64d8b0277e188262a8b771bbfa1502b3";
                            size = 107347;
                            break;
                        case "log4j-core":
                            sha1 = "677991ea2d7426f76309a73739cecf609679492c";
                            size = 677588;
                            break;
                        default:
                            throw new RuntimeException("Unknown log4j artifact " + artifactName + ", cannot continue");
                    }
                    break;
                default:
                    throw new RuntimeException("Unknown log4j version " + log4jVersion + ", cannot continue");
            }
            String url = String.format("https://mirror.technicpack.net/Technic/lib/org/apache/logging/log4j/%1$s/%2$s/%1$s-%2$s.jar", artifactName, log4jVersion);
            Library fixedLog4j = new Library();
            fixedLog4j.setName("org.apache.logging.log4j:" + artifactName + ":" + log4jVersion);
            Artifact artifact = new Artifact(url, sha1, size);
            Downloads downloads = new Downloads();
            downloads.setArtifact(artifact);
            fixedLog4j.setDownloads(downloads);
            // Add fixed lib
            version.addLibrary(fixedLog4j);
            checkLibraryQueue.addTask(new InstallVersionLibTask(fixedLog4j, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
            // Remove unpatched lib
            version.removeLibrary(library.getName());
            continue;
        }
        checkLibraryQueue.addTask(new InstallVersionLibTask(library, checkNonMavenLibsQueue, downloadLibraryQueue, copyLibraryQueue, pack, directories));
    }
    queue.setMetadata(version);
}
Also used : FileVersionBuilder(net.technicpack.minecraftcore.mojang.version.builder.FileVersionBuilder) MojangVersion(net.technicpack.minecraftcore.mojang.version.MojangVersion) Artifact(net.technicpack.minecraftcore.mojang.version.io.Artifact) ZipFileRetriever(net.technicpack.minecraftcore.mojang.version.builder.retrievers.ZipFileRetriever) DownloadException(net.technicpack.launchercore.exception.DownloadException) Library(net.technicpack.minecraftcore.mojang.version.io.Library) Downloads(net.technicpack.minecraftcore.mojang.version.io.Downloads) File(java.io.File)

Aggregations

File (java.io.File)2 Library (net.technicpack.minecraftcore.mojang.version.io.Library)2 DownloadException (net.technicpack.launchercore.exception.DownloadException)1 MojangVersion (net.technicpack.minecraftcore.mojang.version.MojangVersion)1 FileVersionBuilder (net.technicpack.minecraftcore.mojang.version.builder.FileVersionBuilder)1 ZipFileRetriever (net.technicpack.minecraftcore.mojang.version.builder.retrievers.ZipFileRetriever)1 Artifact (net.technicpack.minecraftcore.mojang.version.io.Artifact)1 Downloads (net.technicpack.minecraftcore.mojang.version.io.Downloads)1