2121
2222package com .falsepattern .lib .internal .impl .mixin ;
2323
24- import com .falsepattern .lib .mixin .MinecraftURLClassPath ;
2524import lombok .val ;
25+ import sun .misc .URLClassPath ;
2626
27+ import net .minecraft .launchwrapper .Launch ;
2728import net .minecraft .launchwrapper .LaunchClassLoader ;
28- import cpw .mods .fml .common .Loader ;
29- import cpw .mods .fml .common .ModClassLoader ;
3029
3130import java .io .File ;
32- import java .lang .reflect .Method ;
33- import java .net .URL ;
31+ import java .io .IOException ;
3432
3533public final class UCPImpl {
36- private static final Object ucp ;
37- private static final Method addURL ;
34+ private static final URLClassPath ucp ;
3835 private static final boolean GRIMOIRE ;
3936
4037 static {
@@ -43,45 +40,33 @@ public final class UCPImpl {
4340 new String []{"io.github.crucible.grimoire.Grimoire" , "io.github.crucible.grimoire.common.GrimoireCore" };
4441 for (val className : knownGrimoireClassNames ) {
4542 try {
46- Class .forName (className , false , MinecraftURLClassPath .class .getClassLoader ());
47- grimoire = true ;
48- break ;
49- } catch (ClassNotFoundException ignored ) {
43+ if (Launch .classLoader .getClassBytes (className ) != null ) {
44+ grimoire = true ;
45+ break ;
46+ }
47+ } catch (IOException e ) {
48+ throw new RuntimeException (e );
5049 }
5150 }
5251 GRIMOIRE = grimoire ;
5352 if (!GRIMOIRE ) {
5453 try {
55- val modClassLoaderField = Loader .class .getDeclaredField ("modClassLoader" );
56- modClassLoaderField .setAccessible (true );
57-
58- val loaderInstanceField = Loader .class .getDeclaredField ("instance" );
59- loaderInstanceField .setAccessible (true );
60-
61- val mainClassLoaderField = ModClassLoader .class .getDeclaredField ("mainClassLoader" );
62- mainClassLoaderField .setAccessible (true );
63-
6454 val ucpField = LaunchClassLoader .class .getSuperclass ().getDeclaredField ("ucp" );
6555 ucpField .setAccessible (true );
6656
67- Object loader = loaderInstanceField .get (null );
68- val modClassLoader = (ModClassLoader ) modClassLoaderField .get (loader );
69- val mainClassLoader = (LaunchClassLoader ) mainClassLoaderField .get (modClassLoader );
70- ucp = ucpField .get (mainClassLoader );
71- addURL = ucp .getClass ().getDeclaredMethod ("addURL" , URL .class );
72- } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException e ) {
57+ ucp = (URLClassPath ) ucpField .get (Launch .classLoader );
58+ } catch (NoSuchFieldException | IllegalAccessException e ) {
7359 throw new RuntimeException (e .getMessage ());
7460 }
7561 } else {
7662 ucp = null ;
77- addURL = null ;
7863 System .err .println ("Grimoire detected, disabling jar loading utility" );
7964 }
8065 }
8166
8267 public static void addJar (File pathToJar ) throws Exception {
8368 if (!GRIMOIRE ) {
84- addURL . invoke ( ucp , pathToJar .toURI ().toURL ());
69+ ucp . addURL ( pathToJar .toURI ().toURL ());
8570 }
8671 }
8772}
0 commit comments