From 5f14fbcd67ef85750ac6d27705919795824281dd Mon Sep 17 00:00:00 2001 From: Lassebq Date: Sat, 7 Sep 2024 00:09:15 +0300 Subject: [PATCH] Allow loading of classes in java.* package.. for now --- .../java/org/mcphackers/launchwrapper/Launch.java | 14 +++++++------- .../launchwrapper/loader/LaunchClassLoader.java | 13 ++++++++----- .../org/mcphackers/launchwrapper/tweak/Tweak.java | 5 +++++ 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/mcphackers/launchwrapper/Launch.java b/src/main/java/org/mcphackers/launchwrapper/Launch.java index fac5cc8..43eaae5 100644 --- a/src/main/java/org/mcphackers/launchwrapper/Launch.java +++ b/src/main/java/org/mcphackers/launchwrapper/Launch.java @@ -9,8 +9,7 @@ public class Launch { * Class loader where overwritten classes will be stored */ public static final String VERSION = "1.0"; - @Deprecated - public static final LaunchClassLoader CLASS_LOADER = LaunchClassLoader.instantiate(); + private static final LaunchClassLoader CLASS_LOADER = LaunchClassLoader.instantiate(); static { CLASS_LOADER.addException("org.mcphackers.launchwrapper"); CLASS_LOADER.addException("org.objectweb.asm"); @@ -31,19 +30,20 @@ public static void main(String[] args) { } public void launch() { - CLASS_LOADER.setDebugOutput(new java.io.File(config.gameDir.get(), "debug")); + LaunchClassLoader loader = getLoader(); Tweak mainTweak = getTweak(); if(mainTweak == null) { System.err.println("Could not find launch target"); return; } - if(mainTweak.transform(CLASS_LOADER)) { - mainTweak.transformResources(CLASS_LOADER); + mainTweak.prepare(loader); + if(mainTweak.transform(loader)) { + mainTweak.transformResources(loader); if(config.discordRPC.get()) { setupDiscordRPC(); } - CLASS_LOADER.setLoaderTweak(mainTweak.getLoaderTweak()); - mainTweak.getLaunchTarget().launch(CLASS_LOADER); + loader.setLoaderTweak(mainTweak.getLoaderTweak()); + mainTweak.getLaunchTarget().launch(loader); } else { System.err.println("Tweak could not be applied"); } diff --git a/src/main/java/org/mcphackers/launchwrapper/loader/LaunchClassLoader.java b/src/main/java/org/mcphackers/launchwrapper/loader/LaunchClassLoader.java index be097f4..6958d1b 100644 --- a/src/main/java/org/mcphackers/launchwrapper/loader/LaunchClassLoader.java +++ b/src/main/java/org/mcphackers/launchwrapper/loader/LaunchClassLoader.java @@ -231,9 +231,10 @@ public void saveDebugClass(ClassNode node) { */ // FIXME require name to contain slashes public ClassNode getClass(String name) { - if(classNodeName(name).startsWith("java/")) { - return null; - } + // TODO Breaks SafeClassWriter? + // if(classNodeName(name).startsWith("java/")) { + // return null; + // } ClassNode node = classNodeCache.get(classNodeName(name)); if(node != null) { return node; @@ -317,8 +318,10 @@ private Class transformedClass(String name) throws ClassNotFoundException { ClassNode transformed = overridenClasses.get(name); if(transformed != null) { if(tweak != null) { - tweak.tweakClass(this, classNodeName(name)); - transformed = overridenClasses.get(name); + if(tweak.tweakClass(this, classNodeName(name))) { + transformed = overridenClasses.get(name); + saveDebugClass(transformed); + } } return redefineClass(transformed); } diff --git a/src/main/java/org/mcphackers/launchwrapper/tweak/Tweak.java b/src/main/java/org/mcphackers/launchwrapper/tweak/Tweak.java index f0d0ec1..a96c8a1 100644 --- a/src/main/java/org/mcphackers/launchwrapper/tweak/Tweak.java +++ b/src/main/java/org/mcphackers/launchwrapper/tweak/Tweak.java @@ -6,6 +6,7 @@ import org.mcphackers.launchwrapper.LaunchConfig; import org.mcphackers.launchwrapper.LaunchTarget; +import org.mcphackers.launchwrapper.loader.LaunchClassLoader; import org.mcphackers.launchwrapper.tweak.injection.Injection; import org.mcphackers.launchwrapper.util.ClassNodeSource; import org.mcphackers.launchwrapper.util.ResourceSource; @@ -35,6 +36,10 @@ public Tweak(LaunchConfig config) { public void transformResources(ResourceSource source) { } + + // Any classpath changes required for transformers can be set here + public void prepare(LaunchClassLoader loader) { + } public final boolean transform(ClassNodeSource source) { if(!clean) {