|
| 1 | +package com.fox2code.foxloader.dev; |
| 2 | + |
| 3 | +import com.fox2code.foxloader.dependencies.DependencyHelper; |
| 4 | +import com.fox2code.foxloader.launcher.BuildConfig; |
| 5 | +import com.fox2code.foxloader.patching.dev.DevelopmentSourcePatcher; |
| 6 | +import com.fox2code.foxloader.patching.game.GamePatches; |
| 7 | +import com.fox2code.foxloader.utils.Platform; |
| 8 | +import com.fox2code.foxloader.utils.SourceUtil; |
| 9 | +import com.fox2code.foxloader.utils.io.CertificateHelper; |
| 10 | +import org.objectweb.asm.Type; |
| 11 | + |
| 12 | +import java.io.File; |
| 13 | +import java.io.IOException; |
| 14 | + |
| 15 | +/** |
| 16 | + * Used for debugging FoxLoader dev plugin. |
| 17 | + */ |
| 18 | +public class Main { |
| 19 | + private static final File SELF_ABS_FILE = new File(".").getAbsoluteFile(); |
| 20 | + private static final File PATCHED = new File(SELF_ABS_FILE, BuildConfig.DEV_PATCHED_JAR_NAME); |
| 21 | + private static final File UNPICKED = new File(SELF_ABS_FILE, |
| 22 | + BuildConfig.DEV_PATCHED_JAR_NAME.replace(".jar", "-unpicked.jar")); |
| 23 | + private static final File DECOMPILED = new File(SELF_ABS_FILE, |
| 24 | + BuildConfig.DEV_PATCHED_JAR_NAME.replace(".jar", "-sources.jar")); |
| 25 | + |
| 26 | + static { |
| 27 | + DependencyHelper.DependencyImpl.install(DevDependencyImpl.INSTANCE); |
| 28 | + } |
| 29 | + |
| 30 | + public static void main(String[] args) throws IOException, InterruptedException { |
| 31 | + if (args.length == 0 || "help".equals(args[0])) { |
| 32 | + System.out.println("FoxLoader dev plugin cli debug!"); |
| 33 | + System.out.println(" version -> Show FoxLoader version"); |
| 34 | + System.out.println(" unpick -> Full unpick test"); |
| 35 | + System.out.println(" decomp -> Full decompile test"); |
| 36 | + return; |
| 37 | + } |
| 38 | + switch (args[0]) { |
| 39 | + case "version": { |
| 40 | + System.out.println( |
| 41 | + "FoxLoader " + BuildConfig.FOXLOADER_VERSION + |
| 42 | + " for ReIndev " + BuildConfig.REINDEV_VERSION); |
| 43 | + break; |
| 44 | + } |
| 45 | + case "unpick": { |
| 46 | + deleteAllDecompFiles(); |
| 47 | + System.out.println("Loading patching dependencies..."); |
| 48 | + loadPatchingDependencies(); |
| 49 | + System.out.println("Acquiring slim jar..."); |
| 50 | + File slimJar = DependencyHelper.loadDependencyAsFile(DependencyHelper.reIndevDependencySlim); |
| 51 | + System.out.println("Patching slim jar..."); |
| 52 | + GamePatches.patchSlimJar(slimJar, PATCHED); |
| 53 | + System.out.println("Unpicking patched jar..."); |
| 54 | + DevelopmentSourcePatcher.unpickPatchedJar(PATCHED, UNPICKED); |
| 55 | + break; |
| 56 | + } |
| 57 | + case "decomp": { |
| 58 | + if (DependencyHelper.vineFlower.javaSupport > Platform.getJvmVersion()) { |
| 59 | + throw new RuntimeException("VineFlower requires at least java " + |
| 60 | + DependencyHelper.vineFlower.javaSupport + " to run!"); |
| 61 | + } |
| 62 | + deleteAllDecompFiles(); |
| 63 | + System.out.println("Loading patching dependencies..."); |
| 64 | + loadPatchingDependencies(); |
| 65 | + DependencyHelper.loadDependencyAsFile(DependencyHelper.vineFlower); |
| 66 | + System.out.println("Acquiring slim jar..."); |
| 67 | + File slimJar = DependencyHelper.loadDependencyAsFile(DependencyHelper.reIndevDependencySlim); |
| 68 | + System.out.println("Patching slim jar..."); |
| 69 | + GamePatches.patchSlimJar(slimJar, PATCHED); |
| 70 | + System.out.println("Unpicking patched jar..."); |
| 71 | + DevelopmentSourcePatcher.unpickPatchedJar(PATCHED, UNPICKED); |
| 72 | + System.out.println("Decompiling unpicked jar..."); |
| 73 | + DecompileHelper.decompileExec(); |
| 74 | + break; |
| 75 | + } |
| 76 | + default: { |
| 77 | + System.out.println("Unknown command: " + args[0]); |
| 78 | + break; |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + private static void loadPatchingDependencies() { |
| 84 | + CertificateHelper.initializeSafe(); |
| 85 | + DependencyHelper.setMCLibraryRoot(new File(Platform.getAppDir("minecraft"), "libraries")); |
| 86 | + for (DependencyHelper.Dependency dependency : DependencyHelper.commonDependencies) { |
| 87 | + if (dependency.name.startsWith("org.ow2.asm:")) { |
| 88 | + DependencyHelper.loadDependencySelf(dependency); |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + private static void deleteAllDecompFiles() throws IOException { |
| 94 | + if (PATCHED.exists() && !PATCHED.delete()) { |
| 95 | + throw new IOException("Failed to delete patched file!"); |
| 96 | + } |
| 97 | + if (UNPICKED.exists() && !UNPICKED.delete()) { |
| 98 | + throw new IOException("Failed to delete unpicked file!"); |
| 99 | + } |
| 100 | + if (DECOMPILED.exists() && !DECOMPILED.delete()) { |
| 101 | + throw new IOException("Failed to delete decompiled file!"); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + private static class DecompileHelper { |
| 106 | + private static void decompileExec() throws IOException, InterruptedException { |
| 107 | + // Equivalent of: new FoxLoaderDecompiler(unpickedJarFox, sourcesJarFox).decompile() |
| 108 | + FoxJavaExec foxJavaExec = new FoxJavaExec(Platform.getPlatform().javaBin); |
| 109 | + foxJavaExec.addFile(SourceUtil.getSourceFile(Type.class)); |
| 110 | + foxJavaExec.addFile(SourceUtil.getSourceFile(DecompileHelper.class)); |
| 111 | + foxJavaExec.addFile(DependencyHelper.loadDependencyAsFile(DependencyHelper.vineFlower)); |
| 112 | + foxJavaExec.setMainClass("com.fox2code.foxloader.decompiler.FoxLoaderDecompiler"); |
| 113 | + foxJavaExec.exec("default", Main.UNPICKED.getAbsolutePath(), Main.DECOMPILED.getAbsolutePath()); |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments