Ejemplo n.º 1
0
 @Subscribe
 public void handleModStateEvent(FMLEvent event) {
   if (!eventMethods.containsKey(event.getClass())) {
     return;
   }
   try {
     for (Method m : eventMethods.get(event.getClass())) {
       m.invoke(modInstance, event);
     }
   } catch (Throwable t) {
     controller.errorOccurred(this, t);
   }
 }
Ejemplo n.º 2
0
 @Subscribe
 public void handleModStateEvent(FMLEvent event) {
   Class<? extends Annotation> annotation = modAnnotationTypes.get(event.getClass());
   if (annotation == null) {
     return;
   }
   try {
     for (Object o : annotations.get(annotation)) {
       Method m = (Method) o;
       m.invoke(modInstance, event);
     }
   } catch (Throwable t) {
     controller.errorOccurred(this, t);
     Throwables.propagateIfPossible(t);
   }
 }
Ejemplo n.º 3
0
 @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);
   }
 }
Ejemplo n.º 4
0
  @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);
    }
  }