Merge pull request #10 from OpenModLoader/master

Things are happening
This commit is contained in:
Modmuss50 2018-10-22 19:26:14 +01:00 committed by GitHub
commit 30dc5a3d35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 341 additions and 200 deletions

2
.gitignore vendored
View file

@ -16,4 +16,4 @@
!/LICENSE
!/README.md
!/settings.gradle
!/Jenkinsfile
!/BuildFile

View file

@ -11,5 +11,5 @@ node {
stage "Archive artifacts"
sh "./gradlew upload"
sh "./gradlew publish"
}

View file

@ -1,6 +1,6 @@
# fabric-loom
Gradle plugin for Fabric
# OpenGradle
Gradle plugin for OpenModLoader
Usage: `gradlew setupFabric idea`
(Prefix with `./` on macOS and Linux)
Usage: `gradlew setup idea`
(Use `./gradle` on macOS and Linux)

View file

@ -2,7 +2,7 @@ plugins {
id 'java'
id 'groovy'
id 'maven'
id 'maven-publish'
id 'idea'
id 'eclipse'
}
@ -10,12 +10,9 @@ plugins {
sourceCompatibility = 1.8
targetCompatibility = 1.8
apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/maven.gradle'
apply from: 'https://github.com/FabricMC/fabric-docs/raw/master/gradle/license.gradle'
group = 'net.fabricmc'
archivesBaseName = project.name.toLowerCase()
version = '0.0.7-SNAPSHOT'
archivesBaseName = project.name
version = '0.0.12-SNAPSHOT'
repositories {
mavenCentral()
@ -24,13 +21,17 @@ repositories {
url = 'http://maven.fabricmc.net/'
}
maven {
name "RX14 Repository"
url 'http://mvn.rx14.co.uk/local/'
name "Modmuss"
url 'http://maven.modmuss50.me/'
}
maven {
name = 'Mojang'
url = 'https://libraries.minecraft.net/'
}
maven {
name = 'Forge' //For ModLauncher
url = 'http://files.minecraftforge.net/maven/'
}
}
configurations {
@ -48,14 +49,17 @@ 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 'net.fabricmc:weave:0.1.0.+'
shade 'cuchaz:enigma:0.11.0.+:lib'
shade 'net.fabricmc:tiny-remapper:+'
//Always fun when your dep needs the tool to build, but the tool needs the dep.
//compile 'net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT'
shade ('weave-asm:weave:0.1.0.7'){
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.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'
shade 'cpw.mods:modlauncher:0.1.0-rc.3'
shade 'org.apache.commons:commons-lang3:3.5'
}
@ -68,16 +72,42 @@ sourceSets {
}
jar {
from {
configurations.shade.each { dep ->
from(project.zipTree(dep)){
exclude 'META-INF', 'META-INF/**'
}
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from (configurations.shade.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude 'META-INF/*'
exclude 'META-INF'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '3.1'
gradleVersion = '4.9'
}
publishing {
publications {
maven(MavenPublication) {
groupId project.group
artifactId project.archivesBaseName
version project.version
from components.java
//Removes all of the dependencies from the maven pom, prevents sub projects downloading all the libs, as we use a fat jar
pom.withXml {
asNode().remove(asNode().get('dependencies'))
}
}
}
repositories {
maven {
url "http://mavenupload.modmuss50.me/"
if (project.hasProperty('mavenPass')) {
credentials {
username 'buildslave'
password project.getProperty('mavenPass')
}
}
}
}
}

View file

@ -1,3 +1,3 @@
name = fabric-loom
description = The Gradle plugin for Fabric
url = https://github.com/FabricMC/fabric-loom
url = https://github.com/FabricMC/fabric-loom

Binary file not shown.

View file

@ -1,6 +1,5 @@
#Wed May 10 22:17:52 BST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip

23
gradlew vendored
View file

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
##############################################################################
##
@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
warn () {
echo "$*"
}
die ( ) {
die () {
echo
echo "$*"
echo
@ -154,16 +154,19 @@ if $cygwin ; then
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
exec "$JAVACMD" "$@"

View file

@ -26,6 +26,7 @@ package net.fabricmc.loom;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.fabricmc.loom.task.DownloadTask;
@ -85,6 +86,7 @@ public class AbstractPlugin implements Plugin<Project> {
configureIDEs();
configureCompile();
}
/**
@ -137,10 +139,12 @@ public class AbstractPlugin implements Plugin<Project> {
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.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.COMPILE_MODS));
}
/**
@ -164,7 +168,7 @@ public class AbstractPlugin implements Plugin<Project> {
LoomGradleExtension extension = project1.getExtensions().getByType(LoomGradleExtension.class);
project1.getRepositories().flatDir(flatDirectoryArtifactRepository -> {
flatDirectoryArtifactRepository.dir(extension.getFabricUserCache());
flatDirectoryArtifactRepository.dir(extension.getUserCache());
flatDirectoryArtifactRepository.setName("UserCacheFiles");
});
@ -179,8 +183,8 @@ public class AbstractPlugin implements Plugin<Project> {
});
project1.getRepositories().maven(mavenArtifactRepository -> {
mavenArtifactRepository.setName("SpongePowered");
mavenArtifactRepository.setUrl("http://repo.spongepowered.org/maven");
mavenArtifactRepository.setName("modmuss50");
mavenArtifactRepository.setUrl("https://maven.modmuss50.me/");
});
project1.getRepositories().maven(mavenArtifactRepository -> {
@ -209,14 +213,13 @@ public class AbstractPlugin implements Plugin<Project> {
}
project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:" + Constants.MINECRAFT_FINAL_JAR.get(extension).getName().replace(".jar", ""));
if (extension.fabricVersion != null && !extension.fabricVersion.isEmpty()) {
//only add this when not in a fabric dev env
project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "net.fabricmc:fabric-base:" + extension.version + "-" + extension.fabricVersion + ":deobf");
if (extension.isModWorkspace()) {
//only add this when not in a dev env
project1.getDependencies().add(Constants.CONFIG_MC_DEPENDENCIES, "com.openmodloader:OpenModLoader:" + extension.getVersionString() +":deobf");
}
project1.getDependencies().add(Constants.PROCESS_MODS_DEPENDENCIES, "net.fabricmc:fabric-base:16w38a-0.0.4-SNAPSHOT");
});
project.getTasks().getByName("build").doLast(task -> {
project.getTasks().getByName("jar").doLast(task -> {
project.getLogger().lifecycle(":remapping mods");
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
try {
@ -229,7 +232,7 @@ public class AbstractPlugin implements Plugin<Project> {
});
project.afterEvaluate(project12 -> {
project12.getTasks().getByName("idea").dependsOn(project12.getTasks().getByName("cleanIdea")).dependsOn(project12.getTasks().getByName("setupFabric")).dependsOn(project12.getTasks().getByName("extractNatives"));
project12.getTasks().getByName("idea").dependsOn(project12.getTasks().getByName("cleanIdea")).dependsOn(project12.getTasks().getByName("setup")).dependsOn(project12.getTasks().getByName("extractNatives"));
project12.getTasks().getByName("idea").finalizedBy(project12.getTasks().getByName("genIdeaWorkspace"));
});
@ -242,17 +245,19 @@ public class AbstractPlugin implements Plugin<Project> {
Gson gson = new Gson();
try {
JsonElement jsonElement = gson.fromJson(new FileReader(modJson), JsonElement.class);
JsonObject jsonObject = jsonElement.getAsJsonObject();
if ((extension.version == null || extension.version.isEmpty()) && jsonObject.has("version")) {
project.setVersion(jsonObject.get("version").getAsString());
JsonArray jsonArray = jsonElement.getAsJsonArray();
for (int i = 0; i < jsonArray.size(); i++) {
JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
if ((extension.version == null || extension.version.isEmpty()) && jsonObject.has("version")) {
project.setVersion(jsonObject.get("version").getAsString());
}
if (jsonObject.has("group")) {
project.setGroup(jsonObject.get("group").getAsString());
}
if (jsonObject.has("description")) {
project.setDescription(jsonObject.get("description").getAsString());
}
}
if (jsonObject.has("group")) {
project.setGroup(jsonObject.get("group").getAsString());
}
if (jsonObject.has("description")) {
project.setDescription(jsonObject.get("description").getAsString());
}
//TODO load deps
} catch (FileNotFoundException e) {
//This wont happen as we have checked for it

View file

@ -31,8 +31,9 @@ import java.io.File;
public class LoomGradleExtension {
public String version;
public String runDir = "run";
public String fabricVersion;
public String omlVersion;
public String pomfVersion;
public boolean skipPrebake = false;
public boolean localMappings = false;
//Not to be set in the build.gradle
@ -40,17 +41,17 @@ public class LoomGradleExtension {
public String getVersionString() {
if (isModWorkspace()) {
return version + "-" + fabricVersion;
return version + "-" + omlVersion;
}
return version;
}
public boolean isModWorkspace() {
return fabricVersion != null && !fabricVersion.isEmpty();
return omlVersion != null && !omlVersion.isEmpty();
}
public File getFabricUserCache() {
File userCache = new File(project.getGradle().getGradleUserHomeDir(), "caches" + File.separator + "loom");
public File getUserCache() {
File userCache = new File(project.getGradle().getGradleUserHomeDir(), "caches" + File.separator + "fabric-loom");
if (!userCache.exists()) {
userCache.mkdirs();
}

View file

@ -35,16 +35,17 @@ public class LoomGradlePlugin extends AbstractPlugin {
makeTask("download", DownloadTask.class);
makeTask("mergeJars", MergeJarsTask.class).dependsOn("download");
makeTask("mapJars", MapJarsTask.class).dependsOn("mergeJars");
makeTask("processMods", ProcessModsTask.class).dependsOn("mapJars");
makeTask("setupFabric", DefaultTask.class).dependsOn("processMods");
makeTask("processMods", ProcessModsTask.class).dependsOn("mergeJars");
makeTask("mapJars", MapJarsTask.class).dependsOn("processMods");
makeTask("finaliseJars", FinaliseJar.class).dependsOn("mapJars");
makeTask("setup", DefaultTask.class).dependsOn("finaliseJars").setGroup("openmodloader");
makeTask("extractNatives", ExtractNativesTask.class).dependsOn("download");
makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea");
makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide");
makeTask("vscode", GenVSCodeProjectTask.class).dependsOn("extractNatives");
makeTask("vscode", GenVSCodeProjectTask.class).dependsOn("extractNatives").setGroup("ide");
makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded");
makeTask("runServer", RunServerTask.class).dependsOn("buildNeeded");
makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded").setGroup("minecraft");
makeTask("runServer", RunServerTask.class).dependsOn("buildNeeded").setGroup("minecraft");
}
}

View file

@ -75,7 +75,7 @@ public class DownloadTask extends DefaultTask {
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));
FileUtils.copyURLToFile(new URL("http://modmuss50.me:8080/job/OpenModLoader/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);
}
@ -103,7 +103,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("http://modmuss50.me:8080/job/OpenModLoader/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);
}
@ -138,12 +138,9 @@ public class DownloadTask extends DefaultTask {
version.libraries.stream().filter(lib -> lib.natives != null).forEach(lib -> dependencyHandler.add(Constants.CONFIG_NATIVES, lib.getArtifactName()));
}
// Force add LaunchWrapper
dependencyHandler.add(Constants.CONFIG_MC_DEPENDENCIES, "net.minecraft:launchwrapper:1.12");
Version.AssetIndex assetIndex = version.assetIndex;
File assets = new File(extension.getFabricUserCache(), "assets-" + extension.version);
File assets = new File(extension.getUserCache(), "assets-" + extension.version);
if (!assets.exists()) {
assets.mkdirs();
}

View file

@ -0,0 +1,23 @@
package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import org.apache.commons.io.FileUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
import java.io.IOException;
public class FinaliseJar extends DefaultTask {
@TaskAction
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();
}
FileUtils.copyFile(Constants.MINECRAFT_MAPPED_JAR.get(extension), Constants.MINECRAFT_FINAL_JAR.get(extension));
}
}

View file

@ -135,22 +135,22 @@ public class GenIdeaProjectTask extends DefaultTask {
}
IdeaRunConfig ideaClient = new IdeaRunConfig();
ideaClient.mainClass = "net.minecraft.launchwrapper.Launch";
ideaClient.mainClass = "cpw.mods.modlauncher.Launcher";
ideaClient.projectName = project.getName();
ideaClient.configName = "Minecraft Client";
ideaClient.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
ideaClient.vmArgs = "-Djava.library.path=" + Constants.MINECRAFT_NATIVES.get(extension).getAbsolutePath() + " -Dfabric.development=true";
ideaClient.programArgs = "--tweakClass net.fabricmc.base.launch.FabricClientTweaker --assetIndex " + version.assetIndex.id + " --assetsDir " + new File(extension.getFabricUserCache(), "assets-" + extension.version).getAbsolutePath();
ideaClient.vmArgs = "-Djava.library.path=" + Constants.MINECRAFT_NATIVES.get(extension).getAbsolutePath() + " -Doml.development=true";
ideaClient.programArgs = "--launchTarget oml --accessToken not_a_real_token --version " + extension.version + " --assetIndex " + version.assetIndex.id + " --assetsDir " + new File(extension.getUserCache(), "assets-" + extension.version).getAbsolutePath();
runManager.appendChild(ideaClient.genRuns(runManager));
IdeaRunConfig ideaServer = new IdeaRunConfig();
ideaServer.mainClass = "net.minecraft.launchwrapper.Launch";
ideaServer.mainClass = "com.openmodloader.loader.launch.ServerLauncher";
ideaServer.projectName = project.getName();
ideaServer.configName = "Minecraft Server";
ideaServer.runDir = "file://$PROJECT_DIR$/" + extension.runDir;
ideaServer.vmArgs = "-Dfabric.development=true";
ideaServer.programArgs = "--tweakClass net.fabricmc.base.launch.FabricServerTweaker";
ideaServer.vmArgs = "-Doml.development=true";
ideaServer.programArgs = "";
runManager.appendChild(ideaServer.genRuns(runManager));

View file

@ -67,9 +67,9 @@ public class GenVSCodeProjectTask extends DefaultTask {
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
jsonArray.add("src/main/java");
jsonArray.add("src/main/resorces");
jsonArray.add("src/main/resources");
jsonArray.add("src/test/java");
jsonArray.add("src/test/resorces");
jsonArray.add("src/test/resources");
jsonObject.add("sourcePath", jsonArray);
JsonElement element = new JsonPrimitive(classPathFile.getName());
jsonObject.add("classPathFile", element);

View file

@ -28,8 +28,9 @@ 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 javassist.CtClass;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import org.gradle.api.DefaultTask;
@ -55,7 +56,7 @@ public class MapJarsTask extends DefaultTask {
}
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));
FileUtils.copyFile(Constants.MINECRAFT_MIXED_JAR.get(extension), Constants.MINECRAFT_MAPPED_JAR.get(extension));
return;
}
if (!Constants.MAPPINGS_DIR.get(extension).exists() || extension.localMappings) {
@ -65,7 +66,7 @@ public class MapJarsTask extends DefaultTask {
}
this.getLogger().lifecycle(":remapping jar");
deobfuscator = new Deobfuscator(new JarFile(Constants.MINECRAFT_MERGED_JAR.get(extension)));
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);
@ -76,7 +77,7 @@ public class MapJarsTask extends DefaultTask {
tempAssests.mkdir();
ZipUtil.unpack(Constants.MINECRAFT_CLIENT_JAR.get(extension), tempAssests, name -> {
if (name.startsWith("assets") || name.startsWith("log4j2.xml") || name.startsWith("pack.png")) {
if (name.startsWith("assets") || name.startsWith("pack.mcmeta") || name.startsWith("data") || name.toLowerCase().startsWith("log4j2") || name.startsWith("pack.png")) {
return name;
} else {
return null;
@ -93,22 +94,10 @@ public class MapJarsTask extends DefaultTask {
}
public void writeJar(File out, Deobfuscator.ProgressListener progress, Deobfuscator deobfuscator) {
TranslatingTypeLoader loader = new TranslatingTypeLoader(deobfuscator.getJar(), deobfuscator.getJarIndex(), deobfuscator.getTranslator(TranslationDirection.Obfuscating), deobfuscator.getTranslator(TranslationDirection.Deobfuscating));
deobfuscator.transformJar(out, progress, new CustomClassTransformer(loader));
}
private class CustomClassTransformer implements Deobfuscator.ClassTransformer {
TranslatingTypeLoader loader;
public CustomClassTransformer(TranslatingTypeLoader loader) {
this.loader = loader;
}
@Override
public CtClass transform(CtClass ctClass) throws Exception {
return loader.transformClass(ctClass);
}
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 {

View file

@ -26,7 +26,6 @@ package net.fabricmc.loom.task;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.proccessing.PreBakeMixins;
import org.apache.commons.io.FileUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.artifacts.Configuration;
@ -50,17 +49,17 @@ public class ProcessModsTask extends DefaultTask {
Configuration configuration = getProject().getConfigurations().getByName(Constants.COMPILE_MODS);
List<File> mods = new ArrayList<>();
for (ResolvedArtifact artifact : configuration.getResolvedConfiguration().getResolvedArtifacts()) {
getProject().getLogger().lifecycle(":found mod to mix:" + artifact.getFile().getName());
//getProject().getLogger().lifecycle(":found mod to mix:" + artifact.getFile().getName());
mods.add(artifact.getFile());
}
if (Constants.MINECRAFT_FINAL_JAR.get(extension).exists()) {
Constants.MINECRAFT_FINAL_JAR.get(extension).delete();
}
if (mods.size() == 0) {
FileUtils.copyFile(Constants.MINECRAFT_MAPPED_JAR.get(extension), Constants.MINECRAFT_FINAL_JAR.get(extension));
if (mods.size() == 0 || extension.skipPrebake) {
FileUtils.copyFile(Constants.MINECRAFT_MERGED_JAR.get(extension), Constants.MINECRAFT_MIXED_JAR.get(extension));
} else {
downloadRequiredDeps(extension);
new PreBakeMixins().proccess(getProject(), extension, mods);
// downloadRequiredDeps(extension);
throw new UnsupportedOperationException("Mixin prebake isnt done yet");
}
}

View file

@ -46,7 +46,7 @@ public class RunClientTask extends JavaExec {
try {
version = gson.fromJson(new FileReader(Constants.MINECRAFT_JSON.get(extension)), Version.class);
} catch (FileNotFoundException e) {
e.printStackTrace();
getLogger().error("Failed to retrieve version from minecraft json", e);
}
List<String> libs = new ArrayList<>();
@ -65,10 +65,15 @@ public class RunClientTask extends JavaExec {
libs.add(file.getAbsolutePath());
}
}
libs.add(Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath());
libs.add(Constants.MINECRAFT_CLIENT_JAR.get(extension).getAbsolutePath());
//Removes the deobf jars
libs.removeIf(s -> s.contains(Constants.MINECRAFT_FINAL_JAR.get(extension).getName()));
libs.removeIf(s -> s.contains(getProject().getName() + "-" + getProject().getVersion() + "-deobf.jar"));
classpath(libs);
args("--tweakClass", "net.fabricmc.base.launch.FabricClientTweaker", "--assetIndex", version.assetIndex.id, "--assetsDir", new File(extension.getFabricUserCache(), "assets-" + extension.version).getAbsolutePath());
args("--launchTarget", "oml", "--accessToken", "NOT_A_TOKEN", "--version", extension.version, "--assetIndex", version.assetIndex.id, "--assetsDir", new File(extension.getUserCache(), "assets-" + extension.version).getAbsolutePath());
setWorkingDir(new File(getProject().getRootDir(), "run"));
@ -77,7 +82,7 @@ public class RunClientTask extends JavaExec {
@Override
public String getMain() {
return "net.minecraft.launchwrapper.Launch";
return "cpw.mods.modlauncher.Launcher";
}
@Override
@ -85,7 +90,7 @@ public class RunClientTask extends JavaExec {
LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class);
List<String> args = new ArrayList<>();
args.add("-Djava.library.path=" + Constants.MINECRAFT_NATIVES.get(extension).getAbsolutePath());
args.add("-Dfabric.development=true");
//args.add("-XstartOnFirstThread"); //Fixes lwjgl starting on an incorrect thread
return args;
}

View file

@ -65,8 +65,6 @@ public class RunServerTask extends JavaExec {
libs.add(Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath());
classpath(libs);
args("--tweakClass", "net.fabricmc.base.launch.FabricServerTweaker");
setWorkingDir(new File(getProject().getRootDir(), "run"));
super.exec();
@ -74,7 +72,7 @@ public class RunServerTask extends JavaExec {
@Override
public String getMain() {
return "net.minecraft.launchwrapper.Launch";
return "com.openmodloader.loader.launch.ServerLauncher";
}
@Override

View file

@ -37,13 +37,14 @@ 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 IDelayed<File> MINECRAFT_CLIENT_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-client.jar"));
public static final IDelayed<File> MINECRAFT_SERVER_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-server.jar"));
public static final IDelayed<File> MINECRAFT_MERGED_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-merged.jar"));
public static final IDelayed<File> MINECRAFT_MAPPED_JAR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.getVersionString() + "-mapped-" + extension.pomfVersion + ".jar"));
public static final IDelayed<File> MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.getVersionString() + "-mixed-" + extension.pomfVersion + ".jar"));
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_MIXED_JAR = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-mixed.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_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.getFabricUserCache(), "pomf"));
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"));
@ -53,11 +54,11 @@ public class Constants {
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_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.getFabricUserCache(), extension.version + "-libs"));
public static final IDelayed<File> MINECRAFT_NATIVES = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-natives"));
public static final IDelayed<File> MINECRAFT_JSON = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-info.json"));
public static final IDelayed<File> MINECRAFT_LIBS = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-libs"));
public static final IDelayed<File> MINECRAFT_NATIVES = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-natives"));
public static final IDelayed<File> MINECRAFT_JSON = new DelayedFile(extension -> new File(extension.getUserCache(), extension.version + "-info.json"));
public static final IDelayed<File> VERSION_MANIFEST = new DelayedFile(extension -> new File(extension.getFabricUserCache(), "version_manifest.json"));
public static final IDelayed<File> VERSION_MANIFEST = new DelayedFile(extension -> new File(extension.getUserCache(), "version_manifest.json"));
public static final String LIBRARIES_BASE = "https://libraries.minecraft.net/";
public static final String RESOURCES_BASE = "http://resources.download.minecraft.net/";

View file

@ -25,16 +25,21 @@
package net.fabricmc.loom.util;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils;
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;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
public class ModRemapper {
@ -53,8 +58,11 @@ public class ModRemapper {
deobfJar.delete();
}
FileUtils.touch(modJar); //Done to ensure that the file can be moved
//Move the pre existing mod jar to the deobf jar
modJar.renameTo(deobfJar);
if(!modJar.renameTo(deobfJar)){
throw new RuntimeException("Failed to rename " + modJar);
}
Path mappings = Constants.MAPPINGS_TINY.get(extension).toPath();
@ -65,7 +73,6 @@ public class ModRemapper {
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.add(new File(Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath()));//Seems to fix it not finding it
Path[] classpath = new Path[classpathFiles.size()];
for (int i = 0; i < classpathFiles.size(); i++) {
@ -74,18 +81,155 @@ public class ModRemapper {
TinyRemapper remapper = TinyRemapper.newRemapper()
.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM))
.withRemapperExtension(new MixinRemapper())
.build();
OutputConsumerPath outputConsumer = new OutputConsumerPath(modJar.toPath());
//Rebof the deobf jar
outputConsumer.addNonClassFiles(deobfJar.toPath());
remapper.read(deobfJar.toPath());
remapper.read(classpath);
remapper.apply(deobfJar.toPath(), outputConsumer);
outputConsumer.finish();
remapper.finish();
try {
OutputConsumerPath outputConsumer = new OutputConsumerPath(modJar.toPath());
//Rebof the deobf jar
outputConsumer.addNonClassFiles(deobfJar.toPath());
remapper.read(deobfJar.toPath());
remapper.read(classpath);
remapper.apply(deobfJar.toPath(), outputConsumer);
outputConsumer.finish();
remapper.finish();
} catch (Exception e){
remapper.finish();
throw new RuntimeException("Failed to remap jar", e);
}
if(!deobfJar.exists() || !modJar.exists()){
throw new RuntimeException("Failed to rebof jar");
}
//Add the deobf jar to be uploaded to maven
project.getArtifacts().add("archives", deobfJar);
}
public static class MixinRemapper implements IRemapperExtension{
@Override
public byte[] handleUnmappedClass(byte[] inBytes, TinyRemapper remapper) {
//I know this isnt the fastest, but its the easiest
ClassNode classNode = readClassFromBytes(inBytes);
if(isMixin(classNode)){
String target = getMixinTarget(classNode);
System.out.println("Remapping mixin (" + classNode.name + ") targeting: " + target);
for(MethodNode methodNode : classNode.methods){
if(needsTargetMap(methodNode.visibleAnnotations)){
methodNode.visibleAnnotations.add(createTargetMap(methodNode, target, remapper));
}
}
for(FieldNode fieldNode : classNode.fields){
if(needsTargetMap(fieldNode.visibleAnnotations)){
//fieldNode.visibleAnnotations.add(createTargetMap(fieldNode));
}
}
return writeClassToBytes(classNode);
}
return inBytes;
}
private AnnotationNode createTargetMap(MethodNode methodNode, String targetClass, TinyRemapper remapper){
AnnotationNode targetMapNode = new AnnotationNode("Lme/modmuss50/fusion/api/TargetMap;");
String deobfTarget = methodNode.name + methodNode.desc;
if(getRewriteTarget(methodNode).isPresent()){
deobfTarget = getRewriteTarget(methodNode).get();
}
if(deobfTarget.equals("<init>")){
//No need to handle constructors, may need to do something about the desc but we will see
return targetMapNode;
}
String oldName = deobfTarget.substring(0, deobfTarget.indexOf("("));
String oldDesc = deobfTarget.substring(deobfTarget.lastIndexOf("("));
String newName = remapper.remapper.mapMethodName(targetClass.replaceAll("\\.", "/"), oldName, oldDesc);
String newDesc = remapper.remapper.mapDesc(oldDesc);
System.out.println(oldName + oldDesc + " -> " + newName + newDesc);
targetMapNode.visit("value", newName + newDesc);
return targetMapNode;
}
private boolean isMixin(ClassNode classNode){
if(classNode.visibleAnnotations == null){
return false;
}
for(AnnotationNode annotation : classNode.visibleAnnotations){
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Mixin;")){
return true;
}
}
return false;
}
private String getMixinTarget(ClassNode classNode){
if(classNode.visibleAnnotations == null){
throw new RuntimeException(classNode.name + " is not a mixin!");
}
for(AnnotationNode annotation : classNode.visibleAnnotations){
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Mixin;")){
for (int i = 0; i < annotation.values.size(); i++) {
Object value = annotation.values.get(i);
if(value instanceof String && value.toString().equals("value")){
Type target = (Type) annotation.values.get(i + 1);
return target.getClassName();
}
}
}
}
throw new RuntimeException(classNode.name + " is not a valid mixin!");
}
private Optional<String> getRewriteTarget(MethodNode methodNode){
if(methodNode.visibleAnnotations == null){
return Optional.empty();
}
for(AnnotationNode annotation : methodNode.visibleAnnotations){
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Rewrite;")){
for (int i = 0; i < annotation.values.size(); i++) {
Object value = annotation.values.get(i);
if(value instanceof String && value.toString().equals("target")){
return Optional.of((String) annotation.values.get(i + 1));
}
}
}
}
return Optional.empty();
}
private boolean needsTargetMap(List<AnnotationNode> annotationNodes){
if(annotationNodes == null){
return false;
}
for(AnnotationNode annotation : annotationNodes){
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Rewrite;")){
return true;
}
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Inject;")){
return true;
}
}
return false;
}
private static ClassNode readClassFromBytes(byte[] bytes) {
ClassNode classNode = new org.objectweb.asm.tree.ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
return classNode;
}
private static byte[] writeClassToBytes(ClassNode classNode) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
}
}

View file

@ -1,53 +0,0 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016 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.util.proccessing;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.task.ProcessModsTask;
import net.fabricmc.loom.util.Constants;
import org.gradle.api.Project;
import java.io.File;
import java.util.List;
public class PreBakeMixins {
public void proccess(Project project, LoomGradleExtension extension, List<File> mods) {
project.getLogger().lifecycle(":Found " + mods.size() + " mods to prebake");
String[] args = new String[mods.size() + 4];
args[0] = "-m";
args[1] = Constants.MAPPINGS_TINY.get(extension).getAbsolutePath();
args[2] = Constants.MINECRAFT_MAPPED_JAR.get(extension).getAbsolutePath();
args[3] = Constants.MINECRAFT_FINAL_JAR.get(extension).getAbsolutePath();
for (int i = 0; i < mods.size(); i++) {
args[i + 4] = mods.get(i).getAbsolutePath();
}
project.getLogger().lifecycle(":preBaking mixins");
ProcessModsTask.addFile(Constants.MINECRAFT_MAPPED_JAR.get(extension), this);
//LogManager.getFormatterLogger("test");
// MixinPrebaker.main(args);
}
}

View file

@ -1 +0,0 @@
net.fabricmc.loom.mixin.ObfuscationServiceFabric