diff --git a/.idea/runConfigurations/Build.xml b/.idea/runConfigurations/Build.xml
index 2bf3635..420ff67 100644
--- a/.idea/runConfigurations/Build.xml
+++ b/.idea/runConfigurations/Build.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/.idea/runConfigurations/Create_Repack_Mixin_Jar.xml b/.idea/runConfigurations/Create_Repack_Mixin_Jar.xml
index ee98b13..b65cd69 100644
--- a/.idea/runConfigurations/Create_Repack_Mixin_Jar.xml
+++ b/.idea/runConfigurations/Create_Repack_Mixin_Jar.xml
@@ -4,13 +4,14 @@
-
+
diff --git a/build.gradle b/build.gradle
index 70df301..69bd353 100644
--- a/build.gradle
+++ b/build.gradle
@@ -25,7 +25,7 @@ apply plugin: 'forge'
apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'
-version = '1.0.3'
+version = '1.1.0'
group = 'io.github.tox1cozz.mixinbooterlegacy'
sourceCompatibility = targetCompatibility = '1.8'
@@ -46,6 +46,7 @@ minecraft {
configurations {
repackMixin
+ repackMixinProcessor
sources {
transitive = false
}
@@ -75,11 +76,15 @@ dependencies {
// noinspection GradlePackageUpdate, VulnerableLibrariesLocal
repackMixin 'com.google.guava:guava:21.0'
+ repackMixinProcessor "org.spongepowered:mixin:$mixinVersion:processor"
+
sources "org.spongepowered:mixin:$mixinVersion:sources"
javadoc "org.spongepowered:mixin:$mixinVersion:javadoc"
- implementation name: "mixin-$mixinVersion-repack"
- annotationProcessor "org.spongepowered:mixin:$mixinVersion:processor"
+ if (findProperty('generateRepacks') == null) {
+ implementation name: "mixin-$mixinVersion-repack"
+ annotationProcessor name: "mixin-$mixinVersion-processor-repack"
+ }
}
reobf {
@@ -100,7 +105,9 @@ task repackMixinJar(type: ShadowJar) {
archiveFileName.set("mixin-$mixinVersion-repack.jar")
configurations = [project.configurations.repackMixin]
- exclude 'META-INF/MANIFSET.MF', 'META-INF/maven/**', 'META-INF/*.RSA', 'META-INF/*.SF'
+ mergeServiceFiles()
+
+ exclude 'META-INF/MANIFEST.MF', 'META-INF/maven/**', 'META-INF/*.RSA', 'META-INF/*.SF'
exclude '**/module-info.class'
relocate 'org.objectweb.asm', 'org.spongepowered.libraries.org.objectweb.asm'
@@ -108,6 +115,24 @@ task repackMixinJar(type: ShadowJar) {
relocate 'com.google.thirdparty.publicsuffix', 'org.spongepowered.libraries.com.google.thirdparty.publicsuffix'
}
+// Execute for generate mixin annotation processor repack jar
+task repackMixinProcessorJar(type: ShadowJar) {
+ destinationDirectory.set(layout.projectDirectory.dir('dependencies'))
+ archiveFileName.set("mixin-$mixinVersion-processor-repack.jar")
+ configurations = [project.configurations.repackMixinProcessor]
+
+ mergeServiceFiles()
+
+ exclude 'META-INF/MANIFEST.MF', 'META-INF/maven/**', 'META-INF/*.RSA', 'META-INF/*.SF'
+ exclude '**/module-info.class'
+
+ relocate 'org.objectweb.asm', 'org.spongepowered.libraries.org.objectweb.asm'
+ relocate 'com.google.common', 'org.spongepowered.libraries.com.google.common'
+ relocate 'com.google.gson', 'org.spongepowered.libraries.com.google.gson'
+ relocate 'org.apache.logging.log4j', 'org.spongepowered.libraries.org.apache.logging.log4j'
+ relocate 'com.google.thirdparty.publicsuffix', 'org.spongepowered.libraries.com.google.thirdparty.publicsuffix'
+}
+
compileJava {
dependsOn copySrgs
options.compilerArgs += [
@@ -141,14 +166,11 @@ task annotationProcessorJar(type: Jar, dependsOn: classes) {
classifier = 'processor'
from(sourceSets.main.output) {
include 'io/github/tox1cozz/mixinextras/**'
-
- def processor = 'META-INF/services/javax.annotation.processing.Processor'
- include processor
- filesMatching(processor) { file ->
- file.filter {
- it == 'io.github.tox1cozz.mixinextras.MixinExtrasAnnotationProcessor' ? it : null
- }
- }
+ include 'META-INF/services/javax.annotation.processing.Processor'
+ }
+ from(zipTree(layout.projectDirectory.file("dependencies/mixin-$mixinVersion-processor-repack.jar"))) {
+ exclude 'LICENSE.txt'
+ exclude 'META-INF/services/*.Processor'
}
}
diff --git a/dependencies/mixin-0.8.2-processor-repack.jar b/dependencies/mixin-0.8.2-processor-repack.jar
new file mode 100644
index 0000000..1e0ec49
Binary files /dev/null and b/dependencies/mixin-0.8.2-processor-repack.jar differ
diff --git a/dependencies/mixin-0.8.2-repack.jar b/dependencies/mixin-0.8.2-repack.jar
index 5775764..6a296c0 100644
Binary files a/dependencies/mixin-0.8.2-repack.jar and b/dependencies/mixin-0.8.2-repack.jar differ
diff --git a/gradle/configurations/v1.gradle b/gradle/configurations/v1.gradle
index a6b0c99..4efd31c 100644
--- a/gradle/configurations/v1.gradle
+++ b/gradle/configurations/v1.gradle
@@ -56,9 +56,8 @@ repositories {
}
dependencies {
- implementation 'com.github.tox1cozZ:mixin-booter-legacy:1.0.3'
- annotationProcessor 'org.spongepowered:mixin:0.8.2:processor'
- annotationProcessor 'com.github.tox1cozZ:mixin-booter-legacy:1.0.3:processor'
+ implementation 'com.github.tox1cozZ:mixin-booter-legacy:1.1.0'
+ annotationProcessor 'com.github.tox1cozZ:mixin-booter-legacy:1.1.0:processor'
}
tasks.register('mixin', MixinTask)
diff --git a/src/main/java/io/github/tox1cozz/mixinbooterlegacy/MixinBooterLegacyPlugin.java b/src/main/java/io/github/tox1cozz/mixinbooterlegacy/MixinBooterLegacyPlugin.java
index bac480e..0fcb597 100644
--- a/src/main/java/io/github/tox1cozz/mixinbooterlegacy/MixinBooterLegacyPlugin.java
+++ b/src/main/java/io/github/tox1cozz/mixinbooterlegacy/MixinBooterLegacyPlugin.java
@@ -88,7 +88,7 @@ public Container() {
ModMetadata meta = getMetadata();
meta.modId = "mixinbooterlegacy";
meta.name = "MixinBooterLegacy";
- meta.version = "1.0.3";
+ meta.version = "1.1.0";
meta.description = "A Mixin library and loader.";
meta.logoFile = "/icon.png";
meta.authorList.addAll(Lists.newArrayList("Rongmario", "tox1cozZ"));
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/LICENSE b/src/main/java/io/github/tox1cozz/mixinextras/LICENSE
index ee9ed41..8000a6f 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/LICENSE
+++ b/src/main/java/io/github/tox1cozz/mixinextras/LICENSE
@@ -501,4 +501,4 @@ necessary. Here is a sample; alter the names:
, 1 April 1990
Ty Coon, President of Vice
-That's all there is to it!
\ No newline at end of file
+That's all there is to it!
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/MixinExtrasAnnotationProcessor.java b/src/main/java/io/github/tox1cozz/mixinextras/MixinExtrasAnnotationProcessor.java
index de79c78..2a2caea 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/MixinExtrasAnnotationProcessor.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/MixinExtrasAnnotationProcessor.java
@@ -10,6 +10,10 @@
import javax.lang.model.element.TypeElement;
import java.util.Set;
+/*
+ TODO: Refmap not working for new annotations
+ Use srg names or create dummy @Inject
+ */
@SupportedAnnotationTypes({})
public class MixinExtrasAnnotationProcessor extends AbstractProcessor {
@@ -21,8 +25,12 @@ public boolean process(Set extends TypeElement> annotations, RoundEnvironment
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
- MessageRouter.setMessager(processingEnv.getMessager());
- MixinExtrasBootstrap.init();
+ try {
+ MessageRouter.setMessager(processingEnv.getMessager());
+ MixinExtrasBootstrap.init();
+ } catch (NoClassDefFoundError e) {
+ // The Mixin AP probably isn't available, e.g. if loom has excluded it from IDEA.
+ }
}
@Override
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/MixinExtrasBootstrap.java b/src/main/java/io/github/tox1cozz/mixinextras/MixinExtrasBootstrap.java
index 36c1421..c31b2e0 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/MixinExtrasBootstrap.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/MixinExtrasBootstrap.java
@@ -8,10 +8,28 @@
public class MixinExtrasBootstrap {
- public static void init() {
- InjectionInfo.register(ModifyExpressionValueInjectionInfo.class);
- InjectionInfo.register(ModifyReceiverInjectionInfo.class);
- InjectionInfo.register(ModifyReturnValueInjectionInfo.class);
- InjectionInfo.register(WrapWithConditionInjectionInfo.class);
+ private static boolean initialized = false;
+
+ /**
+ * @deprecated As of 0.0.8, as the field becomes kind of pointless when it gets inlined at compile-time.
+ * Use {@link #getVersion()} instead.
+ */
+ @Deprecated
+ @SuppressWarnings("DeprecatedIsStillUsed")
+ public static final String VERSION = "0.0.12";
+
+ public static synchronized void init() {
+ if (!initialized) {
+ initialized = true;
+
+ InjectionInfo.register(ModifyExpressionValueInjectionInfo.class);
+ InjectionInfo.register(ModifyReceiverInjectionInfo.class);
+ InjectionInfo.register(ModifyReturnValueInjectionInfo.class);
+ InjectionInfo.register(WrapWithConditionInjectionInfo.class);
+ }
+ }
+
+ public static String getVersion() {
+ return VERSION;
}
}
\ No newline at end of file
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/README.md b/src/main/java/io/github/tox1cozz/mixinextras/README.md
deleted file mode 100644
index c17e927..0000000
--- a/src/main/java/io/github/tox1cozz/mixinextras/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-This package contains files shaded in from: https://github.com/LlamaLad7/MixinExtras
-
-Thanks to LlamaLad7 for expanding upon Mixins by providing additional ways via annotations to better inject code in a non-conflicting manner.
-
-Parts of the shaded code have been edited to remove anything unnecessary.
\ No newline at end of file
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyExpressionValueInjectionInfo.java b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyExpressionValueInjectionInfo.java
index 4ea6d1a..dae0019 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyExpressionValueInjectionInfo.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyExpressionValueInjectionInfo.java
@@ -1,12 +1,12 @@
package io.github.tox1cozz.mixinextras.injector;
-import org.spongepowered.libraries.org.objectweb.asm.tree.AnnotationNode;
-import org.spongepowered.libraries.org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.code.Injector;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.HandlerPrefix;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
+import org.spongepowered.libraries.org.objectweb.asm.tree.AnnotationNode;
+import org.spongepowered.libraries.org.objectweb.asm.tree.MethodNode;
@AnnotationType(ModifyExpressionValue.class)
@HandlerPrefix("modifyExpressionValue")
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyExpressionValueInjector.java b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyExpressionValueInjector.java
index 25436b8..b64b2c7 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyExpressionValueInjector.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyExpressionValueInjector.java
@@ -1,5 +1,6 @@
package io.github.tox1cozz.mixinextras.injector;
+import io.github.tox1cozz.mixinextras.utils.CompatibilityHelper;
import org.spongepowered.libraries.org.objectweb.asm.Opcodes;
import org.spongepowered.libraries.org.objectweb.asm.Type;
import org.spongepowered.libraries.org.objectweb.asm.tree.*;
@@ -7,7 +8,6 @@
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.struct.Target;
-import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
import org.spongepowered.asm.util.Bytecode;
public class ModifyExpressionValueInjector extends Injector {
@@ -33,11 +33,11 @@ protected void inject(Target target, InjectionNode node) {
private void checkTargetReturnsAValue(Target target, InjectionNode node) {
Type returnType = getReturnType(node.getCurrentTarget());
if (returnType == Type.VOID_TYPE) {
- throw new InvalidInjectionException(info, String.format("%s annotation is targeting an instruction with a return type of 'void' in %s in %s", annotationType, target, this));
+ throw CompatibilityHelper.makeInvalidInjectionException(info, String.format("%s annotation is targeting an instruction with a return type of 'void' in %s in %s", annotationType, target, this));
}
if (returnType == null) {
- throw new InvalidInjectionException(info, String.format("%s annotation is targeting an invalid insn in %s in %s", annotationType, target, this));
+ throw CompatibilityHelper.makeInvalidInjectionException(info, String.format("%s annotation is targeting an invalid insn in %s in %s", annotationType, target, this));
}
}
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReceiverInjectionInfo.java b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReceiverInjectionInfo.java
index 48839e1..589b99e 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReceiverInjectionInfo.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReceiverInjectionInfo.java
@@ -1,10 +1,10 @@
package io.github.tox1cozz.mixinextras.injector;
+import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
import org.spongepowered.libraries.org.objectweb.asm.tree.AnnotationNode;
import org.spongepowered.libraries.org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.code.Injector;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
-import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.HandlerPrefix;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReceiverInjector.java b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReceiverInjector.java
index 2223aa3..4dd64f8 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReceiverInjector.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReceiverInjector.java
@@ -1,5 +1,7 @@
package io.github.tox1cozz.mixinextras.injector;
+import io.github.tox1cozz.mixinextras.utils.CompatibilityHelper;
+import io.github.tox1cozz.mixinextras.utils.InjectorUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.spongepowered.libraries.org.objectweb.asm.Opcodes;
import org.spongepowered.libraries.org.objectweb.asm.Type;
@@ -8,7 +10,6 @@
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.struct.Target;
-import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
public class ModifyReceiverInjector extends Injector {
@@ -33,7 +34,7 @@ private void checkTargetIsValid(Target target, InjectionNode node) {
case Opcodes.PUTFIELD:
return;
default:
- throw new InvalidInjectionException(info, String.format("%s annotation is targeting an invalid insn in %s in %s", annotationType, target, this));
+ throw CompatibilityHelper.makeInvalidInjectionException(info, String.format("%s annotation is targeting an invalid insn in %s in %s", annotationType, target, this));
}
}
@@ -42,7 +43,7 @@ private void modifyReceiverOfTarget(Target target, InjectionNode node) {
Type[] originalArgTypes = getEffectiveArgTypes(node.getOriginalTarget());
Type[] currentArgTypes = getEffectiveArgTypes(currentTarget);
InsnList insns = new InsnList();
- boolean isVirtualRedirect = node.hasDecoration("redirector") && currentTarget.getOpcode() != Opcodes.INVOKESTATIC;
+ boolean isVirtualRedirect = InjectorUtils.isVirtualRedirect(node);
injectReceiverModifier(target, originalArgTypes, currentArgTypes, isVirtualRedirect, insns);
target.insertBefore(node, insns);
}
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReturnValueInjectionInfo.java b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReturnValueInjectionInfo.java
index be0b54d..d123370 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReturnValueInjectionInfo.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReturnValueInjectionInfo.java
@@ -1,10 +1,10 @@
package io.github.tox1cozz.mixinextras.injector;
+import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
import org.spongepowered.libraries.org.objectweb.asm.tree.AnnotationNode;
import org.spongepowered.libraries.org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.code.Injector;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
-import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.HandlerPrefix;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReturnValueInjector.java b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReturnValueInjector.java
index 0a7fe83..c90a151 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReturnValueInjector.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/injector/ModifyReturnValueInjector.java
@@ -1,5 +1,6 @@
package io.github.tox1cozz.mixinextras.injector;
+import io.github.tox1cozz.mixinextras.utils.CompatibilityHelper;
import org.spongepowered.libraries.org.objectweb.asm.Opcodes;
import org.spongepowered.libraries.org.objectweb.asm.tree.InsnList;
import org.spongepowered.libraries.org.objectweb.asm.tree.InsnNode;
@@ -8,7 +9,6 @@
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.struct.Target;
-import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
public class ModifyReturnValueInjector extends Injector {
@@ -20,7 +20,7 @@ public ModifyReturnValueInjector(InjectionInfo info) {
protected void inject(Target target, InjectionNode node) {
int opcode = node.getCurrentTarget().getOpcode();
if (opcode < Opcodes.IRETURN || opcode >= Opcodes.RETURN) {
- throw new InvalidInjectionException(info, String.format("%s annotation is targeting an invalid insn in %s in %s", annotationType, target, this));
+ throw CompatibilityHelper.makeInvalidInjectionException(info, String.format("%s annotation is targeting an invalid insn in %s in %s", annotationType, target, this));
}
checkTargetModifiers(target, false);
injectReturnValueModifier(target, node);
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/injector/WrapWithConditionInjectionInfo.java b/src/main/java/io/github/tox1cozz/mixinextras/injector/WrapWithConditionInjectionInfo.java
index c90f6e5..d4238eb 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/injector/WrapWithConditionInjectionInfo.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/injector/WrapWithConditionInjectionInfo.java
@@ -1,5 +1,6 @@
package io.github.tox1cozz.mixinextras.injector;
+import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
import org.spongepowered.libraries.org.objectweb.asm.Opcodes;
import org.spongepowered.libraries.org.objectweb.asm.Type;
import org.spongepowered.libraries.org.objectweb.asm.tree.AbstractInsnNode;
@@ -8,7 +9,6 @@
import org.spongepowered.libraries.org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.code.Injector;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
-import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.AnnotationType;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo.HandlerPrefix;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/injector/WrapWithConditionInjector.java b/src/main/java/io/github/tox1cozz/mixinextras/injector/WrapWithConditionInjector.java
index 143b0a1..e181b91 100644
--- a/src/main/java/io/github/tox1cozz/mixinextras/injector/WrapWithConditionInjector.java
+++ b/src/main/java/io/github/tox1cozz/mixinextras/injector/WrapWithConditionInjector.java
@@ -1,5 +1,7 @@
package io.github.tox1cozz.mixinextras.injector;
+import io.github.tox1cozz.mixinextras.utils.CompatibilityHelper;
+import io.github.tox1cozz.mixinextras.utils.InjectorUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.spongepowered.libraries.org.objectweb.asm.Opcodes;
import org.spongepowered.libraries.org.objectweb.asm.Type;
@@ -8,7 +10,6 @@
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.injection.struct.Target;
-import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
public class WrapWithConditionInjector extends Injector {
@@ -31,16 +32,11 @@ private void checkTargetIsLogicallyVoid(Target target, InjectionNode node) {
Type returnType = getReturnType(node.getCurrentTarget());
if (returnType == null) {
- throw new InvalidInjectionException(info, String.format("%s annotation is targeting an invalid insn in %s in %s",
- annotationType, target, this));
+ throw CompatibilityHelper.makeInvalidInjectionException(info, String.format("%s annotation is targeting an invalid insn in %s in %s", annotationType, target, this));
}
if (returnType != Type.VOID_TYPE) {
- throw new InvalidInjectionException(info,
- String.format(
- "%s annotation is targeting an instruction with a non-void return type in %s in %s",
- annotationType, target, this
- ));
+ throw CompatibilityHelper.makeInvalidInjectionException(info, String.format("%s annotation is targeting an instruction with a non-void return type in %s in %s", annotationType, target, this));
}
}
@@ -51,7 +47,7 @@ private void wrapTargetWithCondition(Target target, InjectionNode node) {
Type[] currentArgTypes = getEffectiveArgTypes(currentTarget);
InsnList before = new InsnList();
InsnList after = new InsnList();
- boolean isVirtualRedirect = node.hasDecoration("redirector") && currentTarget.getOpcode() != Opcodes.INVOKESTATIC;
+ boolean isVirtualRedirect = InjectorUtils.isVirtualRedirect(node);
invokeHandler(target, returnType, originalArgTypes, currentArgTypes, isVirtualRedirect, before, after);
target.wrapNode(currentTarget, currentTarget, before, after);
}
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/utils/CompatibilityHelper.java b/src/main/java/io/github/tox1cozz/mixinextras/utils/CompatibilityHelper.java
new file mode 100644
index 0000000..fc17984
--- /dev/null
+++ b/src/main/java/io/github/tox1cozz/mixinextras/utils/CompatibilityHelper.java
@@ -0,0 +1,34 @@
+package io.github.tox1cozz.mixinextras.utils;
+
+import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
+import org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException;
+
+import java.lang.reflect.Constructor;
+import java.util.Arrays;
+
+/**
+ * Helpers for writing code that is compatible with all variants of Mixin 0.8+
+ */
+public class CompatibilityHelper {
+
+ private static final Constructor INVALID_INJECTION_EXCEPTION_CONSTRUCTOR;
+
+ static {
+ // noinspection unchecked
+ INVALID_INJECTION_EXCEPTION_CONSTRUCTOR = (Constructor)Arrays.stream(InvalidInjectionException.class.getConstructors())
+ .filter(it -> {
+ Class>[] parameters = it.getParameterTypes();
+ return parameters.length == 2 && parameters[0].isAssignableFrom(InjectionInfo.class) && parameters[1] == String.class;
+ })
+ .findAny()
+ .orElse(null);
+ }
+
+ public static RuntimeException makeInvalidInjectionException(InjectionInfo info, String message) {
+ try {
+ return INVALID_INJECTION_EXCEPTION_CONSTRUCTOR.newInstance(info, message);
+ } catch (Throwable e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/tox1cozz/mixinextras/utils/InjectorUtils.java b/src/main/java/io/github/tox1cozz/mixinextras/utils/InjectorUtils.java
new file mode 100644
index 0000000..d4cc18b
--- /dev/null
+++ b/src/main/java/io/github/tox1cozz/mixinextras/utils/InjectorUtils.java
@@ -0,0 +1,11 @@
+package io.github.tox1cozz.mixinextras.utils;
+
+import org.spongepowered.libraries.org.objectweb.asm.Opcodes;
+import org.spongepowered.asm.mixin.injection.struct.InjectionNodes;
+
+public class InjectorUtils {
+
+ public static boolean isVirtualRedirect(InjectionNodes.InjectionNode node) {
+ return node.isReplaced() && node.hasDecoration("redirector") && node.getCurrentTarget().getOpcode() != Opcodes.INVOKESTATIC;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/spongepowered/asm/bridge/RemapperAdapter.java b/src/main/java/org/spongepowered/asm/bridge/RemapperAdapter.java
index f295aac..825b7a3 100644
--- a/src/main/java/org/spongepowered/asm/bridge/RemapperAdapter.java
+++ b/src/main/java/org/spongepowered/asm/bridge/RemapperAdapter.java
@@ -2,7 +2,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.objectweb.asm.commons.Remapper;
+import org.spongepowered.libraries.org.objectweb.asm.commons.Remapper;
import org.spongepowered.asm.mixin.extensibility.IRemapper;
import org.spongepowered.asm.util.ObfuscationUtil;
diff --git a/src/main/java/org/spongepowered/asm/bridge/RemapperAdapterFML.java b/src/main/java/org/spongepowered/asm/bridge/RemapperAdapterFML.java
index a2609cd..364b630 100644
--- a/src/main/java/org/spongepowered/asm/bridge/RemapperAdapterFML.java
+++ b/src/main/java/org/spongepowered/asm/bridge/RemapperAdapterFML.java
@@ -3,7 +3,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import org.objectweb.asm.commons.Remapper;
+import org.spongepowered.libraries.org.objectweb.asm.commons.Remapper;
import org.spongepowered.asm.mixin.extensibility.IRemapper;
public final class RemapperAdapterFML extends RemapperAdapter {