minecraft-dev / MinecraftDev

Plugin for IntelliJ IDEA that gives special support for Minecraft modding projects.
https://minecraftdev.org/
GNU Lesser General Public License v3.0
1.5k stars 185 forks source link

Attempt to view opengl constants as their names where possible #316

Open Barteks2x opened 6 years ago

Barteks2x commented 6 years ago

Because of obfuscation, Minecraft's opengl code is full of things like this: GlStateManager.glTexParameteri(3553, 10243, 10497);. Would it be possible for MinecraftDev to either automatically replace them with actual GL constants like GL_TEXTURE_2D, or have a right click option to show method arguments as GL constants? This would probably involve creating a big list of which methods take arguments of which type of gl constants, but I think it should be possible.

marvin-roesch commented 6 years ago

This would be possible to achieve with some heuristics and probably folding (I don't think you can replace the elements completely). However, I'd say this would be much better suited as an extension to FernFlower (or something further up the pipeline, at a bytecode level). Don't take my word on it, but I think there actually already are some heuristics somewhere in the pipeline to resolve some constants.

kashike commented 6 years ago

May be of interest: https://github.com/MinecraftForge/ForgeGradle/blob/FG_2.3/src/main/java/net/minecraftforge/gradle/util/mcp/GLConstantFixer.java

Barteks2x commented 6 years ago

Except fixing it in forge gradle may break some forge patches. It would be possible to add some of the Minecraft classes to the fg list but that would probably have to be done together with forge patches update

thiakil commented 6 years ago

Except fixing it in forge gradle may break some forge patches.

Patches are applied before the GL (and other) fixes are applied. See https://github.com/MinecraftForge/ForgeGradle/blob/FG_2.3/src/main/java/net/minecraftforge/gradle/tasks/PostDecompileTask.java#L122

It should be fixed on ForgeGradle's side imo

Though an inspection could probably be added for modder code

DenWav commented 6 years ago

This seems like it would be easy enough to add with folding, considering the GLConstantFixer reference.

But I'm curious - if that's in ForgeGradle already, is this valid anymore? Or even if FG does do it, would this still be useful?

thiakil commented 6 years ago

As far as I can see it does it for raw GL calls, but not GLStateManager

ramidzkh commented 4 years ago

I wrote a simple proof of concept to show that this is feasible, but it's probably inefficient and it doesn't check if the int literals are actually GL related. https://github.com/minecraft-dev/MinecraftDev/compare/dev...ramidzkh:magic-constants