Mixin icon indicating copy to clipboard operation
Mixin copied to clipboard

`ModifyArg` `index` is broken by instance `Redirect`s

Open LlamaLad7 opened this issue 2 years ago • 0 comments

Given the following example case:

@Redirect(method = "updateWindowTitle", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;setTitle(Ljava/lang/String;)V"))
private void modifyTitle(Window instance, String title) {
    instance.setTitle(title);
}

@ModifyArg(method = "updateWindowTitle", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/util/Window;setTitle(Ljava/lang/String;)V"), index = 0)
private String modifyTitle(String title) {
    return title;
}

I am greeted with the following error:

Specified index 0 for @ModifyArg is invalid for args (Lnet/minecraft/client/util/Window;Ljava/lang/String;), expected Ljava/lang/String;

Originally the target method has only a single argument of type String, however when the Redirect is injected at the desired instruction, there is now an instance parameter as well. It seems that index does not take into account the instance parameter in the redirector which replaced the original instruction, and as such tries to target the wrong thing. It works fine when they apply the other way round, as there is only one parameter for the ModifyArg to look at at that point.

LlamaLad7 avatar Dec 11 '21 21:12 LlamaLad7