Skip to content

Commit

Permalink
Merge pull request #141 from LlamaLad7/merge/0.8.6
Browse files Browse the repository at this point in the history
Merge/0.8.6
  • Loading branch information
modmuss50 authored Jun 2, 2024
2 parents 2f35deb + 8d413b8 commit 02f8479
Show file tree
Hide file tree
Showing 93 changed files with 3,277 additions and 1,017 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ repositories {
}
maven {
// For modlauncher
name = 'forge'
url = 'https://files.minecraftforge.net/maven'
name = 'neoforged'
url = 'https://maven.neoforged.net/releases'
}
}

Expand Down Expand Up @@ -226,7 +226,7 @@ dependencies {
modlauncher9Implementation ("cpw.mods:modlauncher:$modlauncherVersion") {
exclude module: 'jopt-simple'
}
modlauncher9Implementation 'cpw.mods:securejarhandler:0.9.+'
modlauncher9Implementation 'cpw.mods:securejarhandler:2.1.24'

// asm bridge
bridgeImplementation 'org.apache.logging.log4j:log4j-core:2.0-beta9'
Expand All @@ -243,7 +243,8 @@ javadoc {
source sourceSets.ap.allJava
options.encoding = 'UTF-8'
exclude {
it.relativePath.file && it.relativePath.pathString =~ 'tools' && !(it.name =~ /SuppressedBy|package-info/) }
it.relativePath.file && it.relativePath.pathString =~ 'tools' && !(it.name =~ /SuppressedBy|package-info/)
}
options {
docTitle 'Welcome to the Mixin Javadoc'
overview 'docs/javadoc/overview.html'
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ packaging=jar
description=Mixin (Fabric fork)
url=https://fabricmc.net
organization=FabricMC
buildVersion=0.13.4
upstreamMixinVersion=0.8.5
buildVersion=0.14.0
upstreamMixinVersion=0.8.6
buildType=RELEASE
asmVersion=9.6
legacyForgeAsmVersion=5.0.3
modlauncherAsmVersion=9.1
modlauncherVersion=9.0.7
modlauncherAsmVersion=9.5
modlauncherVersion=10.0.9
legacyModlauncherVersion=7.0.0
38 changes: 26 additions & 12 deletions src/agent/java/org/spongepowered/tools/agent/MixinAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
import java.util.ArrayList;
import java.util.List;

import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.logging.Level;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.transformer.IMixinTransformer;
import org.spongepowered.asm.mixin.transformer.ext.IHotSwap;
import org.spongepowered.asm.mixin.transformer.throwables.MixinReloadException;
import org.spongepowered.asm.service.IMixinService;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.service.ServiceNotAvailableError;
import org.spongepowered.asm.transformers.MixinClassReader;
import org.spongepowered.asm.util.asm.ASM;

Expand Down Expand Up @@ -76,23 +77,23 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
}

try {
MixinAgent.logger.info("Redefining class {}", className);
MixinAgent.log(Level.INFO, "Redefining class {}", className);
return MixinAgent.this.classTransformer.transformClassBytes(null, className, classfileBuffer);
} catch (Throwable th) {
MixinAgent.logger.error("Error while re-transforming class {}", className, th);
MixinAgent.log(Level.ERROR, "Error while re-transforming class {}", className, th);
return MixinAgent.ERROR_BYTECODE;
}
}

private List<String> reloadMixin(String className, ClassNode classNode) {
MixinAgent.logger.info("Redefining mixin {}", className);
MixinAgent.log(Level.INFO, "Redefining mixin {}", className);
try {
return MixinAgent.this.classTransformer.reload(className.replace('/', '.'), classNode);
} catch (MixinReloadException e) {
MixinAgent.logger.error("Mixin {} cannot be reloaded, needs a restart to be applied: {} ", e.getMixinInfo(), e.getMessage());
MixinAgent.log(Level.ERROR, "Mixin {} cannot be reloaded, needs a restart to be applied: {} ", e.getMixinInfo(), e.getMessage());
} catch (Throwable th) {
// catch everything as otherwise it is ignored
MixinAgent.logger.error("Error while finding targets for mixin {}", className, th);
MixinAgent.log(Level.ERROR, "Error while finding targets for mixin {}", className, th);
}
return null;
}
Expand All @@ -109,18 +110,18 @@ private boolean reApplyMixins(List<String> targets) {

for (String target : targets) {
String targetName = target.replace('/', '.');
MixinAgent.logger.debug("Re-transforming target class {}", target);
MixinAgent.log(Level.DEBUG, "Re-transforming target class {}", target);
try {
Class<?> targetClass = service.getClassProvider().findClass(targetName);
byte[] targetBytecode = MixinAgent.classLoader.getOriginalTargetBytecode(targetName);
if (targetBytecode == null) {
MixinAgent.logger.error("Target class {} bytecode is not registered", targetName);
MixinAgent.log(Level.ERROR, "Target class {} bytecode is not registered", targetName);
return false;
}
targetBytecode = MixinAgent.this.classTransformer.transformClassBytes(null, targetName, targetBytecode);
MixinAgent.instrumentation.redefineClasses(new ClassDefinition(targetClass, targetBytecode));
} catch (Throwable th) {
MixinAgent.logger.error("Error while re-transforming target class {}", target, th);
MixinAgent.log(Level.ERROR, "Error while re-transforming target class {}", target, th);
return false;
}
}
Expand All @@ -140,8 +141,6 @@ private boolean reApplyMixins(List<String> targets) {
*/
static final MixinAgentClassLoader classLoader = new MixinAgentClassLoader();

static final ILogger logger = MixinService.getService().getLogger("mixin.agent");

/**
* Instance used to register the transformer
*/
Expand Down Expand Up @@ -195,7 +194,7 @@ public void registerTargetClass(String name, ClassNode classNode) {
public static void init(Instrumentation instrumentation) {
MixinAgent.instrumentation = instrumentation;
if (!MixinAgent.instrumentation.isRedefineClassesSupported()) {
MixinAgent.logger.error("The instrumentation doesn't support re-definition of classes");
MixinAgent.log(Level.ERROR, "The instrumentation doesn't support re-definition of classes");
}
for (MixinAgent agent : MixinAgent.agents) {
agent.initTransformer();
Expand Down Expand Up @@ -229,4 +228,19 @@ public static void agentmain(String arg, Instrumentation instrumentation) {
MixinAgent.init(instrumentation);
}

/**
* Wrapper for logger since we can't access the log abstraction in premain
*
* @param level the logging level
* @param message the message to log
* @param params parameters to the message
*/
public static void log(Level level, String message, Object... params) {
try {
MixinService.getService().getLogger("mixin.agent").log(level, message, params);
} catch (ServiceNotAvailableError err) {
System.err.printf("MixinAgent: %s: %s", level.name(), String.format(message, params));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
import java.util.HashMap;
import java.util.Map;

import org.spongepowered.asm.logging.ILogger;
import org.spongepowered.asm.logging.Level;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.MixinEnvironment;
import org.spongepowered.asm.service.MixinService;
import org.spongepowered.asm.service.ServiceNotAvailableError;
import org.spongepowered.asm.util.Constants;

/**
Expand All @@ -43,8 +44,6 @@
*/
class MixinAgentClassLoader extends ClassLoader {

private static final ILogger logger = MixinService.getService().getLogger("mixin.agent");

/**
* Mapping of mixin mixin classes to their fake classes
*/
Expand All @@ -62,7 +61,7 @@ class MixinAgentClassLoader extends ClassLoader {
* @param name Name of the fake class
*/
void addMixinClass(String name) {
MixinAgentClassLoader.logger.debug("Mixin class {} added to class loader", name);
MixinAgentClassLoader.log(Level.DEBUG, "Mixin class {} added to class loader", name);
try {
byte[] bytes = this.materialise(name);
Class<?> clazz = this.defineClass(name, bytes, 0, bytes.length);
Expand All @@ -71,7 +70,7 @@ void addMixinClass(String name) {
clazz.getDeclaredConstructor().newInstance();
this.mixins.put(clazz, bytes);
} catch (Throwable e) {
MixinAgentClassLoader.logger.catching(e);
MixinAgentClassLoader.log(Level.ERROR, "Catching {}", e);
}
}

Expand All @@ -91,9 +90,9 @@ void addTargetClass(String name, ClassNode classNode) {
classNode.accept(cw);
this.targets.put(name, cw.toByteArray());
} catch (Exception ex) {
MixinAgentClassLoader.logger.error("Error storing original class bytecode for {} in mixin hotswap agent. {}: {}",
MixinAgentClassLoader.log(Level.ERROR, "Error storing original class bytecode for {} in mixin hotswap agent. {}: {}",
name, ex.getClass().getName(), ex.getMessage());
MixinAgentClassLoader.logger.debug(ex.toString());
MixinAgentClassLoader.log(Level.DEBUG, ex.toString());
}
}
}
Expand Down Expand Up @@ -144,4 +143,19 @@ private byte[] materialise(String name) {
return cw.toByteArray();
}

/**
* Wrapper for logger since we can't access the log abstraction in premain
*
* @param level the logging level
* @param message the message to log
* @param params parameters to the message
*/
public static void log(Level level, String message, Object... params) {
try {
MixinService.getService().getLogger("mixin.agent").log(level, message, params);
} catch (ServiceNotAvailableError err) {
System.err.printf("MixinAgent: %s: %s", level.name(), String.format(message, params));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ public ReferenceMapper getReferenceMapper() {
public String getClassName() {
return this.getClassRef().replace('/', '.');
}

@Override
public String getTargetClassName() {
return this.primaryTarget.toString();
}

@Override
public String getTargetClassRef() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public String remap(String reference) {
return reference;
}

@Override
public String getElementDescription() {
return String.format("%s annotation on %s", this.getAnnotation(), this);
}

@Override
public String toString() {
return TypeUtils.getName(this.element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public String toString() {
static class AnnotatedElementInvoker extends AnnotatedElementAccessor {

private AccessorType type = AccessorType.METHOD_PROXY;

public AnnotatedElementInvoker(ExecutableElement element, AnnotationHandle annotation, IMixinContext context, boolean shouldRemap) {
super(element, annotation, context, shouldRemap);
}
Expand All @@ -165,16 +165,24 @@ public void attach(TypeHandle target) {

for (String prefix : AccessorType.OBJECT_FACTORY.getExpectedPrefixes()) {
if (prefix.equals(accessorName.prefix)
&& (Constants.CTOR.equals(accessorName.name) || target.getSimpleName().equals(accessorName.name))) {
&& (Constants.CTOR.equals(accessorName.name) || target.getSimpleName().equalsIgnoreCase(accessorName.name))) {
this.type = AccessorType.OBJECT_FACTORY;
return;
}
}
}

@Override
public String getAnnotationValue() {
String value = super.getAnnotationValue();
return (this.type == AccessorType.OBJECT_FACTORY && value == null) ? this.returnType.toString() : value;
}

@Override
public boolean shouldRemap() {
return (this.type == AccessorType.METHOD_PROXY || this.getAnnotationValue() != null) && super.shouldRemap();
return (this.type == AccessorType.OBJECT_FACTORY
|| this.type == AccessorType.METHOD_PROXY
|| this.getAnnotationValue() != null) && super.shouldRemap();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ private boolean registerInjector(AnnotatedElementInjector elem, String reference
}
}

IReferenceManager refMap = this.obf.getReferenceManager();
IReferenceManager refMaps = this.obf.getReferenceManager();
try {
// If the original owner is unspecified, and the mixin is multi-target, we strip the owner from the obf mappings
if ((targetMember.getOwner() == null && this.mixin.isMultiTarget()) || target.isSimulated()) {
obfData = AnnotatedMixinElementHandler.<MappingMethod>stripOwnerData(obfData);
}
refMap.addMethodMapping(this.classRef, reference, obfData);
refMaps.addMethodMapping(this.classRef, reference, obfData);
} catch (ReferenceConflictException ex) {
String conflictType = this.mixin.isMultiTarget() ? "Multi-target" : "Target";

Expand All @@ -270,9 +270,9 @@ private boolean registerInjector(AnnotatedElementInjector elem, String reference
String newName = newMember instanceof ITargetSelectorByName ? ((ITargetSelectorByName)newMember).getName() : newMember.toString();
if (oldName != null && oldName.equals(newName)) {
obfData = AnnotatedMixinElementHandler.<MappingMethod>stripDescriptors(obfData);
refMap.setAllowConflicts(true);
refMap.addMethodMapping(this.classRef, reference, obfData);
refMap.setAllowConflicts(false);
refMaps.setAllowConflicts(true);
refMaps.addMethodMapping(this.classRef, reference, obfData);
refMaps.setAllowConflicts(false);

// This is bad because in notch mappings, using the bare target name might cause everything to explode
elem.printMessage(this.ap, MessageType.BARE_REFERENCE, "Coerced " + conflictType + " reference has conflicting descriptors for "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@

import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic.Kind;

import org.spongepowered.asm.mixin.injection.selectors.ITargetSelectorRemappable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class SupportedOptions {
public static final String PLUGIN_VERSION = "pluginVersion";
public static final String QUIET = "quiet";
public static final String SHOW_MESSAGE_TYPES = "showMessageTypes";
public static final String DISABLE_INTERFACE_MIXINS = "disableInterfaceMixins";

private SupportedOptions() {}

Expand All @@ -70,7 +71,8 @@ public static Set<String> getAllOptions() {
SupportedOptions.MAPPING_TYPES,
SupportedOptions.PLUGIN_VERSION,
SupportedOptions.QUIET,
SupportedOptions.SHOW_MESSAGE_TYPES
SupportedOptions.SHOW_MESSAGE_TYPES,
SupportedOptions.DISABLE_INTERFACE_MIXINS
);
options.addAll(
ObfuscationServices.getInstance().getSupportedOptions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import java.util.List;
import java.util.Set;

import javax.lang.model.element.TypeElement;

import org.spongepowered.tools.obfuscation.mirror.TypeHandle;
import org.spongepowered.tools.obfuscation.mirror.TypeReference;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ public static void applyOptions(CompilerEnvironment env, IOptionProvider options
// Apply the "quiet" option if specified, or if in dev env
MessageType.INFO.setEnabled(!(env.isDevelopmentEnvironment() || "true".equalsIgnoreCase(options.getOption(SupportedOptions.QUIET))));

// Selectively enable injector-in-interface as an error based on user option
MessageType.INJECTOR_IN_INTERFACE.setEnabled(options.getOption(SupportedOptions.DISABLE_INTERFACE_MIXINS, false));

// Legacy option
if ("error".equalsIgnoreCase(options.getOption(SupportedOptions.OVERWRITE_ERROR_LEVEL))) {
MessageType.OVERWRITE_DOCS.setKind(Kind.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class TypeHandle {
* for related classes (eg. superclass) without using mirror
*/
protected final ITypeHandleProvider typeProvider;

/**
* Reference to this handle, for serialisation
*/
Expand Down Expand Up @@ -295,6 +295,8 @@ public boolean isNotInterface() {

/**
* Gets whether this handle is a supertype of the other handle
*
* @param other the TypeHandle to compare with
*/
public boolean isSuperTypeOf(TypeHandle other) {
List<TypeHandle> superTypes = new ArrayList<>();
Expand All @@ -309,7 +311,7 @@ public boolean isSuperTypeOf(TypeHandle other) {
}
return false;
}

/**
* Get the TypeReference for this type, used for serialisation
*/
Expand Down
Loading

0 comments on commit 02f8479

Please sign in to comment.