diff --git a/.gitignore b/.gitignore index d4c25ad90..5b420a0e4 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ baritone_Client.launch .vscode/launch.json +libs/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar +libs/java-objc-bridge-1.1.jar diff --git a/build.gradle b/build.gradle index 8e952df73..70f8a7adf 100755 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ buildscript { repositories { maven { name = 'forge' - url = 'http://files.minecraftforge.net/maven' + url = 'https://files.minecraftforge.net/maven' } maven { name = 'SpongePowered' @@ -32,18 +32,19 @@ buildscript { } dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT' + classpath 'net.minecraftforge.gradle:ForgeGradle:4.+' // TODO: 5.+. `doHackyStuff` relies on 4.x internals. + classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' } } - import baritone.gradle.task.CreateDistTask import baritone.gradle.task.ProguardTask apply plugin: 'java' -apply plugin: 'maven' -apply plugin: 'net.minecraftforge.gradle.tweaker-client' +apply plugin: 'maven-publish' +apply plugin: 'net.minecraftforge.gradle' +apply from: 'hacks.gradle' +ext.doHackyStuff(Class.forName('net.minecraftforge.gradle.mcp.task.GenerateSRG')) // TODO: fg 5.0 - `ext.doHackyStuff(Class.forName('net.minecraftforge.gradle.mcp.tasks.GenerateSRG'))` apply plugin: 'org.spongepowered.mixin' sourceCompatibility = targetCompatibility = '1.8' @@ -53,8 +54,19 @@ compileJava { } sourceSets { + api { + compileClasspath += main.compileClasspath + } + main { + compileClasspath += api.output + } + test { + compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output + runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output + } launch { compileClasspath += main.compileClasspath + main.runtimeClasspath + main.output + runtimeClasspath += main.compileClasspath + main.runtimeClasspath + main.output } schematica_api { @@ -67,13 +79,26 @@ sourceSets { } minecraft { - version = '1.12.2' - mappings = 'stable_39' - tweakClass = 'baritone.launch.BaritoneTweaker' - runDir = 'run' + mappings channel: 'stable', version: '39-1.12' + runs { + def nativesOutput = extractNatives.output // TODO: fg 5.0 - `def nativesOutput = extractNatives.output.get()` + println("[Baritoe] Detected natives: ${nativesOutput}") + client { + workingDirectory project.file('run') + source sourceSets.launch - // The sources jar should use SRG names not MCP to ensure compatibility with all mappings - makeObfSourceJar = true + main 'net.minecraft.launchwrapper.Launch' + + args '--gameDir', '.' + args '--version', '1.12.2' + args '--assetsDir', downloadAssets.output + args '--assetIndex', '{asset_index}' + args '--accessToken', 'INVALID' + + args '--tweakClass', 'baritone.launch.BaritoneTweaker' + jvmArgs "-Dorg.lwjgl.librarypath=${nativesOutput}" + } + } } repositories { @@ -95,23 +120,66 @@ repositories { } } -dependencies { - runtime launchCompile('com.github.ImpactDevelopment:SimpleTweaker:1.2') - runtime launchCompile('org.spongepowered:mixin:0.7.11-SNAPSHOT') { - // Mixin includes a lot of dependencies that are too up-to-date - exclude module: 'launchwrapper' - exclude module: 'guava' - exclude module: 'gson' - exclude module: 'commons-io' - exclude module: 'log4j-core' +// fix forge gradle 4+ bug with 1.12.2 +afterEvaluate { + configurations.minecraft { + exclude group: 'net.minecraftforge', module: 'mergetool' } - runtime launchCompile('dev.babbaj:nether-pathfinder:0.2') +} + +// lwjgl2 hack for running game on arm64 mac os +afterEvaluate { + def os = org.gradle.internal.os.OperatingSystem.current() + if (os.isMacOsX()) { + def arch = System.getProperty("os.arch").toLowerCase() + println("Detected Mac OS X running on ${arch}") + if (arch == "aarch64") { + println("Configurating aarch64 dependencies.") + + configurations.minecraft { + exclude group: 'ca.weblite', module: 'java-objc-bridge' + } + + dependencies { + // https://github.com/MinecraftMachina/lwjgl/releases/download/2.9.4-20150209-mmachina.2/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar + minecraft files("libs/lwjgl-platform-2.9.4-nightly-20150209-natives-osx.jar") // TODO: use prism launcher maven + // https://github.com/MinecraftMachina/Java-Objective-C-Bridge/releases/download/1.1.0-mmachina.1/java-objc-bridge-1.1.jar + minecraft files("libs/java-objc-bridge-1.1.jar") // TODO: use prism launcher maven + minecraft(group: 'net.java.dev.jna', name: 'jna') { + version { + strictly '5.12.1' + } + } + } + } + } +} + +dependencies { + minecraft group: 'net.minecraft', name: 'joined', version: '1.12.2' + implementation(group: 'net.minecraft', name: 'launchwrapper', version: '1.12') { + transitive = false + } + + def asmVersion = '9.5' + implementation group: 'org.ow2.asm', name: 'asm', version: asmVersion + implementation group: 'org.ow2.asm', name: 'asm-tree', version: asmVersion + implementation group: 'org.ow2.asm', name: 'asm-commons', version: asmVersion + implementation group: 'org.ow2.asm', name: 'asm-analysis', version: asmVersion + implementation group: 'org.ow2.asm', name: 'asm-util', version: asmVersion + + launchImplementation('com.github.ImpactDevelopment:SimpleTweaker:1.2') + launchImplementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') { + // Mixin includes a lot of dependencies that are too up-to-date + transitive = false + } + launchAnnotationProcessor 'org.spongepowered:mixin:0.8.4-SNAPSHOT:processor' + launchImplementation('dev.babbaj:nether-pathfinder:0.2') testImplementation 'junit:junit:4.12' implementation 'dev.babbaj:nether-pathfinder:0.2' } mixin { - defaultObfuscationEnv searge add sourceSets.launch, 'mixins.baritone.refmap.json' } @@ -137,7 +205,7 @@ jar { manifest { attributes( 'MixinConfigs': 'mixins.baritone.json', - + 'TweakClass': 'baritone.launch.BaritoneTweaker', 'Implementation-Title': 'Baritone', 'Implementation-Version': version ) @@ -152,25 +220,3 @@ task proguard(type: ProguardTask) { task createDist(type: CreateDistTask, dependsOn: proguard) build.finalizedBy(createDist) - -install { - def jarApiName = String.format("%s-api-%s", rootProject.name, version.toString()) - def jarApiForgeName = String.format("%s-api-forge-%s", rootProject.name, version.toString()) - def jarSAName = String.format("%s-standalone-%s", rootProject.name, version.toString()) - def jarSAForgeName = String.format("%s-standalone-forge-%s", rootProject.name, version.toString()) - - artifacts { - archives file("$buildDir/libs/" + jarApiName + ".jar") - archives file("$buildDir/libs/" + jarApiForgeName + ".jar") - archives file("$buildDir/libs/" + jarSAName + ".jar") - archives file("$buildDir/libs/" + jarSAForgeName + ".jar") - } - repositories.mavenInstaller { - addFilter('api') { artifact, file -> artifact.name == "baritone-api" } - addFilter('api-forge') { artifact, file -> artifact.name == "baritone-api-forge" } - addFilter('standalone') { artifact, file -> artifact.name == "baritone-standalone" } - addFilter('standalone-forge') { artifact, file -> artifact.name == "baritone-standalone-forge" } - } -} - -install.dependsOn(build) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 2ac49af0f..8ab0f7014 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -20,6 +20,6 @@ repositories { } dependencies { - compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5' - compile group: 'commons-io', name: 'commons-io', version: '2.6' + implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5' + implementation group: 'commons-io', name: 'commons-io', version: '2.6' } \ No newline at end of file diff --git a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java index 1c329ee2c..435eabcf3 100644 --- a/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java +++ b/buildSrc/src/main/java/baritone/gradle/task/ProguardTask.java @@ -18,39 +18,33 @@ package baritone.gradle.task; import baritone.gradle.util.Determinizer; -import baritone.gradle.util.MappingType; -import baritone.gradle.util.ReobfWrapper; import org.apache.commons.io.IOUtils; -import org.gradle.api.JavaVersion; -import org.gradle.api.NamedDomainObjectContainer; +import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; -import org.gradle.api.internal.file.IdentityFileResolver; -import org.gradle.api.internal.plugins.DefaultConvention; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskCollection; import org.gradle.api.tasks.compile.ForkOptions; import org.gradle.api.tasks.compile.JavaCompile; -import org.gradle.internal.Pair; import org.gradle.internal.jvm.Jvm; -import org.gradle.internal.jvm.inspection.DefaultJvmVersionDetector; -import org.gradle.process.internal.DefaultExecActionFactory; + +import java.io.File; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.util.Objects; import java.io.*; -import java.lang.reflect.Field; import java.net.URL; import java.nio.file.Files; -import java.nio.file.Path; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; - /** * @author Brady * @since 10/11/2018 @@ -138,23 +132,16 @@ public class ProguardTask extends BaritoneGradleTask { private String findJavaByGradleCurrentRuntime() { String path = Jvm.current().getJavaExecutable().getAbsolutePath(); - - if (this.validateJavaVersion(path)) { - System.out.println("Using Gradle's runtime Java for ProGuard"); - return path; - } - return null; + System.out.println("Using Gradle's runtime Java for ProGuard"); + return path; } private String findJavaByJavaHome() { final String javaHomeEnv = System.getenv("JAVA_HOME"); if (javaHomeEnv != null) { - String path = Jvm.forHome(new File(javaHomeEnv)).getJavaExecutable().getAbsolutePath(); - if (this.validateJavaVersion(path)) { - System.out.println("Detected Java path by JAVA_HOME"); - return path; - } + System.out.println("Detected Java path by JAVA_HOME"); + return path; } return null; } @@ -170,19 +157,11 @@ public class ProguardTask extends BaritoneGradleTask { if (javacPath != null) { File javacFile = new File(javacPath); if (javacFile.exists()) { - File[] maybeJava = javacFile.getParentFile().listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.equals("java"); - } - }); - + File[] maybeJava = javacFile.getParentFile().listFiles((dir, name) -> name.equals("java")); if (maybeJava != null && maybeJava.length > 0) { String path = maybeJava[0].getAbsolutePath(); - if (this.validateJavaVersion(path)) { - System.out.println("Detected Java path by forkOptions"); - return path; - } + System.out.println("Detected Java path by forkOptions"); + return path; } } } @@ -190,21 +169,8 @@ public class ProguardTask extends BaritoneGradleTask { return null; } - private boolean validateJavaVersion(String java) { - final JavaVersion javaVersion = new DefaultJvmVersionDetector(new DefaultExecActionFactory(new IdentityFileResolver())).getJavaVersion(java); - - if (!javaVersion.getMajorVersion().equals("8")) { - System.out.println("Failed to validate Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars"); - // throw new RuntimeException("Java version incorrect: " + javaVersion.getMajorVersion() + " for " + java); - return false; - } - - System.out.println("Validated Java version " + javaVersion.toString() + " [" + java + "] for ProGuard libraryjars"); - return true; - } - private void generateConfigs() throws Exception { - Files.copy(getRelativeFile(PROGUARD_CONFIG_TEMPLATE), getTemporaryFile(PROGUARD_CONFIG_DEST), REPLACE_EXISTING); + Files.copy(getRelativeFile(PROGUARD_CONFIG_TEMPLATE), getTemporaryFile(PROGUARD_CONFIG_DEST), StandardCopyOption.REPLACE_EXISTING); // Setup the template that will be used to derive the API and Standalone configs List template = Files.readAllLines(getTemporaryFile(PROGUARD_CONFIG_DEST)); @@ -236,14 +202,37 @@ public class ProguardTask extends BaritoneGradleTask { }); } - private void acquireDependencies() throws Exception { + private static final class Pair { + public final A a; + public final B b; + private Pair(final A a, final B b) { + this.a = a; + this.b = b; + } + + @Override + public String toString() { + return "Pair{" + + "a=" + this.a + + ", " + + "b=" + this.b + + '}'; + } + } + + private void acquireDependencies() throws Exception { // Create a map of all of the dependencies that we are able to access in this project // Likely a better way to do this, I just pair the dependency with the first valid configuration Map> dependencyLookupMap = new HashMap<>(); - getProject().getConfigurations().stream().filter(Configuration::isCanBeResolved).forEach(config -> - config.getAllDependencies().forEach(dependency -> - dependencyLookupMap.putIfAbsent(dependency.getName() + "-" + dependency.getVersion(), Pair.of(config, dependency)))); + Map files = new HashMap<>(); + getProject().getConfigurations().stream().filter(Configuration::isCanBeResolved).forEach(config -> { + for (File file : config.getFiles()) { + files.put(file.getName(), file); + } + config.getAllDependencies().forEach(dependency -> + dependencyLookupMap.putIfAbsent(dependency.getName() + "-" + dependency.getVersion(), new Pair<>(config, dependency))); + }); // Create the directory if it doesn't already exist Path tempLibraries = getTemporaryFile(TEMP_LIBRARY_DIR); @@ -258,7 +247,7 @@ public class ProguardTask extends BaritoneGradleTask { Path cachedJar = getMinecraftJar(); Path inTempDir = getTemporaryFile("tempLibraries/minecraft.jar"); // TODO: maybe try not to copy every time - Files.copy(cachedJar, inTempDir, REPLACE_EXISTING); + Files.copy(cachedJar, inTempDir, StandardCopyOption.REPLACE_EXISTING); continue; } @@ -270,20 +259,21 @@ public class ProguardTask extends BaritoneGradleTask { pair = entry.getValue(); } } - - // The pair must be non-null - Objects.requireNonNull(pair); - // Find the library jar file, and copy it to tempLibraries - for (File file : pair.getLeft().files(pair.getRight())) { - if (file.getName().startsWith(lib)) { - if (lib.contains("mixin")) { - mixin = file; + if (pair == null) { + File libFile = files.get(lib + ".jar"); + if (libFile == null) { + libFile = files.values().stream().filter(file -> file.getName().startsWith(lib)).findFirst().orElse(null); + if (libFile == null) { + throw new IllegalStateException(lib); } - if (lib.contains("nether-pathfinder")) { - pathfinder = file; + } + copyTempLib(lib, libFile); + } else { + for (File file : pair.a.files(pair.b)) { + if (file.getName().startsWith(lib)) { + copyTempLib(lib, file); } - Files.copy(file.toPath(), getTemporaryFile("tempLibraries/" + lib + ".jar"), REPLACE_EXISTING); } } } @@ -295,87 +285,39 @@ public class ProguardTask extends BaritoneGradleTask { } } + private void copyTempLib(String lib, File libFile) throws IOException { + if (lib.contains("mixin")) { + mixin = libFile; + } + if (lib.contains("nether-pathfinder")) { + pathfinder = libFile; + } + Files.copy(libFile.toPath(), getTemporaryFile("tempLibraries/" + lib + ".jar"), StandardCopyOption.REPLACE_EXISTING); + } + // a bunch of epic stuff to get the path to the cached jar private Path getMinecraftJar() throws Exception { - MappingType mappingType; - try { - mappingType = getMappingType(); - } catch (Exception e) { - System.err.println("Failed to get mapping type, assuming NOTCH."); - mappingType = MappingType.NOTCH; - } - - String suffix; - switch (mappingType) { - case NOTCH: - suffix = ""; - break; - case SEARGE: - suffix = "-srgBin"; - break; - case CUSTOM: - throw new IllegalStateException("Custom mappings not supported!"); - default: - throw new IllegalStateException("Unknown mapping type: " + mappingType); - } - - DefaultConvention convention = (DefaultConvention) this.getProject().getConvention(); - Object extension = convention.getAsMap().get("minecraft"); - Objects.requireNonNull(extension); - - // for some reason cant use Class.forName - Class class_baseExtension = extension.getClass().getSuperclass().getSuperclass().getSuperclass(); // <-- cursed - Field f_replacer = class_baseExtension.getDeclaredField("replacer"); - f_replacer.setAccessible(true); - Object replacer = f_replacer.get(extension); - Class class_replacementProvider = replacer.getClass(); - Field replacement_replaceMap = class_replacementProvider.getDeclaredField("replaceMap"); - replacement_replaceMap.setAccessible(true); - - Map replacements = (Map) replacement_replaceMap.get(replacer); - String cacheDir = replacements.get("CACHE_DIR").toString() + "/net/minecraft"; - String mcVersion = replacements.get("MC_VERSION").toString(); - String mcpInsert = replacements.get("MAPPING_CHANNEL").toString() + "/" + replacements.get("MAPPING_VERSION").toString(); - String fullJarName = "minecraft-" + mcVersion + suffix + ".jar"; - - String baseDir = String.format("%s/minecraft/%s/", cacheDir, mcVersion); - - String jarPath; - if (mappingType == MappingType.SEARGE) { - jarPath = String.format("%s/%s/%s", baseDir, mcpInsert, fullJarName); - } else { - jarPath = baseDir + fullJarName; - } - jarPath = jarPath - .replace("/", File.separator) - .replace("\\", File.separator); // hecking regex - - return new File(jarPath).toPath(); + return getObfuscatedMinecraftJar(getProject(), false); // always notch jar for now. } - // throws IllegalStateException if mapping type is ambiguous or it fails to find it - private MappingType getMappingType() { - // if it fails to find this then its probably a forgegradle version problem - Set reobf = (NamedDomainObjectContainer) this.getProject().getExtensions().getByName("reobf"); + private static Path getObfuscatedMinecraftJar(final Project project, final boolean srg) throws Exception { + final Object extension = Objects.requireNonNull(project.getExtensions().findByName("minecraft"), "Unable to find Minecraft extension."); - List mappingTypes = getUsedMappingTypes(reobf); - long mappingTypesUsed = mappingTypes.size(); - if (mappingTypesUsed == 0) { - throw new IllegalStateException("Failed to find mapping type (no jar task?)"); - } - if (mappingTypesUsed > 1) { - throw new IllegalStateException("Ambiguous mapping type (multiple jars with different mapping types?)"); - } + final Class mcpRepoClass = mcpRepoClass(extension.getClass().getClassLoader()); + final Field mcpRepoInstanceField = mcpRepoClass.getDeclaredField("INSTANCE"); + mcpRepoInstanceField.setAccessible(true); + final Method findMethod = mcpRepoClass.getDeclaredMethod(srg ? "findSrg" : "findRaw", String.class, String.class); + findMethod.setAccessible(true); - return mappingTypes.get(0); + final Object mcpRepo = mcpRepoInstanceField.get(null); + final String mcpVersion = (String) Objects.requireNonNull(project.getExtensions().getExtraProperties().get("MCP_VERSION"), "Extra property \"MCP_VERSION\" not found"); + return ((File) findMethod.invoke(mcpRepo, "joined", mcpVersion)).toPath(); } - private List getUsedMappingTypes(Set reobf) { - return reobf.stream() - .map(ReobfWrapper::new) - .map(ReobfWrapper::getMappingType) - .distinct() - .collect(Collectors.toList()); + private static Class mcpRepoClass(final ClassLoader loader) throws Exception { + final Method forName0 = Class.class.getDeclaredMethod("forName0", String.class, boolean.class, ClassLoader.class, Class.class); + forName0.setAccessible(true); + return (Class) forName0.invoke(null, "net.minecraftforge.gradle.mcp.MCPRepo", true, loader, null); } private void proguardApi() throws Exception { @@ -400,10 +342,18 @@ public class ProguardTask extends BaritoneGradleTask { this.url = url; } + public String getUrl() { + return url; + } + public void setExtract(String extract) { this.extract = extract; } + public String getExtract() { + return extract; + } + private void runProguard(Path config) throws Exception { // Delete the existing proguard output file. Proguard probably handles this already, but why not do it ourselves if (Files.exists(this.proguardOut)) { diff --git a/buildSrc/src/main/java/baritone/gradle/util/MappingType.java b/buildSrc/src/main/java/baritone/gradle/util/MappingType.java deleted file mode 100644 index a3be9b49f..000000000 --- a/buildSrc/src/main/java/baritone/gradle/util/MappingType.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.gradle.util; - -/** - * All credits go to AsmLibGradle and its contributors. - * - * @see Original Source - */ -public enum MappingType { - SEARGE, - NOTCH, - CUSTOM // forgegradle -} diff --git a/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java b/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java deleted file mode 100644 index f752cd946..000000000 --- a/buildSrc/src/main/java/baritone/gradle/util/ReobfWrapper.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This file is part of Baritone. - * - * Baritone is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Baritone is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Baritone. If not, see . - */ - -package baritone.gradle.util; - -import java.lang.reflect.Field; -import java.util.Objects; - -/** - * All credits go to AsmLibGradle and its contributors. - * - * @see Original Source - */ -public class ReobfWrapper { - - private final Object instance; - private final Class type; - - public ReobfWrapper(Object instance) { - this.instance = instance; - Objects.requireNonNull(instance); - this.type = instance.getClass(); - } - - public String getName() { - try { - Field nameField = type.getDeclaredField("name"); - nameField.setAccessible(true); - return (String) nameField.get(this.instance); - } catch (ReflectiveOperationException ex) { - throw new IllegalStateException(ex); - } - } - - public MappingType getMappingType() { - try { - Field enumField = type.getDeclaredField("mappingType"); - enumField.setAccessible(true); - Enum aEnum = (Enum) enumField.get(this.instance); - MappingType mappingType = MappingType.values()[aEnum.ordinal()]; - if (!aEnum.name().equals(mappingType.name())) { - throw new IllegalStateException("ForgeGradle ReobfMappingType is not equivalent to MappingType (version error?)"); - } - return mappingType; - } catch (ReflectiveOperationException ex) { - throw new IllegalStateException(ex); - } - } -} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 4c5670a15..7454180f2 100755 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 599a02b7a..c51cbf173 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Tue Jul 31 21:56:56 PDT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.4-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip diff --git a/gradlew b/gradlew index cccdd3d51..744e882ed 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -56,7 +72,7 @@ case "`uname`" in Darwin* ) darwin=true ;; - MINGW* ) + MSYS* | MINGW* ) msys=true ;; NONSTOP* ) @@ -66,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -109,10 +126,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -138,19 +156,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -159,14 +177,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +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 - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f9553162f..107acd32c 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -35,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -45,28 +64,14 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/hacks.gradle b/hacks.gradle new file mode 100644 index 000000000..821a4d02e --- /dev/null +++ b/hacks.gradle @@ -0,0 +1,161 @@ +/* + * This file is part of Baritone. + * + * Baritone is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Baritone is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Baritone. If not, see . + */ + +ext.doHackyStuff = { final Class clazz -> + def withExtension = { final File file, final String extension -> + def i = file.getName().lastIndexOf('.') + def name = file.getName().substring(0, i) + return new File(file.getParent(), "$name.$extension") + } + + // https://github.com/MinecraftForge/ForgeGradle/blob/6639464b29b0923187eee0a609e546ba9f1b998b/src/patcher/java/net/minecraftforge/gradle/patcher/PatcherPlugin.java#L545 + // https://github.com/MinecraftForge/ForgeGradle/blob/6639464b29b0923187eee0a609e546ba9f1b998b/src/userdev/java/net/minecraftforge/gradle/userdev/UserDevPlugin.java#L149 + // create createMcp2Obf task + this.tasks.register('createMcpToObf', clazz) + .configure { task -> + task.setNotch(true) + task.setReverse(true) + } + afterEvaluate { + def createMcp2Obf = this.tasks.getByName('createMcpToObf') + def createMcp2Srg = this.tasks.getByName('createMcpToSrg') + + // configure createMcp2Obf task + if (createMcp2Obf.getSrg() == null) { + createMcp2Obf.setSrg(createMcp2Srg.getSrg()) + createMcp2Obf.setMappings(createMcp2Srg.getMappings()) + createMcp2Obf.dependsOn(createMcp2Srg) + } + + def createSrgCopyTask = { final Task tsrgTask -> + def srgCopyTask = this.tasks.register("${tsrgTask.name}Srg", tsrgTask.getClass()) + tsrgTask.getDependsOn().forEach({ dep -> + srgCopyTask.get().dependsOn(dep) + }) + // https://github.com/MinecraftForge/ForgeGradle/blob/6639464b29b0923187eee0a609e546ba9f1b998b/src/mcp/java/net/minecraftforge/gradle/mcp/task/GenerateSRG.java#L39 + srgCopyTask.configure { task -> + task.setSrg(tsrgTask.getSrg()) + task.setMappings(tsrgTask.getMappings()) + // https://github.com/MinecraftForge/SrgUtils/blob/bb2ca35bb8d349a122ef512dedd24f54f7cd0bdf/src/main/java/net/minecraftforge/srgutils/IMappingFile.java#L44 + task.setFormat('SRG') + task.setNotch(tsrgTask.getNotch()) + task.setReverse(tsrgTask.getReverse()) + task.setOutput(withExtension(tsrgTask.getOutput(), 'srg')) + } + return srgCopyTask + } + def createMcp2ObfSrgCopyTask = createSrgCopyTask(createMcp2Obf) + createMcp2Obf.dependsOn(createMcp2ObfSrgCopyTask) + def createMcp2SrgSrgCopyTask = createSrgCopyTask(createMcp2Srg) + createMcp2Srg.dependsOn(createMcp2SrgSrgCopyTask) + + this.sourceSets.forEach({ set -> + def compileTask = this.project.tasks[set.compileJavaTaskName] + if (!(compileTask instanceof JavaCompile)) { + println("[Baritoe] Non-java compile task for ${set} of type ${compileTask}") + return + } + compileTask.dependsOn(createMcp2Obf) + compileTask.doFirst { + // inject legacy notch srg file + def createMcp2ObfSrgCopy = createMcp2ObfSrgCopyTask.get() + def reobfNotchSrgFileArgument = "-AreobfNotchSrgFile=${createMcp2ObfSrgCopy.output.canonicalPath}" + compileTask.options.compilerArgs += reobfNotchSrgFileArgument + println("[Baritoe] Injecting compiler argument: ${reobfNotchSrgFileArgument}") + + // inject legacy notch srg out file + def outTSrgFileArgument = '-AoutTsrgFile=' + def compilerArgsIterator = compileTask.options.compilerArgs.listIterator() + while (compilerArgsIterator.hasNext()) { + def compilerArg = compilerArgsIterator.next() + if (compilerArg.startsWith(outTSrgFileArgument)) { + def argumentFileValue = new File(compilerArg.substring(outTSrgFileArgument.length(), compilerArg.length())) + def outNotchSrgFile = withExtension(argumentFileValue, 'notch.srg') + def outNotchSrgFileArgument = "-AoutNotchSrgFile=${outNotchSrgFile.canonicalPath}" + println("[Baritoe] Injecting compiler argument: ${outNotchSrgFileArgument}") + compilerArgsIterator.add(outNotchSrgFileArgument) + } + } + } + }) + + // register reobf jars + def reobfExtension = this.project.getExtensions().getByName('reobf') + if (!reobfExtension) { + throw new IllegalStateException("Could not find \"reobf\" extension") + } + def reobfNotchJar = reobfExtension.create(jar.getName()) + reobfNotchJar.dependsOn(createMcp2Obf) + reobfNotchJar.setMappings(createMcp2Obf.getOutput()) + + // even more horrible hack :) for outNotchSrgFile injection + reobfNotchJar.doFirst { + // https://github.com/MinecraftForge/ForgeGradle/blob/6639464b29b0923187eee0a609e546ba9f1b998b/src/userdev/java/net/minecraftforge/gradle/userdev/tasks/RenameJar.java#L96 + def extraMappings = reobfNotchJar.getExtraMappings() + println("[Baritoe] Extra mappings: ${extraMappings}") + def copy = new ArrayList<>() + extraMappings.forEach { extraMapping -> + copy.add(withExtension(extraMapping, 'notch.srg')) + } + println("[Baritoe] New extra mappings: ${copy}") + reobfNotchJar.setExtraMappings(copy) + } + } +} + +// TODO: In-complete fg 5.0 port. Currently doesn't handle mixin notch srg mapping hack. +//ext.doHackyStuff = { final Class clazz -> +// afterEvaluate { +// def createMcp2Srg = this.tasks.getByName('createMcpToSrg') +// def createMcpToObf = this.tasks.register('createMcpToObf', clazz) +// createMcpToObf.configure { task -> +// task.setNotch(true) +// task.setReverse(true) +// task.getSrg().set(createMcp2Srg.getSrg().get()) +// task.getMappings().set(createMcp2Srg.getMappings().get()) +// task.dependsOn(createMcp2Srg) +// } +// reobf { +// jar { +// dependsOn(createMcpToObf) +// getMappings().set(createMcpToObf.get().getOutput().get()) +// } +// } +// this.sourceSets.forEach({ set -> +// def compileTask = this.project.tasks[set.compileJavaTaskName] +// if (!(compileTask instanceof JavaCompile)) { +// println("[Baritoe] Non-java compile task for ${set} of type ${compileTask}") +// return +// } +// compileTask.dependsOn(createMcpToObf) +// compileTask.doFirst { +// def reobfTSrgFile = '-AreobfTsrgFile=' +// def compilerArgsIterator = compileTask.options.compilerArgs.listIterator() +// while (compilerArgsIterator.hasNext()) { +// def compilerArg = compilerArgsIterator.next() +// if (compilerArg.startsWith(reobfTSrgFile)) { +// compilerArgsIterator.remove() +// def toInject = "-AreobfTsrgFile=${createMcpToObf.get().output.get().asFile.canonicalPath}" +// compilerArgsIterator.add(toInject) +// println("[Baritoe] Injecting compiler argument: ${toInject}") +// } +// } +// println("[Baritoe] Compiler arguments: ${compileTask.options.compilerArgs}") +// } +// }) +// } +//} \ No newline at end of file diff --git a/scripts/proguard.pro b/scripts/proguard.pro index 858494778..d493f60de 100644 --- a/scripts/proguard.pro +++ b/scripts/proguard.pro @@ -92,7 +92,7 @@ -libraryjars 'tempLibraries/text2speech-1.10.3.jar' -libraryjars 'tempLibraries/mixin-0.7.11-SNAPSHOT.jar' --libraryjars 'tempLibraries/launchwrapper-1.11.jar' # TODO why does only 1.11.jar exist? +-libraryjars 'tempLibraries/launchwrapper-1.12.jar' -libraryjars 'tempLibraries/nether-pathfinder-.jar'