Toolchain
This page will explain decompile
->deobfuscate
->reobfuscate
process that forge uses when you install the MDK
.
Why we need to do this
Minecraft is a commercial game, which means the source code is locked away, and not only is the source code unavailable to us, but they obfuscate the game code.
If you look into the client/server JAR, you'll see that all the class names have short, nonsense names like aa
, ab
, xy
, etc. This is called Obfuscating.
The problem is, we don't[1] have the information to convert those nonsensical names to readable, understandable names.
So we need a toolchain to make it possible for us to read the source code so we can mod the game.
For more information about Obfiscating.
Deobfuscation
First the obfuscated names need unique names. Since there could be some methods with the same name, the resulting code then would not compile.
For this all of these obfuscated classes/methods/fields are assigned a number. This number increments sequentially and is called the SRG ID
((SRG stands for Searge, which was one of the co-founders of the original set of scripts and programs which did this in the beginning)) of that class/method/field, this ensures all these classes/methods/fields (henceforth called members) have a unique name.\\
These IDs are converted to SRG
names, also called Notch names
, simply by combining their ID and the type of member\\
class
-> c_XXX_
(you won't ever see this because of reasons, explained later)\\
function
-> func_XXX_
\\
field
-> field_XXX_
\\
parameter
-> p_XXX_X_
(there are two types of parameter names, also explained later)\\
These Ids will be gernerated automatically.
Decompilation
More general info
FernFlower/ForgeFlower
Forge uses ForgeFlower, which is a Fork of FernFlower. FernFlower is a decompiler that takes the compiled Minecraft Jar and turn it in to semi readable source code.
Why semi readable?
Because the decompiler has no sense of formatting or indentation.
Mappings
We don't need this step but coding with the SRG
names is hard and not really fun.
So we need to take the SRG
names and make them more user friendly, the user friendly names are community sourced names.
Since SRG
names are uniquely identifiable, due to the unique ID, it literally does a search-and-replace on all the source code text to do that SRG
->MCP
(( MCP
stands for ModCoderPack (or previously, Minecraft Coder Pack) which was the toolchain that did all of this before the advent of ForgeGradle)) application.
Some additional Infos
- You will never see c_XXX_ for classes, because the class names are picked beforehand
- this is still crowdsourced, but before a new version is ready for Forge, all classes are given an
MCP
name - this
MCP
name stays constant throughout the game version it was picked for; it can change between versions, but it usually wont for already-named classes (except for misspells, typos, and misnames)
- this is still crowdsourced, but before a new version is ready for Forge, all classes are given an
- If you look into the JAR, you won't see any packages for the obfuscated classes, but the deobfuscated classes do have the packages, this is because the same process that names the classes, also decides what package they belong to
- parameters have special names
- there are two types of parameter names:
p_XXX_X_
andp_iXXX_X_
- the one with the i means that it's a parameter for a constructor
- the first set of numbers are the SRG ID of their parent method, and the second number denotes the index of the parameter
- the index of the parameter is a bit more involved, but this will not be explained here
- there are two types of parameter names:
- If you look into the source, you'll see that parameters for lambdas don't have mapped names
- This is because of a complication in how the lambdas are compiled/decompiled; it's a more advanced topic which involves how the compiler compiles lambdas which we will not explain here.
Reobfuscation
TBD
- ↑ Mojang recently released this information in what we call
mojmappings
, but the licensing is a bit iffy For more info