mixinbooter compat

This commit is contained in:
FalsePattern committed 2022-08-20 20:08:26 +02:00
1 parent 44dea11f92
commit 0b3c0a9b3a
12 files changed
+196 -47

No files matched your search

+56 -35
View File
@@ -1,4 +1,4 @@
//version: 1656003793falsepattern29
//version: 1656003793falsepattern31
/*
DO NOT CHANGE THIS FILE!
@@ -24,7 +24,7 @@ buildscript {
mavenLocal()
maven {
name = "forge"
url = "https://maven.minecraftforge.net"
url = "https://mvn.falsepattern.com/forge/"
}
maven {
name = "sonatype"
@@ -36,11 +36,11 @@ buildscript {
}
maven {
name = "jitpack"
url = "https://jitpack.falsepattern.com/"
url = "https://mvn.falsepattern.com/jitpack/"
}
maven {
name = "mavenpattern"
url = "https://maven.falsepattern.com/"
name = "mvnpattern"
url = "https://mvn.falsepattern.com/releases/"
}
}
dependencies {
@@ -120,11 +120,18 @@ propertyDefaultIfUnset("mavenArtifactId", "")
propertyDefaultIfUnset("hasMixinDeps", false)
propertyDefaultIfUnset("mixinPreinitConfig", "")
propertyDefaultIfUnset("remapStubs", false)
propertyDefaultIfUnset("useObsoleteSpongeMixins", false)
propertyDefaultIfUnset("remoteMappings", "https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/")
propertyDefaultIfUnset("mappingsChannel", "stable")
propertyDefaultIfUnset("mappingsVersion", "12")
if (usesMixins.toBoolean() && !useObsoleteSpongeMixins.toBoolean()) {
//1.1.2
//Currently using upstream, will make a fork soon(tm)
apply from: 'https://raw.githubusercontent.com/tox1cozZ/mixin-booter-legacy/30de05f4c3e41360f423d8c5fd4adc73d4677a37/gradle/configurations/v1.gradle'
}
String javaSourceDir = "src/main/java/"
String scalaSourceDir = "src/main/scala/"
String kotlinSourceDir = "src/main/kotlin/"
@@ -271,43 +278,53 @@ repositories {
url = "https://gregtech.overminddl1.com/"
}
if(usesMixins.toBoolean() || hasMixinDeps.toBoolean()) {
maven {
name = "sponge"
url = "https://sponge.falsepattern.com/"
if (useObsoleteSpongeMixins.toBoolean()) {
maven {
name = "sponge"
url = "https://mvn.falsepattern.com/sponge"
}
}
maven {
url = "https://jitpack.falsepattern.com/"
url = "https://mvn.falsepattern.com/jitpack"
}
}
}
dependencies {
if(usesMixins.toBoolean()) {
annotationProcessor("org.ow2.asm:asm-debug-all:5.0.3")
annotationProcessor("com.google.guava:guava:24.1.1-jre")
annotationProcessor("com.google.code.gson:gson:2.8.6")
annotationProcessor("org.spongepowered:mixin:0.8-20200110.181151-15")
// using 0.8 to workaround a issue in 0.7 which fails mixin application
compile("org.spongepowered:mixin:0.7.11-20180703.121122-1") {
// 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"
if (useObsoleteSpongeMixins.toBoolean()) {
annotationProcessor("org.ow2.asm:asm-debug-all:5.0.3")
annotationProcessor("com.google.guava:guava:24.1.1-jre")
annotationProcessor("com.google.code.gson:gson:2.8.6")
annotationProcessor("org.spongepowered:mixin:0.8-20200110.181151-15")
// using 0.8 to workaround a issue in 0.7 which fails mixin application
compile("org.spongepowered:mixin:0.7.11-20180703.121122-1") {
// 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"
}
compile("com.github.GTNewHorizons:SpongeMixins:1.3.3:dev")
} else {
compile("com.github.tox1cozZ:mixin-booter-legacy:1.1.2")
}
compile("com.github.GTNewHorizons:SpongeMixins:1.3.3:dev")
}
if(hasMixinDeps.toBoolean()) {
runtime("org.spongepowered:mixin:0.7.11-20180703.121122-1") {
// 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"
if (useObsoleteSpongeMixins.toBoolean()) {
runtime("org.spongepowered:mixin:0.7.11-20180703.121122-1") {
// 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"
}
runtime("com.github.GTNewHorizons:SpongeMixins:1.3.3:dev")
} else {
runtime("com.github.tox1cozZ:mixin-booter-legacy:1.1.2")
}
runtime("com.github.GTNewHorizons:SpongeMixins:1.3.3:dev")
}
}
@@ -378,7 +395,7 @@ jar {
}
reobf {
if(usesMixins.toBoolean()) {
if(usesMixins.toBoolean() && useObsoleteSpongeMixins.toBoolean() && file(mixinSrg).exists()) {
addExtraSrgFile mixinSrg
}
}
@@ -386,10 +403,14 @@ reobf {
afterEvaluate {
if(usesMixins.toBoolean()) {
tasks.compileJava {
if (useObsoleteSpongeMixins.toBoolean()) {
options.compilerArgs += [
"-AreobfSrgFile=${tasks.reobf.srg}",
"-AoutSrgFile=${mixinSrg}",
"-AoutRefMapFile=${refMap}"
]
}
options.compilerArgs += [
"-AreobfSrgFile=${tasks.reobf.srg}",
"-AoutSrgFile=${mixinSrg}",
"-AoutRefMapFile=${refMap}",
// Elan: from what I understand they are just some linter configs so you get some warning on how to properly code
"-XDenableSunApiLintControl",
"-XDignore.symbol.file"
@@ -694,7 +715,7 @@ task updateBuildScript {
}
}
if (!skipBuildScriptUpdateCheck.toBoolean() && isNewBuildScriptVersionAvailable(projectDir.toString())) {
if (!project.getGradle().startParameter.isOffline() && !skipBuildScriptUpdateCheck.toBoolean() && isNewBuildScriptVersionAvailable(projectDir.toString())) {
if (autoUpdateBuildScript.toBoolean()) {
performBuildScriptUpdate(projectDir.toString())
} else {
+1 -1
View File
@@ -2,7 +2,7 @@ dependencies {
compileOnly("org.projectlombok:lombok:1.18.22") {
transitive = false
}
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
compileOnly("com.github.tox1cozZ:mixin-booter-legacy:1.1.2") {
transitive = false
}
compileOnly("com.falsepattern:json:0.4.1")
+6 -1
View File
@@ -70,10 +70,15 @@ mixinPlugin =
mixinsPackage =
# Specify a preinit mixin here. Preinit mixins should be used very rarely, if at all, so this mixin config will not be managed by the buildscript, only included.
mixinPreinitConfig =
# By default, the buildscript uses mixin-booter-legacy for mixins. You can force the buildscript to use the obsolete SpongeMixins
# library using this setting.
# MixinBooterLegacy provides Mixins 0.8.2
# SpongeMixins provides Mixins 0.7.11 on the official version, and Mixins 0.7.12 on the nh version
useObsoleteSpongeMixins = false
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatability only
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
coreModClass = internal.CoreLoadingPlugin
coreModClass = internal.asm.CoreLoadingPlugin
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
containsMixinsAndOrCoreModOnly = false
+5 -1
View File
@@ -1,7 +1,11 @@
repositories {
maven {
name = "sponge"
url = "https://mvn.falsepattern.com/sponge"
url = "https://mvn.falsepattern.com/sponge/"
}
maven {
name = "jitpack"
url = "https://mvn.falsepattern.com/jitpack/"
}
maven {
name = "mvnpattern"
@@ -24,7 +24,7 @@ import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.asm.exceptions.AsmClassNotFoundException;
import com.falsepattern.lib.asm.exceptions.AsmFieldNotFoundException;
import com.falsepattern.lib.asm.exceptions.AsmMethodNotFoundException;
import com.falsepattern.lib.internal.CoreLoadingPlugin;
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
import com.falsepattern.lib.mapping.MappingManager;
import com.falsepattern.lib.mapping.types.MappingType;
import com.falsepattern.lib.mapping.types.NameType;
@@ -21,7 +21,7 @@
package com.falsepattern.lib.asm;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.CoreLoadingPlugin;
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
import lombok.val;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassReader;
@@ -18,8 +18,10 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal;
package com.falsepattern.lib.internal.asm;
import com.falsepattern.lib.internal.Tags;
import com.falsepattern.lib.internal.asm.FPTransformer;
import lombok.Getter;
import lombok.val;
@@ -36,6 +38,7 @@ import java.util.Map;
@MCVersion("1.7.10")
@Name(Tags.MODID)
@SortingIndex(500)
@IFMLLoadingPlugin.TransformerExclusions({Tags.GROUPNAME + ".internal.asm", Tags.GROUPNAME + ".asm"})
public class CoreLoadingPlugin implements IFMLLoadingPlugin {
@Getter
private static boolean obfuscated;
@@ -101,7 +104,7 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin {
@Override
public String[] getASMTransformerClass() {
return null;
return new String[]{Tags.GROUPNAME + ".internal.asm.FPTransformer"};
}
@Override
@@ -0,0 +1,36 @@
package com.falsepattern.lib.internal.asm;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.asm.IClassNodeTransformer;
import com.falsepattern.lib.asm.SmartTransformer;
import com.falsepattern.lib.internal.Tags;
import lombok.Getter;
import lombok.experimental.Accessors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Collections;
import java.util.List;
@Accessors(fluent = true)
@StableAPI(since = "__INTERNAL__")
public class FPTransformer implements SmartTransformer {
@Getter
private final List<IClassNodeTransformer> transformers;
@Getter
private final Logger logger = LogManager.getLogger(Tags.MODNAME + " ASM");
public FPTransformer() {
boolean obsolete;
try {
Class.forName("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin");
logger.info("Detected MixinBooter Legacy.");
obsolete = false;
} catch (ClassNotFoundException e) {
logger.info("Detected SpongeMixins or Grimoire. Applying legacy compat fix to IMixinPlugin.");
obsolete = true;
}
transformers = Collections.singletonList(new IMixinPluginTransformer(obsolete));
}
}
@@ -0,0 +1,50 @@
package com.falsepattern.lib.internal.asm;
import com.falsepattern.lib.asm.IClassNodeTransformer;
import com.falsepattern.lib.internal.Tags;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import java.util.ArrayList;
@RequiredArgsConstructor
public class IMixinPluginTransformer implements IClassNodeTransformer {
private final boolean obsolete;
@Override
public String getName() {
return "IMixinPluginTransformer";
}
@Override
public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) {
return transformedName.equals(Tags.GROUPNAME + ".mixin.IMixinPlugin");
}
@Override
public void transform(ClassNode cn, String transformedName, boolean obfuscated) {
val methods = cn.methods;
val remove = new ArrayList<MethodNode>();
if (obsolete) {
for (val method : methods) {
if (method.name.equals("preApply") || method.name.equals("postApply")) {
remove.add(method);
}
}
methods.removeAll(remove);
for (val method : methods) {
if (method.name.equals("preApply_obsolete") || method.name.equals("postApply_obsolete")) {
method.name = method.name.substring(0, method.name.indexOf('_'));
}
}
} else {
for (val method : methods) {
if (method.name.equals("preApply_obsolete") || method.name.equals("postApply_obsolete")) {
remove.add(method);
}
}
}
}
}
@@ -24,7 +24,7 @@ import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.dependencies.DependencyLoader;
import com.falsepattern.lib.dependencies.Library;
import com.falsepattern.lib.dependencies.SemanticVersion;
import com.falsepattern.lib.internal.CoreLoadingPlugin;
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
import com.falsepattern.lib.mapping.storage.Lookup;
import com.falsepattern.lib.mapping.types.MappingType;
import com.falsepattern.lib.mapping.types.NameType;
@@ -21,7 +21,7 @@
package com.falsepattern.lib.mapping.types;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.CoreLoadingPlugin;
import com.falsepattern.lib.internal.asm.CoreLoadingPlugin;
import com.falsepattern.lib.mapping.storage.Lookup;
import com.falsepattern.lib.mapping.storage.MappedString;
import lombok.EqualsAndHashCode;
@@ -73,26 +73,31 @@ public interface IMixinPlugin extends IMixinConfigPlugin {
ITargetedMod[] getTargetedModEnumValues();
@Override
@StableAPI.Expose(since = "__INTERNAL__")
default void onLoad(String mixinPackage) {
}
@Override
@StableAPI.Expose(since = "__INTERNAL__")
default String getRefMapperConfig() {
return null;
}
@Override
@StableAPI.Expose(since = "__INTERNAL__")
default boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return true;
}
@Override
@StableAPI.Expose(since = "__INTERNAL__")
default void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}
@Override
@StableAPI.Expose(since = "__INTERNAL__")
default List<String> getMixins() {
val isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
val targetedMods = getTargetedModEnumValues();
@@ -119,6 +124,7 @@ public interface IMixinPlugin extends IMixinConfigPlugin {
return mixins;
}
@StableAPI.Expose(since = "__INTERNAL__")
default boolean loadJarOf(final ITargetedMod mod) {
boolean success = false;
try {
@@ -140,13 +146,37 @@ public interface IMixinPlugin extends IMixinConfigPlugin {
return success;
}
@Override
default void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
/**
* Fallback for spongemixins. Removed for mixinbooter
*/
@StableAPI.Expose(since = "__INTERNAL__")
default void preApply_obsolete(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
/**
* Fallback for spongemixins. Removed for mixinbooter
*/
@StableAPI.Expose(since = "__INTERNAL__")
default void postApply_obsolete(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
/**
* Regular behaviour for mixinbooter. Removed for spongemixins
*/
@Override
default void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
@StableAPI.Expose(since = "__INTERNAL__")
default void preApply(String targetClassName, org.spongepowered.libraries.org.objectweb.asm.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
/**
* Regular behaviour for mixinbooter. Removed for spongemixins
*/
@Override
@StableAPI.Expose(since = "__INTERNAL__")
default void postApply(String targetClassName, org.spongepowered.libraries.org.objectweb.asm.tree.ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}