allow using either Enigma or Tiny for remapping JAR

dev/0.11
Adrian Siekierka 2018-10-27 18:20:29 +02:00
parent fdd4334a15
commit 2668cae022
9 changed files with 239 additions and 54 deletions

View File

@ -53,7 +53,10 @@ dependencies {
shade ('net.fabricmc:weave:+'){
transitive = false
}
shade 'net.fabricmc:tiny-remapper:0.1.0.5'
shade ('enigma-asm:enigma:0.12.0.+:lib'){
exclude group: 'org.ow2.asm'
}
shade 'net.fabricmc:tiny-remapper:0.1.0.12'
shade 'net.sf.jopt-simple:jopt-simple:5.0.4'
shade 'org.apache.logging.log4j:log4j-api:2.11.1'
shade 'org.apache.logging.log4j:log4j-core:2.11.1'

View File

@ -24,6 +24,7 @@
package net.fabricmc.loom;
import net.fabricmc.loom.util.Constants;
import org.gradle.api.Project;
import java.io.File;
@ -34,7 +35,7 @@ public class LoomGradleExtension {
public String fabricVersion;
public String pomfVersion;
public String refmapName;
public boolean skipPrebake = false;
public String jarMapper = Constants.JAR_MAPPER_ENIGMA; // enigma, tiny
public boolean localMappings = false;
//Not to be set in the build.gradle

View File

@ -25,8 +25,10 @@
package net.fabricmc.loom;
import net.fabricmc.loom.task.*;
import net.fabricmc.loom.util.Constants;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.Task;
public class LoomGradlePlugin extends AbstractPlugin {
@Override

View File

@ -40,6 +40,7 @@ import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.logging.Logger;
import org.gradle.api.tasks.TaskAction;
import org.spongepowered.asm.mixin.injection.Constant;
import java.io.*;
import java.net.URL;
@ -72,17 +73,34 @@ public class DownloadTask extends DefaultTask {
Constants.POMF_DIR.get(extension).mkdir();
}
if (Constants.JAR_MAPPER_ENIGMA.equals(extension.jarMapper)) {
if (!Constants.MAPPINGS_ENIGMA_ZIP.get(extension).exists() && extension.hasPomf()) {
this.getLogger().lifecycle(":downloading enigma mappings");
try {
FileUtils.copyURLToFile(
new URL(Constants.POMF_JENKINS_SERVER + "/job/FabricMC/job/pomf/job/" + extension.version + "/" + extension.pomfVersion + "/artifact/build/libs/pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip"),
Constants.MAPPINGS_ENIGMA_ZIP.get(extension)
);
} catch (Exception e) {
throw new RuntimeException("Failed to download mappings", e);
}
}
}
if (!extension.hasPomf()) {
if (Constants.MAPPINGS_DIR_LOCAL.get(extension).exists()) {
if (Constants.MAPPINGS_TINY_GZ_LOCAL.get(extension).exists() && Constants.MAPPINGS_ZIP_LOCAL.get(extension).exists()) {
if (Constants.MAPPINGS_TINY_GZ_LOCAL.get(extension).exists() && (!Constants.JAR_MAPPER_ENIGMA.equals(extension.jarMapper) || Constants.MAPPINGS_ENIGMA_ZIP_LOCAL.get(extension).exists())) {
this.getLogger().lifecycle(":using local mappings!");
extension.localMappings = true;
//We delete this to make sure they are always re extracted.
deleteIfExists(Constants.MAPPINGS_ENIGMA_DIR.get(extension));
deleteIfExists(Constants.MAPPINGS_ENIGMA_ZIP.get(extension));
deleteIfExists(Constants.MAPPINGS_TINY_GZ.get(extension));
deleteIfExists(Constants.MAPPINGS_TINY.get(extension));
Constants.MAPPINGS_TINY_GZ = Constants.MAPPINGS_TINY_GZ_LOCAL;
Constants.MAPPINGS_ENIGMA_ZIP = Constants.MAPPINGS_ENIGMA_ZIP_LOCAL;
}
}
}
@ -91,7 +109,7 @@ public class DownloadTask extends DefaultTask {
if (!Constants.MAPPINGS_TINY_GZ.get(extension).exists() && !extension.localMappings) {
getLogger().lifecycle(":downloading tiny mappings");
try {
FileUtils.copyURLToFile(new URL("http://modmuss50.me:8080/job/FabricMC/job/pomf/job/" + extension.version + "/" + extension.pomfVersion + "/artifact/build/libs/pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz"), Constants.MAPPINGS_TINY_GZ.get(extension));
FileUtils.copyURLToFile(new URL(Constants.POMF_JENKINS_SERVER + "/job/FabricMC/job/pomf/job/" + extension.version + "/" + extension.pomfVersion + "/artifact/build/libs/pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz"), Constants.MAPPINGS_TINY_GZ.get(extension));
} catch (Exception e) {
throw new RuntimeException("Failed to download mappings", e);
}

View File

@ -35,7 +35,7 @@ import java.io.IOException;
public class FinaliseJar extends DefaultTask {
@TaskAction
public void finalisejar() throws IOException {
public void finaliseJar() throws IOException {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
if(Constants.MINECRAFT_FINAL_JAR.get(extension).exists()){
Constants.MINECRAFT_FINAL_JAR.get(extension).delete();

View File

@ -0,0 +1,118 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.task;
import cuchaz.enigma.Deobfuscator;
import cuchaz.enigma.TranslatingTypeLoader;
import cuchaz.enigma.mapping.MappingsEnigmaReader;
import cuchaz.enigma.mapping.TranslationDirection;
import cuchaz.enigma.mapping.Translator;
import cuchaz.enigma.mapping.entry.ReferencedEntryPool;
import cuchaz.enigma.throwables.MappingParseException;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import org.zeroturnaround.zip.ZipUtil;
import org.zeroturnaround.zip.commons.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.jar.JarFile;
public class MapJarsEnigma {
Deobfuscator deobfuscator;
public void mapJars(MapJarsTask task) throws IOException, MappingParseException {
LoomGradleExtension extension = task.getProject().getExtensions().getByType(LoomGradleExtension.class);
if (!Constants.MINECRAFT_MAPPED_JAR.get(extension).exists() || extension.localMappings || true) {
if(Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()){
Constants.MINECRAFT_MAPPED_JAR.get(extension).delete();
}
if (!extension.hasPomf()) {
task.getLogger().lifecycle("POMF version not set, skipping mapping!");
FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), Constants.MINECRAFT_MAPPED_JAR.get(extension));
return;
}
if (!Constants.MAPPINGS_ENIGMA_DIR.get(extension).exists() || extension.localMappings) {
task.getLogger().lifecycle(":unpacking mappings");
FileUtils.deleteDirectory(Constants.MAPPINGS_ENIGMA_DIR.get(extension));
ZipUtil.unpack(Constants.MAPPINGS_ENIGMA_ZIP.get(extension), Constants.MAPPINGS_ENIGMA_DIR.get(extension));
}
task.getLogger().lifecycle(":remapping jar (Enigma)");
deobfuscator = new Deobfuscator(new JarFile(Constants.MINECRAFT_MERGED_JAR.get(extension)));
deobfuscator.setMappings(new MappingsEnigmaReader().read(Constants.MAPPINGS_ENIGMA_DIR.get(extension)));
writeJar(Constants.MINECRAFT_PARTIAL_ENIGMA_JAR.get(extension), new ProgressListener(), deobfuscator);
File tempAssets = new File(Constants.CACHE_FILES, "tempAssets");
if (tempAssets.exists()) {
FileUtils.deleteDirectory(tempAssets);
}
tempAssets.mkdir();
ZipUtil.unpack(Constants.MINECRAFT_CLIENT_JAR.get(extension), tempAssets, name -> {
if (!name.endsWith(".class") && !name.startsWith("META-INF")) {
return name;
} else {
return null;
}
});
ZipUtil.unpack(Constants.MINECRAFT_PARTIAL_ENIGMA_JAR.get(extension), tempAssets);
ZipUtil.pack(tempAssets, Constants.MINECRAFT_MAPPED_JAR.get(extension));
FileUtils.deleteDirectory(tempAssets);
} else {
task.getLogger().lifecycle(Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath());
task.getLogger().lifecycle(":mapped jar found, skipping mapping");
}
}
public void writeJar(File out, Deobfuscator.ProgressListener progress, Deobfuscator deobfuscator) {
Translator obfuscationTranslator = deobfuscator.getTranslator(TranslationDirection.OBFUSCATING);
Translator deobfuscationTranslator = deobfuscator.getTranslator(TranslationDirection.DEOBFUSCATING);
TranslatingTypeLoader loader = new TranslatingTypeLoader(deobfuscator.getJar(), deobfuscator.getJarIndex(), new ReferencedEntryPool(), obfuscationTranslator, deobfuscationTranslator);
deobfuscator.transformJar(out, progress, loader::transformInto);
}
public static class ProgressListener implements Deobfuscator.ProgressListener {
@Override
public void init(int i, String s) {
}
@Override
public void onProgress(int i, String s) {
}
}
}

View File

@ -24,71 +24,34 @@
package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import org.zeroturnaround.zip.ZipUtil;
import org.zeroturnaround.zip.commons.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
public class MapJarsTask extends DefaultTask {
@TaskAction
public void mapJars() throws IOException {
public void mapJars() throws Exception {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
if (!Constants.MINECRAFT_MAPPED_JAR.get(extension).exists() || extension.localMappings || true) {
if(Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()){
Constants.MINECRAFT_MAPPED_JAR.get(extension).delete();
}
if (!extension.hasPomf()) {
this.getLogger().lifecycle("POMF version not set, skipping mapping!");
FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), Constants.MINECRAFT_MAPPED_JAR.get(extension));
return;
}
String fromM = "mojang";
String toM = "pomf";
Path mappings = Constants.MAPPINGS_TINY.get(extension).toPath();
Path[] classpath = getProject().getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles().stream()
.map(File::toPath)
.toArray(Path[]::new);
this.getLogger().lifecycle(":remapping minecraft to " + toM);
TinyRemapper remapper = TinyRemapper.newRemapper()
.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM))
.build();
try {
OutputConsumerPath outputConsumer = new OutputConsumerPath(Constants.MINECRAFT_MAPPED_JAR.get(extension).toPath());
outputConsumer.addNonClassFiles(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath());
remapper.read(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath());
remapper.read(classpath);
remapper.apply(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath(), outputConsumer);
outputConsumer.finish();
remapper.finish();
} catch (Exception e){
remapper.finish();
throw new RuntimeException("Failed to remap minecraft to " + toM, e);
if (Constants.JAR_MAPPER_ENIGMA.equals(extension.jarMapper)) {
new MapJarsEnigma().mapJars(this);
} else if (Constants.JAR_MAPPER_TINY.equals(extension.jarMapper)) {
new MapJarsTiny().mapJars(this);
} else {
throw new RuntimeException("Unknown JAR mapper type: " + extension.jarMapper);
}
File tempAssets = new File(Constants.CACHE_FILES, "tempAssets");
if (tempAssets.exists()) {
FileUtils.deleteDirectory(tempAssets);
}
tempAssets.mkdir();
FileUtils.deleteDirectory(tempAssets);
} else {
this.getLogger().lifecycle(Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath());
this.getLogger().lifecycle(":mapped jar found, skipping mapping");

View File

@ -0,0 +1,74 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import org.zeroturnaround.zip.ZipUtil;
import org.zeroturnaround.zip.commons.FileUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
public class MapJarsTiny {
public void mapJars(MapJarsTask task) throws IOException {
LoomGradleExtension extension = task.getProject().getExtensions().getByType(LoomGradleExtension.class);
String fromM = "mojang";
String toM = "pomf";
Path mappings = Constants.MAPPINGS_TINY.get(extension).toPath();
Path[] classpath = task.getProject().getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles().stream()
.map(File::toPath)
.toArray(Path[]::new);
task.getLogger().lifecycle(":remapping minecraft (TinyRemapper, " + fromM + " -> " + toM + ")");
TinyRemapper remapper = TinyRemapper.newRemapper()
.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM))
.build();
try {
OutputConsumerPath outputConsumer = new OutputConsumerPath(Constants.MINECRAFT_MAPPED_JAR.get(extension).toPath());
outputConsumer.addNonClassFiles(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath());
remapper.read(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath());
remapper.read(classpath);
remapper.apply(Constants.MINECRAFT_MERGED_JAR.get(extension).toPath(), outputConsumer);
outputConsumer.finish();
remapper.finish();
} catch (Exception e){
remapper.finish();
throw new RuntimeException("Failed to remap minecraft to " + toM, e);
}
}
}

View File

@ -37,20 +37,25 @@ public class Constants {
public static final File WORKING_DIRECTORY = new File(".");
public static final File CACHE_FILES = new File(WORKING_DIRECTORY, ".gradle/minecraft");
public static final String JAR_MAPPER_ENIGMA = "enigma";
public static final String JAR_MAPPER_TINY = "tiny";
public static final IDelayed<File> MINECRAFT_CLIENT_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-client.jar"));
public static final IDelayed<File> MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-server.jar"));
public static final IDelayed<File> MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-merged.jar"));
public static final IDelayed<File> MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-mapped-" + extension.pomfVersion + ".jar"));
public static final IDelayed<File> MINECRAFT_PARTIAL_ENIGMA_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-partial-enigma-" + extension.pomfVersion + ".jar"));
public static final IDelayed<File> MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.version + "-final-" + extension.pomfVersion + ".jar"));
public static final IDelayed<File> POMF_DIR = new DelayedFile(extension -> new File(extension.getUserCache(), "pomf"));
public static IDelayed<File> MAPPINGS_TINY_GZ = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz"));
public static final IDelayed<File> MAPPINGS_TINY = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-tiny-" + extension.version + "." + extension.pomfVersion));
public static final IDelayed<File> MAPPINGS_MIXIN_EXPORT = new DelayedFile(extension -> new File(CACHE_FILES, "mixin-map-" + extension.version + "." + extension.pomfVersion + ".mappings"));
public static IDelayed<File> MAPPINGS_ENIGMA_ZIP = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip"));
public static final IDelayed<File> MAPPINGS_ENIGMA_DIR = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ""));
public static final IDelayed<File> MAPPINGS_DIR_LOCAL = new DelayedFile(extension -> new File(WORKING_DIRECTORY, "mappings"));
public static final IDelayed<File> MAPPINGS_ZIP_LOCAL = new DelayedFile(extension -> new File(MAPPINGS_DIR_LOCAL.get(extension), "pomf-enigma-" + extension.version + ".zip"));
public static final IDelayed<File> MAPPINGS_ENIGMA_ZIP_LOCAL = new DelayedFile(extension -> new File(MAPPINGS_DIR_LOCAL.get(extension), "pomf-enigma-" + extension.version + ".zip"));
public static final IDelayed<File> MAPPINGS_TINY_GZ_LOCAL = new DelayedFile(extension -> new File(MAPPINGS_DIR_LOCAL.get(extension), "pomf-tiny-" + extension.version + ".gz"));
public static final IDelayed<File> MINECRAFT_LIBS = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-libs"));
@ -62,6 +67,7 @@ public class Constants {
public static final String FABRIC_CLIENT_TWEAKER = "net.fabricmc.base.launch.FabricClientTweaker";
public static final String FABRIC_SERVER_TWEAKER = "net.fabricmc.base.launch.FabricServerTweaker";
public static final String POMF_JENKINS_SERVER = "http://modmuss50.me:8080";
public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/";
public static final String RESOURCES_BASE = "http://resources.download.minecraft.net/";