|
20 | 20 | import java.util.List; |
21 | 21 | import java.util.Map; |
22 | 22 | import java.util.Scanner; |
23 | | -import java.util.jar.Attributes; |
| 23 | +import java.util.Set; |
24 | 24 |
|
25 | 25 | public class Bootstrap { |
26 | 26 |
|
@@ -84,8 +84,8 @@ private static void findAndLoadJars() { |
84 | 84 | @Override |
85 | 85 | public boolean accept(File pathname) { |
86 | 86 | String fn = pathname.getName().toLowerCase(); |
87 | | - return fn.endsWith(".jar") && (fn.contains("forge") || fn.contains("ftbserver")) |
88 | | - && fn.contains("-universal") && supportedVersion(fn); |
| 87 | + return fn.endsWith(".jar") && (fn.contains("forge") || fn.contains("ftbserver")) |
| 88 | + && fn.contains("-universal") && supportedVersion(fn); |
89 | 89 | } |
90 | 90 | }); |
91 | 91 | spongeJar = findJar(new File(rootDir, "mods"), "sponge", new FileFilter() { |
@@ -185,54 +185,49 @@ public void injectIntoClassLoader(LaunchClassLoader classLoader) { |
185 | 185 | System.arraycopy(rootPlugins, 0, rootPlugins2, 0, rootPlugins.length); |
186 | 186 | rootPlugins2[rootPlugins.length] = COREMOD; |
187 | 187 | rootPluginsField.set(null, rootPlugins2); |
188 | | - mixinHackLookAwayNow(); |
| 188 | + stopMixinReInjection(); |
189 | 189 | logger.info("SpongeCoremod successfully injected into FML"); |
190 | 190 | } catch (Exception e) { |
191 | 191 | e.printStackTrace(); |
192 | 192 | } |
193 | 193 | } |
194 | 194 |
|
195 | | - private void mixinHackLookAwayNow() throws ReflectiveOperationException { |
196 | | - if (spongeJar == null) { // In dev environment |
197 | | - return; |
198 | | - } |
199 | | - // Stop mixin from trying to load spongeforge for a second time |
200 | | - Class<?> attrClass = Class.forName("org.spongepowered.asm.launch.platform.MainAttributes"); |
201 | | - Method mOf = attrClass.getMethod("of", File.class); |
202 | | - mOf.setAccessible(true); |
203 | | - Object inst = mOf.invoke(null, spongeJar); |
204 | | - Field fAttr = attrClass.getDeclaredField("attributes"); |
205 | | - fAttr.setAccessible(true); |
206 | | - Attributes attr = (Attributes) fAttr.get(inst); |
207 | | - attr.remove(new Attributes.Name("FMLCorePlugin")); |
| 195 | + private void stopMixinReInjection() throws ReflectiveOperationException { |
| 196 | + Class<?> agentCls = Class.forName("org.spongepowered.asm.launch.platform.MixinPlatformAgentFML"); |
| 197 | + Field fcoreMods = agentCls.getDeclaredField("loadedCoreMods"); |
| 198 | + fcoreMods.setAccessible(true); |
| 199 | + @SuppressWarnings("unchecked") |
| 200 | + Set<String> loadedCoreMods = (Set<String>) fcoreMods.get(null); |
| 201 | + loadedCoreMods.add(COREMOD); |
208 | 202 | } |
| 203 | + |
209 | 204 | } |
210 | 205 |
|
211 | 206 | public static class PostFMLTweaker extends SimpleTweaker { |
212 | 207 |
|
213 | 208 | @Override |
214 | 209 | public void injectIntoClassLoader(LaunchClassLoader classLoader) { |
215 | | - // Mixin system already loaded early so don't load twice |
216 | | - @SuppressWarnings("unchecked") |
217 | | - List<String> tweakClasses = (List<String>) Launch.blackboard.get("TweakClasses"); |
218 | | - boolean duplicateMixin = false; |
219 | | - while (tweakClasses.remove("org.spongepowered.asm.launch.MixinTweaker")) { |
220 | | - duplicateMixin = true; |
221 | | - } |
222 | | - // Another mod is using mixin system |
223 | | - if (duplicateMixin) { |
224 | | - try { |
225 | | - // This feels wrong but it works |
226 | | - // For some reason 'register' gets called before 'preInit' |
227 | | - // even though MixinTweaker calls preInit in constructor |
228 | | - Class<?> c = Class.forName("org.spongepowered.asm.launch.MixinBootstrap"); |
229 | | - Field init = c.getDeclaredField("initialised"); |
230 | | - init.setAccessible(true); |
231 | | - init.set(null, true); |
232 | | - tweakClasses.add("org.spongepowered.asm.launch.MixinTweaker"); |
233 | | - } catch (Exception e) { |
234 | | - e.printStackTrace(); |
| 210 | + // Fix location of jar file |
| 211 | + try { |
| 212 | + Field fPlugins = CoreModManager.class.getDeclaredField("loadPlugins"); |
| 213 | + fPlugins.setAccessible(true); |
| 214 | + @SuppressWarnings("unchecked") |
| 215 | + List<Object> plugins = (List<Object>) fPlugins.get(null); |
| 216 | + for (Object plugin : plugins) { |
| 217 | + if (plugin.getClass().getName().equals("net.minecraftforge.fml.relauncher.CoreModManager$FMLPluginWrapper")) { |
| 218 | + Field fName = plugin.getClass().getDeclaredField("name"); |
| 219 | + fName.setAccessible(true); |
| 220 | + String name = (String) fName.get(plugin); |
| 221 | + if ("SpongeCoremod".equals(name)) { |
| 222 | + Field fLocation = plugin.getClass().getDeclaredField("location"); |
| 223 | + fLocation.setAccessible(true); |
| 224 | + fLocation.set(plugin, (File) spongeJar); |
| 225 | + break; |
| 226 | + } |
| 227 | + } |
235 | 228 | } |
| 229 | + } catch (Exception e) { |
| 230 | + e.printStackTrace(); |
236 | 231 | } |
237 | 232 | } |
238 | 233 | } |
|
0 commit comments