Unified 1.7.2 and 1.7.10 versions

This commit is contained in:
octarine-noise
2014-07-16 23:25:06 +02:00
parent 7ca25c0da7
commit 91fda1522c
9 changed files with 112 additions and 114 deletions

View File

@@ -20,7 +20,7 @@ minecraft {
version = '1.7.2-10.12.2.1147' version = '1.7.2-10.12.2.1147'
} }
jar.baseName = 'BetterFoliage-1.7.2' jar.baseName = 'BetterFoliage'
group = 'com.github.octarine-noise' group = 'com.github.octarine-noise'
version='0.9.5b' version='0.9.5b'

View File

@@ -18,7 +18,7 @@ public class BetterFoliage {
public static final String MOD_ID = "BetterFoliage"; public static final String MOD_ID = "BetterFoliage";
public static final String MOD_NAME = "Better Foliage"; public static final String MOD_NAME = "Better Foliage";
public static final String MC_VERSIONS = "[1.7.2]"; public static final String MC_VERSIONS = "[1.7.2,1.7.10]";
public static final String GUI_FACTORY = "mods.betterfoliage.client.gui.ConfigGuiFactory"; public static final String GUI_FACTORY = "mods.betterfoliage.client.gui.ConfigGuiFactory";
@Mod.Instance @Mod.Instance

View File

@@ -8,8 +8,8 @@ import java.util.Set;
import mods.betterfoliage.BetterFoliage; import mods.betterfoliage.BetterFoliage;
import mods.betterfoliage.client.BetterFoliageClient; import mods.betterfoliage.client.BetterFoliageClient;
import mods.betterfoliage.common.util.DeobfNames;
import mods.betterfoliage.common.util.Utils; import mods.betterfoliage.common.util.Utils;
import mods.betterfoliage.loader.DeobfHelper;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
@@ -92,15 +92,14 @@ public class LeafTextureGenerator extends BlockTextureGenerator implements IIcon
// enumerate all registered textures, find leaf textures among them // enumerate all registered textures, find leaf textures among them
Map<String, TextureAtlasSprite> mapAtlas = null; Map<String, TextureAtlasSprite> mapAtlas = null;
mapAtlas = Utils.getField(blockTextures, DeobfNames.TM_MRS_SRG, Map.class); mapAtlas = Utils.getField(blockTextures, DeobfHelper.transformElementSearge("mapRegisteredSprites"), Map.class);
if (mapAtlas == null) mapAtlas = Utils.getField(blockTextures, DeobfNames.TM_MRS_MCP, Map.class); if (mapAtlas == null) mapAtlas = Utils.getField(blockTextures, "mapRegisteredSprites", Map.class);
if (mapAtlas == null) { if (mapAtlas == null) {
BetterFoliage.log.warn("Failed to reflect texture atlas, textures may be missing"); BetterFoliage.log.warn("Failed to reflect texture atlas, textures may be missing");
} else { } else {
Set<String> foundLeafTextures = Sets.newHashSet(); Set<String> foundLeafTextures = Sets.newHashSet();
for (TextureAtlasSprite icon : mapAtlas.values()) for (TextureAtlasSprite icon : mapAtlas.values())
for (ILeafTextureRecognizer recognizer : recognizers) if (BetterFoliageClient.isLeafTexture(icon))
if (recognizer.isLeafTexture(icon))
foundLeafTextures.add(icon.getIconName()); foundLeafTextures.add(icon.getIconName());
for (String resourceLocation : foundLeafTextures) { for (String resourceLocation : foundLeafTextures) {
BetterFoliage.log.debug(String.format("Found non-block-registered leaf texture: %s", resourceLocation)); BetterFoliage.log.debug(String.format("Found non-block-registered leaf texture: %s", resourceLocation));

View File

@@ -1,71 +0,0 @@
package mods.betterfoliage.common.util;
public class DeobfNames {
private DeobfNames() {}
/** MCP name of RenderBlocks */
public static final String RB_NAME_MCP = "net/minecraft/client/renderer/RenderBlocks";
/** Obfuscated name of RenderBlocks */
public static final String RB_NAME_OBF = "ble";
/** MCP name of RenderBlocks.blockAccess */
public static final String RB_BA_NAME_MCP = "blockAccess";
/** Obfuscated name of RenderBlocks.blockAccess */
public static final String RB_BA_NAME_OBF = "a";
/** MCP signature of RenderBlocks.blockAccess */
public static final String RB_BA_SIG_MCP = "Lnet/minecraft/world/IBlockAccess;";
/** Obfuscated signature of RenderBlocks.blockAccess */
public static final String RB_BA_SIG_OBF = "Lafx;";
/** MCP name of RenderBlocks.renderBlockByRenderType() */
public static final String RB_RBBRT_NAME_MCP = "renderBlockByRenderType";
/** Obfuscated name of RenderBlocks.renderBlockByRenderType() */
public static final String RB_RBBRT_NAME_OBF = "b";
/** MCP signature of RenderBlocks.renderBlockByRenderType() */
public static final String RB_RBBRT_SIG_MCP = "(Lnet/minecraft/block/Block;III)Z";
/** Obfuscated signature of RenderBlocks.renderBlockByRenderType() */
public static final String RB_RBBRT_SIG_OBF = "(Lahu;III)Z";
/** MCP signature of BetterFoliageClient.getRenderTypeOverride() */
public static final String BFC_GRTO_SIG_MCP = "(Lnet/minecraft/world/IBlockAccess;IIILnet/minecraft/block/Block;I)I";
/** Obfuscated signature of BetterFoliageClient.getRenderTypeOverride() */
public static final String BFC_GRTO_SIG_OBF = "(Lafx;IIILahu;I)I";
/** MCP name of SimpleReloadableResourceManager.domainResourceManagers */
public static final String SRRM_DRM_MCP = "domainResourceManagers";
/** SRG name of SimpleReloadableResourceManager.domainResourceManagers */
public static final String SRRM_DRM_SRGNAME = "field_110548_a";
/** MCP name of TextureMap.mapRegisteredSprites */
public static final String TM_MRS_MCP = "mapRegisteredSprites";
/** Obfuscated name of TextureMap.mapRegisteredSprites */
public static final String TM_MRS_OBF = "bpr";
/** SRG name of TextureMap.mapRegisteredSprites */
public static final String TM_MRS_SRG = "field_110574_e";
/** MCP signature of Shaders.pushEntity() */
public static final String SHADERS_PE_SIG_MCP = "(Lnet/minecraft/client/renderer/RenderBlocks;Lnet/minecraft/block/Block;III)V";
/** Obfuscated signature of Shaders.pushEntity() */
public static final String SHADERS_PE_SIG_OBF = "(Lble;Lahu;III)V";
/** MCP signature of BetterFoliageClient.getGLSLBlockIdOverride() */
public static final String BFC_GLSLID_SIG_MCP = "(ILnet/minecraft/block/Block;)I";
/** Obfuscated signature of BetterFoliageClient.getGLSLBlockIdOverride() */
public static final String BFC_GLSLID_SIG_OBF = "(ILahu;)I";
}

View File

@@ -4,6 +4,7 @@ import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Map; import java.util.Map;
import mods.betterfoliage.loader.DeobfHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.IResource; import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager; import net.minecraft.client.resources.IResourceManager;
@@ -18,8 +19,8 @@ public class Utils {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static Map<String, IResourceManager> getDomainResourceManagers() { public static Map<String, IResourceManager> getDomainResourceManagers() {
IResourceManager manager = Minecraft.getMinecraft().getResourceManager(); IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
Map<String, IResourceManager> result = getField(manager, DeobfNames.SRRM_DRM_MCP, Map.class); Map<String, IResourceManager> result = getField(manager, "domainResourceManagers", Map.class);
if (result == null) result = getField(manager, DeobfNames.SRRM_DRM_SRGNAME, Map.class); if (result == null) result = getField(manager, DeobfHelper.transformElementSearge("domainResourceManagers"), Map.class);
return result; return result;
} }

View File

@@ -4,7 +4,6 @@ import java.util.Map;
import cpw.mods.fml.relauncher.IFMLLoadingPlugin; import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
@IFMLLoadingPlugin.MCVersion("1.7.2")
@IFMLLoadingPlugin.TransformerExclusions({"mods.betterfoliage.loader"}) @IFMLLoadingPlugin.TransformerExclusions({"mods.betterfoliage.loader"})
public class BetterFoliageLoader implements IFMLLoadingPlugin { public class BetterFoliageLoader implements IFMLLoadingPlugin {

View File

@@ -1,7 +1,5 @@
package mods.betterfoliage.loader; package mods.betterfoliage.loader;
import mods.betterfoliage.common.util.DeobfNames;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode; import org.objectweb.asm.tree.FieldInsnNode;
@@ -11,38 +9,39 @@ import org.objectweb.asm.tree.VarInsnNode;
public class BetterFoliageTransformer extends EZTransformerBase { public class BetterFoliageTransformer extends EZTransformerBase {
public BetterFoliageTransformer() {
DeobfHelper.init();
}
@MethodTransform(className="net.minecraft.client.renderer.RenderBlocks", @MethodTransform(className="net.minecraft.client.renderer.RenderBlocks",
obf=@MethodMatch(name=DeobfNames.RB_RBBRT_NAME_OBF, signature=DeobfNames.RB_RBBRT_SIG_OBF), methodName="renderBlockByRenderType",
deobf=@MethodMatch(name=DeobfNames.RB_RBBRT_NAME_MCP, signature=DeobfNames.RB_RBBRT_SIG_MCP), signature="(Lnet/minecraft/block/Block;III)Z",
log="Applying RenderBlocks.renderBlockByRenderType() render type ovverride") log="Applying RenderBlocks.renderBlockByRenderType() render type ovverride")
public void handleRenderBlockOverride(MethodNode method, boolean obf) { public void handleRenderBlockOverride(MethodNode method) {
AbstractInsnNode invokeGetRenderType = findNext(method.instructions.getFirst(), matchInvokeAny()); AbstractInsnNode invokeGetRenderType = findNext(method.instructions.getFirst(), matchInvokeAny());
AbstractInsnNode storeRenderType = findNext(invokeGetRenderType, matchOpcode(Opcodes.ISTORE)); AbstractInsnNode storeRenderType = findNext(invokeGetRenderType, matchOpcode(Opcodes.ISTORE));
insertAfter(method.instructions, storeRenderType, insertAfter(method.instructions, storeRenderType,
new VarInsnNode(Opcodes.ALOAD, 0), new VarInsnNode(Opcodes.ALOAD, 0),
obf ? new FieldInsnNode(Opcodes.GETFIELD, DeobfNames.RB_NAME_OBF, DeobfNames.RB_BA_NAME_OBF, DeobfNames.RB_BA_SIG_OBF) : new FieldInsnNode(Opcodes.GETFIELD, className("net/minecraft/client/renderer/RenderBlocks"), element("blockAccess"), signature("Lnet/minecraft/world/IBlockAccess;")),
new FieldInsnNode(Opcodes.GETFIELD, DeobfNames.RB_NAME_MCP, DeobfNames.RB_BA_NAME_MCP, DeobfNames.RB_BA_SIG_MCP),
new VarInsnNode(Opcodes.ILOAD, 2), new VarInsnNode(Opcodes.ILOAD, 2),
new VarInsnNode(Opcodes.ILOAD, 3), new VarInsnNode(Opcodes.ILOAD, 3),
new VarInsnNode(Opcodes.ILOAD, 4), new VarInsnNode(Opcodes.ILOAD, 4),
new VarInsnNode(Opcodes.ALOAD, 1), new VarInsnNode(Opcodes.ALOAD, 1),
new VarInsnNode(Opcodes.ILOAD, 5), new VarInsnNode(Opcodes.ILOAD, 5),
obf ? new MethodInsnNode(Opcodes.INVOKESTATIC, "mods/betterfoliage/client/BetterFoliageClient", "getRenderTypeOverride", DeobfNames.BFC_GRTO_SIG_OBF) : new MethodInsnNode(Opcodes.INVOKESTATIC, "mods/betterfoliage/client/BetterFoliageClient", "getRenderTypeOverride", signature("(Lnet/minecraft/world/IBlockAccess;IIILnet/minecraft/block/Block;I)I")),
new MethodInsnNode(Opcodes.INVOKESTATIC, "mods/betterfoliage/client/BetterFoliageClient", "getRenderTypeOverride", DeobfNames.BFC_GRTO_SIG_MCP),
new VarInsnNode(Opcodes.ISTORE, 5) new VarInsnNode(Opcodes.ISTORE, 5)
); );
} }
@MethodTransform(className="shadersmodcore.client.Shaders", @MethodTransform(className="shadersmodcore.client.Shaders",
obf=@MethodMatch(name="pushEntity", signature=DeobfNames.SHADERS_PE_SIG_OBF), methodName="pushEntity",
deobf=@MethodMatch(name="pushEntity", signature=DeobfNames.SHADERS_PE_SIG_MCP), signature="(Lnet/minecraft/client/renderer/RenderBlocks;Lnet/minecraft/block/Block;III)V",
log="Applying Shaders.pushEntity() block id ovverride") log="Applying Shaders.pushEntity() block id ovverride")
public void handleGLSLBlockIDOverride(MethodNode method, boolean obf) { public void handleGLSLBlockIDOverride(MethodNode method) {
AbstractInsnNode arrayStore = findNext(method.instructions.getFirst(), matchOpcode(Opcodes.IASTORE)); AbstractInsnNode arrayStore = findNext(method.instructions.getFirst(), matchOpcode(Opcodes.IASTORE));
insertAfter(method.instructions, arrayStore.getPrevious(), insertAfter(method.instructions, arrayStore.getPrevious(),
new VarInsnNode(Opcodes.ALOAD, 1), new VarInsnNode(Opcodes.ALOAD, 1),
obf ? new MethodInsnNode(Opcodes.INVOKESTATIC, "mods/betterfoliage/client/BetterFoliageClient", "getGLSLBlockIdOverride", DeobfNames.BFC_GLSLID_SIG_OBF) : new MethodInsnNode(Opcodes.INVOKESTATIC, "mods/betterfoliage/client/BetterFoliageClient", "getGLSLBlockIdOverride", signature("(ILnet/minecraft/block/Block;)I"))
new MethodInsnNode(Opcodes.INVOKESTATIC, "mods/betterfoliage/client/BetterFoliageClient", "getGLSLBlockIdOverride", DeobfNames.BFC_GLSLID_SIG_MCP)
); );
} }
} }

View File

@@ -0,0 +1,62 @@
package mods.betterfoliage.loader;
import java.util.Map;
import com.google.common.collect.Maps;
import cpw.mods.fml.relauncher.FMLInjectionData;
public class DeobfHelper {
private static Map<String, String> obfClasses = Maps.newHashMap();
private static Map<String, String> obfElements = Maps.newHashMap();
private static Map<String, String> srgElements = Maps.newHashMap();
public static void init() {
String mcVersion = FMLInjectionData.data()[4].toString();
srgElements.put("domainResourceManagers", "field_110548_a");
srgElements.put("mapRegisteredSprites", "field_110574_e");
if ("1.7.2".equals(mcVersion)) {
obfClasses.put("net/minecraft/client/renderer/RenderBlocks", "ble");
obfClasses.put("net/minecraft/world/IBlockAccess", "afx");
obfClasses.put("net/minecraft/block/Block", "ahu");
obfElements.put("blockAccess", "a");
obfElements.put("renderBlockByRenderType", "b");
obfElements.put("mapRegisteredSprites", "bpr");
} else if ("1.7.10".equals(mcVersion)) {
obfClasses.put("net/minecraft/client/renderer/RenderBlocks", "blm");
obfClasses.put("net/minecraft/world/IBlockAccess", "ahl");
obfClasses.put("net/minecraft/block/Block", "aji");
obfElements.put("blockAccess", "a");
obfElements.put("renderBlockByRenderType", "b");
obfElements.put("mapRegisteredSprites", "bpr");
}
}
public static String transformClassName(String className) {
return obfClasses.containsKey(className) ? obfClasses.get(className) : className;
}
public static String transformElementName(String elementName) {
return obfElements.containsKey(elementName) ? obfElements.get(elementName) : elementName;
}
public static String transformElementSearge(String elementName) {
return srgElements.containsKey(elementName) ? srgElements.get(elementName) : elementName;
}
public static String transformSignature(String signature) {
String result = signature;
boolean hasChanged = false;
do {
hasChanged = false;
for (Map.Entry<String, String> entry : obfClasses.entrySet()) if (result.contains("L" + entry.getKey() + ";")) {
result = result.replace("L" + entry.getKey() + ";", "L" + entry.getValue() + ";");
hasChanged = true;
}
} while(hasChanged);
return result;
}
}

View File

@@ -24,23 +24,19 @@ public class EZTransformerBase implements IClassTransformer {
public boolean matches(AbstractInsnNode node); public boolean matches(AbstractInsnNode node);
} }
@Retention(RetentionPolicy.RUNTIME)
public static @interface MethodMatch {
public String name();
public String signature();
}
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public static @interface MethodTransform { public static @interface MethodTransform {
public String className(); public String className();
public MethodMatch deobf(); public String methodName();
public MethodMatch obf(); public String signature();
public String log(); public String log();
} }
protected Logger logger = LogManager.getLogger(getClass().getSimpleName()); protected Logger logger = LogManager.getLogger(getClass().getSimpleName());
protected Boolean isObfuscated;
public byte[] transform(String name, String transformedName, byte[] basicClass) { public byte[] transform(String name, String transformedName, byte[] basicClass) {
// ??? // ???
if (basicClass == null) return null; if (basicClass == null) return null;
@@ -55,25 +51,26 @@ public class EZTransformerBase implements IClassTransformer {
// check for annotated method with correct signature // check for annotated method with correct signature
MethodTransform annot = classMethod.getAnnotation(MethodTransform.class); MethodTransform annot = classMethod.getAnnotation(MethodTransform.class);
if (annot == null) continue; if (annot == null) continue;
if (classMethod.getParameterTypes().length != 2) continue; if (classMethod.getParameterTypes().length != 1) continue;
if (!classMethod.getParameterTypes()[0].equals(MethodNode.class)) continue; if (!classMethod.getParameterTypes()[0].equals(MethodNode.class)) continue;
if (!classMethod.getParameterTypes()[1].equals(boolean.class)) continue;
// try to find specified method in class // try to find specified method in class
if (!transformedName.equals(annot.className())) continue; if (!transformedName.equals(annot.className())) continue;
logger.debug(String.format("Found class: %s -> %s", name, transformedName));
for (MethodNode methodNode : classNode.methods) { for (MethodNode methodNode : classNode.methods) {
Boolean obf = null; logger.trace(String.format("Checking method: %s, sig: %s", methodNode.name, methodNode.desc));
if (methodNode.name.equals(annot.obf().name()) && methodNode.desc.equals(annot.obf().signature())) { isObfuscated = null;
obf = true; if (methodNode.name.equals(DeobfHelper.transformElementName(annot.methodName())) && methodNode.desc.equals(DeobfHelper.transformSignature(annot.signature()))) {
} else if (methodNode.name.equals(annot.deobf().name()) && methodNode.desc.equals(annot.deobf().signature())) { isObfuscated = true;
obf = false; } else if (methodNode.name.equals(annot.methodName()) && methodNode.desc.equals(annot.signature())) {
isObfuscated = false;
} }
if (obf != null) { if (isObfuscated != null) {
// transform // transform
hasTransformed = true; hasTransformed = true;
try { try {
classMethod.invoke(this, new Object[] {methodNode, obf}); classMethod.invoke(this, new Object[] {methodNode});
logger.info(String.format("%s: SUCCESS", annot.log())); logger.info(String.format("%s: SUCCESS", annot.log()));
} catch (Exception e) { } catch (Exception e) {
logger.info(String.format("%s: FAILURE", annot.log())); logger.info(String.format("%s: FAILURE", annot.log()));
@@ -89,6 +86,18 @@ public class EZTransformerBase implements IClassTransformer {
return !hasTransformed ? basicClass : writer.toByteArray(); return !hasTransformed ? basicClass : writer.toByteArray();
} }
protected String className(String className) {
return isObfuscated ? DeobfHelper.transformClassName(className) : className;
}
protected String element(String fieldName) {
return isObfuscated ? DeobfHelper.transformElementName(fieldName) : fieldName;
}
protected String signature(String signature) {
return isObfuscated ? DeobfHelper.transformSignature(signature) : signature;
}
protected AbstractInsnNode findNext(AbstractInsnNode start, IInstructionMatch match) { protected AbstractInsnNode findNext(AbstractInsnNode start, IInstructionMatch match) {
AbstractInsnNode current = start; AbstractInsnNode current = start;
while(current != null) { while(current != null) {