Skip to content

Commit

Permalink
Merge pull request #66 from LlamaLad7/version/0.3.4
Browse files Browse the repository at this point in the history
Version/0.3.4
  • Loading branch information
LlamaLad7 authored Jan 17, 2024
2 parents 2d60dae + f94f152 commit 74e31b5
Show file tree
Hide file tree
Showing 13 changed files with 210 additions and 120 deletions.
16 changes: 8 additions & 8 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ want to use a different version than is provided, see below:

```gradle
dependencies {
implementation(jarJar("io.github.llamalad7:mixinextras-neoforge:0.3.3")) {
jarJar.ranged(it, "[0.3.3,)")
implementation(jarJar("io.github.llamalad7:mixinextras-neoforge:0.3.4")) {
jarJar.ranged(it, "[0.3.4,)")
}
}
```
Expand All @@ -40,9 +40,9 @@ dependencies {

```gradle
dependencies {
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.3"))
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.3.3")) {
jarJar.ranged(it, "[0.3.3,)")
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.4"))
implementation(jarJar("io.github.llamalad7:mixinextras-forge:0.3.4")) {
jarJar.ranged(it, "[0.3.4,)")
}
}
```
Expand All @@ -52,8 +52,8 @@ dependencies {

```gradle
dependencies {
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.3"))
implementation(include("io.github.llamalad7:mixinextras-forge:0.3.3"))
compileOnly(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.4"))
implementation(include("io.github.llamalad7:mixinextras-forge:0.3.4"))
}
```

Expand All @@ -72,7 +72,7 @@ configurations {
}
dependencies {
shadow(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.3"))
shadow(annotationProcessor("io.github.llamalad7:mixinextras-common:0.3.4"))
}
shadowJar {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ allprojects {
apply(plugin = "java")

group = "com.llamalad7"
version = "0.3.3"
version = "0.3.4"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import com.llamalad7.mixinextras.injector.ModifyExpressionValueInjectionInfo;
import com.llamalad7.mixinextras.injector.ModifyReceiverInjectionInfo;
import com.llamalad7.mixinextras.injector.ModifyReturnValueInjectionInfo;
import com.llamalad7.mixinextras.injector.WrapWithConditionInjectionInfo;
import com.llamalad7.mixinextras.injector.WrapWithConditionV1InjectionInfo;
import com.llamalad7.mixinextras.injector.v2.WrapWithConditionInjectionInfo;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperationInjectionInfo;
import org.spongepowered.asm.mixin.injection.struct.InjectionInfo;
import org.spongepowered.asm.util.logging.MessageRouter;
Expand Down Expand Up @@ -39,6 +40,7 @@ private static void registerInjectors() {
InjectionInfo.register(ModifyReceiverInjectionInfo.class);
InjectionInfo.register(ModifyReturnValueInjectionInfo.class);
InjectionInfo.register(WrapOperationInjectionInfo.class);
InjectionInfo.register(WrapWithConditionV1InjectionInfo.class);
InjectionInfo.register(WrapWithConditionInjectionInfo.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.injection.struct.InjectionNodes.InjectionNode;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;

import java.util.List;

public abstract class MixinExtrasLateInjectionInfo extends MixinExtrasInjectionInfo implements LateApplyingInjectorInfo {
private LateApplyingInjectorInfo injectionInfoToQueue = this;
private boolean hasInjectStarted = false;

public MixinExtrasLateInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
super(mixin, method, annotation);
Expand All @@ -17,13 +21,32 @@ public MixinExtrasLateInjectionInfo(MixinTargetContext mixin, MethodNode method,

@Override
public void inject() {
hasInjectStarted = true;
int callbackTotal = 0;
for (List<InjectionNode> nodes : targetNodes.values()) {
callbackTotal += nodes.size();
}
for (int i = 0; i < callbackTotal; i++) {
// Have to add these early since we inject after group validation.
// May as well add them now, the only way they can fail later is by throwing an exception at which point
// it's game over anyway.
super.addCallbackInvocation(method);
}
LateInjectionApplicatorExtension.offerInjection(this.mixin.getTarget(), injectionInfoToQueue);
}

@Override
public void postInject() {
}

@Override
public void addCallbackInvocation(MethodNode handler) {
if (!hasInjectStarted) {
// We want to allow any additional ones that get added during `prepare` by sugar.
super.addCallbackInvocation(handler);
}
}

@Override
public void lateInject() {
super.inject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,14 @@
import java.lang.annotation.Target;

/**
* Allows you to wrap a
* {@link org.spongepowered.asm.mixin.injection.points.BeforeInvoke void method call} or
* {@link org.spongepowered.asm.mixin.injection.points.BeforeFieldAccess field write}
* with a conditional check.
* <p>
* Your handler method receives the targeted instruction's arguments (optionally followed by the enclosing method's
* parameters), and should return a boolean indicating whether the operation should go ahead:
* <table width="100%">
* <tr>
* <th width="25%">Targeted operation</th>
* <th>Handler signature</th>
* </tr>
* <tr>
* <td>Non-static method call</td>
* <td><code>private (static) boolean handler(<b>ReceiverType</b> instance, <b>&lt;params of the original
* call&gt;</b>)</code></td>
* </tr>
* <tr>
* <td>Static method call</td>
* <td><code>private (static) boolean handler(<b>&lt;params of the original call&gt;</b>)</code></td>
* </tr>
* <tr>
* <td>Non-static field write</td>
* <td><code>private (static) boolean handler(<b>ReceiverType</b> instance, <b>FieldType</b> newValue)
* </tr>
* <tr>
* <td>Static field write</td>
* <td><code>private (static) boolean handler(<b>FieldType</b> newValue)</code></td>
* </tr>
* </table>
* This chains when used by multiple people, unlike
* {@link org.spongepowered.asm.mixin.injection.Redirect @Redirect}.
* <p>
* <b>If you always return false then you risk other people's code being silently ignored.</b>
* <p>
* See <a href="https://github.com/LlamaLad7/MixinExtras/wiki/WrapWithCondition">the wiki article</a> for more info.
* Use {@link com.llamalad7.mixinextras.injector.v2.WrapWithCondition} instead.
* This injector occasionally wraps {@code @Inject} handlers if it applies before them.
* The new version applies at a later stage, however in the unlikely case that you rely on the old ordering, make sure
* to test your mixin after converting.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Deprecated
public @interface WrapWithCondition {
String[] method();

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.llamalad7.mixinextras.injector;

import com.llamalad7.mixinextras.utils.InjectorUtils;
import org.objectweb.asm.tree.AnnotationNode;
import 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.HandlerPrefix;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;

@InjectionInfo.AnnotationType(WrapWithCondition.class)
@HandlerPrefix("wrapWithCondition")
public class WrapWithConditionV1InjectionInfo extends MixinExtrasInjectionInfo {
public WrapWithConditionV1InjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
super(mixin, method, annotation);
}

@Override
protected Injector parseInjector(AnnotationNode injectAnnotation) {
return new WrapWithConditionInjector(this);
}

@Override
public void prepare() {
super.prepare();
InjectorUtils.checkForImmediatePops(targetNodes);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.llamalad7.mixinextras.injector.v2;

import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Slice;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Allows you to wrap a
* {@link org.spongepowered.asm.mixin.injection.points.BeforeInvoke void method call} or
* {@link org.spongepowered.asm.mixin.injection.points.BeforeFieldAccess field write}
* with a conditional check.
* <p>
* Your handler method receives the targeted instruction's arguments (optionally followed by the enclosing method's
* parameters), and should return a boolean indicating whether the operation should go ahead:
* <table width="100%">
* <tr>
* <th width="25%">Targeted operation</th>
* <th>Handler signature</th>
* </tr>
* <tr>
* <td>Non-static method call</td>
* <td><code>private (static) boolean handler(<b>ReceiverType</b> instance, <b>&lt;params of the original
* call&gt;</b>)</code></td>
* </tr>
* <tr>
* <td>Static method call</td>
* <td><code>private (static) boolean handler(<b>&lt;params of the original call&gt;</b>)</code></td>
* </tr>
* <tr>
* <td>Non-static field write</td>
* <td><code>private (static) boolean handler(<b>ReceiverType</b> instance, <b>FieldType</b> newValue)
* </tr>
* <tr>
* <td>Static field write</td>
* <td><code>private (static) boolean handler(<b>FieldType</b> newValue)</code></td>
* </tr>
* </table>
* This chains when used by multiple people, unlike
* {@link org.spongepowered.asm.mixin.injection.Redirect @Redirect}.
* <p>
* <b>If you always return false then you risk other people's code being silently ignored.</b>
* <p>
* See <a href="https://github.com/LlamaLad7/MixinExtras/wiki/WrapWithCondition">the wiki article</a> for more info.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface WrapWithCondition {
String[] method();

At[] at();

Slice[] slice() default {};

boolean remap() default true;

int require() default -1;

int expect() default 1;

int allow() default -1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.llamalad7.mixinextras.injector.v2;

import com.llamalad7.mixinextras.injector.MixinExtrasLateInjectionInfo;
import com.llamalad7.mixinextras.injector.WrapWithConditionInjector;
import com.llamalad7.mixinextras.utils.InjectorUtils;
import org.objectweb.asm.tree.AnnotationNode;
import 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.HandlerPrefix;
import org.spongepowered.asm.mixin.transformer.MixinTargetContext;

@InjectionInfo.AnnotationType(WrapWithCondition.class)
@HandlerPrefix("wrapWithCondition")
public class WrapWithConditionInjectionInfo extends MixinExtrasLateInjectionInfo {
public WrapWithConditionInjectionInfo(MixinTargetContext mixin, MethodNode method, AnnotationNode annotation) {
super(mixin, method, annotation);
}

@Override
protected Injector parseInjector(AnnotationNode injectAnnotation) {
return new WrapWithConditionInjector(this);
}

@Override
public void prepare() {
super.prepare();
InjectorUtils.checkForImmediatePops(targetNodes);
}

@Override
public String getLateInjectionType() {
return "WrapWithCondition";
}
}
Loading

0 comments on commit 74e31b5

Please sign in to comment.