1
0
forked from xjboss/KCauldronX

Patch ClimateControl for compatibility. Meh.

This commit is contained in:
Prototik 2015-05-28 17:26:48 +07:00
parent 7483df1567
commit bab4bd8b46
3 changed files with 119 additions and 47 deletions

View File

@ -62,7 +62,7 @@ ext.mcVersion = "1.7.10"
ext.forgeVersion = "1408" ext.forgeVersion = "1408"
ext.revision = retrieveBuildNumber() ext.revision = retrieveBuildNumber()
version = "${mcVersion}-${forgeVersion}.${revision}" version = "${mcVersion}-${forgeVersion}.${revision}"
println "Updated KCauldron version: ${version}" println " # Updated KCauldron version: ${version}"
launch4j { launch4j {
jreMinVersion = '1.6.0' jreMinVersion = '1.6.0'
@ -128,3 +128,35 @@ publishing {
} }
} }
} }
tasks.generateProjectCauldron << {
def file = new File('eclipse/cauldron/build.gradle')
file.append('''
repositories {
maven {
url 'https://prok.pw/repo'
}
}
dependencies {
compile 'pw.prok:KImagine:+@jar'
}
''')
}
configurations {
compile.extendsFrom exported
}
repositories {
maven {
url 'https://prok.pw/repo'
}
}
dependencies {
exported 'pw.prok:KImagine:+'
}
packageUniversal {
from { configurations.exported.collect { it.isDirectory() ? it : zipTree(it) } }
}

View File

@ -23,19 +23,24 @@
import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.asm.transformers.ModAccessTransformer; import cpw.mods.fml.common.asm.transformers.ModAccessTransformer;
import cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker; import cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker;
@@ -94,6 +99,11 @@ @@ -53,7 +58,7 @@
private static final Attributes.Name COREMODCONTAINSFMLMOD = new Attributes.Name("FMLCorePluginContainsFMLMod");
private static final Attributes.Name MODTYPE = new Attributes.Name("ModType");
private static final Attributes.Name MODSIDE = new Attributes.Name("ModSide");
- private static String[] rootPlugins = { "cpw.mods.fml.relauncher.FMLCorePlugin", "net.minecraftforge.classloading.FMLForgePlugin" };
+ private static String[] rootPlugins = { "cpw.mods.fml.relauncher.FMLCorePlugin", "net.minecraftforge.classloading.FMLForgePlugin", "pw.prok.imagine.ImagineLoadingPlugin" };
private static List<String> loadedCoremods = Lists.newArrayList();
private static List<FMLPluginWrapper> loadPlugins;
private static boolean deobfuscatedEnvironment;
@@ -94,6 +99,7 @@
@Override @Override
public void injectIntoClassLoader(LaunchClassLoader classLoader) public void injectIntoClassLoader(LaunchClassLoader classLoader)
{ {
+ // Cauldron start
+ // Register own ClassTransformer for some needs
+ classLoader.registerTransformer("kcauldron.KCauldronClassTransformer");
+ KCauldronClassTransformer.DEV = deobfuscatedEnvironment;
+ // Cauldron end + // Cauldron end
FMLRelaunchLog.fine("Injecting coremod %s {%s} class transformers", name, coreModInstance.getClass().getName()); FMLRelaunchLog.fine("Injecting coremod %s {%s} class transformers", name, coreModInstance.getClass().getName());
if (coreModInstance.getASMTransformerClass() != null) for (String transformer : coreModInstance.getASMTransformerClass()) if (coreModInstance.getASMTransformerClass() != null) for (String transformer : coreModInstance.getASMTransformerClass())
{ {
@@ -153,6 +163,9 @@ @@ -153,6 +159,9 @@
} }
@ -45,7 +50,7 @@
public static void handleLaunch(File mcDir, LaunchClassLoader classLoader, FMLTweaker tweaker) public static void handleLaunch(File mcDir, LaunchClassLoader classLoader, FMLTweaker tweaker)
{ {
CoreModManager.mcDir = mcDir; CoreModManager.mcDir = mcDir;
@@ -212,6 +225,19 @@ @@ -212,6 +221,19 @@
loadCoreMod(classLoader, coreModClassName, null); loadCoreMod(classLoader, coreModClassName, null);
} }
discoverCoreMods(mcDir, classLoader); discoverCoreMods(mcDir, classLoader);
@ -65,7 +70,7 @@
} }
@@ -322,6 +348,10 @@ @@ -322,6 +344,10 @@
FMLRelaunchLog.fine("Not found coremod data in %s", coreMod.getName()); FMLRelaunchLog.fine("Not found coremod data in %s", coreMod.getName());
continue; continue;
} }
@ -76,7 +81,7 @@
// Support things that are mod jars, but not FML mod jars // Support things that are mod jars, but not FML mod jars
try try
{ {
@@ -424,8 +454,11 @@ @@ -424,8 +450,11 @@
MCVersion requiredMCVersion = coreModClazz.getAnnotation(IFMLLoadingPlugin.MCVersion.class); MCVersion requiredMCVersion = coreModClazz.getAnnotation(IFMLLoadingPlugin.MCVersion.class);
if (!Arrays.asList(rootPlugins).contains(coreModClass) && (requiredMCVersion == null || Strings.isNullOrEmpty(requiredMCVersion.value()))) if (!Arrays.asList(rootPlugins).contains(coreModClass) && (requiredMCVersion == null || Strings.isNullOrEmpty(requiredMCVersion.value())))
{ {

View File

@ -1,53 +1,88 @@
package kcauldron; package kcauldron;
import org.apache.logging.log4j.Level;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.IntInsnNode;
import pw.prok.imagine.api.Pair;
import pw.prok.imagine.asm.ImagineASM;
import pw.prok.imagine.asm.ImagineMethod;
import pw.prok.imagine.asm.ImagineRemapper;
import pw.prok.imagine.asm.Transformer;
import com.avaje.ebean.annotation.Transactional;
import cpw.mods.fml.common.FMLLog;
import net.minecraft.launchwrapper.IClassTransformer; import net.minecraft.launchwrapper.IClassTransformer;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.IChunkProvider;
import static org.objectweb.asm.Opcodes.*; import static org.objectweb.asm.Opcodes.*;
public class KCauldronClassTransformer implements IClassTransformer { @Transformer.RegisterTransformer
public static boolean DEV; public class KCauldronClassTransformer implements Transformer {
@Override @Override
public byte[] transform(String name, String transformedName, byte[] basicClass) { public void transform(final ImagineASM asm) {
if ("net.minecraft.world.gen.ChunkProviderServer".equals(transformedName) || "net.minecraftforge.common.chunkio.ChunkIOProvider".equals(transformedName)) { if (asm.is("net.minecraft.world.gen.ChunkProviderServer")
return patchChunkCall(basicClass); || asm.is("net.minecraftforge.common.chunkio.ChunkIOProvider")) {
FMLLog.log(Level.INFO, "KCauldron: Patching " + asm.getActualName() + " for compatibility with Mystcraft");
ClassReader reader = new ClassReader(asm.build());
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
reader.accept(new ClassVisitor(ASM5, writer) {
@Override
public FieldVisitor visitField(int access, String name,
String desc, String signature, Object value) {
if ("loadedChunkHashMap_vanilla".equals(name)) {
name = asm.isDev() ? "loadedChunkHashMap" : "field_73244_f";
}
return super.visitField(access, name, desc, signature,
value);
}
@Override
public MethodVisitor visitMethod(int access, String name,
String desc, String signature, String[] exceptions) {
return new MethodVisitor(api, super.visitMethod(access,
name, desc, signature, exceptions)) {
@Override
public void visitFieldInsn(int opcode, String owner,
String name, String desc) {
if ("loadedChunkHashMap_vanilla".equals(name)) {
name = asm.isDev() ? "loadedChunkHashMap" : "field_73244_f";
}
super.visitFieldInsn(opcode, owner, name, desc);
}
};
}
}, 0);
asm.loadClass(writer.toByteArray());
}
if (asm.is("climateControl.utils.ChunkGeneratorExtractor")) {
boolean undergroundBiomesInstalled = false;
try {
Class.forName("exterminatorJeff.undergroundBiomes.worldGen.ChunkProviderWrapper");
undergroundBiomesInstalled = true;
} catch (Exception ignored) {
}
if (!undergroundBiomesInstalled) {
FMLLog.log(Level.INFO, "KCauldron: Patching " + asm.getActualName() + " for compatibility with Climate Control");
extractFrom(asm, asm.method("extractFrom",
"(Lnet/minecraft/world/WorldServer;)Lnet/minecraft/world/chunk/IChunkProvider;").instructions());
}
} }
return basicClass;
} }
private byte[] patchChunkCall(byte[] bytes) { public void extractFrom(ImagineASM asm, InsnList list) {
ClassReader reader = new ClassReader(bytes); //Pair<String, String> fieldChunkProvider = asm.field("net/minecraft/world/World", "chunkProvider");
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); list.clear();
reader.accept(new ClassVisitor(ASM5, writer) { list.add(new IntInsnNode(ALOAD, 1));
@Override list.add(new FieldInsnNode(GETFIELD, "ahb", "v", "Lapu;"));
public FieldVisitor visitField(int access, String name, list.add(new InsnNode(ARETURN));
String desc, String signature, Object value) {
if ("loadedChunkHashMap_vanilla".equals(name)) {
name = DEV ? "loadedChunkHashMap" : "field_73244_f";
}
return super.visitField(access, name, desc, signature, value);
}
@Override
public MethodVisitor visitMethod(int access, String name,
String desc, String signature, String[] exceptions) {
return new MethodVisitor(api, super.visitMethod(access, name, desc, signature, exceptions)) {
@Override
public void visitFieldInsn(int opcode, String owner,
String name, String desc) {
if ("loadedChunkHashMap_vanilla".equals(name)) {
name = DEV ? "loadedChunkHashMap" : "field_73244_f";
}
super.visitFieldInsn(opcode, owner, name, desc);
}
};
}
}, 0);
return writer.toByteArray();
} }
} }