Skip to content

Commit

Permalink
Updated MixinExtras to latest (0.0.12) version
Browse files Browse the repository at this point in the history
  • Loading branch information
tox1cozZ committed Aug 13, 2022
1 parent 93f70d4 commit 7811589
Show file tree
Hide file tree
Showing 23 changed files with 140 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .idea/runConfigurations/Build.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/runConfigurations/Create_Repack_Mixin_Jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 34 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -46,6 +46,7 @@ minecraft {

configurations {
repackMixin
repackMixinProcessor
sources {
transitive = false
}
Expand Down Expand Up @@ -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 {
Expand All @@ -100,14 +105,34 @@ 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'
relocate 'com.google.common', 'org.spongepowered.libraries.com.google.common'
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 += [
Expand Down Expand Up @@ -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'
}
}

Expand Down
Binary file added dependencies/mixin-0.8.2-processor-repack.jar
Binary file not shown.
Binary file modified dependencies/mixin-0.8.2-repack.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions gradle/configurations/v1.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/github/tox1cozz/mixinextras/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,4 @@ necessary. Here is a sample; alter the names:
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice

That's all there is to it!
That's all there is to it!
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 0 additions & 5 deletions src/main/java/io/github/tox1cozz/mixinextras/README.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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.*;
import org.spongepowered.asm.mixin.injection.code.Injector;
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 {
Expand All @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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));
}
}

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -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));
}
}

Expand All @@ -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);
}
Expand Down
Loading

0 comments on commit 7811589

Please sign in to comment.