Cloud Optimization

This commit is contained in:
kirillsaint 2023-07-26 16:32:56 +06:00
parent b4f0c4f42c
commit 2e89662ac7
5 changed files with 400 additions and 1 deletions

View File

@ -1,8 +1,15 @@
package net.silentclient.client.mixin; package net.silentclient.client.mixin;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.launchwrapper.IClassTransformer; import net.minecraft.launchwrapper.IClassTransformer;
import net.silentclient.client.Client; import net.silentclient.client.Client;
import org.objectweb.asm.*; import net.silentclient.client.mixin.visitors.RenderCloudsFancy;
import net.silentclient.client.mixin.visitors.RenderCloudsFast;
import net.silentclient.client.utils.ClientUtils;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
@ -24,9 +31,41 @@ public class SilentClientTransformer implements IClassTransformer {
return classwriter.toByteArray(); return classwriter.toByteArray();
} }
if (transformedName.equals(RenderGlobal.class.getName())) {
Client.logger.info("Transforming class: " + transformedName);
final ClassReader classReader5 = new ClassReader(bytes);
final ClassWriter classWriter5 = new ClassWriter(1);
classReader5.accept((ClassVisitor)new RenderGlobalClassVisitor(262144, classWriter5), 0);
return classWriter5.toByteArray();
}
return bytes; return bytes;
} }
public static String getClassName(final Class clazz) {
return clazz.getName().replace(".", "/");
}
public static class RenderGlobalClassVisitor extends ClassVisitor
{
private RenderGlobalClassVisitor(final int n, final ClassWriter classWriter) {
super(n, (ClassVisitor)classWriter);
}
public MethodVisitor visitMethod(final int n, final String s, final String s2, final String s3, final String[] array) {
final MethodVisitor visitMethod = super.visitMethod(n, s, s2, s3, array);
if (s.equals(ClientUtils.isDevelopment() ? "renderClouds" : "b") && s2.equals("(FI)V")) {
Client.logger.info("Transforming method: " + s);
return new RenderCloudsFast(this.api, visitMethod);
}
if (s.equals(ClientUtils.isDevelopment() ? "renderCloudsFancy" : "c") && s2.equals("(FI)V")) {
Client.logger.info("Transforming method: " + s);
return new RenderCloudsFancy(this.api, visitMethod);
}
return visitMethod;
}
}
public class AccessTransformerVisitor extends ClassVisitor { public class AccessTransformerVisitor extends ClassVisitor {
public AccessTransformerVisitor(int api, ClassVisitor cv) { public AccessTransformerVisitor(int api, ClassVisitor cv) {

View File

@ -0,0 +1,140 @@
package net.silentclient.client.mixin.visitors;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.MethodVisitor;
public class ClearingMethodVisitor extends MethodVisitor
{
protected boolean clear;
public ClearingMethodVisitor(final int n, final MethodVisitor methodVisitor) {
super(n, methodVisitor);
this.clear = false;
}
public void visitAttribute(final Attribute attribute) {
if (!this.clear) {
super.visitAttribute(attribute);
}
}
public void visitCode() {
if (!this.clear) {
super.visitCode();
}
}
public void visitTableSwitchInsn(final int n, final int n2, final Label label, final Label... array) {
super.visitTableSwitchInsn(n, n2, label, array);
}
public void visitLookupSwitchInsn(final Label label, final int[] array, final Label[] array2) {
super.visitLookupSwitchInsn(label, array, array2);
}
public void visitMultiANewArrayInsn(final String s, final int n) {
super.visitMultiANewArrayInsn(s, n);
}
public void visitTryCatchBlock(final Label label, final Label label2, final Label label3, final String s) {
super.visitTryCatchBlock(label, label2, label3, s);
}
public void visitFrame(final int n, final int n2, final Object[] array, final int n3, final Object[] array2) {
if (!this.clear) {
super.visitFrame(n, n2, array, n3, array2);
}
}
public void visitInsn(final int n) {
if (!this.clear) {
super.visitInsn(n);
}
}
public void visitIntInsn(final int n, final int n2) {
if (!this.clear) {
super.visitIntInsn(n, n2);
}
}
public void visitVarInsn(final int n, final int n2) {
if (!this.clear) {
super.visitVarInsn(n, n2);
}
}
public void visitTypeInsn(final int n, final String s) {
if (!this.clear) {
super.visitTypeInsn(n, s);
}
}
public void visitFieldInsn(final int n, final String s, final String s2, final String s3) {
if (!this.clear) {
super.visitFieldInsn(n, s, s2, s3);
}
}
public void visitMethodInsn(final int n, final String s, final String s2, final String s3) {
if (!this.clear) {
super.visitMethodInsn(n, s, s2, s3);
}
}
public void visitInvokeDynamicInsn(final String s, final String s2, final Handle handle, final Object... array) {
if (!this.clear) {
super.visitInvokeDynamicInsn(s, s2, handle, array);
}
}
public void visitJumpInsn(final int n, final Label label) {
if (!this.clear) {
super.visitJumpInsn(n, label);
}
}
public void visitLabel(final Label label) {
if (!this.clear) {
super.visitLabel(label);
}
}
public void visitLdcInsn(final Object o) {
if (!this.clear) {
super.visitLdcInsn(o);
}
}
public void visitLocalVariable(final String s, final String s2, final String s3, final Label label, final Label label2, final int n) {
if (!this.clear) {
super.visitLocalVariable(s, s2, s3, label, label2, n);
}
}
public void visitLineNumber(final int n, final Label label) {
if (!this.clear) {
super.visitLineNumber(n, label);
}
}
public void visitIincInsn(final int n, final int n2) {
if (!this.clear) {
super.visitIincInsn(n, n2);
}
}
public void visitMaxs(final int n, final int n2) {
if (!this.clear) {
super.visitMaxs(n, n2);
}
}
public void visitEnd() {
if (!this.clear) {
super.visitEnd();
}
}
}

View File

@ -0,0 +1,68 @@
package net.silentclient.client.mixin.visitors;
import net.silentclient.client.mixin.SilentClientTransformer;
import net.silentclient.client.utils.CloudRenderer;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
public class RenderCloudsFancy extends ClearingMethodVisitor
{
private boolean alreadyInjected;
public RenderCloudsFancy(final int n, final MethodVisitor methodVisitor) {
super(n, methodVisitor);
this.alreadyInjected = false;
}
@Override
public void visitMaxs(final int n, final int n2) {
super.visitMaxs(19, n2 - 7);
}
@Override
public void visitLocalVariable(final String s, final String s2, final String s3, final Label label, final Label label2, final int n) {
if (n < 39) {
super.visitLocalVariable(s, s2, s3, label, label2, n);
}
}
@Override
public void visitLineNumber(final int n, final Label label) {
if (n == 2237) {
this.clear = false;
}
else if (n == 2260 && !this.alreadyInjected) {
this.mv.visitFrame(3, 0, (Object[])null, 0, (Object[])null);
this.mv.visitVarInsn(25, 6);
this.mv.visitVarInsn(25, 5);
this.mv.visitVarInsn(23, 15);
this.mv.visitVarInsn(23, 32);
this.mv.visitVarInsn(23, 33);
this.mv.visitVarInsn(23, 19);
this.mv.visitVarInsn(23, 20);
this.mv.visitVarInsn(23, 21);
this.mv.visitVarInsn(23, 25);
this.mv.visitVarInsn(23, 26);
this.mv.visitVarInsn(23, 27);
this.mv.visitVarInsn(23, 28);
this.mv.visitVarInsn(23, 29);
this.mv.visitVarInsn(23, 30);
this.mv.visitVarInsn(23, 22);
this.mv.visitVarInsn(23, 23);
this.mv.visitVarInsn(23, 24);
this.mv.visitVarInsn(23, 34);
this.mv.visitVarInsn(23, 35);
this.mv.visitMethodInsn(184, SilentClientTransformer.getClassName(CloudRenderer.class), "renderFancyClouds", "(Lbfd;Lbfx;FFFFFFFFFFFFFFFFF)V");
this.mv.visitLabel(new Label());
this.alreadyInjected = true;
this.clear = true;
}
else if (n == 2264) {
this.clear = true;
}
else if (n == 2348) {
this.clear = false;
}
super.visitLineNumber(n, label);
}
}

View File

@ -0,0 +1,55 @@
package net.silentclient.client.mixin.visitors;
import net.silentclient.client.mixin.SilentClientTransformer;
import net.silentclient.client.utils.CloudRenderer;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
public class RenderCloudsFast extends ClearingMethodVisitor
{
private boolean alreadyInjected;
public RenderCloudsFast(final int n, final MethodVisitor methodVisitor) {
super(n, methodVisitor);
this.alreadyInjected = false;
}
@Override
public void visitMaxs(final int n, final int n2) {
super.visitMaxs(n, n2 - 2);
}
@Override
public void visitLocalVariable(final String s, final String s2, final String s3, final Label label, final Label label2, final int n) {
if (!s.equals("var24") && !s.equals("var25")) {
super.visitLocalVariable(s, s2, s3, label, label2, n);
}
}
@Override
public void visitLineNumber(final int n, final Label label) {
if (n == 2101) {
this.clear = true;
}
else if (n == 2103) {
this.clear = false;
}
else if (n == 2133 && !this.alreadyInjected) {
this.mv.visitVarInsn(25, 8);
this.mv.visitVarInsn(23, 22);
this.mv.visitVarInsn(23, 23);
this.mv.visitVarInsn(23, 24);
this.mv.visitVarInsn(23, 10);
this.mv.visitVarInsn(23, 11);
this.mv.visitVarInsn(23, 12);
this.mv.visitMethodInsn(184, SilentClientTransformer.getClassName(CloudRenderer.class), "renderFastClouds", "(Lbfd;FFFFFF)V");
this.mv.visitLabel(new Label());
this.alreadyInjected = true;
this.clear = true;
}
else if (n == 2144) {
this.clear = false;
}
super.visitLineNumber(n, label);
}
}

View File

@ -0,0 +1,97 @@
package net.silentclient.client.utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.silentclient.client.mods.settings.FPSBoostMod;
public class CloudRenderer
{
private static Frustum frustum;
public static void setFrustum(final Frustum frustum) {
CloudRenderer.frustum = frustum;
}
public static void renderFastClouds(final WorldRenderer bfd, final float n, final float n2, final float n3, final float n4, final float n5, final float n6) {
final double s = Minecraft.getMinecraft().getRenderViewEntity().posX;
final double t = Minecraft.getMinecraft().getRenderViewEntity().posY;
final double u = Minecraft.getMinecraft().getRenderViewEntity().posZ;
final boolean booleanValue = FPSBoostMod.basicEnabled();
for (int i = -256; i < 256; i += 32) {
for (int j = -256; j < 256; j += 32) {
if (CloudRenderer.frustum.isBoxInFrustum(i + s, n + t - 2.0, j + u, i + 32 + s, n + t, j + 32 + u) || !booleanValue) {
bfd.pos((double)(i + 0), (double)n, (double)(j + 32)).tex((double)((i + 0) * 4.8828125E-4f + n2), (double)((j + 32) * 4.8828125E-4f + n3)).color(n4, n5, n6, 0.8f).endVertex();
bfd.pos((double)(i + 32), (double)n, (double)(j + 32)).tex((double)((i + 32) * 4.8828125E-4f + n2), (double)((j + 32) * 4.8828125E-4f + n3)).color(n4, n5, n6, 0.8f).endVertex();
bfd.pos((double)(i + 32), (double)n, (double)(j + 0)).tex((double)((i + 32) * 4.8828125E-4f + n2), (double)((j + 0) * 4.8828125E-4f + n3)).color(n4, n5, n6, 0.8f).endVertex();
bfd.pos((double)(i + 0), (double)n, (double)(j + 0)).tex((double)((i + 0) * 4.8828125E-4f + n2), (double)((j + 0) * 4.8828125E-4f + n3)).color(n4, n5, n6, 0.8f).endVertex();
}
}
}
}
public static void renderFancyClouds(final WorldRenderer bfd, final Tessellator bfx, final float n, final float n2, final float n3, final float n4, final float n5, final float n6, final float n7, final float n8, final float n9, final float n10, final float n11, final float n12, final float n13, final float n14, final float n15, final float n16, final float n17) {
bfd.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);
final double s = Minecraft.getMinecraft().getRenderViewEntity().posX;
final double t = Minecraft.getMinecraft().getRenderViewEntity().posY;
final double u = Minecraft.getMinecraft().getRenderViewEntity().posZ;
final boolean booleanValue = FPSBoostMod.basicEnabled();
for (int i = -3; i <= 4; ++i) {
for (int j = -3; j <= 4; ++j) {
final float n18 = (float)(i * 8);
final float n19 = (float)(j * 8);
final float n20 = n18 - n16;
final float n21 = n19 - n17;
if (CloudRenderer.frustum.isBoxInFrustum(n20 * 12.0 + s, n + t, n21 * 12.0 + u, (n20 + 9.0f) * 12.0 + s, n + 4.0f + t, (n21 + 9.0f) * 12.0 + u) || !booleanValue) {
if (n > -5.0f) {
bfd.pos((double)(n20 + 0.0f), (double)(n + 0.0f), (double)(n21 + 8.0f)).tex((double)((n18 + 0.0f) * 0.00390625f + n2), (double)((n19 + 8.0f) * 0.00390625f + n3)).color(n7, n8, n9, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + 8.0f), (double)(n + 0.0f), (double)(n21 + 8.0f)).tex((double)((n18 + 8.0f) * 0.00390625f + n2), (double)((n19 + 8.0f) * 0.00390625f + n3)).color(n7, n8, n9, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + 8.0f), (double)(n + 0.0f), (double)(n21 + 0.0f)).tex((double)((n18 + 8.0f) * 0.00390625f + n2), (double)((n19 + 0.0f) * 0.00390625f + n3)).color(n7, n8, n9, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + 0.0f), (double)(n + 0.0f), (double)(n21 + 0.0f)).tex((double)((n18 + 0.0f) * 0.00390625f + n2), (double)((n19 + 0.0f) * 0.00390625f + n3)).color(n7, n8, n9, 0.8f).normal(0.0f, -1.0f, 0.0f).endVertex();
}
if (n <= 5.0f) {
bfd.pos((double)(n20 + 0.0f), (double)(n + 4.0f - 9.765625E-4f), (double)(n21 + 8.0f)).tex((double)((n18 + 0.0f) * 0.00390625f + n2), (double)((n19 + 8.0f) * 0.00390625f + n3)).color(n4, n5, n6, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + 8.0f), (double)(n + 4.0f - 9.765625E-4f), (double)(n21 + 8.0f)).tex((double)((n18 + 8.0f) * 0.00390625f + n2), (double)((n19 + 8.0f) * 0.00390625f + n3)).color(n4, n5, n6, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + 8.0f), (double)(n + 4.0f - 9.765625E-4f), (double)(n21 + 0.0f)).tex((double)((n18 + 8.0f) * 0.00390625f + n2), (double)((n19 + 0.0f) * 0.00390625f + n3)).color(n4, n5, n6, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + 0.0f), (double)(n + 4.0f - 9.765625E-4f), (double)(n21 + 0.0f)).tex((double)((n18 + 0.0f) * 0.00390625f + n2), (double)((n19 + 0.0f) * 0.00390625f + n3)).color(n4, n5, n6, 0.8f).normal(0.0f, 1.0f, 0.0f).endVertex();
}
if (i > -1) {
for (int k = 0; k < 8; ++k) {
bfd.pos((double)(n20 + k + 0.0f), (double)(n + 0.0f), (double)(n21 + 8.0f)).tex((double)((n18 + k + 0.5f) * 0.00390625f + n2), (double)((n19 + 8.0f) * 0.00390625f + n3)).color(n13, n14, n15, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + k + 0.0f), (double)(n + 4.0f), (double)(n21 + 8.0f)).tex((double)((n18 + k + 0.5f) * 0.00390625f + n2), (double)((n19 + 8.0f) * 0.00390625f + n3)).color(n13, n14, n15, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + k + 0.0f), (double)(n + 4.0f), (double)(n21 + 0.0f)).tex((double)((n18 + k + 0.5f) * 0.00390625f + n2), (double)((n19 + 0.0f) * 0.00390625f + n3)).color(n13, n14, n15, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + k + 0.0f), (double)(n + 0.0f), (double)(n21 + 0.0f)).tex((double)((n18 + k + 0.5f) * 0.00390625f + n2), (double)((n19 + 0.0f) * 0.00390625f + n3)).color(n13, n14, n15, 0.8f).normal(-1.0f, 0.0f, 0.0f).endVertex();
}
}
if (i <= 1) {
for (int l = 0; l < 8; ++l) {
bfd.pos((double)(n20 + l + 1.0f - 9.765625E-4f), (double)(n + 0.0f), (double)(n21 + 8.0f)).tex((double)((n18 + l + 0.5f) * 0.00390625f + n2), (double)((n19 + 8.0f) * 0.00390625f + n3)).color(n13, n14, n15, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + l + 1.0f - 9.765625E-4f), (double)(n + 4.0f), (double)(n21 + 8.0f)).tex((double)((n18 + l + 0.5f) * 0.00390625f + n2), (double)((n19 + 8.0f) * 0.00390625f + n3)).color(n13, n14, n15, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + l + 1.0f - 9.765625E-4f), (double)(n + 4.0f), (double)(n21 + 0.0f)).tex((double)((n18 + l + 0.5f) * 0.00390625f + n2), (double)((n19 + 0.0f) * 0.00390625f + n3)).color(n13, n14, n15, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
bfd.pos((double)(n20 + l + 1.0f - 9.765625E-4f), (double)(n + 0.0f), (double)(n21 + 0.0f)).tex((double)((n18 + l + 0.5f) * 0.00390625f + n2), (double)((n19 + 0.0f) * 0.00390625f + n3)).color(n13, n14, n15, 0.8f).normal(1.0f, 0.0f, 0.0f).endVertex();
}
}
if (j > -1) {
for (int n22 = 0; n22 < 8; ++n22) {
bfd.pos((double)(n20 + 0.0f), (double)(n + 4.0f), (double)(n21 + n22 + 0.0f)).tex((double)((n18 + 0.0f) * 0.00390625f + n2), (double)((n19 + n22 + 0.5f) * 0.00390625f + n3)).color(n10, n11, n12, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
bfd.pos((double)(n20 + 8.0f), (double)(n + 4.0f), (double)(n21 + n22 + 0.0f)).tex((double)((n18 + 8.0f) * 0.00390625f + n2), (double)((n19 + n22 + 0.5f) * 0.00390625f + n3)).color(n10, n11, n12, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
bfd.pos((double)(n20 + 8.0f), (double)(n + 0.0f), (double)(n21 + n22 + 0.0f)).tex((double)((n18 + 8.0f) * 0.00390625f + n2), (double)((n19 + n22 + 0.5f) * 0.00390625f + n3)).color(n10, n11, n12, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
bfd.pos((double)(n20 + 0.0f), (double)(n + 0.0f), (double)(n21 + n22 + 0.0f)).tex((double)((n18 + 0.0f) * 0.00390625f + n2), (double)((n19 + n22 + 0.5f) * 0.00390625f + n3)).color(n10, n11, n12, 0.8f).normal(0.0f, 0.0f, -1.0f).endVertex();
}
}
if (j <= 1) {
for (int n23 = 0; n23 < 8; ++n23) {
bfd.pos((double)(n20 + 0.0f), (double)(n + 4.0f), (double)(n21 + n23 + 1.0f - 9.765625E-4f)).tex((double)((n18 + 0.0f) * 0.00390625f + n2), (double)((n19 + n23 + 0.5f) * 0.00390625f + n3)).color(n10, n11, n12, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
bfd.pos((double)(n20 + 8.0f), (double)(n + 4.0f), (double)(n21 + n23 + 1.0f - 9.765625E-4f)).tex((double)((n18 + 8.0f) * 0.00390625f + n2), (double)((n19 + n23 + 0.5f) * 0.00390625f + n3)).color(n10, n11, n12, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
bfd.pos((double)(n20 + 8.0f), (double)(n + 0.0f), (double)(n21 + n23 + 1.0f - 9.765625E-4f)).tex((double)((n18 + 8.0f) * 0.00390625f + n2), (double)((n19 + n23 + 0.5f) * 0.00390625f + n3)).color(n10, n11, n12, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
bfd.pos((double)(n20 + 0.0f), (double)(n + 0.0f), (double)(n21 + n23 + 1.0f - 9.765625E-4f)).tex((double)((n18 + 0.0f) * 0.00390625f + n2), (double)((n19 + n23 + 0.5f) * 0.00390625f + n3)).color(n10, n11, n12, 0.8f).normal(0.0f, 0.0f, 1.0f).endVertex();
}
}
}
}
}
bfx.draw();
}
}