mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-21 23:12:11 +00:00
Quick and dirty merge of platform refactor for remapper, closes #91
This commit is contained in:
1 parent
75f327fa56
commit
adf1c040a6
13 files changed
+481
-278
No files matched your search
@@ -24,14 +24,19 @@
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.launch.platform.MixinPlatformManager;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.util.PrettyPrinter;
|
||||
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
/**
|
||||
* Bootstaps the mixin subsystem. This class acts as a bridge between the mixin
|
||||
@@ -60,7 +65,7 @@ public abstract class MixinBootstrap {
|
||||
/**
|
||||
* Subsystem version
|
||||
*/
|
||||
public static final String VERSION = "0.5.10";
|
||||
public static final String VERSION = "0.6";
|
||||
|
||||
// Consts
|
||||
private static final String LAUNCH_PACKAGE = "org.spongepowered.asm.launch.";
|
||||
@@ -76,7 +81,7 @@ public abstract class MixinBootstrap {
|
||||
|
||||
// These are Klass local, with luck this shouldn't be a problem
|
||||
private static boolean initialised = false;
|
||||
private static boolean injectStateTweaker = true;
|
||||
private static boolean initState = true;
|
||||
|
||||
// Static initialiser, add classloader exclusions as early as possible
|
||||
static {
|
||||
@@ -88,6 +93,8 @@ public abstract class MixinBootstrap {
|
||||
// Only needed in dev, in production this would be handled by the tweaker
|
||||
Launch.classLoader.addClassLoaderExclusion(MixinBootstrap.LAUNCH_PACKAGE);
|
||||
}
|
||||
|
||||
private static MixinPlatformManager platformManager = new MixinPlatformManager();
|
||||
|
||||
private MixinBootstrap() {}
|
||||
|
||||
@@ -98,21 +105,28 @@ public abstract class MixinBootstrap {
|
||||
Launch.classLoader.registerTransformer(MixinBootstrap.TRANSFORMER_PROXY_CLASS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the platform manager
|
||||
*/
|
||||
public static MixinPlatformManager getPlatform() {
|
||||
return MixinBootstrap.platformManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the mixin subsystem
|
||||
*/
|
||||
public static void init() {
|
||||
if (!MixinBootstrap.preInit()) {
|
||||
if (!MixinBootstrap.start()) {
|
||||
return;
|
||||
}
|
||||
|
||||
MixinBootstrap.register();
|
||||
MixinBootstrap.doInit(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 1 of mixin initialisation
|
||||
*/
|
||||
static boolean preInit() {
|
||||
static boolean start() {
|
||||
Object registeredVersion = Blackboard.get(Blackboard.Keys.INIT);
|
||||
if (registeredVersion != null) {
|
||||
if (!registeredVersion.equals(MixinBootstrap.VERSION)) {
|
||||
@@ -132,11 +146,12 @@ public abstract class MixinBootstrap {
|
||||
if (command != null && command.contains("GradleStart")) {
|
||||
System.setProperty("mixin.env.disableRefMap", "true");
|
||||
}
|
||||
|
||||
|
||||
if (MixinBootstrap.findInStackTrace(Launch.class.getName(), "launch") > 132) {
|
||||
MixinBootstrap.logger.error("Initialising mixin subsystem after game pre-init phase! Some mixins may be skipped.");
|
||||
MixinEnvironment.init(Phase.DEFAULT);
|
||||
MixinBootstrap.injectStateTweaker = false;
|
||||
MixinBootstrap.getPlatform().prepare(null);
|
||||
MixinBootstrap.initState = false;
|
||||
} else {
|
||||
MixinEnvironment.init(Phase.PREINIT);
|
||||
}
|
||||
@@ -148,16 +163,23 @@ public abstract class MixinBootstrap {
|
||||
}
|
||||
|
||||
/**
|
||||
* Phase 2 of mixin initialisation, register the state tweaker
|
||||
* Phase 2 of mixin initialisation, initialise the phases
|
||||
*/
|
||||
static void register() {
|
||||
static void doInit(List<String> args) {
|
||||
if (!MixinBootstrap.initialised) {
|
||||
throw new IllegalStateException("MixinBootstrap.register() called before MixinBootstrap.preInit()");
|
||||
throw new IllegalStateException("MixinBootstrap.doInit() called before MixinBootstrap.preInit()");
|
||||
}
|
||||
|
||||
if (MixinBootstrap.injectStateTweaker) {
|
||||
for (String platformProviderClass : MixinBootstrap.getPlatform().getPhaseProviderClasses()) {
|
||||
// System.err.printf("Registering %s\n", platformProviderClass);
|
||||
// MixinEnvironment.registerPhaseProvider(platformProviderClass);
|
||||
}
|
||||
|
||||
if (MixinBootstrap.initState) {
|
||||
MixinBootstrap.getPlatform().prepare(args);
|
||||
|
||||
if (MixinBootstrap.findInStackTrace(Launch.class.getName(), "launch") < 4) {
|
||||
MixinBootstrap.logger.warn("MixinBootstrap.register() called during a tweak constructor. Expect CoModificationException in 5.. 4..");
|
||||
MixinBootstrap.logger.warn("MixinBootstrap.doInit() called during a tweak constructor. Expect CoModificationException in 5.. 4..");
|
||||
}
|
||||
|
||||
List<String> tweakClasses = Blackboard.<List<String>>get(Blackboard.Keys.TWEAKCLASSES);
|
||||
@@ -167,6 +189,10 @@ public abstract class MixinBootstrap {
|
||||
}
|
||||
}
|
||||
|
||||
static void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||
MixinBootstrap.getPlatform().injectIntoClassLoader(classLoader);
|
||||
}
|
||||
|
||||
private static int findInStackTrace(String className, String methodName) {
|
||||
Thread currentThread = Thread.currentThread();
|
||||
|
||||
@@ -183,4 +209,5 @@ public abstract class MixinBootstrap {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,23 +25,9 @@
|
||||
package org.spongepowered.asm.launch;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
import org.spongepowered.asm.util.Constants.ManifestAttributes;
|
||||
|
||||
import net.minecraft.launchwrapper.ITweaker;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
/**
|
||||
@@ -51,90 +37,20 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
*/
|
||||
public class MixinTweaker implements ITweaker {
|
||||
|
||||
private static final String DEFAULT_MAIN_CLASS = "net.minecraft.client.main.Main";
|
||||
|
||||
/**
|
||||
* Make with the logging already
|
||||
*/
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
/**
|
||||
* Tweak containers
|
||||
*/
|
||||
private final Map<URI, MixinTweakContainer> containers = new LinkedHashMap<URI, MixinTweakContainer>();
|
||||
|
||||
/**
|
||||
* Container for this tweaker
|
||||
*/
|
||||
private MixinTweakContainer primaryContainer;
|
||||
|
||||
/**
|
||||
* Tracks whether {@link #acceptOptions} was called yet, if true, causes new
|
||||
* launch agents to be <tt>prepare</tt>d immediately
|
||||
*/
|
||||
private boolean prepared = false;
|
||||
|
||||
/**
|
||||
* Hello world
|
||||
*/
|
||||
public MixinTweaker() {
|
||||
MixinBootstrap.preInit();
|
||||
|
||||
// Add agents for the tweak container
|
||||
URI uri = null;
|
||||
try {
|
||||
uri = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
|
||||
if (uri != null) {
|
||||
this.primaryContainer = this.addContainer(uri);
|
||||
}
|
||||
} catch (URISyntaxException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
MixinBootstrap.start();
|
||||
}
|
||||
|
||||
public final MixinTweakContainer addContainer(URI uri) {
|
||||
MixinTweakContainer existingContainer = this.containers.get(uri);
|
||||
if (existingContainer != null) {
|
||||
return existingContainer;
|
||||
}
|
||||
|
||||
MixinTweaker.logger.debug("Adding mixin launch agents for container {}", uri);
|
||||
MixinTweakContainer container = new MixinTweakContainer(uri);
|
||||
this.containers.put(uri, container);
|
||||
|
||||
if (this.prepared) {
|
||||
container.prepare();
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.launchwrapper.ITweaker#acceptOptions(java.util.List,
|
||||
* java.io.File, java.io.File, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public final void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) {
|
||||
MixinBootstrap.register();
|
||||
this.prepared = true;
|
||||
for (MixinTweakContainer container : this.containers.values()) {
|
||||
container.prepare();
|
||||
}
|
||||
this.parseArgs(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and parse command-line arguments
|
||||
*
|
||||
* @param args command-line arguments
|
||||
*/
|
||||
private void parseArgs(List<String> args) {
|
||||
boolean captureNext = false;
|
||||
for (String arg : args) {
|
||||
if (captureNext) {
|
||||
MixinTweaker.addConfig(arg);
|
||||
}
|
||||
captureNext = "--mixin".equals(arg);
|
||||
}
|
||||
MixinBootstrap.doInit(args);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -143,46 +59,7 @@ public class MixinTweaker implements ITweaker {
|
||||
*/
|
||||
@Override
|
||||
public final void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||
if (this.primaryContainer != null) {
|
||||
this.primaryContainer.initPrimaryContainer();
|
||||
}
|
||||
|
||||
this.scanClasspath();
|
||||
MixinTweaker.logger.debug("injectIntoClassLoader running with {} agents", this.containers.size());
|
||||
for (MixinTweakContainer container : this.containers.values()) {
|
||||
try {
|
||||
container.injectIntoClassLoader(classLoader);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the classpath for mixin containers (containers which declare the
|
||||
* mixin tweaker in their manifest) and add agents for them
|
||||
*/
|
||||
private void scanClasspath() {
|
||||
for (URL url : Launch.classLoader.getSources()) {
|
||||
try {
|
||||
URI uri = url.toURI();
|
||||
if (this.containers.containsKey(uri)) {
|
||||
continue;
|
||||
}
|
||||
MixinTweaker.logger.debug("Scanning {} for mixin tweaker", uri);
|
||||
if (!"file".equals(uri.getScheme()) || !new File(uri).exists()) {
|
||||
continue;
|
||||
}
|
||||
MainAttributes attributes = MainAttributes.of(uri);
|
||||
String tweaker = attributes.get(ManifestAttributes.TWEAKER);
|
||||
if (MixinTweaker.class.getName().equals(tweaker)) {
|
||||
MixinTweaker.logger.debug("{} contains a mixin tweaker, adding agents", uri);
|
||||
this.addContainer(uri);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
MixinBootstrap.injectIntoClassLoader(classLoader);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -190,14 +67,7 @@ public class MixinTweaker implements ITweaker {
|
||||
*/
|
||||
@Override
|
||||
public String getLaunchTarget() {
|
||||
for (MixinTweakContainer container : this.containers.values()) {
|
||||
String mainClass = container.getLaunchTarget();
|
||||
if (mainClass != null) {
|
||||
return mainClass;
|
||||
}
|
||||
}
|
||||
|
||||
return MixinTweaker.DEFAULT_MAIN_CLASS;
|
||||
return MixinBootstrap.getPlatform().getLaunchTarget();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -208,70 +78,4 @@ public class MixinTweaker implements ITweaker {
|
||||
return new String[]{};
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired compatibility level as a string, used by agents to set
|
||||
* compatibility level from jar manifest
|
||||
*
|
||||
* @param level compatibility level as a string
|
||||
*/
|
||||
@Deprecated
|
||||
static void setCompatibilityLevel(String level) {
|
||||
try {
|
||||
CompatibilityLevel value = CompatibilityLevel.valueOf(level.toUpperCase());
|
||||
MixinTweaker.logger.debug("Setting mixin compatibility level: {}", value);
|
||||
MixinEnvironment.setCompatibilityLevel(value);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
MixinTweaker.logger.warn("Invalid compatibility level specified: {}", level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a config from a jar manifest source or the command line. Supports
|
||||
* config declarations in the form <tt>filename.json</tt> or alternatively
|
||||
* <tt>filename.json@PHASE</tt> where <tt>PHASE</tt> is a
|
||||
* case-sensitive string token representing an environment phase.
|
||||
*
|
||||
* @param config config resource name, does not require a leading /
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
static void addConfig(String config) {
|
||||
if (config.endsWith(".json")) {
|
||||
MixinTweaker.logger.debug("Registering mixin config: {}", config);
|
||||
Mixins.addConfiguration(config);
|
||||
} else if (config.contains(".json@")) {
|
||||
int pos = config.indexOf(".json@");
|
||||
String phaseName = config.substring(pos + 6);
|
||||
config = config.substring(0, pos + 5);
|
||||
Phase phase = Phase.forName(phaseName);
|
||||
if (phase != null) {
|
||||
MixinTweaker.logger.warn("Setting config phase via manifest is deprecated: {}. Specify target in config instead", config);
|
||||
MixinTweaker.logger.debug("Registering mixin config: {}", config);
|
||||
MixinEnvironment.getEnvironment(phase).addConfiguration(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token provider class from a jar manifest source. Supports either
|
||||
* bare class names in the form <tt>blah.package.ClassName</tt> or
|
||||
* alternatively <tt>blah.package.ClassName@PHASE</tt> where
|
||||
* <tt>PHASE</tt> is a case-sensitive string token representing an
|
||||
* environment phase name.
|
||||
*
|
||||
* @param provider provider class name, optionally suffixed with @PHASE
|
||||
*/
|
||||
static void addTokenProvider(String provider) {
|
||||
if (provider.contains("@")) {
|
||||
String[] parts = provider.split("@", 2);
|
||||
Phase phase = Phase.forName(parts[1]);
|
||||
if (phase != null) {
|
||||
MixinTweaker.logger.debug("Registering token provider class: {}", parts[0]);
|
||||
MixinEnvironment.getEnvironment(phase).registerTokenProviderClass(parts[0]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MixinEnvironment.getDefaultEnvironment().registerTokenProviderClass(provider);
|
||||
}
|
||||
|
||||
}
|
||||
+13
-7
@@ -22,21 +22,26 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
/**
|
||||
* Base interface for launch agents. Launch agents are environment-specific
|
||||
* launch handlers which are used by the {@link MixinTweaker mixin tweaker} to
|
||||
* perform launch tasks required by that environment without having to fill the
|
||||
* tweaker itself with a bunch of environment-specific cruft.
|
||||
* Base interface for platform agents. Platform agents are environment-specific
|
||||
* handlers which are used by the Mixin subsystem to perform platform-specific
|
||||
* tasks required by different environments without having to litter the Mixin
|
||||
* codebase with a bunch of environment-specific cruft.
|
||||
*
|
||||
* <p>Agents handle mixin environment launch tasks on a per-container basis,
|
||||
* <p>Platform Agents handle mixin environment tasks on a per-container basis,
|
||||
* with each container in the environment being assigned one of each available
|
||||
* type of agent to handle those tasks on behalf of the container.</p>
|
||||
*/
|
||||
interface IMixinLaunchAgent {
|
||||
public interface IMixinPlatformAgent {
|
||||
|
||||
/**
|
||||
* Get the phase provider for this agent
|
||||
*/
|
||||
public abstract String getPhaseProvider();
|
||||
|
||||
/**
|
||||
* Called during pre-initialisation, after all tweakers and tweak containers
|
||||
@@ -63,4 +68,5 @@ interface IMixinLaunchAgent {
|
||||
* custom target is available.
|
||||
*/
|
||||
public abstract String getLaunchTarget();
|
||||
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
+29
-16
@@ -22,46 +22,48 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.spongepowered.asm.launch.Blackboard;
|
||||
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
/**
|
||||
* A collection of {@link IMixinLaunchAgent} launch agents)
|
||||
* A collection of {@link IMixinPlatformAgent} platform agents)
|
||||
*/
|
||||
public class MixinTweakContainer {
|
||||
public class MixinContainer {
|
||||
|
||||
public static final List<String> agentClasses = new ArrayList<String>();
|
||||
|
||||
static {
|
||||
Blackboard.put(Blackboard.Keys.AGENTS, MixinTweakContainer.agentClasses);
|
||||
MixinTweakContainer.agentClasses.add("org.spongepowered.asm.launch.MixinLaunchAgentFML");
|
||||
MixinTweakContainer.agentClasses.add("org.spongepowered.asm.launch.MixinLaunchAgentDefault");
|
||||
Blackboard.put(Blackboard.Keys.AGENTS, MixinContainer.agentClasses);
|
||||
MixinContainer.agentClasses.add("org.spongepowered.asm.launch.platform.MixinPlatformAgentFML");
|
||||
MixinContainer.agentClasses.add("org.spongepowered.asm.launch.platform.MixinPlatformAgentDefault");
|
||||
}
|
||||
|
||||
private final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
private final URI uri;
|
||||
|
||||
private final List<IMixinLaunchAgent> agents = new ArrayList<IMixinLaunchAgent>();
|
||||
private final List<IMixinPlatformAgent> agents = new ArrayList<IMixinPlatformAgent>();
|
||||
|
||||
public MixinTweakContainer(URI uri) {
|
||||
public MixinContainer(MixinPlatformManager manager, URI uri) {
|
||||
this.uri = uri;
|
||||
|
||||
for (String agentClass : MixinTweakContainer.agentClasses) {
|
||||
for (String agentClass : MixinContainer.agentClasses) {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<IMixinLaunchAgent> clazz = (Class<IMixinLaunchAgent>)Class.forName(agentClass);
|
||||
Constructor<IMixinLaunchAgent> ctor = clazz.getDeclaredConstructor(URI.class);
|
||||
IMixinLaunchAgent agent = ctor.newInstance(uri);
|
||||
Class<IMixinPlatformAgent> clazz = (Class<IMixinPlatformAgent>)Class.forName(agentClass);
|
||||
Constructor<IMixinPlatformAgent> ctor = clazz.getDeclaredConstructor(MixinPlatformManager.class, URI.class);
|
||||
IMixinPlatformAgent agent = ctor.newInstance(manager, uri);
|
||||
this.agents.add(agent);
|
||||
} catch (Exception ex) {
|
||||
this.logger.catching(ex);
|
||||
@@ -76,17 +78,28 @@ public class MixinTweakContainer {
|
||||
return this.uri;
|
||||
}
|
||||
|
||||
public Collection<String> getPhaseProviders() {
|
||||
List<String> phaseProviders = new ArrayList<String>();
|
||||
for (IMixinPlatformAgent agent : this.agents) {
|
||||
String phaseProvider = agent.getPhaseProvider();
|
||||
if (phaseProvider != null) {
|
||||
phaseProviders.add(phaseProvider);
|
||||
}
|
||||
}
|
||||
return phaseProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void prepare() {
|
||||
for (IMixinLaunchAgent agent : this.agents) {
|
||||
for (IMixinPlatformAgent agent : this.agents) {
|
||||
agent.prepare();
|
||||
}
|
||||
}
|
||||
|
||||
public void initPrimaryContainer() {
|
||||
for (IMixinLaunchAgent agent : this.agents) {
|
||||
for (IMixinPlatformAgent agent : this.agents) {
|
||||
this.logger.debug("Processing launch tasks for {}", agent);
|
||||
agent.initPrimaryContainer();
|
||||
}
|
||||
@@ -96,13 +109,13 @@ public class MixinTweakContainer {
|
||||
* @param classLoader
|
||||
*/
|
||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||
for (IMixinLaunchAgent agent : this.agents) {
|
||||
for (IMixinPlatformAgent agent : this.agents) {
|
||||
agent.injectIntoClassLoader(classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
public String getLaunchTarget() {
|
||||
for (IMixinLaunchAgent agent : this.agents) {
|
||||
for (IMixinPlatformAgent agent : this.agents) {
|
||||
String launchTarget = agent.getLaunchTarget();
|
||||
if (launchTarget != null) {
|
||||
return launchTarget;
|
||||
+14
-6
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
@@ -31,15 +31,17 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Launch agent base class
|
||||
* Platform agent base class
|
||||
*/
|
||||
public abstract class MixinLaunchAgentAbstract implements IMixinLaunchAgent {
|
||||
public abstract class MixinPlatformAgentAbstract implements IMixinPlatformAgent {
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
protected static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
protected final MixinPlatformManager manager;
|
||||
|
||||
/**
|
||||
* URI to the container
|
||||
*/
|
||||
@@ -56,11 +58,12 @@ public abstract class MixinLaunchAgentAbstract implements IMixinLaunchAgent {
|
||||
protected final MainAttributes attributes;
|
||||
|
||||
/**
|
||||
* Create a new launch agent for the specified URI
|
||||
* Create a new platform agent for the specified URI
|
||||
*
|
||||
* @param uri
|
||||
*/
|
||||
public MixinLaunchAgentAbstract(URI uri) {
|
||||
public MixinPlatformAgentAbstract(MixinPlatformManager manager, URI uri) {
|
||||
this.manager = manager;
|
||||
this.uri = uri;
|
||||
this.container = this.uri != null ? new File(this.uri) : null;
|
||||
this.attributes = MainAttributes.of(uri);
|
||||
@@ -68,7 +71,12 @@ public abstract class MixinLaunchAgentAbstract implements IMixinLaunchAgent {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("LaunchAgent[%s:%s]", this.getClass().getSimpleName(), this.uri);
|
||||
return String.format("PlatformAgent[%s:%s]", this.getClass().getSimpleName(), this.uri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPhaseProvider() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+10
-11
@@ -22,7 +22,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@@ -31,35 +31,34 @@ import org.spongepowered.asm.util.Constants.ManifestAttributes;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
/**
|
||||
* Default launch agent, handles the <tt>MixinConfigs</tt> manifest key
|
||||
* Default platform agent, handles the mixin manifest keys such as
|
||||
* <tt>MixinConfigs</tt> and <tt>MixinTokenProviders</tt>.
|
||||
*/
|
||||
public class MixinLaunchAgentDefault extends MixinLaunchAgentAbstract {
|
||||
public class MixinPlatformAgentDefault extends MixinPlatformAgentAbstract {
|
||||
|
||||
public MixinLaunchAgentDefault(URI uri) {
|
||||
super(uri);
|
||||
public MixinPlatformAgentDefault(MixinPlatformManager manager, URI uri) {
|
||||
super(manager, uri);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void prepare() {
|
||||
@SuppressWarnings("deprecation")
|
||||
String compatibilityLevel = this.attributes.get(ManifestAttributes.COMPATIBILITY);
|
||||
if (compatibilityLevel != null) {
|
||||
MixinLaunchAgentAbstract.logger.warn("{} Setting mixin compatibility level via manifest is deprecated, "
|
||||
+ "use 'compatibilityLevel' key in config instead", this.container);
|
||||
MixinTweaker.setCompatibilityLevel(compatibilityLevel);
|
||||
this.manager.setCompatibilityLevel(compatibilityLevel);
|
||||
}
|
||||
|
||||
String mixinConfigs = this.attributes.get(ManifestAttributes.MIXINCONFIGS);
|
||||
if (mixinConfigs != null) {
|
||||
for (String config : mixinConfigs.split(",")) {
|
||||
MixinTweaker.addConfig(config.trim());
|
||||
this.manager.addConfig(config.trim());
|
||||
}
|
||||
}
|
||||
|
||||
String tokenProviders = this.attributes.get(ManifestAttributes.TOKENPROVIDERS);
|
||||
if (tokenProviders != null) {
|
||||
for (String provider : tokenProviders.split(",")) {
|
||||
MixinTweaker.addTokenProvider(provider.trim());
|
||||
this.manager.addTokenProvider(provider.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
-23
@@ -22,32 +22,39 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.launch;
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
//import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.spongepowered.asm.launch.Blackboard;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
//import org.spongepowered.asm.mixin.environment.IPhaseProvider;
|
||||
//import org.spongepowered.asm.mixin.environment.PhaseDefinition;
|
||||
//import org.spongepowered.asm.mixin.environment.phase.OnLogMessage;
|
||||
import org.spongepowered.asm.mixin.extensibility.IRemapper;
|
||||
|
||||
//import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.launchwrapper.ITweaker;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
/**
|
||||
* Launch agent for use under FML.
|
||||
* Platform agent for use under FML.
|
||||
*
|
||||
* <p>When FML is present we scan containers for the manifest entries which are
|
||||
* inhibited by the tweaker, in particular the <tt>FMLCorePlugin</tt> and
|
||||
* <tt>FMLCorePluginContainsFMLMod</tt> entries. This is required because FML
|
||||
* performs no further processing of containers if they contain a tweaker!</p>
|
||||
*/
|
||||
public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
public class MixinPlatformAgentFML extends MixinPlatformAgentAbstract {
|
||||
|
||||
private static final String LOAD_CORE_MOD_METHOD = "loadCoreMod";
|
||||
private static final String GET_REPARSEABLE_COREMODS_METHOD = "getReparseableCoremods";
|
||||
@@ -83,8 +90,8 @@ public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
/**
|
||||
* @param uri
|
||||
*/
|
||||
public MixinLaunchAgentFML(URI uri) {
|
||||
super(uri);
|
||||
public MixinPlatformAgentFML(MixinPlatformManager manager, URI uri) {
|
||||
super(manager, uri);
|
||||
this.fileName = this.container.getName();
|
||||
this.coreModWrapper = this.initFMLCoreMod();
|
||||
}
|
||||
@@ -94,9 +101,9 @@ public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
*/
|
||||
private ITweaker initFMLCoreMod() {
|
||||
try {
|
||||
this.clCoreModManager = MixinLaunchAgentFML.getCoreModManagerClass();
|
||||
this.clCoreModManager = MixinPlatformAgentFML.getCoreModManagerClass();
|
||||
|
||||
if ("true".equalsIgnoreCase(this.attributes.get(MixinLaunchAgentFML.MFATT_FORCELOADASMOD))) {
|
||||
if ("true".equalsIgnoreCase(this.attributes.get(MixinPlatformAgentFML.MFATT_FORCELOADASMOD))) {
|
||||
this.loadAsMod();
|
||||
}
|
||||
|
||||
@@ -119,12 +126,12 @@ public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
*/
|
||||
private void loadAsMod() {
|
||||
try {
|
||||
MixinLaunchAgentFML.getIgnoredMods(this.clCoreModManager).remove(this.fileName);
|
||||
MixinPlatformAgentFML.getIgnoredMods(this.clCoreModManager).remove(this.fileName);
|
||||
} catch (Exception ex) {
|
||||
MixinLaunchAgentAbstract.logger.catching(ex);
|
||||
MixinPlatformAgentAbstract.logger.catching(ex);
|
||||
}
|
||||
|
||||
if (this.attributes.get(MixinLaunchAgentFML.MFATT_COREMODCONTAINSMOD) != null) {
|
||||
if (this.attributes.get(MixinPlatformAgentFML.MFATT_COREMODCONTAINSMOD) != null) {
|
||||
this.addReparseableJar();
|
||||
}
|
||||
}
|
||||
@@ -136,7 +143,7 @@ public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
private void addReparseableJar() {
|
||||
try {
|
||||
Method mdGetReparsedCoremods = this.clCoreModManager.getDeclaredMethod(Blackboard.getString(
|
||||
Blackboard.Keys.FML_GET_REPARSEABLE_COREMODS, MixinLaunchAgentFML.GET_REPARSEABLE_COREMODS_METHOD));
|
||||
Blackboard.Keys.FML_GET_REPARSEABLE_COREMODS, MixinPlatformAgentFML.GET_REPARSEABLE_COREMODS_METHOD));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> reparsedCoremods = (List<String>)mdGetReparsedCoremods.invoke(null);
|
||||
if (!reparsedCoremods.contains(this.fileName)) {
|
||||
@@ -148,13 +155,13 @@ public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
}
|
||||
|
||||
private ITweaker injectCorePlugin() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
|
||||
String coreModName = this.attributes.get(MixinLaunchAgentFML.MFATT_FMLCOREPLUGIN);
|
||||
String coreModName = this.attributes.get(MixinPlatformAgentFML.MFATT_FMLCOREPLUGIN);
|
||||
if (coreModName == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Method mdLoadCoreMod = this.clCoreModManager.getDeclaredMethod(Blackboard.getString(
|
||||
Blackboard.Keys.FML_LOAD_CORE_MOD, MixinLaunchAgentFML.LOAD_CORE_MOD_METHOD), LaunchClassLoader.class, String.class, File.class);
|
||||
Blackboard.Keys.FML_LOAD_CORE_MOD, MixinPlatformAgentFML.LOAD_CORE_MOD_METHOD), LaunchClassLoader.class, String.class, File.class);
|
||||
mdLoadCoreMod.setAccessible(true);
|
||||
ITweaker wrapper = (ITweaker)mdLoadCoreMod.invoke(null, Launch.classLoader, coreModName, this.container);
|
||||
if (wrapper == null) {
|
||||
@@ -163,38 +170,44 @@ public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPhaseProvider() {
|
||||
return MixinPlatformAgentFML.class.getName() + "$PhaseProvider";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.launch.IMixinLaunchAgent#prepare()
|
||||
* @see org.spongepowered.asm.launch.IMixinPlatformAgent#prepare()
|
||||
*/
|
||||
@Override
|
||||
public void prepare() {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.launch.IMixinLaunchAgent
|
||||
* @see org.spongepowered.asm.launch.IMixinPlatformAgent
|
||||
* #initPrimaryContainer()
|
||||
*/
|
||||
@Override
|
||||
public void initPrimaryContainer() {
|
||||
if (this.clCoreModManager != null) {
|
||||
// MixinEnvironment.registerPhaseProvider(MixinPlatformAgentFML.class.getName() + "$PhaseProvider");
|
||||
this.injectRemapper();
|
||||
}
|
||||
}
|
||||
|
||||
private void injectRemapper() {
|
||||
try {
|
||||
Class<?> clFmlRemapperAdapter = Class.forName(MixinLaunchAgentFML.FML_REMAPPER_ADAPTER_CLASS, true, Launch.classLoader);
|
||||
Class<?> clFmlRemapperAdapter = Class.forName(MixinPlatformAgentFML.FML_REMAPPER_ADAPTER_CLASS, true, Launch.classLoader);
|
||||
Method mdCreate = clFmlRemapperAdapter.getDeclaredMethod("create");
|
||||
IRemapper remapper = (IRemapper)mdCreate.invoke(null);
|
||||
MixinEnvironment.getDefaultEnvironment().getRemappers().add(remapper);
|
||||
} catch (Exception ex) {
|
||||
MixinLaunchAgentAbstract.logger.debug("Failed instancing FML remapper adapter, things will probably go horribly for notch-obf'd mods!");
|
||||
MixinPlatformAgentAbstract.logger.debug("Failed instancing FML remapper adapter, things will probably go horribly for notch-obf'd mods!");
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.launch.IMixinLaunchAgent
|
||||
* @see org.spongepowered.asm.launch.IMixinPlatformAgent
|
||||
* #injectIntoClassLoader(net.minecraft.launchwrapper.LaunchClassLoader)
|
||||
*/
|
||||
@Override
|
||||
@@ -205,13 +218,13 @@ public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.launch.IMixinLaunchAgent#getLaunchTarget()
|
||||
* @see org.spongepowered.asm.launch.IMixinPlatformAgent#getLaunchTarget()
|
||||
*/
|
||||
@Override
|
||||
public String getLaunchTarget() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Performs a naive check which attempts to discover whether we are pre or
|
||||
* post FML's main injection. If we are <i>pre</i>, then we must <b>not</b>
|
||||
@@ -240,7 +253,7 @@ public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
private static Class<?> getCoreModManagerClass() throws ClassNotFoundException {
|
||||
try {
|
||||
return Class.forName(Blackboard.getString(
|
||||
Blackboard.Keys.FML_CORE_MOD_MANAGER, MixinLaunchAgentFML.CORE_MOD_MANAGER_CLASS));
|
||||
Blackboard.Keys.FML_CORE_MOD_MANAGER, MixinPlatformAgentFML.CORE_MOD_MANAGER_CLASS));
|
||||
} catch (ClassNotFoundException ex) {
|
||||
return Class.forName("cpw.mods.fml.relauncher.CoreModManager");
|
||||
}
|
||||
@@ -252,13 +265,13 @@ public class MixinLaunchAgentFML extends MixinLaunchAgentAbstract {
|
||||
|
||||
try {
|
||||
mdGetIgnoredMods = clCoreModManager.getDeclaredMethod(Blackboard.getString(
|
||||
Blackboard.Keys.FML_GET_IGNORED_MODS, MixinLaunchAgentFML.GET_IGNORED_MODS_METHOD));
|
||||
Blackboard.Keys.FML_GET_IGNORED_MODS, MixinPlatformAgentFML.GET_IGNORED_MODS_METHOD));
|
||||
} catch (NoSuchMethodException ex1) {
|
||||
try {
|
||||
// Legacy name
|
||||
mdGetIgnoredMods = clCoreModManager.getDeclaredMethod("getLoadedCoremods");
|
||||
} catch (NoSuchMethodException ex2) {
|
||||
MixinLaunchAgentAbstract.logger.catching(Level.DEBUG, ex2);
|
||||
MixinPlatformAgentAbstract.logger.catching(Level.DEBUG, ex2);
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* This file is part of Mixin, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) SpongePowered <https://www.spongepowered.org>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package org.spongepowered.asm.launch.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
//import org.spongepowered.asm.launch.MixinBootstrap.Delegate;
|
||||
import org.spongepowered.asm.launch.MixinTweaker;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.CompatibilityLevel;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Phase;
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
|
||||
//import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
/**
|
||||
* Handler for platform-specific behaviour required in different mixin
|
||||
* environments.
|
||||
*/
|
||||
public class MixinPlatformManager {
|
||||
|
||||
private static final String MFATT_TWEAKER = "TweakClass";
|
||||
private static final String DEFAULT_MAIN_CLASS = "net.minecraft.client.main.Main";
|
||||
|
||||
/**
|
||||
* Make with the logging already
|
||||
*/
|
||||
private static final Logger logger = LogManager.getLogger("mixin");
|
||||
|
||||
/**
|
||||
* Bootstrap delegate
|
||||
*/
|
||||
// private final Delegate delegate;
|
||||
|
||||
/**
|
||||
* Tweak containers
|
||||
*/
|
||||
private final Map<URI, MixinContainer> containers = new LinkedHashMap<URI, MixinContainer>();
|
||||
|
||||
/**
|
||||
* Container for this tweaker
|
||||
*/
|
||||
private MixinContainer primaryContainer;
|
||||
|
||||
/**
|
||||
* Tracks whether {@link #acceptOptions} was called yet, if true, causes new
|
||||
* agents to be <tt>prepare</tt>d immediately
|
||||
*/
|
||||
private boolean prepared = false;
|
||||
|
||||
/**
|
||||
* Tracks whether {@link #injectIntoClassLoader} was called yet
|
||||
*/
|
||||
private boolean injected;
|
||||
|
||||
public MixinPlatformManager() { //Delegate delegate) {
|
||||
// this.delegate = delegate;
|
||||
|
||||
// Add agents for the tweak container
|
||||
URI uri = null;
|
||||
try {
|
||||
uri = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI();
|
||||
if (uri != null) {
|
||||
this.primaryContainer = this.addContainer(uri);
|
||||
}
|
||||
} catch (URISyntaxException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<String> getPhaseProviderClasses() {
|
||||
Collection<String> phaseProviders = this.primaryContainer.getPhaseProviders();
|
||||
if (phaseProviders != null) {
|
||||
return Collections.<String>unmodifiableCollection(phaseProviders);
|
||||
}
|
||||
|
||||
return Collections.<String>emptyList();
|
||||
}
|
||||
|
||||
public final MixinContainer addContainer(URI uri) {
|
||||
MixinContainer existingContainer = this.containers.get(uri);
|
||||
if (existingContainer != null) {
|
||||
return existingContainer;
|
||||
}
|
||||
|
||||
MixinPlatformManager.logger.debug("Adding mixin platform agents for container {}", uri);
|
||||
MixinContainer container = new MixinContainer(this, uri);
|
||||
this.containers.put(uri, container);
|
||||
|
||||
if (this.prepared) {
|
||||
container.prepare();
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
public final void prepare(List<String> args) {
|
||||
this.prepared = true;
|
||||
for (MixinContainer container : this.containers.values()) {
|
||||
container.prepare();
|
||||
}
|
||||
if (args != null) {
|
||||
this.parseArgs(args);
|
||||
} else {
|
||||
String argv = System.getProperty("sun.java.command");
|
||||
if (argv != null) {
|
||||
this.parseArgs(Arrays.asList(argv.split(" ")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and parse command-line arguments
|
||||
*
|
||||
* @param args command-line arguments
|
||||
*/
|
||||
private void parseArgs(List<String> args) {
|
||||
boolean captureNext = false;
|
||||
for (String arg : args) {
|
||||
if (captureNext) {
|
||||
this.addConfig(arg);
|
||||
}
|
||||
captureNext = "--mixin".equals(arg);
|
||||
}
|
||||
}
|
||||
|
||||
public final void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||
if (this.injected) {
|
||||
return;
|
||||
}
|
||||
this.injected = true;
|
||||
|
||||
if (this.primaryContainer != null) {
|
||||
this.primaryContainer.initPrimaryContainer();
|
||||
}
|
||||
|
||||
this.scanClasspath();
|
||||
MixinPlatformManager.logger.debug("injectIntoClassLoader running with {} agents", this.containers.size());
|
||||
for (MixinContainer container : this.containers.values()) {
|
||||
try {
|
||||
container.injectIntoClassLoader(classLoader);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the classpath for mixin containers (containers which declare the
|
||||
* mixin tweaker in their manifest) and add agents for them
|
||||
*/
|
||||
private void scanClasspath() {
|
||||
for (URL url : Launch.classLoader.getSources()) {
|
||||
try {
|
||||
URI uri = url.toURI();
|
||||
if (this.containers.containsKey(uri)) {
|
||||
continue;
|
||||
}
|
||||
MixinPlatformManager.logger.debug("Scanning {} for mixin tweaker", uri);
|
||||
if (!"file".equals(uri.getScheme()) || !new File(uri).exists()) {
|
||||
continue;
|
||||
}
|
||||
MainAttributes attributes = MainAttributes.of(uri);
|
||||
String tweaker = attributes.get(MixinPlatformManager.MFATT_TWEAKER);
|
||||
if (MixinTweaker.class.getName().equals(tweaker)) {
|
||||
MixinPlatformManager.logger.debug("{} contains a mixin tweaker, adding agents", uri);
|
||||
this.addContainer(uri);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getLaunchTarget() {
|
||||
for (MixinContainer container : this.containers.values()) {
|
||||
String mainClass = container.getLaunchTarget();
|
||||
if (mainClass != null) {
|
||||
return mainClass;
|
||||
}
|
||||
}
|
||||
|
||||
return MixinPlatformManager.DEFAULT_MAIN_CLASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the desired compatibility level as a string, used by agents to set
|
||||
* compatibility level from jar manifest
|
||||
*
|
||||
* @param level compatibility level as a string
|
||||
*/
|
||||
final void setCompatibilityLevel(String level) {
|
||||
try {
|
||||
CompatibilityLevel value = CompatibilityLevel.valueOf(level.toUpperCase());
|
||||
MixinPlatformManager.logger.debug("Setting mixin compatibility level: {}", value);
|
||||
MixinEnvironment.setCompatibilityLevel(value);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
MixinPlatformManager.logger.warn("Invalid compatibility level specified: {}", level);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a config from a jar manifest source or the command line. Supports
|
||||
* config declarations in the form <tt>filename.json</tt> or alternatively
|
||||
* <tt>filename.json@PHASE</tt> where <tt>PHASE</tt> is a
|
||||
* case-sensitive string token representing an environment phase.
|
||||
*
|
||||
* @param config config resource name, does not require a leading /
|
||||
*/
|
||||
final void addConfig(String config) {
|
||||
if (config.endsWith(".json")) {
|
||||
MixinPlatformManager.logger.debug("Registering mixin config: {}", config);
|
||||
Mixins.addConfiguration(config);
|
||||
} else if (config.contains(".json@")) {
|
||||
int pos = config.indexOf(".json@");
|
||||
String phaseName = config.substring(pos + 6);
|
||||
config = config.substring(0, pos + 5);
|
||||
Phase phase = Phase.forName(phaseName);
|
||||
if (phase != null) {
|
||||
MixinPlatformManager.logger.warn("Setting config phase via manifest is deprecated: {}. Specify target in config instead", config);
|
||||
MixinPlatformManager.logger.debug("Registering mixin config: {}", config);
|
||||
MixinEnvironment.getEnvironment(phase).addConfiguration(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a token provider class from a jar manifest source. Supports either
|
||||
* bare class names in the form <tt>blah.package.ClassName</tt> or
|
||||
* alternatively <tt>blah.package.ClassName@PHASE</tt> where
|
||||
* <tt>PHASE</tt> is a case-sensitive string token representing an
|
||||
* environment phase name.
|
||||
*
|
||||
* @param provider provider class name, optionally suffixed with @PHASE
|
||||
*/
|
||||
final void addTokenProvider(String provider) {
|
||||
if (provider.contains("@")) {
|
||||
String[] parts = provider.split("@", 2);
|
||||
Phase phase = Phase.forName(parts[1]);
|
||||
if (phase != null) {
|
||||
MixinPlatformManager.logger.debug("Registering token provider class: {}", parts[0]);
|
||||
MixinEnvironment.getEnvironment(phase).registerTokenProviderClass(parts[0]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
MixinEnvironment.getDefaultEnvironment().registerTokenProviderClass(provider);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -549,6 +549,7 @@ public final class MixinEnvironment implements ITokenProvider {
|
||||
|
||||
@Override
|
||||
public void injectIntoClassLoader(LaunchClassLoader classLoader) {
|
||||
MixinBootstrap.getPlatform().injectIntoClassLoader(classLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,6 +37,11 @@ public class RemapperChain implements IRemapper {
|
||||
|
||||
private final List<IRemapper> remappers = new ArrayList<IRemapper>();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("RemapperChain[%d]", this.remappers.size());
|
||||
}
|
||||
|
||||
public RemapperChain add(IRemapper remapper) {
|
||||
this.remappers.add(remapper);
|
||||
return this;
|
||||
|
||||
@@ -30,6 +30,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
@@ -41,6 +42,15 @@ import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
*/
|
||||
public final class LaunchClassLoaderUtil {
|
||||
|
||||
/**
|
||||
* Class load state
|
||||
*/
|
||||
public enum LoadedType {
|
||||
UNLOADED,
|
||||
LOADED,
|
||||
TRANSFORMED
|
||||
}
|
||||
|
||||
/**
|
||||
* ClassLoader -> util mapping
|
||||
*/
|
||||
@@ -51,6 +61,8 @@ public final class LaunchClassLoaderUtil {
|
||||
*/
|
||||
private final LaunchClassLoader classLoader;
|
||||
|
||||
private final Set<String> parentLoadedClassNames = new HashSet<String>();
|
||||
|
||||
// Reflected fields
|
||||
private Map<String, Class<?>> cachedClasses;
|
||||
private final Set<String> invalidClasses;
|
||||
@@ -109,7 +121,17 @@ public final class LaunchClassLoaderUtil {
|
||||
* @return true if the class name exists in the cache
|
||||
*/
|
||||
public boolean isClassLoaded(String name) {
|
||||
return this.cachedClasses != null && this.cachedClasses.containsKey(name);
|
||||
if (this.cachedClasses != null && this.cachedClasses.containsKey(name)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// if (this.parentLoadedClassNames.contains(name)) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// this.readLoadedClassesFromParent();
|
||||
// return this.parentLoadedClassNames.contains(name);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,6 +185,26 @@ public final class LaunchClassLoaderUtil {
|
||||
return Collections.<String>emptySet();
|
||||
}
|
||||
|
||||
private void readLoadedClassesFromParent() {
|
||||
if (this.classLoader == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClassLoader parent = this.classLoader.getClass().getClassLoader();
|
||||
try {
|
||||
Field fdClasses = ClassLoader.class.getDeclaredField("classes");
|
||||
fdClasses.setAccessible(true);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Vector<Class<?>> classes = (Vector<Class<?>>) fdClasses.get(parent);
|
||||
for (Class<?> c : classes) {
|
||||
this.parentLoadedClassNames.add(c.getName());
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// boo
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T> T getField(LaunchClassLoader classLoader, String fieldName) {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user