SpongePowered / Mixin

Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
MIT License
1.37k stars 185 forks source link

[Question] Modifying existing Bytecode via Mixin #635

Closed BlazingTwist closed 1 year ago

BlazingTwist commented 1 year ago

I'm aware of Overwriting Methods but that is too destructive in my opinion.

I was hoping it would be possible to do something like Harmony's Transpilers

My Usecase: I have a Method that I want to modify with Mixin:

public void targetMethod() {
    /* A bunch of lines I DON'T want to execute, sometimes */

    /* A bunch of lines I DO want to execute, always */
}

Ideally I could modify the method to look like this:

public void targetMethod() {
    if (MyMixin.shouldExecuteFirstBlock()) {
        /* A bunch of lines I DON'T want to execute, sometimes */
    }

    /* A bunch of lines I DO want to execute, always */
}
LlamaLad7 commented 1 year ago

Your use case is probably possible but you always need to show the actual situation. Pseudocode is entirely unhelpful when talking about mixins. However, this is an issue tracker; post your question with full details in the discord.

BlazingTwist commented 1 year ago

I disagree, my request is basically "give my the bytecode of that method and let me edit it directly". Which should not depend on the specific content of the method. The usecase exists solely to illustrate why I would want to do that.

LlamaLad7 commented 1 year ago

Modifying bytecode directly is a terrible idea for compatibility and that is why mixin exists in the first place. In any actual situation you will be able to do what you want with mixin's existing tools. If you have an actual scenario then show it, if not then we can't help. Regardless, this is still not a support forum and further discussion should go to the discord.