Skip to content

Commit

Permalink
Mixin cancelling is based
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Sep 29, 2023
1 parent 701499f commit 8b940de
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
- Updated to support 1.20.2.
- Fixed compatibility with Equipment Compare. (#89)
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}"))
}

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand All @@ -35,4 +39,14 @@ public void onInitializeClient() {
StarFoxUtil.clientTick(client);
});
}

@Override
public boolean shouldCancel(List<String> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
3 changes: 3 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
],
"controlify": [
"nl.enjarai.doabarrelroll.compat.controlify.ControlifyCompat"
],
"mixinsquared": [
"nl.enjarai.doabarrelroll.fabric.DoABarrelRollFabricClient"
]
},

Expand Down

0 comments on commit 8b940de

Please sign in to comment.