Skip to content

Commit

Permalink
Allow overriding CodeSource for classloader exclusions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lassebq committed Nov 3, 2024
1 parent ad10c34 commit bd974ef
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions launchwrapper-fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ compileJava {

dependencies {
implementation "net.fabricmc:fabric-loader:0.16.4"
runtimeOnly "net.fabricmc:sponge-mixin:0.15.4+mixin.0.8.7"
runtimeOnly "org.ow2.asm:asm-commons:9.7"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ private static String gameProdiverSource() {
if (resource == null) {
return null;
}
Launch.LOGGER.logDebug("Fabric compat jar: " + resource.getLocation().getPath());
return resource.getLocation().getPath();
}

Expand All @@ -34,6 +33,7 @@ public static void main(String[] args) {

public void launch() {
LaunchClassLoader loader = getLoader();
System.setProperty("fabric.skipMcProvider", "true");
loader.overrideClassSource(FABRIC_KNOT, gameProdiverSource());
loader.overrideClassSource(FABRIC_KNOT_CLIENT, gameProdiverSource());
loader.invokeMain(FABRIC_KNOT_CLIENT.replace('/', '.'), config.getArgs());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.mcphackers.launchwrapper.target.MainLaunchTarget;
import org.mcphackers.launchwrapper.tweak.Tweak;
import org.mcphackers.launchwrapper.util.ClassNodeSource;
import org.objectweb.asm.ClassReader;
import org.mcphackers.launchwrapper.util.asm.NodeHelper;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;

Expand Down Expand Up @@ -55,14 +55,13 @@ public void locateEntrypoints(FabricLauncher launcher, List<Path> gameJars) {

try {
CpEntry entry = cp.getEntry(LoaderUtil.getClassFileName(name));
if (entry == null)
return null;
if (entry == null) {
// SafeClassWriter needs access to whole classpath
return NodeHelper.readClass(launcher.getResourceAsStream(LoaderUtil.getClassFileName(name)), 0);
}

try (InputStream is = entry.getInputStream()) {
node = new ClassNode();
ClassReader reader = new ClassReader(is);
reader.accept(node, 0);
return node;
return NodeHelper.readClass(is, 0);
} catch (IOException | ZipError e) {
throw new RuntimeException(String.format("error reading %s in %s: %s", name, LoaderUtil.normalizePath(entry.getOrigin()), e), e);
}
Expand All @@ -79,7 +78,7 @@ public void locateEntrypoints(FabricLauncher launcher, List<Path> gameJars) {
throw ExceptionUtil.wrap(e);
}

Log.debug(LogCategory.GAME_PATCH, "Patched %d class%s", modified.size(), modified.size() != 1 ? "s" : "");
Log.debug(LogCategory.GAME_PATCH, "Patched %d class%s", modified.size(), modified.size() != 1 ? "es" : "");
entrypointsLocated = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,16 @@ public Enumeration<URL> findResources(String name) throws IOException {
}

public void addExclusion(String pkg) {
if (pkg == null) {
return;
}
exclusions.add(pkg + (pkg.endsWith(".") ? "" : "."));
}

public void overrideClassSource(String name, String f) {
if (f == null) {
return;
}
overridenSource.put(className(name), f);
}

Expand All @@ -184,7 +190,7 @@ public Class<?> findClass(String name) throws ClassNotFoundException {
assert name.contains(".");

// Force wrap inject package
if (name.startsWith("org.mcphackers.launchwrapper.inject.")) {
if (overridenSource.containsKey(name) || name.startsWith("org.mcphackers.launchwrapper.inject.")) {
return redefineClass(name);
}

Expand Down Expand Up @@ -371,7 +377,7 @@ private ProtectionDomain getProtectionDomain(String name) {
path = path.substring(0, i);
}
}
if (overridenSource.get(name) != null) {
if (overridenSource.containsKey(name)) {
path = overridenSource.get(name);
}
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.objectweb.asm.tree.MethodNode;

/**
* This patch makes it so game window stays fullscreen, even if you change focus via alt-tab
* Part of LWJGLPatch, but for 1.6+ without need for deAWT
*/
public class OutOfFocusFullscreen extends InjectionWithContext<MinecraftGetter> {
Expand Down

0 comments on commit bd974ef

Please sign in to comment.