Skip to content

Commit e55f156

Browse files
committed
Fix loading of .class resources to include patched classes
1 parent 1bbc69c commit e55f156

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/main/java/org/mcphackers/launchwrapper/loader/ClassLoaderURLHandler.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package org.mcphackers.launchwrapper.loader;
22

3-
import static org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
4-
import static org.objectweb.asm.ClassWriter.COMPUTE_MAXS;
3+
import static org.objectweb.asm.ClassWriter.*;
54

65
import java.io.ByteArrayInputStream;
7-
import java.io.FileNotFoundException;
86
import java.io.IOException;
97
import java.io.InputStream;
108
import java.net.URL;
@@ -35,13 +33,14 @@ public void connect() throws IOException {
3533
@Override
3634
public InputStream getInputStream() throws IOException {
3735
String path = url.getPath();
38-
byte[] data = classLoader.overridenResources.get(LaunchClassLoader.classNameFromResource(path));
36+
byte[] data = classLoader.overridenResources.get(path);
3937
if (data != null) {
4038
return new ByteArrayInputStream(data);
4139
}
42-
ClassNode node = classLoader.overridenClasses.get(path);
40+
ClassNode node = classLoader.overridenClasses.get(LaunchClassLoader.classNameFromResource(path));
4341
if (node == null) {
44-
throw new FileNotFoundException();
42+
InputStream is = classLoader.getOriginalURL(path).openStream();
43+
return is;
4544
}
4645
ClassWriter writer = new SafeClassWriter(classLoader, COMPUTE_MAXS | COMPUTE_FRAMES);
4746
node.accept(writer);

src/main/java/org/mcphackers/launchwrapper/loader/LaunchClassLoader.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public URL findResource(String resource) {
144144
return getOriginalURL(resource);
145145
}
146146

147-
private URL getOriginalURL(String resource) {
147+
URL getOriginalURL(String resource) {
148148
URL url = urlClassLoader.findResource(resource);
149149
if (url != null) {
150150
return url;
@@ -164,7 +164,7 @@ private URL getOverridenResourceURL(String resource) {
164164
originalUrl.getProtocol(),
165165
originalUrl.getHost(),
166166
originalUrl.getPort(),
167-
originalUrl.getFile(),
167+
resource,
168168
new ClassLoaderURLHandler(this));
169169
}
170170
} catch (MalformedURLException ignored) {
@@ -497,9 +497,9 @@ public static String classResourceName(String name) {
497497

498498
public static String classNameFromResource(String resource) {
499499
if (resource.endsWith(".class")) {
500-
return resource.substring(0, resource.length() - 6);
500+
return resource.substring(0, resource.length() - 6).replace('/', '.');
501501
}
502-
return resource;
502+
return null;
503503
}
504504

505505
public static LaunchClassLoader instantiate() {

0 commit comments

Comments
 (0)