diff --git a/build.gradle b/build.gradle index 2cc27e478..d800caaa4 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ repositories { excludeGroupByRegex "org\\.eclipse\\.?.*" } } + maven { url "https://jitpack.io" } mavenLocal() } @@ -113,7 +114,7 @@ dependencies { // Forge patches implementation ('net.minecraftforge:installertools:1.2.0') - implementation ('net.minecraftforge:binarypatcher:1.1.1') + implementation ('com.github.wagyourtail:BinaryPatcher:383bae7aa3') implementation ('org.cadixdev:lorenz:0.5.3') implementation ('org.cadixdev:lorenz-asm:0.5.3') implementation ('de.oceanlabs.mcp:mcinjector:3.8.0') diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/forge/McpConfigProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/forge/McpConfigProvider.java index 75f565af6..0ab287a77 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/forge/McpConfigProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/forge/McpConfigProvider.java @@ -80,6 +80,9 @@ public void provide(DependencyInfo dependency, Consumer postPopulation mappingsPath = ZipUtils.contains(mcpZip, "joined.srg") ? "joined.srg" : "config/joined.tsrg"; isSRG = mappingsPath.endsWith(".srg"); remapAction = new FG2RemapAction(getProject()); + if (!Files.exists(mcp) || isRefreshDeps()) { + Files.copy(mcpZip, mcp, StandardCopyOption.REPLACE_EXISTING); + } return; } @@ -172,7 +175,7 @@ public static class FG2RemapAction implements RemapAction { public FG2RemapAction(Project project) { this.project = project; - this.name = "net.md-5:SpecialSource:1.8.3:shaded"; + this.name = "net.md-5:SpecialSource:1.7.4:shaded"; this.mainClasspath = DependencyDownloader.download(project, this.name, false, true) .getSingleFile(); this.classpath = DependencyDownloader.download(project, this.name, true, true); diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/forge/MinecraftPatchedProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/forge/MinecraftPatchedProvider.java index 8389f3a28..52c34c931 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/forge/MinecraftPatchedProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/forge/MinecraftPatchedProvider.java @@ -341,15 +341,17 @@ private void createSrgJars(Logger logger) throws Exception { produceSrgJar(getExtension().isForgeAndOfficial(), minecraftProvider.minecraftClientJar.toPath(), minecraftProvider.getMinecraftServerJar().toPath()); } - private void produceSrgJar(boolean official, Path clientJar, Path serverJar) throws IOException { + private void produceSrgJar(boolean official, Path clientJar, Path serverJar) throws Exception { Path tmpSrg = getToSrgMappings(); Set mcLibs = getProject().getConfigurations().getByName(Constants.Configurations.MINECRAFT_DEPENDENCIES).resolve(); - ThreadingUtils.run(() -> { - Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "client", mcLibs, clientJar, tmpSrg), minecraftClientSrgJar.toPath()); - }, () -> { - Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "server", mcLibs, serverJar, tmpSrg), minecraftServerSrgJar.toPath()); - }); + boolean isSrg = getExtension().getMcpConfigProvider().isSRG(); + +// ThreadingUtils.run(() -> { + Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "client", mcLibs, clientJar, tmpSrg, isSrg), minecraftClientSrgJar.toPath()); +// }, () -> { + Files.copy(SpecialSourceExecutor.produceSrgJar(getExtension().getMcpConfigProvider().getRemapAction(), getProject(), "server", mcLibs, serverJar, tmpSrg, isSrg), minecraftServerSrgJar.toPath()); +// }); } private Path getToSrgMappings() throws IOException { @@ -605,7 +607,9 @@ private void patchJars(Logger logger) throws IOException { PatchProvider patchProvider = getExtension().getPatchProvider(); patchJars(minecraftClientSrgJar, minecraftClientPatchedSrgJar, patchProvider.clientPatches); - patchJars(minecraftServerSrgJar, minecraftServerPatchedSrgJar, patchProvider.serverPatches); + if (!getExtension().getMcpConfigProvider().isSRG()) { + patchJars(minecraftServerSrgJar, minecraftServerPatchedSrgJar, patchProvider.serverPatches); + } ThreadingUtils.run(Environment.values(), environment -> { copyMissingClasses(environment.srgJar.apply(this), environment.patchedSrgJar.apply(this)); @@ -628,12 +632,22 @@ private void patchJars(File clean, File output, Path patches) throws IOException // Failed to replace logger filter, just ignore } - ConsoleTool.main(new String[] { + if (getExtension().getMcpConfigProvider().isSRG()) { + + ConsoleTool.main(new String[] { "--clean", clean.getAbsolutePath(), "--output", output.getAbsolutePath(), "--apply", patches.toAbsolutePath().toString(), - "--pack200" - }); + "--legacy" + }); + + } else { + ConsoleTool.main(new String[] { + "--clean", clean.getAbsolutePath(), + "--output", output.getAbsolutePath(), + "--apply", patches.toAbsolutePath().toString() + }); + } try { System.setOut(previous); diff --git a/src/main/java/net/fabricmc/loom/util/srg/SpecialSourceExecutor.java b/src/main/java/net/fabricmc/loom/util/srg/SpecialSourceExecutor.java index 59392e944..a54ef7a90 100644 --- a/src/main/java/net/fabricmc/loom/util/srg/SpecialSourceExecutor.java +++ b/src/main/java/net/fabricmc/loom/util/srg/SpecialSourceExecutor.java @@ -56,18 +56,30 @@ private static String trimLeadingSlash(String string) { return string; } - public static Path produceSrgJar(RemapAction remapAction, Project project, String side, Set mcLibs, Path officialJar, Path mappings) + public static Path produceSrgJar(RemapAction remapAction, Project project, String side, Set mcLibs, Path officialJar, Path mappings, boolean isSrg) throws Exception { - Set filter = Files.readAllLines(mappings, StandardCharsets.UTF_8).stream() + Set filter; + if (isSrg) { + filter = Files.readAllLines(mappings, StandardCharsets.UTF_8).stream() + .filter(s -> s.startsWith("CL:")) + .map(s -> s.split(" ")[1] + ".class") + .collect(Collectors.toSet()); + } else { + filter = Files.readAllLines(mappings, StandardCharsets.UTF_8).stream() .filter(s -> !s.startsWith("\t")) .map(s -> s.split(" ")[0] + ".class") .collect(Collectors.toSet()); + } LoomGradleExtension extension = LoomGradleExtension.get(project.getProject()); Path stripped = extension.getFiles().getProjectBuildCache().toPath().resolve(officialJar.getFileName().toString().substring(0, officialJar.getFileName().toString().length() - 4) + "-filtered.jar"); Files.deleteIfExists(stripped); + project.getLogger().info(officialJar.toString()); + Stopwatch stopwatch = Stopwatch.createStarted(); + int count = 0; + try (FileSystemUtil.Delegate output = FileSystemUtil.getJarFileSystem(stripped, true)) { try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(officialJar, false)) { ThreadingUtils.TaskCompleter completer = ThreadingUtils.taskCompleter(); @@ -91,18 +103,20 @@ public static Path produceSrgJar(RemapAction remapAction, Project project, Strin completer.add(() -> { Files.copy(path, to, StandardCopyOption.COPY_ATTRIBUTES); }); + count++; } completer.complete(); } } finally { - project.getLogger().info("Copied class files in " + stopwatch.stop()); + project.getLogger().info("Copied " + count + " class files in " + stopwatch.stop()); } Path output = extension.getFiles().getProjectBuildCache().toPath().resolve(officialJar.getFileName().toString().substring(0, officialJar.getFileName().toString().length() - 4) + "-srg-output.jar"); Files.deleteIfExists(output); stopwatch = Stopwatch.createStarted(); + project.getLogger().info(stripped.toString()); List args = remapAction.getArgs(stripped, output, mappings, project.files(mcLibs)); project.getLogger().lifecycle(":remapping minecraft (" + remapAction + ", " + side + ", official -> mojang)");