Skip to content

Latest commit

 

History

History
37 lines (29 loc) · 795 Bytes

inject-cancellable.md

File metadata and controls

37 lines (29 loc) · 795 Bytes

@Inject, cancellable

<- Return

Injects code into the target method, if ci.cancel() was called, returns after the mixin is done executing.

Parameters: see @Inject

Return type: see @Inject

Injecting on constructors: You can only inject on TAIL or RETURN!

Example mixin:

@Inject(method = "target()V", at = @At(value = "INVOKE", target = "Lnet/example/Dummy;dummy()V"), cancellable = true)
private void mixin(CallbackInfo ci) {
    if (condition) {
        ci.cancel();
    }
}

Method modification:

  public void target() {
      Dummy.getInstance().dummy();
+     {
+         boolean canceled = false;
+         if (condition) {
+             canceled = true;
+         }
+         if (canceled) return;
+     }
  }