Skip to content

Commit

Permalink
Rework coremod and transformers. Fixes CleanroomMC/Cleanroom#32
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadl7 committed Jul 16, 2024
1 parent 1db774e commit 498643b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 308 deletions.
44 changes: 32 additions & 12 deletions src/main/java/lain/mods/skins/init/forge/asm/ASMTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.objectweb.asm.Opcodes;
import net.minecraft.launchwrapper.IClassTransformer;

@SuppressWarnings("unused")
public class ASMTransformer implements IClassTransformer
{

Expand All @@ -29,7 +30,8 @@ public void visitInsn(int opcode)
this.visitVarInsn(Opcodes.ASTORE, 1);
this.visitVarInsn(Opcodes.ALOAD, 0);
this.visitVarInsn(Opcodes.ALOAD, 1);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "getLocationCape", "(Lnet/minecraft/client/entity/AbstractClientPlayer;Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation;", false);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "getLocationCape",
"(Lnet/minecraft/client/entity/AbstractClientPlayer;Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation;", false);
}
super.visitInsn(opcode);
}
Expand All @@ -52,7 +54,8 @@ public void visitInsn(int opcode)
this.visitVarInsn(Opcodes.ASTORE, 1);
this.visitVarInsn(Opcodes.ALOAD, 0);
this.visitVarInsn(Opcodes.ALOAD, 1);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "getLocationSkin", "(Lnet/minecraft/client/entity/AbstractClientPlayer;Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation;", false);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "getLocationSkin",
"(Lnet/minecraft/client/entity/AbstractClientPlayer;Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation;", false);
}
super.visitInsn(opcode);
}
Expand All @@ -75,16 +78,23 @@ public void visitInsn(int opcode)
this.visitVarInsn(Opcodes.ASTORE, 1);
this.visitVarInsn(Opcodes.ALOAD, 0);
this.visitVarInsn(Opcodes.ALOAD, 1);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "getSkinType", "(Lnet/minecraft/client/entity/AbstractClientPlayer;Ljava/lang/String;)Ljava/lang/String;", false);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "getSkinType",
"(Lnet/minecraft/client/entity/AbstractClientPlayer;Ljava/lang/String;)Ljava/lang/String;", false);
}
super.visitInsn(opcode);
}

}

ObfHelper m001 = ObfHelper.newMethod("func_110303_q", "net/minecraft/client/entity/AbstractClientPlayer", "()Lnet/minecraft/util/ResourceLocation;").setDevName("getLocationCape");
ObfHelper m002 = ObfHelper.newMethod("func_110306_p", "net/minecraft/client/entity/AbstractClientPlayer", "()Lnet/minecraft/util/ResourceLocation;").setDevName("getLocationSkin");
ObfHelper m003 = ObfHelper.newMethod("func_175154_l", "net/minecraft/client/entity/AbstractClientPlayer", "()Ljava/lang/String;").setDevName("getSkinType");
ObfHelper m001 = ObfHelper.newMethod("func_110303_q", "getLocationCape",
"net/minecraft/client/entity/AbstractClientPlayer",
"()Lnet/minecraft/util/ResourceLocation;");
ObfHelper m002 = ObfHelper.newMethod("func_110306_p", "getLocationSkin",
"net/minecraft/client/entity/AbstractClientPlayer",
"()Lnet/minecraft/util/ResourceLocation;");
ObfHelper m003 = ObfHelper.newMethod("func_175154_l", "getSkinType",
"net/minecraft/client/entity/AbstractClientPlayer",
"()Ljava/lang/String;");

public transformer001(ClassVisitor cv)
{
Expand All @@ -111,7 +121,9 @@ class transformer002 extends ClassVisitor
class method001 extends MethodVisitor
{

ObfHelper target = ObfHelper.newMethod("func_147499_a", "net/minecraft/client/renderer/tileentity/TileEntitySpecialRenderer", "(Lnet/minecraft/util/ResourceLocation;)V").setDevName("bindTexture");
ObfHelper target = ObfHelper.newMethod("func_147499_a", "bindTexture",
"net/minecraft/client/renderer/tileentity/TileEntitySpecialRenderer",
"(Lnet/minecraft/util/ResourceLocation;)V");

int lastALOAD = -1;

Expand All @@ -128,7 +140,8 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
this.visitInsn(Opcodes.POP);
this.visitVarInsn(Opcodes.ALOAD, 7);
this.visitVarInsn(Opcodes.ALOAD, 11);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "TileEntitySkullRenderer_bindTexture", "(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation;", false);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "TileEntitySkullRenderer_bindTexture",
"(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation;", false);
this.visitVarInsn(Opcodes.ASTORE, 11);
this.visitVarInsn(Opcodes.ALOAD, 11);
}
Expand All @@ -145,7 +158,9 @@ public void visitVarInsn(int opcode, int var)

}

ObfHelper m001 = ObfHelper.newMethod("func_188190_a", "net/minecraft/client/renderer/tileentity/TileEntitySkullRenderer", "(FFFLnet/minecraft/util/EnumFacing;FILcom/mojang/authlib/GameProfile;IF)V").setDevName("renderSkull");
ObfHelper m001 = ObfHelper.newMethod("func_188190_a", "renderSkull",
"net/minecraft/client/renderer/tileentity/TileEntitySkullRenderer",
"(FFFLnet/minecraft/util/EnumFacing;FILcom/mojang/authlib/GameProfile;IF)V");

public transformer002(ClassVisitor cv)
{
Expand All @@ -168,7 +183,9 @@ class transformer003 extends ClassVisitor
class method001 extends MethodVisitor
{

ObfHelper target = ObfHelper.newMethod("func_110577_a", "net/minecraft/client/renderer/texture/TextureManager", "(Lnet/minecraft/util/ResourceLocation;)V").setDevName("bindTexture");
ObfHelper target = ObfHelper.newMethod("func_110577_a", "bindTexture",
"net/minecraft/client/renderer/texture/TextureManager",
"(Lnet/minecraft/util/ResourceLocation;)V");

public method001(MethodVisitor mv)
{
Expand All @@ -183,7 +200,8 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
this.visitVarInsn(Opcodes.ASTORE, 32);
this.visitVarInsn(Opcodes.ALOAD, 25);
this.visitVarInsn(Opcodes.ALOAD, 32);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "GuiPlayerTabOverlay_bindTexture", "(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation;", false);
this.visitMethodInsn(Opcodes.INVOKESTATIC, "lain/mods/skins/init/forge/asm/Hooks", "GuiPlayerTabOverlay_bindTexture",
"(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/util/ResourceLocation;)Lnet/minecraft/util/ResourceLocation;", false);
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
Expand All @@ -201,7 +219,9 @@ public void visitVarInsn(int opcode, int var)

}

ObfHelper m001 = ObfHelper.newMethod("func_175249_a", "net/minecraft/client/gui/GuiPlayerTabOverlay", "(ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V").setDevName("renderPlayerlist");
ObfHelper m001 = ObfHelper.newMethod("func_175249_a", "renderPlayerlist",
"net/minecraft/client/gui/GuiPlayerTabOverlay",
"(ILnet/minecraft/scoreboard/Scoreboard;Lnet/minecraft/scoreboard/ScoreObjective;)V");

public transformer003(ClassVisitor cv)
{
Expand Down
1 change: 1 addition & 0 deletions src/main/java/lain/mods/skins/init/forge/asm/Hooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.Loader;

@SuppressWarnings("unused")
public class Hooks
{

Expand Down
177 changes: 9 additions & 168 deletions src/main/java/lain/mods/skins/init/forge/asm/ObfHelper.java
Original file line number Diff line number Diff line change
@@ -1,189 +1,30 @@
package lain.mods.skins.init.forge.asm;

import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.Validate;
import com.google.common.collect.ImmutableList;

public class ObfHelper
{
public class ObfHelper {

public static ObfHelper newClass(String className)
{
Validate.notNull(className);
ObfHelper result = new ObfHelper();
result.type = 2;
result.data[0] = className;
result.transform(!Plugin.runtimeDeobfuscationEnabled);
return result;
}

public static ObfHelper newField(String fieldName, String ownerName, String descriptor)
{
Validate.notNull(fieldName);
Validate.notNull(ownerName);
Validate.notNull(descriptor);
ObfHelper result = new ObfHelper();
result.type = 3;
result.data[0] = ownerName;
result.data[1] = fieldName;
result.data[2] = descriptor;
result.transform(!Plugin.runtimeDeobfuscationEnabled);
return result;
}

public static ObfHelper newMethod(String methodName, String ownerName, String descriptor)
{
public static ObfHelper newMethod(String obfuscatedName, String methodName, String ownerName, String descriptor) {
Validate.notNull(methodName);
Validate.notNull(ownerName);
Validate.notNull(descriptor);
ObfHelper result = new ObfHelper();
result.type = 4;
result.data[0] = ownerName;
result.data[1] = methodName;
result.data[2] = descriptor;
result.transform(!Plugin.runtimeDeobfuscationEnabled);
return result;
}

public static ObfHelper newPackage(String packageName)
{
Validate.notNull(packageName);
ObfHelper result = new ObfHelper();
result.type = 1;
result.data[0] = packageName;
result.transform(!Plugin.runtimeDeobfuscationEnabled);
return result;
}

private int type;
private String[] data = new String[3];

private ObfHelper()
{
}

public String getData(int index)
{
if (index >= 0 && index <= 2)
return data[index];
return null;
}

public int getType()
{
return type;
private ObfHelper() {
}

public boolean match(Object... obj)
{
switch (type)
{
case 1:
if (obj.length == 1)
return data[0].equals(obj[0]);
break;
case 2:
if (obj.length == 1)
return data[0].equals(obj[0]);
break;
case 3:
if (obj.length == 1)
return data[1].equals(obj[0]);
else if (obj.length == 2)
return data[0].equals(obj[0]) && data[1].equals(obj[1]);
break;
case 4:
if (obj.length == 2)
return data[1].equals(obj[0]) && data[2].equals(obj[1]);
else if (obj.length == 3)
return data[0].equals(obj[0]) && data[1].equals(obj[1]) && data[2].equals(obj[2]);
break;
}
public boolean match(Object... obj) {
if (obj.length == 2)
return data[1].equals(obj[0]) && data[2].equals(obj[1]);
else if (obj.length == 3)
return data[0].equals(obj[0]) && data[1].equals(obj[1]) && data[2].equals(obj[2]);
return false;
}

public ObfHelper setDevName(String name)
{
return setDevName(name, Plugin.isDevelopmentEnvironment);
}

private ObfHelper setDevName(String name, boolean devEnv)
{
if (devEnv)
{
switch (type)
{
case 1:
data[0] = name;
break;
case 2:
data[0] = name;
break;
case 3:
data[1] = name;
break;
case 4:
data[1] = name;
break;
}
}
return this;
}

@Override
public String toString()
{
switch (type)
{
case 1:
return String.format("ObfHelper:Package{%s}", data[0]);
case 2:
return String.format("ObfHelper:Class{%s}", data[0]);
case 3:
return String.format("ObfHelper:Field{%s/%s %s}", data[0], data[1], data[2]);
case 4:
return String.format("ObfHelper:Method{%s/%s %s}", data[0], data[1], data[2]);
}
return String.format("ObfHelper:Unknown(%d){%s %s %s}", type, data[0], data[1], data[2]);
}

private void transform(boolean deobfuscated)
{
switch (type)
{
case 1:
Map<String, String> map1 = deobfuscated ? Setup.PackageMap : Setup.PackageMap.inverse();
if (map1.containsKey(data[0]))
data[0] = map1.get(data[0]);
break;
case 2:
Map<String, String> map2 = deobfuscated ? Setup.ClassMap : Setup.ClassMap.inverse();
if (map2.containsKey(data[0]))
data[0] = map2.get(data[0]);
break;
case 3:
Map<List<String>, List<String>> map3 = deobfuscated ? Setup.FieldMap : Setup.FieldMap.inverse();
List<String> list3 = ImmutableList.of(data[0], data[1]);
if (map3.containsKey(list3))
{
list3 = map3.get(list3);
data[0] = list3.get(0);
data[1] = list3.get(1);
}
break;
case 4:
Map<List<String>, List<String>> map4 = deobfuscated ? Setup.MethodMap : Setup.MethodMap.inverse();
List<String> list4 = ImmutableList.of(data[0], data[1], data[2]);
if (map4.containsKey(list4))
{
list4 = map4.get(list4);
data[0] = list4.get(0);
data[1] = list4.get(1);
data[2] = list4.get(2);
}
break;
}
}

}

9 changes: 2 additions & 7 deletions src/main/java/lain/mods/skins/init/forge/asm/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public class Plugin implements IFMLLoadingPlugin
{

public static boolean runtimeDeobfuscationEnabled = false;
public static boolean isDevelopmentEnvironment = false;

@Override
public String getAccessTransformerClass()
Expand All @@ -33,14 +32,10 @@ public String getModContainerClass()
@Override
public String getSetupClass()
{
return "lain.mods.skins.init.forge.asm.Setup";
return null;
}

@Override
public void injectData(Map<String, Object> data)
{
runtimeDeobfuscationEnabled = (Boolean) data.get("runtimeDeobfuscationEnabled");
isDevelopmentEnvironment = (getClass().getResource("/binpatches.pack.lzma") == null);
}
public void injectData(Map<String, Object> data) {}

}
Loading

0 comments on commit 498643b

Please sign in to comment.