mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-19 16:29:45 +00:00
Update hotswapper agent for 0.8
This commit is contained in:
1 parent
7b37a681ee
commit
da74418eca
7 files changed
+79
-46
No files matched your search
+8
-4
@@ -518,10 +518,14 @@ class MixinPreProcessorStandard {
|
||||
String type = method.isSynthetic() ? "synthetic" : "@Unique";
|
||||
|
||||
if (Bytecode.getVisibility(mixinMethod).ordinal() < Visibility.PUBLIC.ordinal()) {
|
||||
String uniqueName = context.getUniqueName(mixinMethod, false);
|
||||
MixinPreProcessorStandard.logger.log(this.mixin.getLoggingLevel(), "Renaming {} method {}{} to {} in {}",
|
||||
type, mixinMethod.name, mixinMethod.desc, uniqueName, this.mixin);
|
||||
mixinMethod.name = method.conform(uniqueName);
|
||||
if (method.isConformed()) {
|
||||
mixinMethod.name = method.getName();
|
||||
} else {
|
||||
String uniqueName = context.getUniqueName(mixinMethod, false);
|
||||
MixinPreProcessorStandard.logger.log(this.mixin.getLoggingLevel(), "Renaming {} method {}{} to {} in {}",
|
||||
type, mixinMethod.name, mixinMethod.desc, uniqueName, this.mixin);
|
||||
mixinMethod.name = method.conform(uniqueName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
|
||||
@@ -132,8 +131,6 @@ public class MixinProcessor {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final String MIXIN_AGENT_CLASS = "org.spongepowered.tools.agent.MixinAgent";
|
||||
|
||||
/**
|
||||
* Log all the things
|
||||
@@ -210,36 +207,16 @@ public class MixinProcessor {
|
||||
/**
|
||||
* ctor
|
||||
*/
|
||||
MixinProcessor(MixinEnvironment environment, Extensions extensions) {
|
||||
MixinProcessor(MixinEnvironment environment, Extensions extensions, IHotSwap hotSwapper) {
|
||||
this.lock = this.service.getReEntranceLock();
|
||||
|
||||
this.extensions = extensions;
|
||||
this.hotSwapper = this.initHotSwapper(environment);
|
||||
this.hotSwapper = hotSwapper;
|
||||
this.postProcessor = new MixinPostProcessor(this.sessionId);
|
||||
|
||||
this.profiler = MixinEnvironment.getProfiler();
|
||||
}
|
||||
|
||||
private IHotSwap initHotSwapper(MixinEnvironment environment) {
|
||||
if (!environment.getOption(Option.HOT_SWAP)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
MixinProcessor.logger.info("Attempting to load Hot-Swap agent");
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends IHotSwap> clazz =
|
||||
(Class<? extends IHotSwap>)Class.forName(MixinProcessor.MIXIN_AGENT_CLASS);
|
||||
Constructor<? extends IHotSwap> ctor = clazz.getDeclaredConstructor(MixinProcessor.class);
|
||||
return ctor.newInstance(this);
|
||||
} catch (Throwable th) {
|
||||
MixinProcessor.logger.info("Hot-swap agent could not be loaded, hot swapping of mixins won't work. {}: {}",
|
||||
th.getClass().getSimpleName(), th.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force-load all classes targetted by mixins but not yet applied
|
||||
*
|
||||
@@ -345,8 +322,7 @@ public class MixinProcessor {
|
||||
}
|
||||
|
||||
if (this.hotSwapper != null) {
|
||||
// TODO hotswapper
|
||||
// this.hotSwapper.registerTargetClass(transformedName, basicClass);
|
||||
this.hotSwapper.registerTargetClass(name, targetClassNode);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -24,13 +24,16 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.List;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment;
|
||||
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
|
||||
import org.spongepowered.asm.mixin.throwables.MixinException;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.Extensions;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IExtensionRegistry;
|
||||
import org.spongepowered.asm.mixin.transformer.ext.IHotSwap;
|
||||
import org.spongepowered.asm.transformers.TreeTransformer;
|
||||
import org.spongepowered.asm.util.Constants;
|
||||
import org.spongepowered.asm.util.asm.ASM;
|
||||
@@ -40,10 +43,22 @@ import org.spongepowered.asm.util.asm.ASM;
|
||||
*/
|
||||
class MixinTransformer extends TreeTransformer implements IMixinTransformer {
|
||||
|
||||
private static final String MIXIN_AGENT_CLASS = "org.spongepowered.tools.agent.MixinAgent";
|
||||
|
||||
/**
|
||||
* Synthetic class registry
|
||||
*/
|
||||
private final SyntheticClassRegistry syntheticClassRegistry;
|
||||
|
||||
/**
|
||||
* Transformer extensions
|
||||
*/
|
||||
private final Extensions extensions;
|
||||
|
||||
/**
|
||||
* Hotswap agent, if available
|
||||
*/
|
||||
private final IHotSwap hotSwapper;
|
||||
|
||||
/**
|
||||
* Mixin processor which actually manages application of mixins
|
||||
@@ -55,11 +70,6 @@ class MixinTransformer extends TreeTransformer implements IMixinTransformer {
|
||||
*/
|
||||
private final MixinClassGenerator generator;
|
||||
|
||||
/**
|
||||
* Synthetic class registry
|
||||
*/
|
||||
private final SyntheticClassRegistry syntheticClassRegistry;
|
||||
|
||||
public MixinTransformer() {
|
||||
MixinEnvironment environment = MixinEnvironment.getCurrentEnvironment();
|
||||
|
||||
@@ -73,13 +83,35 @@ class MixinTransformer extends TreeTransformer implements IMixinTransformer {
|
||||
|
||||
this.syntheticClassRegistry = new SyntheticClassRegistry();
|
||||
this.extensions = new Extensions(this.syntheticClassRegistry);
|
||||
|
||||
this.hotSwapper = this.initHotSwapper(environment);
|
||||
|
||||
this.processor = new MixinProcessor(environment, this.extensions);
|
||||
this.processor = new MixinProcessor(environment, this.extensions, this.hotSwapper);
|
||||
this.generator = new MixinClassGenerator(environment, this.extensions);
|
||||
|
||||
DefaultExtensions.create(environment, this.extensions, this.syntheticClassRegistry);
|
||||
}
|
||||
|
||||
private IHotSwap initHotSwapper(MixinEnvironment environment) {
|
||||
if (!environment.getOption(Option.HOT_SWAP)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
MixinProcessor.logger.info("Attempting to load Hot-Swap agent");
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends IHotSwap> clazz =
|
||||
(Class<? extends IHotSwap>)Class.forName(MixinTransformer.MIXIN_AGENT_CLASS);
|
||||
Constructor<? extends IHotSwap> ctor = clazz.getDeclaredConstructor(IMixinTransformer.class);
|
||||
return ctor.newInstance(this);
|
||||
} catch (Throwable th) {
|
||||
MixinProcessor.logger.info("Hot-swap agent could not be loaded, hot swapping of mixins won't work. {}: {}",
|
||||
th.getClass().getSimpleName(), th.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.spongepowered.asm.mixin.transformer.IMixinTransformer
|
||||
* #getExtensions()
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
*/
|
||||
package org.spongepowered.asm.mixin.transformer.ext;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
/**
|
||||
* Interface to allow the hot-swap agent to be loaded on-demand
|
||||
*/
|
||||
@@ -42,11 +44,11 @@ public interface IHotSwap {
|
||||
* Registers a class targeted by at least one mixin.
|
||||
*
|
||||
* <p>This is used to rollback the target class to a state before the
|
||||
* mixin's were applied.</p>
|
||||
* mixins were applied.</p>
|
||||
*
|
||||
* @param name Name of the class
|
||||
* @param bytecode Bytecode of the class before mixin's have been applied
|
||||
* @param classNode ASM tree of the class before mixins have been applied
|
||||
*/
|
||||
public abstract void registerTargetClass(String name, byte[] bytecode);
|
||||
public abstract void registerTargetClass(String name, ClassNode classNode);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user