Remove old coreMod code
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
package backsun.lod.asm;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.AbstractInsnNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.LabelNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
import org.objectweb.asm.tree.VarInsnNode;
|
||||
|
||||
import backsun.lod.util.RenderGlobalHook;
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
||||
public class RenderGlobalClassTransformer implements IClassTransformer
|
||||
{
|
||||
private static final String[] classesBeingTransformed = { "net.minecraft.client.renderer.RenderGlobal" };
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] classBeingTransformed)
|
||||
{
|
||||
int index = Arrays.asList(classesBeingTransformed).indexOf(transformedName);
|
||||
|
||||
// do we wan't to transform this class?
|
||||
if (index != -1)
|
||||
{
|
||||
// yes, transform this class
|
||||
boolean isObfuscated = !name.equals(transformedName);
|
||||
return transformClass(index, classBeingTransformed, isObfuscated);
|
||||
}
|
||||
else
|
||||
{
|
||||
// no, just skip this class
|
||||
return classBeingTransformed;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] transformClass(int index, byte[] classBeingTransformed, boolean isObfuscated)
|
||||
{
|
||||
try
|
||||
{
|
||||
// convert the byte code into readable ASM code
|
||||
ClassNode classNode = new ClassNode();
|
||||
ClassReader classReader = new ClassReader(classBeingTransformed);
|
||||
classReader.accept(classNode, 0);
|
||||
|
||||
transformRenderGlobal(classNode, isObfuscated);
|
||||
|
||||
// convert back into byte code
|
||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
|
||||
classNode.accept(classWriter);
|
||||
return classWriter.toByteArray();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return classBeingTransformed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void transformRenderGlobal(ClassNode classNode, boolean isObfuscated)
|
||||
{
|
||||
final String methodName = isObfuscated ? "a" : "renderBlockLayer";
|
||||
final String methodDesc = isObfuscated ?
|
||||
"(Lamk;)V" :
|
||||
"(Lnet/minecraft/util/BlockRenderLayer;)V";
|
||||
|
||||
for (MethodNode method : classNode.methods)
|
||||
{
|
||||
if (method.name.equals(methodName) && method.desc.equals(methodDesc))
|
||||
{
|
||||
AbstractInsnNode firstLoadNode = null;
|
||||
AbstractInsnNode firstReturnNode = null;
|
||||
for (AbstractInsnNode instruction : method.instructions.toArray())
|
||||
{
|
||||
if (firstLoadNode == null && instruction.getOpcode() == Opcodes.ALOAD)
|
||||
{
|
||||
// look for the first time the RenderGlobal (self)
|
||||
// variable is loaded, IE the first line of code
|
||||
// in the unedited method
|
||||
if (((VarInsnNode) instruction).var == 0)
|
||||
{
|
||||
firstLoadNode = instruction;
|
||||
}
|
||||
}
|
||||
|
||||
if (instruction.getOpcode() == Opcodes.RETURN)
|
||||
{
|
||||
// look for the first (and only) return statement
|
||||
// IE the last line of code in the unedited method
|
||||
firstReturnNode = instruction;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstLoadNode != null && firstReturnNode != null)
|
||||
{
|
||||
// add the startRenderingStencil method to the beginning of the method
|
||||
InsnList toInsert = new InsnList();
|
||||
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 1)); // BlockRenderLayer variable
|
||||
toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(RenderGlobalHook.class), RenderGlobalHook.START_STENCIL_METHOD_NAME, isObfuscated ? "(Lamk;)V" : "(Lnet/minecraft/util/BlockRenderLayer;)V", false));
|
||||
toInsert.add(new LabelNode());
|
||||
method.instructions.insertBefore(firstLoadNode, toInsert);
|
||||
|
||||
|
||||
// add the endRenderingStencil method to the end of the method
|
||||
toInsert = new InsnList();
|
||||
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 1)); // BlockRenderLayer variable
|
||||
toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type.getInternalName(RenderGlobalHook.class), RenderGlobalHook.END_STENCIL_METHOD_NAME, isObfuscated ? "(Lamk;)V" : "(Lnet/minecraft/util/BlockRenderLayer;)V", false));
|
||||
toInsert.add(new LabelNode());
|
||||
method.instructions.insertBefore(firstReturnNode, toInsert);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Something went wrong transforming RenderGlobal!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package backsun.lod.util;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 02-07-2021
|
||||
*/
|
||||
public class RenderGlobalHook
|
||||
{
|
||||
/**
|
||||
* this variable should be the same as the method name below.
|
||||
* It is used when transforming the RenderGlobal class'
|
||||
* renderBlockLayer method.
|
||||
*/
|
||||
public static final String START_STENCIL_METHOD_NAME = "startRenderingStencil";
|
||||
|
||||
/**
|
||||
* Start drawing to the stencil
|
||||
* <br><br>
|
||||
* called in the order: <br>
|
||||
* BlockRenderLayer.SOLID <br>
|
||||
* BlockRenderLayer.CUTOUT_MIPPED <br>
|
||||
* BlockRenderLayer.CUTOUT <br>
|
||||
* BlockRenderLayer.TRANSLUCENT <br>
|
||||
*/
|
||||
public static void startRenderingStencil(BlockRenderLayer blockLayerIn)
|
||||
{
|
||||
// solid is the first layer rendered
|
||||
// clear the buffer so we can start fresh.
|
||||
// if this isn't cleared first we will have overlap with the fog
|
||||
// outside the world
|
||||
if (blockLayerIn == BlockRenderLayer.SOLID)
|
||||
{
|
||||
GL11.glClearStencil(0);
|
||||
GL11.glStencilMask(0xFF); //255
|
||||
GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_STENCIL_TEST);
|
||||
GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 0x11111111); // the 2 numbers here don't matter since GL_ALWAYS is being used
|
||||
GL11.glStencilMask(0b11111111);
|
||||
GL11.glStencilOp(GL11.GL_KEEP, // this doesn't mater since GL_ALWAYS is being used
|
||||
GL11.GL_KEEP, // stencil test passes
|
||||
GL11.GL_REPLACE); // stencil + depth pass
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this variable should be the same as the method name below.
|
||||
* It is used when transforming the RenderGlobal class'
|
||||
* renderBlockLayer method.
|
||||
*/
|
||||
public static final String END_STENCIL_METHOD_NAME = "endRenderingStencil";
|
||||
|
||||
public static void endRenderingStencil(BlockRenderLayer blockLayerIn)
|
||||
{
|
||||
GL11.glStencilOp(GL11.GL_KEEP, // this doesn't mater since GL_ALWAYS is being used
|
||||
GL11.GL_KEEP, // stencil test passes
|
||||
GL11.GL_KEEP); // stencil + depth pass
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user