21
21
22
22
package com .falsepattern .lib .internal .impl .mixin ;
23
23
24
- import com .falsepattern .lib .mixin .MinecraftURLClassPath ;
25
24
import lombok .val ;
25
+ import sun .misc .URLClassPath ;
26
26
27
+ import net .minecraft .launchwrapper .Launch ;
27
28
import net .minecraft .launchwrapper .LaunchClassLoader ;
28
- import cpw .mods .fml .common .Loader ;
29
- import cpw .mods .fml .common .ModClassLoader ;
30
29
31
30
import java .io .File ;
32
- import java .lang .reflect .Method ;
33
- import java .net .URL ;
31
+ import java .io .IOException ;
34
32
35
33
public final class UCPImpl {
36
- private static final Object ucp ;
37
- private static final Method addURL ;
34
+ private static final URLClassPath ucp ;
38
35
private static final boolean GRIMOIRE ;
39
36
40
37
static {
@@ -43,45 +40,33 @@ public final class UCPImpl {
43
40
new String []{"io.github.crucible.grimoire.Grimoire" , "io.github.crucible.grimoire.common.GrimoireCore" };
44
41
for (val className : knownGrimoireClassNames ) {
45
42
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 );
50
49
}
51
50
}
52
51
GRIMOIRE = grimoire ;
53
52
if (!GRIMOIRE ) {
54
53
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
-
64
54
val ucpField = LaunchClassLoader .class .getSuperclass ().getDeclaredField ("ucp" );
65
55
ucpField .setAccessible (true );
66
56
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 ) {
73
59
throw new RuntimeException (e .getMessage ());
74
60
}
75
61
} else {
76
62
ucp = null ;
77
- addURL = null ;
78
63
System .err .println ("Grimoire detected, disabling jar loading utility" );
79
64
}
80
65
}
81
66
82
67
public static void addJar (File pathToJar ) throws Exception {
83
68
if (!GRIMOIRE ) {
84
- addURL . invoke ( ucp , pathToJar .toURI ().toURL ());
69
+ ucp . addURL ( pathToJar .toURI ().toURL ());
85
70
}
86
71
}
87
72
}
0 commit comments