Remove updateGameProfile transformer. (#143)

* Add an option to control updateGameProfile transformer.

* Remove unnecessary FrameNodes
This commit is contained in:
ZekerZhayard authored and GitHub committed 2021-02-08 11:37:04 +08:00
1 parent ea5d890992
commit 98681e8251
4 files changed
+23 -3

No files matched your search

@@ -27,6 +27,7 @@ public class Config {
public boolean forceIgnoreHttpsCertificate = false;
public boolean forceLoadAllTextures=false;
public boolean enableCape = true;
public boolean forceFillSkullNBT = false;
public int threadPoolSize = 3;
public int retryTime = 1;
+10 -2
View File
@@ -2,6 +2,8 @@ var ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI');
var Opcodes = Java.type('org.objectweb.asm.Opcodes');
var FieldInsnNode = Java.type('org.objectweb.asm.tree.FieldInsnNode');
var InsnNode = Java.type('org.objectweb.asm.tree.InsnNode');
var JumpInsnNode = Java.type('org.objectweb.asm.tree.JumpInsnNode');
var LabelNode = Java.type('org.objectweb.asm.tree.LabelNode');
var MethodInsnNode = Java.type('org.objectweb.asm.tree.MethodInsnNode');
var VarInsnNode = Java.type('org.objectweb.asm.tree.VarInsnNode');
@@ -55,8 +57,14 @@ function initializeCoreMod() {
'transformer': function (cn) {
cn.methods.forEach(function (mn) {
if (checkName(mn.name, "func_174884_b", "updateGameProfile")) {
mn.instructions.insert(new InsnNode(Opcodes.ARETURN));
mn.instructions.insert(new VarInsnNode(Opcodes.ALOAD, 0));
var first = mn.instructions.getFirst();
var label = new LabelNode();
mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETSTATIC, "customskinloader/CustomSkinLoader", "config", "Lcustomskinloader/config/Config;"));
mn.instructions.insertBefore(first, new FieldInsnNode(Opcodes.GETFIELD, "customskinloader/config/Config", "forceFillSkullNBT", "Z"));
mn.instructions.insertBefore(first, new JumpInsnNode(Opcodes.IFNE, label));
mn.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 0));
mn.instructions.insertBefore(first, new InsnNode(Opcodes.ARETURN));
mn.instructions.insertBefore(first, label);
}
});
return cn;
@@ -3,9 +3,12 @@ package customskinloader.forge.transformer;
import customskinloader.forge.TransformerManager;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FrameNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.InsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LabelNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;
@@ -19,8 +22,13 @@ public class TileEntitySkullTransformer {
@Override
public MethodNode transform(ClassNode cn, MethodNode mn) {
InsnList il = new InsnList();
LabelNode ln = new LabelNode();
il.add(new FieldInsnNode(Opcodes.GETSTATIC, "customskinloader/CustomSkinLoader", "config", "Lcustomskinloader/config/Config;"));
il.add(new FieldInsnNode(Opcodes.GETFIELD, "customskinloader/config/Config", "forceFillSkullNBT", "Z"));
il.add(new JumpInsnNode(Opcodes.IFNE, ln));
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
il.add(new InsnNode(Opcodes.ARETURN));
il.add(ln);
il.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null));
mn.instructions.insert(il);
return mn;
@@ -1,6 +1,7 @@
package customskinloader.mixin;
import com.mojang.authlib.GameProfile;
import customskinloader.CustomSkinLoader;
import net.minecraft.tileentity.TileEntitySkull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@@ -15,6 +16,8 @@ public abstract class MixinTileEntitySkull {
cancellable = true
)
private static void inject_updateGameProfile(GameProfile input, CallbackInfoReturnable<GameProfile> callbackInfoReturnable) {
callbackInfoReturnable.setReturnValue(input);
if (!CustomSkinLoader.config.forceFillSkullNBT) {
callbackInfoReturnable.setReturnValue(input);
}
}
}