Use tiny remapper to remap minecraft, some minor cleanup

dev/0.11
modmuss50 2018-10-26 23:43:39 +01:00
parent 90746a93c1
commit 9a2b847772
8 changed files with 49 additions and 86 deletions

View File

@ -16,10 +16,6 @@ version = '0.0.12-SNAPSHOT'
repositories {
mavenCentral()
maven {
name = 'fabric'
url = 'http://maven.fabricmc.net/'
}
maven {
name "Modmuss"
url 'http://maven.modmuss50.me/'
@ -53,13 +49,10 @@ dependencies {
shade 'com.google.code.gson:gson:2.6.2'
shade 'commons-io:commons-io:1.4'
shade 'com.google.guava:guava:19.0'
shade ('weave-asm:weave:0.1.0.7'){
shade ('net.fabricmc:weave:+'){
transitive = false
}
shade ('enigma-asm:enigma:0.12.0.33:lib'){
exclude group: 'org.ow2.asm'
}
shade 'OpenModLoader.tiny-remapper:tiny-remapper:0.1.0.7'
shade 'net.fabricmc:tiny-remapper:0.1.0.5'
shade 'net.sf.jopt-simple:jopt-simple:5.0.4'
shade 'org.apache.logging.log4j:log4j-api:2.11.0'
shade 'org.apache.logging.log4j:log4j-core:2.11.0'

View File

@ -74,6 +74,7 @@ public class AbstractPlugin implements Plugin<Project> {
addMavenRepo(target, "Mojang", "https://libraries.minecraft.net/");
// Minecraft libraries configuration
project.getConfigurations().maybeCreate(Constants.CONFIG_MINECRAFT);
project.getConfigurations().maybeCreate(Constants.CONFIG_MC_DEPENDENCIES);
project.getConfigurations().maybeCreate(Constants.CONFIG_MC_DEPENDENCIES_CLIENT);
project.getConfigurations().maybeCreate(Constants.CONFIG_NATIVES);
@ -82,7 +83,7 @@ public class AbstractPlugin implements Plugin<Project> {
project.getConfigurations().maybeCreate(Constants.PROCESS_MODS_DEPENDENCIES);
// Common libraries extends from client libraries, CONFIG_MC_DEPENDENCIES will contains all MC dependencies
project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).extendsFrom(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES_CLIENT));
project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT).extendsFrom(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).extendsFrom(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES_CLIENT)));
configureIDEs();
configureCompile();
@ -168,12 +169,12 @@ public class AbstractPlugin implements Plugin<Project> {
ideaModule.getModule().setDownloadJavadoc(true);
ideaModule.getModule().setDownloadSources(true);
ideaModule.getModule().setInheritOutputDirs(true);
ideaModule.getModule().getScopes().get("COMPILE").get("plus").add(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES));
ideaModule.getModule().getScopes().get("COMPILE").get("plus").add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT));
ideaModule.getModule().getScopes().get("COMPILE").get("plus").add(project.getConfigurations().getByName(Constants.COMPILE_MODS));
// ECLIPSE
EclipseModel eclipseModule = (EclipseModel) project.getExtensions().getByName("eclipse");
eclipseModule.getClasspath().getPlusConfigurations().add(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES));
eclipseModule.getClasspath().getPlusConfigurations().add(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT));
eclipseModule.getClasspath().getPlusConfigurations().add(project.getConfigurations().getByName(Constants.COMPILE_MODS));
}
@ -186,10 +187,10 @@ public class AbstractPlugin implements Plugin<Project> {
SourceSet main = javaModule.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
SourceSet test = javaModule.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
main.setCompileClasspath(main.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES)));
test.setCompileClasspath(test.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES)));
main.setRuntimeClasspath(main.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES)));
test.setCompileClasspath(test.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES)));
main.setCompileClasspath(main.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)));
test.setCompileClasspath(test.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)));
main.setRuntimeClasspath(main.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)));
test.setCompileClasspath(test.getCompileClasspath().plus(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT)));
Javadoc javadoc = (Javadoc) project.getTasks().getByName(JavaPlugin.JAVADOC_TASK_NAME);
javadoc.setClasspath(main.getOutput().plus(main.getCompileClasspath()));
@ -246,7 +247,7 @@ public class AbstractPlugin implements Plugin<Project> {
} catch (IOException e) {
e.printStackTrace();
}
project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:" + Constants.MINECRAFT_FINAL_JAR.get(extension).getName().replace(".jar", ""));
project1.getDependencies().add(Constants.CONFIG_MINECRAFT, "net.minecraft:" + Constants.MINECRAFT_FINAL_JAR.get(extension).getName().replace(".jar", ""));
if (extension.isModWorkspace()) {
//only add this when not in a dev env

View File

@ -72,15 +72,6 @@ public class DownloadTask extends DefaultTask {
Constants.POMF_DIR.get(extension).mkdir();
}
if (!Constants.MAPPINGS_ZIP.get(extension).exists() && extension.hasPomf()) {
this.getLogger().lifecycle(":downloading mappings");
try {
FileUtils.copyURLToFile(new URL("http://modmuss50.me:8080/job/FabricMC/job/pomf/job/" + extension.version + "/" + extension.pomfVersion + "/artifact/build/libs/pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip"), Constants.MAPPINGS_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()) {
@ -88,13 +79,10 @@ public class DownloadTask extends DefaultTask {
extension.localMappings = true;
//We delete this to make sure they are always re extracted.
deleteIfExists(Constants.MAPPINGS_ZIP.get(extension));
deleteIfExists(Constants.MAPPINGS_TINY_GZ.get(extension));
deleteIfExists(Constants.MAPPINGS_TINY.get(extension));
deleteIfExists(Constants.MAPPINGS_DIR.get(extension));
Constants.MAPPINGS_TINY_GZ = Constants.MAPPINGS_TINY_GZ_LOCAL;
Constants.MAPPINGS_ZIP = Constants.MAPPINGS_ZIP_LOCAL;
}
}
}

View File

@ -24,15 +24,12 @@
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;
@ -40,18 +37,16 @@ import org.zeroturnaround.zip.commons.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.jar.JarFile;
import java.nio.file.Path;
public class MapJarsTask extends DefaultTask {
Deobfuscator deobfuscator;
@TaskAction
public void mapJars() throws IOException, MappingParseException {
public void mapJars() throws IOException {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
if (!Constants.MINECRAFT_MAPPED_JAR.get(extension).exists() || extension.localMappings || true) {
if(extension.localMappings && Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()){
//Always remap the jar when using local mappings.
if(Constants.MINECRAFT_MAPPED_JAR.get(extension).exists()){
Constants.MINECRAFT_MAPPED_JAR.get(extension).delete();
}
if(!extension.hasPomf()){
@ -59,16 +54,34 @@ public class MapJarsTask extends DefaultTask {
FileUtils.copyFile(Constants.MINECRAFT_MIXED_JAR.get(extension), Constants.MINECRAFT_MAPPED_JAR.get(extension));
return;
}
if (!Constants.MAPPINGS_DIR.get(extension).exists() || extension.localMappings) {
this.getLogger().lifecycle(":unpacking mappings");
FileUtils.deleteDirectory(Constants.MAPPINGS_DIR.get(extension));
ZipUtil.unpack(Constants.MAPPINGS_ZIP.get(extension), Constants.MAPPINGS_DIR.get(extension));
}
this.getLogger().lifecycle(":remapping jar");
deobfuscator = new Deobfuscator(new JarFile(Constants.MINECRAFT_MIXED_JAR.get(extension)));
this.deobfuscator.setMappings(new MappingsEnigmaReader().read(Constants.MAPPINGS_DIR.get(extension)));
writeJar(Constants.MINECRAFT_MAPPED_JAR.get(extension), new ProgressListener(), deobfuscator);
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());
//Rebof the mixed mc jar
outputConsumer.addNonClassFiles(Constants.MINECRAFT_MIXED_JAR.get(extension).toPath());
remapper.read(Constants.MINECRAFT_MIXED_JAR.get(extension).toPath());
remapper.read(classpath);
remapper.apply(Constants.MINECRAFT_MIXED_JAR.get(extension).toPath(), outputConsumer);
outputConsumer.finish();
remapper.finish();
} catch (Exception e){
remapper.finish();
throw new RuntimeException("Failed to remap minecraft to " + toM, e);
}
File tempAssests = new File(Constants.CACHE_FILES, "tempAssets");
if (tempAssests.exists()) {
@ -92,24 +105,4 @@ public class MapJarsTask extends DefaultTask {
this.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

@ -53,10 +53,7 @@ public class RunClientTask extends JavaExec {
for (File file : getProject().getConfigurations().getByName("compile").getFiles()) {
libs.add(file.getAbsolutePath());
}
for (File file : getProject().getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES_CLIENT).getFiles()) {
libs.add(file.getAbsolutePath());
}
for (File file : getProject().getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles()) {
for (File file : getProject().getConfigurations().getByName(Constants.CONFIG_MINECRAFT).getFiles()) {
libs.add(file.getAbsolutePath());
}
//Used to add the fabric jar that has been built

View File

@ -53,7 +53,7 @@ public class RunServerTask extends JavaExec {
for (File file : getProject().getConfigurations().getByName("compile").getFiles()) {
libs.add(file.getAbsolutePath());
}
for (File file : getProject().getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles()) {
for (File file : getProject().getConfigurations().getByName(Constants.CONFIG_MINECRAFT).getFiles()) {
libs.add(file.getAbsolutePath());
}
//Used to add the fabric jar that has been built

View File

@ -45,8 +45,6 @@ public class Constants {
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_ZIP = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip"));
public static final IDelayed<File> MAPPINGS_DIR = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ""));
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"));
@ -70,6 +68,7 @@ public class Constants {
public static final String CONFIG_NATIVES = "MC_NATIVES";
public static final String CONFIG_MC_DEPENDENCIES = "MC_DEPENDENCIES";
public static final String CONFIG_MINECRAFT = "MINECRAFT";
public static final String CONFIG_MC_DEPENDENCIES_CLIENT = "MC_DEPENDENCIES_CLIENT";
public static final String PROCESS_MODS_DEPENDENCIES = "PROCESS_MODS_DEPENDENCIES";
public static final String SYSTEM_ARCH = System.getProperty("os.arch").equals("64") ? "64" : "32";

View File

@ -28,13 +28,6 @@ import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.tinyremapper.*;
import org.apache.commons.io.FileUtils;
import org.gradle.api.Project;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
import java.io.File;
import java.io.IOException;
@ -71,8 +64,7 @@ public class ModRemapper {
List<File> classpathFiles = new ArrayList<>();
classpathFiles.addAll(project.getConfigurations().getByName("compile").getFiles());
classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES_CLIENT).getFiles());
classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MC_DEPENDENCIES).getFiles());
classpathFiles.addAll(project.getConfigurations().getByName(Constants.CONFIG_MINECRAFT).getFiles());
Path[] classpath = new Path[classpathFiles.size()];
for (int i = 0; i < classpathFiles.size(); i++) {