Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
remove unused ASM (#371)
Browse files Browse the repository at this point in the history
* remove unused ASM

* accidentally removed too much

* Remove RWG ASM

* spotlessApply

---------

Co-authored-by: Caedis <[email protected]>
Co-authored-by: GitHub GTNH Actions <unknown>
  • Loading branch information
bombcar and Caedis authored Nov 30, 2023
1 parent 815ca22 commit 32fb2a9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 210 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Any issues with this code should be reported to the [GTNH GitHub](https://github

## License

GTNH modifications Copyright (c) 2021-2022 The GTNH Team
GTNH modifications Copyright (c) 2021-2024 The GTNH Team

This code is licensed LGPL v3.0 or later. Feel free to use our changes, just give back any changes you make to the community as well!

Original code Copyright (c) bartimaeusnek 2018-2020 and was released under the MIT license.
Original code Copyright (c) bartimaeusnek 2018-2020 and was released under the MIT license.
12 changes: 0 additions & 12 deletions repositories.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
// Add any additional repositories for your dependencies here

repositories {
ivy {
url 'https://files.vexatos.com/'
patternLayout {
artifact "[module]/[artifact]-[revision](-[classifier])(.[ext])"
}
content {
includeGroup("TGregworks")
}
metadataSources {
artifact()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,12 @@
import static org.objectweb.asm.Opcodes.ALOAD;
import static org.objectweb.asm.Opcodes.ARETURN;
import static org.objectweb.asm.Opcodes.GETFIELD;
import static org.objectweb.asm.Opcodes.GETSTATIC;
import static org.objectweb.asm.Opcodes.GOTO;
import static org.objectweb.asm.Opcodes.ICONST_0;
import static org.objectweb.asm.Opcodes.IFEQ;
import static org.objectweb.asm.Opcodes.IFNE;
import static org.objectweb.asm.Opcodes.IF_ICMPGE;
import static org.objectweb.asm.Opcodes.ILOAD;
import static org.objectweb.asm.Opcodes.INSTANCEOF;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
import static org.objectweb.asm.Opcodes.INVOKEVIRTUAL;
import static org.objectweb.asm.Opcodes.IREM;
import static org.objectweb.asm.Opcodes.IRETURN;
import static org.objectweb.asm.Opcodes.ISTORE;
import static org.objectweb.asm.Opcodes.POP;
import static org.objectweb.asm.Opcodes.SIPUSH;

import java.util.Arrays;
import java.util.List;
Expand All @@ -46,34 +37,25 @@
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 org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeInsnNode;
import org.objectweb.asm.tree.VarInsnNode;

public class BWCoreTransformer implements IClassTransformer {

public static final String[] DESCRIPTIONFORCONFIG = { "REMOVING RAIN FROM LAST MILLENIUM (EXU)",
"REMVOING CREATURES FROM LAST MILLENIUM (EXU)", "PATCHING GLOBAL RENDERER FOR USE WITH MY GALACTIC DIMS",
public static final String[] DESCRIPTIONFORCONFIG = { "REMOVING RAIN FROM LAST MILLENNIUM (EXU)",
"REMOVING CREATURES FROM LAST MILLENNIUM (EXU)",
"PATCHING THAUMCRAFT WAND PEDESTAL TO PREVENT VIS DUPLICATION",
"[UNUSED] PLACING MY GLASS-BLOCK RUNNABLE INTO THE GT_API", "DUCTTAPING RWG WORLDEN FAILS",
"PATCHING CRAFTING MANAGER FOR CACHING RECIPES"
// "REMOVING 12% BONUS OUTPUTS FROM GT++ SIFTER"
};
public static final String[] CLASSESBEEINGTRANSFORMED = {
"PATCHING CRAFTING MANAGER FOR CACHING RECIPES" };
public static final String[] CLASSESBEINGTRANSFORMED = {
"com.rwtema.extrautils.worldgen.endoftime.WorldProviderEndOfTime",
"com.rwtema.extrautils.worldgen.endoftime.ChunkProviderEndOfTime",
"net.minecraft.client.renderer.RenderGlobal", "thaumcraft.common.tiles.TileWandPedestal", "gregtech.GT_Mod",
"rwg.world.ChunkGeneratorRealistic", "net.minecraft.item.crafting.CraftingManager"
// "gtPlusPlus.xmod.gregtech.common.tileentities.machines.multi.processing.GregtechMetaTileEntity_IndustrialSifter"
};
"thaumcraft.common.tiles.TileWandPedestal", "net.minecraft.item.crafting.CraftingManager" };
static boolean obfs;

public static boolean[] shouldTransform = new boolean[BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length];
public static boolean[] shouldTransform = new boolean[BWCoreTransformer.CLASSESBEINGTRANSFORMED.length];

/**
* Made by DarkShaddow44
Expand Down Expand Up @@ -121,15 +103,15 @@ public static byte[] transform(int id, byte[] basicClass) {
return basicClass;
}

if (id < BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length) {
if (id < BWCoreTransformer.CLASSESBEINGTRANSFORMED.length) {
BWCore.BWCORE_LOG.info(BWCoreTransformer.DESCRIPTIONFORCONFIG[id]);
ClassReader classReader = new ClassReader(basicClass);
ClassNode classNode = new ClassNode();
classReader.accept(classNode, ClassReader.SKIP_FRAMES);
List<MethodNode> methods = classNode.methods;
scase: switch (id) {
case 0: {
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]);
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]);
String name_deObfs = "canDoRainSnowIce";

String dsc_deObfs = "(Lnet/minecraft/world/chunk/Chunk;)Z";
Expand All @@ -152,7 +134,7 @@ public static byte[] transform(int id, byte[] basicClass) {
break;
}
case 1: {
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]);
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]);
String name_deObfs = "getPossibleCreatures";
String name_src = "func_73155_a";
String name_Obfs = "a";
Expand All @@ -176,127 +158,7 @@ public static byte[] transform(int id, byte[] basicClass) {
}
}
case 2: {
String name_deObfs = "renderSky";
String name_src = "func_72714_a";
String name_Obfs = "a";
String dsc_universal = "(F)V";
String field_deObfs = "locationSunPng";
String field_src = "field_110928_i";
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]);
for (MethodNode toPatch : methods) {
if (ASMUtils.isCorrectMethod(toPatch, name_deObfs, name_Obfs, name_src)
&& ASMUtils.isCorrectMethod(toPatch, dsc_universal)) {
BWCore.BWCORE_LOG.info("Found " + name_deObfs + "! Patching!");
InsnList nu = new InsnList();
LabelNode[] LabelNodes = { new LabelNode(), new LabelNode() };

String theWorld_src = "field_72769_h";
String renderEngine_src = "field_72770_i";
String provider_src = "field_73011_w";
String bindTexture_src = "func_110577_a";
String nameFieldToPatch;

for (int j = 0; j < toPatch.instructions.size(); j++) {
if (toPatch.instructions.get(j) instanceof FieldInsnNode
&& toPatch.instructions.get(j).getOpcode() == GETSTATIC
&& !(nameFieldToPatch = ASMUtils.matchAny(
((FieldInsnNode) toPatch.instructions.get(j)).name,
field_deObfs,
field_src)).isEmpty()) {
boolean useSrc = nameFieldToPatch.equals(field_src);
if (useSrc) BWCore.BWCORE_LOG.info(
"Found either Optifine or Fastcraft... this patch was annoying to make compatible to them...");

nu.add(new VarInsnNode(ALOAD, 0));
nu.add(
new FieldInsnNode(
GETFIELD,
"net/minecraft/client/renderer/RenderGlobal",
useSrc ? theWorld_src : "theWorld",
"Lnet/minecraft/client/multiplayer/WorldClient;"));
nu.add(
new FieldInsnNode(
GETFIELD,
"net/minecraft/client/multiplayer/WorldClient",
useSrc ? provider_src : "provider",
"Lnet/minecraft/world/WorldProvider;"));
nu.add(
new TypeInsnNode(
INSTANCEOF,
"com/github/bartimaeusnek/crossmod/galacticraft/planets/AbstractWorldProviderSpace"));
nu.add(new JumpInsnNode(IFEQ, LabelNodes[0]));
nu.add(new VarInsnNode(ALOAD, 0));
nu.add(
new FieldInsnNode(
GETFIELD,
"net/minecraft/client/renderer/RenderGlobal",
useSrc ? renderEngine_src : "renderEngine",
"Lnet/minecraft/client/renderer/texture/TextureManager;"));
nu.add(
new FieldInsnNode(
GETSTATIC,
"com/github/bartimaeusnek/crossmod/galacticraft/planets/ross128b/SkyProviderRoss128b",
"sunTex",
"Lnet/minecraft/util/ResourceLocation;"));
nu.add(
new MethodInsnNode(
INVOKEVIRTUAL,
"net/minecraft/client/renderer/texture/TextureManager",
useSrc ? bindTexture_src : "bindTexture",
"(Lnet/minecraft/util/ResourceLocation;)V",
false));
nu.add(new JumpInsnNode(GOTO, LabelNodes[1]));
nu.add(LabelNodes[0]);
nu.add(new VarInsnNode(ALOAD, 0));
nu.add(
new FieldInsnNode(
GETFIELD,
"net/minecraft/client/renderer/RenderGlobal",
useSrc ? renderEngine_src : "renderEngine",
"Lnet/minecraft/client/renderer/texture/TextureManager;"));
nu.add(
new FieldInsnNode(
GETSTATIC,
"net/minecraft/client/renderer/RenderGlobal",
useSrc ? field_src : "locationSunPng",
"Lnet/minecraft/util/ResourceLocation;"));
nu.add(
new MethodInsnNode(
INVOKEVIRTUAL,
"net/minecraft/client/renderer/texture/TextureManager",
useSrc ? bindTexture_src : "bindTexture",
"(Lnet/minecraft/util/ResourceLocation;)V",
false));
nu.add(LabelNodes[1]);
j++;

} else {
if (j < toPatch.instructions.size() - 2) {
if (toPatch.instructions.get(j + 2) instanceof FieldInsnNode
&& toPatch.instructions.get(j + 2).getOpcode() == GETSTATIC
&& !ASMUtils.matchAny(
((FieldInsnNode) toPatch.instructions.get(j + 2)).name,
field_deObfs,
field_src).isEmpty())
continue;
if (toPatch.instructions.get(j + 1) instanceof FieldInsnNode
&& toPatch.instructions.get(j + 1).getOpcode() == GETSTATIC
&& !ASMUtils.matchAny(
((FieldInsnNode) toPatch.instructions.get(j + 1)).name,
field_deObfs,
field_src).isEmpty())
continue;
}
nu.add(toPatch.instructions.get(j));
}
}
toPatch.instructions = nu;
break scase;
}
}
}
case 3: {
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]);
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]);
String name_deObfs = "updateEntity";
String name_src = "func_145845_h";
String name_Obfs = "h";
Expand All @@ -311,47 +173,8 @@ public static byte[] transform(int id, byte[] basicClass) {
}
}
}
case 4: {
break;
}
case 5: {
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]);
String name_deObfs = "getNewNoise";
for (MethodNode toPatch : methods) {
if (ASMUtils.isCorrectMethod(toPatch, name_deObfs)) {
BWCore.BWCORE_LOG.info("Found " + name_deObfs + "! Patching!");
LabelNode[] LabelNodes = { new LabelNode(), new LabelNode() };
InsnList nu = new InsnList();
// if (x < -28675) x %= -28675;
nu.add(new VarInsnNode(ILOAD, 2));
nu.add(new IntInsnNode(SIPUSH, -28675));
nu.add(new JumpInsnNode(IF_ICMPGE, LabelNodes[0]));
nu.add(new VarInsnNode(ILOAD, 2));
nu.add(new LdcInsnNode(-28675));
nu.add(new InsnNode(IREM));
nu.add(new VarInsnNode(ISTORE, 2));
nu.add(LabelNodes[0]);
// if (y < -28675) y %= -28675;
nu.add(new VarInsnNode(ILOAD, 3));
nu.add(new IntInsnNode(SIPUSH, -28675));
nu.add(new JumpInsnNode(IF_ICMPGE, LabelNodes[1]));
nu.add(new VarInsnNode(ILOAD, 3));
nu.add(new LdcInsnNode(-28675));
nu.add(new InsnNode(IREM));
nu.add(new VarInsnNode(ISTORE, 3));
nu.add(LabelNodes[1]);

for (int j = 1; j < toPatch.instructions.size(); j++) {
nu.add(toPatch.instructions.get(j));
}

toPatch.instructions = nu;
break scase;
}
}
}
case 6: {
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]);
case 3: {
BWCore.BWCORE_LOG.info("Could find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]);
String name_deObfs = "findMatchingRecipe";
String name_Obfs = "a";
String name_src = "func_82787_a";
Expand All @@ -377,7 +200,7 @@ public static byte[] transform(int id, byte[] basicClass) {
}

default: {
BWCore.BWCORE_LOG.info("Could not find: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]);
BWCore.BWCORE_LOG.info("Could not find: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]);
return basicClass;
}
}
Expand All @@ -387,17 +210,17 @@ public static byte[] transform(int id, byte[] basicClass) {
classNode.accept(classWriter);
byte[] ret = classWriter.toByteArray();
if (Arrays.hashCode(basicClass) == Arrays.hashCode(ret))
BWCore.BWCORE_LOG.warn("Could not patch: " + BWCoreTransformer.CLASSESBEEINGTRANSFORMED[id]);
BWCore.BWCORE_LOG.warn("Could not patch: " + BWCoreTransformer.CLASSESBEINGTRANSFORMED[id]);
return ret;
}
return basicClass;
}

@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
for (int i = 0; i < BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length; i++) {
if (name.equalsIgnoreCase(BWCoreTransformer.CLASSESBEEINGTRANSFORMED[i])
|| transformedName.equalsIgnoreCase(BWCoreTransformer.CLASSESBEEINGTRANSFORMED[i]))
for (int i = 0; i < BWCoreTransformer.CLASSESBEINGTRANSFORMED.length; i++) {
if (name.equalsIgnoreCase(BWCoreTransformer.CLASSESBEINGTRANSFORMED[i])
|| transformedName.equalsIgnoreCase(BWCoreTransformer.CLASSESBEINGTRANSFORMED[i]))
return BWCoreTransformer.transform(i, basicClass);
}
return basicClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ public ConfigHandler(Configuration C) {
API_ConfigValues.debugLog = ConfigHandler.c
.get("System", "Enable Debug Log", false, "Enables or Disables the debug log.").getBoolean(false);

for (int i = 0; i < BWCoreTransformer.CLASSESBEEINGTRANSFORMED.length; i++)
for (int i = 0; i < BWCoreTransformer.CLASSESBEINGTRANSFORMED.length; i++)
BWCoreTransformer.shouldTransform[i] = ConfigHandler.c.get(
"ASM fixes",
BWCoreTransformer.DESCRIPTIONFORCONFIG[i] + " in class: "
+ BWCoreTransformer.CLASSESBEEINGTRANSFORMED[i],
+ BWCoreTransformer.CLASSESBEINGTRANSFORMED[i],
true).getBoolean(true);

ConfigHandler.enabledPatches = new boolean[BWCoreTransformer.shouldTransform.length];
Expand Down

0 comments on commit 32fb2a9

Please sign in to comment.