Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ debug_woot = false

# SECTION: custom injected tags

groovy_version = 4.0.21
groovy_version = 4.0.26

# END SECTION: custom injected tags

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public class GroovyScript {

@Mod.EventHandler
public void onConstruction(FMLConstructionEvent event) {
JavaVersionCheck.validateJavaVersion(event.getSide());
if (!SandboxData.isInitialised()) {
LOGGER.throwing(new IllegalStateException("Sandbox data should have been initialised by now, but isn't! Trying to initialize again."));
SandboxData.initialize((File) FMLInjectionData.data()[6], LOGGER);
Expand Down

This file was deleted.

68 changes: 0 additions & 68 deletions src/main/java/com/cleanroommc/groovyscript/JavaVersionCheck.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import com.cleanroommc.groovyscript.GroovyScript;
import com.cleanroommc.groovyscript.sandbox.LoadStage;
import net.minecraftforge.fml.client.CustomModLoadingErrorDisplayException;
import net.minecraftforge.fml.common.LoadController;
import net.minecraftforge.fml.common.LoaderState;
import net.minecraftforge.fml.common.ModContainer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.lang.reflect.InvocationTargetException;

@Mixin(value = LoadController.class, remap = false)
public class LoaderControllerMixin {
Expand All @@ -28,15 +25,4 @@ public void preInit(LoaderState state, Object[] eventData, CallbackInfo ci) {
GroovyScript.runGroovyScriptsInLoader(LoadStage.POST_INIT);
}
}

@Inject(method = "errorOccurred", at = @At(value = "NEW", target = "(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)Lorg/apache/logging/log4j/message/FormattedMessage;", shift = At.Shift.BEFORE))
public void errorOccured(ModContainer modContainer, Throwable exception, CallbackInfo ci) throws Throwable {
if (exception instanceof InvocationTargetException) {
exception = exception.getCause();
}
if (exception instanceof CustomModLoadingErrorDisplayException) {
// normally every exception gets wrapped in a LoaderException making these """custom""" exceptions useless, thanks cpw
throw exception;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,76 +1,20 @@
package com.cleanroommc.groovyscript.core.mixin.groovy;

import com.cleanroommc.groovyscript.sandbox.transformer.AsmDecompileHelper;
import groovy.lang.GroovyRuntimeException;
import org.codehaus.groovy.ast.decompiled.AsmDecompiler;
import org.codehaus.groovy.ast.decompiled.ClassStub;
import org.codehaus.groovy.util.URLStreams;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.SoftReference;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;

@Mixin(value = AsmDecompiler.class, remap = false)
public class AsmDecompilerMixin {

@Shadow
@Final
private static Map<URI, SoftReference<ClassStub>> stubCache;

@Inject(method = "parseClass", at = @At("HEAD"), cancellable = true)
@Inject(method = "parseClass", at = @At("HEAD"))
private static void parseClass(URL url, CallbackInfoReturnable<ClassStub> cir) {
URI uri;
try {
uri = url.toURI();
} catch (URISyntaxException e) {
throw new GroovyRuntimeException(e);
}

SoftReference<ClassStub> ref = stubCache.get(uri);
ClassStub stub = (ref != null ? ref.get() : null);
if (stub == null) {
try (InputStream stream = new BufferedInputStream(URLStreams.openUncachedStream(url))) {
ClassReader classReader = new ClassReader(stream);
ClassNode classNode = new ClassNode();
classReader.accept(classNode, 0);
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
byte[] bytes = writer.toByteArray();
if (!AsmDecompileHelper.remove(classNode.visibleAnnotations, AsmDecompileHelper.SIDE)) {
bytes = AsmDecompileHelper.transform(classNode.name, bytes);
}

// now decompile the class normally
groovyjarjarasm.asm.ClassReader classReader2 = new groovyjarjarasm.asm.ClassReader(bytes);
groovyjarjarasm.asm.ClassVisitor decompiler = AsmDecompileHelper.makeGroovyDecompiler();
classReader2.accept(decompiler, ClassReader.SKIP_FRAMES);
stub = AsmDecompileHelper.getDecompiledClass(decompiler);
stubCache.put(uri, new SoftReference<>(stub));
} catch (IOException |
ClassNotFoundException |
NoSuchFieldException |
NoSuchMethodException |
IllegalAccessException |
InvocationTargetException |
InstantiationException e) {
throw new RuntimeException(e);
}
}
cir.setReturnValue(stub);
// redirected in ClassNodeResolverMixin
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.cleanroommc.groovyscript.core.mixin.groovy;

import com.cleanroommc.groovyscript.sandbox.transformer.AsmDecompileHelper;
import groovy.lang.GroovyClassLoader;
import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.decompiled.AsmReferenceResolver;
import org.codehaus.groovy.ast.decompiled.ClassStub;
import org.codehaus.groovy.ast.decompiled.DecompiledClassNode;
import org.codehaus.groovy.control.ClassNodeResolver;
import org.codehaus.groovy.control.CompilationUnit;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;

@Mixin(value = ClassNodeResolver.class, remap = false)
public abstract class ClassNodeResolverMixin {

@Shadow
private static boolean isFromAnotherClassLoader(GroovyClassLoader loader, String fileName) {
return false;
}

@Shadow
private static ClassNodeResolver.LookupResult tryAsScript(String name, CompilationUnit compilationUnit, ClassNode oldClass) {
return null;
}

/**
* @author brachy
* @reason properly find classes
*/
@Overwrite
private ClassNodeResolver.LookupResult findDecompiled(final String name, final CompilationUnit compilationUnit, final GroovyClassLoader loader) {
ClassNode node = ClassHelper.make(name);
if (node.isResolved()) {
return new ClassNodeResolver.LookupResult(null, node);
}

DecompiledClassNode asmClass = null;
ClassStub stub = AsmDecompileHelper.findDecompiledClass(name);
if (stub != null) {
asmClass = new DecompiledClassNode(stub, new AsmReferenceResolver((ClassNodeResolver) (Object) this, compilationUnit));
if (!asmClass.getName().equals(name)) {
// this may happen under Windows because getResource is case-insensitive under that OS!
asmClass = null;
}
}

if (asmClass != null) {
String fileName = name.replace('.', '/') + ".class";
if (isFromAnotherClassLoader(loader, fileName)) {
return tryAsScript(name, compilationUnit, asmClass);
}

return new ClassNodeResolver.LookupResult(null, asmClass);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@ public Class<?> loadClass(final String name, boolean lookupScriptFiles, boolean
cls = recompile(source, name);
} catch (IOException ioe) {
last = new ClassNotFoundException("IOException while opening groovy source: " + name, ioe);
} finally {
if (cls == null) {
removeClassCacheEntry(name);
} else {
setClassCacheEntry(cls);
}
}
}

Expand Down
Loading