Skip to content

Commit eb9dc73

Browse files
committed
Update 1.2.32
1 parent 223e02b commit eb9dc73

File tree

4 files changed

+117
-17
lines changed

4 files changed

+117
-17
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/*/build
99
/run
1010
/run2
11+
/crash-reports
1112

1213
/.project
1314
/.classpath

common/src/main/java/com/fox2code/foxloader/launcher/FoxClassLoader.java

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fox2code.foxloader.launcher;
22

3+
import com.fox2code.foxloader.launcher.utils.Enumerations;
4+
35
import java.io.ByteArrayOutputStream;
46
import java.io.File;
57
import java.io.IOException;
@@ -24,6 +26,7 @@ public final class FoxClassLoader extends URLClassLoader {
2426
private ArrayList<URL> coreMods;
2527
private boolean didPrintedTransformFail = false;
2628
private boolean patchedExclusiveSource = false;
29+
private URL minecraftURL;
2730
static URL earlyMinecraftURL;
2831

2932
FoxClassLoader() {
@@ -146,7 +149,7 @@ private Class<?> findClassImpl(String name, URL resource) throws ClassNotFoundEx
146149
throw new ClassTransformException("Can't compute frames for "+name, e);
147150
}
148151
} else switch (name) {
149-
// We need to apply some patches to mixins to make the actually work.
152+
// We need to apply some patches to mixins to make them actually work.
150153
case MIXIN_CONFIG:
151154
if (wrappedExtensions == null)
152155
throw new ClassTransformException("wrappedExtensions not initialized yet");
@@ -208,6 +211,26 @@ public URL getResource(String name) {
208211
return this.getParent().getResource(name);
209212
}
210213

214+
@Override
215+
public URL findResource(String name) {
216+
if (isGamePath(name)) {
217+
if (gameExclusiveSource != null) {
218+
return gameExclusiveSource.findResource(name);
219+
} else {
220+
return this.getParent().getResource(name);
221+
}
222+
}
223+
return super.findResource(name);
224+
}
225+
226+
@Override
227+
public Enumeration<URL> findResources(String name) throws IOException {
228+
if (isGamePath(name)) {
229+
return Enumerations.optional(this.findResource(name));
230+
}
231+
return super.findResources(name);
232+
}
233+
211234
public boolean isClassLoaded(String className) {
212235
return this.findLoadedClass(className) != null;
213236
}
@@ -263,17 +286,25 @@ public void addCoreModURL(URL url) {
263286
}
264287

265288
public void setMinecraftURL(URL url) {
266-
if (allowLoadingGame)
289+
if (this.allowLoadingGame)
267290
throw new IllegalStateException("Minecraft jar already loaded!");
268-
gameExclusiveSource = new URLClassLoader(makeURLClassPathForSource(url), null);
269-
patchedExclusiveSource = false;
291+
this.gameExclusiveSource = new URLClassLoader(makeURLClassPathForSource(url), null);
292+
this.patchedExclusiveSource = false;
293+
this.minecraftURL = url;
270294
}
271295

272296
public void setPatchedMinecraftURL(URL url) {
273-
if (allowLoadingGame)
297+
if (this.allowLoadingGame)
274298
throw new IllegalStateException("Minecraft jar already loaded!");
275-
gameExclusiveSource = new URLClassLoader(new URL[]{url}, null);
276-
patchedExclusiveSource = true;
299+
URL minecraftURL;
300+
try {
301+
minecraftURL = this.getOriginalMinecraftSource();
302+
} catch (IOException e) {
303+
throw new IllegalStateException("Original Minecraft jar not set", e);
304+
}
305+
this.gameExclusiveSource = new URLClassLoader(new URL[]{url, minecraftURL}, null);
306+
this.patchedExclusiveSource = true;
307+
this.minecraftURL = minecraftURL;
277308
}
278309

279310
public URL[] makeURLClassPathForSource(URL source) {
@@ -290,7 +321,7 @@ public void allowLoadingGame() {
290321
if (coreMods != null) {
291322
try {
292323
if (!patchedExclusiveSource) {
293-
setMinecraftURL(getMinecraftSource());
324+
setMinecraftURL(getOriginalMinecraftSource());
294325
}
295326
coreMods = null;
296327
allowLoadingGame = true;
@@ -305,11 +336,15 @@ public URL getMinecraftSource() throws IOException {
305336
this.getResource("font.txt")).openConnection();
306337
if (urlConnection instanceof JarURLConnection) {
307338
return ((JarURLConnection) urlConnection).getJarFileURL();
308-
} else if (earlyMinecraftURL != null) {
309-
return earlyMinecraftURL;
339+
} else if (this.minecraftURL != null) {
340+
return this.minecraftURL;
310341
} else throw new IOException("Invalid reindev.jar source...");
311342
}
312343

344+
public URL getOriginalMinecraftSource() throws IOException {
345+
return this.minecraftURL != null ? this.minecraftURL : this.getMinecraftSource();
346+
}
347+
313348
public boolean isAllowLoadingGame() {
314349
return allowLoadingGame;
315350
}
@@ -348,14 +383,14 @@ public static boolean isGameClassName(String cls) {
348383
cls.startsWith("com.jcraft.");
349384
}
350385

351-
public static boolean isGamePath(String cls) {
386+
public static boolean isGamePath(String path) {
352387
// Only allow core-mods to modify these files
353-
return cls.startsWith("net/minecraft/") ||
354-
cls.startsWith("com/indigo3d/") ||
355-
cls.startsWith("paulscode/sound/") ||
356-
cls.startsWith("com/jcraft/") ||
388+
return path.startsWith("net/minecraft/") ||
389+
path.startsWith("com/indigo3d/") ||
390+
path.startsWith("paulscode/sound/") ||
391+
path.startsWith("com/jcraft/") ||
357392
// font.txt is a protected game file
358-
cls.equals("font.txt");
393+
path.equals("font.txt");
359394
}
360395

361396
private static class ClassTransformException extends Exception {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.fox2code.foxloader.launcher.utils;
2+
3+
import java.util.Collections;
4+
import java.util.Enumeration;
5+
import java.util.NoSuchElementException;
6+
7+
public class Enumerations {
8+
public static <E> Enumeration<E> empty() {
9+
return Collections.emptyEnumeration();
10+
}
11+
12+
public static <E> Enumeration<E> singleton(E e) {
13+
return e == null ? new Null<>() : new Singleton<>(e);
14+
}
15+
16+
public static <E> Enumeration<E> optional(E e) {
17+
return e == null ? empty() : singleton(e);
18+
}
19+
20+
private static final class Singleton<E> implements Enumeration<E> {
21+
private E element;
22+
23+
private Singleton(E element) {
24+
this.element = element;
25+
}
26+
27+
@Override
28+
public boolean hasMoreElements() {
29+
return this.element != null;
30+
}
31+
32+
@Override
33+
public E nextElement() {
34+
E element = this.element;
35+
this.element = null;
36+
if (element == null) {
37+
throw new NoSuchElementException();
38+
}
39+
return element;
40+
}
41+
}
42+
43+
private static final class Null<E> implements Enumeration<E> {
44+
private boolean hasMoreElements;
45+
46+
private Null() {
47+
this.hasMoreElements = true;
48+
}
49+
50+
@Override
51+
public boolean hasMoreElements() {
52+
return this.hasMoreElements;
53+
}
54+
55+
@Override
56+
public E nextElement() {
57+
if (!this.hasMoreElements) {
58+
throw new NoSuchElementException();
59+
}
60+
this.hasMoreElements = false;
61+
return null;
62+
}
63+
}
64+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ org.gradle.parallel=true
33
org.gradle.jvmargs=-Xmx1024m -XX:-UseGCOverheadLimit -Dfile.encoding=UTF-8
44

55
# FoxLoader properties
6-
foxloader.version=1.2.31
6+
foxloader.version=1.2.32
77
foxloader.lastReIndevTransformerChanges=1.2.31
88
# https://www.jitpack.io/#com.fox2code/FoxLoader
99

0 commit comments

Comments
 (0)