MinecraftDev icon indicating copy to clipboard operation
MinecraftDev copied to clipboard

Attempt to view opengl constants as their names where possible

Open Niko-sk2x opened this issue 8 years ago • 7 comments

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.

Niko-sk2x avatar Oct 25 '17 14:10 Niko-sk2x

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.

marvin-roesch avatar Oct 25 '17 16:10 marvin-roesch

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

kashike avatar Oct 26 '17 08:10 kashike

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

Niko-sk2x avatar Oct 26 '17 09:10 Niko-sk2x

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

thiakil avatar Nov 21 '17 02:11 thiakil

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?

DenWav avatar Dec 23 '17 07:12 DenWav

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

thiakil avatar Dec 23 '17 09:12 thiakil

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

ramidzkh avatar Sep 11 '20 11:09 ramidzkh