From 8b940de63c22d78609ceea817881f256d3feaf17 Mon Sep 17 00:00:00 2001 From: enjarai Date: Fri, 29 Sep 2023 11:01:57 +0200 Subject: [PATCH] Mixin cancelling is based --- CHANGELOG.md | 2 +- build.gradle | 12 +++-- gradle.properties | 3 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../fabric/DoABarrelRollFabricClient.java | 16 ++++++- .../util/MixinCancelChecker.java | 48 +++++++++++++++++++ src/main/resources/fabric.mod.json | 3 ++ 7 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 src/client/java/nl/enjarai/doabarrelroll/util/MixinCancelChecker.java diff --git a/CHANGELOG.md b/CHANGELOG.md index db7772fc..2e9eba6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1 @@ -- Updated to support 1.20.2. \ No newline at end of file +- Fixed compatibility with Equipment Compare. (#89) \ No newline at end of file diff --git a/build.gradle b/build.gradle index c84b958e..48abf572 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id 'fabric-loom' version '1.3-SNAPSHOT' - id 'io.github.juuxel.loom-vineflower' version '1.11.0' + id 'fabric-loom' version '1.4-SNAPSHOT' +// id 'io.github.juuxel.loom-vineflower' version '1.11.0' id 'maven-publish' id 'me.fallenbreath.yamlang' version '1.2.1' } @@ -29,8 +29,8 @@ repositories { // for more information about repositories. // Personal maven for cicada and backup mirrors of some dependencies. - maven { url = "https://maven.enjarai.nl/mirrors" } - maven { url = "https://maven.enjarai.nl/releases" } + maven { url = "https://maven.enjarai.dev/mirrors" } + maven { url = "https://maven.enjarai.dev/releases" } maven { url = "https://www.cursemaven.com" @@ -104,6 +104,10 @@ dependencies { annotationProcessor("com.github.llamalad7.mixinextras:mixinextras-fabric:${project.mixin_extras_version}") clientAnnotationProcessor("com.github.llamalad7.mixinextras:mixinextras-fabric:${project.mixin_extras_version}") + include(implementation("com.github.bawnorton.mixinsquared:mixinsquared-fabric:${project.mixin_squared_version}")) + annotationProcessor("com.github.bawnorton.mixinsquared:mixinsquared-fabric:${project.mixin_squared_version}") + clientAnnotationProcessor("com.github.bawnorton.mixinsquared:mixinsquared-fabric:${project.mixin_squared_version}") + include(modImplementation("me.lucko:fabric-permissions-api:${project.permissions_api_version}")) } diff --git a/gradle.properties b/gradle.properties index 4c832b17..e57e0aa0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx4096M minecraft_version=1.20 archives_base_name=do-a-barrel-roll -mod_version=3.3.3 +mod_version=3.3.4 maven_group=nl.enjarai yarn_version=1.20+build.1 @@ -19,4 +19,5 @@ yacl_version=3.1.0+1.20 # https://github.com/isXander/Controlify/releases controlify_version=1.3.0-beta.2+1.20 mixin_extras_version=0.2.0-beta.8 +mixin_squared_version=0.1.0 permissions_api_version=0.2-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fae08049..db9a6b82 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/client/java/nl/enjarai/doabarrelroll/fabric/DoABarrelRollFabricClient.java b/src/client/java/nl/enjarai/doabarrelroll/fabric/DoABarrelRollFabricClient.java index a17abed2..f18616d3 100644 --- a/src/client/java/nl/enjarai/doabarrelroll/fabric/DoABarrelRollFabricClient.java +++ b/src/client/java/nl/enjarai/doabarrelroll/fabric/DoABarrelRollFabricClient.java @@ -1,5 +1,6 @@ package nl.enjarai.doabarrelroll.fabric; +import com.bawnorton.mixinsquared.api.MixinCanceller; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; @@ -12,10 +13,13 @@ import nl.enjarai.doabarrelroll.ModKeybindings; import nl.enjarai.doabarrelroll.config.ModConfig; import nl.enjarai.doabarrelroll.fabric.net.HandshakeClientFabric; +import nl.enjarai.doabarrelroll.util.MixinCancelChecker; import nl.enjarai.doabarrelroll.util.StarFoxUtil; import org.slf4j.Logger; -public class DoABarrelRollFabricClient implements ClientModInitializer { +import java.util.List; + +public class DoABarrelRollFabricClient implements ClientModInitializer, MixinCanceller { @Override public void onInitializeClient() { DoABarrelRollClient.init(); @@ -35,4 +39,14 @@ public void onInitializeClient() { StarFoxUtil.clientTick(client); }); } + + @Override + public boolean shouldCancel(List targetClassNames, String mixinClassName) { + if (mixinClassName.equals("com.anthonyhilyard.equipmentcompare.mixin.KeyMappingMixin") && !MixinCancelChecker.hasChangedPriority(mixinClassName, 0)) { + DoABarrelRoll.LOGGER.warn("Equipment Compare detected, disabling their overly invasive keybinding mixin. Report any relevant issues to them."); + DoABarrelRoll.LOGGER.warn("If the author of Equipment Compare is reading this: see #31 on your github. Once you've fixed the issue, you can set the priority of this mixin explicitly to stop it being disabled."); + return true; + } + return false; + } } diff --git a/src/client/java/nl/enjarai/doabarrelroll/util/MixinCancelChecker.java b/src/client/java/nl/enjarai/doabarrelroll/util/MixinCancelChecker.java new file mode 100644 index 00000000..44e2340a --- /dev/null +++ b/src/client/java/nl/enjarai/doabarrelroll/util/MixinCancelChecker.java @@ -0,0 +1,48 @@ +package nl.enjarai.doabarrelroll.util; + +import org.objectweb.asm.AnnotationVisitor; +import org.objectweb.asm.Opcodes; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.service.MixinService; +import org.spongepowered.asm.util.Annotations; + +import java.io.IOException; + +public class MixinCancelChecker { + /** + * Check if a mixin does not have the expected priority. + * If priority is not set on the target mixin, expectedPriority should be 0. + */ + public static boolean hasChangedPriority(String mixinClassName, int expectedPriority) { + try { + var classNode = MixinService.getService().getBytecodeProvider().getClassNode(mixinClassName); + var annotationNode = Annotations.getInvisible(classNode, Mixin.class); + var visitor = new Visitor(); + annotationNode.accept(visitor); + + return visitor.getPriority() != expectedPriority; + } catch (ClassNotFoundException | IOException | NullPointerException e) { + return false; + } + } + + static class Visitor extends AnnotationVisitor { + private int priority; + + protected Visitor() { + super(Opcodes.ASM9); + } + + @Override + public void visit(String name, Object value) { + if (name.equals("priority")) { + this.priority = (int) value; + } + super.visit(name, value); + } + + public int getPriority() { + return priority; + } + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 7377e2ef..4eb15738 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -32,6 +32,9 @@ ], "controlify": [ "nl.enjarai.doabarrelroll.compat.controlify.ControlifyCompat" + ], + "mixinsquared": [ + "nl.enjarai.doabarrelroll.fabric.DoABarrelRollFabricClient" ] },