public void findModDirMods(File modsDir, File[] supplementalModFileCandidates) { File[] modList = FileListHelper.sortFileList(modsDir, null); modList = FileListHelper.sortFileList(ObjectArrays.concat(modList, supplementalModFileCandidates, File.class)); for (File modFile : modList) { // skip loaded coremods if (CoreModManager.getIgnoredMods().contains(modFile.getName())) { FMLLog.finer("Skipping already parsed coremod or tweaker %s", modFile.getName()); } else if (modFile.isDirectory()) { FMLLog.fine("Found a candidate mod directory %s", modFile.getName()); addCandidate(new ModCandidate(modFile, modFile, ContainerType.DIR)); } else { Matcher matcher = zipJar.matcher(modFile.getName()); if (matcher.matches()) { FMLLog.fine("Found a candidate zip or jar file %s", matcher.group(0)); addCandidate(new ModCandidate(modFile, modFile, ContainerType.JAR)); } else { FMLLog.fine("Ignoring unknown file %s in mods directory", modFile.getName()); } } } }
private FMLCommonHandler() { registerCrashCallable(new ICrashCallable() { public String call() throws Exception { StringBuilder builder = new StringBuilder(); Joiner joiner = Joiner.on("\n "); for(String coreMod : CoreModManager.getTransformers().keySet()) { builder.append("\n" + coreMod + "\n ").append(joiner.join(CoreModManager.getTransformers().get(coreMod))); } return builder.toString(); } public String getLabel() { return "Loaded coremods (and transformers)"; } }); }
private void setDevEnvironment() { try { Class<CoreModManager> clazz = CoreModManager.class; Field f = clazz.getDeclaredField("deobfuscatedEnvironment"); boolean accessibilityFlag = f.isAccessible(); f.setAccessible(true); isDevEnvironment = f.getBoolean(null); f.setAccessible(accessibilityFlag); if (isDevEnvironment) { ExPMisc.modLogger.log(LogLevel.Fine, "ExPetrum has detected dev environment! Additional debug features enabled!"); ExPMisc.modLogger.setLevel(LogLevel.Debug); } else { ExPMisc.modLogger.log(LogLevel.Fine, "ExPetrum has detected normal minecraft environment. No debug features enabled."); } } catch (Exception ex) { ExPMisc.modLogger.log(LogLevel.Warning, "ExPetrum was unable to determine the environment it is located in! Assuming normal minecraft instance."); } }
@Override public void injectIntoClassLoader(LaunchClassLoader classLoader) { // Adds SpongeCoremod to FML's 'root plugins' so it always loads // before other coremods // Add to end of array so FML plugins are first try { logger.info("Performing SpongeCoremod injection"); Field rootPluginsField = CoreModManager.class.getDeclaredField("rootPlugins"); rootPluginsField.setAccessible(true); String[] rootPlugins = (String[]) rootPluginsField.get(null); String[] rootPlugins2 = new String[rootPlugins.length + 1]; System.arraycopy(rootPlugins, 0, rootPlugins2, 0, rootPlugins.length); rootPlugins2[rootPlugins.length] = COREMOD; rootPluginsField.set(null, rootPlugins2); mixinHackLookAwayNow(); logger.info("SpongeCoremod successfully injected into FML"); } catch (Exception e) { e.printStackTrace(); } }
public void findClasspathMods(ModClassLoader modClassLoader) { List<String> knownLibraries = ImmutableList.<String>builder() // skip default libs .addAll(modClassLoader.getDefaultLibraries()) // skip loaded coremods .addAll(CoreModManager.getIgnoredMods()) // skip reparse coremods here .addAll(CoreModManager.getReparseableCoremods()) .build(); File[] minecraftSources = modClassLoader.getParentSources(); if (minecraftSources.length == 1 && minecraftSources[0].isFile()) { FMLLog.fine("Minecraft is a file at %s, loading", minecraftSources[0].getAbsolutePath()); addCandidate(new ModCandidate(minecraftSources[0], minecraftSources[0], ContainerType.JAR, true, true)); } else { int i = 0; for (File source : minecraftSources) { if (source.isFile()) { if (knownLibraries.contains(source.getName()) || modClassLoader.isDefaultLibrary(source)) { FMLLog.finer("Skipping known library file %s", source.getAbsolutePath()); } else { FMLLog.fine("Found a minecraft related file at %s, examining for mod candidates", source.getAbsolutePath()); addCandidate(new ModCandidate(source, source, ContainerType.JAR, i==0, true)); } } else if (minecraftSources[i].isDirectory()) { FMLLog.fine("Found a minecraft related directory at %s, examining for mod candidates", source.getAbsolutePath()); addCandidate(new ModCandidate(source, source, ContainerType.DIR, i==0, true)); } i++; } } }
@Override public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) { if (!run) { // We sort the tweak list here so that it obeys the tweakordering CoreModManager.sortTweakList(); @SuppressWarnings("unchecked") List<String> newTweaks = (List<String>) Launch.blackboard.get("TweakClasses"); newTweaks.add("net.minecraftforge.fml.common.launcher.TerminalTweaker"); } run = true; }
@Override public void injectIntoClassLoader(LaunchClassLoader classLoader) { // Deobfuscation transformer, always last, and the access transformer tweaker as well classLoader.registerTransformer("net.minecraftforge.fml.common.asm.transformers.DeobfuscationTransformer"); // Add all the access transformers now as well for (String transformer : CoreModManager.getAccessTransformers()) { classLoader.registerTransformer(transformer); } classLoader.registerTransformer("net.minecraftforge.fml.common.asm.transformers.ModAccessTransformer"); classLoader.registerTransformer("net.minecraftforge.fml.common.asm.transformers.ItemStackTransformer"); try { FMLRelaunchLog.fine("Validating minecraft"); Class<?> loaderClazz = Class.forName("net.minecraftforge.fml.common.Loader", true, classLoader); Method m = loaderClazz.getMethod("injectData", Object[].class); m.invoke(null, (Object)FMLInjectionData.data()); m = loaderClazz.getMethod("instance"); m.invoke(null); FMLRelaunchLog.fine("Minecraft validated, launching..."); } catch (Exception e) { // Load in the Loader, make sure he's ready to roll - this will initialize most of the rest of minecraft here System.out.println("A CRITICAL PROBLEM OCCURRED INITIALIZING MINECRAFT - LIKELY YOU HAVE AN INCORRECT VERSION FOR THIS FML"); throw new RuntimeException(e); } }
public FMLInjectionAndSortingTweaker() { CoreModManager.injectCoreModTweaks(this); run = false; }
public static File getMinecraftDir() { return $(CoreModManager.class, "mcDir"); }