mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-21 16:12:10 +00:00
Fix up environments support for production
This commit is contained in:
1 parent
a129617ae7
commit
441c3a7e93
5 files changed
+177
-33
No files matched your search
@@ -38,7 +38,9 @@ public abstract class MixinBootstrap {
|
||||
|
||||
private static final String MIXIN_PACKAGE = "org.spongepowered.asm.mixin.";
|
||||
private static final String ASM_PACKAGE = "org.objectweb.asm.";
|
||||
private static final String TRANSFORMER_CLASS = MixinBootstrap.MIXIN_PACKAGE + "transformer.MixinTransformer";
|
||||
private static final String TRANSFORMER_PROXY_CLASS = MixinBootstrap.MIXIN_PACKAGE + "transformer.MixinTransformer$Proxy";
|
||||
|
||||
private static boolean initialised = false;
|
||||
|
||||
static {
|
||||
Launch.classLoader.addClassLoaderExclusion(MixinBootstrap.ASM_PACKAGE);
|
||||
@@ -50,23 +52,71 @@ public abstract class MixinBootstrap {
|
||||
}
|
||||
|
||||
private MixinBootstrap() {}
|
||||
|
||||
public static void addProxy() {
|
||||
Launch.classLoader.registerTransformer(MixinBootstrap.TRANSFORMER_PROXY_CLASS);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
if (!MixinBootstrap.preInit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
MixinBootstrap.register();
|
||||
}
|
||||
|
||||
static boolean preInit() {
|
||||
Object registeredVersion = Launch.blackboard.get(MixinBootstrap.INIT_KEY);
|
||||
if (registeredVersion != null && !registeredVersion.equals(MixinBootstrap.VERSION)) {
|
||||
throw new MixinInitialisationError("Mixin subsystem version " + registeredVersion
|
||||
+ " was already initialised. Cannot bootstrap version " + MixinBootstrap.VERSION);
|
||||
if (registeredVersion != null) {
|
||||
if (!registeredVersion.equals(MixinBootstrap.VERSION)) {
|
||||
throw new MixinInitialisationError("Mixin subsystem version " + registeredVersion
|
||||
+ " was already initialised. Cannot bootstrap version " + MixinBootstrap.VERSION);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Launch.blackboard.put(MixinBootstrap.INIT_KEY, MixinBootstrap.VERSION);
|
||||
MixinEnvironment.getCurrentEnvironment();
|
||||
|
||||
Launch.classLoader.registerTransformer(MixinBootstrap.TRANSFORMER_CLASS);
|
||||
|
||||
if (!MixinBootstrap.initialised) {
|
||||
MixinBootstrap.initialised = true;
|
||||
MixinEnvironment.getCurrentEnvironment();
|
||||
MixinBootstrap.addProxy();
|
||||
|
||||
if (MixinBootstrap.findInStackTrace(Launch.class.getName(), "launch") > 132) {
|
||||
// MixinEnvironment.gotoPhase(Phase.DEFAULT); TODO
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void register() {
|
||||
if (!MixinBootstrap.initialised) {
|
||||
throw new IllegalStateException("MixinBootstrap.register() called before MixinBootstrap.preInit()");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> tweakClasses = (List<String>)Launch.blackboard.get("TweakClasses");
|
||||
if (tweakClasses != null) {
|
||||
tweakClasses.add(MixinEnvironment.class.getName() + "$EnvironmentStateTweaker");
|
||||
}
|
||||
}
|
||||
|
||||
private static int findInStackTrace(String className, String methodName) {
|
||||
Thread currentThread = Thread.currentThread();
|
||||
|
||||
if (!"main".equals(currentThread.getName())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
StackTraceElement[] stackTrace = currentThread.getStackTrace();
|
||||
for (StackTraceElement s : stackTrace) {
|
||||
if (className.equals(s.getClassName()) && methodName.equals(s.getMethodName())) {
|
||||
return s.getLineNumber();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -63,13 +63,13 @@ public class MixinTweaker implements ITweaker {
|
||||
* jar metadata, this should be a comma-separated list of mixin config JSON
|
||||
* file names.
|
||||
*/
|
||||
private final ITweaker fmlWrapper;
|
||||
private ITweaker fmlWrapper;
|
||||
|
||||
/**
|
||||
* Hello world
|
||||
*/
|
||||
public MixinTweaker() {
|
||||
MixinBootstrap.init();
|
||||
MixinBootstrap.preInit();
|
||||
this.container = this.findJarFile();
|
||||
this.fmlWrapper = this.initFMLCoreMod();
|
||||
}
|
||||
@@ -87,6 +87,29 @@ public class MixinTweaker implements ITweaker {
|
||||
return uri != null ? new File(uri) : null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.launchwrapper.ITweaker#acceptOptions(java.util.List,
|
||||
* java.io.File, java.io.File, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||
|
||||
MixinBootstrap.register();
|
||||
|
||||
if (this.fmlWrapper == null) {
|
||||
String mixinConfigs = this.getManifestAttribute("MixinConfigs");
|
||||
if (mixinConfigs == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String config : mixinConfigs.split(",")) {
|
||||
if (config.endsWith(".json")) {
|
||||
MixinEnvironment.getCurrentEnvironment().addConfiguration(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to initialise the FML coremod (if specified in the jar metadata)
|
||||
*/
|
||||
@@ -129,26 +152,6 @@ public class MixinTweaker implements ITweaker {
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.launchwrapper.ITweaker#acceptOptions(java.util.List,
|
||||
* java.io.File, java.io.File, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||
if (this.fmlWrapper == null) {
|
||||
String mixinConfigs = this.getManifestAttribute("MixinConfigs");
|
||||
if (mixinConfigs == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String config : mixinConfigs.split(",")) {
|
||||
if (config.endsWith(".json")) {
|
||||
MixinEnvironment.getCurrentEnvironment().addConfiguration(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.launchwrapper.ITweaker#injectIntoClassLoader(
|
||||
* net.minecraft.launchwrapper.LaunchClassLoader)
|
||||
|
||||
@@ -42,23 +42,43 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
|
||||
/**
|
||||
* Env interaction for mixins
|
||||
* The mixin environment manages global state information for the mixin
|
||||
* subsystem.
|
||||
*/
|
||||
public class MixinEnvironment {
|
||||
|
||||
/**
|
||||
* Environment phase, deliberately not implemented as an enum
|
||||
*/
|
||||
public static class Phase {
|
||||
|
||||
/**
|
||||
* "Pre initialisation" phase, everything before the tweak system begins
|
||||
* to load the game
|
||||
*/
|
||||
public static final Phase PREINIT = new Phase(0, "PREINIT");
|
||||
|
||||
/**
|
||||
* "Default" phase, during runtime
|
||||
*/
|
||||
public static final Phase DEFAULT = new Phase(1, "DEFAULT");
|
||||
|
||||
/**
|
||||
* All phases
|
||||
*/
|
||||
static final List<Phase> phases = ImmutableList.of(
|
||||
Phase.PREINIT,
|
||||
Phase.DEFAULT
|
||||
);
|
||||
|
||||
/**
|
||||
* Phase ordinal
|
||||
*/
|
||||
final int ordinal;
|
||||
|
||||
/**
|
||||
* Phase name
|
||||
*/
|
||||
final String name;
|
||||
|
||||
private Phase(int ordinal, String name) {
|
||||
@@ -72,7 +92,11 @@ public class MixinEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a "side", client or dedicated server
|
||||
*/
|
||||
public static enum Side {
|
||||
|
||||
/**
|
||||
* The environment was unable to determine current side
|
||||
*/
|
||||
@@ -137,7 +161,11 @@ public class MixinEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mixin options
|
||||
*/
|
||||
public static enum Option {
|
||||
|
||||
/**
|
||||
* Enable all debugging options
|
||||
*/
|
||||
@@ -217,6 +245,10 @@ public class MixinEnvironment {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tweaker used to notify the environment when we transition from preinit to
|
||||
* default
|
||||
*/
|
||||
public static class EnvironmentStateTweaker implements ITweaker {
|
||||
|
||||
@Override
|
||||
@@ -385,6 +417,10 @@ public class MixinEnvironment {
|
||||
}
|
||||
|
||||
static void gotoPhase(Phase phase) {
|
||||
if (phase.ordinal > MixinEnvironment.currentPhase.ordinal) {
|
||||
MixinBootstrap.addProxy();
|
||||
}
|
||||
|
||||
MixinEnvironment.currentPhase = phase;
|
||||
MixinEnvironment.currentEnvironment = MixinEnvironment.getEnvironment(MixinEnvironment.currentPhase);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,50 @@ import org.spongepowered.asm.util.Constants;
|
||||
*/
|
||||
public class MixinTransformer extends TreeTransformer {
|
||||
|
||||
/**
|
||||
* Proxy transformer for the mixin transformer. These transformers are used
|
||||
* to allow the mixin transformer to be re-registered in the transformer
|
||||
* chain at a later stage in startup without having to fully re-initialise
|
||||
* the mixin transformer itself. Only the latest proxy to be instantiated
|
||||
* will actually provide callbacks to the underlying mixin transformer.
|
||||
*/
|
||||
public static class Proxy implements IClassTransformer {
|
||||
|
||||
/**
|
||||
* All existing proxies
|
||||
*/
|
||||
private static List<Proxy> proxies = new ArrayList<Proxy>();
|
||||
|
||||
/**
|
||||
* Actual mixin transformer instance
|
||||
*/
|
||||
private static MixinTransformer transformer = new MixinTransformer();
|
||||
|
||||
/**
|
||||
* True if this is the active proxy, newer proxies disable their older
|
||||
* siblings
|
||||
*/
|
||||
private boolean isActive = true;
|
||||
|
||||
public Proxy() {
|
||||
for (Proxy hook : Proxy.proxies) {
|
||||
hook.isActive = false;
|
||||
}
|
||||
|
||||
Proxy.proxies.add(this);
|
||||
LogManager.getLogger("mixin").debug("Adding new mixin transformer proxy #{}", Proxy.proxies.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] basicClass) {
|
||||
if (this.isActive) {
|
||||
return Proxy.transformer.transform(name, transformedName, basicClass);
|
||||
}
|
||||
|
||||
return basicClass;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-entrance semaphore used to share re-entrance data with the TreeInfo
|
||||
*/
|
||||
@@ -204,10 +248,15 @@ public class MixinTransformer extends TreeTransformer {
|
||||
*/
|
||||
private final String sessionId = UUID.randomUUID().toString();
|
||||
|
||||
/**
|
||||
* Logging level for verbose messages
|
||||
*/
|
||||
private Level verboseLoggingLevel = Level.DEBUG;
|
||||
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
public MixinTransformer() {
|
||||
MixinTransformer() {
|
||||
MixinEnvironment environment = MixinEnvironment.getCurrentEnvironment();
|
||||
|
||||
Object globalMixinTransformer = environment.getActiveTransformer();
|
||||
@@ -230,7 +279,7 @@ public class MixinTransformer extends TreeTransformer {
|
||||
if (basicClass == null || transformedName == null) {
|
||||
return basicClass;
|
||||
}
|
||||
|
||||
|
||||
boolean locked = this.lock.push().isSet();
|
||||
|
||||
MixinEnvironment environment = MixinEnvironment.getCurrentEnvironment();
|
||||
@@ -301,6 +350,9 @@ public class MixinTransformer extends TreeTransformer {
|
||||
}
|
||||
|
||||
private void init(MixinEnvironment environment) {
|
||||
this.verboseLoggingLevel = (environment.getOption(Option.DEBUG_VERBOSE)) ? Level.INFO : Level.DEBUG;
|
||||
this.logger.log(this.verboseLoggingLevel, "Preparing mixins for {}", environment);
|
||||
|
||||
this.addConfigs(environment);
|
||||
this.addModules(environment);
|
||||
this.initConfigs();
|
||||
@@ -320,6 +372,7 @@ public class MixinTransformer extends TreeTransformer {
|
||||
try {
|
||||
MixinConfig config = MixinConfig.create(configFile);
|
||||
if (config != null) {
|
||||
this.logger.log(this.verboseLoggingLevel, "Adding mixin config {}", config);
|
||||
this.pendingConfigs.add(config);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@@ -337,6 +390,8 @@ public class MixinTransformer extends TreeTransformer {
|
||||
* @param environment Environment to query
|
||||
*/
|
||||
private void addModules(MixinEnvironment environment) {
|
||||
this.modules.clear();
|
||||
|
||||
// Run CheckClassAdapter on the mixin bytecode if debug option is enabled
|
||||
if (environment.getOption(Option.DEBUG_VERIFY)) {
|
||||
this.modules.add(new MixinTransformerModuleCheckClass());
|
||||
|
||||
@@ -34,7 +34,7 @@ import java.lang.annotation.Target;
|
||||
* <p>Internal use only.</p>
|
||||
*
|
||||
* <p>Decoration annotation used by
|
||||
* {@link org.spongepowered.asm.mixin.transformer.meta.MixinInfo} and
|
||||
* {@link org.spongepowered.asm.mixin.transformer.MixinInfo} and
|
||||
* {@link org.spongepowered.asm.mixin.transformer.MixinPreProcessor} to mark
|
||||
* methods in a mixin which have been renamed prior to being merged.</p>
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user