@Subscribe public void constructMod(FMLConstructionEvent event) { try { ModClassLoader modClassLoader = event.getModClassLoader(); modClassLoader.addFile(source); // MCPC - show users what mod is being loaded in case a crash occurs FMLLog.fine("Constructing mod from file source : " + source); Class<?> clazz = Class.forName(className, true, modClassLoader); ASMDataTable asmHarvestedAnnotations = event.getASMHarvestedData(); // TODO asmHarvestedAnnotations.getAnnotationsFor(this); annotations = gatherAnnotations(clazz); isNetworkMod = FMLNetworkHandler.instance().registerNetworkMod(this, clazz, event.getASMHarvestedData()); modInstance = clazz.newInstance(); ProxyInjector.inject( this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide()); processFieldAnnotations(event.getASMHarvestedData()); } catch (Throwable e) { controller.errorOccurred(this, e); Throwables.propagateIfPossible(e); } }
@Subscribe public void constructMod(FMLConstructionEvent event) { try { ModClassLoader modClassLoader = event.getModClassLoader(); modClassLoader.addFile(source); modClassLoader.clearNegativeCacheFor(candidate.getClassList()); Class<?> clazz = Class.forName(className, true, modClassLoader); Certificate[] certificates = clazz.getProtectionDomain().getCodeSource().getCertificates(); int len = 0; if (certificates != null) { len = certificates.length; } Builder<String> certBuilder = ImmutableList.<String>builder(); for (int i = 0; i < len; i++) { certBuilder.add(CertificateHelper.getFingerprint(certificates[i])); } ImmutableList<String> certList = certBuilder.build(); sourceFingerprints = ImmutableSet.copyOf(certList); String expectedFingerprint = (String) descriptor.get("certificateFingerprint"); fingerprintNotPresent = true; if (expectedFingerprint != null && !expectedFingerprint.isEmpty()) { if (!sourceFingerprints.contains(expectedFingerprint)) { Level warnLevel = Level.SEVERE; if (source.isDirectory()) { warnLevel = Level.FINER; } FMLLog.log( getModId(), warnLevel, "The mod %s is expecting signature %s for source %s, however there is no signature matching that description", getModId(), expectedFingerprint, source.getName()); } else { certificate = certificates[certList.indexOf(expectedFingerprint)]; fingerprintNotPresent = false; } } CustomProperty[] props = (CustomProperty[]) descriptor.get("customProperties"); if (props != null && props.length > 0) { com.google.common.collect.ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder(); for (CustomProperty p : props) { builder.put(p.k(), p.v()); } customModProperties = builder.build(); } else { customModProperties = EMPTY_PROPERTIES; } Method factoryMethod = gatherAnnotations(clazz); modInstance = getLanguageAdapter().getNewInstance(this, clazz, modClassLoader, factoryMethod); isNetworkMod = FMLNetworkHandler.instance().registerNetworkMod(this, clazz, event.getASMHarvestedData()); if (fingerprintNotPresent) { eventBus.post( new FMLFingerprintViolationEvent( source.isDirectory(), source, ImmutableSet.copyOf(this.sourceFingerprints), expectedFingerprint)); } ProxyInjector.inject( this, event.getASMHarvestedData(), FMLCommonHandler.instance().getSide(), getLanguageAdapter()); processFieldAnnotations(event.getASMHarvestedData()); } catch (Throwable e) { controller.errorOccurred(this, e); Throwables.propagateIfPossible(e); } }
/** * Called from the hook to start mod loading. We trigger the {@link #identifyMods()} and * Constructing, Preinitalization, and Initalization phases here. Finally, the mod list is frozen * completely and is consider immutable from then on. */ public void loadMods() { progressBar = ProgressManager.push("Loading", 7); progressBar.step("Constructing Mods"); initializeLoader(); mods = Lists.newArrayList(); namedMods = Maps.newHashMap(); modController = new LoadController(this); modController.transition(LoaderState.LOADING, false); discoverer = identifyMods(); ModAPIManager.INSTANCE.manageAPI(modClassLoader, discoverer); disableRequestedMods(); modController.distributeStateMessage(FMLLoadEvent.class); sortModList(); ModAPIManager.INSTANCE.cleanupAPIContainers(modController.getActiveModList()); ModAPIManager.INSTANCE.cleanupAPIContainers(mods); mods = ImmutableList.copyOf(mods); for (File nonMod : discoverer.getNonModLibs()) { if (nonMod.isFile()) { FMLLog.info( "FML has found a non-mod file %s in your mods directory. It will now be injected into your classpath. This could severe stability issues, it should be removed if possible.", nonMod.getName()); try { modClassLoader.addFile(nonMod); } catch (MalformedURLException e) { FMLLog.log( Level.ERROR, e, "Encountered a weird problem with non-mod file injection : %s", nonMod.getName()); } } } modController.transition(LoaderState.CONSTRUCTING, false); modController.distributeStateMessage( LoaderState.CONSTRUCTING, modClassLoader, discoverer.getASMTable(), reverseDependencies); List<ModContainer> mods = Lists.newArrayList(); mods.addAll(getActiveModList()); Collections.sort( mods, new Comparator<ModContainer>() { @Override public int compare(ModContainer o1, ModContainer o2) { return o1.getModId().compareTo(o2.getModId()); } }); FMLLog.fine("Mod signature data"); FMLLog.fine(" \tValid Signatures:"); for (ModContainer mod : getActiveModList()) { if (mod.getSigningCertificate() != null) FMLLog.fine( "\t\t(%s) %s\t(%s\t%s)\t%s", CertificateHelper.getFingerprint(mod.getSigningCertificate()), mod.getModId(), mod.getName(), mod.getVersion(), mod.getSource().getName()); } FMLLog.fine(" \tMissing Signatures:"); for (ModContainer mod : getActiveModList()) { if (mod.getSigningCertificate() == null) FMLLog.fine( "\t\t%s\t(%s\t%s)\t%s", mod.getModId(), mod.getName(), mod.getVersion(), mod.getSource().getName()); } if (getActiveModList().isEmpty()) { FMLLog.fine("No user mod signature data found"); } progressBar.step("Initializing mods Phase 1"); modController.transition(LoaderState.PREINITIALIZATION, false); }