11package com .fox2code .foxloader .launcher ;
22
3+ import com .fox2code .foxloader .launcher .utils .Enumerations ;
4+
35import java .io .ByteArrayOutputStream ;
46import java .io .File ;
57import 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 {
0 commit comments