Skip to content

Commit

Permalink
Allow loading of classes in java.* package.. for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Lassebq committed Sep 6, 2024
1 parent d6ec7e0 commit 5f14fbc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/mcphackers/launchwrapper/Launch.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/mcphackers/launchwrapper/tweak/Tweak.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 5f14fbc

Please sign in to comment.