91fb65c22f
Rename every shit.zen.* / asm.patchify.* class to a fresh random 16-char name in one random 16-char package on each build, via an ASM ClassRemapper pass (build.gradle ext.obfuscateJar, run after ForgeGradle reobfJar). Class names only; methods/fields preserved. Manifest Premain/Agent-Class, the DllBootstrap Class.forName string, and the native bridge name (generated_names.h OZ_BRIDGE_FQCN) are wired to the generated names. Residual original-name strings (loggers, log text, the asm.patchify.* property keys) scrubbed. Emits build/rename-mapping.txt. Pin Qt to 6.10.2 (vcpkg builtin-baseline + CI tag 2026.04.27): MSVC 14.44 crashes building Qt 6.11.0. Build Qt single-threaded locally (VCPKG_MAX_CONCURRENCY=1, loader --parallel 1, gated off GitHub Actions) to dodge parallel-compilation compiler crashes on that toolset. CI uploads rename-mapping.txt as an artifact and attaches it to the Release; the Release body warns that prebuilt artifacts share one fixed (blacklist-able) mapping and users should self-compile. README documents the obfuscation + the self-compile warning. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
206 lines
8.4 KiB
Java
206 lines
8.4 KiB
Java
package shit.zen.asm;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import net.minecraft.client.Minecraft;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
import shit.zen.ZenClient;
|
|
|
|
/**
|
|
* Initialises the runtime mojmap→SRG mapping used by {@link
|
|
* asm.patchify.loader.PatchTransformer} when patch handlers refer to Minecraft
|
|
* methods/fields by their mojmap name in annotation strings.
|
|
*
|
|
* <p>Why this exists:
|
|
* <ul>
|
|
* <li>The mod is compiled against mojmap names (e.g. {@code tick}).
|
|
* ForgeGradle's {@code reobfJar} task rewrites bytecode invocations to
|
|
* SRG names, but it does <b>not</b> touch string literals — so
|
|
* {@code @Inject(method = "tick")} stays as {@code "tick"} in the jar.</li>
|
|
* <li>In a production Forge environment Minecraft classes carry SRG names
|
|
* like {@code m_91383_}, so {@code target.methods} contains no method
|
|
* called {@code tick} and patches silently fail.</li>
|
|
* <li>{@code mapping.srg} (shipped under {@code src/main/resources/}) lists
|
|
* the SRG↔mojmap pairs. We parse it here and expose a remap helper.</li>
|
|
* <li>{@code ZenClient.isMCPMapped} is set so reflective field lookups in
|
|
* {@code shit.zen.utils.misc.ReflectionUtil} also use the right side
|
|
* of the {@code "mojmap" : "f_xxxx_"} pairs that codebase carries.</li>
|
|
* </ul>
|
|
*/
|
|
public final class Bootstrap {
|
|
private static final Logger LOGGER = LogManager.getLogger(Bootstrap.class);
|
|
|
|
/**
|
|
* Key format: {@code owner/mojName + mojDesc}. Value: SRG short method name.
|
|
* Owner is the JVM internal name (slashes), e.g. {@code net/minecraft/client/Minecraft}.
|
|
*/
|
|
private static final Map<String, String> METHOD_MOJ_TO_SRG = new HashMap<>();
|
|
|
|
/** Same key/value, but fields don't carry a descriptor: {@code owner/mojName -> srgName}. */
|
|
private static final Map<String, String> FIELD_MOJ_TO_SRG = new HashMap<>();
|
|
|
|
/**
|
|
* Fallback table for cases where the patch annotation names the wrong owner
|
|
* (e.g. a child class instead of the declaring superclass). Key:
|
|
* {@code mojName + mojDesc}. Value: SRG name if globally unambiguous,
|
|
* {@link #AMBIGUOUS} otherwise.
|
|
*/
|
|
private static final Map<String, String> METHOD_FALLBACK = new HashMap<>();
|
|
private static final Map<String, String> FIELD_FALLBACK = new HashMap<>();
|
|
private static final String AMBIGUOUS = " |