mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-19 10:49:19 +00:00
Fix DefaultFMLPlatform can't be loaded when other FML platform being used. (#132)
This commit is contained in:
1 parent
581a2dddea
commit
855131d1aa
5 files changed
+51
-32
No files matched your search
@@ -5,11 +5,14 @@ import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import customskinloader.Logger;
|
||||
import net.minecraft.launchwrapper.ITweaker;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
|
||||
public class ForgeTweaker implements ITweaker {
|
||||
public static Logger logger = new Logger(new File("./CustomSkinLoader/ForgePlugin.log"));
|
||||
|
||||
private final static String FML_PLATFORM_INITIALIZER = "customskinloader.forge.platform.IFMLPlatform$FMLPlatformInitializer";
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -21,6 +24,7 @@ public class ForgeTweaker implements ITweaker {
|
||||
|
||||
String exclusionName = this.getClass().getName().substring(0, this.getClass().getName().lastIndexOf("."));
|
||||
((Set<String>) field.get(Launch.classLoader)).remove(exclusionName);
|
||||
Launch.classLoader.addClassLoaderExclusion(Logger.class.getName());
|
||||
Launch.classLoader.addTransformerExclusion(exclusionName);
|
||||
Launch.classLoader.loadClass(FML_PLATFORM_INITIALIZER).getMethod("initFMLPlatform").invoke(null);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package customskinloader.forge;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -8,12 +7,10 @@ import java.lang.annotation.Target;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import customskinloader.Logger;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
public class TransformerManager {
|
||||
public static Logger logger = new Logger(new File("./CustomSkinLoader/ForgePlugin.log"));
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
@@ -56,9 +53,9 @@ public class TransformerManager {
|
||||
}
|
||||
|
||||
private TransformTarget getTransformTarget(Class<?> cl) {
|
||||
logger.info("[CSL DEBUG] REGISTERING TRANSFORMER %s", cl.getName());
|
||||
ForgeTweaker.logger.info("[CSL DEBUG] REGISTERING TRANSFORMER %s", cl.getName());
|
||||
if (!cl.isAnnotationPresent(TransformTarget.class)) {
|
||||
logger.info("[CSL DEBUG] ERROR occurs while parsing Annotation");
|
||||
ForgeTweaker.logger.info("[CSL DEBUG] ERROR occurs while parsing Annotation");
|
||||
return null;
|
||||
}
|
||||
return cl.getAnnotation(TransformTarget.class);
|
||||
@@ -67,7 +64,7 @@ public class TransformerManager {
|
||||
private void addClassTransformer(String className, IClassTransformer transformer) {
|
||||
if (!classMap.containsKey(className)) {
|
||||
classMap.put(className, transformer);
|
||||
logger.info("[CSL DEBUG] REGISTERING CLASS %s", className);
|
||||
ForgeTweaker.logger.info("[CSL DEBUG] REGISTERING CLASS %s", className);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +73,7 @@ public class TransformerManager {
|
||||
map.put(className, new HashMap<String, IMethodTransformer>());
|
||||
for (String methodName : target.methodNames()) {
|
||||
map.get(className).put(methodName + target.desc(), transformer);
|
||||
logger.info("[CSL DEBUG] REGISTERING METHOD %s::%s", className, methodName + target.desc());
|
||||
ForgeTweaker.logger.info("[CSL DEBUG] REGISTERING METHOD %s::%s", className, methodName + target.desc());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +82,10 @@ public class TransformerManager {
|
||||
if (transformer != null) {
|
||||
try {
|
||||
classNode = transformer.transform(classNode);
|
||||
logger.info("[CSL DEBUG] Successfully transformed class %s", className);
|
||||
ForgeTweaker.logger.info("[CSL DEBUG] Successfully transformed class %s", className);
|
||||
} catch (Exception e) {
|
||||
logger.warning("[CSL DEBUG] An error happened when transforming class %s", className);
|
||||
logger.warning(e);
|
||||
ForgeTweaker.logger.warning("[CSL DEBUG] An error happened when transforming class %s", className);
|
||||
ForgeTweaker.logger.warning(e);
|
||||
}
|
||||
}
|
||||
return classNode;
|
||||
@@ -100,10 +97,10 @@ public class TransformerManager {
|
||||
if (transMap != null && transMap.containsKey(methodTarget)) {
|
||||
try {
|
||||
methodNode = transMap.get(methodTarget).transform(classNode, methodNode);
|
||||
logger.info("[CSL DEBUG] Successfully transformed method %s in class %s", methodName, className);
|
||||
ForgeTweaker.logger.info("[CSL DEBUG] Successfully transformed method %s in class %s", methodName, className);
|
||||
} catch (Exception e) {
|
||||
logger.warning("[CSL DEBUG] An error happened when transforming method %s in class %s", methodTarget, className);
|
||||
logger.warning(e);
|
||||
ForgeTweaker.logger.warning("[CSL DEBUG] An error happened when transforming method %s in class %s", methodTarget, className);
|
||||
ForgeTweaker.logger.warning(e);
|
||||
}
|
||||
}
|
||||
return methodNode;
|
||||
|
||||
@@ -54,8 +54,8 @@ public class LaunchWrapper implements IClassTransformer {
|
||||
cn = transformerManager.transform(cn, className);
|
||||
ArrayList<MethodNode> methods = new ArrayList<>();
|
||||
for (MethodNode mn : cn.methods) {
|
||||
String mappedMethodName = IFMLPlatform.FMLPlatformInitializer.platform.getRemapper().mapMethodName(cn.name, mn.name, mn.desc);
|
||||
String mappedMethodDesc = IFMLPlatform.FMLPlatformInitializer.platform.getRemapper().mapMethodDesc(mn.desc);
|
||||
String mappedMethodName = IFMLPlatform.FMLPlatformInitializer.getPlatform().getRemapper().mapMethodName(cn.name, mn.name, mn.desc);
|
||||
String mappedMethodDesc = IFMLPlatform.FMLPlatformInitializer.getPlatform().getRemapper().mapMethodDesc(mn.desc);
|
||||
methods.add(transformerManager.transform(cn, mn, className, mappedMethodName, mappedMethodDesc));
|
||||
}
|
||||
cn.methods.clear();
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import customskinloader.forge.ForgePlugin;
|
||||
@@ -71,7 +72,13 @@ public class DefaultFMLPlatform implements IFMLPlatform {
|
||||
|
||||
@Override
|
||||
public Remapper getRemapper() {
|
||||
return FMLDeobfuscatingRemapper.INSTANCE;
|
||||
// DO NOT replace with lambda or replace call with method body.
|
||||
return new Supplier<Remapper>() {
|
||||
@Override
|
||||
public Remapper get() {
|
||||
return FMLDeobfuscatingRemapper.INSTANCE;
|
||||
}
|
||||
}.get();
|
||||
}
|
||||
|
||||
protected Class<?> getFMLLoadingPluginClass() {
|
||||
@@ -83,7 +90,6 @@ public class DefaultFMLPlatform implements IFMLPlatform {
|
||||
}
|
||||
|
||||
protected String getNameValue(Annotation annotationIn) {
|
||||
assert annotationIn instanceof IFMLLoadingPlugin.Name;
|
||||
return ((IFMLLoadingPlugin.Name) annotationIn).value();
|
||||
}
|
||||
|
||||
@@ -92,7 +98,6 @@ public class DefaultFMLPlatform implements IFMLPlatform {
|
||||
}
|
||||
|
||||
protected int getSortingIndexValue(Annotation annotationIn) {
|
||||
assert annotationIn instanceof IFMLLoadingPlugin.SortingIndex;
|
||||
return ((IFMLLoadingPlugin.SortingIndex) annotationIn).value();
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,14 @@ package customskinloader.forge.platform;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.security.CodeSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
|
||||
import customskinloader.forge.TransformerManager;
|
||||
import customskinloader.forge.ForgeTweaker;
|
||||
import net.minecraft.launchwrapper.ITweaker;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
@@ -27,19 +29,21 @@ public interface IFMLPlatform {
|
||||
}
|
||||
|
||||
class FMLPlatformInitializer {
|
||||
public static IFMLPlatform platform;
|
||||
|
||||
private final static ServiceLoader<IFMLPlatform> platformsLoader = ServiceLoader.load(IFMLPlatform.class);
|
||||
private final static Set<IFMLPlatform> platforms = new HashSet<>();
|
||||
|
||||
static {
|
||||
for (IFMLPlatform platform : platformsLoader) {
|
||||
platforms.add(platform);
|
||||
}
|
||||
}
|
||||
private static IFMLPlatform platform;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void initFMLPlatform() throws Exception {
|
||||
Set<IFMLPlatform> platforms = new HashSet<>();
|
||||
List<Throwable> throwables = new ArrayList<>();
|
||||
|
||||
for (Iterator<IFMLPlatform> iterator = ServiceLoader.load(IFMLPlatform.class).iterator(); iterator.hasNext(); ) {
|
||||
try {
|
||||
platforms.add(iterator.next());
|
||||
} catch (Throwable t) {
|
||||
throwables.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
for (IFMLPlatform platform0 : platforms) {
|
||||
Set<IFMLPlatform> otherPlatforms = new HashSet<>(platforms);
|
||||
otherPlatforms.remove(platform0);
|
||||
@@ -52,7 +56,12 @@ public interface IFMLPlatform {
|
||||
}
|
||||
}
|
||||
if (platform == null) {
|
||||
throw new RuntimeException("No platform!");
|
||||
for (int i = 0, len = throwables.size(); i < len; i++) {
|
||||
Throwable throwable = throwables.get(i);
|
||||
ForgeTweaker.logger.warning("Platform - %s :", i);
|
||||
ForgeTweaker.logger.warning(throwable);
|
||||
}
|
||||
throw new RuntimeException("No available platform!");
|
||||
}
|
||||
|
||||
// CustomSkinLoader is a client side mod
|
||||
@@ -73,10 +82,14 @@ public interface IFMLPlatform {
|
||||
platform.addLoadPlugins(tweaker);
|
||||
((List<ITweaker>) Launch.blackboard.get("Tweaks")).add(tweaker);
|
||||
} else {
|
||||
TransformerManager.logger.warning("No CodeSource, if this is not a development environment we might run into problems!");
|
||||
TransformerManager.logger.warning(FMLPlatformInitializer.class.getProtectionDomain().toString());
|
||||
ForgeTweaker.logger.warning("No CodeSource, if this is not a development environment we might run into problems!");
|
||||
ForgeTweaker.logger.warning(FMLPlatformInitializer.class.getProtectionDomain().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static IFMLPlatform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
}
|
||||
|
||||
Result init(Set<IFMLPlatform> otherPlatforms);
|
||||
|
||||
Reference in new issue
Block a user