Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capturing locals out of current scope #78

Open
THEREALWWEFAN231 opened this issue Jan 2, 2022 · 4 comments
Open

Capturing locals out of current scope #78

THEREALWWEFAN231 opened this issue Jan 2, 2022 · 4 comments

Comments

@THEREALWWEFAN231
Copy link

I'm not sure if this is the correct place to post this report, I think so. The issue started in fabric loader 0.12 and above. For reference the example is with minecraft 1.17.1.

Issue: mixin is trying/requiring locals out of the current scope and this causes a verification error.

I'm trying to inject right before the second swingHand
image
@Inject(method={"doItemUse"}, at={@At(value="INVOKE", target="net/minecraft/client/network/ClientPlayerEntity.swingHand(Lnet/minecraft/util/Hand;)V", ordinal = 1)}, locals=LocalCapture.CAPTURE_FAILHARD)

This does, only inject right before the second swingHand.

When I tell mixin to print the locals, it gives this
private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, Entity entity, ActionResult actionResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) {

  1. It's suggesting Entity entity, ActionResult actionResult which is out of the current scope

  2. When I use it's suggestion of the locals it crashes with an error
    image

  3. When I use the correct locals private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) {, it crashes, saying it expects what I said in #1

This is the mixin

@Inject(method={"doItemUse"}, at={@At(value="INVOKE", target="net/minecraft/client/network/ClientPlayerEntity.swingHand(Lnet/minecraft/util/Hand;)V", ordinal = 1)}, locals=LocalCapture.CAPTURE_FAILHARD)
    private void onBlockUse(CallbackInfo callbackInfo, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, Entity entity, ActionResult actionResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) {
        //private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, Entity entity, ActionResult actionResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) {
        System.out.println("epic");
    }
@sfPlayer1
Copy link

Does your mod declare a dependency on Fabric Loader 0.12+? Does the behavior change if that changes?

@THEREALWWEFAN231
Copy link
Author

It happens on the newest version
modImplementation "net.fabricmc:fabric-loader:0.12.12"

I investigated the issue a little more and it's really wack, using minecraft 1.14.4, wit fabric loader 0.12.0, the issue persists, but using fabric loader 0.11.7, it works as intended, capturing the correct locals.

Then when I test with minecraft 1.16/1.17. The issue persists on what seems to be all fabric loader versions... 😕

Basically, to my knowledge if you want to test/replicate the issue, you should be able to use an example mod for 1.17, create a mixin for MinecraftClient. Add this method

@Inject(method = { "doItemUse" }, at = { @At(value = "INVOKE", target = "net/minecraft/client/network/ClientPlayerEntity.swingHand(Lnet/minecraft/util/Hand;)V", ordinal = 1) }, locals = LocalCapture.PRINT)
private void onBlockUse(CallbackInfo callbackInfo) {
}

Run the game, it will print

/**                                                                                                                                                                                                                                                      */
/*  * Expected callback signature                                                                                                                                                                                                                           */
/*  * /                                                                                                                                                                                                                                                     */
/* private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, Entity entity, ActionResult actionResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) { */
/*     // Method body                                                                                                                                                                                                                                       */
/* }

Which is incorrect?(Am I wrong?) It should be

/**                                                                                                                                                                                                                                                      */
/*  * Expected callback signature                                                                                                                                                                                                                           */
/*  * /                                                                                                                                                                                                                                                     */
/* private void onBlockUse(CallbackInfo ci, Hand var1[], int var2, int var3, Hand hand, ItemStack itemStack, EntityHitResult entityHitResult, BlockHitResult blockHitResult, int i, ActionResult actionResult2) { */
/*     // Method body                                                                                                                                                                                                                                       */
/* }

(Entity, and the first ActionResult are not in the current scope?)

Regardless of what it should/shouldn't be, if you change the mixin to CAPTURE_FAILHARD and use it's expected parameters the game crashes.
image

@sfPlayer1
Copy link

I need to know what dependencies your fabric.mod.json declares on Loader, it controls the mixin locals algorithm being used. If you depend on a loader version >= 0.12, it'll use the same as current upstream, if you don't have a dependency on Loader or one starting below 0.12 it uses the old algorithm for compatibility.

@THEREALWWEFAN231
Copy link
Author

I tried "fabricloader": ">=0.12.12" it still crashes, I created a repo https://github.com/THEREALWWEFAN231/fabric-example-mod based off the 1.18 example mod, everything is up to date(to my knowledge). Maybe it can give you more insight on the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants