JohnnyJayJay / compatre

An extremely small and fast Bukkit tool to dynamically replace version-specific types (nms, craftbukkit) at runtime without any boilerplate.
GNU Lesser General Public License v3.0
18 stars 0 forks source link

Add support for obfuscation mappings #2

Open JohnnyJayJay opened 4 years ago

JohnnyJayJay commented 4 years ago

In addition to replacing the versions in nms and craftbukkit class names, this library could also take advantage of obfuscation maps and map the names of obfuscated classes, fields and methods to the correct names at runtime.

The first obstacle here is how to integrate the obfuscation maps. For versions following 1.14.4, they can be fetched via an HTTP request:

  1. Fetch version manifest
  2. Find the correct version
  3. Fetch version url (example)
  4. Fetch and parse server_mappings -> url (example)

Doing it like this (dynamically) instead of having a fixed set of mappings files as resources has the advantage that new releases need not be added manually and that the file size is smaller. On the other hand, this also adds some overhead because some http requests need to be made and some JSON files need to be parsed.

How the mappings can be parsed is still not entirely clear to me, but I have heard that Proguard, the obfuscator used by Mojang, has a tool/library for this. I will need to look into that further.

Getting these obfuscation maps is fairly trivial. The more complex part is how to achieve something similar for versions older than 1.14.4. For those versions, no official mappings are available, but with tools like MCP you can obtain unofficial and possibly incomplete community-made mappings. Or so I've heard. I will also need to investigate this and. if it's possible, whether the format matches the one of the official mappings.

Since those mappings are probably not available on the surface web, I will probably need to put them as resources into the jar (provided that this is legal, which it may not).

As for the actual remapping when all the necessary components are available, this will need a lot more ASM than before.

JohnnyJayJay commented 4 years ago

It seems like the MCP obfuscation maps are available for download without any further computation (except unzipping, probably).

To improve performance, maps could be stored in a subdirectory of the server. That way, subsequent remappings using the same maps wouldn't need to fetch them again.

JohnnyJayJay commented 3 years ago

Apparently, a Java parser library is available for neither Proguard nor MCP obfuscation maps, so I may have to resort to writing my own.