Skip to content

Instantly share code, notes, and snippets.

@Marcono1234
Last active August 13, 2024 05:00
Show Gist options
  • Save Marcono1234/670900d90b262d5ac44ae80baa5daf11 to your computer and use it in GitHub Desktop.
Save Marcono1234/670900d90b262d5ac44ae80baa5daf11 to your computer and use it in GitHub Desktop.
Decompiling and deobfuscating Minecraft with MCPConfig (https://github.com/MinecraftForge/MCPConfig)

Disclaimer

I don't have much experience with Gradle and just found a way to get MCPConfig to decompile and deobfuscate Minecraft jar files. The described steps might be extremely inefficient and even wrong.

Any feedback is therefore welcome!

Usage

You can use the project MCPConfig-CSV-mappings afterwards to apply CSV mappings, however in that case you have to adjust the indentation used by fernflower as described in the "Usage with MCPConfig" section before using MCPConfig.

  1. Download the latest MCPConfig version from: https://github.com/MinecraftForge/MCPConfig
  2. Look in the versions folder and choose the version you want, in the following called <version>, for example 1.13.1
  3. Run gradlew <version>:projectClientApplyPatches
    • For a complete (but possibly outdated tree of tasks, see this gist); to list all tasks use gradlew <version>:tasks --all
    • You might have to specify the JDK path, which can be done for example by using the argument -Dorg.gradle.java.home:
      gradlew <task> "-Dorg.gradle.java.home=<path_to_jdk>"
      
    • You likely have to increase the heap space fernflower is allowed to use, otherwise it can fail decompiling classes or methods; see the "Problems" section
    • This task will likely take some time (can be more than 10 minutes)
  4. Once the task finished the directory versions/<version>/projects/client/src/main/java contains the deobfuscated source files

Importing the sources into an IDE

In your IDE choose the option to import a Gradle project and import the directory versions/<version>/projects.

If you are using Eclipse a run / debug configuration will be created automatically, if not, try running the Gradle task eclipse. Afterwards a file called RunClient.launch should have been created in the versions/<version>/projects/client directory and you should be able to select it in the list of run / debug configurations.

Problems

Empty source files / empty methods

Fernflower can fail decompiling classes or methods. In case of classes the source file will just be empty, for methods the comment // $FF: Couldn't be decompiled will be added instead of the method body.

You can do the following things to solve this:

Search for cause (recommended)

  1. Open the log file build/versions/<version>/<version>.client.decomp.log with a text editor.
  2. Search for the class or method which was not decompiled successfully

If the cause was a java.lang.OutOfMemoryError, try increasing the maximum amount of heap memory fernflower is allowed to use:

  1. Open the config file versions/<version>/config.json with a text editor

  2. Add to the array fernflower > jvmargs the respective -Xmx, for example:

    {
        "fernflower": {
            "jvmargs": ["-Xmx2G"]
        }
    }
    

Map decompiled source manually

  1. Decompile Minecraft using a different decompiler
  2. Open the mapping file versions/<version>/joined.tsrg with a text editor
  3. Search for the class names
  4. Open the new decompiled file and copy its content to the empty source file
  5. Rename fields and methods according to the mapping file. You can use the regex ^<obfuscated_name> when searching for the names.
@DontNeedAName
Copy link

DontNeedAName commented Jul 16, 2020

@LaserSlimeHD, it looks like http://export.mcpbot.bspk.rs/ does not have the mappings for 1.16 yet and if I recall correctly MCPConfig on its own only renames classes and gives fields and methods unique (but not understandable) names.

Though maybe https://github.com/FabricMC/yarn is interesting for you. They create their own mappings (different from Forge's and Mojang's) and license them under Creative Commons Zero so everyone can use them. They usually always have mappings for the latest releases and snapshots (though a few names might be missing) and have their own program called "Enigma" ("yarn" uses it, see its README) which allows you to view and export mapped code and modify mappings.

I actually tried replacing the mappings with the mojang mappings converted to tsrg by https://github.com/hube12/DecompilerMC, but I got an error message at the end that was to long to read. I kinda gave up on directly modding clients. I'm trying to use forge now.

@DontNeedAName
Copy link

@LaserSlimeHD, it looks like http://export.mcpbot.bspk.rs/ does not have the mappings for 1.16 yet and if I recall correctly MCPConfig on its own only renames classes and gives fields and methods unique (but not understandable) names.
Though maybe https://github.com/FabricMC/yarn is interesting for you. They create their own mappings (different from Forge's and Mojang's) and license them under Creative Commons Zero so everyone can use them. They usually always have mappings for the latest releases and snapshots (though a few names might be missing) and have their own program called "Enigma" ("yarn" uses it, see its README) which allows you to view and export mapped code and modify mappings.

I actually tried replacing the mappings with the mojang mappings converted to tsrg by https://github.com/hube12/DecompilerMC, but I got an error message at the end that was to long to read. I kinda gave up on directly modding clients. I'm trying to use forge now.

I found out why it didn't work. It's because the patches are still referring to the obfuscated method names. Any way to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment